Bug 55552

Summary: Text selection changes unexpectedly when dragging out of the <input>
Product: WebKit Reporter: Peter Kasting <pkasting>
Component: TextAssignee: Alice Boxhall <aboxhall>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, caseq, commit-queue, dglazkov, jparent, mitz, noel.gordon, ojan, patrick, rniwa
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: All   
Bug Depends on: 57921, 57923    
Bug Blocks: 52986    
Attachments:
Description Flags
test case
none
Patch
none
Patch
none
test for the bug 52986
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Peter Kasting 2011-03-01 22:49:02 PST
Visit http://www.shacknews.com/search?type=4 .  Type anything into the "Search for:" box.  Now click down in the middle of your text, drag left to select the beginning, and keep dragging out of the <input> and into the page to the left.  Also try moving your mouse up and down at various x coordinates.

I expect the selection to be pretty stable, not unexpectedly reverse itself half the time.

I could swear I filed this already, but I can't find it.  In any case this happens on a lot of sites and drive me bananas.  Please tell me someone has time to look into it :(
Comment 1 noel gordon 2011-03-14 17:02:59 PDT
test case: click in the middle and drag out to the right to see the unexpected selection change.
Comment 2 noel gordon 2011-03-14 17:04:22 PDT
Created attachment 85744 [details]
test case
Comment 3 Alice Boxhall 2011-03-17 17:57:57 PDT
I've been digging around this a little, and it seems like the problem might be related to the fact that the contentHeight and contentWidth of the input field are (incorrectly?) set to 0 and 1008, respectively. This causes RenderBox::positionForPoint to incorrectly calculate the relative position of the mouse cursor once the mouse drags out of the input field.
Comment 4 Alice Boxhall 2011-03-31 23:45:30 PDT
Created attachment 87828 [details]
Patch
Comment 5 Alice Boxhall 2011-03-31 23:48:24 PDT
First pass patch; feedback welcome.

After a few blind alleys it turned out to be simplest to just modify updateSelectionForMouseDrag to translate the selection end-point into a local point within the editable element, in the case where the mouse had dragged out of it, since the selection can't extend beyond the editable element anyway.
Comment 6 mitz 2011-03-31 23:59:07 PDT
I think this is bug 12593.
Comment 7 mitz 2011-03-31 23:59:16 PDT
I think this is bug 12593.
Comment 8 Peter Kasting 2011-04-01 09:44:33 PDT
(In reply to comment #6)
> I think this is bug 12593.

Could be.  The description there is a little vague and it lacks the attachments from the Radar bug.  If they're the same, maybe that bug should be duped against this since there's a patch here?  I dunno.
Comment 9 Ryosuke Niwa 2011-04-02 08:30:21 PDT
Comment on attachment 87828 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=87828&action=review

> LayoutTests/editing/selection/resources/select-out-of-floated-editable.js:17
> +} else

This else clause needs to have curly brackets.

> Source/WebCore/page/EventHandler.cpp:640
> +    IntPoint realLocalPoint(localPoint);

I don't think realLocalPoint is a descriptive name.  What does "real" mean?  Also, I think we normally use assignment operator rather than copy constructor when declaring a local variable.  So the preferred way of writing this will be:
IntPoint realLocalPoint = localPoint.

> Source/WebCore/page/EventHandler.cpp:654
> +    if (editableElement && !editableElement->contains(targetNode)) {
> +        targetNode = editableElement;
>  
> -    // Don't modify the selection if we're not on a node.
> -    if (targetPosition.isNull())
> -        return;
> +        FloatPoint absolutePoint = targetRenderer->localToAbsolute(FloatPoint(realLocalPoint));
> +        
> +        targetRenderer = targetNode->renderer();
> +        if (!targetRenderer)
> +            return;
>  
> +        realLocalPoint = roundedIntPoint(targetRenderer->absoluteToLocal(absolutePoint));
> +    }

It's odd that we fix localPoint in updateSelectionForMouseDrag rather than in its call site.  We should fix it in handleMouseDraggedEvent instead.

> Source/WebCore/page/EventHandler.cpp:658
> +    VisiblePosition targetPosition(targetRenderer->positionForPoint(realLocalPoint));

