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

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

Issue 2383113003: Refactor ScrollableArea::setScrollPosition. (Closed)
Patch Set: 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 m_scrollAnchor(this) 106 m_scrollAnchor(this)
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_scrollPosition = element->savedLayerScrollOffset();
117 if (!m_scrollOffset.isZero()) 117 if (!m_scrollPosition.isZero()) {
118 scrollAnimator().setCurrentPosition( 118 scrollAnimator().setCurrentPosition(
119 FloatPoint(m_scrollOffset.width(), m_scrollOffset.height())); 119 FloatPoint(m_scrollPosition.width(), m_scrollPosition.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_scrollPosition));
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return point; 349 return point;
348 } 350 }
349 351
350 int PaintLayerScrollableArea::scrollSize( 352 int PaintLayerScrollableArea::scrollSize(
351 ScrollbarOrientation orientation) const { 353 ScrollbarOrientation orientation) const {
352 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPosition(); 354 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPosition();
353 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() 355 return (orientation == HorizontalScrollbar) ? scrollDimensions.width()
354 : scrollDimensions.height(); 356 : scrollDimensions.height();
355 } 357 }
356 358
357 void PaintLayerScrollableArea::setScrollOffset( 359 void PaintLayerScrollableArea::updateScrollPosition(
358 const DoublePoint& newScrollOffset, 360 const DoublePoint& newPosition,
359 ScrollType scrollType) { 361 ScrollType scrollType) {
360 if (scrollOffset() == toDoubleSize(newScrollOffset)) 362 if (scrollPositionDouble() == newPosition)
361 return; 363 return;
362 364
363 DoubleSize scrollDelta = scrollOffset() - toDoubleSize(newScrollOffset); 365 DoubleSize scrollDelta = scrollPositionDouble() - newPosition;
364 m_scrollOffset = toDoubleSize(newScrollOffset); 366 m_scrollPosition = toDoubleSize(newPosition);
365 367
366 LocalFrame* frame = box().frame(); 368 LocalFrame* frame = box().frame();
367 ASSERT(frame); 369 ASSERT(frame);
368 370
369 FrameView* frameView = box().frameView(); 371 FrameView* frameView = box().frameView();
370 372
371 TRACE_EVENT1("devtools.timeline", "ScrollLayer", "data", 373 TRACE_EVENT1("devtools.timeline", "ScrollLayer", "data",
372 InspectorScrollLayerEvent::data(&box())); 374 InspectorScrollLayerEvent::data(&box()));
373 375
374 // FIXME(420741): Resolve circular dependency between scroll offset and 376 // FIXME(420741): Resolve circular dependency between scroll offset and
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 // All scrolls clear the fragment anchor. 450 // All scrolls clear the fragment anchor.
449 frameView->clearFragmentAnchor(); 451 frameView->clearFragmentAnchor();
450 452
451 // Clear the scroll anchor, unless it is the reason for this scroll. 453 // Clear the scroll anchor, unless it is the reason for this scroll.
452 if (RuntimeEnabledFeatures::scrollAnchoringEnabled() && 454 if (RuntimeEnabledFeatures::scrollAnchoringEnabled() &&
453 scrollType != AnchoringScroll) 455 scrollType != AnchoringScroll)
454 scrollAnchor()->clear(); 456 scrollAnchor()->clear();
455 } 457 }
456 458
457 IntPoint PaintLayerScrollableArea::scrollPosition() const { 459 IntPoint PaintLayerScrollableArea::scrollPosition() const {
458 return IntPoint(flooredIntSize(m_scrollOffset)); 460 return IntPoint(flooredIntSize(m_scrollPosition));
459 } 461 }
460 462
461 DoublePoint PaintLayerScrollableArea::scrollPositionDouble() const { 463 DoublePoint PaintLayerScrollableArea::scrollPositionDouble() const {
462 return DoublePoint(m_scrollOffset); 464 return DoublePoint(m_scrollPosition);
463 } 465 }
464 466
465 IntPoint PaintLayerScrollableArea::minimumScrollPosition() const { 467 IntPoint PaintLayerScrollableArea::minimumScrollPosition() const {
466 return -scrollOrigin(); 468 return -scrollOrigin();
467 } 469 }
468 470
469 IntPoint PaintLayerScrollableArea::maximumScrollPosition() const { 471 IntPoint PaintLayerScrollableArea::maximumScrollPosition() const {
470 IntSize contentSize; 472 IntSize contentSize;
471 IntSize visibleSize; 473 IntSize visibleSize;
472 if (box().hasOverflowClip()) { 474 if (box().hasOverflowClip()) {
(...skipping 18 matching lines...) Expand all
491 verticalScrollbarWidth = 493 verticalScrollbarWidth =
492 (verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar()) 494 (verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar())
493 ? verticalScrollbar()->width() 495 ? verticalScrollbar()->width()
494 : 0; 496 : 0;
495 horizontalScrollbarHeight = 497 horizontalScrollbarHeight =
496 (horizontalScrollbar() && !horizontalScrollbar()->isOverlayScrollbar()) 498 (horizontalScrollbar() && !horizontalScrollbar()->isOverlayScrollbar())
497 ? horizontalScrollbar()->height() 499 ? horizontalScrollbar()->height()
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(offsetFromOrigin())),
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();
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DoublePoint clamped = clampScrollPosition(scrollPositionDouble());
810 if (clamped != scrollPositionDouble() || scrollOriginChanged()) 807 if (scrollOriginChanged())
808 setScrollPositionUnconditionally(clamped);
809 else if (clamped != scrollPositionDouble())
811 ScrollableArea::setScrollPosition(clamped, ProgrammaticScroll); 810 ScrollableArea::setScrollPosition(clamped, ProgrammaticScroll);
812 811
813 setNeedsScrollPositionClamp(false); 812 setNeedsScrollPositionClamp(false);
814 resetScrollOriginChanged(); 813 resetScrollOriginChanged();
815 m_scrollbarManager.destroyDetachedScrollbars(); 814 m_scrollbarManager.destroyDetachedScrollbars();
816 } 815 }
817 816
818 bool PaintLayerScrollableArea::shouldPerformScrollAnchoring() const { 817 bool PaintLayerScrollableArea::shouldPerformScrollAnchoring() const {
819 return RuntimeEnabledFeatures::scrollAnchoringEnabled() && 818 return RuntimeEnabledFeatures::scrollAnchoringEnabled() &&
820 m_scrollAnchor.hasScroller() && 819 m_scrollAnchor.hasScroller() &&
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 LayoutRect localExposeRect( 1552 LayoutRect localExposeRect(
1554 box() 1553 box()
1555 .absoluteToLocalQuad(FloatQuad(FloatRect(rect)), UseTransforms) 1554 .absoluteToLocalQuad(FloatQuad(FloatRect(rect)), UseTransforms)
1556 .boundingBox()); 1555 .boundingBox());
1557 localExposeRect.move(-box().borderLeft(), -box().borderTop()); 1556 localExposeRect.move(-box().borderLeft(), -box().borderTop());
1558 LayoutRect layerBounds(LayoutPoint(), 1557 LayoutRect layerBounds(LayoutPoint(),
1559 LayoutSize(box().clientWidth(), box().clientHeight())); 1558 LayoutSize(box().clientWidth(), box().clientHeight()));
1560 LayoutRect r = ScrollAlignment::getRectToExpose(layerBounds, localExposeRect, 1559 LayoutRect r = ScrollAlignment::getRectToExpose(layerBounds, localExposeRect,
1561 alignX, alignY); 1560 alignX, alignY);
1562 1561
1563 DoublePoint clampedScrollPosition = clampScrollPosition( 1562 DoublePoint oldScrollPosition = scrollPositionDouble();
1564 scrollPositionDouble() + roundedIntSize(r.location())); 1563 DoublePoint newScrollPosition =
1565 if (clampedScrollPosition == scrollPositionDouble()) 1564 clampScrollPosition(oldScrollPosition + roundedIntSize(r.location()));
1565 if (newScrollPosition == oldScrollPosition)
1566 return LayoutRect( 1566 return LayoutRect(
1567 box() 1567 box()
1568 .localToAbsoluteQuad(FloatQuad(FloatRect(intersection( 1568 .localToAbsoluteQuad(FloatQuad(FloatRect(intersection(
1569 layerBounds, localExposeRect))), 1569 layerBounds, localExposeRect))),
1570 UseTransforms) 1570 UseTransforms)
1571 .boundingBox()); 1571 .boundingBox());
1572 1572
1573 DoubleSize oldScrollOffset = adjustedScrollOffset(); 1573 setScrollPosition(newScrollPosition, scrollType, ScrollBehaviorInstant);
1574 scrollToPosition(clampedScrollPosition, ScrollOffsetUnclamped, 1574 DoubleSize scrollOffsetDifference =
1575 ScrollBehaviorInstant, scrollType); 1575 scrollPositionDouble() - oldScrollPosition;
1576 DoubleSize scrollOffsetDifference = adjustedScrollOffset() - oldScrollOffset;
1577 localExposeRect.move(-LayoutSize(scrollOffsetDifference)); 1576 localExposeRect.move(-LayoutSize(scrollOffsetDifference));
1578 return LayoutRect( 1577 return LayoutRect(
1579 box() 1578 box()
1580 .localToAbsoluteQuad( 1579 .localToAbsoluteQuad(
1581 FloatQuad(FloatRect(intersection(layerBounds, localExposeRect))), 1580 FloatQuad(FloatRect(intersection(layerBounds, localExposeRect))),
1582 UseTransforms) 1581 UseTransforms)
1583 .boundingBox()); 1582 .boundingBox());
1584 } 1583 }
1585 1584
1586 void PaintLayerScrollableArea::updateScrollableAreaSet(bool hasOverflow) { 1585 void PaintLayerScrollableArea::updateScrollableAreaSet(bool hasOverflow) {
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 1950
1952 void PaintLayerScrollableArea::DelayScrollPositionClampScope:: 1951 void PaintLayerScrollableArea::DelayScrollPositionClampScope::
1953 clampScrollableAreas() { 1952 clampScrollableAreas() {
1954 for (auto& scrollableArea : *s_needsClamp) 1953 for (auto& scrollableArea : *s_needsClamp)
1955 scrollableArea->clampScrollPositionsAfterLayout(); 1954 scrollableArea->clampScrollPositionsAfterLayout();
1956 delete s_needsClamp; 1955 delete s_needsClamp;
1957 s_needsClamp = nullptr; 1956 s_needsClamp = nullptr;
1958 } 1957 }
1959 1958
1960 } // namespace blink 1959 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698