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/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
| 9 #include "ash/accelerometer/accelerometer_controller.h" | 9 #include "ash/accelerometer/accelerometer_controller.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/display/display_manager.h" | 11 #include "ash/display/display_manager.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" | 13 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" |
| 14 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" | |
| 14 #include "base/auto_reset.h" | 15 #include "base/auto_reset.h" |
| 15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 16 #include "ui/base/accelerators/accelerator.h" | 17 #include "ui/base/accelerators/accelerator.h" |
| 17 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
| 18 #include "ui/events/event_handler.h" | 19 #include "ui/events/event_handler.h" |
| 19 #include "ui/events/keycodes/keyboard_codes.h" | 20 #include "ui/events/keycodes/keyboard_codes.h" |
| 20 #include "ui/gfx/vector3d_f.h" | 21 #include "ui/gfx/vector3d_f.h" |
| 21 | 22 |
| 22 namespace ash { | 23 namespace ash { |
| 23 | 24 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 } | 131 } |
| 131 | 132 |
| 132 #endif // OS_CHROMEOS | 133 #endif // OS_CHROMEOS |
| 133 | 134 |
| 134 } // namespace | 135 } // namespace |
| 135 | 136 |
| 136 MaximizeModeController::MaximizeModeController() | 137 MaximizeModeController::MaximizeModeController() |
| 137 : rotation_locked_(false), | 138 : rotation_locked_(false), |
| 138 have_seen_accelerometer_data_(false), | 139 have_seen_accelerometer_data_(false), |
| 139 in_set_screen_rotation_(false), | 140 in_set_screen_rotation_(false), |
| 140 user_rotation_(gfx::Display::ROTATE_0) { | 141 user_rotation_(gfx::Display::ROTATE_0) { |
|
Mr4D (OOO till 08-26)
2014/05/29 22:15:24
Just wondering - when debugging on goobuntu - is t
jonross
2014/05/30 14:37:50
The controller is fully created, however there is
| |
| 141 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 142 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
| 142 } | 143 } |
| 143 | 144 |
| 144 MaximizeModeController::~MaximizeModeController() { | 145 MaximizeModeController::~MaximizeModeController() { |
| 145 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | 146 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); |
| 146 } | 147 } |
| 147 | 148 |
| 148 bool MaximizeModeController::CanEnterMaximizeMode() { | 149 bool MaximizeModeController::CanEnterMaximizeMode() { |
| 149 // If we have ever seen accelerometer data, then HandleHingeRotation may | 150 // If we have ever seen accelerometer data, then HandleHingeRotation may |
| 150 // trigger maximize mode at some point in the future. | 151 // trigger maximize mode at some point in the future. |
| 151 // The --enable-touch-view-testing switch can also mean that we may enter | 152 // The --enable-touch-view-testing switch can also mean that we may enter |
| 152 // maximize mode. | 153 // maximize mode. |
| 153 return have_seen_accelerometer_data_ || | 154 return have_seen_accelerometer_data_ || |
| 154 CommandLine::ForCurrentProcess()->HasSwitch( | 155 CommandLine::ForCurrentProcess()->HasSwitch( |
| 155 switches::kAshEnableTouchViewTesting); | 156 switches::kAshEnableTouchViewTesting); |
| 156 } | 157 } |
| 157 | 158 |
| 159 void MaximizeModeController::EnableMaximizeModeWindowManager(bool enable) { | |
| 160 if (enable && !maximize_mode_window_manager_.get()) { | |
| 161 maximize_mode_window_manager_.reset(new MaximizeModeWindowManager()); | |
| 162 // TODO(jonross): Move the maximize mode notifications from ShellObserver | |
| 163 // to MaximizeModeController::Observer | |
| 164 Shell::GetInstance()->OnMaximizeModeStarted(); | |
| 165 } else if (!enable && maximize_mode_window_manager_.get()) { | |
| 166 maximize_mode_window_manager_.reset(); | |
| 167 Shell::GetInstance()->OnMaximizeModeEnded(); | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 bool MaximizeModeController::IsMaximizeModeWindowManagerEnabled() const { | |
| 172 return maximize_mode_window_manager_.get() != NULL; | |
| 173 } | |
| 174 | |
| 175 void MaximizeModeController::Shutdown() { | |
| 176 maximize_mode_window_manager_.reset(); | |
| 177 Shell::GetInstance()->OnMaximizeModeEnded(); | |
| 178 } | |
| 179 | |
| 158 void MaximizeModeController::OnAccelerometerUpdated( | 180 void MaximizeModeController::OnAccelerometerUpdated( |
| 159 const gfx::Vector3dF& base, | 181 const gfx::Vector3dF& base, |
| 160 const gfx::Vector3dF& lid) { | 182 const gfx::Vector3dF& lid) { |
| 161 have_seen_accelerometer_data_ = true; | 183 have_seen_accelerometer_data_ = true; |
| 162 | 184 |
| 163 // Ignore the reading if it appears unstable. The reading is considered | 185 // Ignore the reading if it appears unstable. The reading is considered |
| 164 // unstable if it deviates too much from gravity and/or the magnitude of the | 186 // unstable if it deviates too much from gravity and/or the magnitude of the |
| 165 // reading from the lid differs too much from the reading from the base. | 187 // reading from the lid differs too much from the reading from the base. |
| 166 float base_magnitude = base.Length(); | 188 float base_magnitude = base.Length(); |
| 167 float lid_magnitude = lid.Length(); | 189 float lid_magnitude = lid.Length(); |
| 168 if (std::abs(base_magnitude - lid_magnitude) > kNoisyMagnitudeDeviation || | 190 if (std::abs(base_magnitude - lid_magnitude) > kNoisyMagnitudeDeviation || |
| 169 std::abs(base_magnitude - 1.0f) > kDeviationFromGravityThreshold || | 191 std::abs(base_magnitude - 1.0f) > kDeviationFromGravityThreshold || |
| 170 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { | 192 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { |
| 171 return; | 193 return; |
| 172 } | 194 } |
| 173 | 195 |
| 174 // Responding to the hinge rotation can change the maximize mode state which | 196 // Responding to the hinge rotation can change the maximize mode state which |
| 175 // affects screen rotation, so we handle hinge rotation first. | 197 // affects screen rotation, so we handle hinge rotation first. |
| 176 HandleHingeRotation(base, lid); | 198 HandleHingeRotation(base, lid); |
| 177 HandleScreenRotation(lid); | 199 HandleScreenRotation(lid); |
| 178 } | 200 } |
| 179 | 201 |
| 180 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, | 202 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, |
| 181 const gfx::Vector3dF& lid) { | 203 const gfx::Vector3dF& lid) { |
| 182 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); | 204 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); |
| 183 bool maximize_mode_engaged = | 205 bool maximize_mode_engaged = IsMaximizeModeWindowManagerEnabled(); |
| 184 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | |
| 185 // Ignore the component of acceleration parallel to the hinge for the purposes | 206 // Ignore the component of acceleration parallel to the hinge for the purposes |
| 186 // of hinge angle calculation. | 207 // of hinge angle calculation. |
| 187 gfx::Vector3dF base_flattened(base); | 208 gfx::Vector3dF base_flattened(base); |
| 188 gfx::Vector3dF lid_flattened(lid); | 209 gfx::Vector3dF lid_flattened(lid); |
| 189 base_flattened.set_y(0.0f); | 210 base_flattened.set_y(0.0f); |
| 190 lid_flattened.set_y(0.0f); | 211 lid_flattened.set_y(0.0f); |
| 191 | 212 |
| 192 // As the hinge approaches a vertical angle, the base and lid accelerometers | 213 // As the hinge approaches a vertical angle, the base and lid accelerometers |
| 193 // approach the same values making any angle calculations highly inaccurate. | 214 // approach the same values making any angle calculations highly inaccurate. |
| 194 // Bail out early when it is too close. | 215 // Bail out early when it is too close. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 209 angle > kFullyOpenAngleErrorTolerance && | 230 angle > kFullyOpenAngleErrorTolerance && |
| 210 angle < kExitMaximizeModeAngle) { | 231 angle < kExitMaximizeModeAngle) { |
| 211 LeaveMaximizeMode(); | 232 LeaveMaximizeMode(); |
| 212 } else if (!maximize_mode_engaged && | 233 } else if (!maximize_mode_engaged && |
| 213 angle > kEnterMaximizeModeAngle) { | 234 angle > kEnterMaximizeModeAngle) { |
| 214 EnterMaximizeMode(); | 235 EnterMaximizeMode(); |
| 215 } | 236 } |
| 216 } | 237 } |
| 217 | 238 |
| 218 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { | 239 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
| 219 bool maximize_mode_engaged = | 240 bool maximize_mode_engaged = IsMaximizeModeWindowManagerEnabled(); |
| 220 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | |
| 221 | 241 |
| 222 if (!maximize_mode_engaged || rotation_locked_) | 242 if (!maximize_mode_engaged || rotation_locked_) |
| 223 return; | 243 return; |
| 224 | 244 |
| 225 DisplayManager* display_manager = | 245 DisplayManager* display_manager = |
| 226 Shell::GetInstance()->display_manager(); | 246 Shell::GetInstance()->display_manager(); |
| 227 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( | 247 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( |
| 228 gfx::Display::InternalDisplayId()).rotation(); | 248 gfx::Display::InternalDisplayId()).rotation(); |
| 229 | 249 |
| 230 // After determining maximize mode state, determine if the screen should | 250 // After determining maximize mode state, determine if the screen should |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 rotation); | 305 rotation); |
| 286 } | 306 } |
| 287 | 307 |
| 288 void MaximizeModeController::EnterMaximizeMode() { | 308 void MaximizeModeController::EnterMaximizeMode() { |
| 289 // TODO(jonross): Listen for display configuration changes. If the user | 309 // TODO(jonross): Listen for display configuration changes. If the user |
| 290 // causes a rotation change a rotation lock should be applied. | 310 // causes a rotation change a rotation lock should be applied. |
| 291 // https://crbug.com/369505 | 311 // https://crbug.com/369505 |
| 292 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 312 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 293 user_rotation_ = display_manager-> | 313 user_rotation_ = display_manager-> |
| 294 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 314 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 295 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | 315 EnableMaximizeModeWindowManager(true); |
| 296 event_blocker_.reset(new MaximizeModeEventBlocker); | 316 event_blocker_.reset(new MaximizeModeEventBlocker); |
| 297 #if defined(OS_CHROMEOS) | 317 #if defined(OS_CHROMEOS) |
| 298 event_handler_.reset(new ScreenshotActionHandler); | 318 event_handler_.reset(new ScreenshotActionHandler); |
| 299 #endif | 319 #endif |
| 300 } | 320 } |
| 301 | 321 |
| 302 void MaximizeModeController::LeaveMaximizeMode() { | 322 void MaximizeModeController::LeaveMaximizeMode() { |
| 303 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 323 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 304 DisplayInfo info = display_manager-> | 324 DisplayInfo info = display_manager-> |
| 305 GetDisplayInfo(gfx::Display::InternalDisplayId()); | 325 GetDisplayInfo(gfx::Display::InternalDisplayId()); |
| 306 gfx::Display::Rotation current_rotation = info.rotation(); | 326 gfx::Display::Rotation current_rotation = info.rotation(); |
| 307 if (current_rotation != user_rotation_) | 327 if (current_rotation != user_rotation_) |
| 308 SetDisplayRotation(display_manager, user_rotation_); | 328 SetDisplayRotation(display_manager, user_rotation_); |
| 309 rotation_locked_ = false; | 329 rotation_locked_ = false; |
| 310 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 330 EnableMaximizeModeWindowManager(false); |
| 311 event_blocker_.reset(); | 331 event_blocker_.reset(); |
| 312 event_handler_.reset(); | 332 event_handler_.reset(); |
| 313 } | 333 } |
| 314 | 334 |
| 315 } // namespace ash | 335 } // namespace ash |
| OLD | NEW |