Reviewers: bokan
CL:
https://codereview.chromium.org/2536083002/Message:
PTAL, thanks!
Description:
SelectionAutoscroll should not happen in user-select:none.
AutoscrollForSelection is to help users select content outside the current
viewport. However, the current implementation starts the autoscroll whenever
the mouse-drag event reaches the edge of the viewport, regardless of whether
the user is selecting or not. It makes no sense to start the autoscroll when
the element was not selectable at all. This patch allows the
AutoscrollForSelection fire only when the mouse is dragged across a selectable
element.
BUG=588448
Affected files (+35, -1 lines):
A third_party/WebKit/LayoutTests/fast/events/autoscroll-disabled-user-select-none.html
M third_party/WebKit/Source/core/input/MouseEventManager.cpp
Index: third_party/WebKit/LayoutTests/fast/events/autoscroll-disabled-user-select-none.html
diff --git a/third_party/WebKit/LayoutTests/fast/events/autoscroll-disabled-user-select-none.html b/third_party/WebKit/LayoutTests/fast/events/autoscroll-disabled-user-select-none.html
new file mode 100644
index 0000000000000000000000000000000000000000..689cdbec7abf9fb120f1b377319ade4039e10ed7
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/events/autoscroll-disabled-user-select-none.html
@@ -0,0 +1,33 @@
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<div id="container" style="height: 400px; overflow: auto;">
+ <div style="-webkit-user-select:none; height: 2000px; background-color: yellow">
+ Hello World! Hello Woorld! Hello Wooorld! Hello Woooorld!<br />
+ Hello World! Hello Woorld! Hello Wooorld! Hello Woooorld!<br />
+ Hello World! Hello Woorld! Hello Wooorld! Hello Woooorld!<br />
+ Hello World! Hello Woorld! Hello Wooorld! Hello Woooorld!<br />
+ Hello World! Hello Woorld! Hello Wooorld! Hello Woooorld!<br />
+ </div>
+</div>
+<script>
+var testSelectNone = async_test("Selection-autoscroll should not be triggered when the selection happens in an element with user-select:none");
+testSelectNone.step(function() {
+ if (!window.eventSender)
+ return;
+ var dragStartX = 50;
+ var dragStartY = 50;
+ var dragEndX = 60;
+ var dragEndY = 400;
+ var container = document.getElementById("container");
+
+ eventSender.dragMode = false;
+ eventSender.mouseMoveTo(dragStartX, dragStartY);
+ eventSender.mouseDown();
+ eventSender.mouseMoveTo(dragEndX, dragEndY);
+
+ requestAnimationFrame(function() {
+ assert_equals(container.scrollTop, 0);
+ testSelectNone.done();
+ });
+});
+</script>
\ No newline at end of file
Index: third_party/WebKit/Source/core/input/MouseEventManager.cpp
diff --git a/third_party/WebKit/Source/core/input/MouseEventManager.cpp b/third_party/WebKit/Source/core/input/MouseEventManager.cpp
index c38ab2fcb8db66b6adc03875a6e1446fdffb617a..aa178a3276abcdc653bc93d979c86176c10dbe98 100644
--- a/third_party/WebKit/Source/core/input/MouseEventManager.cpp
+++ b/third_party/WebKit/Source/core/input/MouseEventManager.cpp
@@ -733,7 +733,8 @@ WebInputEventResult MouseEventManager::handleMouseDraggedEvent(
m_mouseDownMayStartDrag = false;
if (m_mouseDownMayStartAutoscroll &&
- !m_scrollManager->middleClickAutoscrollInProgress()) {
+ !m_scrollManager->middleClickAutoscrollInProgress() &&
+ layoutObject->isSelectable()) {
if (AutoscrollController* controller =
m_scrollManager->autoscrollController()) {
controller->startAutoscrollForSelection(layoutObject);