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 #ifndef BoxReflection_h | 5 #ifndef BoxReflection_h |
6 #define BoxReflection_h | 6 #define BoxReflection_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "platform/geometry/FloatRect.h" | |
10 #include "platform/graphics/paint/PaintRecord.h" | 9 #include "platform/graphics/paint/PaintRecord.h" |
11 #include "third_party/skia/include/core/SkRefCnt.h" | 10 #include "third_party/skia/include/core/SkRefCnt.h" |
12 | 11 |
13 class SkMatrix; | 12 class SkMatrix; |
14 | 13 |
15 namespace blink { | 14 namespace blink { |
16 | 15 |
| 16 class FloatRect; |
| 17 |
17 // A reflection, as created by -webkit-box-reflect. Consists of: | 18 // A reflection, as created by -webkit-box-reflect. Consists of: |
18 // * a direction (either vertical or horizontal) | 19 // * a direction (either vertical or horizontal) |
19 // * an offset to be applied to the reflection after flipping about the | 20 // * an offset to be applied to the reflection after flipping about the |
20 // x- or y-axis, according to the direction | 21 // x- or y-axis, according to the direction |
21 // * a mask image, which will be applied to the reflection before the | 22 // * a mask image, which will be applied to the reflection before the |
22 // reflection matrix is applied | 23 // reflection matrix is applied |
23 class PLATFORM_EXPORT BoxReflection { | 24 class PLATFORM_EXPORT BoxReflection { |
24 public: | 25 public: |
25 enum ReflectionDirection { | 26 enum ReflectionDirection { |
26 // Vertically flipped (to appear above or below). | 27 // Vertically flipped (to appear above or below). |
27 kVerticalReflection, | 28 kVerticalReflection, |
28 // Horizontally flipped (to appear to the left or right). | 29 // Horizontally flipped (to appear to the left or right). |
29 kHorizontalReflection, | 30 kHorizontalReflection, |
30 }; | 31 }; |
31 | 32 |
32 BoxReflection(ReflectionDirection direction, float offset) | |
33 : BoxReflection(direction, offset, nullptr, FloatRect()) {} | |
34 | |
35 BoxReflection(ReflectionDirection direction, | 33 BoxReflection(ReflectionDirection direction, |
36 float offset, | 34 float offset, |
37 sk_sp<PaintRecord> mask, | 35 sk_sp<PaintRecord> mask = nullptr) |
38 const FloatRect& mask_bounds) | 36 : direction_(direction), offset_(offset), mask_(std::move(mask)) {} |
39 : direction_(direction), | |
40 offset_(offset), | |
41 mask_(std::move(mask)), | |
42 mask_bounds_(mask_bounds) {} | |
43 | 37 |
44 ReflectionDirection Direction() const { return direction_; } | 38 ReflectionDirection Direction() const { return direction_; } |
45 float Offset() const { return offset_; } | 39 float Offset() const { return offset_; } |
46 const sk_sp<PaintRecord>& Mask() const { return mask_; } | 40 const sk_sp<PaintRecord>& Mask() const { return mask_; } |
47 const FloatRect& MaskBounds() const { return mask_bounds_; } | |
48 | 41 |
49 // Returns a matrix which maps points between the original content and its | 42 // Returns a matrix which maps points between the original content and its |
50 // reflection. Reflections are self-inverse, so this matrix can be used to | 43 // reflection. Reflections are self-inverse, so this matrix can be used to |
51 // map in either direction. | 44 // map in either direction. |
52 SkMatrix ReflectionMatrix() const; | 45 SkMatrix ReflectionMatrix() const; |
53 | 46 |
54 // Maps a source rectangle to the destination rectangle it can affect, | 47 // Maps a source rectangle to the destination rectangle it can affect, |
55 // including this reflection. Due to the symmetry of reflections, this can | 48 // including this reflection. Due to the symmetry of reflections, this can |
56 // also be used to map from a destination rectangle to the source rectangle | 49 // also be used to map from a destination rectangle to the source rectangle |
57 // which contributes to it. | 50 // which contributes to it. |
58 FloatRect MapRect(const FloatRect&) const; | 51 FloatRect MapRect(const FloatRect&) const; |
59 | 52 |
60 private: | 53 private: |
61 ReflectionDirection direction_; | 54 ReflectionDirection direction_; |
62 float offset_; | 55 float offset_; |
63 sk_sp<PaintRecord> mask_; | 56 sk_sp<PaintRecord> mask_; |
64 FloatRect mask_bounds_; | |
65 }; | 57 }; |
66 | 58 |
67 inline bool operator==(const BoxReflection& a, const BoxReflection& b) { | 59 inline bool operator==(const BoxReflection& a, const BoxReflection& b) { |
68 return a.Direction() == b.Direction() && a.Offset() == b.Offset() && | 60 return a.Direction() == b.Direction() && a.Offset() == b.Offset() && |
69 a.Mask() == b.Mask() && a.MaskBounds() == b.MaskBounds(); | 61 a.Mask() == b.Mask(); |
70 } | 62 } |
71 | 63 |
72 inline bool operator!=(const BoxReflection& a, const BoxReflection& b) { | 64 inline bool operator!=(const BoxReflection& a, const BoxReflection& b) { |
73 return !(a == b); | 65 return !(a == b); |
74 } | 66 } |
75 | 67 |
76 } // namespace blink | 68 } // namespace blink |
77 | 69 |
78 #endif // BoxReflection_h | 70 #endif // BoxReflection_h |
OLD | NEW |