Chromium Code Reviews| 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/toplevel_window_event_handler.h" | 5 #include "ash/wm/toplevel_window_event_handler.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/wm/resize_shadow_controller.h" | 8 #include "ash/wm/resize_shadow_controller.h" |
| 9 #include "ash/wm/window_resizer.h" | 9 #include "ash/wm/window_resizer.h" |
| 10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 | 212 |
| 213 if (window_resizer_.get() && !in_gesture_drag_) | 213 if (window_resizer_.get() && !in_gesture_drag_) |
| 214 return; | 214 return; |
| 215 | 215 |
| 216 if (window_resizer_.get() && | 216 if (window_resizer_.get() && |
| 217 window_resizer_->resizer()->GetTarget() != target) { | 217 window_resizer_->resizer()->GetTarget() != target) { |
| 218 return; | 218 return; |
| 219 } | 219 } |
| 220 | 220 |
| 221 if (event->details().touch_points() > 2) { | 221 if (event->details().touch_points() > 2) { |
| 222 if (window_resizer_.get()) { | 222 if (CompleteDrag(DRAG_COMPLETE)) |
| 223 CompleteDrag(DRAG_COMPLETE); | |
| 224 event->StopPropagation(); | 223 event->StopPropagation(); |
| 225 } | |
| 226 return; | 224 return; |
| 227 } | 225 } |
| 228 | 226 |
| 229 switch (event->type()) { | 227 switch (event->type()) { |
| 230 case ui::ET_GESTURE_TAP_DOWN: { | 228 case ui::ET_GESTURE_TAP_DOWN: { |
| 231 int component = GetWindowComponent(target, *event); | 229 int component = GetWindowComponent(target, *event); |
| 232 if (!(WindowResizer::GetBoundsChangeForWindowComponent(component) & | 230 if (!(WindowResizer::GetBoundsChangeForWindowComponent(component) & |
| 233 WindowResizer::kBoundsChange_Resizes)) | 231 WindowResizer::kBoundsChange_Resizes)) |
| 234 return; | 232 return; |
| 235 ResizeShadowController* controller = | 233 ResizeShadowController* controller = |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 if (!resizer) | 437 if (!resizer) |
| 440 return false; | 438 return false; |
| 441 | 439 |
| 442 window_resizer_.reset(new ScopedWindowResizer(this, resizer)); | 440 window_resizer_.reset(new ScopedWindowResizer(this, resizer)); |
| 443 | 441 |
| 444 pre_drag_window_bounds_ = window->bounds(); | 442 pre_drag_window_bounds_ = window->bounds(); |
| 445 in_gesture_drag_ = (source == aura::client::WINDOW_MOVE_SOURCE_TOUCH); | 443 in_gesture_drag_ = (source == aura::client::WINDOW_MOVE_SOURCE_TOUCH); |
| 446 return true; | 444 return true; |
| 447 } | 445 } |
| 448 | 446 |
| 449 void ToplevelWindowEventHandler::CompleteDrag(DragCompletionStatus status) { | 447 bool ToplevelWindowEventHandler::CompleteDrag(DragCompletionStatus status) { |
| 448 if (!window_resizer_) | |
| 449 return false; | |
| 450 | |
| 450 scoped_ptr<ScopedWindowResizer> resizer(window_resizer_.release()); | 451 scoped_ptr<ScopedWindowResizer> resizer(window_resizer_.release()); |
| 451 if (resizer) { | 452 switch (status) { |
| 452 if (status == DRAG_COMPLETE) | 453 case DRAG_COMPLETE: |
| 453 resizer->resizer()->CompleteDrag(); | 454 resizer->resizer()->CompleteDrag(); |
| 454 else | 455 break; |
| 456 case DRAG_REVERT: | |
| 455 resizer->resizer()->RevertDrag(); | 457 resizer->resizer()->RevertDrag(); |
| 458 break; | |
| 459 case DRAG_RESIZER_WINDOW_DESTROYED: | |
| 460 // We explicitly do not invoke RevertDrag() since that may do things to | |
| 461 // WindowResizer::GetTarget() which was destroyed. | |
| 462 break; | |
| 456 } | 463 } |
| 457 drag_reverted_ = (status == DRAG_REVERT); | 464 drag_reverted_ = (status == DRAG_REVERT); |
| 458 | 465 |
| 459 first_finger_hittest_ = HTNOWHERE; | 466 first_finger_hittest_ = HTNOWHERE; |
| 460 in_gesture_drag_ = false; | 467 in_gesture_drag_ = false; |
| 461 if (in_move_loop_) | 468 if (in_move_loop_) |
| 462 quit_closure_.Run(); | 469 quit_closure_.Run(); |
| 470 return true; | |
| 463 } | 471 } |
| 464 | 472 |
| 465 void ToplevelWindowEventHandler::HandleMousePressed( | 473 void ToplevelWindowEventHandler::HandleMousePressed( |
| 466 aura::Window* target, | 474 aura::Window* target, |
| 467 ui::MouseEvent* event) { | 475 ui::MouseEvent* event) { |
| 468 if (event->phase() != ui::EP_PRETARGET || !target->delegate()) | 476 if (event->phase() != ui::EP_PRETARGET || !target->delegate()) |
| 469 return; | 477 return; |
| 470 | 478 |
| 471 // We also update the current window component here because for the | 479 // We also update the current window component here because for the |
| 472 // mouse-drag-release-press case, where the mouse is released and | 480 // mouse-drag-release-press case, where the mouse is released and |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 487 CompleteDrag(DRAG_COMPLETE); | 495 CompleteDrag(DRAG_COMPLETE); |
| 488 } | 496 } |
| 489 } | 497 } |
| 490 | 498 |
| 491 void ToplevelWindowEventHandler::HandleMouseReleased( | 499 void ToplevelWindowEventHandler::HandleMouseReleased( |
| 492 aura::Window* target, | 500 aura::Window* target, |
| 493 ui::MouseEvent* event) { | 501 ui::MouseEvent* event) { |
| 494 if (event->phase() != ui::EP_PRETARGET) | 502 if (event->phase() != ui::EP_PRETARGET) |
| 495 return; | 503 return; |
| 496 | 504 |
| 497 if (window_resizer_) { | 505 CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ? |
| 498 CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ? | 506 DRAG_COMPLETE : DRAG_REVERT); |
| 499 DRAG_COMPLETE : DRAG_REVERT); | |
| 500 } | |
| 501 | |
| 502 // Completing the drag may result in hiding the window. If this happens | |
| 503 // mark the event as handled so no other handlers/observers act upon the | |
| 504 // event. They should see the event on a hidden window, to determine targets | |
| 505 // of destructive actions such as hiding. They should not act upon them. | |
| 506 if (window_resizer_ && | |
| 507 event->type() == ui::ET_MOUSE_CAPTURE_CHANGED && | |
| 508 !target->IsVisible()) { | |
| 509 event->SetHandled(); | |
|
sky
2014/07/09 20:27:02
Why is marking the event has handled no longer nec
pkotwicz
2014/07/10 00:23:52
I couldn't find a case where not handling ui::ET_M
| |
| 510 } | |
| 511 } | 507 } |
| 512 | 508 |
| 513 void ToplevelWindowEventHandler::HandleDrag( | 509 void ToplevelWindowEventHandler::HandleDrag( |
| 514 aura::Window* target, | 510 aura::Window* target, |
| 515 ui::LocatedEvent* event) { | 511 ui::LocatedEvent* event) { |
| 516 // This function only be triggered to move window | 512 // This function only be triggered to move window |
| 517 // by mouse drag or touch move event. | 513 // by mouse drag or touch move event. |
| 518 DCHECK(event->type() == ui::ET_MOUSE_DRAGGED || | 514 DCHECK(event->type() == ui::ET_MOUSE_DRAGGED || |
| 519 event->type() == ui::ET_TOUCH_MOVED || | 515 event->type() == ui::ET_TOUCH_MOVED || |
| 520 event->type() == ui::ET_GESTURE_SCROLL_UPDATE); | 516 event->type() == ui::ET_GESTURE_SCROLL_UPDATE); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 const wm::WMEvent event(wm::WM_EVENT_SNAP_RIGHT); | 600 const wm::WMEvent event(wm::WM_EVENT_SNAP_RIGHT); |
| 605 window_state->OnWMEvent(&event); | 601 window_state->OnWMEvent(&event); |
| 606 } | 602 } |
| 607 break; | 603 break; |
| 608 default: | 604 default: |
| 609 NOTREACHED(); | 605 NOTREACHED(); |
| 610 } | 606 } |
| 611 } | 607 } |
| 612 | 608 |
| 613 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { | 609 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { |
| 614 // We explicitly don't invoke RevertDrag() since that may do things to window. | 610 CompleteDrag(DRAG_RESIZER_WINDOW_DESTROYED); |
| 615 // Instead we destroy the resizer. | |
| 616 window_resizer_.reset(); | |
| 617 | |
| 618 CompleteDrag(DRAG_REVERT); | |
| 619 } | 611 } |
| 620 | 612 |
| 621 } // namespace ash | 613 } // namespace ash |
| OLD | NEW |