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/accelerometer/accelerometer_controller.h" | 7 #include "ash/accelerometer/accelerometer_controller.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" | 10 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" |
| 11 #include "ui/gfx/vector3d_f.h" | 11 #include "ui/gfx/vector3d_f.h" |
| 12 #include "ui/message_center/message_center.h" | |
| 13 #include "ui/message_center/notification_blocker.h" | |
| 12 | 14 |
| 13 namespace ash { | 15 namespace ash { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 // The hinge angle at which to enter maximize mode. | 19 // The hinge angle at which to enter maximize mode. |
| 18 const float kEnterMaximizeModeAngle = 200.0f; | 20 const float kEnterMaximizeModeAngle = 200.0f; |
| 19 | 21 |
| 20 // The angle at which to exit maximize mode, this is specifically less than the | 22 // The angle at which to exit maximize mode, this is specifically less than the |
| 21 // angle to enter maximize mode to prevent rapid toggling when near the angle. | 23 // angle to enter maximize mode to prevent rapid toggling when near the angle. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 49 // rotate to match it (i.e. 45.0f is no stickiness). | 51 // rotate to match it (i.e. 45.0f is no stickiness). |
| 50 const float kDisplayRotationStickyAngleDegrees = 60.0f; | 52 const float kDisplayRotationStickyAngleDegrees = 60.0f; |
| 51 | 53 |
| 52 // The minimum acceleration in a direction required to trigger screen rotation. | 54 // The minimum acceleration in a direction required to trigger screen rotation. |
| 53 // This prevents rapid toggling of rotation when the device is near flat and | 55 // This prevents rapid toggling of rotation when the device is near flat and |
| 54 // there is very little screen aligned force on it. | 56 // there is very little screen aligned force on it. |
| 55 const float kMinimumAccelerationScreenRotation = 0.3f; | 57 const float kMinimumAccelerationScreenRotation = 0.3f; |
| 56 | 58 |
| 57 const float kRadiansToDegrees = 180.0f / 3.14159265f; | 59 const float kRadiansToDegrees = 180.0f / 3.14159265f; |
| 58 | 60 |
| 61 // A message centre notification blocker used to suppress screen rotation | |
|
flackr
2014/05/05 20:26:54
nit: s/centre/center
bruthig
2014/05/05 20:57:22
Done.
| |
| 62 // events caused by accelerometer events | |
| 63 class ScopedNotificationBlocker | |
| 64 : public message_center::NotificationBlocker { | |
| 65 public: | |
| 66 ScopedNotificationBlocker(); | |
| 67 | |
|
flackr
2014/05/05 20:26:54
nit: no newline needed between constructor and des
bruthig
2014/05/05 20:57:22
Done.
| |
| 68 virtual ~ScopedNotificationBlocker(); | |
| 69 | |
| 70 private: | |
| 71 // Overriden from message_center::NotificationBlocker. | |
| 72 virtual bool ShouldShowNotificationAsPopup( | |
| 73 const message_center::NotifierId& notifier_id) const OVERRIDE; | |
| 74 | |
| 75 // Overriden from message_center::NotificationBlocker. | |
| 76 virtual bool ShouldShowNotification( | |
| 77 const message_center::NotifierId& notifier_id) const OVERRIDE; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(ScopedNotificationBlocker); | |
| 80 }; | |
| 81 | |
| 82 ScopedNotificationBlocker::ScopedNotificationBlocker() | |
| 83 : message_center::NotificationBlocker( | |
| 84 message_center::MessageCenter::Get()) { | |
|
flackr
2014/05/05 20:26:54
nit: indent 4 more to show it's part of the previo
bruthig
2014/05/05 20:57:22
Done.
| |
| 85 NotifyBlockingStateChanged(); | |
| 86 } | |
| 87 | |
| 88 ScopedNotificationBlocker::~ScopedNotificationBlocker() { | |
| 89 } | |
| 90 | |
| 91 bool ScopedNotificationBlocker::ShouldShowNotificationAsPopup( | |
| 92 const message_center::NotifierId& notifier_id) const { | |
| 93 return false; | |
| 94 } | |
| 95 | |
| 96 bool ScopedNotificationBlocker::ShouldShowNotification( | |
| 97 const message_center::NotifierId& notifier_id) const { | |
| 98 return false; | |
| 99 } | |
| 100 | |
| 59 // Returns the angle between |base| and |other| in degrees. | 101 // Returns the angle between |base| and |other| in degrees. |
| 60 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, | 102 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, |
| 61 const gfx::Vector3dF& other) { | 103 const gfx::Vector3dF& other) { |
| 62 return acos(gfx::DotProduct(base, other) / | 104 return acos(gfx::DotProduct(base, other) / |
| 63 base.Length() / other.Length()) * kRadiansToDegrees; | 105 base.Length() / other.Length()) * kRadiansToDegrees; |
| 64 } | 106 } |
| 65 | 107 |
| 66 // Returns the clockwise angle between |base| and |other| where |normal| is the | 108 // Returns the clockwise angle between |base| and |other| where |normal| is the |
| 67 // normal of the virtual surface to measure clockwise according to. | 109 // normal of the virtual surface to measure clockwise according to. |
| 68 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, | 110 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 // If maximize mode is not engaged, ensure the screen is not rotated and | 204 // If maximize mode is not engaged, ensure the screen is not rotated and |
| 163 // do not rotate to match the current device orientation. | 205 // do not rotate to match the current device orientation. |
| 164 if (!maximize_mode_engaged) { | 206 if (!maximize_mode_engaged) { |
| 165 if (current_rotation != gfx::Display::ROTATE_0) { | 207 if (current_rotation != gfx::Display::ROTATE_0) { |
| 166 // TODO(flackr): Currently this will prevent setting a manual rotation on | 208 // TODO(flackr): Currently this will prevent setting a manual rotation on |
| 167 // the screen of a device with an accelerometer, this should only set it | 209 // the screen of a device with an accelerometer, this should only set it |
| 168 // back to ROTATE_0 if it was last set by the accelerometer. | 210 // back to ROTATE_0 if it was last set by the accelerometer. |
| 169 // Also, SetDisplayRotation will save the setting to the local store, | 211 // Also, SetDisplayRotation will save the setting to the local store, |
| 170 // this should be stored in a way that we can distinguish what the | 212 // this should be stored in a way that we can distinguish what the |
| 171 // rotation was set by. | 213 // rotation was set by. |
| 172 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 214 SetDisplayRotation(display_manager, |
| 173 gfx::Display::ROTATE_0); | 215 gfx::Display::InternalDisplayId(), |
| 216 gfx::Display::ROTATE_0); | |
| 174 } | 217 } |
| 175 rotation_locked_ = false; | 218 rotation_locked_ = false; |
| 176 return; | 219 return; |
| 177 } | 220 } |
| 178 | 221 |
| 179 if (rotation_locked_) | 222 if (rotation_locked_) |
| 180 return; | 223 return; |
| 181 | 224 |
| 182 // After determining maximize mode state, determine if the screen should | 225 // After determining maximize mode state, determine if the screen should |
| 183 // be rotated. | 226 // be rotated. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 new_rotation = gfx::Display::ROTATE_0; | 264 new_rotation = gfx::Display::ROTATE_0; |
| 222 else if (angle < 180.0f) | 265 else if (angle < 180.0f) |
| 223 new_rotation = gfx::Display::ROTATE_270; | 266 new_rotation = gfx::Display::ROTATE_270; |
| 224 else if (angle < 270.0f) | 267 else if (angle < 270.0f) |
| 225 new_rotation = gfx::Display::ROTATE_180; | 268 new_rotation = gfx::Display::ROTATE_180; |
| 226 | 269 |
| 227 // When exiting maximize mode return rotation to 0. When entering, rotate to | 270 // When exiting maximize mode return rotation to 0. When entering, rotate to |
| 228 // match screen orientation. | 271 // match screen orientation. |
| 229 if (new_rotation == gfx::Display::ROTATE_0 || | 272 if (new_rotation == gfx::Display::ROTATE_0 || |
| 230 maximize_mode_engaged) { | 273 maximize_mode_engaged) { |
| 231 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 274 SetDisplayRotation(display_manager, |
| 232 new_rotation); | 275 gfx::Display::InternalDisplayId(), |
| 276 new_rotation); | |
| 233 } | 277 } |
| 234 } | 278 } |
| 235 | 279 |
| 280 void MaximizeModeController::SetDisplayRotation( | |
| 281 DisplayManager* display_manager, | |
| 282 int64 display_id, | |
| 283 gfx::Display::Rotation rotation) const { | |
| 284 // Suppress message centre notifications for screen rotations caused | |
| 285 // by accelerometer events because it should be obvious why the orientation | |
| 286 // changed. | |
| 287 ScopedNotificationBlocker notification_blocker; | |
| 288 display_manager->SetDisplayRotation(display_id, rotation); | |
| 289 } | |
| 290 | |
| 236 } // namespace ash | 291 } // namespace ash |
| OLD | NEW |