Ditto about copy constructor.
Comment 10 Ryosuke Niwa 2011-04-02 08:37:15 PDT
Comment on attachment 87828 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=87828&action=review

r- because you're missing LayoutTests/ChangeLog

> LayoutTests/editing/selection/resources/select-out-of-floated-editable.js:14
> +    eventSender.mouseDown();
> +    x = floatedEditable.offsetLeft + floatedEditable.offsetWidth + 5;
> +    eventSender.mouseMoveTo(x, y);
> +    eventSender.mouseUp();

I believe you need to add leapForward between mouseDown and mouseUp or otherwise this test becomes flaky.

> LayoutTests/editing/selection/resources/select-out-of-floated-editable.js:27
> +    return el.isContentEditable ? window.getSelection().baseOffset : el.selectionStart;

Please do not use arbitrary abbreviations like "el".

> LayoutTests/editing/selection/select-out-of-floated-contenteditable.html:15
> +To test manually, drag from the middle of the editable div to the
> +right, into the non-floated text. The selection should go to the end
> +of the input element and not jump to the beginning.

Are you trying to fit everything in 80 columns? No need to do that here.

> LayoutTests/editing/selection/select-out-of-floated-contenteditable.html:19
> +<p id="result">
> +</p>
> +<pre id="console"></pre>

Can't we have just one pre/p?  It seems silly to have two separate elements for automated / manual test.

> LayoutTests/editing/selection/select-out-of-floated-contenteditable.html:20
> +<script type="text/javascript" src="resources/select-out-of-floated-editable.js"></script>

We don't normally specify type attribute.

> LayoutTests/editing/selection/select-out-of-floated-input.html:22
> +<p id="result">
> +</p>
> +<pre id="console"></pre>
> +<script type="text/javascript" src="resources/select-out-of-floated-editable.js"></script>

Ditto.

> LayoutTests/editing/selection/select-out-of-floated-textarea.html:22
> +<p id="result">
> +</p>
> +<pre id="console"></pre>
> +<script type="text/javascript" src="resources/select-out-of-floated-editable.js"></script>

