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

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

Issue 1930183002: Refactor scroll updates during flexbox layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@rtl-scroll-origin
Patch Set: Fix layout invalidation reason Created 4 years, 7 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 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } else if (box().isFlexibleBox()) { 616 } else if (box().isFlexibleBox()) {
617 EFlexDirection flexDirection = box().style()->flexDirection(); 617 EFlexDirection flexDirection = box().style()->flexDirection();
618 if (flexDirection == FlowColumnReverse) 618 if (flexDirection == FlowColumnReverse)
619 size.expand(verticalScrollbarWidth, 0); 619 size.expand(verticalScrollbarWidth, 0);
620 else if (flexDirection == FlowRowReverse) 620 else if (flexDirection == FlowRowReverse)
621 size.expand(0, horizontalScrollbarHeight); 621 size.expand(0, horizontalScrollbarHeight);
622 } 622 }
623 return size; 623 return size;
624 } 624 }
625 625
626 void PaintLayerScrollableArea::computeScrollDimensions() 626 void PaintLayerScrollableArea::updateScrollOrigin()
627 {
628 if (!overflowRect().size().isZero()) {
cbiesinger 2016/04/29 20:02:50 if (!overflowRect().isEmpty()) ? But can you expl
szager1 2016/05/12 20:44:50 This is a hack to prevent this from running before
629 LayoutPoint scrollableOverflow = m_overflowRect.location() - LayoutSize( box().borderLeft(), box().borderTop());
630 setScrollOrigin(flooredIntPoint(-scrollableOverflow) + originAdjustmentF orScrollbars());
631 }
632 }
633
634 void PaintLayerScrollableArea::updateScrollDimensions()
627 { 635 {
628 m_overflowRect = box().layoutOverflowRect(); 636 m_overflowRect = box().layoutOverflowRect();
629 box().flipForWritingMode(m_overflowRect); 637 box().flipForWritingMode(m_overflowRect);
630 638 updateScrollOrigin();
631 LayoutPoint scrollableOverflow = m_overflowRect.location() - LayoutSize(box( ).borderLeft(), box().borderTop());
632 setScrollOrigin(flooredIntPoint(-scrollableOverflow) + originAdjustmentForSc rollbars());
633 } 639 }
634 640
635 void PaintLayerScrollableArea::scrollToPosition(const DoublePoint& scrollPositio n, ScrollOffsetClamping clamp, ScrollBehavior scrollBehavior, ScrollType scrollT ype) 641 void PaintLayerScrollableArea::scrollToPosition(const DoublePoint& scrollPositio n, ScrollOffsetClamping clamp, ScrollBehavior scrollBehavior, ScrollType scrollT ype)
636 { 642 {
637 cancelProgrammaticScrollAnimation();
cbiesinger 2016/04/29 20:02:50 BTW, why did you remove this? Just because it's no
szager1 2016/05/12 20:44:51 It already gets called further down the call stack
638
639 DoublePoint newScrollPosition = clamp == ScrollOffsetClamped ? clampScrollPo sition(scrollPosition) : scrollPosition; 643 DoublePoint newScrollPosition = clamp == ScrollOffsetClamped ? clampScrollPo sition(scrollPosition) : scrollPosition;
640 if (newScrollPosition != scrollPositionDouble()) 644 if (newScrollPosition != scrollPositionDouble())
641 ScrollableArea::setScrollPosition(newScrollPosition, scrollType, scrollB ehavior); 645 ScrollableArea::setScrollPosition(newScrollPosition, scrollType, scrollB ehavior);
642 } 646 }
643 647
644 bool PaintLayerScrollableArea::updateAfterLayout(SubtreeLayoutScope* delayedLayo utScope) 648 void PaintLayerScrollableArea::updateAfterLayout()
645 { 649 {
646 ASSERT(box().hasOverflowClip()); 650 ASSERT(box().hasOverflowClip());
647 651
648 bool didMarkForDelayedLayout = false; 652 bool relayoutIsPrevented = PreventRelayoutScope::relayoutIsPrevented();
653 bool scrollbarsAreFrozen = FreezeScrollbarsScope::scrollbarsAreFrozen();
649 654
650 if (needsScrollbarReconstruction()) { 655 if (needsScrollbarReconstruction()) {
651 m_scrollbarManager.setCanDetachScrollbars(false);
652 setHasHorizontalScrollbar(false); 656 setHasHorizontalScrollbar(false);
653 setHasVerticalScrollbar(false); 657 setHasVerticalScrollbar(false);
654 } 658 }
655 659
656 m_scrollbarManager.setCanDetachScrollbars(true); 660 updateScrollDimensions();
657
658 IntPoint originalOrigin = scrollOrigin();
659 computeScrollDimensions();
660
661 // Layout may cause us to be at an invalid scroll position. In this case we need
662 // to pull our scroll offsets back to the max (or push them up to the min).
663 DoublePoint clampedScrollPosition = clampScrollPosition(scrollPositionDouble ());
664 if (clampedScrollPosition != scrollPositionDouble()) {
665 scrollToPosition(clampedScrollPosition);
666 } else if (originalOrigin != scrollOrigin()) {
667 // TODO: We should be able to use scrollOriginChanged() here, but we can 't because
668 // PaintLayerScrollableArea does not maintain that flag: it gets set, bu t it never
669 // gets unset. We should unset the flag after layout.
670 scrollPositionChanged(scrollPositionDouble(), ProgrammaticScroll);
671 }
672
673 m_scrollbarManager.setCanDetachScrollbars(false);
674 661
675 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 662 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
676 bool hasVerticalOverflow = this->hasVerticalOverflow(); 663 bool hasVerticalOverflow = this->hasVerticalOverflow();
677 664
678 { 665 {
679 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html. 666 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html.
680 DisableCompositingQueryAsserts disabler; 667 DisableCompositingQueryAsserts disabler;
681 668
682 // overflow:scroll should just enable/disable. 669 // overflow:scroll should just enable/disable.
683 if (box().style()->overflowX() == OverflowScroll && horizontalScrollbar( )) 670 if (box().style()->overflowX() == OverflowScroll && horizontalScrollbar( ))
684 horizontalScrollbar()->setEnabled(hasHorizontalOverflow); 671 horizontalScrollbar()->setEnabled(hasHorizontalOverflow);
685 if (box().style()->overflowY() == OverflowScroll && verticalScrollbar()) 672 if (box().style()->overflowY() == OverflowScroll && verticalScrollbar())
686 verticalScrollbar()->setEnabled(hasVerticalOverflow); 673 verticalScrollbar()->setEnabled(hasVerticalOverflow);
687 } 674 }
688 675
689 // We need to layout again if scrollbars are added or removed by overflow:au to, 676 // We need to layout again if scrollbars are added or removed by overflow:au to,
690 // or by changing between native and custom. 677 // or by changing between native and custom.
691 bool horizontalScrollBarChanged = (box().hasAutoHorizontalScrollbar() && (ha sHorizontalScrollbar() != hasHorizontalOverflow)) 678 bool horizontalScrollBarChanged = (box().hasAutoHorizontalScrollbar() && (ha sHorizontalScrollbar() != hasHorizontalOverflow))
692 || (box().style()->overflowX() == OverflowScroll && !horizontalScrollbar ()); 679 || (box().style()->overflowX() == OverflowScroll && !horizontalScrollbar ());
693 bool verticalScrollBarChanged = (box().hasAutoVerticalScrollbar() && (hasVer ticalScrollbar() != hasVerticalOverflow)) 680 bool verticalScrollBarChanged = (box().hasAutoVerticalScrollbar() && (hasVer ticalScrollbar() != hasVerticalOverflow))
694 || (box().style()->overflowY() == OverflowScroll && !verticalScrollbar() ); 681 || (box().style()->overflowY() == OverflowScroll && !verticalScrollbar() );
695 if (!visualViewportSuppliesScrollbars() && (horizontalScrollBarChanged || ve rticalScrollBarChanged)) { 682 if (!scrollbarsAreFrozen && !visualViewportSuppliesScrollbars() && (horizont alScrollBarChanged || verticalScrollBarChanged)) {
696 if (box().hasAutoHorizontalScrollbar()) 683 if (box().hasAutoHorizontalScrollbar())
697 setHasHorizontalScrollbar(hasHorizontalOverflow); 684 setHasHorizontalScrollbar(hasHorizontalOverflow);
698 else if (box().style()->overflowX() == OverflowScroll) 685 else if (box().style()->overflowX() == OverflowScroll)
699 setHasHorizontalScrollbar(true); 686 setHasHorizontalScrollbar(true);
700 if (box().hasAutoVerticalScrollbar()) 687 if (box().hasAutoVerticalScrollbar())
701 setHasVerticalScrollbar(hasVerticalOverflow); 688 setHasVerticalScrollbar(hasVerticalOverflow);
702 else if (box().style()->overflowY() == OverflowScroll) 689 else if (box().style()->overflowY() == OverflowScroll)
703 setHasVerticalScrollbar(true); 690 setHasVerticalScrollbar(true);
704 691
705 if (hasVerticalOverflow || hasHorizontalOverflow) 692 if (hasVerticalOverflow || hasHorizontalOverflow)
706 updateScrollCornerStyle(); 693 updateScrollCornerStyle();
707 694
708 layer()->updateSelfPaintingLayer(); 695 layer()->updateSelfPaintingLayer();
709 696
710 // Force an update since we know the scrollbars have changed things. 697 // Force an update since we know the scrollbars have changed things.
711 if (box().document().hasAnnotatedRegions()) 698 if (box().document().hasAnnotatedRegions())
712 box().document().setAnnotatedRegionsDirty(true); 699 box().document().setAnnotatedRegionsDirty(true);
713 700
714 // Our proprietary overflow: overlay value doesn't trigger a layout. 701 // Our proprietary overflow: overlay value doesn't trigger a layout.
715 if ((horizontalScrollBarChanged && box().style()->overflowX() != Overflo wOverlay) || (verticalScrollBarChanged && box().style()->overflowY() != Overflow Overlay)) { 702 if ((horizontalScrollBarChanged && box().style()->overflowX() != Overflo wOverlay) || (verticalScrollBarChanged && box().style()->overflowY() != Overflow Overlay)) {
716 if (!m_inOverflowRelayout) { 703 if (!m_inOverflowRelayout) {
717 m_inOverflowRelayout = true; 704 if (relayoutIsPrevented) {
718 if (delayedLayoutScope) {
719 if (box().isLayoutBlock()) 705 if (box().isLayoutBlock())
720 toLayoutBlock(box()).scrollbarsChanged(horizontalScrollB arChanged, verticalScrollBarChanged); 706 toLayoutBlock(box()).scrollbarsChanged(horizontalScrollB arChanged, verticalScrollBarChanged);
721 delayedLayoutScope->setNeedsLayout(&box(), LayoutInvalidatio nReason::ScrollbarChanged); 707 PreventRelayoutScope::setNeedsLayout(box());
722 didMarkForDelayedLayout = true;
723 } else { 708 } else {
709 m_inOverflowRelayout = true;
724 SubtreeLayoutScope layoutScope(box()); 710 SubtreeLayoutScope layoutScope(box());
725 layoutScope.setNeedsLayout(&box(), LayoutInvalidationReason: :ScrollbarChanged); 711 layoutScope.setNeedsLayout(&box(), LayoutInvalidationReason: :ScrollbarChanged);
726 if (box().isLayoutBlock()) { 712 if (box().isLayoutBlock()) {
727 LayoutBlock& block = toLayoutBlock(box()); 713 LayoutBlock& block = toLayoutBlock(box());
728 block.scrollbarsChanged(horizontalScrollBarChanged, vert icalScrollBarChanged); 714 block.scrollbarsChanged(horizontalScrollBarChanged, vert icalScrollBarChanged);
729 block.layoutBlock(true); 715 block.layoutBlock(true);
730 } else { 716 } else {
731 box().layout(); 717 box().layout();
732 } 718 }
719 m_inOverflowRelayout = false;
720 m_scrollbarManager.destroyDetachedScrollbars();
733 } 721 }
734 LayoutObject* parent = box().parent(); 722 LayoutObject* parent = box().parent();
735 if (parent && parent->isFlexibleBox()) 723 if (parent && parent->isFlexibleBox())
736 toLayoutFlexibleBox(parent)->clearCachedMainSizeForChild(box ()); 724 toLayoutFlexibleBox(parent)->clearCachedMainSizeForChild(box ());
737 m_inOverflowRelayout = false;
738 } 725 }
739 } 726 }
740 } 727 }
741 728
742 { 729 {
743 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html. 730 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html.
744 DisableCompositingQueryAsserts disabler; 731 DisableCompositingQueryAsserts disabler;
745 732
746 // Set up the range (and page step/line step). 733 // Set up the range (and page step/line step).
747 if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) { 734 if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) {
748 int clientWidth = box().pixelSnappedClientWidth(); 735 int clientWidth = box().pixelSnappedClientWidth();
749 horizontalScrollbar->setProportion(clientWidth, overflowRect().width ()); 736 horizontalScrollbar->setProportion(clientWidth, overflowRect().width ());
750 } 737 }
751 if (Scrollbar* verticalScrollbar = this->verticalScrollbar()) { 738 if (Scrollbar* verticalScrollbar = this->verticalScrollbar()) {
752 int clientHeight = box().pixelSnappedClientHeight(); 739 int clientHeight = box().pixelSnappedClientHeight();
753 verticalScrollbar->setProportion(clientHeight, overflowRect().height ()); 740 verticalScrollbar->setProportion(clientHeight, overflowRect().height ());
754 } 741 }
755 } 742 }
756 743
757 if (hasOverlayScrollbars()) { 744 if (!scrollbarsAreFrozen && hasOverlayScrollbars()) {
758 if (!scrollSize(HorizontalScrollbar)) 745 if (!scrollSize(HorizontalScrollbar))
759 setHasHorizontalScrollbar(false); 746 setHasHorizontalScrollbar(false);
760 if (!scrollSize(VerticalScrollbar)) 747 if (!scrollSize(VerticalScrollbar))
761 setHasVerticalScrollbar(false); 748 setHasVerticalScrollbar(false);
762 } 749 }
763 750
764 bool hasOverflow = hasScrollableHorizontalOverflow() || hasScrollableVertica lOverflow(); 751 clampScrollPositionsAfterLayout();
765 updateScrollableAreaSet(hasOverflow); 752
753 if (!scrollbarsAreFrozen) {
754 bool hasOverflow = hasScrollableHorizontalOverflow() || hasScrollableVer ticalOverflow();
755 updateScrollableAreaSet(hasOverflow);
756 }
766 757
767 DisableCompositingQueryAsserts disabler; 758 DisableCompositingQueryAsserts disabler;
768 positionOverflowControls(); 759 positionOverflowControls();
760 }
769 761
770 return didMarkForDelayedLayout; 762
763 void PaintLayerScrollableArea::clampScrollPositionsAfterLayout()
764 {
765 // If a vertical scrollbar was removed, the min/max scroll positions may hav e changed,
766 // so the scroll positions needs to be clamped. If the scroll position did not change,
767 // but the scroll origin *did* change, we still need to notify the scrollbar s to
768 // update their dimensions.
769
770 if (DelayScrollPositionClampScope::clampingIsDelayed()) {
771 DelayScrollPositionClampScope::setNeedsClamp(this);
772 return;
773 }
774
775 DoublePoint newScrollPosition = clampScrollPosition(scrollPositionDouble());
776 if (newScrollPosition != scrollPositionDouble())
777 ScrollableArea::setScrollPosition(newScrollPosition, ProgrammaticScroll) ;
778 else if (scrollOriginChanged())
779 scrollPositionChanged(newScrollPosition, ProgrammaticScroll);
780
781 setNeedsScrollPositionClamp(false);
782 resetScrollOriginChanged();
771 } 783 }
772 784
773 ScrollBehavior PaintLayerScrollableArea::scrollBehaviorStyle() const 785 ScrollBehavior PaintLayerScrollableArea::scrollBehaviorStyle() const
774 { 786 {
775 return box().style()->getScrollBehavior(); 787 return box().style()->getScrollBehavior();
776 } 788 }
777 789
778 bool PaintLayerScrollableArea::hasHorizontalOverflow() const 790 bool PaintLayerScrollableArea::hasHorizontalOverflow() const
779 { 791 {
780 return pixelSnappedScrollWidth() > box().pixelSnappedClientWidth(); 792 return pixelSnappedScrollWidth() > box().pixelSnappedClientWidth();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // Avoid drawing two sets of scrollbars when one is provided by the visual v iewport. 840 // Avoid drawing two sets of scrollbars when one is provided by the visual v iewport.
829 if (visualViewportSuppliesScrollbars()) { 841 if (visualViewportSuppliesScrollbars()) {
830 setHasHorizontalScrollbar(false); 842 setHasHorizontalScrollbar(false);
831 setHasVerticalScrollbar(false); 843 setHasVerticalScrollbar(false);
832 return; 844 return;
833 } 845 }
834 846
835 EOverflow overflowX = box().style()->overflowX(); 847 EOverflow overflowX = box().style()->overflowX();
836 EOverflow overflowY = box().style()->overflowY(); 848 EOverflow overflowY = box().style()->overflowY();
837 849
838 // To avoid doing a relayout in updateScrollbarsAfterLayout, we try to keep any automatic scrollbar that was already present.
839 bool needsHorizontalScrollbar = (hasHorizontalScrollbar() && overflowDefines AutomaticScrollbar(overflowX)) || overflowRequiresScrollbar(overflowX); 850 bool needsHorizontalScrollbar = (hasHorizontalScrollbar() && overflowDefines AutomaticScrollbar(overflowX)) || overflowRequiresScrollbar(overflowX);
840 bool needsVerticalScrollbar = (hasVerticalScrollbar() && overflowDefinesAuto maticScrollbar(overflowY)) || overflowRequiresScrollbar(overflowY); 851 bool needsVerticalScrollbar = (hasVerticalScrollbar() && overflowDefinesAuto maticScrollbar(overflowY)) || overflowRequiresScrollbar(overflowY);
841 852
842 // Look for the scrollbarModes and reset the needs Horizontal & vertical Scr ollbar values based on scrollbarModes, as during force style change 853 // Look for the scrollbarModes and reset the needs Horizontal & vertical Scr ollbar values based on scrollbarModes, as during force style change
843 // StyleResolver::styleForDocument returns documentStyle with no overflow v alues, due to which we are destorying the scrollbars that was 854 // StyleResolver::styleForDocument returns documentStyle with no overflow v alues, due to which we are destorying the scrollbars that was
844 // already present. 855 // already present.
845 if (box().isLayoutView()) { 856 if (box().isLayoutView()) {
846 if (LocalFrame* frame = box().frame()) { 857 if (LocalFrame* frame = box().frame()) {
847 if (FrameView* frameView = frame->view()) { 858 if (FrameView* frameView = frame->view()) {
848 ScrollbarMode hMode; 859 ScrollbarMode hMode;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 { 910 {
900 layer()->updateScrollingStateAfterCompositingChange(); 911 layer()->updateScrollingStateAfterCompositingChange();
901 const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild; 912 const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild;
902 m_topmostScrollChild = m_nextTopmostScrollChild; 913 m_topmostScrollChild = m_nextTopmostScrollChild;
903 m_nextTopmostScrollChild = nullptr; 914 m_nextTopmostScrollChild = nullptr;
904 return layersChanged; 915 return layersChanged;
905 } 916 }
906 917
907 void PaintLayerScrollableArea::updateAfterOverflowRecalc() 918 void PaintLayerScrollableArea::updateAfterOverflowRecalc()
908 { 919 {
909 computeScrollDimensions(); 920 updateScrollDimensions();
910 if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) { 921 if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) {
911 int clientWidth = box().pixelSnappedClientWidth(); 922 int clientWidth = box().pixelSnappedClientWidth();
912 horizontalScrollbar->setProportion(clientWidth, overflowRect().width()); 923 horizontalScrollbar->setProportion(clientWidth, overflowRect().width());
913 } 924 }
914 if (Scrollbar* verticalScrollbar = this->verticalScrollbar()) { 925 if (Scrollbar* verticalScrollbar = this->verticalScrollbar()) {
915 int clientHeight = box().pixelSnappedClientHeight(); 926 int clientHeight = box().pixelSnappedClientHeight();
916 verticalScrollbar->setProportion(clientHeight, overflowRect().height()); 927 verticalScrollbar->setProportion(clientHeight, overflowRect().height());
917 } 928 }
918 929
919 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 930 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 if (hasVerticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) { 1042 if (hasVerticalScrollbar() && verticalScrollbar()->isCustomScrollbar()) {
1032 if (actualLayoutObject != toLayoutScrollbar(verticalScrollbar())->owning LayoutObject()) 1043 if (actualLayoutObject != toLayoutScrollbar(verticalScrollbar())->owning LayoutObject())
1033 didCustomScrollbarOwnerChanged = true; 1044 didCustomScrollbarOwnerChanged = true;
1034 } 1045 }
1035 1046
1036 return hasAnyScrollbar && ((shouldUseCustom != hasCustom) || (shouldUseCusto m && didCustomScrollbarOwnerChanged)); 1047 return hasAnyScrollbar && ((shouldUseCustom != hasCustom) || (shouldUseCusto m && didCustomScrollbarOwnerChanged));
1037 } 1048 }
1038 1049
1039 void PaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrollbar) 1050 void PaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrollbar)
1040 { 1051 {
1052 if (FreezeScrollbarsScope::scrollbarsAreFrozen())
1053 return;
1054
1041 if (hasScrollbar == hasHorizontalScrollbar()) 1055 if (hasScrollbar == hasHorizontalScrollbar())
1042 return; 1056 return;
1043 1057
1044 setScrollbarNeedsPaintInvalidation(HorizontalScrollbar); 1058 setScrollbarNeedsPaintInvalidation(HorizontalScrollbar);
1045 1059
1046 m_scrollbarManager.setHasHorizontalScrollbar(hasScrollbar); 1060 m_scrollbarManager.setHasHorizontalScrollbar(hasScrollbar, !m_inOverflowRela yout);
1061
1062 updateScrollOrigin();
1047 1063
1048 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style. 1064 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style.
1049 if (hasHorizontalScrollbar()) 1065 if (hasHorizontalScrollbar())
1050 horizontalScrollbar()->styleChanged(); 1066 horizontalScrollbar()->styleChanged();
1051 if (hasVerticalScrollbar()) 1067 if (hasVerticalScrollbar())
1052 verticalScrollbar()->styleChanged(); 1068 verticalScrollbar()->styleChanged();
1053 1069
1054 setScrollCornerNeedsPaintInvalidation(); 1070 setScrollCornerNeedsPaintInvalidation();
1055 1071
1056 // Force an update since we know the scrollbars have changed things. 1072 // Force an update since we know the scrollbars have changed things.
1057 if (box().document().hasAnnotatedRegions()) 1073 if (box().document().hasAnnotatedRegions())
1058 box().document().setAnnotatedRegionsDirty(true); 1074 box().document().setAnnotatedRegionsDirty(true);
1059 } 1075 }
1060 1076
1061 void PaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollbar) 1077 void PaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollbar)
1062 { 1078 {
1079 if (FreezeScrollbarsScope::scrollbarsAreFrozen())
1080 return;
1081
1063 if (hasScrollbar == hasVerticalScrollbar()) 1082 if (hasScrollbar == hasVerticalScrollbar())
1064 return; 1083 return;
1065 1084
1066 setScrollbarNeedsPaintInvalidation(VerticalScrollbar); 1085 setScrollbarNeedsPaintInvalidation(VerticalScrollbar);
1067 1086
1068 m_scrollbarManager.setHasVerticalScrollbar(hasScrollbar); 1087 m_scrollbarManager.setHasVerticalScrollbar(hasScrollbar, !m_inOverflowRelayo ut);
1088
1089 updateScrollOrigin();
1069 1090
1070 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style. 1091 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style.
1071 if (hasHorizontalScrollbar()) 1092 if (hasHorizontalScrollbar())
1072 horizontalScrollbar()->styleChanged(); 1093 horizontalScrollbar()->styleChanged();
1073 if (hasVerticalScrollbar()) 1094 if (hasVerticalScrollbar())
1074 verticalScrollbar()->styleChanged(); 1095 verticalScrollbar()->styleChanged();
1075 1096
1076 setScrollCornerNeedsPaintInvalidation(); 1097 setScrollCornerNeedsPaintInvalidation();
1077 1098
1078 // Force an update since we know the scrollbars have changed things. 1099 // Force an update since we know the scrollbars have changed things.
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 { 1550 {
1530 if (LocalFrame* frame = box().frame()) { 1551 if (LocalFrame* frame = box().frame()) {
1531 if (Page* page = frame->page()) 1552 if (Page* page = frame->page())
1532 return page->scrollingCoordinator() ? page->scrollingCoordinator()-> compositorAnimationTimeline() : nullptr; 1553 return page->scrollingCoordinator() ? page->scrollingCoordinator()-> compositorAnimationTimeline() : nullptr;
1533 } 1554 }
1534 return nullptr; 1555 return nullptr;
1535 } 1556 }
1536 1557
1537 PaintLayerScrollableArea::ScrollbarManager::ScrollbarManager(PaintLayerScrollabl eArea& scrollableArea) 1558 PaintLayerScrollableArea::ScrollbarManager::ScrollbarManager(PaintLayerScrollabl eArea& scrollableArea)
1538 : m_scrollableArea(&scrollableArea) 1559 : m_scrollableArea(&scrollableArea)
1539 , m_canDetachScrollbars(0)
1540 , m_hBarIsAttached(0) 1560 , m_hBarIsAttached(0)
1541 , m_vBarIsAttached(0) 1561 , m_vBarIsAttached(0)
1542 { 1562 {
1543 } 1563 }
1544 1564
1545 void PaintLayerScrollableArea::ScrollbarManager::dispose() 1565 void PaintLayerScrollableArea::ScrollbarManager::dispose()
1546 { 1566 {
1547 m_canDetachScrollbars = m_hBarIsAttached = m_vBarIsAttached = 0; 1567 m_hBarIsAttached = m_vBarIsAttached = 0;
1548 destroyScrollbar(HorizontalScrollbar); 1568 destroyScrollbar(HorizontalScrollbar);
1549 destroyScrollbar(VerticalScrollbar); 1569 destroyScrollbar(VerticalScrollbar);
1550 } 1570 }
1551 1571
1552 void PaintLayerScrollableArea::ScrollbarManager::setCanDetachScrollbars(bool det ach) 1572 void PaintLayerScrollableArea::ScrollbarManager::destroyDetachedScrollbars()
1553 { 1573 {
1554 ASSERT(!m_hBarIsAttached || m_hBar); 1574 ASSERT(!m_hBarIsAttached || m_hBar);
1555 ASSERT(!m_vBarIsAttached || m_vBar); 1575 ASSERT(!m_vBarIsAttached || m_vBar);
1556 m_canDetachScrollbars = detach ? 1 : 0; 1576 if (m_hBar && !m_hBarIsAttached)
1557 if (!detach) { 1577 destroyScrollbar(HorizontalScrollbar);
1558 if (m_hBar && !m_hBarIsAttached) 1578 if (m_vBar && !m_vBarIsAttached)
1559 destroyScrollbar(HorizontalScrollbar); 1579 destroyScrollbar(VerticalScrollbar);
1560 if (m_vBar && !m_vBarIsAttached)
1561 destroyScrollbar(VerticalScrollbar);
1562 }
1563 } 1580 }
1564 1581
1565 void PaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrollbar(bool hasScrollbar) 1582 void PaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrollbar(bool hasScrollbar, bool canDetach)
1566 { 1583 {
1567 if (hasScrollbar) { 1584 if (hasScrollbar) {
1568 // This doesn't hit in any tests, but since the equivalent code in setHa sVerticalScrollbar 1585 // This doesn't hit in any tests, but since the equivalent code in setHa sVerticalScrollbar
1569 // does, presumably this code does as well. 1586 // does, presumably this code does as well.
1570 DisableCompositingQueryAsserts disabler; 1587 DisableCompositingQueryAsserts disabler;
1571 if (!m_hBar) { 1588 if (!m_hBar) {
1572 m_hBar = createScrollbar(HorizontalScrollbar); 1589 m_hBar = createScrollbar(HorizontalScrollbar);
1573 m_hBarIsAttached = 1; 1590 m_hBarIsAttached = 1;
1574 if (!m_hBar->isCustomScrollbar()) 1591 if (!m_hBar->isCustomScrollbar())
1575 m_scrollableArea->didAddScrollbar(*m_hBar, HorizontalScrollbar); 1592 m_scrollableArea->didAddScrollbar(*m_hBar, HorizontalScrollbar);
1576 } else { 1593 } else {
1577 m_hBarIsAttached = 1; 1594 m_hBarIsAttached = 1;
1578 } 1595 }
1579
1580 } else { 1596 } else {
1581 m_hBarIsAttached = 0; 1597 m_hBarIsAttached = 0;
1582 if (!m_canDetachScrollbars) 1598 if (!canDetach)
1583 destroyScrollbar(HorizontalScrollbar); 1599 destroyScrollbar(HorizontalScrollbar);
1584 } 1600 }
1585 } 1601 }
1586 1602
1587 void PaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollbar(bool ha sScrollbar) 1603 void PaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollbar(bool ha sScrollbar, bool canDetach)
1588 { 1604 {
1589 if (hasScrollbar) { 1605 if (hasScrollbar) {
1590 DisableCompositingQueryAsserts disabler; 1606 DisableCompositingQueryAsserts disabler;
1591 if (!m_vBar) { 1607 if (!m_vBar) {
1592 m_vBar = createScrollbar(VerticalScrollbar); 1608 m_vBar = createScrollbar(VerticalScrollbar);
1593 m_vBarIsAttached = 1; 1609 m_vBarIsAttached = 1;
1594 if (!m_vBar->isCustomScrollbar()) 1610 if (!m_vBar->isCustomScrollbar())
1595 m_scrollableArea->didAddScrollbar(*m_vBar, VerticalScrollbar); 1611 m_scrollableArea->didAddScrollbar(*m_vBar, VerticalScrollbar);
1596 } else { 1612 } else {
1597 m_vBarIsAttached = 1; 1613 m_vBarIsAttached = 1;
1598 } 1614 }
1599
1600 } else { 1615 } else {
1601 m_vBarIsAttached = 0; 1616 m_vBarIsAttached = 0;
1602 if (!m_canDetachScrollbars) 1617 if (!canDetach)
1603 destroyScrollbar(VerticalScrollbar); 1618 destroyScrollbar(VerticalScrollbar);
1604 } 1619 }
1605 } 1620 }
1606 1621
1607 Scrollbar* PaintLayerScrollableArea::ScrollbarManager::createScrollbar(Scrollbar Orientation orientation) 1622 Scrollbar* PaintLayerScrollableArea::ScrollbarManager::createScrollbar(Scrollbar Orientation orientation)
1608 { 1623 {
1609 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached : !m_vBarIsAtt ached); 1624 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached : !m_vBarIsAtt ached);
1610 Scrollbar* scrollbar = nullptr; 1625 Scrollbar* scrollbar = nullptr;
1611 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(m_scrollab leArea->box()); 1626 const LayoutObject& actualLayoutObject = layoutObjectForScrollbar(m_scrollab leArea->box());
1612 bool hasCustomScrollbarStyle = actualLayoutObject.isBox() && actualLayoutObj ect.styleRef().hasPseudoStyle(PseudoIdScrollbar); 1627 bool hasCustomScrollbarStyle = actualLayoutObject.isBox() && actualLayoutObj ect.styleRef().hasPseudoStyle(PseudoIdScrollbar);
(...skipping 30 matching lines...) Expand all
1643 scrollbar = nullptr; 1658 scrollbar = nullptr;
1644 } 1659 }
1645 1660
1646 DEFINE_TRACE(PaintLayerScrollableArea::ScrollbarManager) 1661 DEFINE_TRACE(PaintLayerScrollableArea::ScrollbarManager)
1647 { 1662 {
1648 visitor->trace(m_scrollableArea); 1663 visitor->trace(m_scrollableArea);
1649 visitor->trace(m_hBar); 1664 visitor->trace(m_hBar);
1650 visitor->trace(m_vBar); 1665 visitor->trace(m_vBar);
1651 } 1666 }
1652 1667
1668 int PaintLayerScrollableArea::PreventRelayoutScope::m_count = 0;
1669 SubtreeLayoutScope* PaintLayerScrollableArea::PreventRelayoutScope::m_layoutScop e = nullptr;
1670 bool PaintLayerScrollableArea::PreventRelayoutScope::m_relayoutNeeded = false;
1671 WTF::Vector<LayoutObject*>* PaintLayerScrollableArea::PreventRelayoutScope::m_ne edsRelayout = nullptr;
1672
1673 PaintLayerScrollableArea::PreventRelayoutScope::PreventRelayoutScope(SubtreeLayo utScope& layoutScope)
1674 {
1675 if (!m_count) {
1676 ASSERT(!m_layoutScope);
1677 ASSERT(!m_needsRelayout || m_needsRelayout->isEmpty());
1678 m_layoutScope = &layoutScope;
1679 }
1680 PreventRelayoutScope::increment();
cbiesinger 2016/04/29 20:02:50 Why not just increment()? Also, why do increment(
szager1 2016/05/12 20:44:51 Yeah, I had other callers before, but they're gone
1681 }
1682
1683 PaintLayerScrollableArea::PreventRelayoutScope::~PreventRelayoutScope()
1684 {
1685 PreventRelayoutScope::decrement();
cbiesinger 2016/04/29 20:02:50 same here
szager1 2016/05/12 20:44:51 Done.
1686 }
1687
1688 void PaintLayerScrollableArea::PreventRelayoutScope::increment()
1689 {
1690 ASSERT(m_count == 0 || m_layoutScope);
1691 m_count++;
1692 }
1693
1694 void PaintLayerScrollableArea::PreventRelayoutScope::decrement()
1695 {
1696 if (--m_count == 0) {
1697 if (m_relayoutNeeded) {
1698 for (auto layoutObject : *m_needsRelayout)
1699 m_layoutScope->setNeedsLayout(layoutObject, LayoutInvalidationRe ason::ScrollbarChanged);
1700 m_needsRelayout->clear();
1701 }
1702 m_layoutScope = nullptr;
1703 }
1704 }
1705
1706 void PaintLayerScrollableArea::PreventRelayoutScope::setNeedsLayout(LayoutObject & layoutObject)
1707 {
1708 ASSERT(m_count);
1709 ASSERT(m_layoutScope);
1710 m_relayoutNeeded = true;
1711 if (!m_needsRelayout)
1712 m_needsRelayout = new WTF::Vector<LayoutObject*>();
1713 m_needsRelayout->append(&layoutObject);
1714 }
1715
1716 void PaintLayerScrollableArea::PreventRelayoutScope::resetRelayoutNeeded()
1717 {
1718 ASSERT(m_count == 0);
1719 if (m_needsRelayout)
1720 m_needsRelayout->clear();
cbiesinger 2016/04/29 20:02:50 This is for the case that the second pass may have
szager1 2016/05/12 20:44:51 Actually, no, this should ASSERT(!m_needsRelayout
1721 m_relayoutNeeded = false;
1722 }
1723
1724 int PaintLayerScrollableArea::FreezeScrollbarsScope::m_count = 0;
1725
1726 int PaintLayerScrollableArea::DelayScrollPositionClampScope::m_count = 0;
1727 PersistentHeapVector<Member<PaintLayerScrollableArea>>* PaintLayerScrollableArea ::DelayScrollPositionClampScope::m_needsClamp = nullptr;
1728
1729 PaintLayerScrollableArea::DelayScrollPositionClampScope::DelayScrollPositionClam pScope()
1730 {
1731 if (!m_needsClamp)
1732 m_needsClamp = new PersistentHeapVector<Member<PaintLayerScrollableArea> >();
cbiesinger 2016/04/29 20:02:50 Oilpan confuses me, I trust that this is the right
szager1 2016/05/12 20:44:51 These are basically static vectors that never get
1733 ASSERT(m_count > 0 || m_needsClamp->isEmpty());
cbiesinger 2016/04/29 20:02:50 By the way, please name all static members as s_fo
szager1 2016/05/12 20:44:51 Done.
1734 DelayScrollPositionClampScope::increment();
cbiesinger 2016/04/29 20:02:50 Again, why have these increment/decrement methods
szager1 2016/05/12 20:44:51 Got rid of these.
1735 }
1736
1737 PaintLayerScrollableArea::DelayScrollPositionClampScope::~DelayScrollPositionCla mpScope()
1738 {
1739 DelayScrollPositionClampScope::decrement();
1740 }
1741
1742 void PaintLayerScrollableArea::DelayScrollPositionClampScope::increment()
1743 {
1744 m_count++;
1745 }
1746
1747 void PaintLayerScrollableArea::DelayScrollPositionClampScope::decrement()
1748 {
1749 if (--m_count == 0)
1750 DelayScrollPositionClampScope::clampScrollableAreas();
1751 }
1752
1753 void PaintLayerScrollableArea::DelayScrollPositionClampScope::setNeedsClamp(Pain tLayerScrollableArea* scrollableArea)
1754 {
1755 if (!scrollableArea->needsScrollPositionClamp()) {
1756 scrollableArea->setNeedsScrollPositionClamp(true);
1757 m_needsClamp->append(scrollableArea);
1758 }
1759 }
1760
1761 void PaintLayerScrollableArea::DelayScrollPositionClampScope::clampScrollableAre as()
1762 {
1763 for (auto& scrollableArea : *m_needsClamp)
1764 scrollableArea->clampScrollPositionsAfterLayout();
1765 delete m_needsClamp;
1766 m_needsClamp = nullptr;
1767 }
1768
1653 } // namespace blink 1769 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698