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