Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/ScrollableAreaPainter.h" | 6 #include "core/paint/ScrollableAreaPainter.h" |
| 7 | 7 |
| 8 #include "core/layout/Layer.h" | 8 #include "core/layout/Layer.h" |
| 9 #include "core/layout/LayerScrollableArea.h" | 9 #include "core/layout/LayerScrollableArea.h" |
| 10 #include "core/layout/PaintInfo.h" | 10 #include "core/layout/PaintInfo.h" |
| 11 #include "core/page/Page.h" | 11 #include "core/page/Page.h" |
| 12 #include "core/paint/ScrollbarPainter.h" | 12 #include "core/paint/ScrollbarPainter.h" |
| 13 #include "core/paint/TransformRecorder.h" | |
| 13 #include "core/rendering/RenderView.h" | 14 #include "core/rendering/RenderView.h" |
| 14 #include "platform/graphics/GraphicsContext.h" | 15 #include "platform/graphics/GraphicsContext.h" |
| 15 #include "platform/graphics/GraphicsContextStateSaver.h" | 16 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 16 #include "platform/graphics/paint/DrawingRecorder.h" | 17 #include "platform/graphics/paint/DrawingRecorder.h" |
| 17 | 18 |
| 18 namespace blink { | 19 namespace blink { |
| 19 | 20 |
| 20 void ScrollableAreaPainter::paintResizer(GraphicsContext* context, const IntPoin t& paintOffset, const IntRect& damageRect) | 21 void ScrollableAreaPainter::paintResizer(GraphicsContext* context, const IntPoin t& paintOffset, const IntRect& damageRect) |
| 21 { | 22 { |
| 22 if (m_renderLayerScrollableArea.box().style()->resize() == RESIZE_NONE) | 23 if (m_renderLayerScrollableArea.box().style()->resize() == RESIZE_NONE) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 void ScrollableAreaPainter::paintOverflowControls(GraphicsContext* context, cons t IntPoint& paintOffset, const IntRect& damageRect, bool paintingOverlayControls ) | 85 void ScrollableAreaPainter::paintOverflowControls(GraphicsContext* context, cons t IntPoint& paintOffset, const IntRect& damageRect, bool paintingOverlayControls ) |
| 85 { | 86 { |
| 86 // Don't do anything if we have no overflow. | 87 // Don't do anything if we have no overflow. |
| 87 if (!m_renderLayerScrollableArea.box().hasOverflowClip()) | 88 if (!m_renderLayerScrollableArea.box().hasOverflowClip()) |
| 88 return; | 89 return; |
| 89 | 90 |
| 90 IntPoint adjustedPaintOffset = paintOffset; | 91 IntPoint adjustedPaintOffset = paintOffset; |
| 91 if (paintingOverlayControls) | 92 if (paintingOverlayControls) |
| 92 adjustedPaintOffset = m_renderLayerScrollableArea.cachedOverlayScrollbar Offset(); | 93 adjustedPaintOffset = m_renderLayerScrollableArea.cachedOverlayScrollbar Offset(); |
| 93 | 94 |
| 94 // Move the scrollbar widgets if necessary. We normally move and resize widg ets during layout, | 95 IntRect localDamageRect = damageRect; |
| 95 // but sometimes widgets can move without layout occurring (most notably whe n you scroll a | 96 localDamageRect.moveBy(-adjustedPaintOffset); |
| 96 // document that contains fixed positioned elements). | |
| 97 | |
| 98 // FIXME: this code should not be necessary. | |
| 99 m_renderLayerScrollableArea.positionOverflowControls(toIntSize(adjustedPaint Offset)); | |
| 100 | 97 |
| 101 // Overlay scrollbars paint in a second pass through the layer tree so that they will paint | 98 // Overlay scrollbars paint in a second pass through the layer tree so that they will paint |
| 102 // on top of everything else. If this is the normal painting pass, paintingO verlayControls | 99 // on top of everything else. If this is the normal painting pass, paintingO verlayControls |
| 103 // will be false, and we should just tell the root layer that there are over lay scrollbars | 100 // will be false, and we should just tell the root layer that there are over lay scrollbars |
| 104 // that need to be painted. That will cause the second pass through the laye r tree to run, | 101 // that need to be painted. That will cause the second pass through the laye r tree to run, |
| 105 // and we'll paint the scrollbars then. In the meantime, cache tx and ty so that the | 102 // and we'll paint the scrollbars then. In the meantime, cache tx and ty so that the |
| 106 // second pass doesn't need to re-enter the RenderTree to get it right. | 103 // second pass doesn't need to re-enter the RenderTree to get it right. |
| 107 if (m_renderLayerScrollableArea.hasOverlayScrollbars() && !paintingOverlayCo ntrols) { | 104 if (m_renderLayerScrollableArea.hasOverlayScrollbars() && !paintingOverlayCo ntrols) { |
| 108 m_renderLayerScrollableArea.setCachedOverlayScrollbarOffset(paintOffset) ; | 105 m_renderLayerScrollableArea.setCachedOverlayScrollbarOffset(paintOffset) ; |
| 109 // It's not necessary to do the second pass if the scrollbars paint into layers. | 106 // It's not necessary to do the second pass if the scrollbars paint into layers. |
| 110 if ((m_renderLayerScrollableArea.horizontalScrollbar() && m_renderLayerS crollableArea.layerForHorizontalScrollbar()) || (m_renderLayerScrollableArea.ver ticalScrollbar() && m_renderLayerScrollableArea.layerForVerticalScrollbar())) | 107 if ((m_renderLayerScrollableArea.horizontalScrollbar() && m_renderLayerS crollableArea.layerForHorizontalScrollbar()) || (m_renderLayerScrollableArea.ver ticalScrollbar() && m_renderLayerScrollableArea.layerForVerticalScrollbar())) |
| 111 return; | 108 return; |
| 112 IntRect localDamgeRect = damageRect; | 109 if (!overflowControlsIntersectRect(localDamageRect)) |
| 113 localDamgeRect.moveBy(-paintOffset); | |
| 114 if (!overflowControlsIntersectRect(localDamgeRect)) | |
| 115 return; | 110 return; |
| 116 | 111 |
| 117 RenderView* renderView = m_renderLayerScrollableArea.box().view(); | 112 RenderView* renderView = m_renderLayerScrollableArea.box().view(); |
| 118 | 113 |
| 119 Layer* paintingRoot = m_renderLayerScrollableArea.layer()->enclosingLaye rWithCompositedLayerMapping(IncludeSelf); | 114 Layer* paintingRoot = m_renderLayerScrollableArea.layer()->enclosingLaye rWithCompositedLayerMapping(IncludeSelf); |
| 120 if (!paintingRoot) | 115 if (!paintingRoot) |
| 121 paintingRoot = renderView->layer(); | 116 paintingRoot = renderView->layer(); |
| 122 | 117 |
| 123 paintingRoot->setContainsDirtyOverlayScrollbars(true); | 118 paintingRoot->setContainsDirtyOverlayScrollbars(true); |
| 124 return; | 119 return; |
| 125 } | 120 } |
| 126 | 121 |
| 127 // This check is required to avoid painting custom CSS scrollbars twice. | 122 // This check is required to avoid painting custom CSS scrollbars twice. |
| 128 if (paintingOverlayControls && !m_renderLayerScrollableArea.hasOverlayScroll bars()) | 123 if (paintingOverlayControls && !m_renderLayerScrollableArea.hasOverlayScroll bars()) |
| 129 return; | 124 return; |
| 130 | 125 |
| 131 // Now that we're sure the scrollbars are in the right place, paint them. | 126 { |
| 132 if (m_renderLayerScrollableArea.horizontalScrollbar() && !m_renderLayerScrol lableArea.layerForHorizontalScrollbar()) | 127 TransformRecorder translateRecorder(*context, m_renderLayerScrollableAre a.displayItemClient(), AffineTransform::translation(adjustedPaintOffset.x(), adj ustedPaintOffset.y())); |
|
Julien - ping for review
2015/02/25 01:43:36
Ideally we would want this scope to extend to the
Xianzhu
2015/02/25 01:57:09
Agreed. Tried this but found that paintScrollCorne
| |
| 133 m_renderLayerScrollableArea.horizontalScrollbar()->paint(context, damage Rect); | 128 if (m_renderLayerScrollableArea.horizontalScrollbar() && !m_renderLayerS crollableArea.layerForHorizontalScrollbar()) |
| 134 if (m_renderLayerScrollableArea.verticalScrollbar() && !m_renderLayerScrolla bleArea.layerForVerticalScrollbar()) | 129 m_renderLayerScrollableArea.horizontalScrollbar()->paint(context, lo calDamageRect); |
| 135 m_renderLayerScrollableArea.verticalScrollbar()->paint(context, damageRe ct); | 130 if (m_renderLayerScrollableArea.verticalScrollbar() && !m_renderLayerScr ollableArea.layerForVerticalScrollbar()) |
| 131 m_renderLayerScrollableArea.verticalScrollbar()->paint(context, loca lDamageRect); | |
| 132 } | |
| 136 | 133 |
| 137 if (m_renderLayerScrollableArea.layerForScrollCorner()) | 134 if (m_renderLayerScrollableArea.layerForScrollCorner()) |
| 138 return; | 135 return; |
| 139 | 136 |
| 140 // We fill our scroll corner with white if we have a scrollbar that doesn't run all the way up to the | 137 // We fill our scroll corner with white if we have a scrollbar that doesn't run all the way up to the |
| 141 // edge of the box. | 138 // edge of the box. |
| 142 paintScrollCorner(context, adjustedPaintOffset, damageRect); | 139 paintScrollCorner(context, adjustedPaintOffset, damageRect); |
| 143 | 140 |
| 144 // Paint our resizer last, since it sits on top of the scroll corner. | 141 // Paint our resizer last, since it sits on top of the scroll corner. |
| 145 paintResizer(context, adjustedPaintOffset, damageRect); | 142 paintResizer(context, adjustedPaintOffset, damageRect); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 if (recorder.canUseCachedDrawing()) | 178 if (recorder.canUseCachedDrawing()) |
| 182 return; | 179 return; |
| 183 | 180 |
| 184 // We don't want to paint white if we have overlay scrollbars, since we need | 181 // We don't want to paint white if we have overlay scrollbars, since we need |
| 185 // to see what is behind it. | 182 // to see what is behind it. |
| 186 if (!m_renderLayerScrollableArea.hasOverlayScrollbars()) | 183 if (!m_renderLayerScrollableArea.hasOverlayScrollbars()) |
| 187 context->fillRect(absRect, Color::white); | 184 context->fillRect(absRect, Color::white); |
| 188 } | 185 } |
| 189 | 186 |
| 190 } // namespace blink | 187 } // namespace blink |
| OLD | NEW |