Commit 53546e29 authored by sunyunjia's avatar sunyunjia Committed by Commit bot

Prevent AutoscrollForSelection when selecting text in a fixed-position element.

AutoscrollForSelection is triggered when selecting text and dragging mouse out
of the container. However, we don't want selecting text in a fixed-position
element triggers autoscroll otherwhere. Inside findAutoscrollable, when we find
the object is inside a fixed-position element, we should prevent
AutoscrollForSelection from happening.

BUG=655489

Review-Url: https://codereview.chromium.org/2441683002
Cr-Commit-Position: refs/heads/master@{#427146}
parent 28c207c7
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div style="height: 400px; position: fixed; width: 400px; top: 500px;">
<br />Fixed.......................
<br />Fixed.......................
<br />Fixed.......................
<br />Fixed.......................
<br />Fixed.......................
<br />Fixed.......................
<br />Fixed.......................
</div>
<div style="height: 2000px"></div>
<script>
var testFix = async_test('Selection-autoscroll should not be triggered when the selection is in a fixed-position element');
testFix.step(function() {
if (!window.eventSender)
return;
var dragStartX = 50;
var dragStartY = 550;
var dragEndX = 60;
var dragMoveY = 580;
var dragEndY = 820;
eventSender.dragMode = false;
eventSender.mouseMoveTo(dragStartX, dragStartY);
eventSender.mouseDown();
eventSender.mouseMoveTo(dragEndX, dragMoveY);
eventSender.mouseMoveTo(dragEndX, dragEndY);
requestAnimationFrame(function() {
assert_equals(document.body.scrollTop, 0);
testFix.done();
});
});
</script>
......@@ -1008,6 +1008,12 @@ LayoutBox* LayoutBox::findAutoscrollable(LayoutObject* layoutObject) {
while (
layoutObject &&
!(layoutObject->isBox() && toLayoutBox(layoutObject)->canAutoscroll())) {
// Do not start autoscroll when the node is inside a fixed-position element.
if (layoutObject->isBox() && toLayoutBox(layoutObject)->hasLayer() &&
toLayoutBox(layoutObject)->layer()->scrollsWithViewport()) {
return nullptr;
}
if (!layoutObject->parent() &&
layoutObject->node() == layoutObject->document() &&
layoutObject->document().localOwner())
......@@ -1016,7 +1022,8 @@ LayoutBox* LayoutBox::findAutoscrollable(LayoutObject* layoutObject) {
layoutObject = layoutObject->parent();
}
return layoutObject && layoutObject->isBox() ? toLayoutBox(layoutObject) : 0;
return layoutObject && layoutObject->isBox() ? toLayoutBox(layoutObject)
: nullptr;
}
static inline int adjustedScrollDelta(int beginningDelta) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment