Chromium Code Reviews| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 Shell::GetInstance()->accelerator_controller()->PerformAction( | 124 Shell::GetInstance()->accelerator_controller()->PerformAction( |
| 125 ash::TAKE_SCREENSHOT, ui::Accelerator()); | 125 ash::TAKE_SCREENSHOT, ui::Accelerator()); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 #endif // OS_CHROMEOS | 129 #endif // OS_CHROMEOS |
| 130 | 130 |
| 131 } // namespace | 131 } // namespace |
| 132 | 132 |
| 133 MaximizeModeController::MaximizeModeController() | 133 MaximizeModeController::MaximizeModeController() |
| 134 : rotation_locked_(false), | 134 : accelerometer_setting_rotation_(false), |
| 135 have_seen_accelerometer_data_(false) { | 135 rotation_locked_(false), |
| 136 have_seen_accelerometer_data_(false), | |
| 137 user_rotation_(gfx::Display::ROTATE_0) { | |
| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 float angle = ClockwiseAngleBetweenVectorsInDegrees(base_flattened, | 198 float angle = ClockwiseAngleBetweenVectorsInDegrees(base_flattened, |
| 197 lid_flattened, hinge_vector); | 199 lid_flattened, hinge_vector); |
| 198 | 200 |
| 199 // Toggle maximize mode on or off when corresponding thresholds are passed. | 201 // Toggle maximize mode on or off when corresponding thresholds are passed. |
| 200 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager | 202 // TODO(flackr): Make MaximizeModeController own the MaximizeModeWindowManager |
| 201 // such that observations of state changes occur after the change and shell | 203 // such that observations of state changes occur after the change and shell |
| 202 // has fewer states to track. | 204 // has fewer states to track. |
| 203 if (maximize_mode_engaged && | 205 if (maximize_mode_engaged && |
| 204 angle > kFullyOpenAngleErrorTolerance && | 206 angle > kFullyOpenAngleErrorTolerance && |
| 205 angle < kExitMaximizeModeAngle) { | 207 angle < kExitMaximizeModeAngle) { |
| 206 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 208 LeaveMaximizeMode(); |
| 207 event_blocker_.reset(); | |
| 208 event_handler_.reset(); | |
| 209 } else if (!maximize_mode_engaged && | 209 } else if (!maximize_mode_engaged && |
| 210 angle > kEnterMaximizeModeAngle) { | 210 angle > kEnterMaximizeModeAngle) { |
| 211 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | 211 EnterMaximizeMode(); |
| 212 event_blocker_.reset(new MaximizeModeEventBlocker); | |
| 213 #if defined(OS_CHROMEOS) | |
| 214 event_handler_.reset(new ScreenshotActionHandler); | |
| 215 #endif | |
| 216 } | 212 } |
| 217 } | 213 } |
| 218 | 214 |
| 219 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { | 215 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
| 220 bool maximize_mode_engaged = | 216 bool maximize_mode_engaged = |
| 221 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 217 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
| 222 | 218 |
| 219 if (!maximize_mode_engaged || rotation_locked_) | |
| 220 return; | |
| 221 | |
| 223 DisplayManager* display_manager = | 222 DisplayManager* display_manager = |
| 224 Shell::GetInstance()->display_manager(); | 223 Shell::GetInstance()->display_manager(); |
| 225 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( | 224 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( |
| 226 gfx::Display::InternalDisplayId()).rotation(); | 225 gfx::Display::InternalDisplayId()).rotation(); |
| 227 | 226 |
| 228 // If maximize mode is not engaged, ensure the screen is not rotated and | |
| 229 // do not rotate to match the current device orientation. | |
| 230 if (!maximize_mode_engaged) { | |
| 231 if (current_rotation != gfx::Display::ROTATE_0) { | |
| 232 // 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 | |
| 234 // back to ROTATE_0 if it was last set by the accelerometer. | |
| 235 // Also, SetDisplayRotation will save the setting to the local store, | |
| 236 // this should be stored in a way that we can distinguish what the | |
| 237 // rotation was set by. | |
| 238 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | |
| 239 gfx::Display::ROTATE_0); | |
| 240 } | |
| 241 rotation_locked_ = false; | |
| 242 return; | |
| 243 } | |
| 244 | |
| 245 if (rotation_locked_) | |
| 246 return; | |
| 247 | |
| 248 // After determining maximize mode state, determine if the screen should | 227 // After determining maximize mode state, determine if the screen should |
| 249 // be rotated. | 228 // be rotated. |
| 250 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); | 229 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); |
| 251 float lid_flattened_length = lid_flattened.Length(); | 230 float lid_flattened_length = lid_flattened.Length(); |
| 252 // When the lid is close to being flat, don't change rotation as it is too | 231 // When the lid is close to being flat, don't change rotation as it is too |
| 253 // sensitive to slight movements. | 232 // sensitive to slight movements. |
| 254 if (lid_flattened_length < kMinimumAccelerationScreenRotation) | 233 if (lid_flattened_length < kMinimumAccelerationScreenRotation) |
| 255 return; | 234 return; |
| 256 | 235 |
| 257 // The reference vector is the angle of gravity when the device is rotated | 236 // The reference vector is the angle of gravity when the device is rotated |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 283 lid_flattened, gfx::Vector3dF(0.0f, 0.0f, -1.0f)); | 262 lid_flattened, gfx::Vector3dF(0.0f, 0.0f, -1.0f)); |
| 284 | 263 |
| 285 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; | 264 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; |
| 286 if (angle < 90.0f) | 265 if (angle < 90.0f) |
| 287 new_rotation = gfx::Display::ROTATE_0; | 266 new_rotation = gfx::Display::ROTATE_0; |
| 288 else if (angle < 180.0f) | 267 else if (angle < 180.0f) |
| 289 new_rotation = gfx::Display::ROTATE_270; | 268 new_rotation = gfx::Display::ROTATE_270; |
| 290 else if (angle < 270.0f) | 269 else if (angle < 270.0f) |
| 291 new_rotation = gfx::Display::ROTATE_180; | 270 new_rotation = gfx::Display::ROTATE_180; |
| 292 | 271 |
| 293 // When exiting maximize mode return rotation to 0. When entering, rotate to | 272 // When setting a new rotation set flag so that display configuration changes |
| 294 // match screen orientation. | 273 // are not saved. |
| 295 if (new_rotation == gfx::Display::ROTATE_0 || | 274 if (new_rotation != current_rotation) { |
| 296 maximize_mode_engaged) { | 275 accelerometer_setting_rotation_ = true; |
|
flackr
2014/05/23 15:30:58
nit: use base::AutoReset.
| |
| 297 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 276 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
| 298 new_rotation); | 277 new_rotation); |
| 278 accelerometer_setting_rotation_ = false; | |
| 299 } | 279 } |
| 300 } | 280 } |
| 301 | 281 |
| 282 void MaximizeModeController::EnterMaximizeMode() { | |
| 283 // TODO(jonross): Listen for display configuration changes. If the user | |
| 284 // causes a rotation change a rotation lock should be applied. | |
| 285 // https://crbug.com/369505 | |
| 286 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 287 user_rotation_ = display_manager-> | |
| 288 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | |
| 289 rotation_locked_ = user_rotation_ != gfx::Display::ROTATE_0; | |
|
flackr
2014/05/23 15:30:58
I think the consensus was that we don't want to lo
jonross
2014/05/23 19:07:20
Done.
| |
| 290 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | |
| 291 event_blocker_.reset(new MaximizeModeEventBlocker); | |
| 292 #if defined(OS_CHROMEOS) | |
| 293 event_handler_.reset(new ScreenshotActionHandler); | |
| 294 #endif | |
| 295 } | |
| 296 | |
| 297 void MaximizeModeController::LeaveMaximizeMode() { | |
| 298 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 299 DisplayInfo info = display_manager-> | |
| 300 GetDisplayInfo(gfx::Display::InternalDisplayId()); | |
| 301 gfx::Display::Rotation current_rotation = info.rotation(); | |
| 302 if (current_rotation != user_rotation_) { | |
| 303 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | |
| 304 user_rotation_); | |
| 305 } | |
| 306 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | |
| 307 event_blocker_.reset(); | |
| 308 event_handler_.reset(); | |
| 309 } | |
| 310 | |
| 302 } // namespace ash | 311 } // namespace ash |
| OLD | NEW |