Changeset 115788 in webkit


Ignore:
Timestamp:
May 1, 2012 8:41:29 PM (12 years ago)
Author:
xji@chromium.org
Message:

Source/WebCore: enable ctrl-arrow move by word visually in non-Windows platforms.
https://bugs.webkit.org/show_bug.cgi?id=85017

Reviewed by Ryosuke Niwa.

Enable ctrl-arrow moves caret by word in visual order in non-Windows platforms that use ICU word
break iterator (it is not enabled for WinCE and Qt where ICU is not used). For those platforms, ctrl-arrow
moves caret to word break position before spaces. For example, given a logical text "abc def hij", the word
break positions using ctrl-left-arrow from rightmost position are "|abc |def |hij".
The word break positions using ctrl-right-arrow from leftmost position are "abc| def| hij|".

Test: editing/selection/move-by-word-visually-mac.html

  • editing/EditingBehavior.h:

(EditingBehavior):
(WebCore::EditingBehavior::shouldEatSpaceToNextWord): To control different word break positions
(regards to space) for different platforms.

  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::modifyMovingRight): Enable visual word movement for all platforms that use ICU.
(WebCore::FrameSelection::modifyMovingLeft):

  • editing/visible_units.cpp:

(WebCore::visualWordPosition): Determine the right word break position (regards to space) based on EditingBehavior.
(WebCore::leftWordPosition):
(WebCore::rightWordPosition):

  • editing/visible_units.h:

LayoutTests: enable ctrl-arrow move by word visually in other platforms (besides Windows)
https://bugs.webkit.org/show_bug.cgi?id=85017

Reviewed by Ryosuke Niwa.

Since DOMSelection.modify('move', 'left'/'right', 'word') moves caret by word in visual order (instead of
logical order) now, there are several changes to the test file:

  1. file name renamed from move-left-right-by-word-mac.html to move-by-word-visually-mac.html.
  2. test expectations change from moving caret by word in logical order to moving caret by word in visual order.
  3. since test expectations are inside test file itself, test file itself changes accordingly.
  • editing/selection/move-by-word-visually-mac-expected.txt: Copied from LayoutTests/editing/selection/move-left-right-by-word-mac-expected.txt.
  • editing/selection/move-by-word-visually-mac.html: Copied from LayoutTests/editing/selection/move-left-right-by-word-mac.html.
  • editing/selection/move-left-right-by-word-mac-expected.txt: Removed.
  • editing/selection/move-left-right-by-word-mac.html: Removed.
