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 | 4 |
5 #ifndef ASH_MUS_SHADOW_H_ | 5 #ifndef ASH_MUS_SHADOW_H_ |
6 #define ASH_MUS_SHADOW_H_ | 6 #define ASH_MUS_SHADOW_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "services/ui/public/cpp/window_observer.h" | 11 #include "ui/aura/window_observer.h" |
12 #include "ui/compositor/layer_animation_observer.h" | 12 #include "ui/compositor/layer_animation_observer.h" |
13 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 class Layer; | 16 class Layer; |
17 } // namespace ui | 17 } // namespace ui |
18 | 18 |
19 namespace ash { | 19 namespace ash { |
20 namespace mus { | 20 namespace mus { |
21 | 21 |
22 // Simple class that draws a drop shadow around content at given bounds. | 22 // Simple class that draws a drop shadow around content at given bounds. |
23 class Shadow : public ui::ImplicitAnimationObserver, public ui::WindowObserver { | 23 // http://crbug.com/670840. |
James Cook
2016/12/05 19:21:45
nit: What is the bug saying to do? Eliminate this
sky
2016/12/05 21:39:20
Yes. This class is mostly a copy of the class in u
| |
24 class Shadow : public ui::ImplicitAnimationObserver, | |
25 public aura::WindowObserver { | |
24 public: | 26 public: |
25 enum Style { | 27 enum Style { |
26 // Active windows have more opaque shadows, shifted down to make the window | 28 // Active windows have more opaque shadows, shifted down to make the window |
27 // appear "higher". | 29 // appear "higher". |
28 STYLE_ACTIVE, | 30 STYLE_ACTIVE, |
29 | 31 |
30 // Inactive windows have less opaque shadows. | 32 // Inactive windows have less opaque shadows. |
31 STYLE_INACTIVE, | 33 STYLE_INACTIVE, |
32 | 34 |
33 // Small windows like tooltips and context menus have lighter, smaller | 35 // Small windows like tooltips and context menus have lighter, smaller |
34 // shadows. | 36 // shadows. |
35 STYLE_SMALL, | 37 STYLE_SMALL, |
36 }; | 38 }; |
37 | 39 |
38 Shadow(); | 40 Shadow(); |
39 ~Shadow() override; | 41 ~Shadow() override; |
40 | 42 |
41 void Init(Style style); | 43 void Init(Style style); |
42 | 44 |
45 static Shadow* Get(aura::Window* window); | |
46 | |
43 // Returns the interio inset for the specified style. The interior inset | 47 // Returns the interio inset for the specified style. The interior inset |
44 // is the amount of padding added to each side of the content bounds that the | 48 // is the amount of padding added to each side of the content bounds that the |
45 // shadow renders into. In other words the shadow extends from all sides of | 49 // shadow renders into. In other words the shadow extends from all sides of |
46 // the layer by this value. | 50 // the layer by this value. |
47 static int GetInteriorInsetForStyle(Style style); | 51 static int GetInteriorInsetForStyle(Style style); |
48 | 52 |
49 // Returns |layer_.get()|. This is exposed so it can be added to the same | 53 // Returns |layer_.get()|. This is exposed so it can be added to the same |
50 // layer as the content and stacked below it. SetContentBounds() should be | 54 // layer as the content and stacked below it. SetContentBounds() should be |
51 // used to adjust the shadow's size and position (rather than applying | 55 // used to adjust the shadow's size and position (rather than applying |
52 // transformations to this layer). | 56 // transformations to this layer). |
53 ui::Layer* layer() const { return layer_.get(); } | 57 ui::Layer* layer() const { return layer_.get(); } |
54 | 58 |
55 const gfx::Rect& content_bounds() const { return content_bounds_; } | 59 const gfx::Rect& content_bounds() const { return content_bounds_; } |
56 Style style() const { return style_; } | 60 Style style() const { return style_; } |
57 | 61 |
58 // Moves and resizes the shadow layer to frame |content_bounds|. | 62 // Moves and resizes the shadow layer to frame |content_bounds|. |
59 void SetContentBounds(const gfx::Rect& content_bounds); | 63 void SetContentBounds(const gfx::Rect& content_bounds); |
60 | 64 |
61 // Sets the shadow's style, animating opacity as necessary. | 65 // Sets the shadow's style, animating opacity as necessary. |
62 void SetStyle(Style style); | 66 void SetStyle(Style style); |
63 | 67 |
64 // Installs this shadow for |window|. | 68 // Installs this shadow for |window|. |
65 void Install(ui::Window* window); | 69 void Install(aura::Window* window); |
66 | 70 |
67 // ui::ImplicitAnimationObserver overrides: | 71 // ui::ImplicitAnimationObserver overrides: |
68 void OnImplicitAnimationsCompleted() override; | 72 void OnImplicitAnimationsCompleted() override; |
69 | 73 |
70 private: | 74 private: |
71 // Updates the shadow images to the current |style_|. | 75 // Updates the shadow images to the current |style_|. |
72 void UpdateImagesForStyle(); | 76 void UpdateImagesForStyle(); |
73 | 77 |
74 // Updates the shadow layer bounds based on the inteior inset and the current | 78 // Updates the shadow layer bounds based on the inteior inset and the current |
75 // |content_bounds_|. | 79 // |content_bounds_|. |
76 void UpdateLayerBounds(); | 80 void UpdateLayerBounds(); |
77 | 81 |
78 // WindowObserver: | 82 // WindowObserver: |
79 void OnWindowDestroyed(ui::Window* window) override; | 83 void OnWindowDestroyed(aura::Window* window) override; |
80 | 84 |
81 // The current style, set when the transition animation starts. | 85 // The current style, set when the transition animation starts. |
82 Style style_; | 86 Style style_; |
83 | 87 |
84 // The parent layer of the shadow layer. It serves as a container accessible | 88 // The parent layer of the shadow layer. It serves as a container accessible |
85 // from the outside to control the visibility of the shadow. | 89 // from the outside to control the visibility of the shadow. |
86 std::unique_ptr<ui::Layer> layer_; | 90 std::unique_ptr<ui::Layer> layer_; |
87 | 91 |
88 // The actual shadow layer corresponding to a cc::NinePatchLayer. | 92 // The actual shadow layer corresponding to a cc::NinePatchLayer. |
89 std::unique_ptr<ui::Layer> shadow_layer_; | 93 std::unique_ptr<ui::Layer> shadow_layer_; |
90 | 94 |
91 // Size of the current shadow image. | 95 // Size of the current shadow image. |
92 gfx::Size image_size_; | 96 gfx::Size image_size_; |
93 | 97 |
94 // Bounds of the content that the shadow encloses. | 98 // Bounds of the content that the shadow encloses. |
95 gfx::Rect content_bounds_; | 99 gfx::Rect content_bounds_; |
96 | 100 |
97 // The interior inset of the shadow images. The content bounds of the image | 101 // The interior inset of the shadow images. The content bounds of the image |
98 // grid should be set to |content_bounds_| inset by this amount. | 102 // grid should be set to |content_bounds_| inset by this amount. |
99 int interior_inset_; | 103 int interior_inset_; |
100 | 104 |
101 ui::Window* window_; | 105 aura::Window* window_; |
102 | 106 |
103 DISALLOW_COPY_AND_ASSIGN(Shadow); | 107 DISALLOW_COPY_AND_ASSIGN(Shadow); |
104 }; | 108 }; |
105 | 109 |
106 } // namespace mus | 110 } // namespace mus |
107 } // namespace ash | 111 } // namespace ash |
108 | 112 |
109 #endif // ASH_MUS_SHADOW_H_ | 113 #endif // ASH_MUS_SHADOW_H_ |
OLD | NEW |