| 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_DRAG_WINDOW_CONTROLLER_H_ | 5 #ifndef ASH_WM_DRAG_WINDOW_CONTROLLER_H_ |
| 6 #define ASH_WM_DRAG_WINDOW_CONTROLLER_H_ | 6 #define ASH_WM_DRAG_WINDOW_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <vector> |
| 9 |
| 8 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 9 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "ui/gfx/display.h" | 14 #include "ui/gfx/display.h" |
| 13 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 14 | 16 |
| 15 namespace aura { | 17 namespace aura { |
| 16 class Window; | 18 class Window; |
| 17 } | 19 } |
| 18 | 20 |
| 19 namespace ui { | 21 namespace ui { |
| 20 class Layer; | |
| 21 class LayerTreeOwner; | 22 class LayerTreeOwner; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace views { | |
| 25 class Widget; | |
| 26 } | |
| 27 | |
| 28 namespace ash { | 25 namespace ash { |
| 29 | 26 |
| 30 // DragWindowController is responsible for showing a semi-transparent window | 27 // DragWindowController is responsible for showing a semi-transparent window |
| 31 // while dragging a window across displays. | 28 // while dragging a window across displays. |
| 32 class ASH_EXPORT DragWindowController { | 29 class ASH_EXPORT DragWindowController { |
| 33 public: | 30 public: |
| 31 // Computes the opacity for drag window based on how much of the area |
| 32 // of the window is visible. |
| 33 static float GetDragWindowOpacity(const gfx::Rect& window_bounds, |
| 34 const gfx::Rect& visible_bounds); |
| 35 |
| 34 explicit DragWindowController(aura::Window* window); | 36 explicit DragWindowController(aura::Window* window); |
| 35 virtual ~DragWindowController(); | 37 virtual ~DragWindowController(); |
| 36 | 38 |
| 37 // Sets the display where the window is placed after the window is dropped. | 39 // This is used to update the bounds and opacity for the drag window |
| 38 void SetDestinationDisplay(const gfx::Display& dst_display); | 40 // immediately. |
| 41 // This also creates/destorys the drag window when necessary. |
| 42 void Update(const gfx::Rect& bounds_in_screen, |
| 43 const gfx::Point& drag_location_in_screen); |
| 39 | 44 |
| 40 // Shows the drag window at the specified location (coordinates of the | 45 // Returns the currently active drag windows. |
| 41 // parent). If |layer| is non-NULL, it is shown on top of the drag window. | 46 int GetDragWindowsCountForTest() const; |
| 42 // |layer| is owned by the caller. | |
| 43 // This does not immediately show the window. | |
| 44 void Show(); | |
| 45 | 47 |
| 46 // Hides the drag window. | 48 // Returns the drag window/layer owner for given index of the |
| 47 void Hide(); | 49 // currently active drag windows list. |
| 48 | 50 const aura::Window* GetDragWindowForTest(size_t index) const; |
| 49 // This is used to set bounds for the drag window immediately. This should | 51 const ui::LayerTreeOwner* GetDragLayerOwnerForTest(size_t index) const; |
| 50 // be called only when the drag window is already visible. | |
| 51 void SetBounds(const gfx::Rect& bounds); | |
| 52 | |
| 53 // Sets the opacity of the drag window. | |
| 54 void SetOpacity(float opacity); | |
| 55 | 52 |
| 56 private: | 53 private: |
| 57 FRIEND_TEST_ALL_PREFIXES(DragWindowResizerTest, DragWindowController); | 54 class DragWindowDetails; |
| 58 | |
| 59 // Creates and shows the |drag_widget_| at |bounds|. | |
| 60 // |layer| is shown on top of the drag window if it is non-NULL. | |
| 61 // |layer| is not owned by this object. | |
| 62 void CreateDragWidget(const gfx::Rect& bounds); | |
| 63 | |
| 64 // Sets bounds of the drag window. The window is shown on |dst_display_| | |
| 65 // if its id() is valid. Otherwise, a display nearest to |bounds| is chosen. | |
| 66 void SetBoundsInternal(const gfx::Rect& bounds); | |
| 67 | |
| 68 // Recreates a fresh layer for |window_| and all its child windows. | |
| 69 void RecreateWindowLayers(); | |
| 70 | 55 |
| 71 // Window the drag window is placed beneath. | 56 // Window the drag window is placed beneath. |
| 72 aura::Window* window_; | 57 aura::Window* window_; |
| 73 | 58 |
| 74 // The display where the drag is placed. When dst_display_.id() is | 59 std::vector<scoped_ptr<DragWindowDetails>> drag_windows_; |
| 75 // kInvalidDisplayID (i.e. the default), a display nearest to the current | |
| 76 // |bounds_| is automatically used. | |
| 77 gfx::Display dst_display_; | |
| 78 | |
| 79 // Initially the bounds of |window_|. Each time Show() is invoked | |
| 80 // |start_bounds_| is then reset to the bounds of |drag_widget_| and | |
| 81 // |bounds_| is set to the value passed into Show(). The animation animates | |
| 82 // between these two values. | |
| 83 gfx::Rect bounds_; | |
| 84 | |
| 85 views::Widget* drag_widget_; | |
| 86 | |
| 87 // The copy of window_->layer() and its descendants. | |
| 88 scoped_ptr<ui::LayerTreeOwner> layer_owner_; | |
| 89 | 60 |
| 90 DISALLOW_COPY_AND_ASSIGN(DragWindowController); | 61 DISALLOW_COPY_AND_ASSIGN(DragWindowController); |
| 91 }; | 62 }; |
| 92 | 63 |
| 93 } // namespace ash | 64 } // namespace ash |
| 94 | 65 |
| 95 #endif // ASH_WM_DRAG_WINDOW_CONTROLLER_H_ | 66 #endif // ASH_WM_DRAG_WINDOW_CONTROLLER_H_ |
| OLD | NEW |