| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/paint/PaintInvalidationCapableScrollableArea.h" | 5 #include "core/paint/PaintInvalidationCapableScrollableArea.h" |
| 6 | 6 |
| 7 #include "core/frame/Settings.h" | 7 #include "core/frame/Settings.h" |
| 8 #include "core/html/HTMLFrameOwnerElement.h" | 8 #include "core/html/HTMLFrameOwnerElement.h" |
| 9 #include "core/layout/LayoutBox.h" | 9 #include "core/layout/LayoutBox.h" |
| 10 #include "core/layout/LayoutScrollbar.h" | 10 #include "core/layout/LayoutScrollbar.h" |
| 11 #include "core/layout/LayoutScrollbarPart.h" | 11 #include "core/layout/LayoutScrollbarPart.h" |
| 12 #include "core/layout/PaintInvalidationState.h" | 12 #include "core/layout/PaintInvalidationState.h" |
| 13 #include "core/paint/PaintLayer.h" | 13 #include "core/paint/PaintLayer.h" |
| 14 #include "platform/graphics/GraphicsLayer.h" | 14 #include "platform/graphics/GraphicsLayer.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 void PaintInvalidationCapableScrollableArea::willRemoveScrollbar(Scrollbar& scro
llbar, ScrollbarOrientation orientation) | 18 void PaintInvalidationCapableScrollableArea::willRemoveScrollbar(Scrollbar& scro
llbar, ScrollbarOrientation orientation) |
| 19 { | 19 { |
| 20 if (!scrollbar.isCustomScrollbar() | 20 if (!scrollbar.isCustomScrollbar() |
| 21 && !(orientation == HorizontalScrollbar ? layerForHorizontalScrollbar()
: layerForVerticalScrollbar())) | 21 && !(orientation == HorizontalScrollbar ? layerForHorizontalScrollbar()
: layerForVerticalScrollbar())) |
| 22 boxForScrollControlPaintInvalidation().invalidateDisplayItemClient(scrol
lbar); | 22 boxForScrollControlPaintInvalidation().invalidateDisplayItemClient(scrol
lbar); |
| 23 | 23 |
| 24 ScrollableArea::willRemoveScrollbar(scrollbar, orientation); | 24 ScrollableArea::willRemoveScrollbar(scrollbar, orientation); |
| 25 } | 25 } |
| 26 | 26 |
| 27 static LayoutRect scrollControlPaintInvalidationRect(const IntRect& scrollContro
lRect, const LayoutBox& box, const PaintInvalidationState& paintInvalidationStat
e, const LayoutBoxModelObject& paintInvalidationContainer) | 27 static LayoutRect scrollControlPaintInvalidationRect(const IntRect& scrollContro
lRect, const LayoutBox& box, const PaintInvalidationState& paintInvalidationStat
e) |
| 28 { | 28 { |
| 29 LayoutRect paintInvalidationRect(scrollControlRect); | 29 LayoutRect paintInvalidationRect(scrollControlRect); |
| 30 if (!paintInvalidationRect.isEmpty()) | 30 if (!paintInvalidationRect.isEmpty()) |
| 31 PaintLayer::mapRectToPaintInvalidationBacking(&box, &paintInvalidationCo
ntainer, paintInvalidationRect, &paintInvalidationState); | 31 PaintLayer::mapRectToPaintInvalidationBacking(&box, &paintInvalidationSt
ate.paintInvalidationContainer(), paintInvalidationRect, &paintInvalidationState
); |
| 32 return paintInvalidationRect; | 32 return paintInvalidationRect; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Returns true if the scroll control is invalidated. | 35 // Returns true if the scroll control is invalidated. |
| 36 static bool invalidatePaintOfScrollControlIfNeeded(const LayoutRect& newPaintInv
alidationRect, const LayoutRect& previousPaintInvalidationRect, bool needsPaintI
nvalidation, LayoutBox& box, const LayoutBoxModelObject& paintInvalidationContai
ner) | 36 static bool invalidatePaintOfScrollControlIfNeeded(const LayoutRect& newPaintInv
alidationRect, const LayoutRect& previousPaintInvalidationRect, bool needsPaintI
nvalidation, LayoutBox& box, const LayoutBoxModelObject& paintInvalidationContai
ner) |
| 37 { | 37 { |
| 38 bool shouldInvalidateNewRect = needsPaintInvalidation; | 38 bool shouldInvalidateNewRect = needsPaintInvalidation; |
| 39 if (newPaintInvalidationRect != previousPaintInvalidationRect) { | 39 if (newPaintInvalidationRect != previousPaintInvalidationRect) { |
| 40 box.invalidatePaintUsingContainer(paintInvalidationContainer, previousPa
intInvalidationRect, PaintInvalidationScroll); | 40 box.invalidatePaintUsingContainer(paintInvalidationContainer, previousPa
intInvalidationRect, PaintInvalidationScroll); |
| 41 shouldInvalidateNewRect = true; | 41 shouldInvalidateNewRect = true; |
| 42 } | 42 } |
| 43 if (shouldInvalidateNewRect) { | 43 if (shouldInvalidateNewRect) { |
| 44 box.invalidatePaintUsingContainer(paintInvalidationContainer, newPaintIn
validationRect, PaintInvalidationScroll); | 44 box.invalidatePaintUsingContainer(paintInvalidationContainer, newPaintIn
validationRect, PaintInvalidationScroll); |
| 45 box.enclosingLayer()->setNeedsRepaint(); | 45 box.enclosingLayer()->setNeedsRepaint(); |
| 46 return true; | 46 return true; |
| 47 } | 47 } |
| 48 return false; | 48 return false; |
| 49 } | 49 } |
| 50 | 50 |
| 51 static void invalidatePaintOfScrollbarIfNeeded(Scrollbar* scrollbar, GraphicsLay
er* graphicsLayer, bool& previouslyWasOverlay, LayoutRect& previousPaintInvalida
tionRect, bool needsPaintInvalidationArg, LayoutBox& box, const PaintInvalidatio
nState& paintInvalidationState, const LayoutBoxModelObject& paintInvalidationCon
tainer) | 51 static void invalidatePaintOfScrollbarIfNeeded(Scrollbar* scrollbar, GraphicsLay
er* graphicsLayer, bool& previouslyWasOverlay, LayoutRect& previousPaintInvalida
tionRect, bool needsPaintInvalidationArg, LayoutBox& box, const PaintInvalidatio
nState& paintInvalidationState) |
| 52 { | 52 { |
| 53 bool isOverlay = scrollbar && scrollbar->isOverlayScrollbar(); | 53 bool isOverlay = scrollbar && scrollbar->isOverlayScrollbar(); |
| 54 | 54 |
| 55 // Calculate paint invalidation rect of the scrollbar, except overlay compos
ited scrollbars because we invalidate the graphics layer only. | 55 // Calculate paint invalidation rect of the scrollbar, except overlay compos
ited scrollbars because we invalidate the graphics layer only. |
| 56 LayoutRect newPaintInvalidationRect; | 56 LayoutRect newPaintInvalidationRect; |
| 57 if (scrollbar && !(graphicsLayer && isOverlay)) | 57 if (scrollbar && !(graphicsLayer && isOverlay)) |
| 58 newPaintInvalidationRect = scrollControlPaintInvalidationRect(scrollbar-
>frameRect(), box, paintInvalidationState, paintInvalidationContainer); | 58 newPaintInvalidationRect = scrollControlPaintInvalidationRect(scrollbar-
>frameRect(), box, paintInvalidationState); |
| 59 | 59 |
| 60 bool needsPaintInvalidation = needsPaintInvalidationArg; | 60 bool needsPaintInvalidation = needsPaintInvalidationArg; |
| 61 if (graphicsLayer) { | 61 if (graphicsLayer) { |
| 62 // If the scrollbar needs paint invalidation but didn't change location/
size or the scrollbar is an | 62 // If the scrollbar needs paint invalidation but didn't change location/
size or the scrollbar is an |
| 63 // overlay scrollbar (paint invalidation rect is empty), invalidating th
e graphics layer is enough | 63 // overlay scrollbar (paint invalidation rect is empty), invalidating th
e graphics layer is enough |
| 64 // (which has been done in ScrollableArea::setScrollbarNeedsPaintInvalid
ation()). | 64 // (which has been done in ScrollableArea::setScrollbarNeedsPaintInvalid
ation()). |
| 65 // Otherwise invalidatePaintOfScrollControlIfNeeded() below will invalid
ate the old and new location | 65 // Otherwise invalidatePaintOfScrollControlIfNeeded() below will invalid
ate the old and new location |
| 66 // of the scrollbar on the box's paint invalidation container to ensure
newly expanded/shrunk areas | 66 // of the scrollbar on the box's paint invalidation container to ensure
newly expanded/shrunk areas |
| 67 // of the box to be invalidated. | 67 // of the box to be invalidated. |
| 68 needsPaintInvalidation = false; | 68 needsPaintInvalidation = false; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Invalidate the box's display item client if the box's padding box size is
affected by change of the | 71 // Invalidate the box's display item client if the box's padding box size is
affected by change of the |
| 72 // non-overlay scrollbar width. We detect change of paint invalidation rect
size instead of change of | 72 // non-overlay scrollbar width. We detect change of paint invalidation rect
size instead of change of |
| 73 // scrollbar width change, which may have some false-positives (e.g. the scr
ollbar changed length but | 73 // scrollbar width change, which may have some false-positives (e.g. the scr
ollbar changed length but |
| 74 // not width) but won't invalidate more than expected because in the false-p
ositive case the box must | 74 // not width) but won't invalidate more than expected because in the false-p
ositive case the box must |
| 75 // have changed size and have been invalidated. | 75 // have changed size and have been invalidated. |
| 76 const LayoutBoxModelObject& paintInvalidationContainer = paintInvalidationSt
ate.paintInvalidationContainer(); |
| 76 LayoutSize newScrollbarUsedSpaceInBox; | 77 LayoutSize newScrollbarUsedSpaceInBox; |
| 77 if (!isOverlay) | 78 if (!isOverlay) |
| 78 newScrollbarUsedSpaceInBox = newPaintInvalidationRect.size(); | 79 newScrollbarUsedSpaceInBox = newPaintInvalidationRect.size(); |
| 79 LayoutSize previousScrollbarUsedSpaceInBox; | 80 LayoutSize previousScrollbarUsedSpaceInBox; |
| 80 if (!previouslyWasOverlay) | 81 if (!previouslyWasOverlay) |
| 81 previousScrollbarUsedSpaceInBox= previousPaintInvalidationRect.size(); | 82 previousScrollbarUsedSpaceInBox= previousPaintInvalidationRect.size(); |
| 82 if (newScrollbarUsedSpaceInBox != previousScrollbarUsedSpaceInBox) | 83 if (newScrollbarUsedSpaceInBox != previousScrollbarUsedSpaceInBox) |
| 83 paintInvalidationContainer.invalidateDisplayItemClientOnBacking(box, Pai
ntInvalidationScroll); | 84 paintInvalidationContainer.invalidateDisplayItemClientOnBacking(box, Pai
ntInvalidationScroll); |
| 84 | 85 |
| 85 bool invalidated = invalidatePaintOfScrollControlIfNeeded(newPaintInvalidati
onRect, previousPaintInvalidationRect, needsPaintInvalidation, box, paintInvalid
ationContainer); | 86 bool invalidated = invalidatePaintOfScrollControlIfNeeded(newPaintInvalidati
onRect, previousPaintInvalidationRect, needsPaintInvalidation, box, paintInvalid
ationContainer); |
| 86 | 87 |
| 87 previousPaintInvalidationRect = newPaintInvalidationRect; | 88 previousPaintInvalidationRect = newPaintInvalidationRect; |
| 88 previouslyWasOverlay = isOverlay; | 89 previouslyWasOverlay = isOverlay; |
| 89 | 90 |
| 90 if (!invalidated || !scrollbar || graphicsLayer) | 91 if (!invalidated || !scrollbar || graphicsLayer) |
| 91 return; | 92 return; |
| 92 | 93 |
| 93 paintInvalidationContainer.invalidateDisplayItemClientOnBacking(*scrollbar,
PaintInvalidationScroll); | 94 paintInvalidationContainer.invalidateDisplayItemClientOnBacking(*scrollbar,
PaintInvalidationScroll); |
| 94 if (scrollbar->isCustomScrollbar()) | 95 if (scrollbar->isCustomScrollbar()) |
| 95 toLayoutScrollbar(scrollbar)->invalidateDisplayItemClientsOfScrollbarPar
ts(paintInvalidationContainer); | 96 toLayoutScrollbar(scrollbar)->invalidateDisplayItemClientsOfScrollbarPar
ts(paintInvalidationContainer); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void PaintInvalidationCapableScrollableArea::invalidatePaintOfScrollControlsIfNe
eded(const PaintInvalidationState& paintInvalidationState, const LayoutBoxModelO
bject& paintInvalidationContainer) | 99 void PaintInvalidationCapableScrollableArea::invalidatePaintOfScrollControlsIfNe
eded(const PaintInvalidationState& paintInvalidationState) |
| 99 { | 100 { |
| 100 LayoutBox& box = boxForScrollControlPaintInvalidation(); | 101 LayoutBox& box = boxForScrollControlPaintInvalidation(); |
| 101 invalidatePaintOfScrollbarIfNeeded(horizontalScrollbar(), layerForHorizontal
Scrollbar(), m_horizontalScrollbarPreviouslyWasOverlay, m_horizontalScrollbarPre
viousPaintInvalidationRect, horizontalScrollbarNeedsPaintInvalidation(), box, pa
intInvalidationState, paintInvalidationContainer); | 102 invalidatePaintOfScrollbarIfNeeded(horizontalScrollbar(), layerForHorizontal
Scrollbar(), m_horizontalScrollbarPreviouslyWasOverlay, m_horizontalScrollbarPre
viousPaintInvalidationRect, horizontalScrollbarNeedsPaintInvalidation(), box, pa
intInvalidationState); |
| 102 invalidatePaintOfScrollbarIfNeeded(verticalScrollbar(), layerForVerticalScro
llbar(), m_verticalScrollbarPreviouslyWasOverlay, m_verticalScrollbarPreviousPai
ntInvalidationRect, verticalScrollbarNeedsPaintInvalidation(), box, paintInvalid
ationState, paintInvalidationContainer); | 103 invalidatePaintOfScrollbarIfNeeded(verticalScrollbar(), layerForVerticalScro
llbar(), m_verticalScrollbarPreviouslyWasOverlay, m_verticalScrollbarPreviousPai
ntInvalidationRect, verticalScrollbarNeedsPaintInvalidation(), box, paintInvalid
ationState); |
| 103 | 104 |
| 104 LayoutRect scrollCornerPaintInvalidationRect = scrollControlPaintInvalidatio
nRect(scrollCornerAndResizerRect(), box, paintInvalidationState, paintInvalidati
onContainer); | 105 LayoutRect scrollCornerPaintInvalidationRect = scrollControlPaintInvalidatio
nRect(scrollCornerAndResizerRect(), box, paintInvalidationState); |
| 106 const LayoutBoxModelObject& paintInvalidationContainer = paintInvalidationSt
ate.paintInvalidationContainer(); |
| 105 if (invalidatePaintOfScrollControlIfNeeded(scrollCornerPaintInvalidationRect
, m_scrollCornerAndResizerPreviousPaintInvalidationRect, scrollCornerNeedsPaintI
nvalidation(), box, paintInvalidationContainer)) { | 107 if (invalidatePaintOfScrollControlIfNeeded(scrollCornerPaintInvalidationRect
, m_scrollCornerAndResizerPreviousPaintInvalidationRect, scrollCornerNeedsPaintI
nvalidation(), box, paintInvalidationContainer)) { |
| 106 m_scrollCornerAndResizerPreviousPaintInvalidationRect = scrollCornerPain
tInvalidationRect; | 108 m_scrollCornerAndResizerPreviousPaintInvalidationRect = scrollCornerPain
tInvalidationRect; |
| 107 if (LayoutScrollbarPart* scrollCorner = this->scrollCorner()) | 109 if (LayoutScrollbarPart* scrollCorner = this->scrollCorner()) |
| 108 scrollCorner->invalidateDisplayItemClientsIncludingNonCompositingDes
cendants(&paintInvalidationContainer, PaintInvalidationScroll); | 110 scrollCorner->invalidateDisplayItemClientsIncludingNonCompositingDes
cendants(&paintInvalidationContainer, PaintInvalidationScroll); |
| 109 if (LayoutScrollbarPart* resizer = this->resizer()) | 111 if (LayoutScrollbarPart* resizer = this->resizer()) |
| 110 resizer->invalidateDisplayItemClientsIncludingNonCompositingDescenda
nts(&paintInvalidationContainer, PaintInvalidationScroll); | 112 resizer->invalidateDisplayItemClientsIncludingNonCompositingDescenda
nts(&paintInvalidationContainer, PaintInvalidationScroll); |
| 111 } | 113 } |
| 112 | 114 |
| 113 clearNeedsPaintInvalidationForScrollControls(); | 115 clearNeedsPaintInvalidationForScrollControls(); |
| 114 } | 116 } |
| 115 | 117 |
| 116 void PaintInvalidationCapableScrollableArea::clearPreviousPaintInvalidationRects
() | 118 void PaintInvalidationCapableScrollableArea::clearPreviousPaintInvalidationRects
() |
| 117 { | 119 { |
| 118 m_horizontalScrollbarPreviousPaintInvalidationRect = LayoutRect(); | 120 m_horizontalScrollbarPreviousPaintInvalidationRect = LayoutRect(); |
| 119 m_verticalScrollbarPreviousPaintInvalidationRect = LayoutRect(); | 121 m_verticalScrollbarPreviousPaintInvalidationRect = LayoutRect(); |
| 120 m_scrollCornerAndResizerPreviousPaintInvalidationRect = LayoutRect(); | 122 m_scrollCornerAndResizerPreviousPaintInvalidationRect = LayoutRect(); |
| 121 } | 123 } |
| 122 | 124 |
| 123 } // namespace blink | 125 } // namespace blink |
| OLD | NEW |