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