Changeset 62816 in webkit


Ignore:
Timestamp:
Jul 8, 2010 12:25:36 PM (14 years ago)
Author:
ojan@chromium.org
Message:

2010-07-07 Ojan Vafai <ojan@chromium.org>

Reviewed by Darin Adler.

Regression: Selection anchor + focus swap when arrow keys after setBaseAndExtent
https://bugs.webkit.org/show_bug.cgi?id=32605

  • editing/selection/5195166-1.html:
  • editing/selection/extend-forward-after-set-base-and-extent-expected.txt: Added.
  • editing/selection/extend-forward-after-set-base-and-extent.html: Added.
  • platform/mac/editing/selection/5195166-1-expected.txt:

2010-07-07 Ojan Vafai <ojan@chromium.org>

Reviewed by Darin Adler.

Regression: Selection anchor + focus swap when arrow keys after setBaseAndExtent
https://bugs.webkit.org/show_bug.cgi?id=32605

Only have selections be non-directional when they are set via the mouse.
Otherwise, all selections are directional.

Test: editing/selection/extend-forward-after-set-base-and-extent.html

  • WebCore.base.exp:
  • editing/SelectionController.cpp: (WebCore::SelectionController::setSelection):
  • editing/SelectionController.h: (WebCore::SelectionController::setSelection):
  • page/EventHandler.cpp: (WebCore::EventHandler::selectClosestWordFromMouseEvent): (WebCore::EventHandler::selectClosestWordOrLinkFromMouseEvent): (WebCore::EventHandler::handleMousePressEventTripleClick): (WebCore::EventHandler::handleMousePressEventSingleClick): (WebCore::EventHandler::updateSelectionForMouseDrag):
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r62810 r62816  
     12010-07-07  Ojan Vafai  <ojan@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Regression: Selection anchor + focus swap when arrow keys after setBaseAndExtent
     6        https://bugs.webkit.org/show_bug.cgi?id=32605
     7
     8        * editing/selection/5195166-1.html:
     9        * editing/selection/extend-forward-after-set-base-and-extent-expected.txt: Added.
     10        * editing/selection/extend-forward-after-set-base-and-extent.html: Added.
     11        * platform/mac/editing/selection/5195166-1-expected.txt:
     12
    1132010-07-05  Gavin Barraclough  <barraclough@apple.com>
    214
  • trunk/LayoutTests/editing/selection/5195166-1.html

    r56567 r62816  
    11<p>This tests for a bug where extending a selection created with the mouse would blow it away before extending it.</p>
    2 <div id="div" contenteditable="true">There should be six characters selected in this sentence on Mac and four characters selected on Win/Linux.</div>
     2<div id="div" contenteditable="true">There <span id="select" style="color:green">should be</span> six characters selected in this sentence on Mac and four characters selected on Win/Linux.</div>
    33<ul id="console"></ul>
    44<script>
    5 function log(str) {
     5function log(str)
     6{
    67    console = document.getElementById("console");
    78    li = document.createElement("li");
     
    1011    li.appendChild(text);
    1112}
    12 if (window.layoutTestController) {
    13     layoutTestController.dumpAsText()
    1413
    15     var text = document.getElementById("div").firstChild;
    16     var selection = window.getSelection();
     14function runTest(platform, expectedText)
     15{
     16    layoutTestController.setEditingBehavior(platform);
    1717   
    18     // FIXME: m_lastChangeWasHorizontalExtension isn't cleared in several places
    19     // where it should be, when opening a new document for example.
    20     selection.setPosition(text, 0);
    21     selection.modify("move", "forward", "character");
    22    
    23     selection.setBaseAndExtent(text, 3 + 5, text, 3);
     18    var target = document.getElementById('select');
     19    var startX = target.offsetLeft + target.offsetWidth;
     20    var y = target.offsetTop + target.offsetHeight / 2;
     21    var endX = target.offsetLeft;
     22
     23    // Select all the green text using the mouse.
     24    // Use a word-granularity selection to avoid eventSender bug.
     25    // Using just a single-click would not act is if the initial
     26    // mouseDown was at (endX, y), resulting in a collapsed selection.
     27    eventSender.mouseMoveTo(startX, y);
     28    eventSender.mouseDown();
     29    eventSender.mouseUp();
     30    eventSender.mouseDown();
     31    eventSender.mouseMoveTo(endX, y);
     32    eventSender.mouseUp();
    2433    // Extending this 5 character selection will select 6 characters on mac,
    2534    // but shrink the selection on win/linux.
    2635    layoutTestController.execCommand("MoveForwardAndModifySelection");
    2736    // Extending it in this way flips the anchor and the focus on Mac.
    28     var onMacPlatform = navigator.userAgent.search(/\bMac OS X\b/) != -1;
    29     if (onMacPlatform && selection.focusOffset - selection.anchorOffset == 6 ||
    30         !onMacPlatform && selection.anchorOffset - selection.focusOffset == 4)
     37    var selectedText = window.getSelection().toString();
     38    if (selectedText != expectedText)
     39        log("Failure: Selected text was \"" + selectedText + "\" and should be \"" + expectedText + "\"");
     40    else
    3141        log("Success");
    32     else
    33         log("Failure: Selection isn't the right size. anchorOffset=" + selection.anchorOffset +
    34             " focusOffset=" + selection.focusOffset + " onMacPlatform: " + onMacPlatform);
    35 } else
    36     log ("Failure: This test cannot be run manually.")
     42}
     43
     44if (window.layoutTestController) {
     45    layoutTestController.dumpAsText()
     46    runTest('mac', 'should be s');
     47    runTest('win', 'hould be ');
     48} else {
     49    log("Failure: To test manually, select the green text " +
     50        "starting at the end via double-click (i.e. word granularity), then shift+right-arrow. " +
     51        "On Win/Linux you should see 'hould be ' selected. On Mac, you should see 'should be s' selected." +
     52        "There's currently a bug that selects the space " +
     53        "after 'should be' during the initial selection (https://bugs.webkit.org/show_bug.cgi?id=36256). " +
     54        "Once that's fixed, it the final selected text should be 'should be ' on Mac and 'hould be' on Win/Linux.")
     55}
    3756</script>
  • trunk/LayoutTests/platform/mac/editing/selection/5195166-1-expected.txt

    r56567 r62816  
    33There should be six characters selected in this sentence on Mac and four characters selected on Win/Linux.
    44Success
     5Success
  • trunk/WebCore/ChangeLog

    r62815 r62816  
     12010-07-07  Ojan Vafai  <ojan@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Regression: Selection anchor + focus swap when arrow keys after setBaseAndExtent
     6        https://bugs.webkit.org/show_bug.cgi?id=32605
     7
     8        Only have selections be non-directional when they are set via the mouse.
     9        Otherwise, all selections are directional.
     10
     11        Test: editing/selection/extend-forward-after-set-base-and-extent.html
     12
     13        * WebCore.base.exp:
     14        * editing/SelectionController.cpp:
     15        (WebCore::SelectionController::setSelection):
     16        * editing/SelectionController.h:
     17        (WebCore::SelectionController::setSelection):
     18        * page/EventHandler.cpp:
     19        (WebCore::EventHandler::selectClosestWordFromMouseEvent):
     20        (WebCore::EventHandler::selectClosestWordOrLinkFromMouseEvent):
     21        (WebCore::EventHandler::handleMousePressEventTripleClick):
     22        (WebCore::EventHandler::handleMousePressEventSingleClick):
     23        (WebCore::EventHandler::updateSelectionForMouseDrag):
     24
    1252010-07-08  Antonio Gomes  <tonikitoo@webkit.org>
    226
  • trunk/WebCore/WebCore.exp.in

    r62809 r62816  
    404404__ZN7WebCore19InspectorController34inspectorStartsAttachedSettingNameEv
    405405__ZN7WebCore19SelectionController10setFocusedEb
    406 __ZN7WebCore19SelectionController12setSelectionERKNS_16VisibleSelectionEbbbNS0_19CursorAlignOnScrollENS_15TextGranularityE
     406__ZN7WebCore19SelectionController12setSelectionERKNS_16VisibleSelectionEbbbNS0_19CursorAlignOnScrollENS_15TextGranularityENS_20DirectionalityPolicyE
    407407__ZN7WebCore19SelectionController16setSelectedRangeEPNS_5RangeENS_9EAffinityEb
    408408__ZN7WebCore19SelectionController5clearEv
  • trunk/WebCore/editing/SelectionController.cpp

    r62693 r62816  
    108108}
    109109
    110 void SelectionController::setSelection(const VisibleSelection& s, bool closeTyping, bool clearTypingStyle, bool userTriggered, CursorAlignOnScroll align, TextGranularity granularity)
     110void SelectionController::setSelection(const VisibleSelection& s, bool closeTyping, bool clearTypingStyle, bool userTriggered, CursorAlignOnScroll align, TextGranularity granularity, DirectionalityPolicy directionalityPolicy)
    111111{
    112112    m_granularity = granularity;
    113113
    114     setIsDirectional(false);
     114    setIsDirectional(directionalityPolicy == MakeDirectionalSelection);
    115115
    116116    if (m_isDragCaretController) {
  • trunk/WebCore/editing/SelectionController.h

    r60463 r62816  
    4242class VisiblePosition;
    4343
     44enum DirectionalityPolicy { MakeNonDirectionalSelection, MakeDirectionalSelection };
     45
    4446class SelectionController : public Noncopyable {
    4547public:
     
    6365
    6466    const VisibleSelection& selection() const { return m_selection; }
    65     void setSelection(const VisibleSelection&, bool closeTyping = true, bool clearTypingStyle = true, bool userTriggered = false, CursorAlignOnScroll = AlignCursorOnScrollIfNeeded, TextGranularity = CharacterGranularity);
    66     void setSelection(const VisibleSelection& selection, TextGranularity granularity) { setSelection(selection, true, true, false, AlignCursorOnScrollIfNeeded, granularity); }
     67    void setSelection(const VisibleSelection&, bool closeTyping = true, bool clearTypingStyle = true, bool userTriggered = false, CursorAlignOnScroll = AlignCursorOnScrollIfNeeded, TextGranularity = CharacterGranularity, DirectionalityPolicy = MakeDirectionalSelection);
     68    void setSelection(const VisibleSelection& selection, TextGranularity granularity, DirectionalityPolicy directionality = MakeDirectionalSelection) { setSelection(selection, true, true, false, AlignCursorOnScrollIfNeeded, granularity, directionality); }
    6769    bool setSelectedRange(Range*, EAffinity, bool closeTyping);
    6870    void selectAll();
  • trunk/WebCore/page/EventHandler.cpp

    r62780 r62816  
    260260       
    261261        if (m_frame->shouldChangeSelection(newSelection))
    262             m_frame->selection()->setSelection(newSelection, granularity);
     262            m_frame->selection()->setSelection(newSelection, granularity, MakeNonDirectionalSelection);
    263263    }
    264264}
     
    285285
    286286        if (m_frame->shouldChangeSelection(newSelection))
    287             m_frame->selection()->setSelection(newSelection, granularity);
     287            m_frame->selection()->setSelection(newSelection, granularity, MakeNonDirectionalSelection);
    288288    }
    289289}
     
    330330   
    331331    if (m_frame->shouldChangeSelection(newSelection))
    332         m_frame->selection()->setSelection(newSelection, granularity);
     332        m_frame->selection()->setSelection(newSelection, granularity, MakeNonDirectionalSelection);
    333333
    334334    return true;
     
    397397   
    398398    if (m_frame->shouldChangeSelection(newSelection))
    399         m_frame->selection()->setSelection(newSelection, granularity);
     399        m_frame->selection()->setSelection(newSelection, granularity, MakeNonDirectionalSelection);
    400400
    401401    return true;
     
    634634    if (m_frame->shouldChangeSelection(newSelection)) {
    635635        m_frame->selection()->setIsDirectional(false);
    636         m_frame->selection()->setSelection(newSelection, m_frame->selectionGranularity());
     636        m_frame->selection()->setSelection(newSelection, m_frame->selectionGranularity(), MakeNonDirectionalSelection);
    637637    }
    638638}
Note: See TracChangeset for help on using the changeset viewer.