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 #include "ash/wm/workspace/workspace_event_handler.h" | 5 #include "ash/wm/workspace/workspace_event_handler.h" |
6 | 6 |
7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_delegate.h" | 9 #include "ash/shell_delegate.h" |
10 #include "ash/touch/touch_uma.h" | 10 #include "ash/touch/touch_uma.h" |
11 #include "ash/wm/coordinate_conversion.h" | 11 #include "ash/wm/coordinate_conversion.h" |
12 #include "ash/wm/property_util.h" | 12 #include "ash/wm/window_state.h" |
13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
14 #include "ash/wm/workspace/workspace_window_resizer.h" | 14 #include "ash/wm/workspace/workspace_window_resizer.h" |
15 #include "ui/aura/client/aura_constants.h" | 15 #include "ui/aura/client/aura_constants.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
17 #include "ui/aura/window_delegate.h" | 17 #include "ui/aura/window_delegate.h" |
18 #include "ui/base/hit_test.h" | 18 #include "ui/base/hit_test.h" |
19 #include "ui/compositor/scoped_layer_animation_settings.h" | 19 #include "ui/compositor/scoped_layer_animation_settings.h" |
20 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
21 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
22 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
23 | 23 |
24 namespace ash { | 24 namespace ash { |
25 namespace { | 25 namespace { |
26 | 26 |
27 void SingleAxisMaximize(aura::Window* window, | 27 void SingleAxisMaximize(wm::WindowState* window_state, |
28 const gfx::Rect& maximize_rect_in_screen) { | 28 const gfx::Rect& maximize_rect_in_screen) { |
29 gfx::Rect bounds_in_screen = | 29 window_state->SaveCurrentBoundsForRestore(); |
30 ScreenAsh::ConvertRectToScreen(window->parent(), window->bounds()); | 30 window_state->SetBoundsInScreen(maximize_rect_in_screen); |
31 SetRestoreBoundsInScreen(window, bounds_in_screen); | |
32 gfx::Rect bounds_in_parent = | |
33 ScreenAsh::ConvertRectFromScreen(window->parent(), | |
34 maximize_rect_in_screen); | |
35 window->SetBounds(bounds_in_parent); | |
36 } | 31 } |
37 | 32 |
38 void SingleAxisUnmaximize(aura::Window* window, | 33 void SingleAxisUnmaximize(wm::WindowState* window_state, |
39 const gfx::Rect& restore_bounds_in_screen) { | 34 const gfx::Rect& restore_bounds_in_screen) { |
40 gfx::Rect restore_bounds = ScreenAsh::ConvertRectFromScreen( | 35 window_state->SetBoundsInScreen(restore_bounds_in_screen); |
41 window->parent(), restore_bounds_in_screen); | 36 window_state->ClearRestoreBounds(); |
42 window->SetBounds(restore_bounds); | |
43 ClearRestoreBounds(window); | |
44 } | 37 } |
45 | 38 |
46 void ToggleMaximizedState(aura::Window* window) { | 39 void ToggleMaximizedState(wm::WindowState* window_state) { |
47 if (GetRestoreBoundsInScreen(window)) { | 40 if (window_state->HasRestoreBounds()) { |
48 if (window->GetProperty(aura::client::kShowStateKey) == | 41 if (window_state->GetShowState() == ui::SHOW_STATE_NORMAL) { |
49 ui::SHOW_STATE_NORMAL) { | 42 window_state->window()->SetBounds( |
50 window->SetBounds(GetRestoreBoundsInParent(window)); | 43 window_state->GetRestoreBoundsInParent()); |
51 ClearRestoreBounds(window); | 44 window_state->ClearRestoreBounds(); |
52 } else { | 45 } else { |
53 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 46 window_state->Restore(); |
54 } | 47 } |
55 } else if (wm::CanMaximizeWindow(window)) { | 48 } else if (window_state->CanMaximize()) { |
56 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 49 window_state->Maximize(); |
57 } | 50 } |
58 } | 51 } |
59 | 52 |
60 } // namespace | 53 } // namespace |
61 | 54 |
62 namespace internal { | 55 namespace internal { |
63 | 56 |
64 WorkspaceEventHandler::WorkspaceEventHandler(aura::Window* owner) | 57 WorkspaceEventHandler::WorkspaceEventHandler(aura::Window* owner) |
65 : ToplevelWindowEventHandler(owner), | 58 : ToplevelWindowEventHandler(owner), |
66 destroyed_(NULL) { | 59 destroyed_(NULL) { |
(...skipping 19 matching lines...) Expand all Loading... |
86 case ui::ET_MOUSE_CAPTURE_CHANGED: | 79 case ui::ET_MOUSE_CAPTURE_CHANGED: |
87 case ui::ET_MOUSE_EXITED: | 80 case ui::ET_MOUSE_EXITED: |
88 break; | 81 break; |
89 case ui::ET_MOUSE_PRESSED: { | 82 case ui::ET_MOUSE_PRESSED: { |
90 // Maximize behavior is implemented as post-target handling so the target | 83 // Maximize behavior is implemented as post-target handling so the target |
91 // can cancel it. | 84 // can cancel it. |
92 if (ui::EventCanceledDefaultHandling(*event)) { | 85 if (ui::EventCanceledDefaultHandling(*event)) { |
93 ToplevelWindowEventHandler::OnMouseEvent(event); | 86 ToplevelWindowEventHandler::OnMouseEvent(event); |
94 return; | 87 return; |
95 } | 88 } |
96 | 89 wm::WindowState* target_state = wm::GetWindowState(target); |
97 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && | 90 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && |
98 event->IsOnlyLeftMouseButton() && | 91 event->IsOnlyLeftMouseButton() && |
99 target->delegate()->GetNonClientComponent(event->location()) == | 92 target->delegate()->GetNonClientComponent(event->location()) == |
100 HTCAPTION && | 93 HTCAPTION && |
101 !ash::Shell::IsForcedMaximizeMode()) { | 94 !ash::Shell::IsForcedMaximizeMode()) { |
102 bool destroyed = false; | 95 bool destroyed = false; |
103 destroyed_ = &destroyed; | 96 destroyed_ = &destroyed; |
104 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction( | 97 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
105 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); | 98 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); |
106 ToggleMaximizedState(target); | 99 ToggleMaximizedState(target_state); |
107 if (destroyed) | 100 if (destroyed) |
108 return; | 101 return; |
109 destroyed_ = NULL; | 102 destroyed_ = NULL; |
110 } | 103 } |
111 multi_window_resize_controller_.Hide(); | 104 multi_window_resize_controller_.Hide(); |
112 HandleVerticalResizeDoubleClick(target, event); | 105 HandleVerticalResizeDoubleClick(target_state, event); |
113 break; | 106 break; |
114 } | 107 } |
115 default: | 108 default: |
116 break; | 109 break; |
117 } | 110 } |
118 ToplevelWindowEventHandler::OnMouseEvent(event); | 111 ToplevelWindowEventHandler::OnMouseEvent(event); |
119 } | 112 } |
120 | 113 |
121 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { | 114 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
122 aura::Window* target = static_cast<aura::Window*>(event->target()); | 115 aura::Window* target = static_cast<aura::Window*>(event->target()); |
123 if (event->type() == ui::ET_GESTURE_TAP && | 116 if (event->type() == ui::ET_GESTURE_TAP && |
124 target->delegate()->GetNonClientComponent(event->location()) == | 117 target->delegate()->GetNonClientComponent(event->location()) == |
125 HTCAPTION) { | 118 HTCAPTION) { |
126 if (event->details().tap_count() == 2) { | 119 if (event->details().tap_count() == 2) { |
127 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction( | 120 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
128 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); | 121 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); |
129 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time | 122 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time |
130 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. | 123 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. |
131 TouchUMA::GetInstance()->RecordGestureAction( | 124 TouchUMA::GetInstance()->RecordGestureAction( |
132 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); | 125 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); |
133 ToggleMaximizedState(target); // |this| may be destroyed from here. | 126 // |this| may be destroyed from here. |
| 127 ToggleMaximizedState(wm::GetWindowState(target)); |
134 event->StopPropagation(); | 128 event->StopPropagation(); |
135 return; | 129 return; |
136 } else { | 130 } else { |
137 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. | 131 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. |
138 TouchUMA::GetInstance()->RecordGestureAction( | 132 TouchUMA::GetInstance()->RecordGestureAction( |
139 TouchUMA::GESTURE_FRAMEVIEW_TAP); | 133 TouchUMA::GESTURE_FRAMEVIEW_TAP); |
140 } | 134 } |
141 } | 135 } |
142 ToplevelWindowEventHandler::OnGestureEvent(event); | 136 ToplevelWindowEventHandler::OnGestureEvent(event); |
143 } | 137 } |
144 | 138 |
145 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( | 139 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( |
146 aura::Window* target, | 140 wm::WindowState* target_state, |
147 ui::MouseEvent* event) { | 141 ui::MouseEvent* event) { |
| 142 aura::Window* target = target_state->window(); |
148 gfx::Rect max_size(target->delegate()->GetMaximumSize()); | 143 gfx::Rect max_size(target->delegate()->GetMaximumSize()); |
149 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && | 144 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && !target_state->IsMaximized()) { |
150 !wm::IsWindowMaximized(target)) { | |
151 int component = | 145 int component = |
152 target->delegate()->GetNonClientComponent(event->location()); | 146 target->delegate()->GetNonClientComponent(event->location()); |
153 gfx::Rect work_area = | 147 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( |
154 Shell::GetScreen()->GetDisplayNearestWindow(target).work_area(); | 148 target).work_area(); |
155 const gfx::Rect* restore_bounds = | |
156 GetRestoreBoundsInScreen(target); | |
157 if (component == HTBOTTOM || component == HTTOP) { | 149 if (component == HTBOTTOM || component == HTTOP) { |
158 // Don't maximize vertically if the window has a max height defined. | 150 // Don't maximize vertically if the window has a max height defined. |
159 if (max_size.height() != 0) | 151 if (max_size.height() != 0) |
160 return; | 152 return; |
161 if (restore_bounds && | 153 if (target_state->HasRestoreBounds() && |
162 (target->bounds().height() == work_area.height() && | 154 (target->bounds().height() == work_area.height() && |
163 target->bounds().y() == work_area.y())) { | 155 target->bounds().y() == work_area.y())) { |
164 SingleAxisUnmaximize(target, *restore_bounds); | 156 SingleAxisUnmaximize(target_state, |
| 157 target_state->GetRestoreBoundsInScreen()); |
165 } else { | 158 } else { |
166 gfx::Point origin = target->bounds().origin(); | 159 gfx::Point origin = target->bounds().origin(); |
167 wm::ConvertPointToScreen(target->parent(), &origin); | 160 wm::ConvertPointToScreen(target->parent(), &origin); |
168 SingleAxisMaximize(target, | 161 SingleAxisMaximize(target_state, |
169 gfx::Rect(origin.x(), | 162 gfx::Rect(origin.x(), |
170 work_area.y(), | 163 work_area.y(), |
171 target->bounds().width(), | 164 target->bounds().width(), |
172 work_area.height())); | 165 work_area.height())); |
173 } | 166 } |
174 } else if (component == HTLEFT || component == HTRIGHT) { | 167 } else if (component == HTLEFT || component == HTRIGHT) { |
175 // Don't maximize horizontally if the window has a max width defined. | 168 // Don't maximize horizontally if the window has a max width defined. |
176 if (max_size.width() != 0) | 169 if (max_size.width() != 0) |
177 return; | 170 return; |
178 if (restore_bounds && | 171 if (target_state->HasRestoreBounds() && |
179 (target->bounds().width() == work_area.width() && | 172 (target->bounds().width() == work_area.width() && |
180 target->bounds().x() == work_area.x())) { | 173 target->bounds().x() == work_area.x())) { |
181 SingleAxisUnmaximize(target, *restore_bounds); | 174 SingleAxisUnmaximize(target_state, |
| 175 target_state->GetRestoreBoundsInScreen()); |
182 } else { | 176 } else { |
183 gfx::Point origin = target->bounds().origin(); | 177 gfx::Point origin = target->bounds().origin(); |
184 wm::ConvertPointToScreen(target->parent(), &origin); | 178 wm::ConvertPointToScreen(target->parent(), &origin); |
185 SingleAxisMaximize(target, | 179 SingleAxisMaximize(target_state, |
186 gfx::Rect(work_area.x(), | 180 gfx::Rect(work_area.x(), |
187 origin.y(), | 181 origin.y(), |
188 work_area.width(), | 182 work_area.width(), |
189 target->bounds().height())); | 183 target->bounds().height())); |
190 } | 184 } |
191 } | 185 } |
192 } | 186 } |
193 } | 187 } |
194 | 188 |
195 } // namespace internal | 189 } // namespace internal |
196 } // namespace ash | 190 } // namespace ash |
OLD | NEW |