Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintLayerScrollableArea.cpp

Issue 2383113003: Refactor ScrollableArea::setScrollPosition. (Closed)
Patch Set: Fix clamping, comment tweaks Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. 4 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
5 * 5 *
6 * Other contributors: 6 * Other contributors:
7 * Robert O'Callahan <roc+@cs.cmu.edu> 7 * Robert O'Callahan <roc+@cs.cmu.edu>
8 * David Baron <dbaron@fas.harvard.edu> 8 * David Baron <dbaron@fas.harvard.edu>
9 * Christian Biesinger <cbiesinger@gmail.com> 9 * Christian Biesinger <cbiesinger@gmail.com>
10 * Randall Jesup <rjesup@wgate.com> 10 * Randall Jesup <rjesup@wgate.com>
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 #if ENABLE(ASSERT) 107 #if ENABLE(ASSERT)
108 , 108 ,
109 m_hasBeenDisposed(false) 109 m_hasBeenDisposed(false)
110 #endif 110 #endif
111 { 111 {
112 Node* node = box().node(); 112 Node* node = box().node();
113 if (node && node->isElementNode()) { 113 if (node && node->isElementNode()) {
114 // We save and restore only the scrollOffset as the other scroll values are recalculated. 114 // We save and restore only the scrollOffset as the other scroll values are recalculated.
115 Element* element = toElement(node); 115 Element* element = toElement(node);
116 m_scrollOffset = element->savedLayerScrollOffset(); 116 m_scrollOffset = element->savedLayerScrollOffset();
117 if (!m_scrollOffset.isZero()) 117 if (!m_scrollOffset.isZero()) {
118 scrollAnimator().setCurrentPosition( 118 scrollAnimator().setCurrentPosition(
119 FloatPoint(m_scrollOffset.width(), m_scrollOffset.height())); 119 FloatPoint(m_scrollOffset.width(), m_scrollOffset.height()));
120 }
120 element->setSavedLayerScrollOffset(IntSize()); 121 element->setSavedLayerScrollOffset(IntSize());
121 } 122 }
122 updateResizerAreaSet(); 123 updateResizerAreaSet();
123 } 124 }
124 125
125 PaintLayerScrollableArea::~PaintLayerScrollableArea() { 126 PaintLayerScrollableArea::~PaintLayerScrollableArea() {
126 ASSERT(m_hasBeenDisposed); 127 ASSERT(m_hasBeenDisposed);
127 } 128 }
128 129
129 void PaintLayerScrollableArea::dispose() { 130 void PaintLayerScrollableArea::dispose() {
(...skipping 11 matching lines...) Expand all
141 142
142 if (box().frame() && box().frame()->page()) { 143 if (box().frame() && box().frame()->page()) {
143 if (ScrollingCoordinator* scrollingCoordinator = 144 if (ScrollingCoordinator* scrollingCoordinator =
144 box().frame()->page()->scrollingCoordinator()) 145 box().frame()->page()->scrollingCoordinator())
145 scrollingCoordinator->willDestroyScrollableArea(this); 146 scrollingCoordinator->willDestroyScrollableArea(this);
146 } 147 }
147 148
148 if (!box().documentBeingDestroyed()) { 149 if (!box().documentBeingDestroyed()) {
149 Node* node = box().node(); 150 Node* node = box().node();
150 // FIXME: Make setSavedLayerScrollOffset take DoubleSize. crbug.com/414283. 151 // FIXME: Make setSavedLayerScrollOffset take DoubleSize. crbug.com/414283.
151 if (node && node->isElementNode()) 152 if (node && node->isElementNode()) {
152 toElement(node)->setSavedLayerScrollOffset( 153 toElement(node)->setSavedLayerScrollOffset(
153 flooredIntSize(m_scrollOffset)); 154 flooredIntSize(m_scrollOffset));
155 }
154 } 156 }
155 157
156 if (LocalFrame* frame = box().frame()) { 158 if (LocalFrame* frame = box().frame()) {
157 if (FrameView* frameView = frame->view()) 159 if (FrameView* frameView = frame->view())
158 frameView->removeResizerArea(box()); 160 frameView->removeResizerArea(box());
159 } 161 }
160 162
161 if (RootScrollerController* controller = 163 if (RootScrollerController* controller =
162 box().document().rootScrollerController()) 164 box().document().rootScrollerController())
163 controller->didDisposePaintLayerScrollableArea(*this); 165 controller->didDisposePaintLayerScrollableArea(*this);
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 verticalScrollbarWidth = 493 verticalScrollbarWidth =
492 (verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar()) 494 (verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar())
493 ? verticalScrollbar()->scrollbarThickness() 495 ? verticalScrollbar()->scrollbarThickness()
494 : 0; 496 : 0;
495 horizontalScrollbarHeight = 497 horizontalScrollbarHeight =
496 (horizontalScrollbar() && !horizontalScrollbar()->isOverlayScrollbar()) 498 (horizontalScrollbar() && !horizontalScrollbar()->isOverlayScrollbar())
497 ? horizontalScrollbar()->scrollbarThickness() 499 ? horizontalScrollbar()->scrollbarThickness()
498 : 0; 500 : 0;
499 } 501 }
500 502
503 // TODO(szager): Handle fractional scroll offsets correctly.
501 return IntRect( 504 return IntRect(
502 IntPoint(scrollXOffset(), scrollYOffset()), 505 IntPoint(flooredIntSize(adjustedScrollOffset())),
503 IntSize(max(0, layer()->size().width() - verticalScrollbarWidth), 506 IntSize(max(0, layer()->size().width() - verticalScrollbarWidth),
504 max(0, layer()->size().height() - horizontalScrollbarHeight))); 507 max(0, layer()->size().height() - horizontalScrollbarHeight)));
505 } 508 }
506 509
507 int PaintLayerScrollableArea::visibleHeight() const { 510 int PaintLayerScrollableArea::visibleHeight() const {
508 return layer()->size().height(); 511 return layer()->size().height();
509 } 512 }
510 513
511 int PaintLayerScrollableArea::visibleWidth() const { 514 int PaintLayerScrollableArea::visibleWidth() const {
512 return layer()->size().width(); 515 return layer()->size().width();
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 setScrollOrigin(flooredIntPoint(-scrollableOverflow) + 631 setScrollOrigin(flooredIntPoint(-scrollableOverflow) +
629 box().originAdjustmentForScrollbars()); 632 box().originAdjustmentForScrollbars());
630 } 633 }
631 634
632 void PaintLayerScrollableArea::updateScrollDimensions() { 635 void PaintLayerScrollableArea::updateScrollDimensions() {
633 m_overflowRect = box().layoutOverflowRect(); 636 m_overflowRect = box().layoutOverflowRect();
634 box().flipForWritingMode(m_overflowRect); 637 box().flipForWritingMode(m_overflowRect);
635 updateScrollOrigin(); 638 updateScrollOrigin();
636 } 639 }
637 640
638 void PaintLayerScrollableArea::scrollToPosition( 641 void PaintLayerScrollableArea::setScrollPositionUnconditionally(
639 const DoublePoint& scrollPosition, 642 const DoublePoint& position,
640 ScrollOffsetClamping clamp,
641 ScrollBehavior scrollBehavior,
642 ScrollType scrollType) { 643 ScrollType scrollType) {
643 DoublePoint newScrollPosition = clamp == ScrollOffsetClamped 644 cancelScrollAnimation();
skobes 2016/10/04 22:25:26 Is this what happened before? (cancelling the anim
szager1 2016/10/04 22:54:13 Yes, it's the same thing that ProgrammaticScrollAn
644 ? clampScrollPosition(scrollPosition) 645 scrollPositionChanged(position, scrollType);
645 : scrollPosition;
646 if (newScrollPosition != scrollPositionDouble())
647 ScrollableArea::setScrollPosition(newScrollPosition, scrollType,
648 scrollBehavior);
649 } 646 }
650 647
651 void PaintLayerScrollableArea::updateAfterLayout() { 648 void PaintLayerScrollableArea::updateAfterLayout() {
652 ASSERT(box().hasOverflowClip()); 649 ASSERT(box().hasOverflowClip());
653 650
654 bool relayoutIsPrevented = PreventRelayoutScope::relayoutIsPrevented(); 651 bool relayoutIsPrevented = PreventRelayoutScope::relayoutIsPrevented();
655 bool scrollbarsAreFrozen = 652 bool scrollbarsAreFrozen =
656 m_inOverflowRelayout || FreezeScrollbarsScope::scrollbarsAreFrozen(); 653 m_inOverflowRelayout || FreezeScrollbarsScope::scrollbarsAreFrozen();
657 654
658 if (needsScrollbarReconstruction()) { 655 if (needsScrollbarReconstruction()) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 796
800 if (DelayScrollPositionClampScope::clampingIsDelayed()) { 797 if (DelayScrollPositionClampScope::clampingIsDelayed()) {
801 DelayScrollPositionClampScope::setNeedsClamp(this); 798 DelayScrollPositionClampScope::setNeedsClamp(this);
802 return; 799 return;
803 } 800 }
804 801
805 // Restore before clamping because clamping clears the scroll anchor. 802 // Restore before clamping because clamping clears the scroll anchor.
806 if (shouldPerformScrollAnchoring()) 803 if (shouldPerformScrollAnchoring())
807 m_scrollAnchor.restore(); 804 m_scrollAnchor.restore();
808 805
809 DoublePoint clamped = clampScrollPosition(scrollPositionDouble()); 806 if (scrollOriginChanged()) {
810 if (clamped != scrollPositionDouble() || scrollOriginChanged()) 807 setScrollPositionUnconditionally(
811 ScrollableArea::setScrollPosition(clamped, ProgrammaticScroll); 808 clampScrollPosition(scrollPositionDouble()));
809 } else {
810 ScrollableArea::setScrollPosition(scrollPositionDouble(),
bokan 2016/10/04 22:17:25 Why not just ScrollableArea::setScrollPosition
szager1 2016/10/04 22:54:14 I don't understand the question; maybe you're aski
bokan 2016/10/04 22:56:51 What I meant was, since ScrollableArea::setScrollP
szager1 2016/10/04 23:37:37 No, this is necessary for the case where the scrol
bokan 2016/10/04 23:38:38 Got it, thanks.
811 ProgrammaticScroll);
812 }
812 813
813 setNeedsScrollPositionClamp(false); 814 setNeedsScrollPositionClamp(false);
814 resetScrollOriginChanged(); 815 resetScrollOriginChanged();
815 m_scrollbarManager.destroyDetachedScrollbars(); 816 m_scrollbarManager.destroyDetachedScrollbars();
816 } 817 }
817 818
818 bool PaintLayerScrollableArea::shouldPerformScrollAnchoring() const { 819 bool PaintLayerScrollableArea::shouldPerformScrollAnchoring() const {
819 return RuntimeEnabledFeatures::scrollAnchoringEnabled() && 820 return RuntimeEnabledFeatures::scrollAnchoringEnabled() &&
820 m_scrollAnchor.hasScroller() && 821 m_scrollAnchor.hasScroller() &&
821 layoutBox()->style()->overflowAnchor() != AnchorNone; 822 layoutBox()->style()->overflowAnchor() != AnchorNone;
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 .absoluteToLocalQuad(FloatQuad(FloatRect(rect)), UseTransforms) 1557 .absoluteToLocalQuad(FloatQuad(FloatRect(rect)), UseTransforms)
1557 .boundingBox()); 1558 .boundingBox());
1558 localExposeRect.move(-box().borderLeft(), -box().borderTop()); 1559 localExposeRect.move(-box().borderLeft(), -box().borderTop());
1559 LayoutRect layerBounds(LayoutPoint(), 1560 LayoutRect layerBounds(LayoutPoint(),
1560 LayoutSize(box().clientWidth(), box().clientHeight())); 1561 LayoutSize(box().clientWidth(), box().clientHeight()));
1561 LayoutRect r = ScrollAlignment::getRectToExpose(layerBounds, localExposeRect, 1562 LayoutRect r = ScrollAlignment::getRectToExpose(layerBounds, localExposeRect,
1562 alignX, alignY); 1563 alignX, alignY);
1563 1564
1564 DoublePoint clampedScrollPosition = clampScrollPosition( 1565 DoublePoint clampedScrollPosition = clampScrollPosition(
1565 scrollPositionDouble() + roundedIntSize(r.location())); 1566 scrollPositionDouble() + roundedIntSize(r.location()));
1566 if (clampedScrollPosition == scrollPositionDouble()) 1567 if (clampedScrollPosition == scrollPositionDouble()) {
1567 return LayoutRect( 1568 return LayoutRect(
1568 box() 1569 box()
1569 .localToAbsoluteQuad(FloatQuad(FloatRect(intersection( 1570 .localToAbsoluteQuad(FloatQuad(FloatRect(intersection(
1570 layerBounds, localExposeRect))), 1571 layerBounds, localExposeRect))),
1571 UseTransforms) 1572 UseTransforms)
1572 .boundingBox()); 1573 .boundingBox());
1574 }
1573 1575
1574 DoubleSize oldScrollOffset = adjustedScrollOffset(); 1576 DoubleSize oldScrollOffset = adjustedScrollOffset();
1575 scrollToPosition(clampedScrollPosition, ScrollOffsetUnclamped, 1577 setScrollPosition(clampedScrollPosition, scrollType, ScrollBehaviorInstant);
1576 ScrollBehaviorInstant, scrollType);
1577 DoubleSize scrollOffsetDifference = adjustedScrollOffset() - oldScrollOffset; 1578 DoubleSize scrollOffsetDifference = adjustedScrollOffset() - oldScrollOffset;
1578 localExposeRect.move(-LayoutSize(scrollOffsetDifference)); 1579 localExposeRect.move(-LayoutSize(scrollOffsetDifference));
1579 return LayoutRect( 1580 return LayoutRect(
1580 box() 1581 box()
1581 .localToAbsoluteQuad( 1582 .localToAbsoluteQuad(
1582 FloatQuad(FloatRect(intersection(layerBounds, localExposeRect))), 1583 FloatQuad(FloatRect(intersection(layerBounds, localExposeRect))),
1583 UseTransforms) 1584 UseTransforms)
1584 .boundingBox()); 1585 .boundingBox());
1585 } 1586 }
1586 1587
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 1953
1953 void PaintLayerScrollableArea::DelayScrollPositionClampScope:: 1954 void PaintLayerScrollableArea::DelayScrollPositionClampScope::
1954 clampScrollableAreas() { 1955 clampScrollableAreas() {
1955 for (auto& scrollableArea : *s_needsClamp) 1956 for (auto& scrollableArea : *s_needsClamp)
1956 scrollableArea->clampScrollPositionsAfterLayout(); 1957 scrollableArea->clampScrollPositionsAfterLayout();
1957 delete s_needsClamp; 1958 delete s_needsClamp;
1958 s_needsClamp = nullptr; 1959 s_needsClamp = nullptr;
1959 } 1960 }
1960 1961
1961 } // namespace blink 1962 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698