| 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/LayoutView.h" | 8 #include "core/layout/LayoutView.h" |
| 9 #include "core/page/Page.h" | 9 #include "core/page/Page.h" |
| 10 #include "core/paint/LayoutObjectDrawingRecorder.h" | 10 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 11 #include "core/paint/PaintInfo.h" | 11 #include "core/paint/PaintInfo.h" |
| 12 #include "core/paint/PaintLayer.h" | 12 #include "core/paint/PaintLayer.h" |
| 13 #include "core/paint/PaintLayerScrollableArea.h" | 13 #include "core/paint/PaintLayerScrollableArea.h" |
| 14 #include "core/paint/ScrollbarPainter.h" | 14 #include "core/paint/ScrollbarPainter.h" |
| 15 #include "core/paint/TransformRecorder.h" | 15 #include "core/paint/TransformRecorder.h" |
| 16 #include "platform/graphics/GraphicsContext.h" | 16 #include "platform/graphics/GraphicsContext.h" |
| 17 #include "platform/graphics/GraphicsContextStateSaver.h" | 17 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 void ScrollableAreaPainter::paintResizer(GraphicsContext* context, const IntPoin
t& paintOffset, const CullRect& cullRect) | 21 void ScrollableAreaPainter::paintResizer(GraphicsContext& context, const IntPoin
t& paintOffset, const CullRect& cullRect) |
| 22 { | 22 { |
| 23 if (scrollableArea().box().style()->resize() == RESIZE_NONE) | 23 if (scrollableArea().box().style()->resize() == RESIZE_NONE) |
| 24 return; | 24 return; |
| 25 | 25 |
| 26 IntRect absRect = scrollableArea().resizerCornerRect(scrollableArea().box().
pixelSnappedBorderBoxRect(), ResizerForPointer); | 26 IntRect absRect = scrollableArea().resizerCornerRect(scrollableArea().box().
pixelSnappedBorderBoxRect(), ResizerForPointer); |
| 27 if (absRect.isEmpty()) | 27 if (absRect.isEmpty()) |
| 28 return; | 28 return; |
| 29 absRect.moveBy(paintOffset); | 29 absRect.moveBy(paintOffset); |
| 30 | 30 |
| 31 if (scrollableArea().resizer()) { | 31 if (scrollableArea().resizer()) { |
| 32 if (!cullRect.intersectsCullRect(absRect)) | 32 if (!cullRect.intersectsCullRect(absRect)) |
| 33 return; | 33 return; |
| 34 ScrollbarPainter::paintIntoRect(*scrollableArea().resizer(), context, pa
intOffset, LayoutRect(absRect)); | 34 ScrollbarPainter::paintIntoRect(*scrollableArea().resizer(), context, pa
intOffset, LayoutRect(absRect)); |
| 35 return; | 35 return; |
| 36 } | 36 } |
| 37 | 37 |
| 38 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, scroll
ableArea().box(), DisplayItem::Resizer, paintOffset)) | 38 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, scrolla
bleArea().box(), DisplayItem::Resizer, paintOffset)) |
| 39 return; | 39 return; |
| 40 | 40 |
| 41 LayoutObjectDrawingRecorder recorder(*context, scrollableArea().box(), Displ
ayItem::Resizer, absRect, paintOffset); | 41 LayoutObjectDrawingRecorder recorder(context, scrollableArea().box(), Displa
yItem::Resizer, absRect, paintOffset); |
| 42 | 42 |
| 43 drawPlatformResizerImage(context, absRect); | 43 drawPlatformResizerImage(context, absRect); |
| 44 | 44 |
| 45 // Draw a frame around the resizer (1px grey line) if there are any scrollba
rs present. | 45 // Draw a frame around the resizer (1px grey line) if there are any scrollba
rs present. |
| 46 // Clipping will exclude the right and bottom edges of this frame. | 46 // Clipping will exclude the right and bottom edges of this frame. |
| 47 if (!scrollableArea().hasOverlayScrollbars() && scrollableArea().hasScrollba
r()) { | 47 if (!scrollableArea().hasOverlayScrollbars() && scrollableArea().hasScrollba
r()) { |
| 48 GraphicsContextStateSaver stateSaver(*context); | 48 GraphicsContextStateSaver stateSaver(context); |
| 49 context->clip(absRect); | 49 context.clip(absRect); |
| 50 IntRect largerCorner = absRect; | 50 IntRect largerCorner = absRect; |
| 51 largerCorner.setSize(IntSize(largerCorner.width() + 1, largerCorner.heig
ht() + 1)); | 51 largerCorner.setSize(IntSize(largerCorner.width() + 1, largerCorner.heig
ht() + 1)); |
| 52 context->setStrokeColor(Color(217, 217, 217)); | 52 context.setStrokeColor(Color(217, 217, 217)); |
| 53 context->setStrokeThickness(1.0f); | 53 context.setStrokeThickness(1.0f); |
| 54 context->setFillColor(Color::transparent); | 54 context.setFillColor(Color::transparent); |
| 55 context->drawRect(largerCorner); | 55 context.drawRect(largerCorner); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 void ScrollableAreaPainter::drawPlatformResizerImage(GraphicsContext* context, I
ntRect resizerCornerRect) | 59 void ScrollableAreaPainter::drawPlatformResizerImage(GraphicsContext& context, I
ntRect resizerCornerRect) |
| 60 { | 60 { |
| 61 float deviceScaleFactor = blink::deviceScaleFactor(scrollableArea().box().fr
ame()); | 61 float deviceScaleFactor = blink::deviceScaleFactor(scrollableArea().box().fr
ame()); |
| 62 | 62 |
| 63 RefPtr<Image> resizeCornerImage; | 63 RefPtr<Image> resizeCornerImage; |
| 64 IntSize cornerResizerSize; | 64 IntSize cornerResizerSize; |
| 65 if (deviceScaleFactor >= 2) { | 65 if (deviceScaleFactor >= 2) { |
| 66 DEFINE_STATIC_REF(Image, resizeCornerImageHiRes, (Image::loadPlatformRes
ource("textAreaResizeCorner@2x"))); | 66 DEFINE_STATIC_REF(Image, resizeCornerImageHiRes, (Image::loadPlatformRes
ource("textAreaResizeCorner@2x"))); |
| 67 resizeCornerImage = resizeCornerImageHiRes; | 67 resizeCornerImage = resizeCornerImageHiRes; |
| 68 cornerResizerSize = resizeCornerImage->size(); | 68 cornerResizerSize = resizeCornerImage->size(); |
| 69 cornerResizerSize.scale(0.5f); | 69 cornerResizerSize.scale(0.5f); |
| 70 } else { | 70 } else { |
| 71 DEFINE_STATIC_REF(Image, resizeCornerImageLoRes, (Image::loadPlatformRes
ource("textAreaResizeCorner"))); | 71 DEFINE_STATIC_REF(Image, resizeCornerImageLoRes, (Image::loadPlatformRes
ource("textAreaResizeCorner"))); |
| 72 resizeCornerImage = resizeCornerImageLoRes; | 72 resizeCornerImage = resizeCornerImageLoRes; |
| 73 cornerResizerSize = resizeCornerImage->size(); | 73 cornerResizerSize = resizeCornerImage->size(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 if (scrollableArea().box().shouldPlaceBlockDirectionScrollbarOnLogicalLeft()
) { | 76 if (scrollableArea().box().shouldPlaceBlockDirectionScrollbarOnLogicalLeft()
) { |
| 77 context->save(); | 77 context.save(); |
| 78 context->translate(resizerCornerRect.x() + cornerResizerSize.width(), re
sizerCornerRect.y() + resizerCornerRect.height() - cornerResizerSize.height()); | 78 context.translate(resizerCornerRect.x() + cornerResizerSize.width(), res
izerCornerRect.y() + resizerCornerRect.height() - cornerResizerSize.height()); |
| 79 context->scale(-1.0, 1.0); | 79 context.scale(-1.0, 1.0); |
| 80 context->drawImage(resizeCornerImage.get(), IntRect(IntPoint(), cornerRe
sizerSize)); | 80 context.drawImage(resizeCornerImage.get(), IntRect(IntPoint(), cornerRes
izerSize)); |
| 81 context->restore(); | 81 context.restore(); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 IntRect imageRect(resizerCornerRect.maxXMaxYCorner() - cornerResizerSize, co
rnerResizerSize); | 84 IntRect imageRect(resizerCornerRect.maxXMaxYCorner() - cornerResizerSize, co
rnerResizerSize); |
| 85 context->drawImage(resizeCornerImage.get(), imageRect); | 85 context.drawImage(resizeCornerImage.get(), imageRect); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void ScrollableAreaPainter::paintOverflowControls(GraphicsContext* context, cons
t IntPoint& paintOffset, const CullRect& cullRect, bool paintingOverlayControls) | 88 void ScrollableAreaPainter::paintOverflowControls(GraphicsContext& context, cons
t IntPoint& paintOffset, const CullRect& cullRect, bool paintingOverlayControls) |
| 89 { | 89 { |
| 90 // Don't do anything if we have no overflow. | 90 // Don't do anything if we have no overflow. |
| 91 if (!scrollableArea().box().hasOverflowClip()) | 91 if (!scrollableArea().box().hasOverflowClip()) |
| 92 return; | 92 return; |
| 93 | 93 |
| 94 IntPoint adjustedPaintOffset = paintOffset; | 94 IntPoint adjustedPaintOffset = paintOffset; |
| 95 if (paintingOverlayControls) | 95 if (paintingOverlayControls) |
| 96 adjustedPaintOffset = scrollableArea().cachedOverlayScrollbarOffset(); | 96 adjustedPaintOffset = scrollableArea().cachedOverlayScrollbarOffset(); |
| 97 | 97 |
| 98 CullRect adjustedCullRect(cullRect, -adjustedPaintOffset); | 98 CullRect adjustedCullRect(cullRect, -adjustedPaintOffset); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 120 paintingRoot->setContainsDirtyOverlayScrollbars(true); | 120 paintingRoot->setContainsDirtyOverlayScrollbars(true); |
| 121 return; | 121 return; |
| 122 } | 122 } |
| 123 | 123 |
| 124 // This check is required to avoid painting custom CSS scrollbars twice. | 124 // This check is required to avoid painting custom CSS scrollbars twice. |
| 125 if (paintingOverlayControls && !scrollableArea().hasOverlayScrollbars()) | 125 if (paintingOverlayControls && !scrollableArea().hasOverlayScrollbars()) |
| 126 return; | 126 return; |
| 127 | 127 |
| 128 { | 128 { |
| 129 if (scrollableArea().horizontalScrollbar() && !scrollableArea().layerFor
HorizontalScrollbar()) { | 129 if (scrollableArea().horizontalScrollbar() && !scrollableArea().layerFor
HorizontalScrollbar()) { |
| 130 TransformRecorder translateRecorder(*context, *scrollableArea().hori
zontalScrollbar(), AffineTransform::translation(adjustedPaintOffset.x(), adjuste
dPaintOffset.y())); | 130 TransformRecorder translateRecorder(context, *scrollableArea().horiz
ontalScrollbar(), AffineTransform::translation(adjustedPaintOffset.x(), adjusted
PaintOffset.y())); |
| 131 scrollableArea().horizontalScrollbar()->paint(context, adjustedCullR
ect); | 131 scrollableArea().horizontalScrollbar()->paint(context, adjustedCullR
ect); |
| 132 } | 132 } |
| 133 if (scrollableArea().verticalScrollbar() && !scrollableArea().layerForVe
rticalScrollbar()) { | 133 if (scrollableArea().verticalScrollbar() && !scrollableArea().layerForVe
rticalScrollbar()) { |
| 134 TransformRecorder translateRecorder(*context, *scrollableArea().vert
icalScrollbar(), AffineTransform::translation(adjustedPaintOffset.x(), adjustedP
aintOffset.y())); | 134 TransformRecorder translateRecorder(context, *scrollableArea().verti
calScrollbar(), AffineTransform::translation(adjustedPaintOffset.x(), adjustedPa
intOffset.y())); |
| 135 scrollableArea().verticalScrollbar()->paint(context, adjustedCullRec
t); | 135 scrollableArea().verticalScrollbar()->paint(context, adjustedCullRec
t); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 if (scrollableArea().layerForScrollCorner()) | 139 if (scrollableArea().layerForScrollCorner()) |
| 140 return; | 140 return; |
| 141 | 141 |
| 142 // We fill our scroll corner with white if we have a scrollbar that doesn't
run all the way up to the | 142 // We fill our scroll corner with white if we have a scrollbar that doesn't
run all the way up to the |
| 143 // edge of the box. | 143 // edge of the box. |
| 144 paintScrollCorner(context, adjustedPaintOffset, cullRect); | 144 paintScrollCorner(context, adjustedPaintOffset, cullRect); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 159 | 159 |
| 160 if (cullRect.intersectsCullRect(scrollableArea().scrollCornerRect())) | 160 if (cullRect.intersectsCullRect(scrollableArea().scrollCornerRect())) |
| 161 return true; | 161 return true; |
| 162 | 162 |
| 163 if (cullRect.intersectsCullRect(scrollableArea().resizerCornerRect(borderBox
, ResizerForPointer))) | 163 if (cullRect.intersectsCullRect(scrollableArea().resizerCornerRect(borderBox
, ResizerForPointer))) |
| 164 return true; | 164 return true; |
| 165 | 165 |
| 166 return false; | 166 return false; |
| 167 } | 167 } |
| 168 | 168 |
| 169 void ScrollableAreaPainter::paintScrollCorner(GraphicsContext* context, const In
tPoint& paintOffset, const CullRect& adjustedCullRect) | 169 void ScrollableAreaPainter::paintScrollCorner(GraphicsContext& context, const In
tPoint& paintOffset, const CullRect& adjustedCullRect) |
| 170 { | 170 { |
| 171 IntRect absRect = scrollableArea().scrollCornerRect(); | 171 IntRect absRect = scrollableArea().scrollCornerRect(); |
| 172 if (absRect.isEmpty()) | 172 if (absRect.isEmpty()) |
| 173 return; | 173 return; |
| 174 absRect.moveBy(paintOffset); | 174 absRect.moveBy(paintOffset); |
| 175 | 175 |
| 176 if (scrollableArea().scrollCorner()) { | 176 if (scrollableArea().scrollCorner()) { |
| 177 if (!adjustedCullRect.intersectsCullRect(absRect)) | 177 if (!adjustedCullRect.intersectsCullRect(absRect)) |
| 178 return; | 178 return; |
| 179 ScrollbarPainter::paintIntoRect(*scrollableArea().scrollCorner(), contex
t, paintOffset, LayoutRect(absRect)); | 179 ScrollbarPainter::paintIntoRect(*scrollableArea().scrollCorner(), contex
t, paintOffset, LayoutRect(absRect)); |
| 180 return; | 180 return; |
| 181 } | 181 } |
| 182 | 182 |
| 183 // We don't want to paint white if we have overlay scrollbars, since we need | 183 // We don't want to paint white if we have overlay scrollbars, since we need |
| 184 // to see what is behind it. | 184 // to see what is behind it. |
| 185 if (scrollableArea().hasOverlayScrollbars()) | 185 if (scrollableArea().hasOverlayScrollbars()) |
| 186 return; | 186 return; |
| 187 | 187 |
| 188 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, scroll
ableArea().box(), DisplayItem::ScrollbarCorner, paintOffset)) | 188 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, scrolla
bleArea().box(), DisplayItem::ScrollbarCorner, paintOffset)) |
| 189 return; | 189 return; |
| 190 | 190 |
| 191 LayoutObjectDrawingRecorder recorder(*context, scrollableArea().box(), Displ
ayItem::ScrollbarCorner, absRect, paintOffset); | 191 LayoutObjectDrawingRecorder recorder(context, scrollableArea().box(), Displa
yItem::ScrollbarCorner, absRect, paintOffset); |
| 192 context->fillRect(absRect, Color::white); | 192 context.fillRect(absRect, Color::white); |
| 193 } | 193 } |
| 194 | 194 |
| 195 PaintLayerScrollableArea& ScrollableAreaPainter::scrollableArea() const | 195 PaintLayerScrollableArea& ScrollableAreaPainter::scrollableArea() const |
| 196 { | 196 { |
| 197 return *m_scrollableArea; | 197 return *m_scrollableArea; |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace blink | 200 } // namespace blink |
| OLD | NEW |