Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: ash/wm/wm_toplevel_window_event_handler.cc

Issue 2905893002: chromeos: convert more ash/wm code to aura::Window (Closed)
Patch Set: moar cleanup Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/wm_toplevel_window_event_handler.h" 5 #include "ash/wm/wm_toplevel_window_event_handler.h"
6 6
7 #include "ash/public/cpp/config.h"
8 #include "ash/shell.h"
7 #include "ash/shell_port.h" 9 #include "ash/shell_port.h"
10 #include "ash/wm/resize_shadow_controller.h"
8 #include "ash/wm/window_resizer.h" 11 #include "ash/wm/window_resizer.h"
9 #include "ash/wm/window_state.h" 12 #include "ash/wm/window_state.h"
10 #include "ash/wm/window_state_observer.h" 13 #include "ash/wm/window_state_observer.h"
14 #include "ash/wm/window_util.h"
11 #include "ash/wm/wm_event.h" 15 #include "ash/wm/wm_event.h"
12 #include "ash/wm_window.h" 16 #include "ui/aura/client/window_types.h"
13 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/aura/window_delegate.h"
14 #include "ui/aura/window_observer.h" 19 #include "ui/aura/window_observer.h"
15 #include "ui/base/hit_test.h" 20 #include "ui/base/hit_test.h"
16 #include "ui/events/event.h" 21 #include "ui/events/event.h"
17 22
18 namespace { 23 namespace {
19 const double kMinHorizVelocityForWindowSwipe = 1100; 24 const double kMinHorizVelocityForWindowSwipe = 1100;
20 const double kMinVertVelocityForWindowMinimize = 1000; 25 const double kMinVertVelocityForWindowMinimize = 1000;
21 } 26 }
22 27
23 namespace ash { 28 namespace ash {
24 namespace wm { 29 namespace wm {
25 30
26 namespace { 31 namespace {
27 32
28 // Returns whether |window| can be moved via a two finger drag given 33 // Returns whether |window| can be moved via a two finger drag given
29 // the hittest results of the two fingers. 34 // the hittest results of the two fingers.
30 bool CanStartTwoFingerMove(WmWindow* window, 35 bool CanStartTwoFingerMove(aura::Window* window,
31 int window_component1, 36 int window_component1,
32 int window_component2) { 37 int window_component2) {
33 // We allow moving a window via two fingers when the hittest components are 38 // We allow moving a window via two fingers when the hittest components are
34 // HTCLIENT. This is done so that a window can be dragged via two fingers when 39 // HTCLIENT. This is done so that a window can be dragged via two fingers when
35 // the tab strip is full and hitting the caption area is difficult. We check 40 // the tab strip is full and hitting the caption area is difficult. We check
36 // the window type and the state type so that we do not steal touches from the 41 // the window type and the state type so that we do not steal touches from the
37 // web contents. 42 // web contents.
38 if (!window->GetWindowState()->IsNormalOrSnapped() || 43 if (!GetWindowState(window)->IsNormalOrSnapped() ||
39 window->GetType() != aura::client::WINDOW_TYPE_NORMAL) { 44 window->type() != aura::client::WINDOW_TYPE_NORMAL) {
40 return false; 45 return false;
41 } 46 }
42 int component1_behavior = 47 int component1_behavior =
43 WindowResizer::GetBoundsChangeForWindowComponent(window_component1); 48 WindowResizer::GetBoundsChangeForWindowComponent(window_component1);
44 int component2_behavior = 49 int component2_behavior =
45 WindowResizer::GetBoundsChangeForWindowComponent(window_component2); 50 WindowResizer::GetBoundsChangeForWindowComponent(window_component2);
46 return (component1_behavior & WindowResizer::kBoundsChange_Resizes) == 0 && 51 return (component1_behavior & WindowResizer::kBoundsChange_Resizes) == 0 &&
47 (component2_behavior & WindowResizer::kBoundsChange_Resizes) == 0; 52 (component2_behavior & WindowResizer::kBoundsChange_Resizes) == 0;
48 } 53 }
49 54
50 // Returns whether |window| can be moved or resized via one finger given 55 // Returns whether |window| can be moved or resized via one finger given
51 // |window_component|. 56 // |window_component|.
52 bool CanStartOneFingerDrag(int window_component) { 57 bool CanStartOneFingerDrag(int window_component) {
53 return WindowResizer::GetBoundsChangeForWindowComponent(window_component) != 58 return WindowResizer::GetBoundsChangeForWindowComponent(window_component) !=
54 0; 59 0;
55 } 60 }
56 61
57 // Returns the window component containing |event|'s location. 62 void ShowResizeShadow(aura::Window* window, int component) {
58 int GetWindowComponent(WmWindow* window, const ui::LocatedEvent& event) { 63 if (Shell::GetAshConfig() == Config::MASH) {
59 return window->GetNonClientComponent(event.location()); 64 // TODO: http://crbug.com/640773.
65 return;
66 }
67 ResizeShadowController* resize_shadow_controller =
68 Shell::Get()->resize_shadow_controller();
69 if (resize_shadow_controller)
70 resize_shadow_controller->ShowShadow(window, component);
71 }
72
73 void HideResizeShadow(aura::Window* window) {
74 if (Shell::GetAshConfig() == Config::MASH) {
75 // TODO: http://crbug.com/640773.
76 return;
77 }
78 ResizeShadowController* resize_shadow_controller =
79 Shell::Get()->resize_shadow_controller();
80 if (resize_shadow_controller)
81 resize_shadow_controller->HideShadow(window);
60 } 82 }
61 83
62 } // namespace 84 } // namespace
63 85
64 // ScopedWindowResizer --------------------------------------------------------- 86 // ScopedWindowResizer ---------------------------------------------------------
65 87
66 // Wraps a WindowResizer and installs an observer on its target window. When 88 // Wraps a WindowResizer and installs an observer on its target window. When
67 // the window is destroyed ResizerWindowDestroyed() is invoked back on the 89 // the window is destroyed ResizerWindowDestroyed() is invoked back on the
68 // WmToplevelWindowEventHandler to clean up. 90 // WmToplevelWindowEventHandler to clean up.
69 class WmToplevelWindowEventHandler::ScopedWindowResizer 91 class WmToplevelWindowEventHandler::ScopedWindowResizer
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 170 }
149 171
150 void WmToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { 172 void WmToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) {
151 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED && 173 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED &&
152 event->key_code() == ui::VKEY_ESCAPE) { 174 event->key_code() == ui::VKEY_ESCAPE) {
153 CompleteDrag(DragResult::REVERT); 175 CompleteDrag(DragResult::REVERT);
154 } 176 }
155 } 177 }
156 178
157 void WmToplevelWindowEventHandler::OnMouseEvent(ui::MouseEvent* event, 179 void WmToplevelWindowEventHandler::OnMouseEvent(ui::MouseEvent* event,
158 WmWindow* target) { 180 aura::Window* target) {
159 if (event->handled()) 181 if (event->handled())
160 return; 182 return;
161 if ((event->flags() & 183 if ((event->flags() &
162 (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)) != 0) 184 (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)) != 0)
163 return; 185 return;
164 186
165 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED) { 187 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED) {
166 // Capture is grabbed when both gesture and mouse drags start. Handle 188 // Capture is grabbed when both gesture and mouse drags start. Handle
167 // capture loss regardless of which type of drag is in progress. 189 // capture loss regardless of which type of drag is in progress.
168 HandleCaptureLost(event); 190 HandleCaptureLost(event);
(...skipping 18 matching lines...) Expand all
187 break; 209 break;
188 case ui::ET_MOUSE_EXITED: 210 case ui::ET_MOUSE_EXITED:
189 HandleMouseExited(target, event); 211 HandleMouseExited(target, event);
190 break; 212 break;
191 default: 213 default:
192 break; 214 break;
193 } 215 }
194 } 216 }
195 217
196 void WmToplevelWindowEventHandler::OnGestureEvent(ui::GestureEvent* event, 218 void WmToplevelWindowEventHandler::OnGestureEvent(ui::GestureEvent* event,
197 WmWindow* target) { 219 aura::Window* target) {
198 if (event->handled()) 220 if (event->handled())
199 return; 221 return;
200 if (!target->HasNonClientArea()) 222 if (!target->delegate())
201 return; 223 return;
202 224
203 if (window_resizer_.get() && !in_gesture_drag_) 225 if (window_resizer_.get() && !in_gesture_drag_)
204 return; 226 return;
205 227
206 if (window_resizer_.get() && 228 if (window_resizer_.get() &&
207 window_resizer_->resizer()->GetTarget() != target->aura_window()) { 229 window_resizer_->resizer()->GetTarget() != target) {
208 return; 230 return;
209 } 231 }
210 232
211 if (event->details().touch_points() > 2) { 233 if (event->details().touch_points() > 2) {
212 if (CompleteDrag(DragResult::SUCCESS)) 234 if (CompleteDrag(DragResult::SUCCESS))
213 event->StopPropagation(); 235 event->StopPropagation();
214 return; 236 return;
215 } 237 }
216 238
217 switch (event->type()) { 239 switch (event->type()) {
218 case ui::ET_GESTURE_TAP_DOWN: { 240 case ui::ET_GESTURE_TAP_DOWN: {
219 int component = GetWindowComponent(target, *event); 241 int component = GetNonClientComponent(target, event->location());
220 if (!(WindowResizer::GetBoundsChangeForWindowComponent(component) & 242 if (!(WindowResizer::GetBoundsChangeForWindowComponent(component) &
221 WindowResizer::kBoundsChange_Resizes)) 243 WindowResizer::kBoundsChange_Resizes))
222 return; 244 return;
223 target->ShowResizeShadow(component); 245 ShowResizeShadow(target, component);
224 return; 246 return;
225 } 247 }
226 case ui::ET_GESTURE_END: { 248 case ui::ET_GESTURE_END: {
227 target->HideResizeShadow(); 249 HideResizeShadow(target);
228 250
229 if (window_resizer_.get() && 251 if (window_resizer_.get() &&
230 (event->details().touch_points() == 1 || 252 (event->details().touch_points() == 1 ||
231 !CanStartOneFingerDrag(first_finger_hittest_))) { 253 !CanStartOneFingerDrag(first_finger_hittest_))) {
232 CompleteDrag(DragResult::SUCCESS); 254 CompleteDrag(DragResult::SUCCESS);
233 event->StopPropagation(); 255 event->StopPropagation();
234 } 256 }
235 return; 257 return;
236 } 258 }
237 case ui::ET_GESTURE_BEGIN: { 259 case ui::ET_GESTURE_BEGIN: {
238 if (event->details().touch_points() == 1) { 260 if (event->details().touch_points() == 1) {
239 first_finger_hittest_ = GetWindowComponent(target, *event); 261 first_finger_hittest_ =
262 GetNonClientComponent(target, event->location());
240 } else if (window_resizer_.get()) { 263 } else if (window_resizer_.get()) {
241 if (!window_resizer_->IsMove()) { 264 if (!window_resizer_->IsMove()) {
242 // The transition from resizing with one finger to resizing with two 265 // The transition from resizing with one finger to resizing with two
243 // fingers causes unintended resizing because the location of 266 // fingers causes unintended resizing because the location of
244 // ET_GESTURE_SCROLL_UPDATE jumps from the position of the first 267 // ET_GESTURE_SCROLL_UPDATE jumps from the position of the first
245 // finger to the position in the middle of the two fingers. For this 268 // finger to the position in the middle of the two fingers. For this
246 // reason two finger resizing is not supported. 269 // reason two finger resizing is not supported.
247 CompleteDrag(DragResult::SUCCESS); 270 CompleteDrag(DragResult::SUCCESS);
248 event->StopPropagation(); 271 event->StopPropagation();
249 } 272 }
250 } else { 273 } else {
251 int second_finger_hittest = GetWindowComponent(target, *event); 274 int second_finger_hittest =
275 GetNonClientComponent(target, event->location());
252 if (CanStartTwoFingerMove(target, first_finger_hittest_, 276 if (CanStartTwoFingerMove(target, first_finger_hittest_,
253 second_finger_hittest)) { 277 second_finger_hittest)) {
254 gfx::Point location_in_parent = 278 gfx::Point location_in_parent =
255 event->details().bounding_box().CenterPoint(); 279 event->details().bounding_box().CenterPoint();
256 AttemptToStartDrag(target, location_in_parent, HTCAPTION, 280 AttemptToStartDrag(target, location_in_parent, HTCAPTION,
257 aura::client::WINDOW_MOVE_SOURCE_TOUCH, 281 aura::client::WINDOW_MOVE_SOURCE_TOUCH,
258 EndClosure()); 282 EndClosure());
259 event->StopPropagation(); 283 event->StopPropagation();
260 } 284 }
261 } 285 }
262 return; 286 return;
263 } 287 }
264 case ui::ET_GESTURE_SCROLL_BEGIN: { 288 case ui::ET_GESTURE_SCROLL_BEGIN: {
265 // The one finger drag is not started in ET_GESTURE_BEGIN to avoid the 289 // The one finger drag is not started in ET_GESTURE_BEGIN to avoid the
266 // window jumping upon initiating a two finger drag. When a one finger 290 // window jumping upon initiating a two finger drag. When a one finger
267 // drag is converted to a two finger drag, a jump occurs because the 291 // drag is converted to a two finger drag, a jump occurs because the
268 // location of the ET_GESTURE_SCROLL_UPDATE event switches from the single 292 // location of the ET_GESTURE_SCROLL_UPDATE event switches from the single
269 // finger's position to the position in the middle of the two fingers. 293 // finger's position to the position in the middle of the two fingers.
270 if (window_resizer_.get()) 294 if (window_resizer_.get())
271 return; 295 return;
272 int component = GetWindowComponent(target, *event); 296 int component = GetNonClientComponent(target, event->location());
273 if (!CanStartOneFingerDrag(component)) 297 if (!CanStartOneFingerDrag(component))
274 return; 298 return;
275 gfx::Point location_in_parent( 299 gfx::Point location_in_parent = event->location();
276 target->ConvertPointToTarget(target->GetParent(), event->location())); 300 aura::Window::ConvertPointToTarget(target, target->parent(),
301 &location_in_parent);
277 AttemptToStartDrag(target, location_in_parent, component, 302 AttemptToStartDrag(target, location_in_parent, component,
278 aura::client::WINDOW_MOVE_SOURCE_TOUCH, EndClosure()); 303 aura::client::WINDOW_MOVE_SOURCE_TOUCH, EndClosure());
279 event->StopPropagation(); 304 event->StopPropagation();
280 return; 305 return;
281 } 306 }
282 default: 307 default:
283 break; 308 break;
284 } 309 }
285 310
286 if (!window_resizer_.get()) 311 if (!window_resizer_.get())
(...skipping 12 matching lines...) Expand all
299 // WindowMoveClient::EndMoveLoop(). 324 // WindowMoveClient::EndMoveLoop().
300 CompleteDrag(DragResult::SUCCESS); 325 CompleteDrag(DragResult::SUCCESS);
301 event->StopPropagation(); 326 event->StopPropagation();
302 return; 327 return;
303 case ui::ET_SCROLL_FLING_START: 328 case ui::ET_SCROLL_FLING_START:
304 CompleteDrag(DragResult::SUCCESS); 329 CompleteDrag(DragResult::SUCCESS);
305 330
306 // TODO(pkotwicz): Fix tests which inadvertantly start flings and check 331 // TODO(pkotwicz): Fix tests which inadvertantly start flings and check
307 // window_resizer_->IsMove() instead of the hittest component at |event|'s 332 // window_resizer_->IsMove() instead of the hittest component at |event|'s
308 // location. 333 // location.
309 if (GetWindowComponent(target, *event) != HTCAPTION || 334 if (GetNonClientComponent(target, event->location()) != HTCAPTION ||
310 !target->GetWindowState()->IsNormalOrSnapped()) { 335 !GetWindowState(target)->IsNormalOrSnapped()) {
311 return; 336 return;
312 } 337 }
313 338
314 if (event->details().velocity_y() > kMinVertVelocityForWindowMinimize) { 339 if (event->details().velocity_y() > kMinVertVelocityForWindowMinimize) {
315 SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MINIMIZED); 340 SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MINIMIZED);
316 } else if (event->details().velocity_y() < 341 } else if (event->details().velocity_y() <
317 -kMinVertVelocityForWindowMinimize) { 342 -kMinVertVelocityForWindowMinimize) {
318 SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MAXIMIZED); 343 SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MAXIMIZED);
319 } else if (event->details().velocity_x() > 344 } else if (event->details().velocity_x() >
320 kMinHorizVelocityForWindowSwipe) { 345 kMinHorizVelocityForWindowSwipe) {
321 SetWindowStateTypeFromGesture(target, 346 SetWindowStateTypeFromGesture(target,
322 wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); 347 wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED);
323 } else if (event->details().velocity_x() < 348 } else if (event->details().velocity_x() <
324 -kMinHorizVelocityForWindowSwipe) { 349 -kMinHorizVelocityForWindowSwipe) {
325 SetWindowStateTypeFromGesture(target, 350 SetWindowStateTypeFromGesture(target,
326 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED); 351 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED);
327 } 352 }
328 event->StopPropagation(); 353 event->StopPropagation();
329 return; 354 return;
330 case ui::ET_GESTURE_SWIPE: 355 case ui::ET_GESTURE_SWIPE:
331 DCHECK_GT(event->details().touch_points(), 0); 356 DCHECK_GT(event->details().touch_points(), 0);
332 if (event->details().touch_points() == 1) 357 if (event->details().touch_points() == 1)
333 return; 358 return;
334 if (!target->GetWindowState()->IsNormalOrSnapped()) 359 if (!GetWindowState(target)->IsNormalOrSnapped())
335 return; 360 return;
336 361
337 CompleteDrag(DragResult::SUCCESS); 362 CompleteDrag(DragResult::SUCCESS);
338 363
339 if (event->details().swipe_down()) { 364 if (event->details().swipe_down()) {
340 SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MINIMIZED); 365 SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MINIMIZED);
341 } else if (event->details().swipe_up()) { 366 } else if (event->details().swipe_up()) {
342 SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MAXIMIZED); 367 SetWindowStateTypeFromGesture(target, wm::WINDOW_STATE_TYPE_MAXIMIZED);
343 } else if (event->details().swipe_right()) { 368 } else if (event->details().swipe_right()) {
344 SetWindowStateTypeFromGesture(target, 369 SetWindowStateTypeFromGesture(target,
345 wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); 370 wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED);
346 } else { 371 } else {
347 SetWindowStateTypeFromGesture(target, 372 SetWindowStateTypeFromGesture(target,
348 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED); 373 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED);
349 } 374 }
350 event->StopPropagation(); 375 event->StopPropagation();
351 return; 376 return;
352 default: 377 default:
353 return; 378 return;
354 } 379 }
355 } 380 }
356 381
357 bool WmToplevelWindowEventHandler::AttemptToStartDrag( 382 bool WmToplevelWindowEventHandler::AttemptToStartDrag(
358 WmWindow* window, 383 aura::Window* window,
359 const gfx::Point& point_in_parent, 384 const gfx::Point& point_in_parent,
360 int window_component, 385 int window_component,
361 aura::client::WindowMoveSource source, 386 aura::client::WindowMoveSource source,
362 const EndClosure& end_closure) { 387 const EndClosure& end_closure) {
363 if (window_resizer_.get()) 388 if (window_resizer_.get())
364 return false; 389 return false;
365 std::unique_ptr<WindowResizer> resizer(CreateWindowResizer( 390 std::unique_ptr<WindowResizer> resizer(
366 window->aura_window(), point_in_parent, window_component, source)); 391 CreateWindowResizer(window, point_in_parent, window_component, source));
367 if (!resizer) 392 if (!resizer)
368 return false; 393 return false;
369 394
370 end_closure_ = end_closure; 395 end_closure_ = end_closure;
371 window_resizer_.reset(new ScopedWindowResizer(this, std::move(resizer))); 396 window_resizer_.reset(new ScopedWindowResizer(this, std::move(resizer)));
372 397
373 pre_drag_window_bounds_ = window->GetBounds(); 398 pre_drag_window_bounds_ = window->bounds();
374 in_gesture_drag_ = (source == aura::client::WINDOW_MOVE_SOURCE_TOUCH); 399 in_gesture_drag_ = (source == aura::client::WINDOW_MOVE_SOURCE_TOUCH);
375 return true; 400 return true;
376 } 401 }
377 402
378 void WmToplevelWindowEventHandler::RevertDrag() { 403 void WmToplevelWindowEventHandler::RevertDrag() {
379 CompleteDrag(DragResult::REVERT); 404 CompleteDrag(DragResult::REVERT);
380 } 405 }
381 406
382 bool WmToplevelWindowEventHandler::CompleteDrag(DragResult result) { 407 bool WmToplevelWindowEventHandler::CompleteDrag(DragResult result) {
383 if (!window_resizer_) 408 if (!window_resizer_)
(...skipping 17 matching lines...) Expand all
401 in_gesture_drag_ = false; 426 in_gesture_drag_ = false;
402 if (!end_closure_.is_null()) { 427 if (!end_closure_.is_null()) {
403 // Clear local state in case running the closure deletes us. 428 // Clear local state in case running the closure deletes us.
404 EndClosure end_closure = end_closure_; 429 EndClosure end_closure = end_closure_;
405 end_closure_.Reset(); 430 end_closure_.Reset();
406 end_closure.Run(result); 431 end_closure.Run(result);
407 } 432 }
408 return true; 433 return true;
409 } 434 }
410 435
411 void WmToplevelWindowEventHandler::HandleMousePressed(WmWindow* target, 436 void WmToplevelWindowEventHandler::HandleMousePressed(aura::Window* target,
412 ui::MouseEvent* event) { 437 ui::MouseEvent* event) {
413 if (event->phase() != ui::EP_PRETARGET || !target->HasNonClientArea()) 438 if (event->phase() != ui::EP_PRETARGET || !target->delegate())
414 return; 439 return;
415 440
416 // We also update the current window component here because for the 441 // We also update the current window component here because for the
417 // mouse-drag-release-press case, where the mouse is released and 442 // mouse-drag-release-press case, where the mouse is released and
418 // pressed without mouse move event. 443 // pressed without mouse move event.
419 int component = GetWindowComponent(target, *event); 444 int component = GetNonClientComponent(target, event->location());
420 if ((event->flags() & (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 445 if ((event->flags() & (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) ==
421 0 && 446 0 &&
422 WindowResizer::GetBoundsChangeForWindowComponent(component)) { 447 WindowResizer::GetBoundsChangeForWindowComponent(component)) {
423 gfx::Point location_in_parent( 448 gfx::Point location_in_parent = event->location();
424 target->ConvertPointToTarget(target->GetParent(), event->location())); 449 aura::Window::ConvertPointToTarget(target, target->parent(),
450 &location_in_parent);
425 AttemptToStartDrag(target, location_in_parent, component, 451 AttemptToStartDrag(target, location_in_parent, component,
426 aura::client::WINDOW_MOVE_SOURCE_MOUSE, EndClosure()); 452 aura::client::WINDOW_MOVE_SOURCE_MOUSE, EndClosure());
427 // Set as handled so that other event handlers do no act upon the event 453 // Set as handled so that other event handlers do no act upon the event
428 // but still receive it so that they receive both parts of each pressed/ 454 // but still receive it so that they receive both parts of each pressed/
429 // released pair. 455 // released pair.
430 event->SetHandled(); 456 event->SetHandled();
431 } else { 457 } else {
432 CompleteDrag(DragResult::SUCCESS); 458 CompleteDrag(DragResult::SUCCESS);
433 } 459 }
434 } 460 }
435 461
436 void WmToplevelWindowEventHandler::HandleMouseReleased(WmWindow* target, 462 void WmToplevelWindowEventHandler::HandleMouseReleased(aura::Window* target,
437 ui::MouseEvent* event) { 463 ui::MouseEvent* event) {
438 if (event->phase() == ui::EP_PRETARGET) 464 if (event->phase() == ui::EP_PRETARGET)
439 CompleteDrag(DragResult::SUCCESS); 465 CompleteDrag(DragResult::SUCCESS);
440 } 466 }
441 467
442 void WmToplevelWindowEventHandler::HandleDrag(WmWindow* target, 468 void WmToplevelWindowEventHandler::HandleDrag(aura::Window* target,
443 ui::LocatedEvent* event) { 469 ui::LocatedEvent* event) {
444 // This function only be triggered to move window 470 // This function only be triggered to move window
445 // by mouse drag or touch move event. 471 // by mouse drag or touch move event.
446 DCHECK(event->type() == ui::ET_MOUSE_DRAGGED || 472 DCHECK(event->type() == ui::ET_MOUSE_DRAGGED ||
447 event->type() == ui::ET_TOUCH_MOVED || 473 event->type() == ui::ET_TOUCH_MOVED ||
448 event->type() == ui::ET_GESTURE_SCROLL_UPDATE); 474 event->type() == ui::ET_GESTURE_SCROLL_UPDATE);
449 475
450 // Drag actions are performed pre-target handling to prevent spurious mouse 476 // Drag actions are performed pre-target handling to prevent spurious mouse
451 // moves from the move/size operation from being sent to the target. 477 // moves from the move/size operation from being sent to the target.
452 if (event->phase() != ui::EP_PRETARGET) 478 if (event->phase() != ui::EP_PRETARGET)
453 return; 479 return;
454 480
455 if (!window_resizer_) 481 if (!window_resizer_)
456 return; 482 return;
457 window_resizer_->resizer()->Drag( 483 gfx::Point location_in_parent = event->location();
458 target->ConvertPointToTarget(target->GetParent(), event->location()), 484 aura::Window::ConvertPointToTarget(target, target->parent(),
459 event->flags()); 485 &location_in_parent);
486 window_resizer_->resizer()->Drag(location_in_parent, event->flags());
460 event->StopPropagation(); 487 event->StopPropagation();
461 } 488 }
462 489
463 void WmToplevelWindowEventHandler::HandleMouseMoved(WmWindow* target, 490 void WmToplevelWindowEventHandler::HandleMouseMoved(aura::Window* target,
464 ui::LocatedEvent* event) { 491 ui::LocatedEvent* event) {
465 // Shadow effects are applied after target handling. Note that we don't 492 // Shadow effects are applied after target handling. Note that we don't
466 // respect ER_HANDLED here right now since we have not had a reason to allow 493 // respect ER_HANDLED here right now since we have not had a reason to allow
467 // the target to cancel shadow rendering. 494 // the target to cancel shadow rendering.
468 if (event->phase() != ui::EP_POSTTARGET || !target->HasNonClientArea()) 495 if (event->phase() != ui::EP_POSTTARGET || !target->delegate())
469 return; 496 return;
470 497
471 // TODO(jamescook): Move the resize cursor update code into here from 498 // TODO(jamescook): Move the resize cursor update code into here from
472 // CompoundEventFilter? 499 // CompoundEventFilter?
473 if (event->flags() & ui::EF_IS_NON_CLIENT) { 500 if (event->flags() & ui::EF_IS_NON_CLIENT) {
474 int component = target->GetNonClientComponent(event->location()); 501 int component = GetNonClientComponent(target, event->location());
475 target->ShowResizeShadow(component); 502 ShowResizeShadow(target, component);
476 } else { 503 } else {
477 target->HideResizeShadow(); 504 HideResizeShadow(target);
478 } 505 }
479 } 506 }
480 507
481 void WmToplevelWindowEventHandler::HandleMouseExited(WmWindow* target, 508 void WmToplevelWindowEventHandler::HandleMouseExited(aura::Window* target,
482 ui::LocatedEvent* event) { 509 ui::LocatedEvent* event) {
483 // Shadow effects are applied after target handling. Note that we don't 510 // Shadow effects are applied after target handling. Note that we don't
484 // respect ER_HANDLED here right now since we have not had a reason to allow 511 // respect ER_HANDLED here right now since we have not had a reason to allow
485 // the target to cancel shadow rendering. 512 // the target to cancel shadow rendering.
486 if (event->phase() != ui::EP_POSTTARGET) 513 if (event->phase() != ui::EP_POSTTARGET)
487 return; 514 return;
488 515
489 target->HideResizeShadow(); 516 HideResizeShadow(target);
490 } 517 }
491 518
492 void WmToplevelWindowEventHandler::HandleCaptureLost(ui::LocatedEvent* event) { 519 void WmToplevelWindowEventHandler::HandleCaptureLost(ui::LocatedEvent* event) {
493 if (event->phase() == ui::EP_PRETARGET) { 520 if (event->phase() == ui::EP_PRETARGET) {
494 // We complete the drag instead of reverting it, as reverting it will result 521 // We complete the drag instead of reverting it, as reverting it will result
495 // in a weird behavior when a dragged tab produces a modal dialog while the 522 // in a weird behavior when a dragged tab produces a modal dialog while the
496 // drag is in progress. crbug.com/558201. 523 // drag is in progress. crbug.com/558201.
497 CompleteDrag(DragResult::SUCCESS); 524 CompleteDrag(DragResult::SUCCESS);
498 } 525 }
499 } 526 }
500 527
501 void WmToplevelWindowEventHandler::SetWindowStateTypeFromGesture( 528 void WmToplevelWindowEventHandler::SetWindowStateTypeFromGesture(
502 WmWindow* window, 529 aura::Window* window,
503 wm::WindowStateType new_state_type) { 530 wm::WindowStateType new_state_type) {
504 wm::WindowState* window_state = window->GetWindowState(); 531 wm::WindowState* window_state = GetWindowState(window);
varkha 2017/05/25 19:11:52 nit: Do you need wm:: (here and elsewhere in this
505 // TODO(oshima): Move extra logic (set_unminimize_to_restore_bounds, 532 // TODO(oshima): Move extra logic (set_unminimize_to_restore_bounds,
506 // SetRestoreBoundsInParent) that modifies the window state 533 // SetRestoreBoundsInParent) that modifies the window state
507 // into WindowState. 534 // into WindowState.
508 switch (new_state_type) { 535 switch (new_state_type) {
509 case wm::WINDOW_STATE_TYPE_MINIMIZED: 536 case wm::WINDOW_STATE_TYPE_MINIMIZED:
510 if (window_state->CanMinimize()) { 537 if (window_state->CanMinimize()) {
511 window_state->Minimize(); 538 window_state->Minimize();
512 window_state->set_unminimize_to_restore_bounds(true); 539 window_state->set_unminimize_to_restore_bounds(true);
513 window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_); 540 window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_);
514 } 541 }
(...skipping 26 matching lines...) Expand all
541 void WmToplevelWindowEventHandler::ResizerWindowDestroyed() { 568 void WmToplevelWindowEventHandler::ResizerWindowDestroyed() {
542 CompleteDrag(DragResult::WINDOW_DESTROYED); 569 CompleteDrag(DragResult::WINDOW_DESTROYED);
543 } 570 }
544 571
545 void WmToplevelWindowEventHandler::OnDisplayConfigurationChanging() { 572 void WmToplevelWindowEventHandler::OnDisplayConfigurationChanging() {
546 CompleteDrag(DragResult::REVERT); 573 CompleteDrag(DragResult::REVERT);
547 } 574 }
548 575
549 } // namespace wm 576 } // namespace wm
550 } // namespace ash 577 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698