Home | History | Annotate | Download | only in workspace
      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 ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_
      6 #define ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_
      7 
      8 #include "ash/ash_export.h"
      9 #include "base/basictypes.h"
     10 #include "base/gtest_prod_util.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "ui/base/animation/animation_delegate.h"
     13 #include "ui/gfx/rect.h"
     14 
     15 namespace aura {
     16 class Window;
     17 }
     18 
     19 namespace ui {
     20 class SlideAnimation;
     21 }
     22 
     23 namespace views {
     24 class Widget;
     25 }
     26 
     27 namespace ash {
     28 namespace internal {
     29 
     30 // PhantomWindowController is responsible for showing a phantom representation
     31 // of a window. It's used used during dragging a window to show a snap location.
     32 class ASH_EXPORT PhantomWindowController : public ui::AnimationDelegate {
     33  public:
     34   explicit PhantomWindowController(aura::Window* window);
     35   virtual ~PhantomWindowController();
     36 
     37   // Bounds last passed to Show().
     38   const gfx::Rect& bounds() const { return bounds_; }
     39 
     40   // Shows the phantom window at the specified location (coordinates of the
     41   // parent). If |layer| is non-NULL, it is shown on top of the phantom window.
     42   // |layer| is owned by the caller.
     43   // This does not immediately show the window.
     44   void Show(const gfx::Rect& bounds);
     45 
     46   // Hides the phantom.
     47   void Hide();
     48 
     49   // Returns true if the phantom is showing.
     50   bool IsShowing() const;
     51 
     52   // If set, the phantom window is stacked below this window, otherwise it
     53   // is stacked above the window passed to the constructor.
     54   void set_phantom_below_window(aura::Window* phantom_below_window) {
     55     phantom_below_window_ = phantom_below_window;
     56   }
     57 
     58   // ui::AnimationDelegate overrides:
     59   virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
     60 
     61  private:
     62   FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, PhantomStyle);
     63 
     64   // Creates and shows the |phantom_widget_| at |bounds|.
     65   // |layer| is shown on top of the phantom window if it is non-NULL.
     66   // |layer| is not owned by this object.
     67   void CreatePhantomWidget(const gfx::Rect& bounds);
     68 
     69   // Window the phantom is placed beneath.
     70   aura::Window* window_;
     71 
     72   // If set, the phantom window should get stacked below this window.
     73   aura::Window* phantom_below_window_;
     74 
     75   // Initially the bounds of |window_|. Each time Show() is invoked
     76   // |start_bounds_| is then reset to the bounds of |phantom_widget_| and
     77   // |bounds_| is set to the value passed into Show(). The animation animates
     78   // between these two values.
     79   gfx::Rect start_bounds_;
     80   gfx::Rect bounds_;
     81 
     82   views::Widget* phantom_widget_;
     83 
     84   // Used to transition the bounds.
     85   scoped_ptr<ui::SlideAnimation> animation_;
     86 
     87   DISALLOW_COPY_AND_ASSIGN(PhantomWindowController);
     88 };
     89 
     90 }  // namespace internal
     91 }  // namespace ash
     92 
     93 #endif  // ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_
     94