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