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

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: Fixed MaximizeModeNotifcationBlocker to only filter notifcations from "ash.display" 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
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/system/chromeos/tray_display.h"
11 #include "ash/system/system_notifier.h"
10 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" 12 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h"
11 #include "ui/gfx/vector3d_f.h" 13 #include "ui/gfx/vector3d_f.h"
14 #include "ui/message_center/message_center.h"
15 #include "ui/message_center/notification_blocker.h"
12 16
13 namespace ash { 17 namespace ash {
14 18
15 namespace { 19 namespace {
16 20
17 // The hinge angle at which to enter maximize mode. 21 // The hinge angle at which to enter maximize mode.
18 const float kEnterMaximizeModeAngle = 200.0f; 22 const float kEnterMaximizeModeAngle = 200.0f;
19 23
20 // The angle at which to exit maximize mode, this is specifically less than the 24 // 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. 25 // angle to enter maximize mode to prevent rapid toggling when near the angle.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // If the dot product of this cross product is normal, it means that the 78 // 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 79 // shortest angle between |base| and |other| was counterclockwise with respect
76 // to the surface represented by |normal| and this angle must be reversed. 80 // to the surface represented by |normal| and this angle must be reversed.
77 if (gfx::DotProduct(cross, normal) > 0.0f) 81 if (gfx::DotProduct(cross, normal) > 0.0f)
78 angle = 360.0f - angle; 82 angle = 360.0f - angle;
79 return angle; 83 return angle;
80 } 84 }
81 85
82 } // namespace 86 } // namespace
83 87
88 MaximizeModeController::MaximizeModeNotificationBlocker::
flackr 2014/05/08 18:04:00 Perhaps this should be called DisplayNotificationB
bruthig 2014/05/08 21:15:33 Done.
89 MaximizeModeNotificationBlocker()
90 : message_center::NotificationBlocker(
flackr 2014/05/08 18:04:00 nit: I think the : should align with the M in Maxi
91 message_center::MessageCenter::Get()),
flackr 2014/05/08 18:04:00 nit: this should be indented 4 from the m in "mess
92 show_notifications_(true) {
93 }
94
95 MaximizeModeController::MaximizeModeNotificationBlocker::
96 ~MaximizeModeNotificationBlocker() {
97 }
98
99 void MaximizeModeController::MaximizeModeNotificationBlocker::
100 SetShouldShowNotification(bool should_show) {
101 bool did_change = show_notifications_ != should_show;
102 show_notifications_ = should_show;
103 if (did_change)
104 NotifyBlockingStateChanged();
105 }
106
107 bool MaximizeModeController::MaximizeModeNotificationBlocker::
108 ShouldShowNotificationAsPopup(
109 const message_center::NotifierId& notifier_id) const {
flackr 2014/05/08 18:04:00 nit: should be indented 4 from the Should above.
110 if (notifier_id.id == ash::system_notifier::kNotifierDisplay)
111 return show_notifications_;
112 return true;
flackr 2014/05/08 18:04:00 Why does this one not defer to the base class wher
bruthig 2014/05/08 21:15:33 It is a pure virtual function in the base class.
113 }
114
115 bool MaximizeModeController::MaximizeModeNotificationBlocker::
116 ShouldShowNotificati
flackr 2014/05/08 18:04:00 truncated line?
bruthig 2014/05/08 21:15:33 Done.
117 const message_center::NotifierId& notifier_id) const {
118 if (notifier_id.id == ash::system_notifier::kNotifierDisplay)
119 return show_notifications_;
120 return message_center::NotificationBlocker::ShouldShowNotification(
121 notifier_id);
122 }
123
84 MaximizeModeController::MaximizeModeController() 124 MaximizeModeController::MaximizeModeController()
85 : rotation_locked_(false) { 125 : rotation_locked_(false) {
86 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); 126 Shell::GetInstance()->accelerometer_controller()->AddObserver(this);
87 } 127 }
88 128
89 MaximizeModeController::~MaximizeModeController() { 129 MaximizeModeController::~MaximizeModeController() {
90 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); 130 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
91 } 131 }
92 132
93 void MaximizeModeController::OnAccelerometerUpdated( 133 void MaximizeModeController::OnAccelerometerUpdated(
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 new_rotation = gfx::Display::ROTATE_0; 242 new_rotation = gfx::Display::ROTATE_0;
203 else if (angle < 180.0f) 243 else if (angle < 180.0f)
204 new_rotation = gfx::Display::ROTATE_270; 244 new_rotation = gfx::Display::ROTATE_270;
205 else if (angle < 270.0f) 245 else if (angle < 270.0f)
206 new_rotation = gfx::Display::ROTATE_180; 246 new_rotation = gfx::Display::ROTATE_180;
207 247
208 // When exiting maximize mode return rotation to 0. When entering, rotate to 248 // When exiting maximize mode return rotation to 0. When entering, rotate to
209 // match screen orientation. 249 // match screen orientation.
210 if (new_rotation == gfx::Display::ROTATE_0 || 250 if (new_rotation == gfx::Display::ROTATE_0 ||
211 maximize_mode_engaged) { 251 maximize_mode_engaged) {
212 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 252 SetDisplayRotation(display_manager,
213 new_rotation); 253 gfx::Display::InternalDisplayId(),
254 new_rotation);
214 } 255 }
215 } 256 }
216 257
258 // Sets the display's rotation.
259 void MaximizeModeController::SetDisplayRotation(DisplayManager* display_manager,
260 int64 display_id,
261 gfx::Display::Rotation rotation) {
262 // Suppress message centre notifications for screen rotations caused
263 // by accelerometer events because it should be obvious why the orientation
264 // changed.
265 notification_blocker_.SetShouldShowNotification(false);
266 display_manager->SetDisplayRotation(display_id, rotation);
267 message_center::MessageCenter* message_center =
268 message_center::MessageCenter::Get();
269 if (message_center->HasNotification(TrayDisplay::kNotificationId))
270 message_center->MarkSinglePopupAsShown(TrayDisplay::kNotificationId, true);
jonross 2014/05/08 18:12:34 Since TrayDisplay is responsible for the creation
271 notification_blocker_.SetShouldShowNotification(true);
272 }
273
217 void MaximizeModeController::EnterMaximizeMode() { 274 void MaximizeModeController::EnterMaximizeMode() {
218 // TODO(jonross): Create a property on the display to track user rotations. 275 // TODO(jonross): Create a property on the display to track user rotations.
219 // We should lock based on this property. Furthermore we should apply the 276 // We should lock based on this property. Furthermore we should apply the
220 // lock if the user changes the display settings while we are in maximize 277 // lock if the user changes the display settings while we are in maximize
221 // mode. https://crbug.com/369505 278 // mode. https://crbug.com/369505
222 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 279 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
223 gfx::Display::Rotation current_rotation = display_manager-> 280 gfx::Display::Rotation current_rotation = display_manager->
224 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); 281 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
225 rotation_locked_ = current_rotation != gfx::Display::ROTATE_0; 282 rotation_locked_ = current_rotation != gfx::Display::ROTATE_0;
226 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); 283 Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
227 event_blocker_.reset(new MaximizeModeEventBlocker); 284 event_blocker_.reset(new MaximizeModeEventBlocker);
228 } 285 }
229 286
230 void MaximizeModeController::LeaveMaximizeMode() { 287 void MaximizeModeController::LeaveMaximizeMode() {
231 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 288 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
232 gfx::Display::Rotation current_rotation = display_manager-> 289 gfx::Display::Rotation current_rotation = display_manager->
233 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); 290 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
234 if (!rotation_locked_ && current_rotation != gfx::Display::ROTATE_0) { 291 if (!rotation_locked_ && current_rotation != gfx::Display::ROTATE_0) {
235 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), 292 SetDisplayRotation(display_manager,
236 gfx::Display::ROTATE_0); 293 gfx::Display::InternalDisplayId(),
294 gfx::Display::ROTATE_0);
237 } 295 }
238 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); 296 Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
239 event_blocker_.reset(); 297 event_blocker_.reset();
240 } 298 }
241 299
242 } // namespace ash 300 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698