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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Shell::GetInstance()->OnMaximizeModeStarted(); | |
|
flackr
2014/05/29 16:10:06
Can you add a TODO (probably to ShellObserver) to
jonross
2014/05/29 17:40:00
Done.
| |
| 163 } else if (!enable && maximize_mode_window_manager_.get()) { | |
| 164 maximize_mode_window_manager_.reset(); | |
| 165 Shell::GetInstance()->OnMaximizeModeEnded(); | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 bool MaximizeModeController::IsMaximizeModeWindowManagerEnabled() const { | |
| 170 return maximize_mode_window_manager_.get() != NULL; | |
| 171 } | |
| 172 | |
| 158 void MaximizeModeController::OnAccelerometerUpdated( | 173 void MaximizeModeController::OnAccelerometerUpdated( |
| 159 const gfx::Vector3dF& base, | 174 const gfx::Vector3dF& base, |
| 160 const gfx::Vector3dF& lid) { | 175 const gfx::Vector3dF& lid) { |
| 161 have_seen_accelerometer_data_ = true; | 176 have_seen_accelerometer_data_ = true; |
| 162 | 177 |
| 163 // Ignore the reading if it appears unstable. The reading is considered | 178 // 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 | 179 // 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. | 180 // reading from the lid differs too much from the reading from the base. |
| 166 float base_magnitude = base.Length(); | 181 float base_magnitude = base.Length(); |
| 167 float lid_magnitude = lid.Length(); | 182 float lid_magnitude = lid.Length(); |
| 168 if (std::abs(base_magnitude - lid_magnitude) > kNoisyMagnitudeDeviation || | 183 if (std::abs(base_magnitude - lid_magnitude) > kNoisyMagnitudeDeviation || |
| 169 std::abs(base_magnitude - 1.0f) > kDeviationFromGravityThreshold || | 184 std::abs(base_magnitude - 1.0f) > kDeviationFromGravityThreshold || |
| 170 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { | 185 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { |
| 171 return; | 186 return; |
| 172 } | 187 } |
| 173 | 188 |
| 174 // Responding to the hinge rotation can change the maximize mode state which | 189 // Responding to the hinge rotation can change the maximize mode state which |
| 175 // affects screen rotation, so we handle hinge rotation first. | 190 // affects screen rotation, so we handle hinge rotation first. |
| 176 HandleHingeRotation(base, lid); | 191 HandleHingeRotation(base, lid); |
| 177 HandleScreenRotation(lid); | 192 HandleScreenRotation(lid); |
| 178 } | 193 } |
| 179 | 194 |
| 180 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, | 195 void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, |
| 181 const gfx::Vector3dF& lid) { | 196 const gfx::Vector3dF& lid) { |
| 182 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); | 197 static const gfx::Vector3dF hinge_vector(0.0f, 1.0f, 0.0f); |
| 183 bool maximize_mode_engaged = | 198 bool maximize_mode_engaged = IsMaximizeModeWindowManagerEnabled(); |
| 184 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | |
| 185 // Ignore the component of acceleration parallel to the hinge for the purposes | 199 // Ignore the component of acceleration parallel to the hinge for the purposes |
| 186 // of hinge angle calculation. | 200 // of hinge angle calculation. |
| 187 gfx::Vector3dF base_flattened(base); | 201 gfx::Vector3dF base_flattened(base); |
| 188 gfx::Vector3dF lid_flattened(lid); | 202 gfx::Vector3dF lid_flattened(lid); |
| 189 base_flattened.set_y(0.0f); | 203 base_flattened.set_y(0.0f); |
| 190 lid_flattened.set_y(0.0f); | 204 lid_flattened.set_y(0.0f); |
| 191 | 205 |
| 192 // As the hinge approaches a vertical angle, the base and lid accelerometers | 206 // As the hinge approaches a vertical angle, the base and lid accelerometers |
| 193 // approach the same values making any angle calculations highly inaccurate. | 207 // approach the same values making any angle calculations highly inaccurate. |
| 194 // Bail out early when it is too close. | 208 // Bail out early when it is too close. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 209 angle > kFullyOpenAngleErrorTolerance && | 223 angle > kFullyOpenAngleErrorTolerance && |
| 210 angle < kExitMaximizeModeAngle) { | 224 angle < kExitMaximizeModeAngle) { |
| 211 LeaveMaximizeMode(); | 225 LeaveMaximizeMode(); |
| 212 } else if (!maximize_mode_engaged && | 226 } else if (!maximize_mode_engaged && |
| 213 angle > kEnterMaximizeModeAngle) { | 227 angle > kEnterMaximizeModeAngle) { |
| 214 EnterMaximizeMode(); | 228 EnterMaximizeMode(); |
| 215 } | 229 } |
| 216 } | 230 } |
| 217 | 231 |
| 218 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { | 232 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { |
| 219 bool maximize_mode_engaged = | 233 bool maximize_mode_engaged = IsMaximizeModeWindowManagerEnabled(); |
| 220 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled(); | |
| 221 | 234 |
| 222 if (!maximize_mode_engaged || rotation_locked_) | 235 if (!maximize_mode_engaged || rotation_locked_) |
| 223 return; | 236 return; |
| 224 | 237 |
| 225 DisplayManager* display_manager = | 238 DisplayManager* display_manager = |
| 226 Shell::GetInstance()->display_manager(); | 239 Shell::GetInstance()->display_manager(); |
| 227 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( | 240 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( |
| 228 gfx::Display::InternalDisplayId()).rotation(); | 241 gfx::Display::InternalDisplayId()).rotation(); |
| 229 | 242 |
| 230 // After determining maximize mode state, determine if the screen should | 243 // 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); | 298 rotation); |
| 286 } | 299 } |
| 287 | 300 |
| 288 void MaximizeModeController::EnterMaximizeMode() { | 301 void MaximizeModeController::EnterMaximizeMode() { |
| 289 // TODO(jonross): Listen for display configuration changes. If the user | 302 // TODO(jonross): Listen for display configuration changes. If the user |
| 290 // causes a rotation change a rotation lock should be applied. | 303 // causes a rotation change a rotation lock should be applied. |
| 291 // https://crbug.com/369505 | 304 // https://crbug.com/369505 |
| 292 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 305 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 293 user_rotation_ = display_manager-> | 306 user_rotation_ = display_manager-> |
| 294 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 307 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
| 295 Shell::GetInstance()->EnableMaximizeModeWindowManager(true); | 308 EnableMaximizeModeWindowManager(true); |
| 296 event_blocker_.reset(new MaximizeModeEventBlocker); | 309 event_blocker_.reset(new MaximizeModeEventBlocker); |
| 297 #if defined(OS_CHROMEOS) | 310 #if defined(OS_CHROMEOS) |
| 298 event_handler_.reset(new ScreenshotActionHandler); | 311 event_handler_.reset(new ScreenshotActionHandler); |
| 299 #endif | 312 #endif |
| 300 } | 313 } |
| 301 | 314 |
| 302 void MaximizeModeController::LeaveMaximizeMode() { | 315 void MaximizeModeController::LeaveMaximizeMode() { |
| 303 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 316 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 304 DisplayInfo info = display_manager-> | 317 DisplayInfo info = display_manager-> |
| 305 GetDisplayInfo(gfx::Display::InternalDisplayId()); | 318 GetDisplayInfo(gfx::Display::InternalDisplayId()); |
| 306 gfx::Display::Rotation current_rotation = info.rotation(); | 319 gfx::Display::Rotation current_rotation = info.rotation(); |
| 307 if (current_rotation != user_rotation_) | 320 if (current_rotation != user_rotation_) |
| 308 SetDisplayRotation(display_manager, user_rotation_); | 321 SetDisplayRotation(display_manager, user_rotation_); |
| 309 rotation_locked_ = false; | 322 rotation_locked_ = false; |
| 310 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 323 EnableMaximizeModeWindowManager(false); |
| 311 event_blocker_.reset(); | 324 event_blocker_.reset(); |
| 312 event_handler_.reset(); | 325 event_handler_.reset(); |
| 313 } | 326 } |
| 314 | 327 |
| 315 } // namespace ash | 328 } // namespace ash |
| OLD | NEW |