Commit 961e2d02 authored by sunyunjia's avatar sunyunjia Committed by Commit bot

Scroll the position into view when the content is not visible.

Previously, we implement scrollIntoView by scrolling the intersection of the
viewport and the content. However, when the content is not visible in the
viewport, e.g. outside boundary and the viewport's overflow attribute is
hidden, the intersection would be empty and the browser would stop the
scrolling logic. In this case, we presume the webpage wants to scroll the
position of the content but for some reason doesn't want to show it. In this
patch, we scroll the content's position for this special case.

BUG=673396
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://codereview.chromium.org/2576963002
Cr-Commit-Position: refs/heads/master@{#441469}
parent 38c3c8c8
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div style="height: 2000px"></div>
<div style="overflow: scroll; height: 100px">
<div id="scroll" style="margin-top: -15px; height: 15px; width: 15px;background-color: red"></div>
Target
</div>
<script>
test(function(t) {
var scroll = document.getElementById("scroll");
scroll.scrollIntoView();
assert_not_equals(window.scrollY, 0);
}, "Tests that when the element to be scrolled can't be scrolled to visible in its closest scrollable parent, the element's position should still be scrolled into view");
</script>
\ No newline at end of file
......@@ -85,6 +85,12 @@
namespace blink {
static LayoutRect localToAbsolute(LayoutBox& offset, LayoutRect rect) {
return LayoutRect(
offset.localToAbsoluteQuad(FloatQuad(FloatRect(rect)), UseTransforms)
.boundingBox());
}
PaintLayerScrollableAreaRareData::PaintLayerScrollableAreaRareData() {}
const int ResizerControlExpandRatioForTouch = 2;
......@@ -1622,25 +1628,17 @@ LayoutRect PaintLayerScrollableArea::scrollIntoView(
ScrollOffset oldScrollOffset = getScrollOffset();
ScrollOffset newScrollOffset(clampScrollOffset(roundedIntSize(
toScrollOffset(FloatPoint(r.location()) + oldScrollOffset))));
if (newScrollOffset == oldScrollOffset) {
return LayoutRect(
box()
.localToAbsoluteQuad(FloatQuad(FloatRect(intersection(
layerBounds, localExposeRect))),
UseTransforms)
.boundingBox());
}
setScrollOffset(newScrollOffset, scrollType, ScrollBehaviorInstant);
ScrollOffset scrollOffsetDifference = getScrollOffset() - oldScrollOffset;
localExposeRect.move(-LayoutSize(scrollOffsetDifference));
return LayoutRect(
box()
.localToAbsoluteQuad(
FloatQuad(FloatRect(intersection(layerBounds, localExposeRect))),
UseTransforms)
.boundingBox());
LayoutRect intersect =
localToAbsolute(box(), intersection(layerBounds, localExposeRect));
if (intersect.isEmpty() && !layerBounds.isEmpty() &&
!localExposeRect.isEmpty()) {
return localToAbsolute(box(), localExposeRect);
}
return intersect;
}
void PaintLayerScrollableArea::updateScrollableAreaSet(bool hasOverflow) {
......
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