Changeset 102252 in webkit


Ignore:
Timestamp:
Dec 7, 2011 11:05:50 AM (12 years ago)
Author:
xji@chromium.org
Message:

Source/WebCore: Turn on move caret by word visually for Windows platform.
https://bugs.webkit.org/show_bug.cgi?id=59652

Reviewed by Ryosuke Niwa.

We already support (arrow key) moving cursor by character in visual order.
This patch implements (ctrl/alt-arrow) moving cursor by word in visual order (in Windows).
It matches Firefox's default behavior.

Without this patch, ctrl(alt for mac)-arrow key or
selection.modify("move", "left"/"right", "word") moves cursor by word in logical order.

IE implements moving cursor by logical order for both arrow key and ctrl-arrow key.
Firefox implements moving cursor by visual order for both operations.
From Chromium bug report, native speakers would like moving cursor by visual order since it
is more intuitive.

The patch is only enabled for Windows (by EditingBehavior) because current implementation
matches Windows' native behavior.
For exmaple, if the logical text is "abc def hij", the cursor positions are
"|abc |def |hij|" no matter pressing ctrl-left-arrow or ctrl-right-arrow.

Mac and Linux's native behavior is slightly different. In which, when pressing
ctrl-left-arrow, the cursor positions are "|abc |def |hij|". When pressing ctrl-right-arrow,
the cursor positions are "|abc| def| hij|". We will implement it next.

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

  • editing/EditingBehavior.h:

(WebCore::EditingBehavior::shouldMoveLeftRightByWordInVisualOrder):

  • editing/FrameSelection.cpp: Remove experimental enum WebKitVisualWordGranularity.

(WebCore::FrameSelection::modifyExtendingRight):
(WebCore::FrameSelection::modifyExtendingForward):
(WebCore::FrameSelection::modifyMovingRight):
(WebCore::FrameSelection::modifyMovingForward):
(WebCore::FrameSelection::modifyExtendingLeft):
(WebCore::FrameSelection::modifyExtendingBackward):
(WebCore::FrameSelection::modifyMovingLeft):
(WebCore::FrameSelection::modifyMovingBackward):

  • editing/TextGranularity.h: Remove experimental enum WebKitVisualWordGranularity.
  • editing/VisibleSelection.cpp: Remove experimental enum WebKitVisualWordGranularity.

(WebCore::VisibleSelection::setStartAndEndFromBaseAndExtentRespectingGranularity):

  • page/DOMSelection.cpp: Remove experimental experimental flag -webkit-visual-word.

(WebCore::DOMSelection::modify):

LayoutTests: Turn on move caret by word visually for windows platform.
https://bugs.webkit.org/show_bug.cgi?id=59652

Reviewed by Ryosuke Niwa.

  • editing/selection/caret-mode-paragraph-keys-navigation.html:
  • editing/selection/move-by-word-visually-crash-test-1.html:
  • editing/selection/move-by-word-visually-crash-test-2.html:
  • editing/selection/move-by-word-visually-crash-test-3.html:
  • editing/selection/move-by-word-visually-crash-test-4.html:
  • editing/selection/move-by-word-visually-crash-test-textarea.html:
  • editing/selection/move-by-word-visually-inline-block-positioned-element.html:
  • editing/selection/move-by-word-visually-multi-line.html:
  • editing/selection/move-by-word-visually-multi-space.html:
  • editing/selection/move-by-word-visually-null-box.html:
  • editing/selection/move-by-word-visually-single-space-inline-element.html:
  • editing/selection/move-by-word-visually-single-space-one-element.html:
  • editing/selection/move-by-word-visually-textarea.html:
  • editing/selection/move-left-right-by-word-mac-expected.txt: Added.
  • editing/selection/move-left-right-by-word-mac.html: Added.
  • editing/selection/resources/move-by-word-visually.js:

(moveByWord):
(moveByWordOnEveryChar):

Location:
trunk
Files:
2 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r102245 r102252  
     12011-12-07  Xiaomei Ji  <xji@chromium.org>
     2
     3        Turn on move caret by word visually for windows platform.
     4        https://bugs.webkit.org/show_bug.cgi?id=59652
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * editing/selection/caret-mode-paragraph-keys-navigation.html:
     9        * editing/selection/move-by-word-visually-crash-test-1.html:
     10        * editing/selection/move-by-word-visually-crash-test-2.html:
     11        * editing/selection/move-by-word-visually-crash-test-3.html:
     12        * editing/selection/move-by-word-visually-crash-test-4.html:
     13        * editing/selection/move-by-word-visually-crash-test-textarea.html:
     14        * editing/selection/move-by-word-visually-inline-block-positioned-element.html:
     15        * editing/selection/move-by-word-visually-multi-line.html:
     16        * editing/selection/move-by-word-visually-multi-space.html:
     17        * editing/selection/move-by-word-visually-null-box.html:
     18        * editing/selection/move-by-word-visually-single-space-inline-element.html:
     19        * editing/selection/move-by-word-visually-single-space-one-element.html:
     20        * editing/selection/move-by-word-visually-textarea.html:
     21        * editing/selection/move-left-right-by-word-mac-expected.txt: Added.
     22        * editing/selection/move-left-right-by-word-mac.html: Added.
     23        * editing/selection/resources/move-by-word-visually.js:
     24        (moveByWord):
     25        (moveByWordOnEveryChar):
     26
    1272011-12-07  Balazs Kelemen  <kbalazs@webkit.org>
    228
  • trunk/LayoutTests/editing/selection/caret-mode-paragraph-keys-navigation.html

    r99258 r102252  
    1414  layoutTestController.overridePreference("WebKitEnableCaretBrowsing", true);
    1515  layoutTestController.dumpAsText();
     16  layoutTestController.setEditingBehavior('mac');
    1617
    1718  var target = document.getElementById("target");
  • trunk/LayoutTests/editing/selection/move-by-word-visually-crash-test-1.html

    r93935 r102252  
    1010};
    1111
    12 if (window.layoutTestController)
     12if (window.layoutTestController) {
    1313    layoutTestController.dumpAsText();
     14    layoutTestController.setEditingBehavior('win');
     15}
    1416</script>
    1517<textarea></textarea>
  • trunk/LayoutTests/editing/selection/move-by-word-visually-crash-test-2.html

    r93935 r102252  
    1010};
    1111
    12 if (window.layoutTestController)
     12if (window.layoutTestController) {
    1313    layoutTestController.dumpAsText();
     14    layoutTestController.setEditingBehavior('win');
     15}
    1416</script>
    1517<vkern></vkern><marquee><div title="0|0" class="test_move_by_word">abc def
  • trunk/LayoutTests/editing/selection/move-by-word-visually-crash-test-3.html

    r93935 r102252  
    1010};
    1111
    12 if (window.layoutTestController)
     12if (window.layoutTestController) {
    1313    layoutTestController.dumpAsText();
     14    layoutTestController.setEditingBehavior('win');
     15}
    1416</script>
    1517<video></video><meter><image class="test_move_by_word" title="0|0">
  • trunk/LayoutTests/editing/selection/move-by-word-visually-crash-test-4.html

    r93935 r102252  
    1010};
    1111
    12 if (window.layoutTestController)
     12if (window.layoutTestController) {
    1313    layoutTestController.dumpAsText();
     14    layoutTestController.setEditingBehavior('win');
     15}
    1416</script>
    1517><div title="0|0" class="test_move_by_word" dir=ltr><keygen><base>
  • trunk/LayoutTests/editing/selection/move-by-word-visually-crash-test-textarea.html

    r99886 r102252  
    1616};
    1717
    18 if (window.layoutTestController)
     18if (window.layoutTestController) {
    1919    layoutTestController.dumpAsText();
     20    layoutTestController.setEditingBehavior('win');
     21}
    2022</script>
    2123
  • trunk/LayoutTests/editing/selection/move-by-word-visually-inline-block-positioned-element.html

    r101430 r102252  
    1010};
    1111
    12 if (window.layoutTestController)
     12if (window.layoutTestController) {
    1313    layoutTestController.dumpAsText();
     14    layoutTestController.setEditingBehavior('win');
     15}
    1416</script>
    1517
  • trunk/LayoutTests/editing/selection/move-by-word-visually-multi-line.html

    r101430 r102252  
    1818};
    1919
    20 if (window.layoutTestController)
     20if (window.layoutTestController) {
    2121    layoutTestController.dumpAsText();
     22    layoutTestController.setEditingBehavior('win');
     23}
    2224</script>
    2325</head>
  • trunk/LayoutTests/editing/selection/move-by-word-visually-multi-space.html

    r92223 r102252  
    1818};
    1919
    20 if (window.layoutTestController)
     20if (window.layoutTestController) {
    2121    layoutTestController.dumpAsText();
     22    layoutTestController.setEditingBehavior('win');
     23}
    2224</script>
    2325</head>
  • trunk/LayoutTests/editing/selection/move-by-word-visually-null-box.html

    r91788 r102252  
    1616};
    1717
    18 if (window.layoutTestController)
     18if (window.layoutTestController) {
    1919    layoutTestController.dumpAsText();
     20    layoutTestController.setEditingBehavior('win');
     21}
    2022</script>
    2123<div id="console"></div>
  • trunk/LayoutTests/editing/selection/move-by-word-visually-single-space-inline-element.html

    r92223 r102252  
    1818};
    1919
    20 if (window.layoutTestController)
     20if (window.layoutTestController) {
    2121    layoutTestController.dumpAsText();
     22    layoutTestController.setEditingBehavior('win');
     23}
    2224</script>
    2325</head>
  • trunk/LayoutTests/editing/selection/move-by-word-visually-single-space-one-element.html

    r98428 r102252  
    1818};
    1919
    20 if (window.layoutTestController)
     20if (window.layoutTestController) {
    2121    layoutTestController.dumpAsText();
     22    layoutTestController.setEditingBehavior('win');
     23}
    2224</script>
    2325</head>
  • trunk/LayoutTests/editing/selection/move-by-word-visually-textarea.html

    r101430 r102252  
    1818    for (i = 0; i < 5; ++i) {
    1919        var start = test.selectionStart;
    20         sel.modify("move", "right", "-webkit-visual-word");
     20        sel.modify("move", "right", "word");
    2121        var wordBreak;
    2222        if (i >= wordBreaks.length)
     
    3434}
    3535
    36 if (window.layoutTestController)
     36if (window.layoutTestController) {
    3737    layoutTestController.dumpAsText();
     38    layoutTestController.setEditingBehavior('win');
     39}
    3840</script>
    3941
  • trunk/LayoutTests/editing/selection/resources/move-by-word-visually.js

    r93935 r102252  
    156156
    157157    while (1) {
    158         sel.modify("move", searchDirection, "-webkit-visual-word");
     158        sel.modify("move", searchDirection, "word");
    159159        if (prevNode == sel.anchorNode && prevOffset == sel.anchorOffset)
    160160            break;
     
    179179        var positions = [];
    180180        positions.push({ node: sel.anchorNode, offset: sel.anchorOffset });
    181         sel.modify("move", searchDirection, "-webkit-visual-word");
     181        sel.modify("move", searchDirection, "word");
    182182
    183183        var position = { node: sel.anchorNode, offset: sel.anchorOffset };
  • trunk/Source/WebCore/ChangeLog

    r102250 r102252  
     12011-12-07  Xiaomei Ji  <xji@chromium.org>
     2
     3        Turn on move caret by word visually for Windows platform.
     4        https://bugs.webkit.org/show_bug.cgi?id=59652
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        We already support (arrow key) moving cursor by character in visual order.
     9        This patch implements (ctrl/alt-arrow) moving cursor by word in visual order (in Windows).
     10        It matches Firefox's default behavior.
     11
     12        Without this patch, ctrl(alt for mac)-arrow key or
     13        selection.modify("move", "left"/"right", "word") moves cursor by word in logical order.
     14
     15        IE implements moving cursor by logical order for both arrow key and ctrl-arrow key.
     16        Firefox implements moving cursor by visual order for both operations.
     17        From Chromium bug report, native speakers would like moving cursor by visual order since it
     18        is more intuitive.
     19
     20        The patch is only enabled for Windows (by EditingBehavior) because current implementation
     21        matches Windows' native behavior.
     22        For exmaple, if the logical text is "abc def hij", the cursor positions are
     23        "|abc |def |hij|" no matter pressing ctrl-left-arrow or ctrl-right-arrow.
     24
     25        Mac and Linux's native behavior is slightly different. In which, when pressing
     26        ctrl-left-arrow, the cursor positions are "|abc |def |hij|". When pressing ctrl-right-arrow,
     27        the cursor positions are "|abc| def| hij|". We will implement it next.
     28
     29        Test: editing/selection/move-left-right-by-word-mac.html
     30
     31        * editing/EditingBehavior.h:
     32        (WebCore::EditingBehavior::shouldMoveLeftRightByWordInVisualOrder):
     33        * editing/FrameSelection.cpp: Remove experimental enum WebKitVisualWordGranularity.
     34        (WebCore::FrameSelection::modifyExtendingRight):
     35        (WebCore::FrameSelection::modifyExtendingForward):
     36        (WebCore::FrameSelection::modifyMovingRight):
     37        (WebCore::FrameSelection::modifyMovingForward):
     38        (WebCore::FrameSelection::modifyExtendingLeft):
     39        (WebCore::FrameSelection::modifyExtendingBackward):
     40        (WebCore::FrameSelection::modifyMovingLeft):
     41        (WebCore::FrameSelection::modifyMovingBackward):
     42        * editing/TextGranularity.h: Remove experimental enum WebKitVisualWordGranularity.
     43        * editing/VisibleSelection.cpp: Remove experimental enum WebKitVisualWordGranularity.
     44        (WebCore::VisibleSelection::setStartAndEndFromBaseAndExtentRespectingGranularity):
     45        * page/DOMSelection.cpp: Remove experimental experimental flag -webkit-visual-word.
     46        (WebCore::DOMSelection::modify):
     47
    1482011-12-07  Jonathan Backer  <backer@chromium.org>
    249
  • trunk/Source/WebCore/editing/EditingBehavior.h

    r95901 r102252  
    6060    // On Mac, when processing a contextual click, the object being clicked upon should be selected.
    6161    bool shouldSelectOnContextualMenuClick() const { return m_type == EditingMacBehavior; }
     62   
     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; }
    6266
    6367    // On Mac and Windows, pressing backspace (when it isn't handled otherwise) should navigate back.
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r102225 r102252  
    573573        pos = modifyExtendingForward(granularity);
    574574        break;
    575     case WebKitVisualWordGranularity:
    576         break;
    577575    }
    578576    return pos;
     
    613611        else
    614612            pos = endOfDocument(pos);
    615         break;
    616     case WebKitVisualWordGranularity:
    617613        break;
    618614    }
     
    635631        break;
    636632    case WordGranularity:
    637         if (visualWordMovementEnabled()) {
     633        if (visualWordMovementEnabled()
     634            || (m_frame && m_frame->editor()->behavior().shouldMoveLeftRightByWordInVisualOrder())) {
    638635            pos = rightWordPosition(VisiblePosition(m_selection.extent(), m_selection.affinity()));
    639636            break;
     
    651648        pos = rightBoundaryOfLine(startForPlatform(), directionOfEnclosingBlock());
    652649        break;
    653     case WebKitVisualWordGranularity:
    654         pos = rightWordPosition(VisiblePosition(m_selection.extent(), m_selection.affinity()));
    655         break;
    656650    }
    657651    return pos;
     
    701695        else
    702696            pos = endOfDocument(pos);
    703         break;
    704     case WebKitVisualWordGranularity:
    705697        break;
    706698    }
     
    744736        pos = modifyExtendingBackward(granularity);
    745737        break;
    746     case WebKitVisualWordGranularity:
    747         break;
    748738    }
    749739    return pos;
     
    789779        else
    790780            pos = startOfDocument(pos);
    791         break;
    792     case WebKitVisualWordGranularity:
    793781        break;
    794782    }
     
    810798        break;
    811799    case WordGranularity:
    812         if (visualWordMovementEnabled()) {
     800        if (visualWordMovementEnabled()
     801            || (m_frame && m_frame->editor()->behavior().shouldMoveLeftRightByWordInVisualOrder())) {
    813802            pos = leftWordPosition(VisiblePosition(m_selection.extent(), m_selection.affinity()));
    814803            break;
     
    826815        pos = leftBoundaryOfLine(startForPlatform(), directionOfEnclosingBlock());
    827816        break;
    828     case WebKitVisualWordGranularity:
    829         pos = leftWordPosition(VisiblePosition(m_selection.extent(), m_selection.affinity()));
    830         break;
    831817    }
    832818    return pos;
     
    870856        else
    871857            pos = startOfDocument(pos);
    872         break;
    873     case WebKitVisualWordGranularity:
    874858        break;
    875859    }
  • trunk/Source/WebCore/editing/TextGranularity.h

    r82588 r102252  
    4040    LineBoundary,
    4141    ParagraphBoundary,
    42     DocumentBoundary,
    43     // FIXME: this is added temporarily for experiment with visually move
    44     // caret by wordGranularity. Once all patches are landed, it should be removed.
    45     WebKitVisualWordGranularity
     42    DocumentBoundary
    4643};
    4744
  • trunk/Source/WebCore/editing/VisibleSelection.cpp

    r93134 r102252  
    387387            m_end = endOfSentence(VisiblePosition(m_end, m_affinity)).deepEquivalent();
    388388            break;
    389         case WebKitVisualWordGranularity:
    390             break;
    391389    }
    392390   
  • trunk/Source/WebCore/page/DOMSelection.cpp

    r89440 r102252  
    334334    else if (equalIgnoringCase(granularityString, "documentboundary"))
    335335        granularity = DocumentBoundary;
    336     else if (equalIgnoringCase(granularityString, "-webkit-visual-word"))
    337         granularity = WebKitVisualWordGranularity;
    338336    else
    339337        return;
Note: See TracChangeset for help on using the changeset viewer.