| 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/default_window_resizer.h" | 8 #include "ash/wm/default_window_resizer.h" |
| 9 #include "ash/wm/property_util.h" | 9 #include "ash/wm/property_util.h" |
| 10 #include "ash/wm/resize_shadow_controller.h" | 10 #include "ash/wm/resize_shadow_controller.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 DCHECK(resizer_.get()); | 89 DCHECK(resizer_.get()); |
| 90 DCHECK_EQ(resizer_->GetTarget(), window); | 90 DCHECK_EQ(resizer_->GetTarget(), window); |
| 91 handler_->ResizerWindowDestroyed(); | 91 handler_->ResizerWindowDestroyed(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 | 94 |
| 95 // ToplevelWindowEventHandler -------------------------------------------------- | 95 // ToplevelWindowEventHandler -------------------------------------------------- |
| 96 | 96 |
| 97 ToplevelWindowEventHandler::ToplevelWindowEventHandler(aura::Window* owner) | 97 ToplevelWindowEventHandler::ToplevelWindowEventHandler(aura::Window* owner) |
| 98 : in_move_loop_(false), | 98 : in_move_loop_(false), |
| 99 in_gesture_resize_(false) { | 99 move_cancelled_(false) { |
| 100 aura::client::SetWindowMoveClient(owner, this); | 100 aura::client::SetWindowMoveClient(owner, this); |
| 101 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 101 } | 102 } |
| 102 | 103 |
| 103 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { | 104 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { |
| 105 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 104 } | 106 } |
| 105 | 107 |
| 106 ui::EventResult ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { | 108 ui::EventResult ToplevelWindowEventHandler::OnKeyEvent(ui::KeyEvent* event) { |
| 107 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED && | 109 if (window_resizer_.get() && event->type() == ui::ET_KEY_PRESSED && |
| 108 event->key_code() == ui::VKEY_ESCAPE) { | 110 event->key_code() == ui::VKEY_ESCAPE) { |
| 109 CompleteDrag(DRAG_REVERT, event->flags()); | 111 CompleteDrag(DRAG_REVERT, event->flags()); |
| 110 } | 112 } |
| 111 return ui::ER_UNHANDLED; | 113 return ui::ER_UNHANDLED; |
| 112 } | 114 } |
| 113 | 115 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 249 } |
| 248 break; | 250 break; |
| 249 } | 251 } |
| 250 default: | 252 default: |
| 251 return ui::ER_UNHANDLED; | 253 return ui::ER_UNHANDLED; |
| 252 } | 254 } |
| 253 | 255 |
| 254 return ui::ER_CONSUMED; | 256 return ui::ER_CONSUMED; |
| 255 } | 257 } |
| 256 | 258 |
| 257 void ToplevelWindowEventHandler::RunMoveLoop(aura::Window* source, | 259 aura::client::WindowMoveResult ToplevelWindowEventHandler::RunMoveLoop( |
| 258 const gfx::Point& drag_offset) { | 260 aura::Window* source, |
| 261 const gfx::Point& drag_offset) { |
| 259 DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. | 262 DCHECK(!in_move_loop_); // Can only handle one nested loop at a time. |
| 260 in_move_loop_ = true; | 263 in_move_loop_ = true; |
| 264 move_cancelled_ = false; |
| 261 aura::RootWindow* root_window = source->GetRootWindow(); | 265 aura::RootWindow* root_window = source->GetRootWindow(); |
| 262 DCHECK(root_window); | 266 DCHECK(root_window); |
| 263 gfx::Point drag_location; | 267 gfx::Point drag_location; |
| 264 if (aura::Env::GetInstance()->is_touch_down()) { | 268 if (aura::Env::GetInstance()->is_touch_down()) { |
| 265 in_gesture_resize_ = true; | 269 in_gesture_resize_ = true; |
| 266 bool has_point = root_window->gesture_recognizer()-> | 270 bool has_point = root_window->gesture_recognizer()-> |
| 267 GetLastTouchPointForTarget(source, &drag_location); | 271 GetLastTouchPointForTarget(source, &drag_location); |
| 268 DCHECK(has_point); | 272 DCHECK(has_point); |
| 269 } else { | 273 } else { |
| 270 drag_location = root_window->GetLastMouseLocationInRoot(); | 274 drag_location = root_window->GetLastMouseLocationInRoot(); |
| 271 aura::Window::ConvertPointToTarget( | 275 aura::Window::ConvertPointToTarget( |
| 272 root_window, source->parent(), &drag_location); | 276 root_window, source->parent(), &drag_location); |
| 273 } | 277 } |
| 274 CreateScopedWindowResizer(source, drag_location, HTCAPTION); | 278 CreateScopedWindowResizer(source, drag_location, HTCAPTION); |
| 275 source->GetRootWindow()->SetCursor(ui::kCursorPointer); | 279 source->GetRootWindow()->SetCursor(ui::kCursorPointer); |
| 276 #if !defined(OS_MACOSX) | 280 #if !defined(OS_MACOSX) |
| 277 MessageLoopForUI* loop = MessageLoopForUI::current(); | 281 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 278 MessageLoop::ScopedNestableTaskAllower allow_nested(loop); | 282 MessageLoop::ScopedNestableTaskAllower allow_nested(loop); |
| 279 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); | 283 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); |
| 280 quit_closure_ = run_loop.QuitClosure(); | 284 quit_closure_ = run_loop.QuitClosure(); |
| 281 run_loop.Run(); | 285 run_loop.Run(); |
| 282 #endif // !defined(OS_MACOSX) | 286 #endif // !defined(OS_MACOSX) |
| 283 in_gesture_resize_ = in_move_loop_ = false; | 287 in_gesture_resize_ = in_move_loop_ = false; |
| 288 return move_cancelled_ ? aura::client::MOVE_CANCELED : |
| 289 aura::client::MOVE_SUCCESSFUL; |
| 284 } | 290 } |
| 285 | 291 |
| 286 void ToplevelWindowEventHandler::EndMoveLoop() { | 292 void ToplevelWindowEventHandler::EndMoveLoop() { |
| 287 if (!in_move_loop_) | 293 if (!in_move_loop_) |
| 288 return; | 294 return; |
| 289 | 295 |
| 290 in_move_loop_ = false; | 296 in_move_loop_ = false; |
| 291 if (window_resizer_.get()) { | 297 if (window_resizer_.get()) { |
| 292 window_resizer_->resizer()->RevertDrag(); | 298 window_resizer_->resizer()->RevertDrag(); |
| 293 window_resizer_.reset(); | 299 window_resizer_.reset(); |
| 294 } | 300 } |
| 295 quit_closure_.Run(); | 301 quit_closure_.Run(); |
| 296 } | 302 } |
| 297 | 303 |
| 304 void ToplevelWindowEventHandler::OnDisplayConfigurationChanging() { |
| 305 if (in_move_loop_) { |
| 306 move_cancelled_ = true; |
| 307 EndMoveLoop(); |
| 308 } else if (window_resizer_.get()) { |
| 309 window_resizer_->resizer()->RevertDrag(); |
| 310 window_resizer_.reset(); |
| 311 } |
| 312 } |
| 313 |
| 298 // static | 314 // static |
| 299 WindowResizer* ToplevelWindowEventHandler::CreateWindowResizer( | 315 WindowResizer* ToplevelWindowEventHandler::CreateWindowResizer( |
| 300 aura::Window* window, | 316 aura::Window* window, |
| 301 const gfx::Point& point_in_parent, | 317 const gfx::Point& point_in_parent, |
| 302 int window_component) { | 318 int window_component) { |
| 303 if (!wm::IsWindowNormal(window)) | 319 if (!wm::IsWindowNormal(window)) |
| 304 return NULL; // Don't allow resizing/dragging maximized/fullscreen windows. | 320 return NULL; // Don't allow resizing/dragging maximized/fullscreen windows. |
| 305 return DefaultWindowResizer::Create( | 321 return DefaultWindowResizer::Create( |
| 306 window, point_in_parent, window_component); | 322 window, point_in_parent, window_component); |
| 307 } | 323 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { | 390 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { |
| 375 // We explicitly don't invoke RevertDrag() since that may do things to window. | 391 // We explicitly don't invoke RevertDrag() since that may do things to window. |
| 376 // Instead we destroy the resizer. | 392 // Instead we destroy the resizer. |
| 377 window_resizer_.reset(); | 393 window_resizer_.reset(); |
| 378 | 394 |
| 379 // End the move loop. This does nothing if we're not in a move loop. | 395 // End the move loop. This does nothing if we're not in a move loop. |
| 380 EndMoveLoop(); | 396 EndMoveLoop(); |
| 381 } | 397 } |
| 382 | 398 |
| 383 } // namespace ash | 399 } // namespace ash |
| OLD | NEW |