| 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/property_util.h" | 8 #include "ash/wm/property_util.h" |
| 9 #include "ash/wm/resize_shadow_controller.h" | 9 #include "ash/wm/resize_shadow_controller.h" |
| 10 #include "ash/wm/window_resizer.h" | 10 #include "ash/wm/window_resizer.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 *destroyed_ = true; | 123 *destroyed_ = true; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { | 126 void ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { |
| 127 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED && | 127 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED && |
| 128 event->key_code() == ui::VKEY_ESCAPE) { | 128 event->key_code() == ui::VKEY_ESCAPE) { |
| 129 CompleteDrag(DRAG_REVERT, event->flags()); | 129 CompleteDrag(DRAG_REVERT, event->flags()); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 ui::EventResult ToplevelWindowEventHandler::OnMouseEvent( | 133 void ToplevelWindowEventHandler::OnMouseEvent( |
| 134 ui::MouseEvent* event) { | 134 ui::MouseEvent* event) { |
| 135 if ((event->flags() & | 135 if ((event->flags() & |
| 136 (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)) != 0) | 136 (ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)) != 0) |
| 137 return ui::ER_UNHANDLED; | 137 return; |
| 138 | 138 |
| 139 aura::Window* target = static_cast<aura::Window*>(event->target()); | 139 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 140 switch (event->type()) { | 140 switch (event->type()) { |
| 141 case ui::ET_MOUSE_PRESSED: | 141 case ui::ET_MOUSE_PRESSED: |
| 142 return HandleMousePressed(target, event); | 142 HandleMousePressed(target, event); |
| 143 break; |
| 143 case ui::ET_MOUSE_DRAGGED: | 144 case ui::ET_MOUSE_DRAGGED: |
| 144 return HandleDrag(target, event) ? ui::ER_CONSUMED : ui::ER_UNHANDLED; | 145 HandleDrag(target, event); |
| 146 break; |
| 145 case ui::ET_MOUSE_CAPTURE_CHANGED: | 147 case ui::ET_MOUSE_CAPTURE_CHANGED: |
| 146 case ui::ET_MOUSE_RELEASED: | 148 case ui::ET_MOUSE_RELEASED: |
| 147 return HandleMouseReleased(target, event); | 149 HandleMouseReleased(target, event); |
| 150 break; |
| 148 case ui::ET_MOUSE_MOVED: | 151 case ui::ET_MOUSE_MOVED: |
| 149 return HandleMouseMoved(target, event); | 152 HandleMouseMoved(target, event); |
| 153 break; |
| 150 case ui::ET_MOUSE_EXITED: | 154 case ui::ET_MOUSE_EXITED: |
| 151 return HandleMouseExited(target, event); | 155 HandleMouseExited(target, event); |
| 156 break; |
| 152 default: | 157 default: |
| 153 break; | 158 break; |
| 154 } | 159 } |
| 155 return ui::ER_UNHANDLED; | |
| 156 } | 160 } |
| 157 | 161 |
| 158 void ToplevelWindowEventHandler::OnGestureEvent(ui::GestureEvent* event) { | 162 void ToplevelWindowEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
| 159 aura::Window* target = static_cast<aura::Window*>(event->target()); | 163 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 160 if (!target->delegate()) | 164 if (!target->delegate()) |
| 161 return; | 165 return; |
| 162 | 166 |
| 163 switch (event->type()) { | 167 switch (event->type()) { |
| 164 case ui::ET_GESTURE_SCROLL_BEGIN: { | 168 case ui::ET_GESTURE_SCROLL_BEGIN: { |
| 165 int component = | 169 int component = |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 int event_flags) { | 318 int event_flags) { |
| 315 scoped_ptr<ScopedWindowResizer> resizer(window_resizer_.release()); | 319 scoped_ptr<ScopedWindowResizer> resizer(window_resizer_.release()); |
| 316 if (resizer.get()) { | 320 if (resizer.get()) { |
| 317 if (status == DRAG_COMPLETE) | 321 if (status == DRAG_COMPLETE) |
| 318 resizer->resizer()->CompleteDrag(event_flags); | 322 resizer->resizer()->CompleteDrag(event_flags); |
| 319 else | 323 else |
| 320 resizer->resizer()->RevertDrag(); | 324 resizer->resizer()->RevertDrag(); |
| 321 } | 325 } |
| 322 } | 326 } |
| 323 | 327 |
| 324 ui::EventResult ToplevelWindowEventHandler::HandleMousePressed( | 328 void ToplevelWindowEventHandler::HandleMousePressed( |
| 325 aura::Window* target, | 329 aura::Window* target, |
| 326 ui::MouseEvent* event) { | 330 ui::MouseEvent* event) { |
| 327 // Move/size operations are initiated post-target handling to give the target | 331 // Move/size operations are initiated post-target handling to give the target |
| 328 // an opportunity to cancel this default behavior by returning ER_HANDLED. | 332 // an opportunity to cancel this default behavior by returning ER_HANDLED. |
| 329 if (ui::EventCanceledDefaultHandling(*event)) | 333 if (ui::EventCanceledDefaultHandling(*event)) |
| 330 return ui::ER_UNHANDLED; | 334 return; |
| 331 | 335 |
| 332 // We also update the current window component here because for the | 336 // We also update the current window component here because for the |
| 333 // mouse-drag-release-press case, where the mouse is released and | 337 // mouse-drag-release-press case, where the mouse is released and |
| 334 // pressed without mouse move event. | 338 // pressed without mouse move event. |
| 335 int component = | 339 int component = |
| 336 target->delegate()->GetNonClientComponent(event->location()); | 340 target->delegate()->GetNonClientComponent(event->location()); |
| 337 if ((event->flags() & | 341 if ((event->flags() & |
| 338 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 && | 342 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 && |
| 339 WindowResizer::GetBoundsChangeForWindowComponent(component)) { | 343 WindowResizer::GetBoundsChangeForWindowComponent(component)) { |
| 340 gfx::Point location_in_parent( | 344 gfx::Point location_in_parent( |
| 341 ConvertPointToParent(target, event->location())); | 345 ConvertPointToParent(target, event->location())); |
| 342 CreateScopedWindowResizer(target, location_in_parent, component); | 346 CreateScopedWindowResizer(target, location_in_parent, component); |
| 343 } else { | 347 } else { |
| 344 window_resizer_.reset(); | 348 window_resizer_.reset(); |
| 345 } | 349 } |
| 346 return WindowResizer::GetBoundsChangeForWindowComponent(component) != 0 ? | 350 if (WindowResizer::GetBoundsChangeForWindowComponent(component) != 0) |
| 347 ui::ER_CONSUMED : ui::ER_UNHANDLED; | 351 event->StopPropagation(); |
| 348 } | 352 } |
| 349 | 353 |
| 350 ui::EventResult ToplevelWindowEventHandler::HandleMouseReleased( | 354 void ToplevelWindowEventHandler::HandleMouseReleased( |
| 351 aura::Window* target, | 355 aura::Window* target, |
| 352 ui::MouseEvent* event) { | 356 ui::MouseEvent* event) { |
| 353 if (event->phase() != ui::EP_PRETARGET) | 357 if (event->phase() != ui::EP_PRETARGET) |
| 354 return ui::ER_UNHANDLED; | 358 return; |
| 355 | 359 |
| 356 CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ? | 360 CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ? |
| 357 DRAG_COMPLETE : DRAG_REVERT, | 361 DRAG_COMPLETE : DRAG_REVERT, |
| 358 event->flags()); | 362 event->flags()); |
| 359 if (in_move_loop_) { | 363 if (in_move_loop_) { |
| 360 quit_closure_.Run(); | 364 quit_closure_.Run(); |
| 361 in_move_loop_ = false; | 365 in_move_loop_ = false; |
| 362 } | 366 } |
| 363 // Completing the drag may result in hiding the window. If this happens | 367 // Completing the drag may result in hiding the window. If this happens |
| 364 // return true so no other handlers/observers see the event. Otherwise | 368 // return true so no other handlers/observers see the event. Otherwise |
| 365 // they see the event on a hidden window. | 369 // they see the event on a hidden window. |
| 366 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED && | 370 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED && |
| 367 !target->IsVisible()) { | 371 !target->IsVisible()) { |
| 368 return ui::ER_CONSUMED; | 372 event->StopPropagation(); |
| 369 } | 373 } |
| 370 return ui::ER_UNHANDLED; | |
| 371 } | 374 } |
| 372 | 375 |
| 373 ui::EventResult ToplevelWindowEventHandler::HandleDrag( | 376 void ToplevelWindowEventHandler::HandleDrag( |
| 374 aura::Window* target, | 377 aura::Window* target, |
| 375 ui::LocatedEvent* event) { | 378 ui::LocatedEvent* event) { |
| 376 // This function only be triggered to move window | 379 // This function only be triggered to move window |
| 377 // by mouse drag or touch move event. | 380 // by mouse drag or touch move event. |
| 378 DCHECK(event->type() == ui::ET_MOUSE_DRAGGED || | 381 DCHECK(event->type() == ui::ET_MOUSE_DRAGGED || |
| 379 event->type() == ui::ET_TOUCH_MOVED || | 382 event->type() == ui::ET_TOUCH_MOVED || |
| 380 event->type() == ui::ET_GESTURE_SCROLL_UPDATE); | 383 event->type() == ui::ET_GESTURE_SCROLL_UPDATE); |
| 381 | 384 |
| 382 // Drag actions are performed pre-target handling to prevent spurious mouse | 385 // Drag actions are performed pre-target handling to prevent spurious mouse |
| 383 // moves from the move/size operation from being sent to the target. | 386 // moves from the move/size operation from being sent to the target. |
| 384 if (event->phase() != ui::EP_PRETARGET) | 387 if (event->phase() != ui::EP_PRETARGET) |
| 385 return ui::ER_UNHANDLED; | 388 return; |
| 386 | 389 |
| 387 if (!window_resizer_.get()) | 390 if (!window_resizer_.get()) |
| 388 return ui::ER_UNHANDLED; | 391 return; |
| 389 window_resizer_->resizer()->Drag( | 392 window_resizer_->resizer()->Drag( |
| 390 ConvertPointToParent(target, event->location()), event->flags()); | 393 ConvertPointToParent(target, event->location()), event->flags()); |
| 391 return ui::ER_CONSUMED; | 394 event->StopPropagation(); |
| 392 } | 395 } |
| 393 | 396 |
| 394 ui::EventResult ToplevelWindowEventHandler::HandleMouseMoved( | 397 void ToplevelWindowEventHandler::HandleMouseMoved( |
| 395 aura::Window* target, | 398 aura::Window* target, |
| 396 ui::LocatedEvent* event) { | 399 ui::LocatedEvent* event) { |
| 397 // Shadow effects are applied after target handling. Note that we don't | 400 // Shadow effects are applied after target handling. Note that we don't |
| 398 // respect ER_HANDLED here right now since we have not had a reason to allow | 401 // respect ER_HANDLED here right now since we have not had a reason to allow |
| 399 // the target to cancel shadow rendering. | 402 // the target to cancel shadow rendering. |
| 400 if (event->phase() != ui::EP_POSTTARGET) | 403 if (event->phase() != ui::EP_POSTTARGET) |
| 401 return ui::ER_UNHANDLED; | 404 return; |
| 402 | 405 |
| 403 // TODO(jamescook): Move the resize cursor update code into here from | 406 // TODO(jamescook): Move the resize cursor update code into here from |
| 404 // CompoundEventFilter? | 407 // CompoundEventFilter? |
| 405 internal::ResizeShadowController* controller = | 408 internal::ResizeShadowController* controller = |
| 406 Shell::GetInstance()->resize_shadow_controller(); | 409 Shell::GetInstance()->resize_shadow_controller(); |
| 407 if (controller) { | 410 if (controller) { |
| 408 if (event->flags() & ui::EF_IS_NON_CLIENT) { | 411 if (event->flags() & ui::EF_IS_NON_CLIENT) { |
| 409 int component = | 412 int component = |
| 410 target->delegate()->GetNonClientComponent(event->location()); | 413 target->delegate()->GetNonClientComponent(event->location()); |
| 411 controller->ShowShadow(target, component); | 414 controller->ShowShadow(target, component); |
| 412 } else { | 415 } else { |
| 413 controller->HideShadow(target); | 416 controller->HideShadow(target); |
| 414 } | 417 } |
| 415 } | 418 } |
| 416 return ui::ER_UNHANDLED; | |
| 417 } | 419 } |
| 418 | 420 |
| 419 ui::EventResult ToplevelWindowEventHandler::HandleMouseExited( | 421 void ToplevelWindowEventHandler::HandleMouseExited( |
| 420 aura::Window* target, | 422 aura::Window* target, |
| 421 ui::LocatedEvent* event) { | 423 ui::LocatedEvent* event) { |
| 422 // Shadow effects are applied after target handling. Note that we don't | 424 // Shadow effects are applied after target handling. Note that we don't |
| 423 // respect ER_HANDLED here right now since we have not had a reason to allow | 425 // respect ER_HANDLED here right now since we have not had a reason to allow |
| 424 // the target to cancel shadow rendering. | 426 // the target to cancel shadow rendering. |
| 425 if (event->phase() != ui::EP_POSTTARGET) | 427 if (event->phase() != ui::EP_POSTTARGET) |
| 426 return ui::ER_UNHANDLED; | 428 return; |
| 427 | 429 |
| 428 internal::ResizeShadowController* controller = | 430 internal::ResizeShadowController* controller = |
| 429 Shell::GetInstance()->resize_shadow_controller(); | 431 Shell::GetInstance()->resize_shadow_controller(); |
| 430 if (controller) | 432 if (controller) |
| 431 controller->HideShadow(target); | 433 controller->HideShadow(target); |
| 432 return ui::ER_UNHANDLED; | |
| 433 } | 434 } |
| 434 | 435 |
| 435 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { | 436 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { |
| 436 // We explicitly don't invoke RevertDrag() since that may do things to window. | 437 // We explicitly don't invoke RevertDrag() since that may do things to window. |
| 437 // Instead we destroy the resizer. | 438 // Instead we destroy the resizer. |
| 438 window_resizer_.reset(); | 439 window_resizer_.reset(); |
| 439 | 440 |
| 440 // End the move loop. This does nothing if we're not in a move loop. | 441 // End the move loop. This does nothing if we're not in a move loop. |
| 441 EndMoveLoop(); | 442 EndMoveLoop(); |
| 442 } | 443 } |
| 443 | 444 |
| 444 } // namespace ash | 445 } // namespace ash |
| OLD | NEW |