Ditto.
Comment 11 Alice Boxhall 2011-04-03 17:30:18 PDT
Created attachment 88024 [details]
Patch
Comment 12 Alice Boxhall 2011-04-03 17:31:21 PDT
(In reply to comment #9)
> (From update of attachment 87828 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=87828&action=review
> 
> > LayoutTests/editing/selection/resources/select-out-of-floated-editable.js:17
> > +} else
> 
> This else clause needs to have curly brackets.

Done.

> > Source/WebCore/page/EventHandler.cpp:640
> > +    IntPoint realLocalPoint(localPoint);
> 
> I don't think realLocalPoint is a descriptive name.  What does "real" mean?  Also, I think we normally use assignment operator rather than copy constructor when declaring a local variable.  So the preferred way of writing this will be:
> IntPoint realLocalPoint = localPoint.

Renamed to finalPoint, and used assignment.

> > Source/WebCore/page/EventHandler.cpp:654
> > +    if (editableElement && !editableElement->contains(targetNode)) {
> > +        targetNode = editableElement;
> >  
> > -    // Don't modify the selection if we're not on a node.
> > -    if (targetPosition.isNull())
> > -        return;
> > +        FloatPoint absolutePoint = targetRenderer->localToAbsolute(FloatPoint(realLocalPoint));
> > +        
> > +        targetRenderer = targetNode->renderer();
> > +        if (!targetRenderer)
> > +            return;
> >  
> > +        realLocalPoint = roundedIntPoint(targetRenderer->absoluteToLocal(absolutePoint));
> > +    }
> 
> It's odd that we fix localPoint in updateSelectionForMouseDrag rather than in its call site.  We should fix it in handleMouseDraggedEvent instead.

I don't understand why... the point only needs to be re-interpreted in the case where a selection is being updated and the mouse has been dragged outside of the editable element in which it began. To me it seems like a good fit to do this in the updateSelectionForMouseDrag function. Also, handleMouseDraggedEvent has two branches which call updateSelectionForMouseDrag, with two different points as arguments, so I'd need to modify both of them.


> > Source/WebCore/page/EventHandler.cpp:658
> > +    VisiblePosition targetPosition(targetRenderer->positionForPoint(realLocalPoint));
> 
> Ditto about copy constructor.

Done.


(In reply to comment #10)
> (From update of attachment 87828 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=87828&action=review
> 
> r- because you're missing LayoutTests/ChangeLog
> 
> > LayoutTests/editing/selection/resources/select-out-of-floated-editable.js:14
> > +    eventSender.mouseDown();
> > +    x = floatedEditable.offsetLeft + floatedEditable.offsetWidth + 5;
> > +    eventSender.mouseMoveTo(x, y);
> > +    eventSender.mouseUp();
> 
> I believe you need to add leapForward between mouseDown and mouseUp or otherwise this test becomes flaky.

Why is that? I haven't observed any flaky behaviour in running it.

> > LayoutTests/editing/selection/resources/select-out-of-floated-editable.js:27
> > +    return el.isContentEditable ? window.getSelection().baseOffset : el.selectionStart;
> 
> Please do not use arbitrary abbreviations like "el".

Ok.

> > LayoutTests/editing/selection/select-out-of-floated-contenteditable.html:15
> > +To test manually, drag from the middle of the editable div to the
> > +right, into the non-floated text. The selection should go to the end
> > +of the input element and not jump to the beginning.
> 
> Are you trying to fit everything in 80 columns? No need to do that here.

I find it easier to read wrapped text than text that flows off the page; is there a preferable width to wrap it to?

> > LayoutTests/editing/selection/select-out-of-floated-contenteditable.html:19
> > +<p id="result">
> > +</p>
> > +<pre id="console"></pre>
> 
> Can't we have just one pre/p?  It seems silly to have two separate elements for automated / manual test.

I think this simplifies separating out the success/fail handling and the logging. The result div is used in the manual test as well (although obviously it's not 100% reliable if you don't follow the written instructions).

> > LayoutTests/editing/selection/select-out-of-floated-contenteditable.html:20
> > +<script type="text/javascript" src="resources/select-out-of-floated-editable.js"></script>
> 
> We don't normally specify type attribute.

Ok.

> > LayoutTests/editing/selection/select-out-of-floated-input.html:22
> > +<p id="result">
> > +</p>
> > +<pre id="console"></pre>
> > +<script type="text/javascript" src="resources/select-out-of-floated-editable.js"></script>
> 
> Ditto.

Done.

> > LayoutTests/editing/selection/select-out-of-floated-textarea.html:22
> > +<p id="result">
> > +</p>
> > +<pre id="console"></pre>
> > +<script type="text/javascript" src="resources/select-out-of-floated-editable.js"></script>
> 
> Ditto.

Done.
Comment 13 Ryosuke Niwa 2011-04-03 22:20:20 PDT
(In reply to comment #12)
> > > Source/WebCore/page/EventHandler.cpp:654
> > It's odd that we fix localPoint in updateSelectionForMouseDrag rather than in its call site.  We should fix it in handleMouseDraggedEvent instead.
> 
> I don't understand why... the point only needs to be re-interpreted in the case where a selection is being updated and the mouse has been dragged outside of the editable element in which it began. To me it seems like a good fit to do this in the updateSelectionForMouseDrag function. Also, handleMouseDraggedEvent has two branches which call updateSelectionForMouseDrag, with two different points as arguments, so I'd need to modify both of them.

The problem is that updateSelectionForMouseDrag explicitly takes a node and localPoint.  It's a really bad API to let a function take a node and a local point and then modify the node & local point inside the function.  So much of editing code has been hacked around like this and it really reduces the readability and maintainability of code because when I see the calls to updateSelectionForMouseDrag, I'd assume that selection is updated with respect to the node and local rect I passed in.

On my second thought, I think the best way to resolve this is to change the signature of updateSelectionForMouseDrag to MouseEventWithHitTestResults(HitTestResult).  That way, we're not explicitly passing a node & localRect so it doesn't look magical.

> > > LayoutTests/editing/selection/resources/select-out-of-floated-editable.js:14
> > > +    eventSender.mouseDown();
> > > +    x = floatedEditable.offsetLeft + floatedEditable.offsetWidth + 5;
> > > +    eventSender.mouseMoveTo(x, y);
> > > +    eventSender.mouseUp();
> > 
> > I believe you need to add leapForward between mouseDown and mouseUp or otherwise this test becomes flaky.
> 
> Why is that? I haven't observed any flaky behaviour in running it.

You may not observe flakiness locally but some bots might.  Sadly, many existing tests do this and are flaky on some bots :(

> > > LayoutTests/editing/selection/select-out-of-floated-contenteditable.html:15
> > > +To test manually, drag from the middle of the editable div to the
> > > +right, into the non-floated text. The selection should go to the end
> > > +of the input element and not jump to the beginning.
> > 
> > Are you trying to fit everything in 80 columns? No need to do that here.
> 
> I find it easier to read wrapped text than text that flows off the page; is there a preferable width to wrap it to?

Historically, I don't think we ever wrap text inside HTML files (except maybe at the end of sentence).

> > > LayoutTests/editing/selection/select-out-of-floated-contenteditable.html:19
> > > +<p id="result">
> > > +</p>
> > > +<pre id="console"></pre>
> > 
> > Can't we have just one pre/p?  It seems silly to have two separate elements for automated / manual test.
> 
> I think this simplifies separating out the success/fail handling and the logging. The result div is used in the manual test as well (although obviously it's not 100% reliable if you don't follow the written instructions).

Huh... it seems odd to have these two elements when only either one is used.  Can we auto-generate them instead then?

By the way, this bug might be a duplicate of the bug 52986.
Comment 14 Ryosuke Niwa 2011-04-03 22:21:16 PDT
Comment on attachment 88024 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=88024&action=review

> Source/WebCore/page/EventHandler.cpp:655
> -    VisiblePosition targetPosition(targetRenderer->positionForPoint(localPoint));
> +    IntPoint finalPoint = localPoint;
> +    
> +    VisibleSelection newSelection = m_frame->selection()->selection();
> +    Element* editableElement = newSelection.rootEditableElement();
> +    if (editableElement && !editableElement->contains(targetNode)) {
> +        targetNode = editableElement;
>  
> -    // Don't modify the selection if we're not on a node.
> -    if (targetPosition.isNull())
> -        return;
> +        FloatPoint absolutePoint = targetRenderer->localToAbsolute(FloatPoint(finalPoint));
> +        
> +        targetRenderer = targetNode->renderer();
> +        if (!targetRenderer)
> +            return;
>  
> +        finalPoint = roundedIntPoint(targetRenderer->absoluteToLocal(absolutePoint));
> +    }
> +    

Please extract this code as a function.
Comment 15 Ryosuke Niwa 2011-04-04 23:02:24 PDT
*** Bug 52986 has been marked as a duplicate of this bug. ***
Comment 16 Ryosuke Niwa 2011-04-05 02:11:08 PDT
Created attachment 88192 [details]
test for the bug 52986

Hi Alice, Here's DRT test for the bug 52986. Please add it to your patch.
Comment 17 Ryosuke Niwa 2011-04-05 02:12:20 PDT
When I was writing this test, I realized that the bug 52986 does not reproduce when there's non-editable content above or below the editable div. I'd greatly appreciate it if you could figure out why that's the case.
Comment 18 Ojan Vafai 2011-04-10 17:07:23 PDT
(In reply to comment #17)
> When I was writing this test, I realized that the bug 52986 does not reproduce when there's non-editable content above or below the editable div. I'd greatly appreciate it if you could figure out why that's the case.

This bug doesn't look like a duplicate to me. Although, it's not clear to me what's causing bug 52986. Have you confirmed it's fixed by Alice's patch? We shouldn't dupe this until we're sure it's the same root cause.
Comment 19 Ojan Vafai 2011-04-10 17:09:59 PDT
Comment on attachment 88024 [details]
Patch

Removing this from the review queue per the above comment and till bug 57923 gets committed.
Comment 20 Alice Boxhall 2011-04-10 17:10:32 PDT
(In reply to comment #19)
> (From update of attachment 88024 [details])
> Removing this from the review queue per the above comment and till bug 57923 gets committed.

I'm not sure that it's a duplicate, but both Ryosuke and Noel have verified that it's fixed by this change.
Comment 21 Ryosuke Niwa 2011-04-10 17:38:53 PDT
(In reply to comment #18)
> (In reply to comment #17)
> > When I was writing this test, I realized that the bug 52986 does not reproduce when there's non-editable content above or below the editable div. I'd greatly appreciate it if you could figure out why that's the case.
> 
> This bug doesn't look like a duplicate to me. Although, it's not clear to me what's causing bug 52986. Have you confirmed it's fixed by Alice's patch? We shouldn't dupe this until we're sure it's the same root cause.

It is a duplicate.  We're not passing a node inside editable region to the SelectionController.  The reason we can't reproduce this bug when there are content above or blow the editable region is probably due to the canonicalization.
Comment 22 Ryosuke Niwa 2011-04-10 17:39:28 PDT
(In reply to comment #21)
> It is a duplicate.  We're not passing a node inside editable region to the SelectionController.  The reason we can't reproduce this bug when there are content above or blow the editable region is probably due to the canonicalization.

Or rather how we fix up positions in SelectionController when the root editable element doesn't match.
Comment 23 Alice Boxhall 2011-04-10 23:32:18 PDT
Created attachment 88970 [details]
Patch
Comment 24 Ryosuke Niwa 2011-04-11 10:39:10 PDT
Comment on attachment 88970 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=88970&action=review

Okay, I like the patch in general but there are few nits I want you to address before landing this patch. I'd say r- for now given that you're not a committer yet.

> LayoutTests/ChangeLog:38
> +
> +2011-04-03  Alice Boxhall  <aboxhall@chromium.org>
> +
> +        Reviewed by NOBODY (OOPS!).
> +
> +        Text selection changes unexpectedly when dragging out of the &lt;input&gt;
> +        https://bugs.webkit.org/show_bug.cgi?id=55552
> +
> +        Tests that dragging outside of a contenteditable, input or textarea selects to the end of the
> +        element, rather than jumping back to the beginning.
> +
> +        * editing/selection/resources/select-out-of-floated-editable.js: Added.
> +        * editing/selection/select-out-of-floated-contenteditable-expected.txt: Added.
> +        * editing/selection/select-out-of-floated-contenteditable.html: Added.
> +        * editing/selection/select-out-of-floated-input-expected.txt: Added.
> +        * editing/selection/select-out-of-floated-input.html: Added.
> +        * editing/selection/select-out-of-floated-textarea-expected.txt: Added.
> +        * editing/selection/select-out-of-floated-textarea.html: Added.
> +

You have two change log entires. Please fix.

> LayoutTests/editing/selection/resources/select-out-of-floated-editable.js:12
> +    x = floatedEditable.offsetLeft + floatedEditable.offsetWidth + 5;

You need to call leap forward here.

> LayoutTests/editing/selection/resources/select-out-of-floated-editable.js:37
> +                                                      : floatedEditable.value;

I don't think we normally align after tertiary operator like this.  Please do:
var inputText = floatedEditable.isContentEditable ? floatedEditable.textContent
    : floatedEditable.value;

> LayoutTests/editing/selection/select-out-of-floated-contenteditable.html:5
> +<style>
> +  div { float: left; }
> +  p { padding-top: 1em; }
> +</style>

I don't know why we need to specify these as style rules. p already has some margins and you can specify float: left in the inline style declaration.

> LayoutTests/editing/selection/select-out-of-floated-contenteditable.html:19
> +<p id="result">
> +</p>
> +<pre id="console"></pre>

Nit: It seems odd that you have <p> and </p> on a separate line even though it's empty and right beneath it, you have <pre></pre>.

> Source/WebCore/ChangeLog:15
> +        (WebCore::targetPositionForSelectionEndpoint): When dragging from an editable element, check that
> +            the endpoint is not outside the element. If it is, translate the point into a local point within the
> +            editable element.

Nit: I don't think we intend in change log like this. Please align the start of each line to (. Also, it's odd that line break exists between an article and the noun that immediately follows it. We usually truncate a line at more natural places between "within" and "the" or between "local point" and "within"

> Source/WebCore/page/EventHandler.cpp:634
> +        // If selecting out of an editable element, translate the endpoint into a local point within the 
> +        // editable element, to avoid confusing behaviour which can occur when dragging into a node which is
> +        // earlier in the DOM.

Nit: this comment is too verbose.  We can either omit the comment entirely or simply state that we're respecting editing boundary.
We certainly don't need to say that we're translating the endpoint to a local point within the editable element because that's self-evident from the code.
"avoid confusing behavior when dragging out of an editable element" will be better but we need to be a little more specific than "confusing".
Comment 25 Peter Kasting 2011-04-11 10:56:07 PDT
Comment on attachment 88970 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=88970&action=review

>> LayoutTests/editing/selection/resources/select-out-of-floated-editable.js:37
>> +                                                      : floatedEditable.value;
> 
> I don't think we normally align after tertiary operator like this.  Please do:
> var inputText = floatedEditable.isContentEditable ? floatedEditable.textContent
>     : floatedEditable.value;

I have actually seen this style.  However, I think breaking after the '?', or not breaking at all, might be best.
Comment 26 Alice Boxhall 2011-04-11 22:30:24 PDT
Created attachment 89157 [details]
Patch
Comment 27 Ryosuke Niwa 2011-04-11 22:39:01 PDT
Comment on attachment 89157 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=89157&action=review

> Source/WebCore/page/EventHandler.cpp:633
> +        // Avoid selection changing direction when dragging out of an editable element into
> +        // an element which comes earlier in the DOM.

Mn... this is the description of the bug you're solving but I don't think that'll necessarily address the all cases where we reach this code path.  i.e. I think you're solving more general problem here than what comment explains and that's kind of misleading.
Comment 28 Alice Boxhall 2011-04-11 22:59:56 PDT
(In reply to comment #27)
> (From update of attachment 89157 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=89157&action=review
> 
> > Source/WebCore/page/EventHandler.cpp:633
> > +        // Avoid selection changing direction when dragging out of an editable element into
> > +        // an element which comes earlier in the DOM.
> 
> Mn... this is the description of the bug you're solving but I don't think that'll necessarily address the all cases where we reach this code path.  i.e. I think you're solving more general problem here than what comment explains and that's kind of misleading.

True, although I don't think it suffices to say "respect editing boundaries" either, since that happens elsewhere. Will have a think -- happy to take the comment off altogether, but I think it's worth clarifying why this is necessary here.
Comment 29 Alice Boxhall 2011-04-11 23:06:30 PDT
(In reply to comment #28)
> (In reply to comment #27)
> > (From update of attachment 89157 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=89157&action=review
> > 
> > > Source/WebCore/page/EventHandler.cpp:633
> > > +        // Avoid selection changing direction when dragging out of an editable element into
> > > +        // an element which comes earlier in the DOM.
> > 
> > Mn... this is the description of the bug you're solving but I don't think that'll necessarily address the all cases where we reach this code path.  i.e. I think you're solving more general problem here than what comment explains and that's kind of misleading.
> 
> True, although I don't think it suffices to say "respect editing boundaries" either, since that happens elsewhere. Will have a think -- happy to take the comment off altogether, but I think it's worth clarifying why this is necessary here.

How about:
    // When dragging out of an editable element, the selection cannot cross the editing boundary,                                                              
        // so it doesn't make sense to calculate a selection endpoint outside the editable element.
Comment 30 Ryosuke Niwa 2011-04-11 23:50:36 PDT
Comment on attachment 89157 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=89157&action=review

>>>> Source/WebCore/page/EventHandler.cpp:633
>>>> +        // an element which comes earlier in the DOM.
>>> 
>>> Mn... this is the description of the bug you're solving but I don't think that'll necessarily address the all cases where we reach this code path.  i.e. I think you're solving more general problem here than what comment explains and that's kind of misleading.
>> 
>> True, although I don't think it suffices to say "respect editing boundaries" either, since that happens elsewhere. Will have a think -- happy to take the comment off altogether, but I think it's worth clarifying why this is necessary here.
> 
> How about:
>     // When dragging out of an editable element, the selection cannot cross the editing boundary,                                                              
>         // so it doesn't make sense to calculate a selection endpoint outside the editable element.

okay, that explains why we don't use the old end point but doesn't explain why we use editable root as new end point.
I'd say something along the line of "use the root editable element as the end point when dragging out of the element because selection cannot cross the editing boundary."
To be more explicitly, I say something like working around issues in adjustSelectionToAvoidCrossingEditingBoundaries but then you need to start talking about how it affects selection, etc... and it'll be too verbose again.
Comment 31 Ojan Vafai 2011-04-12 11:22:03 PDT
(In reply to comment #30)
> To be more explicitly, I say something like working around issues in adjustSelectionToAvoidCrossingEditingBoundaries but then you need to start talking about how it affects selection, etc... and it'll be too verbose again.

The bug this patch was originally for isn't about adjustSelectionToAvoidCrossingEditingBoundaries. It's that there are cases where we set the selection at the start of the container node when there are floats involved instead of at the end. You get similarly weird selections if you ignore editing, but in the absence of editing, there's nothing better we can do (and in fact we match Firefox).

Alice's last comments seems fine to me.
Comment 32 Ryosuke Niwa 2011-04-12 11:36:58 PDT
(In reply to comment #31)
> The bug this patch was originally for isn't about adjustSelectionToAvoidCrossingEditingBoundaries. It's that there are cases where we set the selection at the start of the container node when there are floats involved instead of at the end. You get similarly weird selections if you ignore editing, but in the absence of editing, there's nothing better we can do (and in fact we match Firefox).

Sure, but I don't think it's important what this bug or patch was for because the comment is added to the code and not to the change log entry.  Having said that, I'm fine with Alice's last comment as well (in the sense that I don't mind r+ing it) although I still feel like we can improve it more.
Comment 33 Alice Boxhall 2011-04-12 18:09:03 PDT
Created attachment 89322 [details]
Patch
Comment 34 Ryosuke Niwa 2011-04-12 18:19:55 PDT
Comment on attachment 89322 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=89322&action=review

> Source/WebCore/page/EventHandler.cpp:638
> +        FloatPoint absolutePoint = targetNode->renderer()->localToAbsolute(FloatPoint(selectionEndPoint));
> +
> +        selectionEndPoint = roundedIntPoint(selectionEndNode->renderer()->absoluteToLocal(absolutePoint));
> +    }
> +
> +    return selectionEndNode->renderer()->positionForPoint(selectionEndPoint);

Oops, these nodes may not have renderers.
Comment 35 Alice Boxhall 2011-04-13 21:04:39 PDT
Created attachment 89526 [details]
Patch
Comment 36 Alice Boxhall 2011-04-13 21:07:09 PDT
(In reply to comment #34)
> (From update of attachment 89322 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=89322&action=review
> 
> > Source/WebCore/page/EventHandler.cpp:638
> > +        FloatPoint absolutePoint = targetNode->renderer()->localToAbsolute(FloatPoint(selectionEndPoint));
> > +
> > +        selectionEndPoint = roundedIntPoint(selectionEndNode->renderer()->absoluteToLocal(absolutePoint));
> > +    }
> > +
> > +    return selectionEndNode->renderer()->positionForPoint(selectionEndPoint);
> 
> Oops, these nodes may not have renderers.

Fixed.

(In reply to comment #32)
> (In reply to comment #31)
> > The bug this patch was originally for isn't about adjustSelectionToAvoidCrossingEditingBoundaries. It's that there are cases where we set the selection at the start of the container node when there are floats involved instead of at the end. You get similarly weird selections if you ignore editing, but in the absence of editing, there's nothing better we can do (and in fact we match Firefox).
> 
> Sure, but I don't think it's important what this bug or patch was for because the comment is added to the code and not to the change log entry.  Having said that, I'm fine with Alice's last comment as well (in the sense that I don't mind r+ing it) although I still feel like we can improve it more.

Comment removed.
Comment 37 Ryosuke Niwa 2011-04-13 21:20:50 PDT
Comment on attachment 89526 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=89526&action=review

> Source/WebCore/page/EventHandler.cpp:641
> +    return selectionEndNode->renderer()->positionForPoint(selectionEndPoint);

You need to check renderer here as well.

> Source/WebCore/page/EventHandler.cpp:658
>      if (!targetRenderer)
>          return;

You should remove this early exit.
Comment 38 Alice Boxhall 2011-04-13 21:41:46 PDT
Created attachment 89527 [details]
Patch
Comment 39 Alice Boxhall 2011-04-13 21:42:25 PDT
(In reply to comment #37)
> (From update of attachment 89526 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=89526&action=review
> 
> > Source/WebCore/page/EventHandler.cpp:641
> > +    return selectionEndNode->renderer()->positionForPoint(selectionEndPoint);
> 
> You need to check renderer here as well.

Done.

> > Source/WebCore/page/EventHandler.cpp:658
> >      if (!targetRenderer)
> >          return;
> 
> You should remove this early exit.

Done (and removed that local variable too, as it wasn't used anywhere).
Comment 40 Ryosuke Niwa 2011-04-13 22:09:03 PDT
Comment on attachment 89527 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=89527&action=review

> Source/WebCore/page/EventHandler.cpp:660
> +    VisibleSelection newSelection = m_frame->selection()->selection();
> +    VisiblePosition targetPosition = selectionExtentRespectingEditingBoundary(newSelection, hitTestResult.localPoint(), target);

You can just pass m_frame->selection()->selection() here since you're not modifying newSelection. That'll avoid copying VisibleSelection needlessly when we're bailing out early.  Please make this change and I'll cq+ it.
Comment 41 Alice Boxhall 2011-04-14 15:41:39 PDT
Created attachment 89672 [details]
Patch
Comment 42 WebKit Commit Bot 2011-04-15 06:45:13 PDT
Comment on attachment 89672 [details]
Patch

Clearing flags on attachment: 89672

Committed r83967: <http://trac.webkit.org/changeset/83967>
Comment 43 WebKit Commit Bot 2011-04-15 06:45:20 PDT
All reviewed patches have been landed.  Closing bug.
Comment 44 Andrey Kosyakov 2011-04-15 10:19:34 PDT
This caused somewhat strange change of chromium expectations to certain other selection tests:

http://test-results.appspot.com/dashboards/flakiness_dashboard.html#showLargeExpectations=true&showExpectations=true&group=%40ToT%20-%20chromium.org&tests=editing%2Fselection%2Fselect-from-textfield-outwards.html%2Cfast%2Fforms%2Finput-text-drag-down.html

Does anyone have an idea whether this is safe to rebaseline?
Comment 45 Ojan Vafai 2011-04-15 10:35:21 PDT
(In reply to comment #44)
> This caused somewhat strange change of chromium expectations to certain other selection tests:
> 
> http://test-results.appspot.com/dashboards/flakiness_dashboard.html#showLargeExpectations=true&showExpectations=true&group=%40ToT%20-%20chromium.org&tests=editing%2Fselection%2Fselect-from-textfield-outwards.html%2Cfast%2Fforms%2Finput-text-drag-down.html
> 
> Does anyone have an idea whether this is safe to rebaseline?

From a quick look at the failures and what the tests are doing, I can't tell if this is fixing a bug or causing one. :) Alice, mind taking a closer look?
Comment 46 Ryosuke Niwa 2011-04-15 10:43:21 PDT
Also see https://bugs.webkit.org/show_bug.cgi?id=55552.

Looking at the chromium result, the test has regressed.  But I'm now sure if it's a bug in WebKit or a bug in the tests.  Will take a look later.
Comment 47 Ryosuke Niwa 2011-04-15 14:44:30 PDT
I meant to say see https://bugs.webkit.org/show_bug.cgi?id=58664.
Comment 48 Alice Boxhall 2011-04-15 16:23:13 PDT
(In reply to comment #46)
> Also see https://bugs.webkit.org/show_bug.cgi?id=55552.
> 
> Looking at the chromium result, the test has regressed.  But I'm now sure if it's a bug in WebKit or a bug in the tests.  Will take a look later.

I'm without a workstation till Monday, as our team is moving desks over the weekend. Will take a look on Monday when things are up and running again.