OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef UI_VIEWS_ANIMATION_INK_DROP_PAINTED_LAYER_DELEGATES_H_ | 4 #ifndef UI_VIEWS_ANIMATION_INK_DROP_PAINTED_LAYER_DELEGATES_H_ |
5 #define UI_VIEWS_ANIMATION_INK_DROP_PAINTED_LAYER_DELEGATES_H_ | 5 #define UI_VIEWS_ANIMATION_INK_DROP_PAINTED_LAYER_DELEGATES_H_ |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
10 #include "ui/compositor/layer_delegate.h" | 10 #include "ui/compositor/layer_delegate.h" |
| 11 #include "ui/gfx/geometry/point_f.h" |
11 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
12 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
13 | 14 |
14 namespace views { | 15 namespace views { |
15 | 16 |
16 // Base ui::LayerDelegate stub that can be extended to paint shapes of a | 17 // Base ui::LayerDelegate stub that can be extended to paint shapes of a |
17 // specific color. | 18 // specific color. |
18 class BasePaintedLayerDelegate : public ui::LayerDelegate { | 19 class BasePaintedLayerDelegate : public ui::LayerDelegate { |
19 public: | 20 public: |
20 ~BasePaintedLayerDelegate() override; | 21 ~BasePaintedLayerDelegate() override; |
21 | 22 |
22 SkColor color() const { return color_; } | 23 SkColor color() const { return color_; } |
23 | 24 |
| 25 // Returns the center point of the painted shape. |
| 26 virtual gfx::PointF GetCenterPoint() const = 0; |
| 27 |
24 // ui::LayerDelegate: | 28 // ui::LayerDelegate: |
25 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override; | 29 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override; |
26 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 30 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
27 base::Closure PrepareForLayerBoundsChange() override; | 31 base::Closure PrepareForLayerBoundsChange() override; |
28 | 32 |
29 protected: | 33 protected: |
30 explicit BasePaintedLayerDelegate(SkColor color); | 34 explicit BasePaintedLayerDelegate(SkColor color); |
31 | 35 |
32 private: | 36 private: |
33 // The color to paint. | 37 // The color to paint. |
34 SkColor color_; | 38 SkColor color_; |
35 | 39 |
36 DISALLOW_COPY_AND_ASSIGN(BasePaintedLayerDelegate); | 40 DISALLOW_COPY_AND_ASSIGN(BasePaintedLayerDelegate); |
37 }; | 41 }; |
38 | 42 |
39 // A BasePaintedLayerDelegate that paints a circle of a specified color and | 43 // A BasePaintedLayerDelegate that paints a circle of a specified color and |
40 // radius. | 44 // radius. |
41 class CircleLayerDelegate : public BasePaintedLayerDelegate { | 45 class CircleLayerDelegate : public BasePaintedLayerDelegate { |
42 public: | 46 public: |
43 CircleLayerDelegate(SkColor color, int radius); | 47 CircleLayerDelegate(SkColor color, int radius); |
44 ~CircleLayerDelegate() override; | 48 ~CircleLayerDelegate() override; |
45 | 49 |
46 int radius() const { return radius_; } | 50 int radius() const { return radius_; } |
47 | 51 |
48 // ui::LayerDelegate: | 52 // BasePaintedLayerDelegate: |
| 53 gfx::PointF GetCenterPoint() const override; |
49 void OnPaintLayer(const ui::PaintContext& context) override; | 54 void OnPaintLayer(const ui::PaintContext& context) override; |
50 | 55 |
51 private: | 56 private: |
52 // The radius of the circle. | 57 // The radius of the circle. |
53 int radius_; | 58 int radius_; |
54 | 59 |
55 DISALLOW_COPY_AND_ASSIGN(CircleLayerDelegate); | 60 DISALLOW_COPY_AND_ASSIGN(CircleLayerDelegate); |
56 }; | 61 }; |
57 | 62 |
58 // A BasePaintedLayerDelegate that paints a rectangle of a specified color and | 63 // A BasePaintedLayerDelegate that paints a rectangle of a specified color and |
59 // size. | 64 // size. |
60 class RectangleLayerDelegate : public BasePaintedLayerDelegate { | 65 class RectangleLayerDelegate : public BasePaintedLayerDelegate { |
61 public: | 66 public: |
62 RectangleLayerDelegate(SkColor color, gfx::Size size); | 67 RectangleLayerDelegate(SkColor color, gfx::Size size); |
63 ~RectangleLayerDelegate() override; | 68 ~RectangleLayerDelegate() override; |
64 | 69 |
65 const gfx::Size& size() const { return size_; } | 70 const gfx::Size& size() const { return size_; } |
66 | 71 |
67 // ui::LayerDelegate: | 72 // BasePaintedLayerDelegate: |
| 73 gfx::PointF GetCenterPoint() const override; |
68 void OnPaintLayer(const ui::PaintContext& context) override; | 74 void OnPaintLayer(const ui::PaintContext& context) override; |
69 | 75 |
70 private: | 76 private: |
71 // The size of the rectangle. | 77 // The size of the rectangle. |
72 gfx::Size size_; | 78 gfx::Size size_; |
73 | 79 |
74 DISALLOW_COPY_AND_ASSIGN(RectangleLayerDelegate); | 80 DISALLOW_COPY_AND_ASSIGN(RectangleLayerDelegate); |
75 }; | 81 }; |
76 | 82 |
77 // A BasePaintedLayerDelegate that paints a rounded rectangle of a specified | 83 // A BasePaintedLayerDelegate that paints a rounded rectangle of a specified |
78 // color, size and corner radius. | 84 // color, size and corner radius. |
79 class RoundedRectangleLayerDelegate : public BasePaintedLayerDelegate { | 85 class RoundedRectangleLayerDelegate : public BasePaintedLayerDelegate { |
80 public: | 86 public: |
81 RoundedRectangleLayerDelegate(SkColor color, | 87 RoundedRectangleLayerDelegate(SkColor color, |
82 gfx::Size size, | 88 gfx::Size size, |
83 int corner_radius); | 89 int corner_radius); |
84 ~RoundedRectangleLayerDelegate() override; | 90 ~RoundedRectangleLayerDelegate() override; |
85 | 91 |
86 const gfx::Size& size() const { return size_; } | 92 const gfx::Size& size() const { return size_; } |
87 | 93 |
88 // ui::LayerDelegate: | 94 // BasePaintedLayerDelegate: |
| 95 gfx::PointF GetCenterPoint() const override; |
89 void OnPaintLayer(const ui::PaintContext& context) override; | 96 void OnPaintLayer(const ui::PaintContext& context) override; |
90 | 97 |
91 private: | 98 private: |
92 // The size of the rectangle. | 99 // The size of the rectangle. |
93 gfx::Size size_; | 100 gfx::Size size_; |
94 | 101 |
95 // The radius of the corners. | 102 // The radius of the corners. |
96 int corner_radius_; | 103 int corner_radius_; |
97 | 104 |
98 DISALLOW_COPY_AND_ASSIGN(RoundedRectangleLayerDelegate); | 105 DISALLOW_COPY_AND_ASSIGN(RoundedRectangleLayerDelegate); |
99 }; | 106 }; |
100 | 107 |
101 } // namespace views | 108 } // namespace views |
102 | 109 |
103 #endif // UI_VIEWS_ANIMATION_INK_DROP_PAINTED_LAYER_DELEGATES_H_ | 110 #endif // UI_VIEWS_ANIMATION_INK_DROP_PAINTED_LAYER_DELEGATES_H_ |
OLD | NEW |