OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/maximize_mode/maximize_mode_controller.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
9 #include "ash/accelerometer/accelerometer_controller.h" | 9 #include "ash/accelerometer/accelerometer_controller.h" |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 #endif // OS_CHROMEOS | 130 #endif // OS_CHROMEOS |
131 | 131 |
132 } // namespace | 132 } // namespace |
133 | 133 |
134 MaximizeModeController::MaximizeModeController() | 134 MaximizeModeController::MaximizeModeController() |
135 : rotation_locked_(false), | 135 : rotation_locked_(false), |
136 have_seen_accelerometer_data_(false), | 136 have_seen_accelerometer_data_(false), |
137 in_set_screen_rotation_(false) { | 137 in_set_screen_rotation_(false), |
| 138 user_rotation_(gfx::Display::ROTATE_0) { |
138 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 139 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
139 } | 140 } |
140 | 141 |
141 MaximizeModeController::~MaximizeModeController() { | 142 MaximizeModeController::~MaximizeModeController() { |
142 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | 143 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); |
143 } | 144 } |
144 | 145 |
145 bool MaximizeModeController::CanEnterMaximizeMode() { | 146 bool MaximizeModeController::CanEnterMaximizeMode() { |
146 // If we have ever seen accelerometer data, then HandleHingeRotation may | 147 // If we have ever seen accelerometer data, then HandleHingeRotation may |
147 // trigger maximize mode at some point in the future. | 148 // trigger maximize mode at some point in the future. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 float angle = ClockwiseAngleBetweenVectorsInDegrees(base_flattened, | 199 float angle = ClockwiseAngleBetweenVectorsInDegrees(base_flattened, |
199 lid_flattened, hinge_vector); | 200 lid_flattened, hinge_vector); |
200 | 201 |
201 // Toggle maximize mode on or off when corresponding thresholds are passed. | 202 // Toggle maximize mode on or off when corresponding thresholds are passed. |
202 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager | 203 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager |
203 // such that observations of state changes occur after the change and shell | 204 // such that observations of state changes occur after the change and shell |
204 // has fewer states to track. | 205 // has fewer states to track. |
205 if (maximize_mode_engaged && | 206 if (maximize_mode_engaged && |
206 angle > kFullyOpenAngleErrorTolerance && | 207 angle > kFullyOpenAngleErrorTolerance && |
207 angle < kExitMaximizeModeAngle) { | 208 angle < kExitMaximizeModeAngle) { |
208 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 209 LeaveMaximizeMode(); |
209 event_blocker_.reset(); | |
210 event_handler_.reset(); | |
211 } else if (!maximize_mode_engaged && | 210 } else if (!maximize_mode_engaged && |
212 angle > kEnterMaximizeModeAngle) { | 211 angle > kEnterMaximizeModeAngle) { |
213 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | 212 EnterMaximizeMode(); |
214 event_blocker_.reset(new MaximizeModeEventBlocker); | |
215 #if defined(OS_CHROMEOS) | |
216 event_handler_.reset(new ScreenshotActionHandler); | |
217 #endif | |
218 } | 213 } |
219 } | 214 } |
220 | 215 |
221 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { | 216 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
222 bool maximize_mode_engaged = | 217 bool maximize_mode_engaged = |
223 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 218 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
224 | 219 |
| 220 if (!maximize_mode_engaged || rotation_locked_) |
| 221 return; |
| 222 |
225 DisplayManager* display_manager = | 223 DisplayManager* display_manager = |
226 Shell::GetInstance()->display_manager(); | 224 Shell::GetInstance()->display_manager(); |
227 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( | 225 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( |
228 gfx::Display::InternalDisplayId()).rotation(); | 226 gfx::Display::InternalDisplayId()).rotation(); |
229 | 227 |
230 // If maximize mode is not engaged, ensure the screen is not rotated and | |
231 // do not rotate to match the current device orientation. | |
232 if (!maximize_mode_engaged) { | |
233 if (current_rotation != gfx::Display::ROTATE_0) { | |
234 // TODO(flackr): Currently this will prevent setting a manual rotation on | |
235 // the screen of a device with an accelerometer, this should only set it | |
236 // back to ROTATE_0 if it was last set by the accelerometer. | |
237 // Also, SetDisplayRotation will save the setting to the local store, | |
238 // this should be stored in a way that we can distinguish what the | |
239 // rotation was set by. | |
240 SetDisplayRotation(display_manager, | |
241 gfx::Display::ROTATE_0); | |
242 } | |
243 rotation_locked_ = false; | |
244 return; | |
245 } | |
246 | |
247 if (rotation_locked_) | |
248 return; | |
249 | |
250 // After determining maximize mode state, determine if the screen should | 228 // After determining maximize mode state, determine if the screen should |
251 // be rotated. | 229 // be rotated. |
252 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); | 230 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); |
253 float lid_flattened_length = lid_flattened.Length(); | 231 float lid_flattened_length = lid_flattened.Length(); |
254 // When the lid is close to being flat, don't change rotation as it is too | 232 // When the lid is close to being flat, don't change rotation as it is too |
255 // sensitive to slight movements. | 233 // sensitive to slight movements. |
256 if (lid_flattened_length < kMinimumAccelerationScreenRotation) | 234 if (lid_flattened_length < kMinimumAccelerationScreenRotation) |
257 return; | 235 return; |
258 | 236 |
259 // The reference vector is the angle of gravity when the device is rotated | 237 // The reference vector is the angle of gravity when the device is rotated |
(...skipping 25 matching lines...) Expand all Loading... |
285 lid_flattened, gfx::Vector3dF(0.0f, 0.0f, -1.0f)); | 263 lid_flattened, gfx::Vector3dF(0.0f, 0.0f, -1.0f)); |
286 | 264 |
287 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; | 265 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; |
288 if (angle < 90.0f) | 266 if (angle < 90.0f) |
289 new_rotation = gfx::Display::ROTATE_0; | 267 new_rotation = gfx::Display::ROTATE_0; |
290 else if (angle < 180.0f) | 268 else if (angle < 180.0f) |
291 new_rotation = gfx::Display::ROTATE_270; | 269 new_rotation = gfx::Display::ROTATE_270; |
292 else if (angle < 270.0f) | 270 else if (angle < 270.0f) |
293 new_rotation = gfx::Display::ROTATE_180; | 271 new_rotation = gfx::Display::ROTATE_180; |
294 | 272 |
295 // When exiting maximize mode return rotation to 0. When entering, rotate to | 273 if (new_rotation != current_rotation) |
296 // match screen orientation. | 274 SetDisplayRotation(display_manager, new_rotation); |
297 if (new_rotation == gfx::Display::ROTATE_0 || | |
298 maximize_mode_engaged) { | |
299 SetDisplayRotation(display_manager, | |
300 new_rotation); | |
301 } | |
302 } | 275 } |
303 | 276 |
304 void MaximizeModeController::SetDisplayRotation( | 277 void MaximizeModeController::SetDisplayRotation( |
305 DisplayManager* display_manager, | 278 DisplayManager* display_manager, |
306 gfx::Display::Rotation rotation) { | 279 gfx::Display::Rotation rotation) { |
307 base::AutoReset<bool> auto_in_set_screen_rotation( | 280 base::AutoReset<bool> auto_in_set_screen_rotation( |
308 &in_set_screen_rotation_, true); | 281 &in_set_screen_rotation_, true); |
309 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 282 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
310 rotation); | 283 rotation); |
311 } | 284 } |
312 | 285 |
| 286 void MaximizeModeController::EnterMaximizeMode() { |
| 287 // TODO(jonross): Listen for display configuration changes. If the user |
| 288 // causes a rotation change a rotation lock should be applied. |
| 289 // https://crbug.com/369505 |
| 290 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 291 user_rotation_ = display_manager-> |
| 292 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 293 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); |
| 294 event_blocker_.reset(new MaximizeModeEventBlocker); |
| 295 #if defined(OS_CHROMEOS) |
| 296 event_handler_.reset(new ScreenshotActionHandler); |
| 297 #endif |
| 298 } |
| 299 |
| 300 void MaximizeModeController::LeaveMaximizeMode() { |
| 301 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 302 DisplayInfo info = display_manager-> |
| 303 GetDisplayInfo(gfx::Display::InternalDisplayId()); |
| 304 gfx::Display::Rotation current_rotation = info.rotation(); |
| 305 if (current_rotation != user_rotation_) |
| 306 SetDisplayRotation(display_manager, user_rotation_); |
| 307 rotation_locked_ = false; |
| 308 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); |
| 309 event_blocker_.reset(); |
| 310 event_handler_.reset(); |
| 311 } |
| 312 |
313 } // namespace ash | 313 } // namespace ash |
OLD | NEW |