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. 4 5 #ifndef UI_WM_CORE_SHADOW_H_ 6 #define UI_WM_CORE_SHADOW_H_ 7 8 #include "base/basictypes.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "ui/compositor/layer_animation_observer.h" 11 #include "ui/gfx/rect.h" 12 #include "ui/wm/wm_export.h" 13 14 namespace ui { 15 class Layer; 16 } // namespace ui 17 18 namespace wm { 19 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, 27 28 // Inactive windows have less opaque shadows. 29 STYLE_INACTIVE, 30 31 // Small windows like tooltips and context menus have lighter, smaller 32 // shadows. 33 STYLE_SMALL, 34 }; 35 36 Shadow(); 37 virtual ~Shadow(); 38 39 void Init(Style style); 40 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). layer()45 ui::Layer* layer() const { return layer_.get(); } 46 content_bounds()47 const gfx::Rect& content_bounds() const { return content_bounds_; } style()48 Style style() const { return style_; } 49 50 // Moves and resizes the shadow layer to frame |content_bounds|. 51 void SetContentBounds(const gfx::Rect& content_bounds); 52 53 // Sets the shadow's style, animating opacity as necessary. 54 void SetStyle(Style style); 55 56 // ui::ImplicitAnimationObserver overrides: 57 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 58 59 private: 60 // Updates the shadow images to the current |style_|. 61 void UpdateImagesForStyle(); 62 63 // Updates the shadow layer bounds based on the inteior inset and the current 64 // |content_bounds_|. 65 void UpdateLayerBounds(); 66 67 // The current style, set when the transition animation starts. 68 Style style_; 69 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_; 73 74 // The actual shadow layer corresponding to a cc::NinePatchLayer. 75 scoped_ptr<ui::Layer> shadow_layer_; 76 77 // Size of the current shadow image. 78 gfx::Size image_size_; 79 80 // Bounds of the content that the shadow encloses. 81 gfx::Rect content_bounds_; 82 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_; 86 87 DISALLOW_COPY_AND_ASSIGN(Shadow); 88 }; 89 90 } // namespace wm 91 92 #endif // UI_WM_CORE_SHADOW_H_ 93