| 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/gestures/two_finger_drag_handler.h" | 5 #include "ash/wm/gestures/two_finger_drag_handler.h" |
| 6 | 6 |
| 7 #include "ash/wm/window_resizer.h" | 7 #include "ash/wm/window_resizer.h" |
| 8 #include "ash/wm/window_state.h" |
| 8 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 9 #include "ash/wm/workspace/snap_sizer.h" | 10 #include "ash/wm/workspace/snap_sizer.h" |
| 10 #include "ui/aura/client/window_types.h" | 11 #include "ui/aura/client/window_types.h" |
| 11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_delegate.h" | 13 #include "ui/aura/window_delegate.h" |
| 13 #include "ui/base/hit_test.h" | 14 #include "ui/base/hit_test.h" |
| 14 #include "ui/compositor/layer.h" | 15 #include "ui/compositor/layer.h" |
| 15 #include "ui/compositor/scoped_layer_animation_settings.h" | 16 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 16 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 17 #include "ui/events/event_constants.h" | 18 #include "ui/events/event_constants.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if (!target->delegate()) | 85 if (!target->delegate()) |
| 85 return false; | 86 return false; |
| 86 | 87 |
| 87 if (event.type() == ui::ET_GESTURE_BEGIN && | 88 if (event.type() == ui::ET_GESTURE_BEGIN && |
| 88 event.details().touch_points() == 1) { | 89 event.details().touch_points() == 1) { |
| 89 first_finger_hittest_ = | 90 first_finger_hittest_ = |
| 90 target->delegate()->GetNonClientComponent(event.location()); | 91 target->delegate()->GetNonClientComponent(event.location()); |
| 91 return false; | 92 return false; |
| 92 } | 93 } |
| 93 | 94 |
| 95 wm::WindowState* window_state = wm::GetWindowState(target); |
| 96 |
| 94 if (event.type() == ui::ET_GESTURE_BEGIN && | 97 if (event.type() == ui::ET_GESTURE_BEGIN && |
| 95 event.details().touch_points() == 2) { | 98 event.details().touch_points() == 2) { |
| 96 if (!window_resizer_.get() && wm::IsWindowNormal(target) && | 99 if (!window_resizer_.get() && window_state->IsNormalShowState() && |
| 97 target->type() == aura::client::WINDOW_TYPE_NORMAL) { | 100 target->type() == aura::client::WINDOW_TYPE_NORMAL) { |
| 98 if (WindowComponentsAllowMoving(first_finger_hittest_, | 101 if (WindowComponentsAllowMoving(first_finger_hittest_, |
| 99 target->delegate()->GetNonClientComponent(event.location()))) { | 102 target->delegate()->GetNonClientComponent(event.location()))) { |
| 100 target->AddObserver(this); | 103 target->AddObserver(this); |
| 101 window_resizer_ = CreateWindowResizer( | 104 window_resizer_ = CreateWindowResizer( |
| 102 target, | 105 target, |
| 103 event.details().bounding_box().CenterPoint(), | 106 event.details().bounding_box().CenterPoint(), |
| 104 HTCAPTION, | 107 HTCAPTION, |
| 105 aura::client::WINDOW_MOVE_SOURCE_TOUCH); | 108 aura::client::WINDOW_MOVE_SOURCE_TOUCH); |
| 106 return true; | 109 return true; |
| 107 } | 110 } |
| 108 } | 111 } |
| 109 | 112 |
| 110 return false; | 113 return false; |
| 111 } | 114 } |
| 112 | 115 |
| 113 if (!window_resizer_) { | 116 if (!window_resizer_) { |
| 114 // Consume all two-finger gestures on a normal window. | 117 // Consume all two-finger gestures on a normal window. |
| 115 return event.details().touch_points() == 2 && | 118 return event.details().touch_points() == 2 && |
| 116 target->type() == aura::client::WINDOW_TYPE_NORMAL && | 119 target->type() == aura::client::WINDOW_TYPE_NORMAL && |
| 117 wm::IsWindowNormal(target); | 120 window_state->IsNormalShowState(); |
| 118 } | 121 } |
| 119 | 122 |
| 120 if (target != window_resizer_->GetTarget()) | 123 if (target != window_resizer_->GetTarget()) |
| 121 return false; | 124 return false; |
| 122 | 125 |
| 123 switch (event.type()) { | 126 switch (event.type()) { |
| 124 case ui::ET_GESTURE_BEGIN: | 127 case ui::ET_GESTURE_BEGIN: |
| 125 if (event.details().touch_points() > 2) | 128 if (event.details().touch_points() > 2) |
| 126 Reset(); | 129 Reset(); |
| 127 return false; | 130 return false; |
| 128 | 131 |
| 129 case ui::ET_GESTURE_SCROLL_BEGIN: | 132 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 130 case ui::ET_GESTURE_PINCH_BEGIN: | 133 case ui::ET_GESTURE_PINCH_BEGIN: |
| 131 case ui::ET_GESTURE_SCROLL_END: | 134 case ui::ET_GESTURE_SCROLL_END: |
| 132 return true; | 135 return true; |
| 133 | 136 |
| 134 case ui::ET_GESTURE_MULTIFINGER_SWIPE: { | 137 case ui::ET_GESTURE_MULTIFINGER_SWIPE: { |
| 135 // For a swipe, the window either maximizes, minimizes, or snaps. In this | 138 // For a swipe, the window either maximizes, minimizes, or snaps. In this |
| 136 // case, cancel the drag, and do the appropriate action. | 139 // case, cancel the drag, and do the appropriate action. |
| 137 Reset(); | 140 Reset(); |
| 138 | |
| 139 if (event.details().swipe_up()) { | 141 if (event.details().swipe_up()) { |
| 140 if (wm::CanMaximizeWindow(target)) | 142 if (window_state->CanMaximize()) |
| 141 wm::MaximizeWindow(target); | 143 window_state->Maximize(); |
| 142 } else if (event.details().swipe_down() && | 144 } else if (event.details().swipe_down() && window_state->CanMinimize()) { |
| 143 wm::CanMinimizeWindow(target)) { | 145 window_state->Minimize(); |
| 144 wm::MinimizeWindow(target); | 146 } else if (window_state->CanSnap()) { |
| 145 } else if (wm::CanSnapWindow(target)) { | |
| 146 ui::ScopedLayerAnimationSettings scoped_setter( | 147 ui::ScopedLayerAnimationSettings scoped_setter( |
| 147 target->layer()->GetAnimator()); | 148 target->layer()->GetAnimator()); |
| 148 scoped_setter.SetPreemptionStrategy( | 149 scoped_setter.SetPreemptionStrategy( |
| 149 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 150 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 150 internal::SnapSizer::SnapWindow(target, | 151 internal::SnapSizer::SnapWindow(target, |
| 151 event.details().swipe_left() ? internal::SnapSizer::LEFT_EDGE : | 152 event.details().swipe_left() ? internal::SnapSizer::LEFT_EDGE : |
| 152 internal::SnapSizer::RIGHT_EDGE); | 153 internal::SnapSizer::RIGHT_EDGE); |
| 153 } | 154 } |
| 154 return true; | 155 return true; |
| 155 } | 156 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 bool visible) { | 190 bool visible) { |
| 190 Reset(); | 191 Reset(); |
| 191 } | 192 } |
| 192 | 193 |
| 193 void TwoFingerDragHandler::OnWindowDestroying(aura::Window* window) { | 194 void TwoFingerDragHandler::OnWindowDestroying(aura::Window* window) { |
| 194 Reset(); | 195 Reset(); |
| 195 } | 196 } |
| 196 | 197 |
| 197 } // namespace internal | 198 } // namespace internal |
| 198 } // namespace ash | 199 } // namespace ash |
| OLD | NEW |