Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Selecting with shift+drag results in unexpected drag-n-drop
https://bugs.webkit.org/show_bug.cgi?id=155314

Reviewed by Darin Adler.

Source/WebCore:

Test: editing/selection/shift-drag-selection-no-drag-n-drop.html

Whenever user tries to extend an existing text selection by dragging the mouse
(left button hold) with shift key pressed, WebKit enters drag-n-drop mode.
This behavior does not match common editing behavior out there, including other
browsers' (Firefox, Opera/Presto and IE).

Patch changes WebKit so that whenever one extends a selection with mouse
and shift key pressed off of a #text node, it does not enter drag-n-drop mode.

Additionally, patch also adds some further tests to ensure that when
selection is extended off of either a link or an image, drag-n-drop does
get triggered, no matter if shift key is pressed.

* page/EventHandler.cpp:
(WebCore::EventHandler::handleMousePressEvent):

LayoutTests:

Tests that ensure that WebKit:

1) does not enter drag-n-drop mode and extending selection by dragging with mouse with shift key is pressed,
   off of a #text node.
2) does enter drag-n-drop mode and extending selection by dragging with mouse with shift key is pressed,
   off of a link.
3) does enter drag-n-drop mode and extending selection by dragging with mouse with shift key is pressed,
   off of an image.

Note that (1) is a behavior changed by this patch, whereas (2) and (3) represent existing
behavior that is kept.
Tests are also skip for iOS similarly to other drag-n-drop related tests.

* fast/events/shift-drag-selection-no-drag-n-drop-expected.txt: Added.
* fast/events/shift-drag-selection-no-drag-n-drop.html: Added.
* fast/events/shift-drag-selection-on-link-triggers-drag-n-drop-expected.txt: Added.
* fast/events/shift-drag-selection-on-link-triggers-drag-n-drop.html: Added.
* fast/events/shift-drag-selection-on-image-triggers-drag-n-drop-expected.txt: Added.
* fast/events/shift-drag-selection-on-image-triggers-drag-n-drop.html: Added.

Canonical link: https://commits.webkit.org/173579@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@198163 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Antonio Gomes committed Mar 14, 2016
1 parent beb3673 commit ee9e7b3
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 1 deletion.
27 changes: 27 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,30 @@
2016-03-10 Antonio Gomes <tonikitoo@webkit.org>

Selecting with shift+drag results in unexpected drag-n-drop
https://bugs.webkit.org/show_bug.cgi?id=155314

Reviewed by Darin Adler.

Tests that ensure that WebKit:

1) does not enter drag-n-drop mode and extending selection by dragging with mouse with shift key is pressed,
off of a #text node.
2) does enter drag-n-drop mode and extending selection by dragging with mouse with shift key is pressed,
off of a link.
3) does enter drag-n-drop mode and extending selection by dragging with mouse with shift key is pressed,
off of an image.

Note that (1) is a behavior changed by this patch, whereas (2) and (3) represent existing
behavior that is kept.
Tests are also skip for iOS similarly to other drag-n-drop related tests.

* fast/events/shift-drag-selection-no-drag-n-drop-expected.txt: Added.
* fast/events/shift-drag-selection-no-drag-n-drop.html: Added.
* fast/events/shift-drag-selection-on-link-triggers-drag-n-drop-expected.txt: Added.
* fast/events/shift-drag-selection-on-link-triggers-drag-n-drop.html: Added.
* fast/events/shift-drag-selection-on-image-triggers-drag-n-drop-expected.txt: Added.
* fast/events/shift-drag-selection-on-image-triggers-drag-n-drop.html: Added.

2016-03-14 Ryan Haddad <ryanhaddad@apple.com>

Marking storage/indexeddb/transaction-abort-private.html as flaky on mac-wk1
Expand Down
@@ -0,0 +1,4 @@
This test ensures drag-n-drop does not start when extending an existing selecting with shift + mouse drag, starting over a #text.

Drag count: 0

