Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/paint/BoxReflectionUtils.h" | |
| 6 | |
| 7 #include "core/layout/LayoutBox.h" | |
| 8 #include "core/paint/NinePieceImagePainter.h" | |
| 9 #include "core/paint/PaintLayer.h" | |
| 10 #include "platform/LengthFunctions.h" | |
| 11 #include "platform/geometry/FloatRect.h" | |
| 12 #include "platform/geometry/LayoutPoint.h" | |
| 13 #include "platform/geometry/LayoutRect.h" | |
| 14 #include "platform/graphics/BoxReflection.h" | |
| 15 #include "platform/graphics/paint/DrawingRecorder.h" | |
| 16 #include "platform/graphics/paint/SkPictureBuilder.h" | |
| 17 | |
| 18 namespace blink { | |
| 19 | |
| 20 BoxReflection boxReflectionForPaintLayer(const PaintLayer& layer, const Computed Style& style) | |
| 21 { | |
| 22 const auto* reflectStyle = style.boxReflect(); | |
|
Stephen White
2016/04/20 21:33:56
This might be personal style, but I find "auto" he
jbroman
2016/04/21 16:52:05
Alright. The type is "StyleReflection", so the lin
| |
| 23 | |
| 24 LayoutRect frameLayoutRect = toLayoutBox(layer.layoutObject())->frameRect(); | |
| 25 FloatRect frameRect(frameLayoutRect); | |
| 26 BoxReflection::ReflectionDirection direction = BoxReflection::VerticalReflec tion; | |
| 27 float offset = 0; | |
| 28 switch (reflectStyle->direction()) { | |
| 29 case ReflectionAbove: | |
| 30 direction = BoxReflection::VerticalReflection; | |
| 31 offset = -floatValueForLength(reflectStyle->offset(), frameRect.height() ); | |
| 32 break; | |
| 33 case ReflectionBelow: | |
| 34 direction = BoxReflection::VerticalReflection; | |
| 35 offset = 2 * frameRect.height() + floatValueForLength(reflectStyle->offs et(), frameRect.height()); | |
| 36 break; | |
| 37 case ReflectionLeft: | |
| 38 direction = BoxReflection::HorizontalReflection; | |
| 39 offset = -floatValueForLength(reflectStyle->offset(), frameRect.width()) ; | |
| 40 break; | |
| 41 case ReflectionRight: | |
| 42 direction = BoxReflection::HorizontalReflection; | |
| 43 offset = 2 * frameRect.width() + floatValueForLength(reflectStyle->offse t(), frameRect.width()); | |
| 44 break; | |
| 45 } | |
| 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; | |
| 56 const auto& maskNinePiece = reflectStyle->mask(); | |
|
Stephen White
2016/04/20 21:33:56
Same here.
jbroman
2016/04/21 16:52:05
Done.
| |
| 57 if (maskNinePiece.hasImage()) { | |
| 58 LayoutRect maskRect(LayoutPoint(), frameLayoutRect.size()); | |
| 59 maskRect.moveBy(-filterInputBounds.location()); | |
| 60 | |
| 61 LayoutRect maskBoundingRect(maskRect); | |
| 62 maskBoundingRect.expand(style.imageOutsets(maskNinePiece)); | |
| 63 FloatRect maskBoundingFloatRect(maskBoundingRect); | |
| 64 | |
| 65 // TODO(jbroman): SkPictureBuilder + DrawingRecorder seems excessive. | |
| 66 // If NinePieceImagePainter operated on SkCanvas, we'd only need an | |
| 67 // SkPictureRecorder here. | |
| 68 SkPictureBuilder recorder(maskBoundingFloatRect); | |
| 69 { | |
| 70 GraphicsContext& context = recorder.context(); | |
| 71 DrawingRecorder drawingRecorder(context, *layer.layoutObject(), Disp layItem::ReflectionMask, maskBoundingFloatRect); | |
| 72 NinePieceImagePainter(*layer.layoutObject()).paint( | |
| 73 recorder.context(), maskRect, style, maskNinePiece, SkXfermode:: kSrcOver_Mode); | |
| 74 } | |
| 75 mask = recorder.endRecording(); | |
| 76 } | |
| 77 | |
| 78 return BoxReflection(direction, offset, mask); | |
| 79 } | |
| 80 | |
| 81 } // namespace blink | |
| OLD | NEW |