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 "third_party/skia/include/core/SkPicture.h" | 9 #include "platform/graphics/paint/PaintRecord.h" |
10 #include "third_party/skia/include/core/SkRefCnt.h" | 10 #include "third_party/skia/include/core/SkRefCnt.h" |
11 | 11 |
12 class SkMatrix; | 12 class SkMatrix; |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class FloatRect; | 16 class FloatRect; |
17 | 17 |
18 // A reflection, as created by -webkit-box-reflect. Consists of: | 18 // A reflection, as created by -webkit-box-reflect. Consists of: |
19 // * a direction (either vertical or horizontal) | 19 // * a direction (either vertical or horizontal) |
20 // * 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 |
21 // x- or y-axis, according to the direction | 21 // x- or y-axis, according to the direction |
22 // * 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 |
23 // reflection matrix is applied | 23 // reflection matrix is applied |
24 class PLATFORM_EXPORT BoxReflection { | 24 class PLATFORM_EXPORT BoxReflection { |
25 public: | 25 public: |
26 enum ReflectionDirection { | 26 enum ReflectionDirection { |
27 // Vertically flipped (to appear above or below). | 27 // Vertically flipped (to appear above or below). |
28 VerticalReflection, | 28 VerticalReflection, |
29 // Horizontally flipped (to appear to the left or right). | 29 // Horizontally flipped (to appear to the left or right). |
30 HorizontalReflection, | 30 HorizontalReflection, |
31 }; | 31 }; |
32 | 32 |
33 BoxReflection(ReflectionDirection direction, | 33 BoxReflection(ReflectionDirection direction, |
34 float offset, | 34 float offset, |
35 sk_sp<SkPicture> mask = nullptr) | 35 sk_sp<PaintRecord> mask = nullptr) |
36 : m_direction(direction), m_offset(offset), m_mask(std::move(mask)) {} | 36 : m_direction(direction), m_offset(offset), m_mask(std::move(mask)) {} |
37 | 37 |
38 ReflectionDirection direction() const { return m_direction; } | 38 ReflectionDirection direction() const { return m_direction; } |
39 float offset() const { return m_offset; } | 39 float offset() const { return m_offset; } |
40 SkPicture* mask() const { return m_mask.get(); } | 40 PaintRecord* mask() const { return m_mask.get(); } |
41 | 41 |
42 // 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 |
43 // 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 |
44 // map in either direction. | 44 // map in either direction. |
45 SkMatrix reflectionMatrix() const; | 45 SkMatrix reflectionMatrix() const; |
46 | 46 |
47 // Maps a source rectangle to the destination rectangle it can affect, | 47 // Maps a source rectangle to the destination rectangle it can affect, |
48 // including this reflection. Due to the symmetry of reflections, this can | 48 // including this reflection. Due to the symmetry of reflections, this can |
49 // 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 |
50 // which contributes to it. | 50 // which contributes to it. |
51 FloatRect mapRect(const FloatRect&) const; | 51 FloatRect mapRect(const FloatRect&) const; |
52 | 52 |
53 private: | 53 private: |
54 ReflectionDirection m_direction; | 54 ReflectionDirection m_direction; |
55 float m_offset; | 55 float m_offset; |
56 sk_sp<SkPicture> m_mask; | 56 sk_sp<PaintRecord> m_mask; |
57 }; | 57 }; |
58 | 58 |
59 inline bool operator==(const BoxReflection& a, const BoxReflection& b) { | 59 inline bool operator==(const BoxReflection& a, const BoxReflection& b) { |
60 return a.direction() == b.direction() && a.offset() == b.offset() && | 60 return a.direction() == b.direction() && a.offset() == b.offset() && |
61 a.mask() == b.mask(); | 61 a.mask() == b.mask(); |
62 } | 62 } |
63 | 63 |
64 inline bool operator!=(const BoxReflection& a, const BoxReflection& b) { | 64 inline bool operator!=(const BoxReflection& a, const BoxReflection& b) { |
65 return !(a == b); | 65 return !(a == b); |
66 } | 66 } |
67 | 67 |
68 } // namespace blink | 68 } // namespace blink |
69 | 69 |
70 #endif // BoxReflection_h | 70 #endif // BoxReflection_h |
OLD | NEW |