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" |
11 #include "ash/display/display_manager.h" | 11 #include "ash/display/display_manager.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" | 13 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" |
14 #include "base/auto_reset.h" | |
15 #include "base/command_line.h" | 14 #include "base/command_line.h" |
16 #include "ui/base/accelerators/accelerator.h" | 15 #include "ui/base/accelerators/accelerator.h" |
17 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
18 #include "ui/events/event_handler.h" | 17 #include "ui/events/event_handler.h" |
19 #include "ui/events/keycodes/keyboard_codes.h" | 18 #include "ui/events/keycodes/keyboard_codes.h" |
20 #include "ui/gfx/vector3d_f.h" | 19 #include "ui/gfx/vector3d_f.h" |
21 | 20 |
22 namespace ash { | 21 namespace ash { |
23 | 22 |
24 namespace { | 23 namespace { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 ash::TAKE_SCREENSHOT, ui::Accelerator()); | 125 ash::TAKE_SCREENSHOT, ui::Accelerator()); |
127 } | 126 } |
128 } | 127 } |
129 | 128 |
130 #endif // OS_CHROMEOS | 129 #endif // OS_CHROMEOS |
131 | 130 |
132 } // namespace | 131 } // namespace |
133 | 132 |
134 MaximizeModeController::MaximizeModeController() | 133 MaximizeModeController::MaximizeModeController() |
135 : rotation_locked_(false), | 134 : rotation_locked_(false), |
136 have_seen_accelerometer_data_(false), | 135 have_seen_accelerometer_data_(false) { |
137 in_set_screen_rotation_(false) { | |
138 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 136 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
139 } | 137 } |
140 | 138 |
141 MaximizeModeController::~MaximizeModeController() { | 139 MaximizeModeController::~MaximizeModeController() { |
142 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | 140 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); |
143 } | 141 } |
144 | 142 |
145 bool MaximizeModeController::CanEnterMaximizeMode() { | 143 bool MaximizeModeController::CanEnterMaximizeMode() { |
146 // If we have ever seen accelerometer data, then HandleHingeRotation may | 144 // If we have ever seen accelerometer data, then HandleHingeRotation may |
147 // trigger maximize mode at some point in the future. | 145 // trigger maximize mode at some point in the future. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // If maximize mode is not engaged, ensure the screen is not rotated and | 228 // If maximize mode is not engaged, ensure the screen is not rotated and |
231 // do not rotate to match the current device orientation. | 229 // do not rotate to match the current device orientation. |
232 if (!maximize_mode_engaged) { | 230 if (!maximize_mode_engaged) { |
233 if (current_rotation != gfx::Display::ROTATE_0) { | 231 if (current_rotation != gfx::Display::ROTATE_0) { |
234 // TODO(flackr): Currently this will prevent setting a manual rotation on | 232 // 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 | 233 // 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. | 234 // back to ROTATE_0 if it was last set by the accelerometer. |
237 // Also, SetDisplayRotation will save the setting to the local store, | 235 // Also, SetDisplayRotation will save the setting to the local store, |
238 // this should be stored in a way that we can distinguish what the | 236 // this should be stored in a way that we can distinguish what the |
239 // rotation was set by. | 237 // rotation was set by. |
240 SetDisplayRotation(display_manager, | 238 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
241 gfx::Display::ROTATE_0); | 239 gfx::Display::ROTATE_0); |
242 } | 240 } |
243 rotation_locked_ = false; | 241 rotation_locked_ = false; |
244 return; | 242 return; |
245 } | 243 } |
246 | 244 |
247 if (rotation_locked_) | 245 if (rotation_locked_) |
248 return; | 246 return; |
249 | 247 |
250 // After determining maximize mode state, determine if the screen should | 248 // After determining maximize mode state, determine if the screen should |
251 // be rotated. | 249 // be rotated. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 new_rotation = gfx::Display::ROTATE_0; | 287 new_rotation = gfx::Display::ROTATE_0; |
290 else if (angle < 180.0f) | 288 else if (angle < 180.0f) |
291 new_rotation = gfx::Display::ROTATE_270; | 289 new_rotation = gfx::Display::ROTATE_270; |
292 else if (angle < 270.0f) | 290 else if (angle < 270.0f) |
293 new_rotation = gfx::Display::ROTATE_180; | 291 new_rotation = gfx::Display::ROTATE_180; |
294 | 292 |
295 // When exiting maximize mode return rotation to 0. When entering, rotate to | 293 // When exiting maximize mode return rotation to 0. When entering, rotate to |
296 // match screen orientation. | 294 // match screen orientation. |
297 if (new_rotation == gfx::Display::ROTATE_0 || | 295 if (new_rotation == gfx::Display::ROTATE_0 || |
298 maximize_mode_engaged) { | 296 maximize_mode_engaged) { |
299 SetDisplayRotation(display_manager, | 297 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
300 new_rotation); | 298 new_rotation); |
301 } | 299 } |
302 } | 300 } |
303 | 301 |
304 void MaximizeModeController::SetDisplayRotation( | |
305 DisplayManager* display_manager, | |
306 gfx::Display::Rotation rotation) { | |
307 base::AutoReset<bool> auto_in_set_screen_rotation( | |
308 &in_set_screen_rotation_, true); | |
309 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | |
310 rotation); | |
311 } | |
312 | |
313 } // namespace ash | 302 } // namespace ash |
OLD | NEW |