Home | History | Annotate | Download | only in core
      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 class ImageGrid;
     21 
     22 // Simple class that draws a drop shadow around content at given bounds.
     23 class WM_EXPORT Shadow : public ui::ImplicitAnimationObserver {
     24  public:
     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();
     39   virtual ~Shadow();
     40 
     41   void Init(Style style);
     42 
     43   // Returns |image_grid_|'s ui::Layer.  This is exposed so it can be added to
     44   // the same layer as the content and stacked below it.  SetContentBounds()
     45   // should be used to adjust the shadow's size and position (rather than
     46   // applying transformations to this layer).
     47   ui::Layer* layer() const;
     48 
     49   const gfx::Rect& content_bounds() const { return content_bounds_; }
     50   Style style() const { return style_; }
     51 
     52   // Moves and resizes |image_grid_| to frame |content_bounds|.
     53   void SetContentBounds(const gfx::Rect& content_bounds);
     54 
     55   // Sets the shadow's style, animating opacity as necessary.
     56   void SetStyle(Style style);
     57 
     58   // ui::ImplicitAnimationObserver overrides:
     59   virtual void OnImplicitAnimationsCompleted() OVERRIDE;
     60 
     61  private:
     62   // Updates the |image_grid_| images to the current |style_|.
     63   void UpdateImagesForStyle();
     64 
     65   // Updates the |image_grid_| bounds based on its image sizes and the
     66   // current |content_bounds_|.
     67   void UpdateImageGridBounds();
     68 
     69   // The current style, set when the transition animation starts.
     70   Style style_;
     71 
     72   scoped_ptr<ImageGrid> image_grid_;
     73 
     74   // Bounds of the content that the shadow encloses.
     75   gfx::Rect content_bounds_;
     76 
     77   // The interior inset of the shadow images. The content bounds of the image
     78   // grid should be set to |content_bounds_| inset by this amount.
     79   int interior_inset_;
     80 
     81   DISALLOW_COPY_AND_ASSIGN(Shadow);
     82 };
     83 
     84 }  // namespace wm
     85 
     86 #endif  // UI_WM_CORE_SHADOW_H_
     87