Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller.cc

Issue 267743010: Suppressed screen rotation notifications triggeres by the accelerometer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Rob's comments from patch set 2 Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ash/wm/maximize_mode/maximize_mode_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 center notification blocker used to suppress screen rotation
62 // events caused by accelerometer events
flackr 2014/05/05 21:12:12 nit: Punctuation.
bruthig 2014/05/08 17:50:02 Done.
63 class ScopedNotificationBlocker
64 : public message_center::NotificationBlocker {
65 public:
66 ScopedNotificationBlocker();
67 virtual ~ScopedNotificationBlocker();
68
69 private:
70 // Overriden from message_center::NotificationBlocker.
71 virtual bool ShouldShowNotificationAsPopup(
72 const message_center::NotifierId& notifier_id) const OVERRIDE;
73
74 // Overriden from message_center::NotificationBlocker.
75 virtual bool ShouldShowNotification(
76 const message_center::NotifierId& notifier_id) const OVERRIDE;
77
78 DISALLOW_COPY_AND_ASSIGN(ScopedNotificationBlocker);
79 };
80
81 ScopedNotificationBlocker::ScopedNotificationBlocker()
82 : message_center::NotificationBlocker(
83 message_center::MessageCenter::Get()) {
84 NotifyBlockingStateChanged();
flackr 2014/05/05 21:12:12 Will this cause us to remove other currently activ
bruthig 2014/05/08 17:50:02 Nope
bruthig 2014/05/08 17:50:02 Done.
85 }
86
87 ScopedNotificationBlocker::~ScopedNotificationBlocker() {
88 }
89
90 bool ScopedNotificationBlocker::ShouldShowNotificationAsPopup(
91 const message_center::NotifierId& notifier_id) const {
92 return false;
93 }
94
95 bool ScopedNotificationBlocker::ShouldShowNotification(
96 const message_center::NotifierId& notifier_id) const {
97 return false;
98 }
99
59 // Returns the angle between |base| and |other| in degrees. 100 // Returns the angle between |base| and |other| in degrees.
60 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, 101 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,
61 const gfx::Vector3dF& other) { 102 const gfx::Vector3dF& other) {
62 return acos(gfx::DotProduct(base, other) / 103 return acos(gfx::DotProduct(base, other) /
63 base.Length() / other.Length()) * kRadiansToDegrees; 104 base.Length() / other.Length()) * kRadiansToDegrees;
64 } 105 }
65 106
66 // Returns the clockwise angle between |base| and |other| where |normal| is the 107 // Returns the clockwise angle between |base| and |other| where |normal| is the
67 // normal of the virtual surface to measure clockwise according to. 108 // normal of the virtual surface to measure clockwise according to.
68 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, 109 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,
69 const gfx::Vector3dF& other, 110 const gfx::Vector3dF& other,
70 const gfx::Vector3dF& normal) { 111 const gfx::Vector3dF& normal) {
71 float angle = AngleBetweenVectorsInDegrees(base, other); 112 float angle = AngleBetweenVectorsInDegrees(base, other);
72 gfx::Vector3dF cross(base); 113 gfx::Vector3dF cross(base);
73 cross.Cross(other); 114 cross.Cross(other);
74 // If the dot product of this cross product is normal, it means that the 115 // If the dot product of this cross product is normal, it means that the
75 // shortest angle between |base| and |other| was counterclockwise with respect 116 // shortest angle between |base| and |other| was counterclockwise with respect
76 // to the surface represented by |normal| and this angle must be reversed. 117 // to the surface represented by |normal| and this angle must be reversed.
77 if (gfx::DotProduct(cross, normal) > 0.0f) 118 if (gfx::DotProduct(cross, normal) > 0.0f)
78 angle = 360.0f - angle; 119 angle = 360.0f - angle;
79 return angle; 120 return angle;
80 } 121 }
81 122
123 // Sets the display's rotation.
124 void SetDisplayRotation(DisplayManager* display_manager,
125 int64 display_id,
126 gfx::Display::Rotation rotation) {
127 // Suppress message centre notifications for screen rotations caused
128 // by accelerometer events because it should be obvious why the orientation
129 // changed.
130 ScopedNotificationBlocker notification_blocker;
131 display_manager->SetDisplayRotation(display_id, rotation);
132 }
133
82 } // namespace 134 } // namespace
83 135
84 MaximizeModeController::MaximizeModeController() 136 MaximizeModeController::MaximizeModeController()
85 : rotation_locked_(false) { 137 : rotation_locked_(false) {
86 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); 138 Shell::GetInstance()->accelerometer_controller()->AddObserver(this);
87 } 139 }
88 140
89 MaximizeModeController::~MaximizeModeController() { 141 MaximizeModeController::~MaximizeModeController() {
90 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); 142 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
91 } 143 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // If maximize mode is not engaged, ensure the screen is not rotated and 214 // If maximize mode is not engaged, ensure the screen is not rotated and
163 // do not rotate to match the current device orientation. 215 // do not rotate to match the current device orientation.
164 if (!maximize_mode_engaged) { 216 if (!maximize_mode_engaged) {
165 if (current_rotation != gfx::Display::ROTATE_0) { 217 if (current_rotation != gfx::Display::ROTATE_0) {
166 // TODO(flackr): Currently this will prevent setting a manual rotation on 218 // 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 219 // 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. 220 // back to ROTATE_0 if it was last set by the accelerometer.
169 // Also, SetDisplayRotation will save the setting to the local store, 221 // Also, SetDisplayRotation will save the setting to the local store,
170 // this should be stored in a way that we can distinguish what the 222 // this should be stored in a way that we can distinguish what the
171 // rotation was set by. 223 // rotation was set by.
172 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 224 SetDisplayRotation(display_manager,
173 gfx::Display::ROTATE_0); 225 gfx::Display::InternalDisplayId(),
226 gfx::Display::ROTATE_0);
174 } 227 }
175 rotation_locked_ = false; 228 rotation_locked_ = false;
176 return; 229 return;
177 } 230 }
178 231
179 if (rotation_locked_) 232 if (rotation_locked_)
180 return; 233 return;
181 234
182 // After determining maximize mode state, determine if the screen should 235 // After determining maximize mode state, determine if the screen should
183 // be rotated. 236 // be rotated.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 new_rotation = gfx::Display::ROTATE_0; 274 new_rotation = gfx::Display::ROTATE_0;
222 else if (angle < 180.0f) 275 else if (angle < 180.0f)
223 new_rotation = gfx::Display::ROTATE_270; 276 new_rotation = gfx::Display::ROTATE_270;
224 else if (angle < 270.0f) 277 else if (angle < 270.0f)
225 new_rotation = gfx::Display::ROTATE_180; 278 new_rotation = gfx::Display::ROTATE_180;
226 279
227 // When exiting maximize mode return rotation to 0. When entering, rotate to 280 // When exiting maximize mode return rotation to 0. When entering, rotate to
228 // match screen orientation. 281 // match screen orientation.
229 if (new_rotation == gfx::Display::ROTATE_0 || 282 if (new_rotation == gfx::Display::ROTATE_0 ||
230 maximize_mode_engaged) { 283 maximize_mode_engaged) {
231 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 284 SetDisplayRotation(display_manager,
232 new_rotation); 285 gfx::Display::InternalDisplayId(),
286 new_rotation);
233 } 287 }
234 } 288 }
235 289
236 } // namespace ash 290 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/wm/maximize_mode/maximize_mode_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698