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/ash_switches.h" |
8 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
10 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" | 11 #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" |
| 12 #include "base/command_line.h" |
11 #include "ui/gfx/vector3d_f.h" | 13 #include "ui/gfx/vector3d_f.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 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // shortest angle between |base| and |other| was counterclockwise with respect | 77 // shortest angle between |base| and |other| was counterclockwise with respect |
76 // to the surface represented by |normal| and this angle must be reversed. | 78 // to the surface represented by |normal| and this angle must be reversed. |
77 if (gfx::DotProduct(cross, normal) > 0.0f) | 79 if (gfx::DotProduct(cross, normal) > 0.0f) |
78 angle = 360.0f - angle; | 80 angle = 360.0f - angle; |
79 return angle; | 81 return angle; |
80 } | 82 } |
81 | 83 |
82 } // namespace | 84 } // namespace |
83 | 85 |
84 MaximizeModeController::MaximizeModeController() | 86 MaximizeModeController::MaximizeModeController() |
85 : rotation_locked_(false) { | 87 : rotation_locked_(false), |
| 88 have_seen_accelerometer_data_(false) { |
86 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 89 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
87 } | 90 } |
88 | 91 |
89 MaximizeModeController::~MaximizeModeController() { | 92 MaximizeModeController::~MaximizeModeController() { |
90 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | 93 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); |
91 } | 94 } |
92 | 95 |
| 96 bool MaximizeModeController::CanEnterMaximizeMode() { |
| 97 // If we have ever seen accelerometer data, then HandleHingeRotation may |
| 98 // trigger maximize mode at some point in the future. |
| 99 // The --enable-touch-view-testing switch can also mean that we may enter |
| 100 // maximize mode. |
| 101 return have_seen_accelerometer_data_ || |
| 102 CommandLine::ForCurrentProcess()->HasSwitch( |
| 103 switches::kAshEnableTouchViewTesting); |
| 104 } |
| 105 |
93 void MaximizeModeController::OnAccelerometerUpdated( | 106 void MaximizeModeController::OnAccelerometerUpdated( |
94 const gfx::Vector3dF& base, | 107 const gfx::Vector3dF& base, |
95 const gfx::Vector3dF& lid) { | 108 const gfx::Vector3dF& lid) { |
| 109 have_seen_accelerometer_data_ = true; |
| 110 |
96 // Ignore the reading if it appears unstable. The reading is considered | 111 // 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 | 112 // 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. | 113 // reading from the lid differs too much from the reading from the base. |
99 float base_magnitude = base.Length(); | 114 float base_magnitude = base.Length(); |
100 float lid_magnitude = lid.Length(); | 115 float lid_magnitude = lid.Length(); |
101 if (std::abs(base_magnitude - lid_magnitude) > kNoisyMagnitudeDeviation || | 116 if (std::abs(base_magnitude - lid_magnitude) > kNoisyMagnitudeDeviation || |
102 std::abs(base_magnitude - 1.0f) > kDeviationFromGravityThreshold || | 117 std::abs(base_magnitude - 1.0f) > kDeviationFromGravityThreshold || |
103 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { | 118 std::abs(lid_magnitude - 1.0f) > kDeviationFromGravityThreshold) { |
104 return; | 119 return; |
105 } | 120 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | 248 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
234 if (!rotation_locked_ && current_rotation != gfx::Display::ROTATE_0) { | 249 if (!rotation_locked_ && current_rotation != gfx::Display::ROTATE_0) { |
235 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | 250 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), |
236 gfx::Display::ROTATE_0); | 251 gfx::Display::ROTATE_0); |
237 } | 252 } |
238 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); | 253 Shell::GetInstance()->EnableMaximizeModeWindowManager(false); |
239 event_blocker_.reset(); | 254 event_blocker_.reset(); |
240 } | 255 } |
241 | 256 |
242 } // namespace ash | 257 } // namespace ash |
OLD | NEW |