Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / wm / core / shadow.h
blob0166d9bcd511fb4a126bb12f421ea29b467278b4
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
3 // found in the LICENSE file.
5 #ifndef UI_WM_CORE_SHADOW_H_
6 #define UI_WM_CORE_SHADOW_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/compositor/layer_animation_observer.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/wm/wm_export.h"
14 namespace ui {
15 class Layer;
16 } // namespace ui
18 namespace wm {
20 // Simple class that draws a drop shadow around content at given bounds.
21 class WM_EXPORT Shadow : public ui::ImplicitAnimationObserver {
22 public:
23 enum Style {
24 // Active windows have more opaque shadows, shifted down to make the window
25 // appear "higher".
26 STYLE_ACTIVE,
28 // Inactive windows have less opaque shadows.
29 STYLE_INACTIVE,
31 // Small windows like tooltips and context menus have lighter, smaller
32 // shadows.
33 STYLE_SMALL,
36 Shadow();
37 ~Shadow() override;
39 void Init(Style style);
41 // Returns |layer_.get()|. This is exposed so it can be added to the same
42 // layer as the content and stacked below it. SetContentBounds() should be
43 // used to adjust the shadow's size and position (rather than applying
44 // transformations to this layer).
45 ui::Layer* layer() const { return layer_.get(); }
47 const gfx::Rect& content_bounds() const { return content_bounds_; }
48 Style style() const { return style_; }
50 // Moves and resizes the shadow layer to frame |content_bounds|.
51 void SetContentBounds(const gfx::Rect& content_bounds);
53 // Sets the shadow's style, animating opacity as necessary.
54 void SetStyle(Style style);
56 // ui::ImplicitAnimationObserver overrides:
57 void OnImplicitAnimationsCompleted() override;
59 private:
60 // Updates the shadow images to the current |style_|.
61 void UpdateImagesForStyle();
63 // Updates the shadow layer bounds based on the inteior inset and the current
64 // |content_bounds_|.
65 void UpdateLayerBounds();
67 // The current style, set when the transition animation starts.
68 Style style_;
70 // The parent layer of the shadow layer. It serves as a container accessible
71 // from the outside to control the visibility of the shadow.
72 scoped_ptr<ui::Layer> layer_;
74 // The actual shadow layer corresponding to a cc::NinePatchLayer.
75 scoped_ptr<ui::Layer> shadow_layer_;
77 // Size of the current shadow image.
78 gfx::Size image_size_;
80 // Bounds of the content that the shadow encloses.
81 gfx::Rect content_bounds_;
83 // The interior inset of the shadow images. The content bounds of the image
84 // grid should be set to |content_bounds_| inset by this amount.
85 int interior_inset_;
87 DISALLOW_COPY_AND_ASSIGN(Shadow);
90 } // namespace wm
92 #endif // UI_WM_CORE_SHADOW_H_