43 changes: 43 additions & 0 deletions LayoutTests/fast/events/shift-drag-selection-no-drag-n-drop.html
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<body>
<p>This test ensures drag-n-drop does not start when extending an existing selecting with shift + mouse drag, starting over a #text.</p>
<span style='font-size: 50px; padding: 10px;'>hello world</span>
<pre>
<script>

var span = document.getElementsByTagName('span')[0];
span.focus();

var dragStartCount = 0;
document.addEventListener('dragstart', function (event) { dragStartCount++; });

if (!window.testRunner || !window.eventSender)
document.write('This test requires eventSender');
else {
testRunner.dumpAsText();

var y = span.offsetTop + span.offsetHeight / 2;
eventSender.mouseMoveTo(span.offsetLeft + 5, y);
eventSender.mouseDown();
eventSender.leapForward(200);
eventSender.mouseUp();

eventSender.mouseMoveTo(span.offsetLeft + span.offsetWidth / 4, y);
eventSender.mouseDown(0, ['shiftKey']);
eventSender.leapForward(200);
eventSender.mouseUp();

eventSender.mouseMoveTo(span.offsetLeft + span.offsetWidth / 2, y);
eventSender.mouseDown(0, ['shiftKey']);
eventSender.leapForward(200);
eventSender.mouseMoveTo(span.offsetLeft + span.offsetWidth, y);
eventSender.leapForward(200);
eventSender.mouseUp();

document.writeln("Drag count: " + dragStartCount);
span.parentNode.removeChild(span);
}
</script></pre>
</body>
</html>
@@ -0,0 +1,4 @@
This test ensures drag-n-drop does start when extending an existing selecting with shift + mouse drag, starting over an image.

Drag count: 1

@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<body>
<p>This test ensures drag-n-drop does start when extending an existing selecting with shift + mouse drag, starting over an image.</p>
<span style='font-size: 30px; padding: 10px;'>Some text with an image <img src="resources/webkit-logo.png" width="50" height="50"> at end.</span>
<pre>
<script>

var span = document.getElementsByTagName('span')[0];
span.focus();

var img = document.getElementsByTagName('img')[0];

var dragStartCount = 0;
document.addEventListener('dragstart', function (event) { dragStartCount++; });

if (!window.testRunner || !window.eventSender)
document.write('This test requires eventSender');
else {
testRunner.dumpAsText();

var y = span.offsetTop + span.offsetHeight / 2;
eventSender.mouseMoveTo(span.offsetLeft + 5, y);
eventSender.mouseDown();
eventSender.leapForward(200);
eventSender.mouseUp();

eventSender.mouseMoveTo(span.offsetLeft + span.offsetWidth / 4, y);
eventSender.mouseDown(0, ['shiftKey']);
eventSender.leapForward(200);
eventSender.mouseUp();

eventSender.mouseMoveTo(img.offsetLeft + img.offsetWidth / 2 , y);
eventSender.mouseDown(0, ['shiftKey']);
eventSender.leapForward(200);
eventSender.mouseMoveTo(img.offsetLeft + img.offsetWidth / 2 , y + 120);
eventSender.leapForward(200);
eventSender.mouseUp();

document.writeln("Drag count: " + dragStartCount);
span.parentNode.removeChild(span);
}
</script></pre>
</body>
</html>
@@ -0,0 +1,4 @@
This test ensures drag-n-drop does start when extending an existing selecting with shift + mouse drag, starting over a link.

Drag count: 1

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<body>
<p>This test ensures drag-n-drop does start when extending an existing selecting with shift + mouse drag, starting over a link.</p>
<span style='font-size: 30px; padding: 10px;'>Some text with a <a href=#>link in the end of sentence</a>.</span>
<pre>
<script>

var span = document.getElementsByTagName('span')[0];
span.focus();

var dragStartCount = 0;
document.addEventListener('dragstart', function (event) { dragStartCount++; });

