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/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_properties.h" | |
| 10 #include "ash/wm/window_resizer.h" | 11 #include "ash/wm/window_resizer.h" |
| 11 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 12 #include "ash/wm/workspace/snap_sizer.h" | 13 #include "ash/wm/workspace/snap_sizer.h" |
| 13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "ui/aura/client/aura_constants.h" | 16 #include "ui/aura/client/aura_constants.h" |
| 16 #include "ui/aura/client/cursor_client.h" | 17 #include "ui/aura/client/cursor_client.h" |
| 17 #include "ui/aura/env.h" | 18 #include "ui/aura/env.h" |
| 18 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
| 19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 class ToplevelWindowEventHandler::ScopedWindowResizer | 56 class ToplevelWindowEventHandler::ScopedWindowResizer |
| 56 : public aura::WindowObserver { | 57 : public aura::WindowObserver { |
| 57 public: | 58 public: |
| 58 ScopedWindowResizer(ToplevelWindowEventHandler* handler, | 59 ScopedWindowResizer(ToplevelWindowEventHandler* handler, |
| 59 WindowResizer* resizer); | 60 WindowResizer* resizer); |
| 60 virtual ~ScopedWindowResizer(); | 61 virtual ~ScopedWindowResizer(); |
| 61 | 62 |
| 62 WindowResizer* resizer() { return resizer_.get(); } | 63 WindowResizer* resizer() { return resizer_.get(); } |
| 63 | 64 |
| 64 // WindowObserver overrides: | 65 // WindowObserver overrides: |
| 66 virtual void OnWindowHierarchyChanging( | |
| 67 const HierarchyChangeParams& params) OVERRIDE; | |
| 65 virtual void OnWindowPropertyChanged(aura::Window* window, | 68 virtual void OnWindowPropertyChanged(aura::Window* window, |
| 66 const void* key, | 69 const void* key, |
| 67 intptr_t old) OVERRIDE; | 70 intptr_t old) OVERRIDE; |
| 68 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; | 71 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
| 69 | 72 |
| 70 private: | 73 private: |
| 74 void AddHandlers(aura::Window* container); | |
| 75 void RemoveHandlers(); | |
| 76 | |
| 71 ToplevelWindowEventHandler* handler_; | 77 ToplevelWindowEventHandler* handler_; |
| 72 scoped_ptr<WindowResizer> resizer_; | 78 scoped_ptr<WindowResizer> resizer_; |
| 73 | 79 |
| 80 // If not NULL, this is an additional container that the dragged window has | |
| 81 // moved to which ScopedWindowResizer has temporarily added observers on. | |
| 82 aura::Window* target_container_; | |
| 83 | |
| 74 DISALLOW_COPY_AND_ASSIGN(ScopedWindowResizer); | 84 DISALLOW_COPY_AND_ASSIGN(ScopedWindowResizer); |
| 75 }; | 85 }; |
| 76 | 86 |
| 77 ToplevelWindowEventHandler::ScopedWindowResizer::ScopedWindowResizer( | 87 ToplevelWindowEventHandler::ScopedWindowResizer::ScopedWindowResizer( |
| 78 ToplevelWindowEventHandler* handler, | 88 ToplevelWindowEventHandler* handler, |
| 79 WindowResizer* resizer) | 89 WindowResizer* resizer) |
| 80 : handler_(handler), | 90 : handler_(handler), |
| 81 resizer_(resizer) { | 91 resizer_(resizer), |
| 92 target_container_(NULL) { | |
| 82 if (resizer_.get()) | 93 if (resizer_.get()) |
| 83 resizer_->GetTarget()->AddObserver(this); | 94 resizer_->GetTarget()->AddObserver(this); |
| 84 } | 95 } |
| 85 | 96 |
| 86 ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() { | 97 ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() { |
| 98 RemoveHandlers(); | |
| 87 if (resizer_.get()) | 99 if (resizer_.get()) |
| 88 resizer_->GetTarget()->RemoveObserver(this); | 100 resizer_->GetTarget()->RemoveObserver(this); |
| 89 } | 101 } |
| 90 | 102 |
| 103 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowHierarchyChanging( | |
| 104 const HierarchyChangeParams& params) { | |
| 105 if (params.receiver != resizer_->GetTarget()) | |
| 106 return; | |
| 107 | |
| 108 if (params.receiver->GetProperty(internal::kContinueDragAfterReparent)) { | |
| 109 params.receiver->SetProperty(internal::kContinueDragAfterReparent, false); | |
| 110 AddHandlers(params.new_parent); | |
| 111 } else { | |
| 112 handler_->CompleteDrag(DRAG_COMPLETE, 0); | |
|
flackr
2013/03/20 10:01:40
If the new parent is also contained by handler_->o
| |
| 113 } | |
| 114 } | |
| 115 | |
| 91 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowPropertyChanged( | 116 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowPropertyChanged( |
| 92 aura::Window* window, | 117 aura::Window* window, |
| 93 const void* key, | 118 const void* key, |
| 94 intptr_t old) { | 119 intptr_t old) { |
| 95 if (!wm::IsWindowNormal(window)) | 120 if (!wm::IsWindowNormal(window)) |
| 96 handler_->CompleteDrag(DRAG_COMPLETE, 0); | 121 handler_->CompleteDrag(DRAG_COMPLETE, 0); |
| 97 } | 122 } |
| 98 | 123 |
| 99 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( | 124 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( |
| 100 aura::Window* window) { | 125 aura::Window* window) { |
| 101 DCHECK(resizer_.get()); | 126 DCHECK(resizer_.get()); |
| 102 DCHECK_EQ(resizer_->GetTarget(), window); | 127 DCHECK_EQ(resizer_->GetTarget(), window); |
| 103 handler_->ResizerWindowDestroyed(); | 128 handler_->ResizerWindowDestroyed(); |
| 104 } | 129 } |
| 105 | 130 |
| 131 void ToplevelWindowEventHandler::ScopedWindowResizer::AddHandlers( | |
| 132 aura::Window* container) { | |
| 133 RemoveHandlers(); | |
| 134 if (!handler_->owner()->Contains(container)) { | |
| 135 container->AddPreTargetHandler(handler_); | |
| 136 container->AddPostTargetHandler(handler_); | |
| 137 target_container_ = container; | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 void ToplevelWindowEventHandler::ScopedWindowResizer::RemoveHandlers() { | |
| 142 if (target_container_) { | |
| 143 target_container_->RemovePreTargetHandler(handler_); | |
| 144 target_container_->RemovePostTargetHandler(handler_); | |
| 145 target_container_ = NULL; | |
| 146 } | |
| 147 } | |
| 148 | |
| 106 | 149 |
| 107 // ToplevelWindowEventHandler -------------------------------------------------- | 150 // ToplevelWindowEventHandler -------------------------------------------------- |
| 108 | 151 |
| 109 ToplevelWindowEventHandler::ToplevelWindowEventHandler(aura::Window* owner) | 152 ToplevelWindowEventHandler::ToplevelWindowEventHandler(aura::Window* owner) |
| 110 : in_move_loop_(false), | 153 : owner_(owner), |
| 154 in_move_loop_(false), | |
| 111 move_cancelled_(false), | 155 move_cancelled_(false), |
| 112 in_gesture_drag_(false), | 156 in_gesture_drag_(false), |
| 113 destroyed_(NULL) { | 157 destroyed_(NULL) { |
| 114 aura::client::SetWindowMoveClient(owner, this); | 158 aura::client::SetWindowMoveClient(owner, this); |
| 115 Shell::GetInstance()->display_controller()->AddObserver(this); | 159 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 116 owner->AddPreTargetHandler(this); | 160 owner->AddPreTargetHandler(this); |
| 117 owner->AddPostTargetHandler(this); | 161 owner->AddPostTargetHandler(this); |
| 118 } | 162 } |
| 119 | 163 |
| 120 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { | 164 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { | 500 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { |
| 457 // We explicitly don't invoke RevertDrag() since that may do things to window. | 501 // We explicitly don't invoke RevertDrag() since that may do things to window. |
| 458 // Instead we destroy the resizer. | 502 // Instead we destroy the resizer. |
| 459 window_resizer_.reset(); | 503 window_resizer_.reset(); |
| 460 | 504 |
| 461 // End the move loop. This does nothing if we're not in a move loop. | 505 // End the move loop. This does nothing if we're not in a move loop. |
| 462 EndMoveLoop(); | 506 EndMoveLoop(); |
| 463 } | 507 } |
| 464 | 508 |
| 465 } // namespace ash | 509 } // namespace ash |
| OLD | NEW |