OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/border_gesture_handler.h" | 5 #include "ash/wm/gestures/border_gesture_handler.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
9 #include "ash/shelf/shelf_types.h" | 9 #include "ash/shelf/shelf_types.h" |
10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/wm/property_util.h" | |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "ui/aura/window.h" | |
15 #include "ui/base/events/event.h" | 17 #include "ui/base/events/event.h" |
16 #include "ui/base/ui_base_switches.h" | 18 #include "ui/base/ui_base_switches.h" |
17 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
18 | 20 |
19 namespace ash { | 21 namespace ash { |
20 namespace internal { | 22 namespace internal { |
21 namespace { | 23 namespace { |
22 | 24 |
23 // How far from the edge of the display a gesture can start and be considered an | 25 // How far from the edge of the display a gesture can start and be considered an |
24 // edge gesture. | 26 // edge gesture. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 gfx::Rect screen = | 58 gfx::Rect screen = |
57 Shell::GetScreen()->GetDisplayNearestWindow(target).bounds(); | 59 Shell::GetScreen()->GetDisplayNearestWindow(target).bounds(); |
58 if (!screen.Contains(event.location())) { | 60 if (!screen.Contains(event.location())) { |
59 return true; | 61 return true; |
60 } | 62 } |
61 break; | 63 break; |
62 } | 64 } |
63 return false; | 65 return false; |
64 } | 66 } |
65 | 67 |
68 bool BorderGestureHandler::HandleImmersiveControl( | |
69 aura::Window* target, | |
70 const ui::GestureEvent& event) { | |
71 // If not in immersive mode let the gesture pass through | |
72 if (!GetRootWindowController(target->GetRootWindow())->IsImmersiveMode()) | |
73 return false; | |
74 | |
75 switch (event.type()) { | |
76 case ui::ET_GESTURE_SCROLL_BEGIN: | |
77 return true; | |
78 case ui::ET_GESTURE_SCROLL_UPDATE: | |
79 GetRootWindowController( | |
80 target->GetRootWindow())->SetPendingImmersiveGesture(true); | |
sadrul
2013/04/19 01:41:20
I think you should do this in SCROLL_BEGIN
rharrison
2013/04/22 18:36:52
I agree, I suspect this is a typo
| |
81 return true; | |
82 case ui::ET_GESTURE_SCROLL_END: | |
83 case ui::ET_SCROLL_FLING_START: | |
84 return true; | |
85 default: | |
86 return false; | |
87 } | |
88 } | |
89 | |
66 bool BorderGestureHandler::HandleLauncherControl( | 90 bool BorderGestureHandler::HandleLauncherControl( |
67 const ui::GestureEvent& event) { | 91 const ui::GestureEvent& event) { |
68 ShelfLayoutManager* shelf = | 92 ShelfLayoutManager* shelf = |
69 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); | 93 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); |
70 switch (shelf->GetAlignment()) { | 94 switch (shelf->GetAlignment()) { |
71 case SHELF_ALIGNMENT_BOTTOM: | 95 case SHELF_ALIGNMENT_BOTTOM: |
72 if (start_location_.test(BORDER_LOCATION_BOTTOM)) | 96 if (start_location_.test(BORDER_LOCATION_BOTTOM)) |
73 return shelf_handler_.ProcessGestureEvent(event); | 97 return shelf_handler_.ProcessGestureEvent(event); |
74 break; | 98 break; |
75 case SHELF_ALIGNMENT_LEFT: | 99 case SHELF_ALIGNMENT_LEFT: |
76 if (start_location_.test(BORDER_LOCATION_LEFT)) | 100 if (start_location_.test(BORDER_LOCATION_LEFT)) |
77 return shelf_handler_.ProcessGestureEvent(event); | 101 return shelf_handler_.ProcessGestureEvent(event); |
78 break; | 102 break; |
79 case SHELF_ALIGNMENT_TOP: | 103 case SHELF_ALIGNMENT_TOP: |
80 if (start_location_.test(BORDER_LOCATION_TOP)) | 104 NOTREACHED(); |
81 return shelf_handler_.ProcessGestureEvent(event); | |
82 break; | 105 break; |
83 case SHELF_ALIGNMENT_RIGHT: | 106 case SHELF_ALIGNMENT_RIGHT: |
84 if (start_location_.test(BORDER_LOCATION_RIGHT)) | 107 if (start_location_.test(BORDER_LOCATION_RIGHT)) |
85 return shelf_handler_.ProcessGestureEvent(event); | 108 return shelf_handler_.ProcessGestureEvent(event); |
86 break; | 109 break; |
87 } | 110 } |
88 return false; | 111 return false; |
89 } | 112 } |
90 | 113 |
91 bool BorderGestureHandler::HandleBorderGestureStart( | 114 bool BorderGestureHandler::HandleBorderGestureStart( |
92 aura::Window* target, | 115 aura::Window* target, |
93 const ui::GestureEvent& event) { | 116 const ui::GestureEvent& event) { |
94 orientation_ = BORDER_SCROLL_ORIENTATION_UNSET; | 117 orientation_ = BORDER_SCROLL_ORIENTATION_UNSET; |
95 start_location_.reset(); | 118 start_location_.reset(); |
96 | 119 |
97 gfx::Rect screen = | 120 gfx::Rect screen = |
98 Shell::GetScreen()->GetDisplayNearestWindow(target).bounds(); | 121 Shell::GetScreen()->GetDisplayNearestWindow(target).bounds(); |
99 GestureStartInTargetArea(screen, event); | 122 GestureStartInTargetArea(screen, event); |
100 | 123 |
101 if (start_location_.any()) | 124 if (start_location_.test(BORDER_LOCATION_TOP)) |
125 return HandleImmersiveControl(target, event); | |
126 if (start_location_.test(BORDER_LOCATION_BOTTOM) || | |
127 start_location_.test(BORDER_LOCATION_LEFT) || | |
128 start_location_.test(BORDER_LOCATION_RIGHT)) | |
102 return HandleLauncherControl(event); | 129 return HandleLauncherControl(event); |
103 return false; | 130 return false; |
104 } | 131 } |
105 | 132 |
106 bool BorderGestureHandler::HandleBorderGestureUpdate( | 133 bool BorderGestureHandler::HandleBorderGestureUpdate( |
107 aura::Window* target, | 134 aura::Window* target, |
108 const ui::GestureEvent& event) { | 135 const ui::GestureEvent& event) { |
136 if (IsGestureInImmersiveOrientation(event)) | |
137 return HandleImmersiveControl(target, event); | |
109 if (IsGestureInLauncherOrientation(event)) | 138 if (IsGestureInLauncherOrientation(event)) |
110 return HandleLauncherControl(event); | 139 return HandleLauncherControl(event); |
111 return false; | 140 return false; |
112 } | 141 } |
113 | 142 |
114 bool BorderGestureHandler::HandleBorderGestureEnd( | 143 bool BorderGestureHandler::HandleBorderGestureEnd( |
115 aura::Window* target, | 144 aura::Window* target, |
116 const ui::GestureEvent& event) { | 145 const ui::GestureEvent& event) { |
117 bool ret_val = HandleLauncherControl(event); | 146 bool ret_val = false; |
147 if (IsGestureInImmersiveOrientation(event)) | |
148 ret_val = HandleImmersiveControl(target, event); | |
149 if (IsGestureInLauncherOrientation(event)) | |
150 ret_val = HandleLauncherControl(event); | |
118 start_location_.reset(); | 151 start_location_.reset(); |
119 return ret_val; | 152 return ret_val; |
120 } | 153 } |
121 | 154 |
122 void BorderGestureHandler::GestureStartInTargetArea( | 155 void BorderGestureHandler::GestureStartInTargetArea( |
123 const gfx::Rect& screen, | 156 const gfx::Rect& screen, |
124 const ui::GestureEvent& event) { | 157 const ui::GestureEvent& event) { |
125 if (event.y() > screen.bottom() - kBottomEdgeThreshold) | 158 if (event.y() > screen.bottom() - kBottomEdgeThreshold) |
126 start_location_[BORDER_LOCATION_BOTTOM] = 1; | 159 start_location_[BORDER_LOCATION_BOTTOM] = 1; |
127 if (event.x() < screen.x() + kLeftEdgeThreshold) | 160 if (event.x() < screen.x() + kLeftEdgeThreshold) |
(...skipping 10 matching lines...) Expand all Loading... | |
138 if (!event.details().scroll_x() && !event.details().scroll_y()) | 171 if (!event.details().scroll_x() && !event.details().scroll_y()) |
139 return false; | 172 return false; |
140 orientation_ = abs(event.details().scroll_y()) > | 173 orientation_ = abs(event.details().scroll_y()) > |
141 abs(event.details().scroll_x()) ? | 174 abs(event.details().scroll_x()) ? |
142 BORDER_SCROLL_ORIENTATION_VERTICAL : | 175 BORDER_SCROLL_ORIENTATION_VERTICAL : |
143 BORDER_SCROLL_ORIENTATION_HORIZONTAL; | 176 BORDER_SCROLL_ORIENTATION_HORIZONTAL; |
144 } | 177 } |
145 return true; | 178 return true; |
146 } | 179 } |
147 | 180 |
181 bool BorderGestureHandler::IsGestureInImmersiveOrientation( | |
182 const ui::GestureEvent& event) { | |
183 if (ui::ET_GESTURE_SCROLL_UPDATE == event.type()) { | |
184 BorderScrollOrientation new_orientation = abs(event.details().scroll_y()) > | |
185 abs(event.details().scroll_x()) ? | |
186 BORDER_SCROLL_ORIENTATION_VERTICAL : | |
187 BORDER_SCROLL_ORIENTATION_HORIZONTAL; | |
188 if (new_orientation != orientation_) | |
189 return false; | |
190 } | |
191 | |
192 if (start_location_.test(BORDER_LOCATION_TOP) && | |
193 orientation_ == BORDER_SCROLL_ORIENTATION_VERTICAL) | |
194 return true; | |
195 return false; | |
196 } | |
197 | |
148 bool BorderGestureHandler::IsGestureInLauncherOrientation( | 198 bool BorderGestureHandler::IsGestureInLauncherOrientation( |
149 const ui::GestureEvent& event) { | 199 const ui::GestureEvent& event) { |
150 BorderScrollOrientation new_orientation = abs(event.details().scroll_y()) > | 200 if (ui::ET_GESTURE_SCROLL_UPDATE == event.type()) { |
151 abs(event.details().scroll_x()) ? | 201 BorderScrollOrientation new_orientation = abs(event.details().scroll_y()) > |
152 BORDER_SCROLL_ORIENTATION_VERTICAL : BORDER_SCROLL_ORIENTATION_HORIZONTAL; | 202 abs(event.details().scroll_x()) ? |
153 if (new_orientation != orientation_) | 203 BORDER_SCROLL_ORIENTATION_VERTICAL : |
154 return false; | 204 BORDER_SCROLL_ORIENTATION_HORIZONTAL; |
205 if (new_orientation != orientation_) | |
206 return false; | |
207 } | |
155 | 208 |
156 ShelfLayoutManager* shelf = | 209 ShelfLayoutManager* shelf = |
157 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); | 210 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); |
158 switch (shelf->GetAlignment()) { | 211 switch (shelf->GetAlignment()) { |
159 case SHELF_ALIGNMENT_BOTTOM: | 212 case SHELF_ALIGNMENT_BOTTOM: |
160 if (orientation_ == BORDER_SCROLL_ORIENTATION_VERTICAL) | 213 if (orientation_ == BORDER_SCROLL_ORIENTATION_VERTICAL) |
161 return true; | 214 return true; |
162 break; | 215 break; |
163 case SHELF_ALIGNMENT_LEFT: | 216 case SHELF_ALIGNMENT_LEFT: |
164 if (orientation_ == BORDER_SCROLL_ORIENTATION_HORIZONTAL) | 217 if (orientation_ == BORDER_SCROLL_ORIENTATION_HORIZONTAL) |
165 return true; | 218 return true; |
166 break; | 219 break; |
167 case SHELF_ALIGNMENT_TOP: | 220 case SHELF_ALIGNMENT_TOP: |
168 if (orientation_ == BORDER_SCROLL_ORIENTATION_VERTICAL) | 221 NOTREACHED(); |
169 return true; | |
170 break; | 222 break; |
171 case SHELF_ALIGNMENT_RIGHT: | 223 case SHELF_ALIGNMENT_RIGHT: |
172 if (orientation_ == BORDER_SCROLL_ORIENTATION_HORIZONTAL) | 224 if (orientation_ == BORDER_SCROLL_ORIENTATION_HORIZONTAL) |
173 return true; | 225 return true; |
174 break; | 226 break; |
175 } | 227 } |
176 return false; | 228 return false; |
177 } | 229 } |
178 | 230 |
179 } // namespace internal | 231 } // namespace internal |
180 } // namespace ash | 232 } // namespace ash |
OLD | NEW |