Commit 6d73ab5e authored by sunyunjia's avatar sunyunjia Committed by Commit bot

Enable the scroll of empty elements by setting the rect's size to 1.

LayoutBox::scrollRectToVisible will return if the new rect to be scrolled is
empty after clipped by layerBounds. However, the rect to be scrolled might be
an empty rect originally. A common case is empty <a> elements used as named
anchors for navigation. This patch sets the size of the empty rect to 1 so that
it can still be scrolled.

BUG=646738

Review-Url: https://codereview.chromium.org/2339653003
Cr-Commit-Position: refs/heads/master@{#418856}
parent 2525299c
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div style="overflow-x:hidden">
<div id="click" ><a href="#anchor">Click me should jump to the anchor</a></div>
<div style="height: 2000px"></div>
<a id="anchor"></a>
<p>Text</p>
<div style="height: 2000px"></div>
</div>
<script>
test(function() {
if (!window.eventSender)
return;
var click = document.getElementById("click");
var x = click.offsetLeft + 5;
var y = click.offsetTop + 5;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.mouseUp();
assert_not_equals(window.scrollY, 0);
}, "Tests that when the anchor's layoutbox is empty, we can still jump to it by hashtag");
</script>
......@@ -565,8 +565,14 @@ void LayoutBox::scrollRectToVisible(const LayoutRect& rect, const ScrollAlignmen
// Presumably the same issue as in setScrollTop. See crbug.com/343132.
DisableCompositingQueryAsserts disabler;
LayoutRect rectToScroll = rect;
if (rectToScroll.width() <= 0)
rectToScroll.setWidth(LayoutUnit(1));
if (rectToScroll.height() <= 0)
rectToScroll.setHeight(LayoutUnit(1));
LayoutBox* parentBox = nullptr;
LayoutRect newRect = rect;
LayoutRect newRect = rectToScroll;
bool restrictedByLineClamp = false;
if (parent()) {
......@@ -577,7 +583,7 @@ void LayoutBox::scrollRectToVisible(const LayoutRect& rect, const ScrollAlignmen
if (hasOverflowClip() && !restrictedByLineClamp) {
// Don't scroll to reveal an overflow layer that is restricted by the -webkit-line-clamp property.
// This will prevent us from revealing text hidden by the slider in Safari RSS.
newRect = getScrollableArea()->scrollIntoView(rect, alignX, alignY, scrollType);
newRect = getScrollableArea()->scrollIntoView(rectToScroll, alignX, alignY, scrollType);
if (newRect.isEmpty())
return;
} else if (!parentBox && canBeProgramaticallyScrolled()) {
......@@ -585,15 +591,15 @@ void LayoutBox::scrollRectToVisible(const LayoutRect& rect, const ScrollAlignmen
HTMLFrameOwnerElement* ownerElement = document().localOwner();
if (!isDisallowedAutoscroll(ownerElement, frameView)) {
if (makeVisibleInVisualViewport) {
frameView->getScrollableArea()->scrollIntoView(rect, alignX, alignY, scrollType);
frameView->getScrollableArea()->scrollIntoView(rectToScroll, alignX, alignY, scrollType);
} else {
frameView->layoutViewportScrollableArea()->scrollIntoView(rect, alignX, alignY, scrollType);
frameView->layoutViewportScrollableArea()->scrollIntoView(rectToScroll, alignX, alignY, scrollType);
}
if (ownerElement && ownerElement->layoutObject()) {
if (frameView->safeToPropagateScrollToParent()) {
parentBox = ownerElement->layoutObject()->enclosingBox();
LayoutView* parentView = ownerElement->layoutObject()->view();
newRect = enclosingLayoutRect(view()->localToAncestorQuad(FloatRect(rect), parentView, UseTransforms | TraverseDocumentBoundaries).boundingBox());
newRect = enclosingLayoutRect(view()->localToAncestorQuad(FloatRect(rectToScroll), parentView, UseTransforms | TraverseDocumentBoundaries).boundingBox());
} else {
parentBox = nullptr;
}
......
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