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 | |
62 // events caused by accelerometer events | |
63 class ScreenRotationNotificationBlocker | |
flackr
2014/05/05 19:06:00
nit: Just call this ScopedNotificationBlocker. It
bruthig
2014/05/05 19:35:35
Done.
| |
64 : public message_center::NotificationBlocker { | |
65 public: | |
66 ScreenRotationNotificationBlocker() | |
flackr
2014/05/05 19:06:00
nit: I don't think any of these methods should be
bruthig
2014/05/05 19:35:35
Done.
| |
67 : message_center::NotificationBlocker( | |
68 message_center::MessageCenter::Get()) { | |
69 NotifyBlockingStateChanged(); | |
70 } | |
71 | |
72 virtual ~ScreenRotationNotificationBlocker() { | |
73 }; | |
74 | |
75 private: | |
76 // Overriden from message_center::NotificationBlocker. | |
77 virtual bool ShouldShowNotificationAsPopup( | |
78 const message_center::NotifierId& notifier_id) const OVERRIDE { | |
79 return false; | |
80 } | |
81 | |
82 // Overriden from message_center::NotificationBlocker. | |
83 virtual bool ShouldShowNotification( | |
84 const message_center::NotifierId& notifier_id) const OVERRIDE { | |
85 return false; | |
86 } | |
87 | |
88 DISALLOW_COPY_AND_ASSIGN(ScreenRotationNotificationBlocker); | |
89 }; | |
90 | |
59 // Returns the angle between |base| and |other| in degrees. | 91 // Returns the angle between |base| and |other| in degrees. |
60 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, | 92 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, |
61 const gfx::Vector3dF& other) { | 93 const gfx::Vector3dF& other) { |
62 return acos(gfx::DotProduct(base, other) / | 94 return acos(gfx::DotProduct(base, other) / |
63 base.Length() / other.Length()) * kRadiansToDegrees; | 95 base.Length() / other.Length()) * kRadiansToDegrees; |
64 } | 96 } |
65 | 97 |
66 // Returns the clockwise angle between |base| and |other| where |normal| is the | 98 // Returns the clockwise angle between |base| and |other| where |normal| is the |
67 // normal of the virtual surface to measure clockwise according to. | 99 // normal of the virtual surface to measure clockwise according to. |
68 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, | 100 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 float lid_magnitude = lid.Length(); | 132 float lid_magnitude = lid.Length(); |
101 if (std::abs(base_magnitude - lid_magnitude) > kNoisyMagnitudeDeviation || | 133 if (std::abs(base_magnitude - lid_magnitude) > kNoisyMagnitudeDeviation || |
102 std::abs(base_magnitude - 1.0f) > kDeviationFromGravityThreshold || | 134 std::abs(base_magnitude - 1.0f) > kDeviationFromGravityThreshold || |
103 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { | 135 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { |
104 return; | 136 return; |
105 } | 137 } |
106 | 138 |
107 // Responding to the hinge rotation can change the maximize mode state which | 139 // Responding to the hinge rotation can change the maximize mode state which |
108 // affects screen rotation, so we handle hinge rotation first. | 140 // affects screen rotation, so we handle hinge rotation first. |
109 HandleHingeRotation(base, lid); | 141 HandleHingeRotation(base, lid); |
110 HandleScreenRotation(lid); | 142 { |
143 // Suppress message centre notifications for screen rotations caused | |
144 // by accelerometer events because it should be obvious why the orientation | |
145 // changed. | |
146 ScreenRotationNotificationBlocker notification_blocker; | |
flackr
2014/05/05 19:06:00
This method (OnAccelerometerUpdated) is called fai
bruthig
2014/05/05 19:35:35
Done.
| |
147 HandleScreenRotation(lid); | |
148 } | |
111 } | 149 } |
112 | 150 |
113 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, | 151 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, |
114 const gfx::Vector3dF& lid) { | 152 const gfx::Vector3dF& lid) { |
115 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); | 153 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); |
116 bool maximize_mode_engaged = | 154 bool maximize_mode_engaged = |
117 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 155 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
118 // Ignore the component of acceleration parallel to the hinge for the purposes | 156 // Ignore the component of acceleration parallel to the hinge for the purposes |
119 // of hinge angle calculation. | 157 // of hinge angle calculation. |
120 gfx::Vector3dF base_flattened(base); | 158 gfx::Vector3dF base_flattened(base); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 // When exiting maximize mode return rotation to 0. When entering, rotate to | 265 // When exiting maximize mode return rotation to 0. When entering, rotate to |
228 // match screen orientation. | 266 // match screen orientation. |
229 if (new_rotation == gfx::Display::ROTATE_0 || | 267 if (new_rotation == gfx::Display::ROTATE_0 || |
230 maximize_mode_engaged) { | 268 maximize_mode_engaged) { |
231 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 269 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
232 new_rotation); | 270 new_rotation); |
233 } | 271 } |
234 } | 272 } |
235 | 273 |
236 } // namespace ash | 274 } // namespace ash |
OLD | NEW |