if (!window.testRunner || !window.eventSender)
document.write('This test requires eventSender');
else {
testRunner.dumpAsText();

var y = span.offsetTop + span.offsetHeight / 2;
eventSender.mouseMoveTo(span.offsetLeft + 5, y);
eventSender.mouseDown();
eventSender.leapForward(200);
eventSender.mouseUp();

eventSender.mouseMoveTo(span.offsetLeft + span.offsetWidth / 4, y);
eventSender.mouseDown(0, ['shiftKey']);
eventSender.leapForward(200);
eventSender.mouseUp();

eventSender.mouseMoveTo(span.offsetLeft + span.offsetWidth * .75 , y);
eventSender.mouseDown(0, ['shiftKey']);
eventSender.leapForward(200);
eventSender.mouseMoveTo(span.offsetLeft + span.offsetWidth * .75, y + 120);
eventSender.leapForward(200);
eventSender.mouseUp();

document.writeln("Drag count: " + dragStartCount);
span.parentNode.removeChild(span);
}
</script></pre>
</body>
</html>
3 changes: 3 additions & 0 deletions LayoutTests/platform/ios-simulator/TestExpectations
Expand Up @@ -1654,6 +1654,9 @@ fast/events/selectstart-by-arrow-keys.html [ Failure ]
fast/events/selectstart-by-double-triple-clicks.html [ Failure ]
fast/events/selectstart-by-drag.html [ Failure ]
fast/events/selectstart-by-single-click-with-shift.html [ Failure ]
fast/events/shift-drag-selection-no-drag-n-drop.html [ Failure ]
fast/events/shift-drag-selection-on-link-triggers-drag-n-drop.html [ Failure ]
fast/events/shift-drag-selection-on-image-triggers-drag-n-drop.html [ Failure ]
fast/events/selectstart-prevent-selection-on-right-click.html [ Failure ]
fast/events/shadow-event-path.html [ Failure ]
fast/events/show-modal-dialog-onblur-onfocus.html [ Failure ]
Expand Down
24 changes: 24 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,27 @@
2016-03-10 Antonio Gomes <tonikitoo@webkit.org>

Selecting with shift+drag results in unexpected drag-n-drop
https://bugs.webkit.org/show_bug.cgi?id=155314

Reviewed by Darin Adler.

Test: editing/selection/shift-drag-selection-no-drag-n-drop.html

Whenever user tries to extend an existing text selection by dragging the mouse
(left button hold) with shift key pressed, WebKit enters drag-n-drop mode.
This behavior does not match common editing behavior out there, including other
browsers' (Firefox, Opera/Presto and IE).

Patch changes WebKit so that whenever one extends a selection with mouse
and shift key pressed off of a #text node, it does not enter drag-n-drop mode.

Additionally, patch also adds some further tests to ensure that when
selection is extended off of either a link or an image, drag-n-drop does
get triggered, no matter if shift key is pressed.

* page/EventHandler.cpp:
(WebCore::EventHandler::handleMousePressEvent):

2016-03-14 Brent Fulgham <bfulgham@apple.com>

REGRESSION (r197114): Crash in WebCore::MediaDevicesRequest::didCompletePermissionCheck
Expand Down
7 changes: 6 additions & 1 deletion Source/WebCore/page/EventHandler.cpp
Expand Up @@ -760,7 +760,12 @@ bool EventHandler::handleMousePressEvent(const MouseEventWithHitTestResults& eve

#if ENABLE(DRAG_SUPPORT)
// Careful that the drag starting logic stays in sync with eventMayStartDrag()
m_mouseDownMayStartDrag = singleClick;
// FIXME: eventMayStartDrag() does not check for shift key press, link or image event targets.
// Bug: https://bugs.webkit.org/show_bug.cgi?id=155390

// Single mouse down on links or images can always trigger drag-n-drop.
bool isMouseDownOnLinkOrImage = event.isOverLink() || event.hitTestResult().image();
m_mouseDownMayStartDrag = singleClick && (!event.event().shiftKey() || isMouseDownOnLinkOrImage);
#endif

m_mouseDownWasSingleClickInSelection = false;
Expand Down

0 comments on commit ee9e7b3

Please sign in to comment.