| OLD | NEW |
| 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 ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_ | 5 #ifndef ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_ |
| 6 #define ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_ | 6 #define ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "ui/base/animation/animation_delegate.h" | 11 #include "ui/base/animation/animation_delegate.h" |
| 12 #include "ui/gfx/display.h" |
| 12 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
| 13 | 14 |
| 14 namespace aura { | 15 namespace aura { |
| 15 class Window; | 16 class Window; |
| 17 class RootWindow; |
| 16 } | 18 } |
| 17 | 19 |
| 18 namespace ui { | 20 namespace ui { |
| 19 class SlideAnimation; | 21 class SlideAnimation; |
| 20 } | 22 } |
| 21 | 23 |
| 22 namespace views { | 24 namespace views { |
| 23 class Widget; | 25 class Widget; |
| 24 } | 26 } |
| 25 | 27 |
| 26 namespace ash { | 28 namespace ash { |
| 27 namespace internal { | 29 namespace internal { |
| 28 | 30 |
| 29 // PhantomWindowController is responsible for showing a phantom representation | 31 // PhantomWindowController is responsible for showing a phantom representation |
| 30 // of a window. It's used used during dragging a window to show a snap location. | 32 // of a window. It's used used during dragging a window to show a snap location. |
| 31 class ASH_EXPORT PhantomWindowController : public ui::AnimationDelegate { | 33 class ASH_EXPORT PhantomWindowController : public ui::AnimationDelegate { |
| 32 public: | 34 public: |
| 33 explicit PhantomWindowController(aura::Window* window); | 35 enum Style { |
| 36 STYLE_SHADOW, // for window snapping. |
| 37 STYLE_WINDOW, // for window dragging. |
| 38 }; |
| 39 |
| 40 PhantomWindowController(aura::Window* window, |
| 41 aura::RootWindow* root_window, |
| 42 Style style); |
| 34 virtual ~PhantomWindowController(); | 43 virtual ~PhantomWindowController(); |
| 35 | 44 |
| 36 // Bounds last passed to Show(). | 45 // Bounds last passed to Show(). |
| 37 const gfx::Rect& bounds() const { return bounds_; } | 46 const gfx::Rect& bounds() const { return bounds_; } |
| 38 | 47 |
| 39 // Shows the phantom window at the specified location (coordinates of the | 48 // Shows the phantom window at the specified location (coordinates of the |
| 40 // parent). This does not immediately show the window. | 49 // parent). This does not immediately show the window. |
| 41 void Show(const gfx::Rect& bounds); | 50 void Show(const gfx::Rect& bounds); |
| 42 | 51 |
| 43 // This is used to set bounds for the phantom window immediately. This should | 52 // This is used to set bounds for the phantom window immediately. This should |
| 44 // be called only when the phantom window is already visible. | 53 // be called only when the phantom window is already visible. |
| 45 void SetBounds(const gfx::Rect& bounds); | 54 void SetBounds(const gfx::Rect& bounds); |
| 46 | 55 |
| 47 // Hides the phantom. | 56 // Hides the phantom. |
| 48 void Hide(); | 57 void Hide(); |
| 49 | 58 |
| 50 // Returns true if the phantom is showing. | 59 // Returns true if the phantom is showing. |
| 51 bool IsShowing() const; | 60 bool IsShowing() const; |
| 52 | 61 |
| 53 // If set, the phantom window is stacked below this window, otherwise it | 62 // If set, the phantom window is stacked below this window, otherwise it |
| 54 // is stacked above the window passed to the constructor. | 63 // is stacked above the window passed to the constructor. |
| 55 void set_phantom_below_window(aura::Window* phantom_below_window) { | 64 void set_phantom_below_window(aura::Window* phantom_below_window) { |
| 56 phantom_below_window_ = phantom_below_window; | 65 phantom_below_window_ = phantom_below_window; |
| 57 } | 66 } |
| 58 | 67 |
| 68 Style style() const { |
| 69 return style_; |
| 70 } |
| 71 |
| 72 // Sets/gets the opacity of the phantom window. |
| 73 void SetOpacity(float opacity); |
| 74 float GetOpacity() const; |
| 75 |
| 59 // ui::AnimationDelegate overrides: | 76 // ui::AnimationDelegate overrides: |
| 60 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 77 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 61 | 78 |
| 62 private: | 79 private: |
| 63 // Creates and shows the |phantom_widget_| at |bounds|. | 80 // Creates and shows the |phantom_widget_| at |bounds|. |
| 64 void CreatePhantomWidget(const gfx::Rect& bounds); | 81 void CreatePhantomWidget(const gfx::Rect& bounds); |
| 65 | 82 |
| 83 // Sets bounds of the phantom window. The window is shown on |dst_display_| |
| 84 // if its id() is valid. Otherwise, a display nearest to |bounds| is chosen. |
| 85 void SetBoundsInternal(const gfx::Rect& bounds); |
| 86 |
| 66 // Window the phantom is placed beneath. | 87 // Window the phantom is placed beneath. |
| 67 aura::Window* window_; | 88 aura::Window* window_; |
| 68 | 89 |
| 90 // The display where the phantom is placed. When dst_display_.id() is -1, a |
| 91 // display nearest to the current |bounds_| is automatically used. |
| 92 gfx::Display dst_display_; |
| 93 |
| 69 // If set, the phantom window should get stacked below this window. | 94 // If set, the phantom window should get stacked below this window. |
| 70 aura::Window* phantom_below_window_; | 95 aura::Window* phantom_below_window_; |
| 71 | 96 |
| 72 // Initially the bounds of |window_|. Each time Show() is invoked | 97 // Initially the bounds of |window_|. Each time Show() is invoked |
| 73 // |start_bounds_| is then reset to the bounds of |phantom_widget_| and | 98 // |start_bounds_| is then reset to the bounds of |phantom_widget_| and |
| 74 // |bounds_| is set to the value passed into Show(). The animation animates | 99 // |bounds_| is set to the value passed into Show(). The animation animates |
| 75 // between these two values. | 100 // between these two values. |
| 76 gfx::Rect start_bounds_; | 101 gfx::Rect start_bounds_; |
| 77 gfx::Rect bounds_; | 102 gfx::Rect bounds_; |
| 78 | 103 |
| 79 views::Widget* phantom_widget_; | 104 views::Widget* phantom_widget_; |
| 80 | 105 |
| 81 // Used to transition the bounds. | 106 // Used to transition the bounds. |
| 82 scoped_ptr<ui::SlideAnimation> animation_; | 107 scoped_ptr<ui::SlideAnimation> animation_; |
| 83 | 108 |
| 109 // The style of the phantom window. |
| 110 Style style_; |
| 111 |
| 84 DISALLOW_COPY_AND_ASSIGN(PhantomWindowController); | 112 DISALLOW_COPY_AND_ASSIGN(PhantomWindowController); |
| 85 }; | 113 }; |
| 86 | 114 |
| 87 } // namespace internal | 115 } // namespace internal |
| 88 } // namespace ash | 116 } // namespace ash |
| 89 | 117 |
| 90 #endif // ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_ | 118 #endif // ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_ |
| OLD | NEW |