OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/BoxReflectionUtils.h" | 5 #include "core/paint/BoxReflectionUtils.h" |
6 | 6 |
7 #include "core/layout/LayoutBox.h" | 7 #include "core/layout/LayoutBox.h" |
8 #include "core/paint/NinePieceImagePainter.h" | 8 #include "core/paint/NinePieceImagePainter.h" |
9 #include "core/paint/PaintLayer.h" | 9 #include "core/paint/PaintLayer.h" |
10 #include "platform/LengthFunctions.h" | 10 #include "platform/LengthFunctions.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 case ReflectionLeft: | 37 case ReflectionLeft: |
38 direction = BoxReflection::HorizontalReflection; | 38 direction = BoxReflection::HorizontalReflection; |
39 offset = -floatValueForLength(reflectStyle->offset(), frameRect.width())
; | 39 offset = -floatValueForLength(reflectStyle->offset(), frameRect.width())
; |
40 break; | 40 break; |
41 case ReflectionRight: | 41 case ReflectionRight: |
42 direction = BoxReflection::HorizontalReflection; | 42 direction = BoxReflection::HorizontalReflection; |
43 offset = 2 * frameRect.width() + floatValueForLength(reflectStyle->offse
t(), frameRect.width()); | 43 offset = 2 * frameRect.width() + floatValueForLength(reflectStyle->offse
t(), frameRect.width()); |
44 break; | 44 break; |
45 } | 45 } |
46 | 46 |
47 // Since the filter origin is the corner of the input bounds, which may | |
48 // include visual overflow (e.g. due to box-shadow), we must adjust the | |
49 // offset to also account for this offset (this is equivalent to using | |
50 // SkLocalMatrixImageFilter, but simpler). | |
51 // The rect used here should match the one used in FilterPainter. | |
52 LayoutRect filterInputBounds = layer.physicalBoundingBoxIncludingReflectionA
ndStackingChildren(LayoutPoint()); | |
53 offset -= 2 * (direction == BoxReflection::VerticalReflection ? filterInputB
ounds.y() : filterInputBounds.x()).toFloat(); | |
54 | |
55 RefPtr<SkPicture> mask; | 47 RefPtr<SkPicture> mask; |
56 const NinePieceImage& maskNinePiece = reflectStyle->mask(); | 48 const NinePieceImage& maskNinePiece = reflectStyle->mask(); |
57 if (maskNinePiece.hasImage()) { | 49 if (maskNinePiece.hasImage()) { |
58 LayoutRect maskRect(LayoutPoint(), frameLayoutRect.size()); | 50 LayoutRect maskRect(LayoutPoint(), frameLayoutRect.size()); |
59 maskRect.moveBy(-filterInputBounds.location()); | |
60 | |
61 LayoutRect maskBoundingRect(maskRect); | 51 LayoutRect maskBoundingRect(maskRect); |
62 maskBoundingRect.expand(style.imageOutsets(maskNinePiece)); | 52 maskBoundingRect.expand(style.imageOutsets(maskNinePiece)); |
63 FloatRect maskBoundingFloatRect(maskBoundingRect); | 53 FloatRect maskBoundingFloatRect(maskBoundingRect); |
64 | 54 |
65 // TODO(jbroman): SkPictureBuilder + DrawingRecorder seems excessive. | 55 // TODO(jbroman): SkPictureBuilder + DrawingRecorder seems excessive. |
66 // If NinePieceImagePainter operated on SkCanvas, we'd only need an | 56 // If NinePieceImagePainter operated on SkCanvas, we'd only need an |
67 // SkPictureRecorder here. | 57 // SkPictureRecorder here. |
68 SkPictureBuilder recorder(maskBoundingFloatRect); | 58 SkPictureBuilder recorder(maskBoundingFloatRect); |
69 { | 59 { |
70 GraphicsContext& context = recorder.context(); | 60 GraphicsContext& context = recorder.context(); |
71 DrawingRecorder drawingRecorder(context, *layer.layoutObject(), Disp
layItem::ReflectionMask, maskBoundingFloatRect); | 61 DrawingRecorder drawingRecorder(context, *layer.layoutObject(), Disp
layItem::ReflectionMask, maskBoundingFloatRect); |
72 NinePieceImagePainter(*layer.layoutObject()).paint( | 62 NinePieceImagePainter(*layer.layoutObject()).paint( |
73 recorder.context(), maskRect, style, maskNinePiece, SkXfermode::
kSrcOver_Mode); | 63 recorder.context(), maskRect, style, maskNinePiece, SkXfermode::
kSrcOver_Mode); |
74 } | 64 } |
75 mask = recorder.endRecording(); | 65 mask = recorder.endRecording(); |
76 } | 66 } |
77 | 67 |
78 return BoxReflection(direction, offset, mask); | 68 return BoxReflection(direction, offset, mask); |
79 } | 69 } |
80 | 70 |
81 } // namespace blink | 71 } // namespace blink |
OLD | NEW |