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

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

Issue 1370373003: Revert of Avoid scrollbar construction/destruction thrashing during flex layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: 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)
92 , m_scrollCorner(nullptr) 91 , m_scrollCorner(nullptr)
93 , m_resizer(nullptr) 92 , m_resizer(nullptr)
94 #if ENABLE(ASSERT) 93 #if ENABLE(ASSERT)
95 , m_hasBeenDisposed(false) 94 , m_hasBeenDisposed(false)
96 #endif 95 #endif
97 { 96 {
98 Node* node = box().node(); 97 Node* node = box().node();
99 if (node && node->isElementNode()) { 98 if (node && node->isElementNode()) {
100 // We save and restore only the scrollOffset as the other scroll values are recalculated. 99 // We save and restore only the scrollOffset as the other scroll values are recalculated.
101 Element* element = toElement(node); 100 Element* element = toElement(node);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // FIXME: Make setSavedLayerScrollOffset take DoubleSize. crbug.com/4142 83. 135 // FIXME: Make setSavedLayerScrollOffset take DoubleSize. crbug.com/4142 83.
137 if (node && node->isElementNode()) 136 if (node && node->isElementNode())
138 toElement(node)->setSavedLayerScrollOffset(flooredIntSize(m_scrollOf fset)); 137 toElement(node)->setSavedLayerScrollOffset(flooredIntSize(m_scrollOf fset));
139 } 138 }
140 139
141 if (LocalFrame* frame = box().frame()) { 140 if (LocalFrame* frame = box().frame()) {
142 if (FrameView* frameView = frame->view()) 141 if (FrameView* frameView = frame->view())
143 frameView->removeResizerArea(box()); 142 frameView->removeResizerArea(box());
144 } 143 }
145 144
146 m_scrollbarManager.dispose(); 145 destroyScrollbar(HorizontalScrollbar);
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 m_scrollbarManager.trace(visitor); 162 visitor->trace(m_hBar);
163 visitor->trace(m_vBar);
163 ScrollableArea::trace(visitor); 164 ScrollableArea::trace(visitor);
164 } 165 }
165 166
166 HostWindow* DeprecatedPaintLayerScrollableArea::hostWindow() const 167 HostWindow* DeprecatedPaintLayerScrollableArea::hostWindow() const
167 { 168 {
168 if (Page* page = box().frame()->page()) 169 if (Page* page = box().frame()->page())
169 return &page->chromeClient(); 170 return &page->chromeClient();
170 return nullptr; 171 return nullptr;
171 } 172 }
172 173
(...skipping 24 matching lines...) Expand all
197 DisableCompositingQueryAsserts disabler; 198 DisableCompositingQueryAsserts disabler;
198 199
199 return layer()->hasCompositedDeprecatedPaintLayerMapping() ? layer()->compos itedDeprecatedPaintLayerMapping()->layerForScrollCorner() : 0; 200 return layer()->hasCompositedDeprecatedPaintLayerMapping() ? layer()->compos itedDeprecatedPaintLayerMapping()->layerForScrollCorner() : 0;
200 } 201 }
201 202
202 void DeprecatedPaintLayerScrollableArea::invalidateScrollbarRect(Scrollbar* scro llbar, const IntRect& rect) 203 void DeprecatedPaintLayerScrollableArea::invalidateScrollbarRect(Scrollbar* scro llbar, const IntRect& rect)
203 { 204 {
204 // See crbug.com/343132. 205 // See crbug.com/343132.
205 DisableCompositingQueryAsserts disabler; 206 DisableCompositingQueryAsserts disabler;
206 207
207 ASSERT(scrollbar == horizontalScrollbar() || scrollbar == verticalScrollbar( )); 208 ASSERT(scrollbar == m_hBar.get() || scrollbar == m_vBar.get());
208 ASSERT(scrollbar == horizontalScrollbar() ? !layerForHorizontalScrollbar() : !layerForVerticalScrollbar()); 209 ASSERT(scrollbar == m_hBar.get() ? !layerForHorizontalScrollbar() : !layerFo rVerticalScrollbar());
209 210
210 IntRect scrollRect = rect; 211 IntRect scrollRect = rect;
211 // If we are not yet inserted into the tree, there is no need to issue paint invaldiations. 212 // If we are not yet inserted into the tree, there is no need to issue paint invaldiations.
212 if (!box().isLayoutView() && !box().parent()) 213 if (!box().isLayoutView() && !box().parent())
213 return; 214 return;
214 215
215 if (scrollbar == verticalScrollbar()) 216 if (scrollbar == m_vBar.get())
216 scrollRect.move(verticalScrollbarStart(0, box().size().width()), box().b orderTop()); 217 scrollRect.move(verticalScrollbarStart(0, box().size().width()), box().b orderTop());
217 else 218 else
218 scrollRect.move(horizontalScrollbarStart(0), box().size().height() - box ().borderBottom() - scrollbar->height()); 219 scrollRect.move(horizontalScrollbarStart(0), box().size().height() - box ().borderBottom() - scrollbar->height());
219 220
220 if (scrollRect.isEmpty()) 221 if (scrollRect.isEmpty())
221 return; 222 return;
222 223
223 box().invalidateDisplayItemClient(*scrollbar); 224 box().invalidateDisplayItemClient(*scrollbar);
224 225
225 LayoutRect paintInvalidationRect = LayoutRect(scrollRect); 226 LayoutRect paintInvalidationRect = LayoutRect(scrollRect);
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 DoublePoint newScrollPosition = clamp == ScrollOffsetClamped ? clampScrollPo sition(scrollPosition) : scrollPosition; 646 DoublePoint newScrollPosition = clamp == ScrollOffsetClamped ? clampScrollPo sition(scrollPosition) : scrollPosition;
646 if (newScrollPosition != scrollPositionDouble()) 647 if (newScrollPosition != scrollPositionDouble())
647 ScrollableArea::setScrollPosition(newScrollPosition, ProgrammaticScroll, scrollBehavior); 648 ScrollableArea::setScrollPosition(newScrollPosition, ProgrammaticScroll, scrollBehavior);
648 } 649 }
649 650
650 void DeprecatedPaintLayerScrollableArea::updateScrollDimensions(DoubleSize& scro llOffset, bool& autoHorizontalScrollBarChanged, bool& autoVerticalScrollBarChang ed) 651 void DeprecatedPaintLayerScrollableArea::updateScrollDimensions(DoubleSize& scro llOffset, bool& autoHorizontalScrollBarChanged, bool& autoVerticalScrollBarChang ed)
651 { 652 {
652 ASSERT(box().hasOverflowClip()); 653 ASSERT(box().hasOverflowClip());
653 654
654 if (needsScrollbarReconstruction()) { 655 if (needsScrollbarReconstruction()) {
655 m_scrollbarManager.setCanDetachScrollbars(false); 656 if (m_hBar)
656 setHasHorizontalScrollbar(false); 657 destroyScrollbar(HorizontalScrollbar);
657 setHasVerticalScrollbar(false); 658 if (m_vBar)
659 destroyScrollbar(VerticalScrollbar);
658 } 660 }
659 661
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()) 677 if (box().hasAutoHorizontalScrollbar() || (box().style()->overflowX() == OSCROLL && !horizontalScrollbar()))
678 setHasHorizontalScrollbar(hasHorizontalOverflow); 678 setHasHorizontalScrollbar(box().style()->overflowX() == OSCROLL ? tr ue : hasHorizontalOverflow);
679 else if (box().style()->overflowX() == OSCROLL) 679 if (box().hasAutoVerticalScrollbar() || (box().style()->overflowY() == O SCROLL && !verticalScrollbar()))
680 setHasHorizontalScrollbar(true); 680 setHasVerticalScrollbar(box().style()->overflowY() == OSCROLL ? true : hasVerticalOverflow);
681 if (box().hasAutoVerticalScrollbar())
682 setHasVerticalScrollbar(hasVerticalOverflow);
683 else if (box().style()->overflowX() == OSCROLL)
684 setHasVerticalScrollbar(true);
685 } 681 }
686 } 682 }
687 683
688 void DeprecatedPaintLayerScrollableArea::finalizeScrollDimensions(const DoubleSi ze& originalScrollOffset, bool autoHorizontalScrollBarChanged, bool autoVertical ScrollBarChanged) 684 void DeprecatedPaintLayerScrollableArea::finalizeScrollDimensions(const DoubleSi ze& originalScrollOffset, bool autoHorizontalScrollBarChanged, bool autoVertical ScrollBarChanged)
689 { 685 {
690 ASSERT(box().hasOverflowClip()); 686 ASSERT(box().hasOverflowClip());
691 687
692 // Layout may cause us to be at an invalid scroll position. In this case we need 688 // Layout may cause us to be at an invalid scroll position. In this case we need
693 // to pull our scroll offsets back to the max (or push them up to the min). 689 // to pull our scroll offsets back to the max (or push them up to the min).
694 DoublePoint clampedScrollPosition = clampScrollPosition(scrollPositionDouble ()); 690 DoublePoint clampedScrollPosition = clampScrollPosition(scrollPositionDouble ());
695 if (clampedScrollPosition != scrollPositionDouble()) 691 if (clampedScrollPosition != scrollPositionDouble())
696 scrollToPosition(clampedScrollPosition); 692 scrollToPosition(clampedScrollPosition);
697 693
698 if (originalScrollOffset != adjustedScrollOffset()) { 694 if (originalScrollOffset != adjustedScrollOffset()) {
699 DoublePoint origin(scrollOrigin()); 695 DoublePoint origin(scrollOrigin());
700 scrollPositionChanged(-origin + adjustedScrollOffset(), ProgrammaticScro ll); 696 scrollPositionChanged(-origin + adjustedScrollOffset(), ProgrammaticScro ll);
701 } 697 }
702 698
703 m_scrollbarManager.setCanDetachScrollbars(false);
704
705 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 699 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
706 bool hasVerticalOverflow = this->hasVerticalOverflow(); 700 bool hasVerticalOverflow = this->hasVerticalOverflow();
707 701
708 { 702 {
709 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html. 703 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html.
710 DisableCompositingQueryAsserts disabler; 704 DisableCompositingQueryAsserts disabler;
711 705
712 // overflow:scroll should just enable/disable. 706 // overflow:scroll should just enable/disable.
713 if (box().style()->overflowX() == OSCROLL && horizontalScrollbar()) 707 if (box().style()->overflowX() == OSCROLL && horizontalScrollbar())
714 horizontalScrollbar()->setEnabled(hasHorizontalOverflow); 708 horizontalScrollbar()->setEnabled(hasHorizontalOverflow);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 // To avoid doing a relayout in updateScrollbarsAfterLayout, we try to keep any automatic scrollbar that was already present. 844 // To avoid doing a relayout in updateScrollbarsAfterLayout, we try to keep any automatic scrollbar that was already present.
851 bool needsHorizontalScrollbar = (hasHorizontalScrollbar() && overflowDefines AutomaticScrollbar(overflowX)) || overflowRequiresScrollbar(overflowX); 845 bool needsHorizontalScrollbar = (hasHorizontalScrollbar() && overflowDefines AutomaticScrollbar(overflowX)) || overflowRequiresScrollbar(overflowX);
852 bool needsVerticalScrollbar = (hasVerticalScrollbar() && overflowDefinesAuto maticScrollbar(overflowY)) || overflowRequiresScrollbar(overflowY); 846 bool needsVerticalScrollbar = (hasVerticalScrollbar() && overflowDefinesAuto maticScrollbar(overflowY)) || overflowRequiresScrollbar(overflowY);
853 setHasHorizontalScrollbar(needsHorizontalScrollbar); 847 setHasHorizontalScrollbar(needsHorizontalScrollbar);
854 setHasVerticalScrollbar(needsVerticalScrollbar); 848 setHasVerticalScrollbar(needsVerticalScrollbar);
855 849
856 // With overflow: scroll, scrollbars are always visible but may be disabled. 850 // With overflow: scroll, scrollbars are always visible but may be disabled.
857 // When switching to another value, we need to re-enable them (see bug 11985 ). 851 // When switching to another value, we need to re-enable them (see bug 11985 ).
858 if (needsHorizontalScrollbar && oldStyle && oldStyle->overflowX() == OSCROLL && overflowX != OSCROLL) { 852 if (needsHorizontalScrollbar && oldStyle && oldStyle->overflowX() == OSCROLL && overflowX != OSCROLL) {
859 ASSERT(hasHorizontalScrollbar()); 853 ASSERT(hasHorizontalScrollbar());
860 horizontalScrollbar()->setEnabled(true); 854 m_hBar->setEnabled(true);
861 } 855 }
862 856
863 if (needsVerticalScrollbar && oldStyle && oldStyle->overflowY() == OSCROLL & & overflowY != OSCROLL) { 857 if (needsVerticalScrollbar && oldStyle && oldStyle->overflowY() == OSCROLL & & overflowY != OSCROLL) {
864 ASSERT(hasVerticalScrollbar()); 858 ASSERT(hasVerticalScrollbar());
865 verticalScrollbar()->setEnabled(true); 859 m_vBar->setEnabled(true);
866 } 860 }
867 861
868 // FIXME: Need to detect a swap from custom to native scrollbars (and vice v ersa). 862 // FIXME: Need to detect a swap from custom to native scrollbars (and vice v ersa).
869 if (horizontalScrollbar()) 863 if (m_hBar)
870 horizontalScrollbar()->styleChanged(); 864 m_hBar->styleChanged();
871 if (verticalScrollbar()) 865 if (m_vBar)
872 verticalScrollbar()->styleChanged(); 866 m_vBar->styleChanged();
873 867
874 updateScrollCornerStyle(); 868 updateScrollCornerStyle();
875 updateResizerAreaSet(); 869 updateResizerAreaSet();
876 updateResizerStyle(); 870 updateResizerStyle();
877 } 871 }
878 872
879 bool DeprecatedPaintLayerScrollableArea::updateAfterCompositingChange() 873 bool DeprecatedPaintLayerScrollableArea::updateAfterCompositingChange()
880 { 874 {
881 layer()->updateScrollingStateAfterCompositingChange(); 875 layer()->updateScrollingStateAfterCompositingChange();
882 const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild; 876 const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild;
(...skipping 17 matching lines...) Expand all
900 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 894 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
901 bool hasVerticalOverflow = this->hasVerticalOverflow(); 895 bool hasVerticalOverflow = this->hasVerticalOverflow();
902 bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow); 896 bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow);
903 bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (has VerticalScrollbar() != hasVerticalOverflow); 897 bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (has VerticalScrollbar() != hasVerticalOverflow);
904 if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged) 898 if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged)
905 box().setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::U nknown); 899 box().setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::U nknown);
906 } 900 }
907 901
908 IntRect DeprecatedPaintLayerScrollableArea::rectForHorizontalScrollbar(const Int Rect& borderBoxRect) const 902 IntRect DeprecatedPaintLayerScrollableArea::rectForHorizontalScrollbar(const Int Rect& borderBoxRect) const
909 { 903 {
910 if (!hasHorizontalScrollbar()) 904 if (!m_hBar)
911 return IntRect(); 905 return IntRect();
912 906
913 const IntRect& scrollCorner = scrollCornerRect(); 907 const IntRect& scrollCorner = scrollCornerRect();
914 908
915 return IntRect(horizontalScrollbarStart(borderBoxRect.x()), 909 return IntRect(horizontalScrollbarStart(borderBoxRect.x()),
916 borderBoxRect.maxY() - box().borderBottom() - horizontalScrollbar()->hei ght(), 910 borderBoxRect.maxY() - box().borderBottom() - m_hBar->height(),
917 borderBoxRect.width() - (box().borderLeft() + box().borderRight()) - scr ollCorner.width(), 911 borderBoxRect.width() - (box().borderLeft() + box().borderRight()) - scr ollCorner.width(),
918 horizontalScrollbar()->height()); 912 m_hBar->height());
919 } 913 }
920 914
921 IntRect DeprecatedPaintLayerScrollableArea::rectForVerticalScrollbar(const IntRe ct& borderBoxRect) const 915 IntRect DeprecatedPaintLayerScrollableArea::rectForVerticalScrollbar(const IntRe ct& borderBoxRect) const
922 { 916 {
923 if (!hasVerticalScrollbar()) 917 if (!m_vBar)
924 return IntRect(); 918 return IntRect();
925 919
926 const IntRect& scrollCorner = scrollCornerRect(); 920 const IntRect& scrollCorner = scrollCornerRect();
927 921
928 return IntRect(verticalScrollbarStart(borderBoxRect.x(), borderBoxRect.maxX( )), 922 return IntRect(verticalScrollbarStart(borderBoxRect.x(), borderBoxRect.maxX( )),
929 borderBoxRect.y() + box().borderTop(), 923 borderBoxRect.y() + box().borderTop(),
930 verticalScrollbar()->width(), 924 m_vBar->width(),
931 borderBoxRect.height() - (box().borderTop() + box().borderBottom()) - sc rollCorner.height()); 925 borderBoxRect.height() - (box().borderTop() + box().borderBottom()) - sc rollCorner.height());
932 } 926 }
933 927
934 LayoutUnit DeprecatedPaintLayerScrollableArea::verticalScrollbarStart(int minX, int maxX) const 928 LayoutUnit DeprecatedPaintLayerScrollableArea::verticalScrollbarStart(int minX, int maxX) const
935 { 929 {
936 if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) 930 if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
937 return minX + box().borderLeft(); 931 return minX + box().borderLeft();
938 return maxX - box().borderRight() - verticalScrollbar()->width(); 932 return maxX - box().borderRight() - m_vBar->width();
939 } 933 }
940 934
941 LayoutUnit DeprecatedPaintLayerScrollableArea::horizontalScrollbarStart(int minX ) const 935 LayoutUnit DeprecatedPaintLayerScrollableArea::horizontalScrollbarStart(int minX ) const
942 { 936 {
943 int x = minX + box().borderLeft(); 937 int x = minX + box().borderLeft();
944 if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) 938 if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
945 x += hasVerticalScrollbar() ? verticalScrollbar()->width() : resizerCorn erRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer).width(); 939 x += m_vBar ? m_vBar->width() : resizerCornerRect(box().pixelSnappedBord erBoxRect(), ResizerForPointer).width();
946 return x; 940 return x;
947 } 941 }
948 942
949 IntSize DeprecatedPaintLayerScrollableArea::scrollbarOffset(const Scrollbar* scr ollbar) const 943 IntSize DeprecatedPaintLayerScrollableArea::scrollbarOffset(const Scrollbar* scr ollbar) const
950 { 944 {
951 if (scrollbar == verticalScrollbar()) 945 if (scrollbar == m_vBar.get())
952 return IntSize(verticalScrollbarStart(0, box().size().width()), box().bo rderTop()); 946 return IntSize(verticalScrollbarStart(0, box().size().width()), box().bo rderTop());
953 947
954 if (scrollbar == horizontalScrollbar()) 948 if (scrollbar == m_hBar.get())
955 return IntSize(horizontalScrollbarStart(0), box().size().height() - box( ).borderBottom() - scrollbar->height()); 949 return IntSize(horizontalScrollbarStart(0), box().size().height() - box( ).borderBottom() - scrollbar->height());
956 950
957 ASSERT_NOT_REACHED(); 951 ASSERT_NOT_REACHED();
958 return IntSize(); 952 return IntSize();
959 } 953 }
960 954
961 static inline LayoutObject* layoutObjectForScrollbar(LayoutObject& layoutObject) 955 static inline LayoutObject* layoutObjectForScrollbar(LayoutObject& layoutObject)
962 { 956 {
963 if (Node* node = layoutObject.node()) { 957 if (Node* node = layoutObject.node()) {
964 if (layoutObject.isLayoutView()) { 958 if (layoutObject.isLayoutView()) {
(...skipping 25 matching lines...) Expand all
990 } 984 }
991 985
992 return &layoutObject; 986 return &layoutObject;
993 } 987 }
994 988
995 bool DeprecatedPaintLayerScrollableArea::needsScrollbarReconstruction() const 989 bool DeprecatedPaintLayerScrollableArea::needsScrollbarReconstruction() const
996 { 990 {
997 LayoutObject* actualLayoutObject = layoutObjectForScrollbar(box()); 991 LayoutObject* actualLayoutObject = layoutObjectForScrollbar(box());
998 bool shouldUseCustom = actualLayoutObject->isBox() && actualLayoutObject->st yle()->hasPseudoStyle(SCROLLBAR); 992 bool shouldUseCustom = actualLayoutObject->isBox() && actualLayoutObject->st yle()->hasPseudoStyle(SCROLLBAR);
999 bool hasAnyScrollbar = hasScrollbar(); 993 bool hasAnyScrollbar = hasScrollbar();
1000 bool hasCustom = (hasHorizontalScrollbar() && horizontalScrollbar()->isCusto mScrollbar()) || (hasVerticalScrollbar() && verticalScrollbar()->isCustomScrollb ar()); 994 bool hasCustom = (m_hBar && m_hBar->isCustomScrollbar()) || (m_vBar && m_vBa r->isCustomScrollbar());
1001 return hasAnyScrollbar && (shouldUseCustom != hasCustom); 995 return hasAnyScrollbar && (shouldUseCustom != hasCustom);
1002 } 996 }
1003 997
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
1004 void DeprecatedPaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrol lbar) 1033 void DeprecatedPaintLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrol lbar)
1005 { 1034 {
1006 if (hasScrollbar == hasHorizontalScrollbar()) 1035 if (hasScrollbar == hasHorizontalScrollbar())
1007 return; 1036 return;
1008 1037
1009 if (!hasScrollbar && !layerForHorizontalScrollbar()) 1038 if (hasScrollbar) {
1010 horizontalScrollbar()->invalidate(); 1039 // This doesn't hit in any tests, but since the equivalent code in setHa sVerticalScrollbar
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.
1011 1047
1012 m_scrollbarManager.setHasHorizontalScrollbar(hasScrollbar); 1048 destroyScrollbar(HorizontalScrollbar);
1049 }
1013 1050
1014 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style. 1051 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style.
1015 if (hasHorizontalScrollbar()) 1052 if (m_hBar)
1016 horizontalScrollbar()->styleChanged(); 1053 m_hBar->styleChanged();
1017 if (hasVerticalScrollbar()) 1054 if (m_vBar)
1018 verticalScrollbar()->styleChanged(); 1055 m_vBar->styleChanged();
1019 1056
1020 // These are valid because we want to invalidate display item clients on the current backing. 1057 // These are valid because we want to invalidate display item clients on the current backing.
1021 DisablePaintInvalidationStateAsserts paintInvalidationAssertDisabler; 1058 DisablePaintInvalidationStateAsserts paintInvalidationAssertDisabler;
1022 DisableCompositingQueryAsserts compositingAssertDisabler; 1059 DisableCompositingQueryAsserts compositingAssertDisabler;
1023 invalidateScrollCorner(scrollCornerRect()); 1060 invalidateScrollCorner(scrollCornerRect());
1024 1061
1025 // Force an update since we know the scrollbars have changed things. 1062 // Force an update since we know the scrollbars have changed things.
1026 if (box().document().hasAnnotatedRegions()) 1063 if (box().document().hasAnnotatedRegions())
1027 box().document().setAnnotatedRegionsDirty(true); 1064 box().document().setAnnotatedRegionsDirty(true);
1028 } 1065 }
1029 1066
1030 void DeprecatedPaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollb ar) 1067 void DeprecatedPaintLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollb ar)
1031 { 1068 {
1032 if (hasScrollbar == hasVerticalScrollbar()) 1069 if (hasScrollbar == hasVerticalScrollbar())
1033 return; 1070 return;
1034 1071
1035 if (!hasScrollbar && !layerForVerticalScrollbar()) 1072 if (hasScrollbar) {
1036 verticalScrollbar()->invalidate(); 1073 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html
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.
1037 1080
1038 m_scrollbarManager.setHasVerticalScrollbar(hasScrollbar); 1081 destroyScrollbar(VerticalScrollbar);
1082 }
1039 1083
1040 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style. 1084 // Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style.
1041 if (hasHorizontalScrollbar()) 1085 if (m_hBar)
1042 horizontalScrollbar()->styleChanged(); 1086 m_hBar->styleChanged();
1043 if (hasVerticalScrollbar()) 1087 if (m_vBar)
1044 verticalScrollbar()->styleChanged(); 1088 m_vBar->styleChanged();
1045 1089
1046 // These are valid because we want to invalidate display item clients on the current backing. 1090 // These are valid because we want to invalidate display item clients on the current backing.
1047 DisablePaintInvalidationStateAsserts paintInvalidationAssertDisabler; 1091 DisablePaintInvalidationStateAsserts paintInvalidationAssertDisabler;
1048 DisableCompositingQueryAsserts compositingAssertDisabler; 1092 DisableCompositingQueryAsserts compositingAssertDisabler;
1049 invalidateScrollCorner(scrollCornerRect()); 1093 invalidateScrollCorner(scrollCornerRect());
1050 1094
1051 // Force an update since we know the scrollbars have changed things. 1095 // Force an update since we know the scrollbars have changed things.
1052 if (box().document().hasAnnotatedRegions()) 1096 if (box().document().hasAnnotatedRegions())
1053 box().document().setAnnotatedRegionsDirty(true); 1097 box().document().setAnnotatedRegionsDirty(true);
1054 } 1098 }
1055 1099
1056 int DeprecatedPaintLayerScrollableArea::verticalScrollbarWidth(OverlayScrollbarS izeRelevancy relevancy) const 1100 int DeprecatedPaintLayerScrollableArea::verticalScrollbarWidth(OverlayScrollbarS izeRelevancy relevancy) const
1057 { 1101 {
1058 if (!hasVerticalScrollbar() || (verticalScrollbar()->isOverlayScrollbar() && (relevancy == IgnoreOverlayScrollbarSize || !verticalScrollbar()->shouldPartici pateInHitTesting()))) 1102 if (!m_vBar || (m_vBar->isOverlayScrollbar() && (relevancy == IgnoreOverlayS crollbarSize || !m_vBar->shouldParticipateInHitTesting())))
1059 return 0; 1103 return 0;
1060 return verticalScrollbar()->width(); 1104 return m_vBar->width();
1061 } 1105 }
1062 1106
1063 int DeprecatedPaintLayerScrollableArea::horizontalScrollbarHeight(OverlayScrollb arSizeRelevancy relevancy) const 1107 int DeprecatedPaintLayerScrollableArea::horizontalScrollbarHeight(OverlayScrollb arSizeRelevancy relevancy) const
1064 { 1108 {
1065 if (!hasHorizontalScrollbar() || (horizontalScrollbar()->isOverlayScrollbar( ) && (relevancy == IgnoreOverlayScrollbarSize || !horizontalScrollbar()->shouldP articipateInHitTesting()))) 1109 if (!m_hBar || (m_hBar->isOverlayScrollbar() && (relevancy == IgnoreOverlayS crollbarSize || !m_hBar->shouldParticipateInHitTesting())))
1066 return 0; 1110 return 0;
1067 return horizontalScrollbar()->height(); 1111 return m_hBar->height();
1068 } 1112 }
1069 1113
1070 void DeprecatedPaintLayerScrollableArea::positionOverflowControls() 1114 void DeprecatedPaintLayerScrollableArea::positionOverflowControls()
1071 { 1115 {
1072 if (!hasScrollbar() && !box().canResize()) 1116 if (!hasScrollbar() && !box().canResize())
1073 return; 1117 return;
1074 1118
1075 const IntRect borderBox = box().pixelSnappedBorderBoxRect(); 1119 const IntRect borderBox = box().pixelSnappedBorderBoxRect();
1076 if (Scrollbar* verticalScrollbar = this->verticalScrollbar()) 1120 if (Scrollbar* verticalScrollbar = this->verticalScrollbar())
1077 verticalScrollbar->setFrameRect(rectForVerticalScrollbar(borderBox)); 1121 verticalScrollbar->setFrameRect(rectForVerticalScrollbar(borderBox));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 return false; 1164 return false;
1121 1165
1122 IntRect resizeControlRect; 1166 IntRect resizeControlRect;
1123 if (box().style()->resize() != RESIZE_NONE) { 1167 if (box().style()->resize() != RESIZE_NONE) {
1124 resizeControlRect = resizerCornerRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer); 1168 resizeControlRect = resizerCornerRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer);
1125 if (resizeControlRect.contains(localPoint)) 1169 if (resizeControlRect.contains(localPoint))
1126 return true; 1170 return true;
1127 } 1171 }
1128 1172
1129 int resizeControlSize = max(resizeControlRect.height(), 0); 1173 int resizeControlSize = max(resizeControlRect.height(), 0);
1130 if (hasVerticalScrollbar() && verticalScrollbar()->shouldParticipateInHitTes ting()) { 1174 if (m_vBar && m_vBar->shouldParticipateInHitTesting()) {
1131 LayoutRect vBarRect(verticalScrollbarStart(0, box().size().width()), 1175 LayoutRect vBarRect(verticalScrollbarStart(0, box().size().width()),
1132 box().borderTop(), 1176 box().borderTop(),
1133 verticalScrollbar()->width(), 1177 m_vBar->width(),
1134 box().size().height() - (box().borderTop() + box().borderBottom()) - (hasHorizontalScrollbar() ? horizontalScrollbar()->height() : resizeControlSize )); 1178 box().size().height() - (box().borderTop() + box().borderBottom()) - (m_hBar ? m_hBar->height() : resizeControlSize));
1135 if (vBarRect.contains(localPoint)) { 1179 if (vBarRect.contains(localPoint)) {
1136 result.setScrollbar(verticalScrollbar()); 1180 result.setScrollbar(m_vBar.get());
1137 return true; 1181 return true;
1138 } 1182 }
1139 } 1183 }
1140 1184
1141 resizeControlSize = max(resizeControlRect.width(), 0); 1185 resizeControlSize = max(resizeControlRect.width(), 0);
1142 if (hasHorizontalScrollbar() && horizontalScrollbar()->shouldParticipateInHi tTesting()) { 1186 if (m_hBar && m_hBar->shouldParticipateInHitTesting()) {
1143 LayoutRect hBarRect(horizontalScrollbarStart(0), 1187 LayoutRect hBarRect(horizontalScrollbarStart(0),
1144 box().size().height() - box().borderBottom() - horizontalScrollbar() ->height(), 1188 box().size().height() - box().borderBottom() - m_hBar->height(),
1145 box().size().width() - (box().borderLeft() + box().borderRight()) - (hasVerticalScrollbar() ? verticalScrollbar()->width() : resizeControlSize), 1189 box().size().width() - (box().borderLeft() + box().borderRight()) - (m_vBar ? m_vBar->width() : resizeControlSize),
1146 horizontalScrollbar()->height()); 1190 m_hBar->height());
1147 if (hBarRect.contains(localPoint)) { 1191 if (hBarRect.contains(localPoint)) {
1148 result.setScrollbar(horizontalScrollbar()); 1192 result.setScrollbar(m_hBar.get());
1149 return true; 1193 return true;
1150 } 1194 }
1151 } 1195 }
1152 1196
1153 // FIXME: We should hit test the m_scrollCorner and pass it back through the result. 1197 // FIXME: We should hit test the m_scrollCorner and pass it back through the result.
1154 1198
1155 return false; 1199 return false;
1156 } 1200 }
1157 1201
1158 IntRect DeprecatedPaintLayerScrollableArea::resizerCornerRect(const IntRect& bou nds, ResizerHitTestType resizerHitTestType) const 1202 IntRect DeprecatedPaintLayerScrollableArea::resizerCornerRect(const IntRect& bou nds, ResizerHitTestType resizerHitTestType) const
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 if (!layer()->isRootLayer()) 1483 if (!layer()->isRootLayer())
1440 return false; 1484 return false;
1441 1485
1442 LocalFrame* frame = box().frame(); 1486 LocalFrame* frame = box().frame();
1443 if (!frame || !frame->isMainFrame() || !frame->settings()) 1487 if (!frame || !frame->isMainFrame() || !frame->settings())
1444 return false; 1488 return false;
1445 1489
1446 return frame->settings()->viewportMetaEnabled(); 1490 return frame->settings()->viewportMetaEnabled();
1447 } 1491 }
1448 1492
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
1552 } // namespace blink 1493 } // 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