Location:
trunk
Files:
2 added
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r115787 r115788  
     12012-05-01  Xiaomei Ji  <xji@chromium.org>
     2
     3        enable ctrl-arrow move by word visually in other platforms (besides Windows)
     4        https://bugs.webkit.org/show_bug.cgi?id=85017
     5
     6        Reviewed by Ryosuke Niwa.
     7 
     8        Since DOMSelection.modify('move', 'left'/'right', 'word') moves caret by word in visual order (instead of
     9        logical order) now, there are several changes to the test file:
     10        1. file name renamed from move-left-right-by-word-mac.html to move-by-word-visually-mac.html.
     11        2. test expectations change from moving caret by word in logical order to moving caret by word in visual order.
     12        3. since test expectations are inside test file itself, test file itself changes accordingly.
     13       
     14        * editing/selection/move-by-word-visually-mac-expected.txt: Copied from LayoutTests/editing/selection/move-left-right-by-word-mac-expected.txt.
     15        * editing/selection/move-by-word-visually-mac.html: Copied from LayoutTests/editing/selection/move-left-right-by-word-mac.html.
     16        * editing/selection/move-left-right-by-word-mac-expected.txt: Removed.
     17        * editing/selection/move-left-right-by-word-mac.html: Removed.
     18
    1192012-05-01  Raymond Liu  <raymond.liu@intel.com>
    220
  • trunk/Source/WebCore/ChangeLog

    r115787 r115788  
     12012-05-01  Xiaomei Ji  <xji@chromium.org>
     2
     3        enable ctrl-arrow move by word visually in non-Windows platforms.
     4        https://bugs.webkit.org/show_bug.cgi?id=85017
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Enable ctrl-arrow moves caret by word in visual order in non-Windows platforms that use ICU word
     9        break iterator (it is not enabled for WinCE and Qt where ICU is not used). For those platforms, ctrl-arrow
     10        moves caret to word break position before spaces. For example, given a logical text "abc def hij", the word
     11        break positions using ctrl-left-arrow from rightmost position are "|abc |def |hij".
     12        The word break positions using ctrl-right-arrow from leftmost position are "abc| def| hij|".
     13
     14        Test: editing/selection/move-by-word-visually-mac.html
     15
     16        * editing/EditingBehavior.h:
     17        (EditingBehavior):
     18        (WebCore::EditingBehavior::shouldEatSpaceToNextWord): To control different word break positions
     19        (regards to space) for different platforms.
     20        * editing/FrameSelection.cpp:
     21        (WebCore::FrameSelection::modifyMovingRight): Enable visual word movement for all platforms that use ICU.
     22        (WebCore::FrameSelection::modifyMovingLeft):
     23        * editing/visible_units.cpp:
     24        (WebCore::visualWordPosition): Determine the right word break position (regards to space) based on EditingBehavior.
     25        (WebCore::leftWordPosition):
     26        (WebCore::rightWordPosition):
     27        * editing/visible_units.h:
     28
    1292012-05-01  Raymond Liu  <raymond.liu@intel.com>
    230
  • trunk/Source/WebCore/editing/EditingBehavior.h

    r105473 r115788  
    6161    bool shouldSelectOnContextualMenuClick() const { return m_type == EditingMacBehavior; }
    6262   
    63     // On Windows, moving caret left or right by word moves the caret by word in visual order.
    64     // It moves the caret by word in logical order in other platforms.
    65     bool shouldMoveLeftRightByWordInVisualOrder() const { return m_type == EditingWindowsBehavior; }
    66 
    6763    // On Mac and Windows, pressing backspace (when it isn't handled otherwise) should navigate back.
    6864    bool shouldNavigateBackOnBackspace() const { return m_type != EditingUnixBehavior; }
     
    7369    bool shouldExtendSelectionByWordOrLineAcrossCaret() const { return m_type != EditingMacBehavior; }
    7470
     71    // Based on native behavior, when using ctrl(alt)+arrow to move caret by word, ctrl(alt)+left arrow moves caret to
     72    // immediately before the word in all platforms, for example, the word break positions are: "|abc |def |hij |opq".
     73    // But ctrl+right arrow moves caret to "abc |def |hij |opq" on Windows and "abc| def| hij| opq|" on Mac and Linux.
     74    bool shouldSkipSpaceWhenMovingRight() const { return m_type == EditingWindowsBehavior; }
     75
    7576private:
    7677    EditingBehaviorType m_type;
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r115097 r115788  
    641641            pos = VisiblePosition(m_selection.extent(), m_selection.affinity()).right(true);
    642642        break;
    643     case WordGranularity:
    644 #if !OS(WINCE)
    645         // Visual word movement relies on isWordTextBreak which is not implemented in WinCE.
    646         if (visualWordMovementEnabled()
    647             || (m_frame && m_frame->editor()->behavior().shouldMoveLeftRightByWordInVisualOrder())) {
    648             pos = rightWordPosition(VisiblePosition(m_selection.extent(), m_selection.affinity()));
    649             break;
    650         }
     643    case WordGranularity: {
     644#if USE(ICU_UNICODE)
     645        // Visual word movement relies on isWordTextBreak which is not implemented in WinCE and QT.
     646        // https://bugs.webkit.org/show_bug.cgi?id=81136.
     647        bool skipsSpaceWhenMovingRight = m_frame && m_frame->editor()->behavior().shouldSkipSpaceWhenMovingRight();
     648        pos = rightWordPosition(VisiblePosition(m_selection.extent(), m_selection.affinity()), skipsSpaceWhenMovingRight);
     649        break;
    651650#endif
     651    }
    652652    case SentenceGranularity:
    653653    case LineGranularity:
     
    811811            pos = VisiblePosition(m_selection.extent(), m_selection.affinity()).left(true);
    812812        break;
    813     case WordGranularity:
    814 #if !OS(WINCE)
    815         if (visualWordMovementEnabled()
    816             || (m_frame && m_frame->editor()->behavior().shouldMoveLeftRightByWordInVisualOrder())) {
    817             pos = leftWordPosition(VisiblePosition(m_selection.extent(), m_selection.affinity()));
    818             break;
    819         }
     813    case WordGranularity: {
     814#if USE(ICU_UNICODE)
     815        bool skipsSpaceWhenMovingRight = m_frame && m_frame->editor()->behavior().shouldSkipSpaceWhenMovingRight();
     816        pos = leftWordPosition(VisiblePosition(m_selection.extent(), m_selection.affinity()), skipsSpaceWhenMovingRight);
     817        break;
    820818#endif
     819    }
    821820    case SentenceGranularity:
    822821    case LineGranularity:
  • trunk/Source/WebCore/editing/visible_units.cpp

    r113990 r115788  
    368368enum CursorMovementDirection { MoveLeft, MoveRight };
    369369
    370 static VisiblePosition visualWordPosition(const VisiblePosition& visiblePosition, CursorMovementDirection direction)
     370static VisiblePosition visualWordPosition(const VisiblePosition& visiblePosition, CursorMovementDirection direction,
     371    bool skipsSpaceWhenMovingRight)
    371372{
    372373    if (visiblePosition.isNull())
     
    419420
    420421        bool isWordBreak;
    421         if (box->direction() == blockDirection) {
     422        bool boxHasSameDirectionalityAsBlock = box->direction() == blockDirection;
     423        bool movingBackward = (direction == MoveLeft && box->direction() == LTR) || (direction == MoveRight && box->direction() == RTL);
     424        if ((skipsSpaceWhenMovingRight && boxHasSameDirectionalityAsBlock)
     425            || (!skipsSpaceWhenMovingRight && movingBackward)) {
    422426            bool logicalStartInRenderer = offsetInBox == static_cast<int>(textBox->start()) && previousBoxInDifferentBlock;
    423427            isWordBreak = isLogicalStartOfWord(iter, offsetInIterator, logicalStartInRenderer);
     
    435439}
    436440
    437 VisiblePosition leftWordPosition(const VisiblePosition& visiblePosition)
    438 {
    439     VisiblePosition leftWordBreak = visualWordPosition(visiblePosition, MoveLeft);
     441VisiblePosition leftWordPosition(const VisiblePosition& visiblePosition, bool skipsSpaceWhenMovingRight)
     442{
     443    VisiblePosition leftWordBreak = visualWordPosition(visiblePosition, MoveLeft, skipsSpaceWhenMovingRight);
    440444    leftWordBreak = visiblePosition.honorEditingBoundaryAtOrBefore(leftWordBreak);
    441445   
     
    448452}
    449453
    450 VisiblePosition rightWordPosition(const VisiblePosition& visiblePosition)
    451 {
    452     VisiblePosition rightWordBreak = visualWordPosition(visiblePosition, MoveRight);
     454VisiblePosition rightWordPosition(const VisiblePosition& visiblePosition, bool skipsSpaceWhenMovingRight)
     455{
     456    VisiblePosition rightWordBreak = visualWordPosition(visiblePosition, MoveRight, skipsSpaceWhenMovingRight);
    453457    rightWordBreak = visiblePosition.honorEditingBoundaryAtOrBefore(rightWordBreak);
    454458
  • trunk/Source/WebCore/editing/visible_units.h

    r104276 r115788  
    2727#define visible_units_h
    2828
     29#include "EditingBehaviorTypes.h"
    2930#include "EditingBoundary.h"
    3031#include "TextDirection.h"
     
    4243VisiblePosition previousWordPosition(const VisiblePosition &);
    4344VisiblePosition nextWordPosition(const VisiblePosition &);
    44 VisiblePosition rightWordPosition(const VisiblePosition&);
    45 VisiblePosition leftWordPosition(const VisiblePosition&);
     45VisiblePosition rightWordPosition(const VisiblePosition&, bool skipsSpaceWhenMovingRight);
     46VisiblePosition leftWordPosition(const VisiblePosition&, bool skipsSpaceWhenMovingRight);
    4647bool isStartOfWord(const VisiblePosition&);
    4748
Note: See TracChangeset for help on using the changeset viewer.