| OLD | NEW |
| (Empty) |
| 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_MULTI_WINDOW_RESIZE_CONTROLLER_H_ | |
| 6 #define ASH_WM_WORKSPACE_MULTI_WINDOW_RESIZE_CONTROLLER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "ash/ash_export.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/timer/timer.h" | |
| 14 #include "ui/aura/window_observer.h" | |
| 15 #include "ui/gfx/geometry/rect.h" | |
| 16 #include "ui/views/mouse_watcher.h" | |
| 17 | |
| 18 namespace aura { | |
| 19 class Window; | |
| 20 } | |
| 21 | |
| 22 namespace views { | |
| 23 class Widget; | |
| 24 } | |
| 25 | |
| 26 namespace ash { | |
| 27 class MultiWindowResizeControllerTest; | |
| 28 class WorkspaceWindowResizer; | |
| 29 | |
| 30 // Two directions resizes happen in. | |
| 31 enum Direction { | |
| 32 TOP_BOTTOM, | |
| 33 LEFT_RIGHT, | |
| 34 }; | |
| 35 | |
| 36 // MultiWindowResizeController is responsible for determining and showing a | |
| 37 // widget that allows resizing multiple windows at the same time. | |
| 38 // MultiWindowResizeController is driven by WorkspaceEventFilter. | |
| 39 class ASH_EXPORT MultiWindowResizeController : | |
| 40 public views::MouseWatcherListener, public aura::WindowObserver { | |
| 41 public: | |
| 42 MultiWindowResizeController(); | |
| 43 ~MultiWindowResizeController() override; | |
| 44 | |
| 45 // If necessary, shows the resize widget. |window| is the window the mouse | |
| 46 // is over, |component| the edge and |point| the location of the mouse. | |
| 47 void Show(aura::Window* window, int component, const gfx::Point& point); | |
| 48 | |
| 49 // Hides the resize widget. | |
| 50 void Hide(); | |
| 51 | |
| 52 // MouseWatcherListenre overrides: | |
| 53 void MouseMovedOutOfHost() override; | |
| 54 | |
| 55 // WindowObserver overrides: | |
| 56 void OnWindowDestroying(aura::Window* window) override; | |
| 57 | |
| 58 private: | |
| 59 friend class MultiWindowResizeControllerTest; | |
| 60 | |
| 61 // Used to track the two resizable windows and direction. | |
| 62 struct ResizeWindows { | |
| 63 ResizeWindows(); | |
| 64 ResizeWindows(const ResizeWindows& other); | |
| 65 ~ResizeWindows(); | |
| 66 | |
| 67 // Returns true if |other| equals this ResizeWindows. This does *not* | |
| 68 // consider the windows in |other_windows|. | |
| 69 bool Equals(const ResizeWindows& other) const; | |
| 70 | |
| 71 // Returns true if this ResizeWindows is valid. | |
| 72 bool is_valid() const { return window1 && window2; } | |
| 73 | |
| 74 // The left/top window to resize. | |
| 75 aura::Window* window1; | |
| 76 | |
| 77 // Other window to resize. | |
| 78 aura::Window* window2; | |
| 79 | |
| 80 // Direction | |
| 81 Direction direction; | |
| 82 | |
| 83 // Windows after |window2| that are to be resized. Determined at the time | |
| 84 // the resize starts. | |
| 85 std::vector<aura::Window*> other_windows; | |
| 86 }; | |
| 87 | |
| 88 class ResizeMouseWatcherHost; | |
| 89 class ResizeView; | |
| 90 | |
| 91 void CreateMouseWatcher(); | |
| 92 | |
| 93 // Returns a ResizeWindows based on the specified arguments. Use is_valid() | |
| 94 // to test if the return value is a valid multi window resize location. | |
| 95 ResizeWindows DetermineWindows(aura::Window* window, | |
| 96 int window_component, | |
| 97 const gfx::Point& point) const; | |
| 98 | |
| 99 // Variant of DetermineWindows() that uses the current location of the mouse | |
| 100 // to determine the resize windows. | |
| 101 ResizeWindows DetermineWindowsFromScreenPoint(aura::Window* window) const; | |
| 102 | |
| 103 // Finds a window by edge (one of the constants HitTestCompat. | |
| 104 aura::Window* FindWindowByEdge(aura::Window* window_to_ignore, | |
| 105 int edge_want, | |
| 106 int x_in_parent, | |
| 107 int y_in_parent) const; | |
| 108 | |
| 109 // Returns the first window touching |window|. | |
| 110 aura::Window* FindWindowTouching(aura::Window* window, | |
| 111 Direction direction) const; | |
| 112 | |
| 113 // Places any windows touching |start| into |others|. | |
| 114 void FindWindowsTouching(aura::Window* start, | |
| 115 Direction direction, | |
| 116 std::vector<aura::Window*>* others) const; | |
| 117 | |
| 118 // Shows the resizer if the mouse is still at a valid location. This is called | |
| 119 // from the |show_timer_|. | |
| 120 void ShowIfValidMouseLocation(); | |
| 121 | |
| 122 // Shows the widget immediately. | |
| 123 void ShowNow(); | |
| 124 | |
| 125 // Returns true if the widget is showing. | |
| 126 bool IsShowing() const; | |
| 127 | |
| 128 // Initiates a resize. | |
| 129 void StartResize(const gfx::Point& location_in_screen); | |
| 130 | |
| 131 // Resizes to the new location. | |
| 132 void Resize(const gfx::Point& location_in_screen, int event_flags); | |
| 133 | |
| 134 // Completes the resize. | |
| 135 void CompleteResize(); | |
| 136 | |
| 137 // Cancels the resize. | |
| 138 void CancelResize(); | |
| 139 | |
| 140 // Returns the bounds for the resize widget. | |
| 141 gfx::Rect CalculateResizeWidgetBounds( | |
| 142 const gfx::Point& location_in_parent) const; | |
| 143 | |
| 144 // Returns true if |location_in_screen| is over the resize widget. | |
| 145 bool IsOverResizeWidget(const gfx::Point& location_in_screen) const; | |
| 146 | |
| 147 // Returns true if |location_in_screen| is over the resize windows | |
| 148 // (or the resize widget itself). | |
| 149 bool IsOverWindows(const gfx::Point& location_in_screen) const; | |
| 150 | |
| 151 // Returns true if |location_in_screen| is over |component| in |window|. | |
| 152 bool IsOverComponent(aura::Window* window, | |
| 153 const gfx::Point& location_in_screen, | |
| 154 int component) const; | |
| 155 | |
| 156 // Windows and direction to resize. | |
| 157 ResizeWindows windows_; | |
| 158 | |
| 159 // Timer used before showing. | |
| 160 base::OneShotTimer show_timer_; | |
| 161 | |
| 162 std::unique_ptr<views::Widget> resize_widget_; | |
| 163 | |
| 164 // If non-null we're in a resize loop. | |
| 165 std::unique_ptr<WorkspaceWindowResizer> window_resizer_; | |
| 166 | |
| 167 // Mouse coordinate passed to Show() in container's coodinates. | |
| 168 gfx::Point show_location_in_parent_; | |
| 169 | |
| 170 // Bounds the widget was last shown at in screen coordinates. | |
| 171 gfx::Rect show_bounds_in_screen_; | |
| 172 | |
| 173 // Used to detect whether the mouse is over the windows. While | |
| 174 // |resize_widget_| is non-NULL (ie the widget is showing) we ignore calls | |
| 175 // to Show(). | |
| 176 std::unique_ptr<views::MouseWatcher> mouse_watcher_; | |
| 177 | |
| 178 DISALLOW_COPY_AND_ASSIGN(MultiWindowResizeController); | |
| 179 }; | |
| 180 | |
| 181 } // namespace ash | |
| 182 | |
| 183 #endif // ASH_WM_WORKSPACE_MULTI_WINDOW_RESIZE_CONTROLLER_H_ | |
| OLD | NEW |