Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / wm / workspace / multi_window_resize_controller.h
blob35a25a6d2ec0d068b595bcd75f0b32d0ffec1ad6
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.
5 #ifndef ASH_WM_WORKSPACE_MULTI_WINDOW_RESIZE_CONTROLLER_H_
6 #define ASH_WM_WORKSPACE_MULTI_WINDOW_RESIZE_CONTROLLER_H_
8 #include <vector>
10 #include "ash/ash_export.h"
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.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"
18 namespace aura {
19 class Window;
22 namespace views {
23 class Widget;
26 namespace ash {
27 class MultiWindowResizeControllerTest;
28 class WorkspaceWindowResizer;
30 // Two directions resizes happen in.
31 enum Direction {
32 TOP_BOTTOM,
33 LEFT_RIGHT,
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;
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);
49 // Hides the resize widget.
50 void Hide();
52 // MouseWatcherListenre overrides:
53 void MouseMovedOutOfHost() override;
55 // WindowObserver overrides:
56 void OnWindowDestroying(aura::Window* window) override;
58 private:
59 friend class MultiWindowResizeControllerTest;
61 // Used to track the two resizable windows and direction.
62 struct ResizeWindows {
63 ResizeWindows();
64 ~ResizeWindows();
66 // Returns true if |other| equals this ResizeWindows. This does *not*
67 // consider the windows in |other_windows|.
68 bool Equals(const ResizeWindows& other) const;
70 // Returns true if this ResizeWindows is valid.
71 bool is_valid() const { return window1 && window2; }
73 // The left/top window to resize.
74 aura::Window* window1;
76 // Other window to resize.
77 aura::Window* window2;
79 // Direction
80 Direction direction;
82 // Windows after |window2| that are to be resized. Determined at the time
83 // the resize starts.
84 std::vector<aura::Window*> other_windows;
87 class ResizeMouseWatcherHost;
88 class ResizeView;
90 void CreateMouseWatcher();
92 // Returns a ResizeWindows based on the specified arguments. Use is_valid()
93 // to test if the return value is a valid multi window resize location.
94 ResizeWindows DetermineWindows(aura::Window* window,
95 int window_component,
96 const gfx::Point& point) const;
98 // Variant of DetermineWindows() that uses the current location of the mouse
99 // to determine the resize windows.
100 ResizeWindows DetermineWindowsFromScreenPoint(aura::Window* window) const;
102 // Finds a window by edge (one of the constants HitTestCompat.
103 aura::Window* FindWindowByEdge(aura::Window* window_to_ignore,
104 int edge_want,
105 int x_in_parent,
106 int y_in_parent) const;
108 // Returns the first window touching |window|.
109 aura::Window* FindWindowTouching(aura::Window* window,
110 Direction direction) const;
112 // Places any windows touching |start| into |others|.
113 void FindWindowsTouching(aura::Window* start,
114 Direction direction,
115 std::vector<aura::Window*>* others) const;
117 // Shows the resizer if the mouse is still at a valid location. This is called
118 // from the |show_timer_|.
119 void ShowIfValidMouseLocation();
121 // Shows the widget immediately.
122 void ShowNow();
124 // Returns true if the widget is showing.
125 bool IsShowing() const;
127 // Initiates a resize.
128 void StartResize(const gfx::Point& location_in_screen);
130 // Resizes to the new location.
131 void Resize(const gfx::Point& location_in_screen, int event_flags);
133 // Completes the resize.
134 void CompleteResize();
136 // Cancels the resize.
137 void CancelResize();
139 // Returns the bounds for the resize widget.
140 gfx::Rect CalculateResizeWidgetBounds(
141 const gfx::Point& location_in_parent) const;
143 // Returns true if |location_in_screen| is over the resize widget.
144 bool IsOverResizeWidget(const gfx::Point& location_in_screen) const;
146 // Returns true if |location_in_screen| is over the resize windows
147 // (or the resize widget itself).
148 bool IsOverWindows(const gfx::Point& location_in_screen) const;
150 // Returns true if |location_in_screen| is over |component| in |window|.
151 bool IsOverComponent(aura::Window* window,
152 const gfx::Point& location_in_screen,
153 int component) const;
155 // Windows and direction to resize.
156 ResizeWindows windows_;
158 // Timer used before showing.
159 base::OneShotTimer<MultiWindowResizeController> show_timer_;
161 scoped_ptr<views::Widget> resize_widget_;
163 // If non-null we're in a resize loop.
164 scoped_ptr<WorkspaceWindowResizer> window_resizer_;
166 // Mouse coordinate passed to Show() in container's coodinates.
167 gfx::Point show_location_in_parent_;
169 // Bounds the widget was last shown at in screen coordinates.
170 gfx::Rect show_bounds_in_screen_;
172 // Used to detect whether the mouse is over the windows. While
173 // |resize_widget_| is non-NULL (ie the widget is showing) we ignore calls
174 // to Show().
175 scoped_ptr<views::MouseWatcher> mouse_watcher_;
177 DISALLOW_COPY_AND_ASSIGN(MultiWindowResizeController);
180 } // namespace ash
182 #endif // ASH_WM_WORKSPACE_MULTI_WINDOW_RESIZE_CONTROLLER_H_