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/system_pinch_handler.h" | 5 #include "ash/wm/gestures/system_pinch_handler.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
9 #include "ash/shelf/shelf_widget.h" | 9 #include "ash/shelf/shelf_widget.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/wm/property_util.h" | |
12 #include "ash/wm/window_animations.h" | 11 #include "ash/wm/window_animations.h" |
| 12 #include "ash/wm/window_state.h" |
13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
14 #include "ash/wm/workspace/snap_sizer.h" | 14 #include "ash/wm/workspace/snap_sizer.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/base/gestures/gesture_types.h" | 16 #include "ui/base/gestures/gesture_types.h" |
17 #include "ui/compositor/scoped_layer_animation_settings.h" | 17 #include "ui/compositor/scoped_layer_animation_settings.h" |
18 #include "ui/events/event_constants.h" | 18 #include "ui/events/event_constants.h" |
19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
21 #include "ui/views/widget/widget_delegate.h" | 21 #include "ui/views/widget/widget_delegate.h" |
22 | 22 |
(...skipping 14 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 SystemPinchHandler::~SystemPinchHandler() { | 39 SystemPinchHandler::~SystemPinchHandler() { |
40 } | 40 } |
41 | 41 |
42 SystemGestureStatus SystemPinchHandler::ProcessGestureEvent( | 42 SystemGestureStatus SystemPinchHandler::ProcessGestureEvent( |
43 const ui::GestureEvent& event) { | 43 const ui::GestureEvent& event) { |
44 // The target has changed, somehow. Let's bale. | 44 // The target has changed, somehow. Let's bale. |
45 if (!widget_ || !widget_->widget_delegate()->CanResize()) | 45 if (!widget_ || !widget_->widget_delegate()->CanResize()) |
46 return SYSTEM_GESTURE_END; | 46 return SYSTEM_GESTURE_END; |
47 | 47 wm::WindowState* window_state = wm::GetWindowState(target_); |
48 switch (event.type()) { | 48 switch (event.type()) { |
49 case ui::ET_GESTURE_END: { | 49 case ui::ET_GESTURE_END: { |
50 if (event.details().touch_points() > kSystemGesturePoints) | 50 if (event.details().touch_points() > kSystemGesturePoints) |
51 break; | 51 break; |
52 | 52 |
53 if (phantom_state_ == PHANTOM_WINDOW_MAXIMIZED) { | 53 if (phantom_state_ == PHANTOM_WINDOW_MAXIMIZED) { |
54 if (!wm::IsWindowMaximized(target_) && | 54 if (!window_state->IsMaximizedOrFullscreen()) |
55 !wm::IsWindowFullscreen(target_)) | 55 window_state->Maximize(); |
56 wm::MaximizeWindow(target_); | |
57 } else if (phantom_state_ == PHANTOM_WINDOW_MINIMIZED) { | 56 } else if (phantom_state_ == PHANTOM_WINDOW_MINIMIZED) { |
58 if (wm::IsWindowMaximized(target_) || | 57 if (window_state->IsMaximizedOrFullscreen()) { |
59 wm::IsWindowFullscreen(target_)) { | 58 window_state->Restore(); |
60 wm::RestoreWindow(target_); | |
61 } else { | 59 } else { |
62 wm::MinimizeWindow(target_); | 60 window_state->Minimize(); |
63 | 61 |
64 // NOTE: Minimizing the window will cause this handler to be | 62 // NOTE: Minimizing the window will cause this handler to be |
65 // destroyed. So do not access anything from |this| from here. | 63 // destroyed. So do not access anything from |this| from here. |
66 return SYSTEM_GESTURE_END; | 64 return SYSTEM_GESTURE_END; |
67 } | 65 } |
68 } | 66 } |
69 return SYSTEM_GESTURE_END; | 67 return SYSTEM_GESTURE_END; |
70 } | 68 } |
71 | 69 |
72 case ui::ET_GESTURE_PINCH_UPDATE: { | 70 case ui::ET_GESTURE_PINCH_UPDATE: { |
(...skipping 12 matching lines...) Expand all Loading... |
85 phantom_state_ = PHANTOM_WINDOW_NORMAL; | 83 phantom_state_ = PHANTOM_WINDOW_NORMAL; |
86 | 84 |
87 if (event.details().swipe_left() || event.details().swipe_right()) { | 85 if (event.details().swipe_left() || event.details().swipe_right()) { |
88 // Snap for left/right swipes. | 86 // Snap for left/right swipes. |
89 ui::ScopedLayerAnimationSettings settings( | 87 ui::ScopedLayerAnimationSettings settings( |
90 target_->layer()->GetAnimator()); | 88 target_->layer()->GetAnimator()); |
91 internal::SnapSizer::SnapWindow(target_, | 89 internal::SnapSizer::SnapWindow(target_, |
92 event.details().swipe_left() ? internal::SnapSizer::LEFT_EDGE : | 90 event.details().swipe_left() ? internal::SnapSizer::LEFT_EDGE : |
93 internal::SnapSizer::RIGHT_EDGE); | 91 internal::SnapSizer::RIGHT_EDGE); |
94 } else if (event.details().swipe_up()) { | 92 } else if (event.details().swipe_up()) { |
95 if (!wm::IsWindowMaximized(target_) && | 93 if (!window_state->IsMaximizedOrFullscreen()) |
96 !wm::IsWindowFullscreen(target_)) | 94 window_state->Maximize(); |
97 wm::MaximizeWindow(target_); | |
98 } else if (event.details().swipe_down()) { | 95 } else if (event.details().swipe_down()) { |
99 wm::MinimizeWindow(target_); | 96 window_state->Minimize(); |
100 } else { | 97 } else { |
101 NOTREACHED() << "Swipe happened without a direction."; | 98 NOTREACHED() << "Swipe happened without a direction."; |
102 } | 99 } |
103 break; | 100 break; |
104 } | 101 } |
105 | 102 |
106 default: | 103 default: |
107 break; | 104 break; |
108 } | 105 } |
109 | 106 |
110 return SYSTEM_GESTURE_PROCESSED; | 107 return SYSTEM_GESTURE_PROCESSED; |
111 } | 108 } |
112 | 109 |
113 gfx::Rect SystemPinchHandler::GetPhantomWindowScreenBounds( | 110 gfx::Rect SystemPinchHandler::GetPhantomWindowScreenBounds( |
114 aura::Window* window, | 111 aura::Window* window, |
115 const gfx::Point& point) { | 112 const gfx::Point& point) { |
116 if (pinch_factor_ > kPinchThresholdForMaximize) { | 113 if (pinch_factor_ > kPinchThresholdForMaximize) { |
117 phantom_state_ = PHANTOM_WINDOW_MAXIMIZED; | 114 phantom_state_ = PHANTOM_WINDOW_MAXIMIZED; |
118 return ScreenAsh::ConvertRectToScreen( | 115 return ScreenAsh::ConvertRectToScreen( |
119 target_->parent(), | 116 target_->parent(), |
120 ScreenAsh::GetMaximizedWindowBoundsInParent(target_)); | 117 ScreenAsh::GetMaximizedWindowBoundsInParent(target_)); |
121 } | 118 } |
122 | 119 |
123 if (pinch_factor_ < kPinchThresholdForMinimize) { | 120 if (pinch_factor_ < kPinchThresholdForMinimize) { |
124 if (wm::IsWindowMaximized(window) || wm::IsWindowFullscreen(window)) { | 121 wm::WindowState* window_state = wm::GetWindowState(window); |
125 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); | 122 if (window_state->IsMaximizedOrFullscreen()) { |
126 if (restore) { | 123 if (window_state->HasRestoreBounds()) { |
127 phantom_state_ = PHANTOM_WINDOW_MINIMIZED; | 124 phantom_state_ = PHANTOM_WINDOW_MINIMIZED; |
128 return *restore; | 125 return window_state->GetRestoreBoundsInScreen(); |
129 } | 126 } |
130 return window->bounds(); | 127 return window->bounds(); |
131 } | 128 } |
132 | 129 |
133 gfx::Rect rect = GetMinimizeAnimationTargetBoundsInScreen(target_); | 130 gfx::Rect rect = GetMinimizeAnimationTargetBoundsInScreen(target_); |
134 if (!rect.IsEmpty()) | 131 if (!rect.IsEmpty()) |
135 rect.Inset(-8, -8); | 132 rect.Inset(-8, -8); |
136 phantom_state_ = PHANTOM_WINDOW_MINIMIZED; | 133 phantom_state_ = PHANTOM_WINDOW_MINIMIZED; |
137 return rect; | 134 return rect; |
138 } | 135 } |
139 | 136 |
140 phantom_state_ = PHANTOM_WINDOW_NORMAL; | 137 phantom_state_ = PHANTOM_WINDOW_NORMAL; |
141 return window->bounds(); | 138 return window->bounds(); |
142 } | 139 } |
143 | 140 |
144 } // namespace internal | 141 } // namespace internal |
145 } // namespace ash | 142 } // namespace ash |
OLD | NEW |