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/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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 84 MaximizeModeController::MaximizeModeController() | 88 MaximizeModeController::MaximizeModeController() |
| 85 : rotation_locked_(false) { | 89 : message_center::NotificationBlocker(message_center::MessageCenter::Get()), |
|
flackr
2014/05/08 21:56:15
Are there any potential lifetime issues here? Does
bruthig
2014/05/14 00:36:16
Done.
| |
| 90 rotation_locked_(false), | |
| 91 show_notifications_(true) { | |
| 86 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 92 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
| 87 } | 93 } |
| 88 | 94 |
| 89 MaximizeModeController::~MaximizeModeController() { | 95 MaximizeModeController::~MaximizeModeController() { |
| 90 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | 96 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); |
| 91 } | 97 } |
| 92 | 98 |
| 93 void MaximizeModeController::OnAccelerometerUpdated( | 99 void MaximizeModeController::OnAccelerometerUpdated( |
| 94 const gfx::Vector3dF& base, | 100 const gfx::Vector3dF& base, |
| 95 const gfx::Vector3dF& lid) { | 101 const gfx::Vector3dF& lid) { |
| 96 // Ignore the reading if it appears unstable. The reading is considered | 102 // Ignore the reading if it appears unstable. The reading is considered |
| 97 // unstable if it deviates too much from gravity and/or the magnitude of the | 103 // unstable if it deviates too much from gravity and/or the magnitude of the |
| 98 // reading from the lid differs too much from the reading from the base. | 104 // reading from the lid differs too much from the reading from the base. |
| 99 float base_magnitude = base.Length(); | 105 float base_magnitude = base.Length(); |
| 100 float lid_magnitude = lid.Length(); | 106 float lid_magnitude = lid.Length(); |
| 101 if (std::abs(base_magnitude - lid_magnitude) > kNoisyMagnitudeDeviation || | 107 if (std::abs(base_magnitude - lid_magnitude) > kNoisyMagnitudeDeviation || |
| 102 std::abs(base_magnitude - 1.0f) > kDeviationFromGravityThreshold || | 108 std::abs(base_magnitude - 1.0f) > kDeviationFromGravityThreshold || |
| 103 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { | 109 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { |
| 104 return; | 110 return; |
| 105 } | 111 } |
| 106 | 112 |
| 107 // Responding to the hinge rotation can change the maximize mode state which | 113 // Responding to the hinge rotation can change the maximize mode state which |
| 108 // affects screen rotation, so we handle hinge rotation first. | 114 // affects screen rotation, so we handle hinge rotation first. |
| 109 HandleHingeRotation(base, lid); | 115 HandleHingeRotation(base, lid); |
| 110 HandleScreenRotation(lid); | 116 HandleScreenRotation(lid); |
| 111 } | 117 } |
| 112 | 118 |
| 119 void MaximizeModeController::set_show_notifications(bool should_show) { | |
| 120 bool did_change = show_notifications_ != should_show; | |
| 121 show_notifications_ = should_show; | |
| 122 if (did_change) | |
| 123 NotifyBlockingStateChanged(); | |
| 124 } | |
| 125 | |
| 126 bool MaximizeModeController::ShouldShowNotificationAsPopup( | |
| 127 const message_center::NotifierId& notifier_id) const { | |
| 128 if (notifier_id.id == ash::system_notifier::kNotifierDisplay) | |
| 129 return show_notifications_; | |
| 130 return true; | |
|
jonross
2014/05/09 14:57:33
on 137 you fall back to checking with the message
bruthig
2014/05/14 00:36:16
For some reason ShouldShowNotificationAsPopup is a
| |
| 131 } | |
| 132 | |
| 133 bool MaximizeModeController::ShouldShowNotification( | |
| 134 const message_center::NotifierId& notifier_id) const { | |
| 135 if (notifier_id.id == ash::system_notifier::kNotifierDisplay) | |
| 136 return show_notifications_; | |
| 137 return message_center::NotificationBlocker::ShouldShowNotification( | |
| 138 notifier_id); | |
| 139 } | |
| 140 | |
| 113 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, | 141 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, |
| 114 const gfx::Vector3dF& lid) { | 142 const gfx::Vector3dF& lid) { |
| 115 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); | 143 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); |
| 116 bool maximize_mode_engaged = | 144 bool maximize_mode_engaged = |
| 117 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | 145 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); |
| 118 // Ignore the component of acceleration parallel to the hinge for the purposes | 146 // Ignore the component of acceleration parallel to the hinge for the purposes |
| 119 // of hinge angle calculation. | 147 // of hinge angle calculation. |
| 120 gfx::Vector3dF base_flattened(base); | 148 gfx::Vector3dF base_flattened(base); |
| 121 gfx::Vector3dF lid_flattened(lid); | 149 gfx::Vector3dF lid_flattened(lid); |
| 122 base_flattened.set_y(0.0f); | 150 base_flattened.set_y(0.0f); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 new_rotation = gfx::Display::ROTATE_0; | 230 new_rotation = gfx::Display::ROTATE_0; |
| 203 else if (angle < 180.0f) | 231 else if (angle < 180.0f) |
| 204 new_rotation = gfx::Display::ROTATE_270; | 232 new_rotation = gfx::Display::ROTATE_270; |
| 205 else if (angle < 270.0f) | 233 else if (angle < 270.0f) |
| 206 new_rotation = gfx::Display::ROTATE_180; | 234 new_rotation = gfx::Display::ROTATE_180; |
| 207 | 235 |
| 208 // When exiting maximize mode return rotation to 0. When entering, rotate to | 236 // When exiting maximize mode return rotation to 0. When entering, rotate to |
| 209 // match screen orientation. | 237 // match screen orientation. |
| 210 if (new_rotation == gfx::Display::ROTATE_0 || | 238 if (new_rotation == gfx::Display::ROTATE_0 || |
| 211 maximize_mode_engaged) { | 239 maximize_mode_engaged) { |
| 212 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 240 SetDisplayRotation(display_manager, |
| 213 new_rotation); | 241 gfx::Display::InternalDisplayId(), |
| 242 new_rotation); | |
| 214 } | 243 } |
| 215 } | 244 } |
| 216 | 245 |
| 246 // Sets the display's rotation. | |
| 247 void MaximizeModeController::SetDisplayRotation( | |
| 248 DisplayManager* display_manager, | |
| 249 int64 display_id, | |
| 250 gfx::Display::Rotation rotation) { | |
| 251 // Suppress message centre notifications for screen rotations caused | |
| 252 // by accelerometer events because it should be obvious why the orientation | |
| 253 // changed. | |
| 254 set_show_notifications(false); | |
|
flackr
2014/05/08 21:56:15
It still seems like it would be nicer to scope the
bruthig
2014/05/14 00:36:16
Done.
| |
| 255 display_manager->SetDisplayRotation(display_id, rotation); | |
| 256 message_center::MessageCenter* message_center = | |
| 257 message_center::MessageCenter::Get(); | |
| 258 if (message_center->HasNotification(TrayDisplay::kNotificationId)) | |
|
flackr
2014/05/08 21:56:15
This is a bit hacky, this could probably use a tod
bruthig
2014/05/14 00:36:16
Done.
| |
| 259 message_center->MarkSinglePopupAsShown(TrayDisplay::kNotificationId, true); | |
| 260 set_show_notifications(true); | |
| 261 } | |
| 262 | |
| 217 void MaximizeModeController::EnterMaximizeMode() { | 263 void MaximizeModeController::EnterMaximizeMode() { |
| 218 // TODO(jonross): Create a property on the display to track user rotations. | 264 // 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 | 265 // 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 | 266 // lock if the user changes the display settings while we are in maximize |
| 221 // mode. https://crbug.com/369505 | 267 // mode. https://crbug.com/369505 |
| 222 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 268 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 223 gfx::Display::Rotation current_rotation = display_manager-> | 269 gfx::Display::Rotation current_rotation = display_manager-> |
| 224 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 270 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 225 rotation_locked_ = current_rotation != gfx::Display::ROTATE_0; | 271 rotation_locked_ = current_rotation != gfx::Display::ROTATE_0; |
| 226 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | 272 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); |
| 227 event_blocker_.reset(new MaximizeModeEventBlocker); | 273 event_blocker_.reset(new MaximizeModeEventBlocker); |
| 228 } | 274 } |
| 229 | 275 |
| 230 void MaximizeModeController::LeaveMaximizeMode() { | 276 void MaximizeModeController::LeaveMaximizeMode() { |
| 231 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 277 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 232 gfx::Display::Rotation current_rotation = display_manager-> | 278 gfx::Display::Rotation current_rotation = display_manager-> |
| 233 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 279 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 234 if (!rotation_locked_ && current_rotation != gfx::Display::ROTATE_0) { | 280 if (!rotation_locked_ && current_rotation != gfx::Display::ROTATE_0) { |
| 235 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 281 SetDisplayRotation(display_manager, |
| 236 gfx::Display::ROTATE_0); | 282 gfx::Display::InternalDisplayId(), |
| 283 gfx::Display::ROTATE_0); | |
| 237 } | 284 } |
| 238 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 285 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); |
| 239 event_blocker_.reset(); | 286 event_blocker_.reset(); |
| 240 } | 287 } |
| 241 | 288 |
| 242 } // namespace ash | 289 } // namespace ash |
| OLD | NEW |