Changeset 76312 in webkit


Ignore:
Timestamp:
Jan 20, 2011 5:21:11 PM (13 years ago)
Author:
leviw@chromium.org
Message:

2011-01-20 Levi Weintraub <leviw@chromium.org>

Reviewed by Ryosuke Niwa.

RTL: Caret goes to the opposite direction when pressing an arrow key after selection is made
https://bugs.webkit.org/show_bug.cgi?id=49511

Test: editing/selection/rtl-move-selection-right-left.html

  • editing/SelectionController.cpp: (WebCore::SelectionController::willBeModified): Respecting the direction of the containing block when switching selection base and extent in RTL content.

(WebCore::SelectionController::modifyMovingRight):
(WebCore::SelectionController::modifyMovingLeft):
Using directionOfEnclosingBlock when deciding to use the selection start or end to do the
correct thing for RTL.

2011-01-20 Levi Weintraub <leviw@chromium.org>

Reviewed by Ryosuke Niwa.

RTL: Caret goes to the opposite direction when pressing an arrow key after selection is made
https://bugs.webkit.org/show_bug.cgi?id=49511

  • editing/editing.js: (execMoveSelectionLeftByCharacterCommand): (moveSelectionLeftByCharacterCommand): (execMoveSelectionRightByCharacterCommand): (moveSelectionRightByCharacterCommand): (execExtendSelectionLeftByCharacterCommand): (extendSelectionLeftByCharacterCommand): (execExtendSelectionRightByCharacterCommand): (extendSelectionRightByCharacterCommand): Adding some left/right selection convenience methods for use with RTL tests.
  • editing/selection/rtl-move-selection-right-left-expected.txt: Added.
  • editing/selection/rtl-move-selection-right-left.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r76307 r76312  
     12011-01-20  Levi Weintraub  <leviw@chromium.org>
     2
     3        Reviewed by Ryosuke Niwa.
     4
     5        RTL: Caret goes to the opposite direction when pressing an arrow key after selection is made
     6        https://bugs.webkit.org/show_bug.cgi?id=49511
     7
     8        * editing/editing.js:
     9        (execMoveSelectionLeftByCharacterCommand):
     10        (moveSelectionLeftByCharacterCommand):
     11        (execMoveSelectionRightByCharacterCommand):
     12        (moveSelectionRightByCharacterCommand):
     13        (execExtendSelectionLeftByCharacterCommand):
     14        (extendSelectionLeftByCharacterCommand):
     15        (execExtendSelectionRightByCharacterCommand):
     16        (extendSelectionRightByCharacterCommand):
     17        Adding some left/right selection convenience methods for use with RTL tests.
     18
     19        * editing/selection/rtl-move-selection-right-left-expected.txt: Added.
     20        * editing/selection/rtl-move-selection-right-left.html: Added.
     21
    1222011-01-20  Tony Chang  <tony@chromium.org>
    223
  • trunk/LayoutTests/editing/editing.js

    r55913 r76312  
    3535    else {
    3636        execTransposeCharactersCommand();
     37    }
     38}
     39
     40//-------------------------------------------------------------------------------------------------------
     41
     42function execMoveSelectionLeftByCharacterCommand() {
     43    selection.modify("move", "left", "character");
     44}
     45function moveSelectionLeftByCharacterCommand() {
     46    if (commandDelay > 0) {
     47        window.setTimeout(execMoveSelectionLeftByCharacterCommand, commandCount * commandDelay);
     48        commandCount++;
     49    }
     50    else {
     51        execMoveSelectionLeftByCharacterCommand();
     52    }
     53}
     54
     55//-------------------------------------------------------------------------------------------------------
     56
     57function execMoveSelectionRightByCharacterCommand() {
     58    selection.modify("move", "Right", "character");
     59}
     60function moveSelectionRightByCharacterCommand() {
     61    if (commandDelay > 0) {
     62        window.setTimeout(execMoveSelectionRightByCharacterCommand, commandCount * commandDelay);
     63        commandCount++;
     64    }
     65    else {
     66        execMoveSelectionRightByCharacterCommand();
     67    }
     68}
     69
     70//-------------------------------------------------------------------------------------------------------
     71
     72function execExtendSelectionLeftByCharacterCommand() {
     73    selection.modify("extend", "left", "character");
     74}
     75function extendSelectionLeftByCharacterCommand() {
     76    if (commandDelay > 0) {
     77        window.setTimeout(execExtendSelectionLeftByCharacterCommand, commandCount * commandDelay);
     78        commandCount++;
     79    }
     80    else {
     81        execExtendSelectionLeftByCharacterCommand();
     82    }
     83}
     84
     85//-------------------------------------------------------------------------------------------------------
     86
     87function execExtendSelectionRightByCharacterCommand() {
     88    selection.modify("extend", "Right", "character");
     89}
     90function extendSelectionRightByCharacterCommand() {
     91    if (commandDelay > 0) {
     92        window.setTimeout(execExtendSelectionRightByCharacterCommand, commandCount * commandDelay);
     93        commandCount++;
     94    }
     95    else {
     96        execExtendSelectionRightByCharacterCommand();
    3797    }
    3898}
  • trunk/Source/WebCore/ChangeLog

    r76303 r76312  
     12011-01-20  Levi Weintraub  <leviw@chromium.org>
     2
     3        Reviewed by Ryosuke Niwa.
     4
     5        RTL: Caret goes to the opposite direction when pressing an arrow key after selection is made
     6        https://bugs.webkit.org/show_bug.cgi?id=49511
     7
     8        Test: editing/selection/rtl-move-selection-right-left.html
     9
     10        * editing/SelectionController.cpp:
     11        (WebCore::SelectionController::willBeModified):
     12        Respecting the direction of the containing block when switching selection base and extent in
     13        RTL content.
     14
     15        (WebCore::SelectionController::modifyMovingRight):
     16        (WebCore::SelectionController::modifyMovingLeft):
     17        Using directionOfEnclosingBlock when deciding to use the selection start or end to do the
     18        correct thing for RTL.
     19
    1202011-01-20  Nate Chapin  <japhet@chromium.org>
    221
  • trunk/Source/WebCore/editing/SelectionController.cpp

    r75018 r76312  
    314314    Position end = m_selection.end();
    315315
     316    bool baseIsStart;
     317
    316318    if (m_isDirectional) {
    317319        // Make base and extent match start and end so we extend the user-visible selection.
    318320        // This only matters for cases where base and extend point to different positions than
    319321        // start and end (e.g. after a double-click to select a word).
    320         if (m_selection.isBaseFirst()) {
    321             m_selection.setBase(start);
    322             m_selection.setExtent(end);           
    323         } else {
    324             m_selection.setBase(end);
    325             m_selection.setExtent(start);
    326         }
     322        if (m_selection.isBaseFirst())
     323            baseIsStart = true;
     324        else
     325            baseIsStart = false;
    327326    } else {
    328         // FIXME: This is probably not correct for right and left when the direction is RTL.
    329327        switch (direction) {
    330328        case DirectionRight:
     329            if (directionOfEnclosingBlock() == LTR)
     330                baseIsStart = true;
     331            else
     332                baseIsStart = false;
     333            break;
    331334        case DirectionForward:
    332             m_selection.setBase(start);
    333             m_selection.setExtent(end);
     335            baseIsStart = true;
    334336            break;
    335337        case DirectionLeft:
     338            if (directionOfEnclosingBlock() == LTR)
     339                baseIsStart = false;
     340            else
     341                baseIsStart = true;
     342            break;
    336343        case DirectionBackward:
    337             m_selection.setBase(end);
    338             m_selection.setExtent(start);
     344            baseIsStart = false;
    339345            break;
    340346        }
     347    }
     348    if (baseIsStart) {
     349        m_selection.setBase(start);
     350        m_selection.setExtent(end);
     351    } else {
     352        m_selection.setBase(end);
     353        m_selection.setExtent(start);
    341354    }
    342355}
     
    456469    switch (granularity) {
    457470    case CharacterGranularity:
    458         if (isRange())
    459             pos = VisiblePosition(m_selection.end(), m_selection.affinity());
    460         else
     471        if (isRange()) {
     472            if (directionOfEnclosingBlock() == LTR)
     473                pos = VisiblePosition(m_selection.end(), m_selection.affinity());
     474            else
     475                pos = VisiblePosition(m_selection.start(), m_selection.affinity());
     476        } else
    461477            pos = VisiblePosition(m_selection.extent(), m_selection.affinity()).right(true);
    462478        break;
     
    610626    case CharacterGranularity:
    611627        if (isRange())
    612             pos = VisiblePosition(m_selection.start(), m_selection.affinity());
     628            if (directionOfEnclosingBlock() == LTR)
     629                pos = VisiblePosition(m_selection.start(), m_selection.affinity());
     630            else
     631                pos = VisiblePosition(m_selection.end(), m_selection.affinity());
    613632        else
    614633            pos = VisiblePosition(m_selection.extent(), m_selection.affinity()).left(true);
Note: See TracChangeset for help on using the changeset viewer.