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

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

Issue 1357423007: Avoid scrollbar construction/destruction thrashing during flex layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Comment fixes. Created 5 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
« no previous file with comments | « third_party/WebKit/Source/core/paint/DeprecatedPaintLayerScrollableArea.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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@web.de> 9 * Christian Biesinger <cbiesinger@web.de>
10 * Randall Jesup <rjesup@wgate.com> 10 * Randall Jesup <rjesup@wgate.com>
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 const int ResizerControlExpandRatioForTouch = 2; 81 const int ResizerControlExpandRatioForTouch = 2;
82 82
83 DeprecatedPaintLayerScrollableArea::DeprecatedPaintLayerScrollableArea(Deprecate dPaintLayer& layer) 83 DeprecatedPaintLayerScrollableArea::DeprecatedPaintLayerScrollableArea(Deprecate dPaintLayer& layer)
84 : m_layer(layer) 84 : m_layer(layer)
85 , m_inResizeMode(false) 85 , m_inResizeMode(false)
86 , m_scrollsOverflow(false) 86 , m_scrollsOverflow(false)
87 , m_inOverflowRelayout(false) 87 , m_inOverflowRelayout(false)
88 , m_nextTopmostScrollChild(0) 88 , m_nextTopmostScrollChild(0)
89 , m_topmostScrollChild(0) 89 , m_topmostScrollChild(0)
90 , m_needsCompositedScrolling(false) 90 , m_needsCompositedScrolling(false)
91 , m_scrollbarManager(*this)
91 , m_scrollCorner(nullptr) 92 , m_scrollCorner(nullptr)
92 , m_resizer(nullptr) 93 , m_resizer(nullptr)
93 #if ENABLE(ASSERT) 94 #if ENABLE(ASSERT)
94 , m_hasBeenDisposed(false) 95 , m_hasBeenDisposed(false)
95 #endif 96 #endif
96 { 97 {
97 Node* node = box().node(); 98 Node* node = box().node();
98 if (node && node->isElementNode()) { 99 if (node && node->isElementNode()) {
99 // We save and restore only the scrollOffset as the other scroll values are recalculated. 100 // We save and restore only the scrollOffset as the other scroll values are recalculated.
100 Element* element = toElement(node); 101 Element* element = toElement(node);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // FIXME: Make setSavedLayerScrollOffset take DoubleSize. crbug.com/4142 83. 136 // FIXME: Make setSavedLayerScrollOffset take DoubleSize. crbug.com/4142 83.
136 if (node && node->isElementNode()) 137 if (node && node->isElementNode())
137 toElement(node)->setSavedLayerScrollOffset(flooredIntSize(m_scrollOf fset)); 138 toElement(node)->setSavedLayerScrollOffset(flooredIntSize(m_scrollOf fset));
138 } 139 }
139 140
140 if (LocalFrame* frame = box().frame()) { 141 if (LocalFrame* frame = box().frame()) {
141 if (FrameView* frameView = frame->view()) 142 if (FrameView* frameView = frame->view())
142 frameView->removeResizerArea(box()); 143 frameView->removeResizerArea(box());
143 } 144 }
144 145
145 destroyScrollbar(HorizontalScrollbar); 146 m_scrollbarManager.dispose();
146 destroyScrollbar(VerticalScrollbar);
147 147
148 if (m_scrollCorner) 148 if (m_scrollCorner)
149 m_scrollCorner->destroy(); 149 m_scrollCorner->destroy();
150 if (m_resizer) 150 if (m_resizer)
151 m_resizer->destroy(); 151 m_resizer->destroy();
152 152
153 clearScrollAnimators(); 153 clearScrollAnimators();
154 154
155 #if ENABLE(ASSERT) 155 #if ENABLE(ASSERT)
156 m_hasBeenDisposed = true; 156 m_hasBeenDisposed = true;
157 #endif 157 #endif
158 } 158 }
159 159
160 DEFINE_TRACE(DeprecatedPaintLayerScrollableArea) 160 DEFINE_TRACE(DeprecatedPaintLayerScrollableArea)
161 { 161 {
162 visitor->trace(m_hBar); 162 m_scrollbarManager.trace(visitor);
163 visitor->trace(m_vBar);
164 ScrollableArea::trace(visitor); 163 ScrollableArea::trace(visitor);
165 } 164 }
166 165
167 HostWindow* DeprecatedPaintLayerScrollableArea::hostWindow() const 166 HostWindow* DeprecatedPaintLayerScrollableArea::hostWindow() const
168 { 167 {
169 if (Page* page = box().frame()->page()) 168 if (Page* page = box().frame()->page())
170 return &page->chromeClient(); 169 return &page->chromeClient();
171 return nullptr; 170 return nullptr;
172 } 171 }
173 172
(...skipping 24 matching lines...) Expand all
198 DisableCompositingQueryAsserts disabler; 197 DisableCompositingQueryAsserts disabler;
199 198
200 return layer()->hasCompositedDeprecatedPaintLayerMapping() ? layer()->compos itedDeprecatedPaintLayerMapping()->layerForScrollCorner() : 0; 199 return layer()->hasCompositedDeprecatedPaintLayerMapping() ? layer()->compos itedDeprecatedPaintLayerMapping()->layerForScrollCorner() : 0;
201 } 200 }
202 201
203 void DeprecatedPaintLayerScrollableArea::invalidateScrollbarRect(Scrollbar* scro llbar, const IntRect& rect) 202 void DeprecatedPaintLayerScrollableArea::invalidateScrollbarRect(Scrollbar* scro llbar, const IntRect& rect)
204 { 203 {
205 // See crbug.com/343132. 204 // See crbug.com/343132.
206 DisableCompositingQueryAsserts disabler; 205 DisableCompositingQueryAsserts disabler;
207 206
208 ASSERT(scrollbar == m_hBar.get() || scrollbar == m_vBar.get()); 207 ASSERT(scrollbar == horizontalScrollbar() || scrollbar == verticalScrollbar( ));
209 ASSERT(scrollbar == m_hBar.get() ? !layerForHorizontalScrollbar() : !layerFo rVerticalScrollbar()); 208 ASSERT(scrollbar == horizontalScrollbar() ? !layerForHorizontalScrollbar() : !layerForVerticalScrollbar());
210 209
211 IntRect scrollRect = rect; 210 IntRect scrollRect = rect;
212 // If we are not yet inserted into the tree, there is no need to issue paint invaldiations. 211 // If we are not yet inserted into the tree, there is no need to issue paint invaldiations.
213 if (!box().isLayoutView() && !box().parent()) 212 if (!box().isLayoutView() && !box().parent())
214 return; 213 return;
215 214
216 if (scrollbar == m_vBar.get()) 215 if (scrollbar == verticalScrollbar())
217 scrollRect.move(verticalScrollbarStart(0, box().size().width()), box().b orderTop()); 216 scrollRect.move(verticalScrollbarStart(0, box().size().width()), box().b orderTop());
218 else 217 else
219 scrollRect.move(horizontalScrollbarStart(0), box().size().height() - box ().borderBottom() - scrollbar->height()); 218 scrollRect.move(horizontalScrollbarStart(0), box().size().height() - box ().borderBottom() - scrollbar->height());
220 219
221 if (scrollRect.isEmpty()) 220 if (scrollRect.isEmpty())
222 return; 221 return;
223 222
224 box().invalidateDisplayItemClient(*scrollbar); 223 box().invalidateDisplayItemClient(*scrollbar);
225 224
226 LayoutRect paintInvalidationRect = LayoutRect(scrollRect); 225 LayoutRect paintInvalidationRect = LayoutRect(scrollRect);
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 DoublePoint newScrollPosition = clamp == ScrollOffsetClamped ? clampScrollPo sition(scrollPosition) : scrollPosition; 645 DoublePoint newScrollPosition = clamp == ScrollOffsetClamped ? clampScrollPo sition(scrollPosition) : scrollPosition;
647 if (newScrollPosition != scrollPositionDouble()) 646 if (newScrollPosition != scrollPositionDouble())
648 ScrollableArea::setScrollPosition(newScrollPosition, ProgrammaticScroll, scrollBehavior); 647 ScrollableArea::setScrollPosition(newScrollPosition, ProgrammaticScroll, scrollBehavior);
649 } 648 }
650 649
651 void DeprecatedPaintLayerScrollableArea::updateScrollDimensions(DoubleSize& scro llOffset, bool& autoHorizontalScrollBarChanged, bool& autoVerticalScrollBarChang ed) 650 void DeprecatedPaintLayerScrollableArea::updateScrollDimensions(DoubleSize& scro llOffset, bool& autoHorizontalScrollBarChanged, bool& autoVerticalScrollBarChang ed)
652 { 651 {
653 ASSERT(box().hasOverflowClip()); 652 ASSERT(box().hasOverflowClip());
654 653
655 if (needsScrollbarReconstruction()) { 654 if (needsScrollbarReconstruction()) {
656 if (m_hBar) 655 m_scrollbarManager.setCanDetachScrollbars(false);
657 destroyScrollbar(HorizontalScrollbar); 656 setHasHorizontalScrollbar(false);
658 if (m_vBar) 657 setHasVerticalScrollbar(false);
659 destroyScrollbar(VerticalScrollbar);
660 } 658 }
661 659
660 m_scrollbarManager.setCanDetachScrollbars(true);
661
662 scrollOffset = adjustedScrollOffset(); 662 scrollOffset = adjustedScrollOffset();
663 computeScrollDimensions(); 663 computeScrollDimensions();
664 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 664 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
665 bool hasVerticalOverflow = this->hasVerticalOverflow(); 665 bool hasVerticalOverflow = this->hasVerticalOverflow();
666 if (hasOverlayScrollbars()) { 666 if (hasOverlayScrollbars()) {
667 if (!scrollSize(HorizontalScrollbar)) 667 if (!scrollSize(HorizontalScrollbar))
668 setHasHorizontalScrollbar(false); 668 setHasHorizontalScrollbar(false);
669 if (!scrollSize(VerticalScrollbar)) 669 if (!scrollSize(VerticalScrollbar))
670 setHasVerticalScrollbar(false); 670 setHasVerticalScrollbar(false);
671 } 671 }
672 672
673 // overflow:auto may need to lay out again if scrollbars got added/removed. 673 // overflow:auto may need to lay out again if scrollbars got added/removed.
674 autoHorizontalScrollBarChanged = (box().hasAutoHorizontalScrollbar() && (has HorizontalScrollbar() != hasHorizontalOverflow)) || (box().style()->overflowX() == OSCROLL && !horizontalScrollbar()); 674 autoHorizontalScrollBarChanged = (box().hasAutoHorizontalScrollbar() && (has HorizontalScrollbar() != hasHorizontalOverflow)) || (box().style()->overflowX() == OSCROLL && !horizontalScrollbar());
675 autoVerticalScrollBarChanged = (box().hasAutoVerticalScrollbar() && (hasVert icalScrollbar() != hasVerticalOverflow)) || (box().style()->overflowY() == OSCRO LL && !verticalScrollbar()); 675 autoVerticalScrollBarChanged = (box().hasAutoVerticalScrollbar() && (hasVert icalScrollbar() != hasVerticalOverflow)) || (box().style()->overflowY() == OSCRO LL && !verticalScrollbar());
676 if (!visualViewportSuppliesScrollbars() && (autoHorizontalScrollBarChanged | | autoVerticalScrollBarChanged)) { 676 if (!visualViewportSuppliesScrollbars() && (autoHorizontalScrollBarChanged | | autoVerticalScrollBarChanged)) {
677 if (box().hasAutoHorizontalScrollbar() || (box().style()->overflowX() == OSCROLL && !horizontalScrollbar())) 677 if (box().hasAutoHorizontalScrollbar())
678 setHasHorizontalScrollbar(box().style()->overflowX() == OSCROLL ? tr ue : hasHorizontalOverflow); 678 setHasHorizontalScrollbar(hasHorizontalOverflow);
679 if (box().hasAutoVerticalScrollbar() || (box().style()->overflowY() == O SCROLL && !verticalScrollbar())) 679 else if (box().style()->overflowX() == OSCROLL)
680 setHasVerticalScrollbar(box().style()->overflowY() == OSCROLL ? true : hasVerticalOverflow); 680 setHasHorizontalScrollbar(true);
681 if (box().hasAutoVerticalScrollbar())
682 setHasVerticalScrollbar(hasVerticalOverflow);
683 else if (box().style()->overflowX() == OSCROLL)
684 setHasVerticalScrollbar(true);
681 } 685 }
682 } 686 }
683 687
684 void DeprecatedPaintLayerScrollableArea::finalizeScrollDimensions(const DoubleSi ze& originalScrollOffset, bool autoHorizontalScrollBarChanged, bool autoVertical ScrollBarChanged) 688 void DeprecatedPaintLayerScrollableArea::finalizeScrollDimensions(const DoubleSi ze& originalScrollOffset, bool autoHorizontalScrollBarChanged, bool autoVertical ScrollBarChanged)
685 { 689 {
686 ASSERT(box().hasOverflowClip()); 690 ASSERT(box().hasOverflowClip());
687 691
688 // Layout may cause us to be at an invalid scroll position. In this case we need 692 // Layout may cause us to be at an invalid scroll position. In this case we need
689 // to pull our scroll offsets back to the max (or push them up to the min). 693 // to pull our scroll offsets back to the max (or push them up to the min).
690 DoublePoint clampedScrollPosition = clampScrollPosition(scrollPositionDouble ()); 694 DoublePoint clampedScrollPosition = clampScrollPosition(scrollPositionDouble ());
691 if (clampedScrollPosition != scrollPositionDouble()) 695 if (clampedScrollPosition != scrollPositionDouble())
692 scrollToPosition(clampedScrollPosition); 696 scrollToPosition(clampedScrollPosition);
693 697
694 if (originalScrollOffset != adjustedScrollOffset()) { 698 if (originalScrollOffset != adjustedScrollOffset()) {
695 DoublePoint origin(scrollOrigin()); 699 DoublePoint origin(scrollOrigin());
696 scrollPositionChanged(-origin + adjustedScrollOffset(), ProgrammaticScro ll); 700 scrollPositionChanged(-origin + adjustedScrollOffset(), ProgrammaticScro ll);
697 } 701 }
698 702
703 m_scrollbarManager.setCanDetachScrollbars(false);
704
699 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 705 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
700 bool hasVerticalOverflow = this->hasVerticalOverflow(); 706 bool hasVerticalOverflow = this->hasVerticalOverflow();
701 707
702 { 708 {
703 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html. 709 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html.
704 DisableCompositingQueryAsserts disabler; 710 DisableCompositingQueryAsserts disabler;
705 711
706 // overflow:scroll should just enable/disable. 712 // overflow:scroll should just enable/disable.
707 if (box().style()->overflowX() == OSCROLL && horizontalScrollbar()) 713 if (box().style()->overflowX() == OSCROLL && horizontalScrollbar())
708 horizontalScrollbar()->setEnabled(hasHorizontalOverflow); 714 horizontalScrollbar()->setEnabled(hasHorizontalOverflow);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 // To avoid doing a relayout in updateScrollbarsAfterLayout, we try to keep any automatic scrollbar that was already present. 850 // To avoid doing a relayout in updateScrollbarsAfterLayout, we try to keep any automatic scrollbar that was already present.
845 bool needsHorizontalScrollbar = (hasHorizontalScrollbar() && overflowDefines AutomaticScrollbar(overflowX)) || overflowRequiresScrollbar(overflowX); 851 bool needsHorizontalScrollbar = (hasHorizontalScrollbar() && overflowDefines AutomaticScrollbar(overflowX)) || overflowRequiresScrollbar(overflowX);
846 bool needsVerticalScrollbar = (hasVerticalScrollbar() && overflowDefinesAuto maticScrollbar(overflowY)) || overflowRequiresScrollbar(overflowY); 852 bool needsVerticalScrollbar = (hasVerticalScrollbar() && overflowDefinesAuto maticScrollbar(overflowY)) || overflowRequiresScrollbar(overflowY);
847 setHasHorizontalScrollbar(needsHorizontalScrollbar); 853 setHasHorizontalScrollbar(needsHorizontalScrollbar);
848 setHasVerticalScrollbar(needsVerticalScrollbar); 854 setHasVerticalScrollbar(needsVerticalScrollbar);
849 855
850 // With overflow: scroll, scrollbars are always visible but may be disabled. 856 // With overflow: scroll, scrollbars are always visible but may be disabled.
851 // When switching to another value, we need to re-enable them (see bug 11985 ). 857 // When switching to another value, we need to re-enable them (see bug 11985 ).
852 if (needsHorizontalScrollbar && oldStyle && oldStyle->overflowX() == OSCROLL && overflowX != OSCROLL) { 858 if (needsHorizontalScrollbar && oldStyle && oldStyle->overflowX() == OSCROLL && overflowX != OSCROLL) {
853 ASSERT(hasHorizontalScrollbar()); 859 ASSERT(hasHorizontalScrollbar());
854 m_hBar->setEnabled(true); 860 horizontalScrollbar()->setEnabled(true);
855 } 861 }
856 862
857 if (needsVerticalScrollbar && oldStyle && oldStyle->overflowY() == OSCROLL & & overflowY != OSCROLL) { 863 if (needsVerticalScrollbar && oldStyle && oldStyle->overflowY() == OSCROLL & & overflowY != OSCROLL) {
858 ASSERT(hasVerticalScrollbar()); 864 ASSERT(hasVerticalScrollbar());
859 m_vBar->setEnabled(true); 865 verticalScrollbar()->setEnabled(true);
860 } 866 }
861 867
862 // FIXME: Need to detect a swap from custom to native scrollbars (and vice v ersa). 868 // FIXME: Need to detect a swap from custom to native scrollbars (and vice v ersa).
863 if (m_hBar) 869 if (horizontalScrollbar())
864 m_hBar->styleChanged(); 870 horizontalScrollbar()->styleChanged();
865 if (m_vBar) 871 if (verticalScrollbar())
866 m_vBar->styleChanged(); 872 verticalScrollbar()->styleChanged();
867 873
868 updateScrollCornerStyle(); 874 updateScrollCornerStyle();
869 updateResizerAreaSet(); 875 updateResizerAreaSet();
870 updateResizerStyle(); 876 updateResizerStyle();
871 } 877 }
872 878
873 bool DeprecatedPaintLayerScrollableArea::updateAfterCompositingChange() 879 bool DeprecatedPaintLayerScrollableArea::updateAfterCompositingChange()
874 { 880 {
875 layer()->updateScrollingStateAfterCompositingChange(); 881 layer()->updateScrollingStateAfterCompositingChange();
876 const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild; 882 const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild;
(...skipping 17 matching lines...) Expand all
894 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 900 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
895 bool hasVerticalOverflow = this->hasVerticalOverflow(); 901 bool hasVerticalOverflow = this->hasVerticalOverflow();
896 bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow); 902 bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow);
897 bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (has VerticalScrollbar() != hasVerticalOverflow); 903 bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (has VerticalScrollbar() != hasVerticalOverflow);
898 if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged) 904 if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged)
899 box().setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::U nknown); 905 box().setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::U nknown);
900 } 906 }
901 907
902 IntRect DeprecatedPaintLayerScrollableArea::rectForHorizontalScrollbar(const Int Rect& borderBoxRect) const 908 IntRect DeprecatedPaintLayerScrollableArea::rectForHorizontalScrollbar(const Int Rect& borderBoxRect) const
903 { 909 {
904 if (!m_hBar) 910 if (!hasHorizontalScrollbar())
905 return IntRect(); 911 return IntRect();
906 912
907 const IntRect& scrollCorner = scrollCornerRect(); 913 const IntRect& scrollCorner = scrollCornerRect();
908 914
909 return IntRect(horizontalScrollbarStart(borderBoxRect.x()), 915 return IntRect(horizontalScrollbarStart(borderBoxRect.x()),
910 borderBoxRect.maxY() - box().borderBottom() - m_hBar->height(), 916 borderBoxRect.maxY() - box().borderBottom() - horizontalScrollbar()->hei ght(),
911 borderBoxRect.width() - (box().borderLeft() + box().borderRight()) - scr ollCorner.width(), 917 borderBoxRect.width() - (box().borderLeft() + box().borderRight()) - scr ollCorner.width(),
912 m_hBar->height()); 918 horizontalScrollbar()->height());
913 } 919 }
914 920
915 IntRect DeprecatedPaintLayerScrollableArea::rectForVerticalScrollbar(const IntRe ct& borderBoxRect) const 921 IntRect DeprecatedPaintLayerScrollableArea::rectForVerticalScrollbar(const IntRe ct& borderBoxRect) const
916 { 922 {
917 if (!m_vBar) 923 if (!hasVerticalScrollbar())
918 return IntRect(); 924 return IntRect();
919 925
920 const IntRect& scrollCorner = scrollCornerRect(); 926 const IntRect& scrollCorner = scrollCornerRect();
921 927
922 return IntRect(verticalScrollbarStart(borderBoxRect.x(), borderBoxRect.maxX( )), 928 return IntRect(verticalScrollbarStart(borderBoxRect.x(), borderBoxRect.maxX( )),
923 borderBoxRect.y() + box().borderTop(), 929 borderBoxRect.y() + box().borderTop(),
924 m_vBar->width(), 930 verticalScrollbar()->width(),
925 borderBoxRect.height() - (box().borderTop() + box().borderBottom()) - sc rollCorner.height()); 931 borderBoxRect.height() - (box().borderTop() + box().borderBottom()) - sc rollCorner.height());
926 } 932 }
927 933
928 LayoutUnit DeprecatedPaintLayerScrollableArea::verticalScrollbarStart(int minX, int maxX) const 934 LayoutUnit DeprecatedPaintLayerScrollableArea::verticalScrollbarStart(int minX, int maxX) const
929 { 935 {
930 if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) 936 if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
931 return minX + box().borderLeft(); 937 return minX + box().borderLeft();
932 return maxX - box().borderRight() - m_vBar->width(); 938 return maxX - box().borderRight() - verticalScrollbar()->width();
933 } 939 }
934 940
935 LayoutUnit DeprecatedPaintLayerScrollableArea::horizontalScrollbarStart(int minX ) const 941 LayoutUnit DeprecatedPaintLayerScrollableArea::horizontalScrollbarStart(int minX ) const
936 { 942 {
937 int x = minX + box().borderLeft(); 943 int x = minX + box().borderLeft();
938 if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) 944 if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
939 x += m_vBar ? m_vBar->width() : resizerCornerRect(box().pixelSnappedBord erBoxRect(), ResizerForPointer).width(); 945 x += hasVerticalScrollbar() ? verticalScrollbar()->width() : resizerCorn erRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer).width();
940 return x; 946 return x;
941 } 947 }
942 948
943 IntSize DeprecatedPaintLayerScrollableArea::scrollbarOffset(const Scrollbar* scr ollbar) const 949 IntSize DeprecatedPaintLayerScrollableArea::scrollbarOffset(const Scrollbar* scr ollbar) const
944 { 950 {
945 if (scrollbar == m_vBar.get()) 951 if (scrollbar == verticalScrollbar())
946 return IntSize(verticalScrollbarStart(0, box().size().width()), box().bo rderTop()); 952 return IntSize(verticalScrollbarStart(0, box().size().width()), box().bo rderTop());
947 953
948 if (scrollbar == m_hBar.get()) 954 if (scrollbar == horizontalScrollbar())
949 return IntSize(horizontalScrollbarStart(0), box().size().height() - box( ).borderBottom() - scrollbar->height()); 955 return IntSize(horizontalScrollbarStart(0), box().size().height() - box( ).borderBottom() - scrollbar->height());
950 956
951 ASSERT_NOT_REACHED(); 957 ASSERT_NOT_REACHED();
952 return IntSize(); 958 return IntSize();
953 } 959 }
954 960
955 static inline LayoutObject* layoutObjectForScrollbar(LayoutObject& layoutObject) 961 static inline LayoutObject* layoutObjectForScrollbar(LayoutObject& layoutObject)
956 { 962 {
957 if (Node* node = layoutObject.node()) { 963 if (Node* node = layoutObject.node()) {
958 if (layoutObject.isLayoutView()) { 964 if (layoutObject.isLayoutView()) {
(...skipping 25 matching lines...) Expand all
984 } 990 }
985 991
986 return &layoutObject; 992 return &layoutObject;
987 } 993 }
988 994
989 bool DeprecatedPaintLayerScrollableArea::needsScrollbarReconstruction() const 995 bool DeprecatedPaintLayerScrollableArea::needsScrollbarReconstruction() const
990 { 996 {
991 LayoutObject* actualLayoutObject = layoutObjectForScrollbar(box()); 997 LayoutObject* actualLayoutObject = layoutObjectForScrollbar(box());
992 bool shouldUseCustom = actualLayoutObject->isBox() && actualLayoutObject->st yle()->hasPseudoStyle(SCROLLBAR); 998 bool shouldUseCustom = actualLayoutObject->isBox() && actualLayoutObject->st yle()->hasPseudoStyle(SCROLLBAR);
993 bool hasAnyScrollbar = hasScrollbar(); 999 bool hasAnyScrollbar = hasScrollbar();
994 bool hasCustom = (m_hBar && m_hBar->isCustomScrollbar()) || (m_vBar && m_vBa r->isCustomScrollbar()); 1000 bool hasCustom = (hasHorizontalScrollbar() && horizontalScrollbar()->isCusto mScrollbar()) || (hasVerticalScrollbar() && verticalScrollbar()->isCustomScrollb ar());
995 return hasAnyScrollbar && (shouldUseCustom != hasCustom); 1001 return hasAnyScrollbar && (shouldUseCustom != hasCustom);
996 } 1002 }
997 1003
998 PassRefPtrWillBeRawPtr<Scrollbar> DeprecatedPaintLayerScrollableArea::createScro llbar(ScrollbarOrientation orientation)
999 {
1000 RefPtrWillBeRawPtr<Scrollbar> widget = nullptr;
1001 LayoutObject* actualLayoutObject = layoutObjectForScrollbar(box());
1002 bool hasCustomScrollbarStyle = actualLayoutObject->isBox() && actualLayoutOb ject->style()->hasPseudoStyle(SCROLLBAR);
1003 if (hasCustomScrollbarStyle) {
1004 widget = LayoutScrollbar::createCustomScrollbar(this, orientation, actua lLayoutObject->node());
1005 } else {
1006 ScrollbarControlSize scrollbarSize = RegularScrollbar;
1007 if (actualLayoutObject->style()->hasAppearance())
1008 scrollbarSize = LayoutTheme::theme().scrollbarControlSizeForPart(act ualLayoutObject->style()->appearance());
1009 widget = Scrollbar::create(this, orientation, scrollbarSize);
1010 if (orientation == HorizontalScrollbar)
1011 didAddScrollbar(widget.get(), HorizontalScrollbar);
1012 else
1013 didAddScrollbar(widget.get(), VerticalScrollbar);
1014 }
1015 box().document().view()->addChild(widget.get());
1016 return widget.release();
1017 }
1018
1019 void DeprecatedPaintLayerScrollableArea::destroyScrollbar(ScrollbarOrientation o rientation)
1020 {
1021 RefPtrWillBeMember<Scrollbar>& scrollbar = orientation == HorizontalScrollba r ? m_hBar : m_vBar;
1022 if (!scrollbar)
1023 return;
1024
1025 if (!scrollbar->isCustomScrollbar())
1026 willRemoveScrollbar(scrollbar.get(), orientation);
1027
1028 toFrameView(scrollbar->parent())->removeChild(scrollbar.get());
1029 scrollbar->disconnectFromScrollableArea();
1030 scrollbar = nullptr;
1031 }
1032
1033 void DeprecatedPaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrol lbar) 1004 void DeprecatedPaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrol lbar)
1034 { 1005 {
1035 if (hasScrollbar == hasHorizontalScrollbar()) 1006 if (hasScrollbar == hasHorizontalScrollbar())
1036 return; 1007 return;
1037 1008
1038 if (hasScrollbar) { 1009 if (!hasScrollbar && !layerForHorizontalScrollbar())
1039 // This doesn't hit in any tests, but since the equivalent code in setHa sVerticalScrollbar 1010 horizontalScrollbar()->invalidate();
1040 // does, presumably this code does as well.
1041 DisableCompositingQueryAsserts disabler;
1042 m_hBar = createScrollbar(HorizontalScrollbar);
1043 } else {
1044 if (!layerForHorizontalScrollbar())
1045 m_hBar->invalidate();
1046 // Otherwise we will remove the layer and just need recompositing.
1047 1011
1048 destroyScrollbar(HorizontalScrollbar); 1012 m_scrollbarManager.setHasHorizontalScrollbar(hasScrollbar);
1049 }
1050 1013
1051 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style. 1014 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style.
1052 if (m_hBar) 1015 if (hasHorizontalScrollbar())
1053 m_hBar->styleChanged(); 1016 horizontalScrollbar()->styleChanged();
1054 if (m_vBar) 1017 if (hasVerticalScrollbar())
1055 m_vBar->styleChanged(); 1018 verticalScrollbar()->styleChanged();
1056 1019
1057 // These are valid because we want to invalidate display item clients on the current backing. 1020 // These are valid because we want to invalidate display item clients on the current backing.
1058 DisablePaintInvalidationStateAsserts paintInvalidationAssertDisabler; 1021 DisablePaintInvalidationStateAsserts paintInvalidationAssertDisabler;
1059 DisableCompositingQueryAsserts compositingAssertDisabler; 1022 DisableCompositingQueryAsserts compositingAssertDisabler;
1060 invalidateScrollCorner(scrollCornerRect()); 1023 invalidateScrollCorner(scrollCornerRect());
1061 1024
1062 // Force an update since we know the scrollbars have changed things. 1025 // Force an update since we know the scrollbars have changed things.
1063 if (box().document().hasAnnotatedRegions()) 1026 if (box().document().hasAnnotatedRegions())
1064 box().document().setAnnotatedRegionsDirty(true); 1027 box().document().setAnnotatedRegionsDirty(true);
1065 } 1028 }
1066 1029
1067 void DeprecatedPaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollb ar) 1030 void DeprecatedPaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollb ar)
1068 { 1031 {
1069 if (hasScrollbar == hasVerticalScrollbar()) 1032 if (hasScrollbar == hasVerticalScrollbar())
1070 return; 1033 return;
1071 1034
1072 if (hasScrollbar) { 1035 if (!hasScrollbar && !layerForVerticalScrollbar())
1073 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html 1036 verticalScrollbar()->invalidate();
1074 DisableCompositingQueryAsserts disabler;
1075 m_vBar = createScrollbar(VerticalScrollbar);
1076 } else {
1077 if (!layerForVerticalScrollbar())
1078 m_vBar->invalidate();
1079 // Otherwise we will remove the layer and just need recompositing.
1080 1037
1081 destroyScrollbar(VerticalScrollbar); 1038 m_scrollbarManager.setHasVerticalScrollbar(hasScrollbar);
1082 }
1083 1039
1084 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style. 1040 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style.
1085 if (m_hBar) 1041 if (hasHorizontalScrollbar())
1086 m_hBar->styleChanged(); 1042 horizontalScrollbar()->styleChanged();
1087 if (m_vBar) 1043 if (hasVerticalScrollbar())
1088 m_vBar->styleChanged(); 1044 verticalScrollbar()->styleChanged();
1089 1045
1090 // These are valid because we want to invalidate display item clients on the current backing. 1046 // These are valid because we want to invalidate display item clients on the current backing.
1091 DisablePaintInvalidationStateAsserts paintInvalidationAssertDisabler; 1047 DisablePaintInvalidationStateAsserts paintInvalidationAssertDisabler;
1092 DisableCompositingQueryAsserts compositingAssertDisabler; 1048 DisableCompositingQueryAsserts compositingAssertDisabler;
1093 invalidateScrollCorner(scrollCornerRect()); 1049 invalidateScrollCorner(scrollCornerRect());
1094 1050
1095 // Force an update since we know the scrollbars have changed things. 1051 // Force an update since we know the scrollbars have changed things.
1096 if (box().document().hasAnnotatedRegions()) 1052 if (box().document().hasAnnotatedRegions())
1097 box().document().setAnnotatedRegionsDirty(true); 1053 box().document().setAnnotatedRegionsDirty(true);
1098 } 1054 }
1099 1055
1100 int DeprecatedPaintLayerScrollableArea::verticalScrollbarWidth(OverlayScrollbarS izeRelevancy relevancy) const 1056 int DeprecatedPaintLayerScrollableArea::verticalScrollbarWidth(OverlayScrollbarS izeRelevancy relevancy) const
1101 { 1057 {
1102 if (!m_vBar || (m_vBar->isOverlayScrollbar() && (relevancy == IgnoreOverlayS crollbarSize || !m_vBar->shouldParticipateInHitTesting()))) 1058 if (!hasVerticalScrollbar() || (verticalScrollbar()->isOverlayScrollbar() && (relevancy == IgnoreOverlayScrollbarSize || !verticalScrollbar()->shouldPartici pateInHitTesting())))
1103 return 0; 1059 return 0;
1104 return m_vBar->width(); 1060 return verticalScrollbar()->width();
1105 } 1061 }
1106 1062
1107 int DeprecatedPaintLayerScrollableArea::horizontalScrollbarHeight(OverlayScrollb arSizeRelevancy relevancy) const 1063 int DeprecatedPaintLayerScrollableArea::horizontalScrollbarHeight(OverlayScrollb arSizeRelevancy relevancy) const
1108 { 1064 {
1109 if (!m_hBar || (m_hBar->isOverlayScrollbar() && (relevancy == IgnoreOverlayS crollbarSize || !m_hBar->shouldParticipateInHitTesting()))) 1065 if (!hasHorizontalScrollbar() || (horizontalScrollbar()->isOverlayScrollbar( ) && (relevancy == IgnoreOverlayScrollbarSize || !horizontalScrollbar()->shouldP articipateInHitTesting())))
1110 return 0; 1066 return 0;
1111 return m_hBar->height(); 1067 return horizontalScrollbar()->height();
1112 } 1068 }
1113 1069
1114 void DeprecatedPaintLayerScrollableArea::positionOverflowControls() 1070 void DeprecatedPaintLayerScrollableArea::positionOverflowControls()
1115 { 1071 {
1116 if (!hasScrollbar() && !box().canResize()) 1072 if (!hasScrollbar() && !box().canResize())
1117 return; 1073 return;
1118 1074
1119 const IntRect borderBox = box().pixelSnappedBorderBoxRect(); 1075 const IntRect borderBox = box().pixelSnappedBorderBoxRect();
1120 if (Scrollbar* verticalScrollbar = this->verticalScrollbar()) 1076 if (Scrollbar* verticalScrollbar = this->verticalScrollbar())
1121 verticalScrollbar->setFrameRect(rectForVerticalScrollbar(borderBox)); 1077 verticalScrollbar->setFrameRect(rectForVerticalScrollbar(borderBox));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 return false; 1120 return false;
1165 1121
1166 IntRect resizeControlRect; 1122 IntRect resizeControlRect;
1167 if (box().style()->resize() != RESIZE_NONE) { 1123 if (box().style()->resize() != RESIZE_NONE) {
1168 resizeControlRect = resizerCornerRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer); 1124 resizeControlRect = resizerCornerRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer);
1169 if (resizeControlRect.contains(localPoint)) 1125 if (resizeControlRect.contains(localPoint))
1170 return true; 1126 return true;
1171 } 1127 }
1172 1128
1173 int resizeControlSize = max(resizeControlRect.height(), 0); 1129 int resizeControlSize = max(resizeControlRect.height(), 0);
1174 if (m_vBar && m_vBar->shouldParticipateInHitTesting()) { 1130 if (hasVerticalScrollbar() && verticalScrollbar()->shouldParticipateInHitTes ting()) {
1175 LayoutRect vBarRect(verticalScrollbarStart(0, box().size().width()), 1131 LayoutRect vBarRect(verticalScrollbarStart(0, box().size().width()),
1176 box().borderTop(), 1132 box().borderTop(),
1177 m_vBar->width(), 1133 verticalScrollbar()->width(),
1178 box().size().height() - (box().borderTop() + box().borderBottom()) - (m_hBar ? m_hBar->height() : resizeControlSize)); 1134 box().size().height() - (box().borderTop() + box().borderBottom()) - (hasHorizontalScrollbar() ? horizontalScrollbar()->height() : resizeControlSize ));
1179 if (vBarRect.contains(localPoint)) { 1135 if (vBarRect.contains(localPoint)) {
1180 result.setScrollbar(m_vBar.get()); 1136 result.setScrollbar(verticalScrollbar());
1181 return true; 1137 return true;
1182 } 1138 }
1183 } 1139 }
1184 1140
1185 resizeControlSize = max(resizeControlRect.width(), 0); 1141 resizeControlSize = max(resizeControlRect.width(), 0);
1186 if (m_hBar && m_hBar->shouldParticipateInHitTesting()) { 1142 if (hasHorizontalScrollbar() && horizontalScrollbar()->shouldParticipateInHi tTesting()) {
1187 LayoutRect hBarRect(horizontalScrollbarStart(0), 1143 LayoutRect hBarRect(horizontalScrollbarStart(0),
1188 box().size().height() - box().borderBottom() - m_hBar->height(), 1144 box().size().height() - box().borderBottom() - horizontalScrollbar() ->height(),
1189 box().size().width() - (box().borderLeft() + box().borderRight()) - (m_vBar ? m_vBar->width() : resizeControlSize), 1145 box().size().width() - (box().borderLeft() + box().borderRight()) - (hasVerticalScrollbar() ? verticalScrollbar()->width() : resizeControlSize),
1190 m_hBar->height()); 1146 horizontalScrollbar()->height());
1191 if (hBarRect.contains(localPoint)) { 1147 if (hBarRect.contains(localPoint)) {
1192 result.setScrollbar(m_hBar.get()); 1148 result.setScrollbar(horizontalScrollbar());
1193 return true; 1149 return true;
1194 } 1150 }
1195 } 1151 }
1196 1152
1197 // FIXME: We should hit test the m_scrollCorner and pass it back through the result. 1153 // FIXME: We should hit test the m_scrollCorner and pass it back through the result.
1198 1154
1199 return false; 1155 return false;
1200 } 1156 }
1201 1157
1202 IntRect DeprecatedPaintLayerScrollableArea::resizerCornerRect(const IntRect& bou nds, ResizerHitTestType resizerHitTestType) const 1158 IntRect DeprecatedPaintLayerScrollableArea::resizerCornerRect(const IntRect& bou nds, ResizerHitTestType resizerHitTestType) const
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 if (!layer()->isRootLayer()) 1439 if (!layer()->isRootLayer())
1484 return false; 1440 return false;
1485 1441
1486 LocalFrame* frame = box().frame(); 1442 LocalFrame* frame = box().frame();
1487 if (!frame || !frame->isMainFrame() || !frame->settings()) 1443 if (!frame || !frame->isMainFrame() || !frame->settings())
1488 return false; 1444 return false;
1489 1445
1490 return frame->settings()->viewportMetaEnabled(); 1446 return frame->settings()->viewportMetaEnabled();
1491 } 1447 }
1492 1448
1449 DeprecatedPaintLayerScrollableArea::ScrollbarManager::ScrollbarManager(Deprecate dPaintLayerScrollableArea& scrollableArea)
1450 : m_scrollableArea(scrollableArea)
1451 , m_canDetachScrollbars(0)
1452 , m_hBarIsAttached(0)
1453 , m_vBarIsAttached(0)
1454 {
1455 }
1456
1457 void DeprecatedPaintLayerScrollableArea::ScrollbarManager::dispose()
1458 {
1459 m_canDetachScrollbars = m_hBarIsAttached = m_vBarIsAttached = 0;
1460 destroyScrollbar(HorizontalScrollbar);
1461 destroyScrollbar(VerticalScrollbar);
1462 }
1463
1464 void DeprecatedPaintLayerScrollableArea::ScrollbarManager::setCanDetachScrollbar s(bool detach)
1465 {
1466 ASSERT(!m_hBarIsAttached || m_hBar);
1467 ASSERT(!m_vBarIsAttached || m_vBar);
1468 m_canDetachScrollbars = detach ? 1 : 0;
1469 if (!detach) {
1470 if (m_hBar && !m_hBarIsAttached)
1471 destroyScrollbar(HorizontalScrollbar, true);
1472 if (m_vBar && !m_vBarIsAttached)
1473 destroyScrollbar(VerticalScrollbar, true);
1474 }
1475 }
1476
1477 void DeprecatedPaintLayerScrollableArea::ScrollbarManager::setHasHorizontalScrol lbar(bool hasScrollbar)
1478 {
1479 if (hasScrollbar) {
1480 // This doesn't hit in any tests, but since the equivalent code in setHa sVerticalScrollbar
1481 // does, presumably this code does as well.
1482 DisableCompositingQueryAsserts disabler;
1483 if (!m_hBar)
1484 m_hBar = createScrollbar(HorizontalScrollbar);
1485 m_hBarIsAttached = 1;
1486 } else {
1487 m_hBarIsAttached = 0;
1488 if (!m_canDetachScrollbars)
1489 destroyScrollbar(HorizontalScrollbar);
1490 }
1491 }
1492
1493 void DeprecatedPaintLayerScrollableArea::ScrollbarManager::setHasVerticalScrollb ar(bool hasScrollbar)
1494 {
1495 if (hasScrollbar) {
1496 DisableCompositingQueryAsserts disabler;
1497 if (!m_vBar)
1498 m_vBar = createScrollbar(VerticalScrollbar);
1499 m_vBarIsAttached = 1;
1500 } else {
1501 m_vBarIsAttached = 0;
1502 if (!m_canDetachScrollbars)
1503 destroyScrollbar(VerticalScrollbar);
1504 }
1505 }
1506
1507 PassRefPtrWillBeRawPtr<Scrollbar> DeprecatedPaintLayerScrollableArea::ScrollbarM anager::createScrollbar(ScrollbarOrientation orientation)
1508 {
1509 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached : !m_vBarIsAtt ached);
1510 RefPtrWillBeRawPtr<Scrollbar> widget = nullptr;
1511 LayoutObject* actualLayoutObject = layoutObjectForScrollbar(m_scrollableArea .box());
1512 bool hasCustomScrollbarStyle = actualLayoutObject->isBox() && actualLayoutOb ject->style()->hasPseudoStyle(SCROLLBAR);
1513 if (hasCustomScrollbarStyle) {
1514 widget = LayoutScrollbar::createCustomScrollbar(&m_scrollableArea, orien tation, actualLayoutObject->node());
1515 } else {
1516 ScrollbarControlSize scrollbarSize = RegularScrollbar;
1517 if (actualLayoutObject->style()->hasAppearance())
1518 scrollbarSize = LayoutTheme::theme().scrollbarControlSizeForPart(act ualLayoutObject->style()->appearance());
1519 widget = Scrollbar::create(&m_scrollableArea, orientation, scrollbarSize );
1520 if (orientation == HorizontalScrollbar)
1521 m_scrollableArea.didAddScrollbar(widget.get(), HorizontalScrollbar);
1522 else
1523 m_scrollableArea.didAddScrollbar(widget.get(), VerticalScrollbar);
1524 }
1525 m_scrollableArea.box().document().view()->addChild(widget.get());
1526 return widget.release();
1527 }
1528
1529 void DeprecatedPaintLayerScrollableArea::ScrollbarManager::destroyScrollbar(Scro llbarOrientation orientation, bool invalidate)
1530 {
1531 RefPtrWillBeMember<Scrollbar>& scrollbar = orientation == HorizontalScrollba r ? m_hBar : m_vBar;
1532 ASSERT(orientation == HorizontalScrollbar ? !m_hBarIsAttached: !m_vBarIsAtta ched);
1533 if (!scrollbar)
1534 return;
1535
1536 if (invalidate)
1537 scrollbar->invalidate();
1538 if (!scrollbar->isCustomScrollbar())
1539 m_scrollableArea.willRemoveScrollbar(scrollbar.get(), orientation);
1540
1541 toFrameView(scrollbar->parent())->removeChild(scrollbar.get());
1542 scrollbar->disconnectFromScrollableArea();
1543 scrollbar = nullptr;
1544 }
1545
1546 DEFINE_TRACE(DeprecatedPaintLayerScrollableArea::ScrollbarManager)
1547 {
1548 visitor->trace(m_hBar);
1549 visitor->trace(m_vBar);
1550 }
1551
1493 } // namespace blink 1552 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/DeprecatedPaintLayerScrollableArea.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698