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 | |
82 // moved to which ScopedWindowResizer has temporarily added observers on. | |
83 aura::Window* target_container_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(ScopedWindowResizer); | 78 DISALLOW_COPY_AND_ASSIGN(ScopedWindowResizer); |
86 }; | 79 }; |
87 | 80 |
88 ToplevelWindowEventHandler::ScopedWindowResizer::ScopedWindowResizer( | 81 ToplevelWindowEventHandler::ScopedWindowResizer::ScopedWindowResizer( |
89 ToplevelWindowEventHandler* handler, | 82 ToplevelWindowEventHandler* handler, |
90 WindowResizer* resizer) | 83 WindowResizer* resizer) |
91 : handler_(handler), | 84 : handler_(handler), |
92 resizer_(resizer), | 85 resizer_(resizer) { |
93 target_container_(NULL) { | |
94 if (resizer_) { | 86 if (resizer_) { |
95 resizer_->GetTarget()->AddObserver(this); | 87 resizer_->GetTarget()->AddObserver(this); |
96 wm::GetWindowState(resizer_->GetTarget())->AddObserver(this); | 88 wm::GetWindowState(resizer_->GetTarget())->AddObserver(this); |
97 } | 89 } |
98 } | 90 } |
99 | 91 |
100 ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() { | 92 ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() { |
101 RemoveHandlers(); | |
102 if (resizer_) { | 93 if (resizer_) { |
103 resizer_->GetTarget()->RemoveObserver(this); | 94 resizer_->GetTarget()->RemoveObserver(this); |
104 wm::GetWindowState(resizer_->GetTarget())->RemoveObserver(this); | 95 wm::GetWindowState(resizer_->GetTarget())->RemoveObserver(this); |
105 } | 96 } |
106 } | 97 } |
107 | 98 |
108 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowHierarchyChanging( | 99 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowHierarchyChanging( |
109 const HierarchyChangeParams& params) { | 100 const HierarchyChangeParams& params) { |
110 if (params.receiver != resizer_->GetTarget()) | 101 if (params.receiver != resizer_->GetTarget()) |
111 return; | 102 return; |
112 wm::WindowState* state = wm::GetWindowState(params.receiver); | 103 wm::WindowState* state = wm::GetWindowState(params.receiver); |
113 if (state->continue_drag_after_reparent()) { | 104 if (state->continue_drag_after_reparent()) |
114 state->set_continue_drag_after_reparent(false); | 105 state->set_continue_drag_after_reparent(false); |
115 AddHandlers(params.new_parent); | 106 else |
116 } else { | |
117 handler_->CompleteDrag(DRAG_COMPLETE, 0); | 107 handler_->CompleteDrag(DRAG_COMPLETE, 0); |
118 } | |
119 } | 108 } |
120 | 109 |
121 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowShowTypeChanged( | 110 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowShowTypeChanged( |
122 wm::WindowState* window_state, | 111 wm::WindowState* window_state, |
123 wm::WindowShowType old) { | 112 wm::WindowShowType old) { |
124 if (!window_state->IsNormalShowState()) | 113 if (!window_state->IsNormalShowState()) |
125 handler_->CompleteDrag(DRAG_COMPLETE, 0); | 114 handler_->CompleteDrag(DRAG_COMPLETE, 0); |
126 } | 115 } |
127 | 116 |
128 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( | 117 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( |
129 aura::Window* window) { | 118 aura::Window* window) { |
130 DCHECK(resizer_.get()); | 119 DCHECK(resizer_.get()); |
131 DCHECK_EQ(resizer_->GetTarget(), window); | 120 DCHECK_EQ(resizer_->GetTarget(), window); |
132 handler_->ResizerWindowDestroyed(); | 121 handler_->ResizerWindowDestroyed(); |
133 } | 122 } |
134 | 123 |
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 -------------------------------------------------- | 124 // ToplevelWindowEventHandler -------------------------------------------------- |
155 | 125 |
156 ToplevelWindowEventHandler::ToplevelWindowEventHandler(aura::Window* owner) | 126 ToplevelWindowEventHandler::ToplevelWindowEventHandler() |
157 : owner_(owner), | 127 : in_move_loop_(false), |
158 in_move_loop_(false), | |
159 move_cancelled_(false), | 128 move_cancelled_(false), |
160 in_gesture_drag_(false), | 129 in_gesture_drag_(false), |
161 destroyed_(NULL) { | 130 destroyed_(NULL) { |
162 aura::client::SetWindowMoveClient(owner, this); | |
163 Shell::GetInstance()->display_controller()->AddObserver(this); | 131 Shell::GetInstance()->display_controller()->AddObserver(this); |
164 owner->AddPreTargetHandler(this); | |
165 owner->AddPostTargetHandler(this); | |
166 } | 132 } |
167 | 133 |
168 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { | 134 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { |
169 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 135 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
170 if (destroyed_) | 136 if (destroyed_) |
171 *destroyed_ = true; | 137 *destroyed_ = true; |
172 } | 138 } |
173 | 139 |
174 void ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { | 140 void ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { |
175 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED && | 141 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. | 392 // pressed without mouse move event. |
427 int component = | 393 int component = |
428 target->delegate()->GetNonClientComponent(event->location()); | 394 target->delegate()->GetNonClientComponent(event->location()); |
429 if ((event->flags() & | 395 if ((event->flags() & |
430 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 && | 396 (ui::EF_IS_DOUBLE_CLICK | ui::EF_IS_TRIPLE_CLICK)) == 0 && |
431 WindowResizer::GetBoundsChangeForWindowComponent(component)) { | 397 WindowResizer::GetBoundsChangeForWindowComponent(component)) { |
432 gfx::Point location_in_parent( | 398 gfx::Point location_in_parent( |
433 ConvertPointToParent(target, event->location())); | 399 ConvertPointToParent(target, event->location())); |
434 CreateScopedWindowResizer(target, location_in_parent, component, | 400 CreateScopedWindowResizer(target, location_in_parent, component, |
435 aura::client::WINDOW_MOVE_SOURCE_MOUSE); | 401 aura::client::WINDOW_MOVE_SOURCE_MOUSE); |
| 402 event->StopPropagation(); |
436 } else { | 403 } else { |
437 window_resizer_.reset(); | 404 window_resizer_.reset(); |
438 } | 405 } |
439 if (WindowResizer::GetBoundsChangeForWindowComponent(component) != 0) | |
440 event->StopPropagation(); | |
441 } | 406 } |
442 | 407 |
443 void ToplevelWindowEventHandler::HandleMouseReleased( | 408 void ToplevelWindowEventHandler::HandleMouseReleased( |
444 aura::Window* target, | 409 aura::Window* target, |
445 ui::MouseEvent* event) { | 410 ui::MouseEvent* event) { |
446 if (event->phase() != ui::EP_PRETARGET) | 411 if (event->phase() != ui::EP_PRETARGET) |
447 return; | 412 return; |
448 | 413 |
449 CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ? | 414 CompleteDrag(event->type() == ui::ET_MOUSE_RELEASED ? |
450 DRAG_COMPLETE : DRAG_REVERT, | 415 DRAG_COMPLETE : DRAG_REVERT, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { | 490 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { |
526 // We explicitly don't invoke RevertDrag() since that may do things to window. | 491 // We explicitly don't invoke RevertDrag() since that may do things to window. |
527 // Instead we destroy the resizer. | 492 // Instead we destroy the resizer. |
528 window_resizer_.reset(); | 493 window_resizer_.reset(); |
529 | 494 |
530 // End the move loop. This does nothing if we're not in a move loop. | 495 // End the move loop. This does nothing if we're not in a move loop. |
531 EndMoveLoop(); | 496 EndMoveLoop(); |
532 } | 497 } |
533 | 498 |
534 } // namespace ash | 499 } // namespace ash |
OLD | NEW |