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* extra_handler_container_; | |
|
sky
2013/03/18 16:17:47
Can you name this target_contaienr_ ?
flackr
2013/03/20 01:59:32
Done.
| |
| 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 extra_handler_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 params.receiver->GetProperty(internal::kContinueDragAfterReparent)) { | |
| 107 params.receiver->SetProperty(internal::kContinueDragAfterReparent, false); | |
| 108 AddHandlers(params.new_parent); | |
| 109 } | |
| 110 } | |
| 111 | |
| 91 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowPropertyChanged( | 112 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowPropertyChanged( |
| 92 aura::Window* window, | 113 aura::Window* window, |
| 93 const void* key, | 114 const void* key, |
| 94 intptr_t old) { | 115 intptr_t old) { |
| 95 if (!wm::IsWindowNormal(window)) | 116 if (!wm::IsWindowNormal(window)) |
| 96 handler_->CompleteDrag(DRAG_COMPLETE, 0); | 117 handler_->CompleteDrag(DRAG_COMPLETE, 0); |
| 97 } | 118 } |
| 98 | 119 |
| 99 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( | 120 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( |
| 100 aura::Window* window) { | 121 aura::Window* window) { |
| 101 DCHECK(resizer_.get()); | 122 DCHECK(resizer_.get()); |
| 102 DCHECK_EQ(resizer_->GetTarget(), window); | 123 DCHECK_EQ(resizer_->GetTarget(), window); |
| 103 handler_->ResizerWindowDestroyed(); | 124 handler_->ResizerWindowDestroyed(); |
| 104 } | 125 } |
| 105 | 126 |
| 127 void ToplevelWindowEventHandler::ScopedWindowResizer::AddHandlers( | |
| 128 aura::Window* container) { | |
| 129 RemoveHandlers(); | |
| 130 if (!handler_->owner()->Contains(container)) { | |
| 131 container->AddPreTargetHandler(handler_); | |
| 132 container->AddPostTargetHandler(handler_); | |
| 133 extra_handler_container_ = container; | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 void ToplevelWindowEventHandler::ScopedWindowResizer::RemoveHandlers() { | |
| 138 if (extra_handler_container_) { | |
| 139 extra_handler_container_->RemovePreTargetHandler(handler_); | |
| 140 extra_handler_container_->RemovePostTargetHandler(handler_); | |
| 141 extra_handler_container_ = NULL; | |
| 142 } | |
| 143 } | |
| 144 | |
| 106 | 145 |
| 107 // ToplevelWindowEventHandler -------------------------------------------------- | 146 // ToplevelWindowEventHandler -------------------------------------------------- |
| 108 | 147 |
| 109 ToplevelWindowEventHandler::ToplevelWindowEventHandler(aura::Window* owner) | 148 ToplevelWindowEventHandler::ToplevelWindowEventHandler(aura::Window* owner) |
| 110 : in_move_loop_(false), | 149 : owner_(owner), |
| 150 in_move_loop_(false), | |
| 111 move_cancelled_(false), | 151 move_cancelled_(false), |
| 112 in_gesture_drag_(false), | 152 in_gesture_drag_(false), |
| 113 destroyed_(NULL) { | 153 destroyed_(NULL) { |
| 114 aura::client::SetWindowMoveClient(owner, this); | 154 aura::client::SetWindowMoveClient(owner, this); |
| 115 Shell::GetInstance()->display_controller()->AddObserver(this); | 155 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 116 owner->AddPreTargetHandler(this); | 156 owner->AddPreTargetHandler(this); |
| 117 owner->AddPostTargetHandler(this); | 157 owner->AddPostTargetHandler(this); |
| 118 } | 158 } |
| 119 | 159 |
| 120 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { | 160 ToplevelWindowEventHandler::~ToplevelWindowEventHandler() { |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { | 496 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { |
| 457 // We explicitly don't invoke RevertDrag() since that may do things to window. | 497 // We explicitly don't invoke RevertDrag() since that may do things to window. |
| 458 // Instead we destroy the resizer. | 498 // Instead we destroy the resizer. |
| 459 window_resizer_.reset(); | 499 window_resizer_.reset(); |
| 460 | 500 |
| 461 // End the move loop. This does nothing if we're not in a move loop. | 501 // End the move loop. This does nothing if we're not in a move loop. |
| 462 EndMoveLoop(); | 502 EndMoveLoop(); |
| 463 } | 503 } |
| 464 | 504 |
| 465 } // namespace ash | 505 } // namespace ash |
| OLD | NEW |