Commit c5b90a15 authored by szager@chromium.org's avatar szager@chromium.org

Get rid of clampScrollOffset and make maximumScrollPosition sane.

This also gets rid of a bug in clampScrollOffset that sometimes caused it to use a maximum offset that was one pixel too small, so a few tests need to be rebaselined.

BUG=492871
R=skobes@chromium.org

Review URL: https://codereview.chromium.org/1223173006

git-svn-id: svn://svn.chromium.org/blink/trunk@201983 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent bb2036fb
......@@ -70,6 +70,12 @@ crbug.com/463358 [ Mac Linux Debug ] fast/backgrounds/transformed-body-backgroun
crbug.com/463358 [ Mac Linux Debug ] svg/W3C-SVG-1.1/paths-data-02-t.svg [ ImageOnlyFailure ]
crbug.com/463358 [ Mac Linux Debug ] css3/masking/clip-path-polygon.html [ ImageOnlyFailure ]
crbug.com/492871 [ Mac ] fast/forms/listbox-scrollbar-incremental-load.html [ NeedsRebaseline ]
crbug.com/492871 [ Mac ] fast/forms/select-initial-position.html [ NeedsRebaseline ]
crbug.com/492871 [ Mac ] fast/overflow/overflow-text-hit-testing.html [ NeedsRebaseline ]
crbug.com/492871 [ Mac ] fast/repaint/caret-invalidation-in-overflow-scroll.html [ NeedsRebaseline ]
crbug.com/492871 [ Win ] fast/overflow/overflow-text-hit-testing.html [ NeedsRebaseline ]
crbug.com/267206 [ Mac ] virtual/rootlayerscrolls/fast/scrolling/scrollbar-tickmarks-hittest.html [ Timeout ]
# Times out on the windows trybot.
......
......@@ -2990,17 +2990,10 @@ IntPoint FrameView::maximumScrollPosition() const
{
// Make the same calculation as in CC's LayerImpl::MaxScrollOffset()
// FIXME: We probably shouldn't be storing the bounds in a float. crbug.com/422331.
FloatSize visibleSize = visibleContentSize(ExcludeScrollbars);
visibleSize.expand(0, m_topControlsViewportAdjustment);
FloatSize contentBounds = contentsSize();
contentBounds = flooredIntSize(contentBounds);
FloatSize maximumOffset = contentBounds - visibleSize - toIntSize(scrollOrigin());
IntPoint snappedMaximumOffset = flooredIntPoint(maximumOffset);
snappedMaximumOffset = snappedMaximumOffset.expandedTo(minimumScrollPosition());
return snappedMaximumOffset;
IntSize visibleSize = visibleContentSize(ExcludeScrollbars) + topControlsSize();
IntSize contentBounds = contentsSize();
IntPoint maximumPosition = -scrollOrigin() + (contentBounds - visibleSize);
return maximumPosition.expandedTo(minimumScrollPosition());
}
void FrameView::addChild(PassRefPtrWillBeRawPtr<Widget> prpChild)
......
......@@ -336,6 +336,7 @@ public:
// commit scroll offsets before a WebView::resize occurs, we need to adjust
// our scroll extents to prevent clamping the scroll offsets.
void setTopControlsViewportAdjustment(float);
IntSize topControlsSize() const { return IntSize(0, roundf(m_topControlsViewportAdjustment)); }
IntPoint maximumScrollPosition() const override;
......
......@@ -398,10 +398,7 @@ LayoutUnit LayoutTextControlSingleLine::scrollWidth() const
// Adjust scrollWidth to inculde input element horizontal paddings and
// decoration width
LayoutUnit adjustment = clientWidth() - inner->clientWidth();
// TODO(leviw): We floor to avoid breaking JS that tries to scroll to
// scrollWidth - clientWidth.
// TODO(leviw): These values are broken when zooming. crbug.com/471412
return inner->scrollWidth().floor() + adjustment;
return inner->scrollWidth() + adjustment;
}
return LayoutBlockFlow::scrollWidth();
}
......@@ -412,10 +409,7 @@ LayoutUnit LayoutTextControlSingleLine::scrollHeight() const
// Adjust scrollHeight to include input element vertical paddings and
// decoration height
LayoutUnit adjustment = clientHeight() - inner->clientHeight();
// TODO(leviw): We floor to avoid breaking JS that tries to scroll to
// scrollHeight - clientHeight.
// TODO(leviw): These values are broken when zooming. crbug.com/471412
return inner->scrollHeight().floor() + adjustment;
return inner->scrollHeight() + adjustment;
}
return LayoutBlockFlow::scrollHeight();
}
......
......@@ -489,9 +489,17 @@ IntPoint DeprecatedPaintLayerScrollableArea::minimumScrollPosition() const
IntPoint DeprecatedPaintLayerScrollableArea::maximumScrollPosition() const
{
if (!box().hasOverflowClip())
return -scrollOrigin();
return -scrollOrigin() + IntPoint(pixelSnappedScrollWidth(), pixelSnappedScrollHeight()) - enclosingIntRect(box().clientBoxRect()).size();
IntSize contentSize;
IntSize visibleSize;
if (layer()->isRootLayer()) {
FrameView* frameView = box().frameView();
contentSize = frameView->contentsSize();
visibleSize = frameView->visibleContentSize(ExcludeScrollbars) + frameView->topControlsSize();
} else if (box().hasOverflowClip()) {
contentSize = IntSize(pixelSnappedScrollWidth(), pixelSnappedScrollHeight());
visibleSize = enclosingIntRect(box().clientBoxRect()).size();
}
return -scrollOrigin() + (contentSize - visibleSize);
}
IntRect DeprecatedPaintLayerScrollableArea::visibleContentRect(IncludeScrollbarsInRect scrollbarInclusion) const
......@@ -642,14 +650,13 @@ void DeprecatedPaintLayerScrollableArea::computeScrollDimensions()
setScrollOrigin(IntPoint(-scrollableLeftOverflow, -scrollableTopOverflow));
}
void DeprecatedPaintLayerScrollableArea::scrollToOffset(const DoubleSize& scrollOffset, ScrollOffsetClamping clamp, ScrollBehavior scrollBehavior)
void DeprecatedPaintLayerScrollableArea::scrollToPosition(const DoublePoint& scrollPosition, ScrollOffsetClamping clamp, ScrollBehavior scrollBehavior)
{
cancelProgrammaticScrollAnimation();
DoubleSize newScrollOffset = clamp == ScrollOffsetClamped ? clampScrollOffset(scrollOffset) : scrollOffset;
if (newScrollOffset != adjustedScrollOffset()) {
DoublePoint origin(scrollOrigin());
ScrollableArea::setScrollPosition(-origin + newScrollOffset, ProgrammaticScroll, scrollBehavior);
}
DoublePoint newScrollPosition = clamp == ScrollOffsetClamped ? clampScrollPosition(scrollPosition) : scrollPosition;
if (newScrollPosition != scrollPositionDouble())
ScrollableArea::setScrollPosition(newScrollPosition, ProgrammaticScroll, scrollBehavior);
}
void DeprecatedPaintLayerScrollableArea::updateScrollDimensions(DoubleSize& scrollOffset, bool& autoHorizontalScrollBarChanged, bool& autoVerticalScrollBarChanged)
......@@ -691,9 +698,9 @@ void DeprecatedPaintLayerScrollableArea::finalizeScrollDimensions(const DoubleSi
// Layout may cause us to be at an invalid scroll position. In this case we need
// to pull our scroll offsets back to the max (or push them up to the min).
DoubleSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset());
if (clampedScrollOffset != adjustedScrollOffset())
scrollToOffset(clampedScrollOffset);
DoublePoint clampedScrollPosition = clampScrollPosition(scrollPositionDouble());
if (clampedScrollPosition != scrollPositionDouble())
scrollToPosition(clampedScrollPosition);
if (originalScrollOffset != adjustedScrollOffset()) {
DoublePoint origin(scrollOrigin());
......@@ -903,16 +910,6 @@ void DeprecatedPaintLayerScrollableArea::updateAfterOverflowRecalc()
box().setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::Unknown);
}
DoubleSize DeprecatedPaintLayerScrollableArea::clampScrollOffset(const DoubleSize& scrollOffset) const
{
int maxX = scrollWidth() - box().pixelSnappedClientWidth();
int maxY = scrollHeight() - box().pixelSnappedClientHeight();
double x = std::max(std::min(scrollOffset.width(), static_cast<double>(maxX)), 0.0);
double y = std::max(std::min(scrollOffset.height(), static_cast<double>(maxY)), 0.0);
return DoubleSize(x, y);
}
IntRect DeprecatedPaintLayerScrollableArea::rectForHorizontalScrollbar(const IntRect& borderBoxRect) const
{
if (!m_hBar)
......@@ -1402,12 +1399,12 @@ LayoutRect DeprecatedPaintLayerScrollableArea::scrollIntoView(const LayoutRect&
LayoutRect layerBounds(0, 0, box().clientWidth(), box().clientHeight());
LayoutRect r = ScrollAlignment::getRectToExpose(layerBounds, localExposeRect, alignX, alignY);
DoubleSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset() + roundedIntSize(r.location()));
if (clampedScrollOffset == adjustedScrollOffset())
DoublePoint clampedScrollPosition = clampScrollPosition(scrollPositionDouble() + roundedIntSize(r.location()));
if (clampedScrollPosition == scrollPositionDouble())
return rect;
DoubleSize oldScrollOffset = adjustedScrollOffset();
scrollToOffset(clampedScrollOffset);
scrollToPosition(clampedScrollPosition);
DoubleSize scrollOffsetDifference = adjustedScrollOffset() - oldScrollOffset;
localExposeRect.move(-LayoutSize(scrollOffsetDifference));
return LayoutRect(box().localToAbsoluteQuad(FloatQuad(FloatRect(localExposeRect)), UseTransforms).boundingBox());
......
......@@ -132,7 +132,12 @@ public:
// FIXME: We shouldn't allow access to m_overflowRect outside this class.
LayoutRect overflowRect() const { return m_overflowRect; }
void scrollToOffset(const DoubleSize& scrollOffset, ScrollOffsetClamping = ScrollOffsetUnclamped, ScrollBehavior = ScrollBehaviorInstant);
void scrollToPosition(const DoublePoint& scrollPosition, ScrollOffsetClamping = ScrollOffsetUnclamped, ScrollBehavior = ScrollBehaviorInstant);
void scrollToOffset(const DoubleSize& scrollOffset, ScrollOffsetClamping clamp = ScrollOffsetUnclamped, ScrollBehavior scrollBehavior = ScrollBehaviorInstant)
{
scrollToPosition(-scrollOrigin() + scrollOffset, clamp, scrollBehavior);
}
void scrollToXOffset(double x, ScrollOffsetClamping clamp = ScrollOffsetUnclamped, ScrollBehavior scrollBehavior = ScrollBehaviorInstant)
{
......@@ -243,10 +248,6 @@ private:
void computeScrollDimensions();
// TODO(bokan): This method hides the base class version and is subtly different.
// Should be unified.
DoubleSize clampScrollOffset(const DoubleSize&) const;
void setScrollOffset(const IntPoint&, ScrollType) override;
void setScrollOffset(const DoublePoint&, ScrollType) override;
......
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