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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 // WindowObserver overrides: | 65 // WindowObserver overrides: |
| 66 virtual void OnWindowHierarchyChanging( | 66 virtual void OnWindowHierarchyChanging( |
| 67 const HierarchyChangeParams& params) OVERRIDE; | 67 const HierarchyChangeParams& params) OVERRIDE; |
| 68 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; | 68 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
| 69 | 69 |
| 70 // WindowStateObserver overrides: | 70 // WindowStateObserver overrides: |
| 71 virtual void OnWindowShowTypeChanged(wm::WindowState* window_state, | 71 virtual void OnWindowShowTypeChanged(wm::WindowState* window_state, |
| 72 wm::WindowShowType type) OVERRIDE; | 72 wm::WindowShowType type) OVERRIDE; |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 void AddHandlers(aura::Window* container); | |
| 76 void RemoveHandlers(); | |
| 77 | |
| 78 ToplevelWindowEventHandler* handler_; | 75 ToplevelWindowEventHandler* handler_; |
| 79 scoped_ptr<WindowResizer> resizer_; | 76 scoped_ptr<WindowResizer> resizer_; |
| 80 | 77 |
| 81 // If not NULL, this is an additional container that the dragged window has | 78 // If not NULL, this is an additional container that the dragged window has |
| 82 // moved to which ScopedWindowResizer has temporarily added observers on. | 79 // moved to which ScopedWindowResizer has temporarily added observers on. |
| 83 aura::Window* target_container_; | 80 aura::Window* target_container_; |
| 84 | 81 |
| 85 DISALLOW_COPY_AND_ASSIGN(ScopedWindowResizer); | 82 DISALLOW_COPY_AND_ASSIGN(ScopedWindowResizer); |
| 86 }; | 83 }; |
| 87 | 84 |
| 88 ToplevelWindowEventHandler::ScopedWindowResizer::ScopedWindowResizer( | 85 ToplevelWindowEventHandler::ScopedWindowResizer::ScopedWindowResizer( |
| 89 ToplevelWindowEventHandler* handler, | 86 ToplevelWindowEventHandler* handler, |
| 90 WindowResizer* resizer) | 87 WindowResizer* resizer) |
| 91 : handler_(handler), | 88 : handler_(handler), |
| 92 resizer_(resizer), | 89 resizer_(resizer), |
| 93 target_container_(NULL) { | 90 target_container_(NULL) { |
| 94 if (resizer_) { | 91 if (resizer_) { |
| 95 resizer_->GetTarget()->AddObserver(this); | 92 resizer_->GetTarget()->AddObserver(this); |
| 96 wm::GetWindowState(resizer_->GetTarget())->AddObserver(this); | 93 wm::GetWindowState(resizer_->GetTarget())->AddObserver(this); |
| 97 } | 94 } |
| 98 } | 95 } |
| 99 | 96 |
| 100 ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() { | 97 ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() { |
| 101 RemoveHandlers(); | |
| 102 if (resizer_) { | 98 if (resizer_) { |
| 103 resizer_->GetTarget()->RemoveObserver(this); | 99 resizer_->GetTarget()->RemoveObserver(this); |
| 104 wm::GetWindowState(resizer_->GetTarget())->RemoveObserver(this); | 100 wm::GetWindowState(resizer_->GetTarget())->RemoveObserver(this); |
| 105 } | 101 } |
| 106 } | 102 } |
| 107 | 103 |
| 108 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowHierarchyChanging( | 104 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowHierarchyChanging( |
| 109 const HierarchyChangeParams& params) { | 105 const HierarchyChangeParams& params) { |
| 110 if (params.receiver != resizer_->GetTarget()) | 106 if (params.receiver != resizer_->GetTarget()) |
| 111 return; | 107 return; |
| 112 wm::WindowState* state = wm::GetWindowState(params.receiver); | 108 wm::WindowState* state = wm::GetWindowState(params.receiver); |
| 113 if (state->continue_drag_after_reparent()) { | 109 if (state->continue_drag_after_reparent()) |
| 114 state->set_continue_drag_after_reparent(false); | 110 state->set_continue_drag_after_reparent(false); |
| 115 AddHandlers(params.new_parent); | 111 else |
| 116 } else { | |
| 117 handler_->CompleteDrag(DRAG_COMPLETE, 0); | 112 handler_->CompleteDrag(DRAG_COMPLETE, 0); |
| 118 } | |
| 119 } | 113 } |
| 120 | 114 |
| 121 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowShowTypeChanged( | 115 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowShowTypeChanged( |
| 122 wm::WindowState* window_state, | 116 wm::WindowState* window_state, |
| 123 wm::WindowShowType old) { | 117 wm::WindowShowType old) { |
| 124 if (!window_state->IsNormalShowState()) | 118 if (!window_state->IsNormalShowState()) |
| 125 handler_->CompleteDrag(DRAG_COMPLETE, 0); | 119 handler_->CompleteDrag(DRAG_COMPLETE, 0); |
| 126 } | 120 } |
| 127 | 121 |
| 128 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( | 122 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( |
| 129 aura::Window* window) { | 123 aura::Window* window) { |
| 130 DCHECK(resizer_.get()); | 124 DCHECK(resizer_.get()); |
| 131 DCHECK_EQ(resizer_->GetTarget(), window); | 125 DCHECK_EQ(resizer_->GetTarget(), window); |
| 132 handler_->ResizerWindowDestroyed(); | 126 handler_->ResizerWindowDestroyed(); |
| 133 } | 127 } |
| 134 | 128 |
| 135 void ToplevelWindowEventHandler::ScopedWindowResizer::AddHandlers( | |
| 136 aura::Window* container) { | |
| 137 RemoveHandlers(); | |
| 138 if (!handler_->owner()->Contains(container)) { | |
| 139 container->AddPreTargetHandler(handler_); | |
| 140 container->AddPostTargetHandler(handler_); | |
| 141 target_container_ = container; | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 void ToplevelWindowEventHandler::ScopedWindowResizer::RemoveHandlers() { | |
| 146 if (target_container_) { | |
| 147 target_container_->RemovePreTargetHandler(handler_); | |
| 148 target_container_->RemovePostTargetHandler(handler_); | |
| 149 target_container_ = NULL; | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 | |
| 154 // ToplevelWindowEventHandler -------------------------------------------------- | 129 // ToplevelWindowEventHandler -------------------------------------------------- |
| 155 | 130 |
| 156 ToplevelWindowEventHandler::ToplevelWindowEventHandler(aura::Window* owner) | 131 ToplevelWindowEventHandler::ToplevelWindowEventHandler() |
| 157 : owner_(owner), | 132 : in_move_loop_(false), |
| 158 in_move_loop_(false), | |
| 159 move_cancelled_(false), | 133 move_cancelled_(false), |
| 160 in_gesture_drag_(false), | 134 in_gesture_drag_(false), |
| 161 destroyed_(NULL) { | 135 destroyed_(NULL) { |
| 162 aura::client::SetWindowMoveClient(owner, this); | |
| 163 Shell::GetInstance()->display_controller()->AddObserver(this); | 136 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 164 owner->AddPreTargetHandler(this); | |
| 165 owner->AddPostTargetHandler(this); | |
| 166 } | 137 } |
| 167 | 138 |
| 168 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { | 139 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { |
| 169 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 140 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 170 if (destroyed_) | 141 if (destroyed_) |
| 171 *destroyed_ = true; | 142 *destroyed_ = true; |
| 172 } | 143 } |
| 173 | 144 |
| 174 void ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { | 145 void ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { |
| 175 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED && | 146 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED && |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 // pressed without mouse move event. | 397 // pressed without mouse move event. |
| 427 int component = | 398 int component = |
| 428 target->delegate()->GetNonClientComponent(event->location()); | 399 target->delegate()->GetNonClientComponent(event->location()); |
| 429 if ((event->flags() & | 400 if ((event->flags() & |
| 430 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 && | 401 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 && |
| 431 WindowResizer::GetBoundsChangeForWindowComponent(component)) { | 402 WindowResizer::GetBoundsChangeForWindowComponent(component)) { |
| 432 gfx::Point location_in_parent( | 403 gfx::Point location_in_parent( |
| 433 ConvertPointToParent(target, event->location())); | 404 ConvertPointToParent(target, event->location())); |
| 434 CreateScopedWindowResizer(target, location_in_parent, component, | 405 CreateScopedWindowResizer(target, location_in_parent, component, |
| 435 aura::client::WINDOW_MOVE_SOURCE_MOUSE); | 406 aura::client::WINDOW_MOVE_SOURCE_MOUSE); |
| 407 event->StopPropagation(); | |
|
varkha
2013/12/13 04:05:14
Just a question. Previously the code was stopping
pkotwicz
2013/12/13 20:28:42
It should not because ToplevelWindowEventHandler a
| |
| 436 } else { | 408 } else { |
| 437 window_resizer_.reset(); | 409 window_resizer_.reset(); |
| 438 } | 410 } |
| 439 if (WindowResizer::GetBoundsChangeForWindowComponent(component) != 0) | |
| 440 event->StopPropagation(); | |
| 441 } | 411 } |
| 442 | 412 |
| 443 void ToplevelWindowEventHandler::HandleMouseReleased( | 413 void ToplevelWindowEventHandler::HandleMouseReleased( |
| 444 aura::Window* target, | 414 aura::Window* target, |
| 445 ui::MouseEvent* event) { | 415 ui::MouseEvent* event) { |
| 446 if (event->phase() != ui::EP_PRETARGET) | 416 if (event->phase() != ui::EP_PRETARGET) |
| 447 return; | 417 return; |
| 448 | 418 |
| 449 CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ? | 419 CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ? |
| 450 DRAG_COMPLETE : DRAG_REVERT, | 420 DRAG_COMPLETE : DRAG_REVERT, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { | 495 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { |
| 526 // We explicitly don't invoke RevertDrag() since that may do things to window. | 496 // We explicitly don't invoke RevertDrag() since that may do things to window. |
| 527 // Instead we destroy the resizer. | 497 // Instead we destroy the resizer. |
| 528 window_resizer_.reset(); | 498 window_resizer_.reset(); |
| 529 | 499 |
| 530 // End the move loop. This does nothing if we're not in a move loop. | 500 // End the move loop. This does nothing if we're not in a move loop. |
| 531 EndMoveLoop(); | 501 EndMoveLoop(); |
| 532 } | 502 } |
| 533 | 503 |
| 534 } // namespace ash | 504 } // namespace ash |
| OLD | NEW |