Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: ui/wm/core/shadow.h

Issue 2596743002: Replace WM shadow types (on/off) and styles (small/inactive/active) (Closed)
Patch Set: one more mechanical change Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/widget/widget.h ('k') | ui/wm/core/shadow.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 UI_WM_CORE_SHADOW_H_ 5 #ifndef UI_WM_CORE_SHADOW_H_
6 #define UI_WM_CORE_SHADOW_H_ 6 #define UI_WM_CORE_SHADOW_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "ui/compositor/layer_animation_observer.h" 11 #include "ui/compositor/layer_animation_observer.h"
12 #include "ui/gfx/geometry/rect.h" 12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/wm/wm_export.h" 13 #include "ui/wm/wm_export.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 wm { 19 namespace wm {
20 enum class ShadowElevation;
20 21
21 // 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.
22 class WM_EXPORT Shadow : public ui::ImplicitAnimationObserver { 23 class WM_EXPORT Shadow : public ui::ImplicitAnimationObserver {
23 public: 24 public:
24 // TODO(estade): remove this enum and instead set elevation directly.
25 enum Style {
26 // Active windows have more opaque shadows, shifted down to make the window
27 // appear "higher".
28 STYLE_ACTIVE,
29
30 // Inactive windows have less opaque shadows.
31 STYLE_INACTIVE,
32
33 // Small windows like tooltips and context menus have lighter, smaller
34 // shadows.
35 STYLE_SMALL,
36 };
37
38 Shadow(); 25 Shadow();
39 ~Shadow() override; 26 ~Shadow() override;
40 27
41 void Init(Style style); 28 void Init(ShadowElevation elevation);
42 29
43 // Returns |layer_.get()|. This is exposed so it can be added to the same 30 // Returns |layer_.get()|. This is exposed so it can be added to the same
44 // layer as the content and stacked below it. SetContentBounds() should be 31 // layer as the content and stacked below it. SetContentBounds() should be
45 // used to adjust the shadow's size and position (rather than applying 32 // used to adjust the shadow's size and position (rather than applying
46 // transformations to this layer). 33 // transformations to this layer).
47 ui::Layer* layer() const { return layer_.get(); } 34 ui::Layer* layer() const { return layer_.get(); }
48 35
49 // Exposed to allow setting animation parameters for bounds and opacity 36 // Exposed to allow setting animation parameters for bounds and opacity
50 // animations. 37 // animations.
51 ui::Layer* shadow_layer() const { return shadow_layer_.get(); } 38 ui::Layer* shadow_layer() const { return shadow_layer_.get(); }
52 39
53 const gfx::Rect& content_bounds() const { return content_bounds_; } 40 const gfx::Rect& content_bounds() const { return content_bounds_; }
54 Style style() const { return style_; } 41 ShadowElevation desired_elevation() const { return desired_elevation_; }
55 42
56 // Moves and resizes the shadow layer to frame |content_bounds|. 43 // Moves and resizes the shadow layer to frame |content_bounds|.
57 void SetContentBounds(const gfx::Rect& content_bounds); 44 void SetContentBounds(const gfx::Rect& content_bounds);
58 45
59 // Sets the shadow's style, animating opacity as necessary. 46 // Sets the shadow's appearance, animating opacity as necessary.
60 void SetStyle(Style style); 47 void SetElevation(ShadowElevation elevation);
61 48
62 // ui::ImplicitAnimationObserver overrides: 49 // ui::ImplicitAnimationObserver overrides:
63 void OnImplicitAnimationsCompleted() override; 50 void OnImplicitAnimationsCompleted() override;
64 51
65 private: 52 private:
66 // Updates the shadow layer and its image to the current |style_|. 53 // Updates the shadow layer and its image to reflect |desired_elevation_|.
67 void RecreateShadowLayer(); 54 void RecreateShadowLayer();
68 55
69 // Updates the shadow layer bounds based on the inteior inset and the current 56 // Updates the shadow layer bounds based on the inteior inset and the current
70 // |content_bounds_|. 57 // |content_bounds_|.
71 void UpdateLayerBounds(); 58 void UpdateLayerBounds();
72 59
73 // Returns the "elevation" for |style_|, which dictates the shadow's display 60 // The goal elevation, set when the transition animation starts. The elevation
74 // characteristics. The elevation is proportional to the size of the blur and 61 // dictates the shadow's display characteristics and is proportional to the
75 // its offset. 62 // size of the blur and its offset. This may not match reality if the window
76 int ElevationForStyle(); 63 // isn't big enough to support it.
64 ShadowElevation desired_elevation_;
77 65
78 // The current style, set when the transition animation starts. 66 // The elevation of the shadow image that's currently set on |shadow_layer_|.
79 Style style_ = STYLE_ACTIVE; 67 int effective_elevation_ = 0;
80 68
81 // The parent layer of the shadow layer. It serves as a container accessible 69 // The parent layer of the shadow layer. It serves as a container accessible
82 // from the outside to control the visibility of the shadow. 70 // from the outside to control the visibility of the shadow.
83 std::unique_ptr<ui::Layer> layer_; 71 std::unique_ptr<ui::Layer> layer_;
84 72
85 // The actual shadow layer corresponding to a cc::NinePatchLayer. 73 // The actual shadow layer corresponding to a cc::NinePatchLayer.
86 std::unique_ptr<ui::Layer> shadow_layer_; 74 std::unique_ptr<ui::Layer> shadow_layer_;
87 75
88 // When the style changes, the old shadow cross-fades with the new one. 76 // When the elevation changes, the old shadow cross-fades with the new one.
89 // When non-null, this is an old |shadow_layer_| that's being animated out. 77 // When non-null, this is an old |shadow_layer_| that's being animated out.
90 std::unique_ptr<ui::Layer> fading_layer_; 78 std::unique_ptr<ui::Layer> fading_layer_;
91 79
92 // Bounds of the content that the shadow encloses. 80 // Bounds of the content that the shadow encloses.
93 gfx::Rect content_bounds_; 81 gfx::Rect content_bounds_;
94 82
95 // The elevation of the shadow image that's currently set on |shadow_layer_|.
96 int effective_elevation_ = 0;
97
98 DISALLOW_COPY_AND_ASSIGN(Shadow); 83 DISALLOW_COPY_AND_ASSIGN(Shadow);
99 }; 84 };
100 85
101 } // namespace wm 86 } // namespace wm
102 87
103 #endif // UI_WM_CORE_SHADOW_H_ 88 #endif // UI_WM_CORE_SHADOW_H_
OLDNEW
« no previous file with comments | « ui/views/widget/widget.h ('k') | ui/wm/core/shadow.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698