| 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" | |
| 9 #include "ash/wm/resize_shadow_controller.h" | 8 #include "ash/wm/resize_shadow_controller.h" |
| 10 #include "ash/wm/window_resizer.h" | 9 #include "ash/wm/window_resizer.h" |
| 11 #include "ash/wm/window_settings.h" | 10 #include "ash/wm/window_state.h" |
| 12 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
| 13 #include "ash/wm/workspace/snap_sizer.h" | 12 #include "ash/wm/workspace/snap_sizer.h" |
| 14 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 16 #include "ui/aura/client/aura_constants.h" | 15 #include "ui/aura/client/aura_constants.h" |
| 17 #include "ui/aura/client/cursor_client.h" | 16 #include "ui/aura/client/cursor_client.h" |
| 18 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
| 19 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
| 20 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_delegate.h" | 20 #include "ui/aura/window_delegate.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() { | 96 ToplevelWindowEventHandler::ScopedWindowResizer::~ScopedWindowResizer() { |
| 98 RemoveHandlers(); | 97 RemoveHandlers(); |
| 99 if (resizer_) | 98 if (resizer_) |
| 100 resizer_->GetTarget()->RemoveObserver(this); | 99 resizer_->GetTarget()->RemoveObserver(this); |
| 101 } | 100 } |
| 102 | 101 |
| 103 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowHierarchyChanging( | 102 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowHierarchyChanging( |
| 104 const HierarchyChangeParams& params) { | 103 const HierarchyChangeParams& params) { |
| 105 if (params.receiver != resizer_->GetTarget()) | 104 if (params.receiver != resizer_->GetTarget()) |
| 106 return; | 105 return; |
| 107 | 106 wm::WindowState* state = wm::GetWindowState(params.receiver); |
| 108 if (wm::GetWindowSettings(params.receiver)->continue_drag_after_reparent()) { | 107 if (state->continue_drag_after_reparent()) { |
| 109 wm::GetWindowSettings(params.receiver)-> | 108 state->set_continue_drag_after_reparent(false); |
| 110 set_continue_drag_after_reparent(false); | |
| 111 AddHandlers(params.new_parent); | 109 AddHandlers(params.new_parent); |
| 112 } else { | 110 } else { |
| 113 handler_->CompleteDrag(DRAG_COMPLETE, 0); | 111 handler_->CompleteDrag(DRAG_COMPLETE, 0); |
| 114 } | 112 } |
| 115 } | 113 } |
| 116 | 114 |
| 117 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowPropertyChanged( | 115 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowPropertyChanged( |
| 118 aura::Window* window, | 116 aura::Window* window, |
| 119 const void* key, | 117 const void* key, |
| 120 intptr_t old) { | 118 intptr_t old) { |
| 121 if (key == aura::client::kShowStateKey && !wm::IsWindowNormal(window)) | 119 if (key == aura::client::kShowStateKey && |
| 120 !wm::GetWindowState(window)->IsNormalShowState()) |
| 122 handler_->CompleteDrag(DRAG_COMPLETE, 0); | 121 handler_->CompleteDrag(DRAG_COMPLETE, 0); |
| 123 } | 122 } |
| 124 | 123 |
| 125 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( | 124 void ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowDestroying( |
| 126 aura::Window* window) { | 125 aura::Window* window) { |
| 127 DCHECK(resizer_.get()); | 126 DCHECK(resizer_.get()); |
| 128 DCHECK_EQ(resizer_->GetTarget(), window); | 127 DCHECK_EQ(resizer_->GetTarget(), window); |
| 129 handler_->ResizerWindowDestroyed(); | 128 handler_->ResizerWindowDestroyed(); |
| 130 } | 129 } |
| 131 | 130 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 279 |
| 281 if (event->type() == ui::ET_GESTURE_SCROLL_END) { | 280 if (event->type() == ui::ET_GESTURE_SCROLL_END) { |
| 282 event->StopPropagation(); | 281 event->StopPropagation(); |
| 283 return; | 282 return; |
| 284 } | 283 } |
| 285 | 284 |
| 286 int component = | 285 int component = |
| 287 target->delegate()->GetNonClientComponent(event->location()); | 286 target->delegate()->GetNonClientComponent(event->location()); |
| 288 if (WindowResizer::GetBoundsChangeForWindowComponent(component) == 0) | 287 if (WindowResizer::GetBoundsChangeForWindowComponent(component) == 0) |
| 289 return; | 288 return; |
| 290 if (!wm::IsWindowNormal(target)) | 289 |
| 290 wm::WindowState* window_state = wm::GetWindowState(target); |
| 291 if (!window_state->IsNormalShowState()) |
| 291 return; | 292 return; |
| 292 | 293 |
| 293 if (fabs(event->details().velocity_y()) > | 294 if (fabs(event->details().velocity_y()) > |
| 294 kMinVertVelocityForWindowMinimize) { | 295 kMinVertVelocityForWindowMinimize) { |
| 295 // Minimize/maximize. | 296 // Minimize/maximize. |
| 296 if (event->details().velocity_y() > 0 && | 297 if (event->details().velocity_y() > 0 && |
| 297 wm::CanMinimizeWindow(target)) { | 298 window_state->CanMinimize()) { |
| 298 wm::MinimizeWindow(target); | 299 window_state->Minimize(); |
| 299 SetWindowAlwaysRestoresToRestoreBounds(target, true); | 300 window_state->set_always_restores_to_restore_bounds(true); |
| 300 SetRestoreBoundsInParent(target, pre_drag_window_bounds_); | 301 window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_); |
| 301 } else if (wm::CanMaximizeWindow(target)) { | 302 } else if (window_state->CanMaximize()) { |
| 302 SetRestoreBoundsInParent(target, pre_drag_window_bounds_); | 303 window_state->SetRestoreBoundsInParent(pre_drag_window_bounds_); |
| 303 wm::MaximizeWindow(target); | 304 window_state->Maximize(); |
| 304 } | 305 } |
| 305 } else if (wm::CanSnapWindow(target) && | 306 } else if (window_state->CanSnap() && |
| 306 fabs(event->details().velocity_x()) > | 307 fabs(event->details().velocity_x()) > |
| 307 kMinHorizVelocityForWindowSwipe) { | 308 kMinHorizVelocityForWindowSwipe) { |
| 308 // Snap left/right. | 309 // Snap left/right. |
| 309 ui::ScopedLayerAnimationSettings scoped_setter( | 310 ui::ScopedLayerAnimationSettings scoped_setter( |
| 310 target->layer()->GetAnimator()); | 311 target->layer()->GetAnimator()); |
| 311 scoped_setter.SetPreemptionStrategy( | 312 scoped_setter.SetPreemptionStrategy( |
| 312 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 313 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 313 internal::SnapSizer::SnapWindow(target, | 314 internal::SnapSizer::SnapWindow(target, |
| 314 event->details().velocity_x() < 0 ? | 315 event->details().velocity_x() < 0 ? |
| 315 internal::SnapSizer::LEFT_EDGE : internal::SnapSizer::RIGHT_EDGE); | 316 internal::SnapSizer::LEFT_EDGE : internal::SnapSizer::RIGHT_EDGE); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { | 525 void ToplevelWindowEventHandler::ResizerWindowDestroyed() { |
| 525 // We explicitly don't invoke RevertDrag() since that may do things to window. | 526 // We explicitly don't invoke RevertDrag() since that may do things to window. |
| 526 // Instead we destroy the resizer. | 527 // Instead we destroy the resizer. |
| 527 window_resizer_.reset(); | 528 window_resizer_.reset(); |
| 528 | 529 |
| 529 // End the move loop. This does nothing if we're not in a move loop. | 530 // End the move loop. This does nothing if we're not in a move loop. |
| 530 EndMoveLoop(); | 531 EndMoveLoop(); |
| 531 } | 532 } |
| 532 | 533 |
| 533 } // namespace ash | 534 } // namespace ash |
| OLD | NEW |