| 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 "services/ui/public/cpp/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, | 23 class Shadow : public ui::ImplicitAnimationObserver, public ui::WindowObserver { |
| 24 public ::ui::WindowObserver { | |
| 25 public: | 24 public: |
| 26 enum Style { | 25 enum Style { |
| 27 // Active windows have more opaque shadows, shifted down to make the window | 26 // Active windows have more opaque shadows, shifted down to make the window |
| 28 // appear "higher". | 27 // appear "higher". |
| 29 STYLE_ACTIVE, | 28 STYLE_ACTIVE, |
| 30 | 29 |
| 31 // Inactive windows have less opaque shadows. | 30 // Inactive windows have less opaque shadows. |
| 32 STYLE_INACTIVE, | 31 STYLE_INACTIVE, |
| 33 | 32 |
| 34 // Small windows like tooltips and context menus have lighter, smaller | 33 // Small windows like tooltips and context menus have lighter, smaller |
| (...skipping 21 matching lines...) Expand all Loading... |
| 56 const gfx::Rect& content_bounds() const { return content_bounds_; } | 55 const gfx::Rect& content_bounds() const { return content_bounds_; } |
| 57 Style style() const { return style_; } | 56 Style style() const { return style_; } |
| 58 | 57 |
| 59 // Moves and resizes the shadow layer to frame |content_bounds|. | 58 // Moves and resizes the shadow layer to frame |content_bounds|. |
| 60 void SetContentBounds(const gfx::Rect& content_bounds); | 59 void SetContentBounds(const gfx::Rect& content_bounds); |
| 61 | 60 |
| 62 // Sets the shadow's style, animating opacity as necessary. | 61 // Sets the shadow's style, animating opacity as necessary. |
| 63 void SetStyle(Style style); | 62 void SetStyle(Style style); |
| 64 | 63 |
| 65 // Installs this shadow for |window|. | 64 // Installs this shadow for |window|. |
| 66 void Install(::ui::Window* window); | 65 void Install(ui::Window* window); |
| 67 | 66 |
| 68 // ui::ImplicitAnimationObserver overrides: | 67 // ui::ImplicitAnimationObserver overrides: |
| 69 void OnImplicitAnimationsCompleted() override; | 68 void OnImplicitAnimationsCompleted() override; |
| 70 | 69 |
| 71 private: | 70 private: |
| 72 // Updates the shadow images to the current |style_|. | 71 // Updates the shadow images to the current |style_|. |
| 73 void UpdateImagesForStyle(); | 72 void UpdateImagesForStyle(); |
| 74 | 73 |
| 75 // Updates the shadow layer bounds based on the inteior inset and the current | 74 // Updates the shadow layer bounds based on the inteior inset and the current |
| 76 // |content_bounds_|. | 75 // |content_bounds_|. |
| 77 void UpdateLayerBounds(); | 76 void UpdateLayerBounds(); |
| 78 | 77 |
| 79 // WindowObserver: | 78 // WindowObserver: |
| 80 void OnWindowDestroyed(::ui::Window* window) override; | 79 void OnWindowDestroyed(ui::Window* window) override; |
| 81 | 80 |
| 82 // The current style, set when the transition animation starts. | 81 // The current style, set when the transition animation starts. |
| 83 Style style_; | 82 Style style_; |
| 84 | 83 |
| 85 // The parent layer of the shadow layer. It serves as a container accessible | 84 // The parent layer of the shadow layer. It serves as a container accessible |
| 86 // from the outside to control the visibility of the shadow. | 85 // from the outside to control the visibility of the shadow. |
| 87 std::unique_ptr<ui::Layer> layer_; | 86 std::unique_ptr<ui::Layer> layer_; |
| 88 | 87 |
| 89 // The actual shadow layer corresponding to a cc::NinePatchLayer. | 88 // The actual shadow layer corresponding to a cc::NinePatchLayer. |
| 90 std::unique_ptr<ui::Layer> shadow_layer_; | 89 std::unique_ptr<ui::Layer> shadow_layer_; |
| 91 | 90 |
| 92 // Size of the current shadow image. | 91 // Size of the current shadow image. |
| 93 gfx::Size image_size_; | 92 gfx::Size image_size_; |
| 94 | 93 |
| 95 // Bounds of the content that the shadow encloses. | 94 // Bounds of the content that the shadow encloses. |
| 96 gfx::Rect content_bounds_; | 95 gfx::Rect content_bounds_; |
| 97 | 96 |
| 98 // The interior inset of the shadow images. The content bounds of the image | 97 // The interior inset of the shadow images. The content bounds of the image |
| 99 // grid should be set to |content_bounds_| inset by this amount. | 98 // grid should be set to |content_bounds_| inset by this amount. |
| 100 int interior_inset_; | 99 int interior_inset_; |
| 101 | 100 |
| 102 ::ui::Window* window_; | 101 ui::Window* window_; |
| 103 | 102 |
| 104 DISALLOW_COPY_AND_ASSIGN(Shadow); | 103 DISALLOW_COPY_AND_ASSIGN(Shadow); |
| 105 }; | 104 }; |
| 106 | 105 |
| 107 } // namespace mus | 106 } // namespace mus |
| 108 } // namespace ash | 107 } // namespace ash |
| 109 | 108 |
| 110 #endif // ASH_MUS_SHADOW_H_ | 109 #endif // ASH_MUS_SHADOW_H_ |
| OLD | NEW |