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_window_manager.h" | 13 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
14 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" | 14 #include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h" |
15 #include "base/auto_reset.h" | |
16 #include "base/command_line.h" | 15 #include "base/command_line.h" |
17 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
18 #include "base/time/default_tick_clock.h" | 17 #include "base/time/default_tick_clock.h" |
19 #include "base/time/tick_clock.h" | 18 #include "base/time/tick_clock.h" |
20 #include "ui/base/accelerators/accelerator.h" | 19 #include "ui/base/accelerators/accelerator.h" |
21 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
22 #include "ui/events/keycodes/keyboard_codes.h" | 21 #include "ui/events/keycodes/keyboard_codes.h" |
23 #include "ui/gfx/geometry/vector3d_f.h" | 22 #include "ui/gfx/geometry/vector3d_f.h" |
24 | 23 |
25 #if defined(USE_X11) | 24 #if defined(USE_X11) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 // The maximum deviation from the acceleration expected due to gravity under | 68 // The maximum deviation from the acceleration expected due to gravity under |
70 // which to detect hinge angle and screen rotation in m/s^2 | 69 // which to detect hinge angle and screen rotation in m/s^2 |
71 const float kDeviationFromGravityThreshold = 1.0f; | 70 const float kDeviationFromGravityThreshold = 1.0f; |
72 | 71 |
73 // The maximum deviation between the magnitude of the two accelerometers under | 72 // The maximum deviation between the magnitude of the two accelerometers under |
74 // which to detect hinge angle and screen rotation in m/s^2. These | 73 // which to detect hinge angle and screen rotation in m/s^2. These |
75 // accelerometers are attached to the same physical device and so should be | 74 // accelerometers are attached to the same physical device and so should be |
76 // under the same acceleration. | 75 // under the same acceleration. |
77 const float kNoisyMagnitudeDeviation = 1.0f; | 76 const float kNoisyMagnitudeDeviation = 1.0f; |
78 | 77 |
79 // The angle which the screen has to be rotated past before the display will | |
80 // rotate to match it (i.e. 45.0f is no stickiness). | |
81 const float kDisplayRotationStickyAngleDegrees = 60.0f; | |
82 | |
83 // The minimum acceleration in m/s^2 in a direction required to trigger screen | |
84 // rotation. This prevents rapid toggling of rotation when the device is near | |
85 // flat and there is very little screen aligned force on it. The value is | |
86 // effectively the sine of the rise angle required times the acceleration due | |
87 // to gravity, with the current value requiring at least a 25 degree rise. | |
88 const float kMinimumAccelerationScreenRotation = 4.2f; | |
89 | |
90 const float kRadiansToDegrees = 180.0f / 3.14159265f; | 78 const float kRadiansToDegrees = 180.0f / 3.14159265f; |
91 | 79 |
92 // Returns the angle between |base| and |other| in degrees. | 80 // Returns the angle between |base| and |other| in degrees. |
93 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, | 81 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, |
94 const gfx::Vector3dF& other) { | 82 const gfx::Vector3dF& other) { |
95 return acos(gfx::DotProduct(base, other) / | 83 return acos(gfx::DotProduct(base, other) / |
96 base.Length() / other.Length()) * kRadiansToDegrees; | 84 base.Length() / other.Length()) * kRadiansToDegrees; |
97 } | 85 } |
98 | 86 |
99 // Returns the clockwise angle between |base| and |other| where |normal| is the | 87 // Returns the clockwise angle between |base| and |other| where |normal| is the |
100 // normal of the virtual surface to measure clockwise according to. | 88 // normal of the virtual surface to measure clockwise according to. |
101 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, | 89 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, |
102 const gfx::Vector3dF& other, | 90 const gfx::Vector3dF& other, |
103 const gfx::Vector3dF& normal) { | 91 const gfx::Vector3dF& normal) { |
104 float angle = AngleBetweenVectorsInDegrees(base, other); | 92 float angle = AngleBetweenVectorsInDegrees(base, other); |
105 gfx::Vector3dF cross(base); | 93 gfx::Vector3dF cross(base); |
106 cross.Cross(other); | 94 cross.Cross(other); |
107 // If the dot product of this cross product is normal, it means that the | 95 // If the dot product of this cross product is normal, it means that the |
108 // shortest angle between |base| and |other| was counterclockwise with respect | 96 // shortest angle between |base| and |other| was counterclockwise with respect |
109 // to the surface represented by |normal| and this angle must be reversed. | 97 // to the surface represented by |normal| and this angle must be reversed. |
110 if (gfx::DotProduct(cross, normal) > 0.0f) | 98 if (gfx::DotProduct(cross, normal) > 0.0f) |
111 angle = 360.0f - angle; | 99 angle = 360.0f - angle; |
112 return angle; | 100 return angle; |
113 } | 101 } |
114 | 102 |
115 } // namespace | 103 } // namespace |
116 | 104 |
117 MaximizeModeController::MaximizeModeController() | 105 MaximizeModeController::MaximizeModeController() |
118 : rotation_locked_(false), | 106 : have_seen_accelerometer_data_(false), |
119 have_seen_accelerometer_data_(false), | |
120 ignore_display_configuration_updates_(false), | |
121 lid_open_past_180_(false), | 107 lid_open_past_180_(false), |
122 shutting_down_(false), | |
123 user_rotation_(gfx::Display::ROTATE_0), | |
124 last_touchview_transition_time_(base::Time::Now()), | 108 last_touchview_transition_time_(base::Time::Now()), |
125 tick_clock_(new base::DefaultTickClock()), | 109 tick_clock_(new base::DefaultTickClock()), |
126 lid_is_closed_(false) { | 110 lid_is_closed_(false) { |
127 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); | 111 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); |
128 Shell::GetInstance()->AddShellObserver(this); | 112 Shell::GetInstance()->AddShellObserver(this); |
129 #if defined(OS_CHROMEOS) | 113 #if defined(OS_CHROMEOS) |
130 chromeos::DBusThreadManager::Get()-> | 114 chromeos::DBusThreadManager::Get()-> |
131 GetPowerManagerClient()->AddObserver(this); | 115 GetPowerManagerClient()->AddObserver(this); |
132 #endif // OS_CHROMEOS | 116 #endif // OS_CHROMEOS |
133 } | 117 } |
134 | 118 |
135 MaximizeModeController::~MaximizeModeController() { | 119 MaximizeModeController::~MaximizeModeController() { |
136 Shell::GetInstance()->RemoveShellObserver(this); | 120 Shell::GetInstance()->RemoveShellObserver(this); |
137 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); | 121 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); |
138 #if defined(OS_CHROMEOS) | 122 #if defined(OS_CHROMEOS) |
139 chromeos::DBusThreadManager::Get()-> | 123 chromeos::DBusThreadManager::Get()-> |
140 GetPowerManagerClient()->RemoveObserver(this); | 124 GetPowerManagerClient()->RemoveObserver(this); |
141 #endif // OS_CHROMEOS | 125 #endif // OS_CHROMEOS |
142 } | 126 } |
143 | 127 |
144 void MaximizeModeController::SetRotationLocked(bool rotation_locked) { | |
145 if (rotation_locked_ == rotation_locked) | |
146 return; | |
147 base::AutoReset<bool> auto_ignore_display_configuration_updates( | |
148 &ignore_display_configuration_updates_, true); | |
149 rotation_locked_ = rotation_locked; | |
150 Shell::GetInstance()->display_manager()-> | |
151 RegisterDisplayRotationProperties(rotation_locked_, current_rotation_); | |
152 FOR_EACH_OBSERVER(Observer, observers_, | |
153 OnRotationLockChanged(rotation_locked_)); | |
154 } | |
155 | |
156 void MaximizeModeController::LockRotation(gfx::Display::Rotation rotation) { | |
157 SetRotationLocked(true); | |
158 SetDisplayRotation(Shell::GetInstance()->display_manager(), rotation); | |
159 } | |
160 | |
161 void MaximizeModeController::AddObserver(Observer* observer) { | |
162 observers_.AddObserver(observer); | |
163 } | |
164 | |
165 void MaximizeModeController::RemoveObserver(Observer* observer) { | |
166 observers_.RemoveObserver(observer); | |
167 } | |
168 | |
169 bool MaximizeModeController::CanEnterMaximizeMode() { | 128 bool MaximizeModeController::CanEnterMaximizeMode() { |
170 // If we have ever seen accelerometer data, then HandleHingeRotation may | 129 // If we have ever seen accelerometer data, then HandleHingeRotation may |
171 // trigger maximize mode at some point in the future. | 130 // trigger maximize mode at some point in the future. |
172 // The --enable-touch-view-testing switch can also mean that we may enter | 131 // The --enable-touch-view-testing switch can also mean that we may enter |
173 // maximize mode. | 132 // maximize mode. |
174 return have_seen_accelerometer_data_ || | 133 return have_seen_accelerometer_data_ || |
175 base::CommandLine::ForCurrentProcess()->HasSwitch( | 134 base::CommandLine::ForCurrentProcess()->HasSwitch( |
176 switches::kAshEnableTouchViewTesting); | 135 switches::kAshEnableTouchViewTesting); |
177 } | 136 } |
178 | 137 |
(...skipping 11 matching lines...) Expand all Loading... | |
190 | 149 |
191 bool MaximizeModeController::IsMaximizeModeWindowManagerEnabled() const { | 150 bool MaximizeModeController::IsMaximizeModeWindowManagerEnabled() const { |
192 return maximize_mode_window_manager_.get() != NULL; | 151 return maximize_mode_window_manager_.get() != NULL; |
193 } | 152 } |
194 | 153 |
195 void MaximizeModeController::AddWindow(aura::Window* window) { | 154 void MaximizeModeController::AddWindow(aura::Window* window) { |
196 if (IsMaximizeModeWindowManagerEnabled()) | 155 if (IsMaximizeModeWindowManagerEnabled()) |
197 maximize_mode_window_manager_->AddWindow(window); | 156 maximize_mode_window_manager_->AddWindow(window); |
198 } | 157 } |
199 | 158 |
200 void MaximizeModeController::Shutdown() { | |
201 shutting_down_ = true; | |
202 LeaveMaximizeMode(); | |
oshima
2014/12/11 23:51:28
don't we have to keep this for shutdown?
jonross
2014/12/12 18:30:04
Rob and I discussed this, and I looked into it.
A
oshima
2014/12/12 19:59:53
In that case, can you update the document for OnMa
| |
203 } | |
204 | |
205 void MaximizeModeController::OnAccelerometerUpdated( | 159 void MaximizeModeController::OnAccelerometerUpdated( |
206 const ui::AccelerometerUpdate& update) { | 160 const ui::AccelerometerUpdate& update) { |
207 bool first_accelerometer_update = !have_seen_accelerometer_data_; | 161 bool first_accelerometer_update = !have_seen_accelerometer_data_; |
208 have_seen_accelerometer_data_ = true; | 162 have_seen_accelerometer_data_ = true; |
209 | 163 |
210 // Ignore the reading if it appears unstable. The reading is considered | |
211 // unstable if it deviates too much from gravity and/or the magnitude of the | |
212 // reading from the lid differs too much from the reading from the base. | |
213 float lid_magnitude = update.has(ui::ACCELEROMETER_SOURCE_SCREEN) ? | |
214 update.get(ui::ACCELEROMETER_SOURCE_SCREEN).Length() : 0.0f; | |
215 bool lid_stable = update.has(ui::ACCELEROMETER_SOURCE_SCREEN) && | |
216 std::abs(lid_magnitude - kMeanGravity) <= kDeviationFromGravityThreshold; | |
217 | |
218 // Whether or not we enter maximize mode affects whether we handle screen | 164 // Whether or not we enter maximize mode affects whether we handle screen |
219 // rotation, so determine whether to enter maximize mode first. | 165 // rotation, so determine whether to enter maximize mode first. |
220 if (!update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) { | 166 if (!update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) { |
221 if (first_accelerometer_update && | 167 if (first_accelerometer_update && |
222 update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) { | 168 update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) { |
223 EnterMaximizeMode(); | 169 EnterMaximizeMode(); |
224 } | 170 } |
225 } else { // update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) | 171 } else { // update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) |
172 // Ignore the reading if it appears unstable. The reading is considered | |
173 // unstable if it deviates too much from gravity and/or the magnitude of the | |
174 // reading from the lid differs too much from the reading from the base. | |
175 float lid_magnitude = | |
176 update.has(ui::ACCELEROMETER_SOURCE_SCREEN) | |
177 ? update.get(ui::ACCELEROMETER_SOURCE_SCREEN).Length() | |
178 : 0.0f; | |
179 bool lid_stable = update.has(ui::ACCELEROMETER_SOURCE_SCREEN) && | |
180 std::abs(lid_magnitude - kMeanGravity) <= | |
181 kDeviationFromGravityThreshold; | |
oshima
2014/12/11 23:51:28
can you define a utility function in ash/accelerom
jonross
2014/12/12 18:30:04
Done.
| |
226 float base_magnitude = | 182 float base_magnitude = |
227 update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD).Length(); | 183 update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD).Length(); |
228 bool base_angle_stable = lid_stable && | 184 bool base_angle_stable = lid_stable && |
229 std::abs(base_magnitude - lid_magnitude) <= kNoisyMagnitudeDeviation && | 185 std::abs(base_magnitude - lid_magnitude) <= kNoisyMagnitudeDeviation && |
230 std::abs(base_magnitude - kMeanGravity) <= | 186 std::abs(base_magnitude - kMeanGravity) <= |
231 kDeviationFromGravityThreshold; | 187 kDeviationFromGravityThreshold; |
232 if (base_angle_stable) { | 188 if (base_angle_stable) { |
233 HandleHingeRotation( | 189 HandleHingeRotation( |
234 update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD), | 190 update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD), |
235 update.get(ui::ACCELEROMETER_SOURCE_SCREEN)); | 191 update.get(ui::ACCELEROMETER_SOURCE_SCREEN)); |
236 } | 192 } |
237 } | 193 } |
238 | |
239 if (lid_stable) | |
240 HandleScreenRotation(update.get(ui::ACCELEROMETER_SOURCE_SCREEN)); | |
241 | |
242 if (first_accelerometer_update) { | |
243 // On the first accelerometer update we will know if we have entered | |
244 // maximize mode or not. Update the preferences to reflect the current | |
245 // state. | |
246 Shell::GetInstance()->display_manager()-> | |
247 RegisterDisplayRotationProperties(rotation_locked_, current_rotation_); | |
248 } | |
249 } | |
250 | |
251 void MaximizeModeController::OnDisplayConfigurationChanged() { | |
252 if (ignore_display_configuration_updates_) | |
253 return; | |
254 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
255 gfx::Display::Rotation user_rotation = display_manager-> | |
256 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | |
257 if (user_rotation != current_rotation_) { | |
258 // A user may change other display configuration settings. When the user | |
259 // does change the rotation setting, then lock rotation to prevent the | |
260 // accelerometer from erasing their change. | |
261 SetRotationLocked(true); | |
262 user_rotation_ = user_rotation; | |
263 current_rotation_ = user_rotation; | |
264 } | |
265 } | 194 } |
266 | 195 |
267 #if defined(OS_CHROMEOS) | 196 #if defined(OS_CHROMEOS) |
268 void MaximizeModeController::LidEventReceived(bool open, | 197 void MaximizeModeController::LidEventReceived(bool open, |
269 const base::TimeTicks& time) { | 198 const base::TimeTicks& time) { |
270 if (open) | 199 if (open) |
271 last_lid_open_time_ = time; | 200 last_lid_open_time_ = time; |
272 lid_is_closed_ = !open; | 201 lid_is_closed_ = !open; |
273 LeaveMaximizeMode(); | 202 LeaveMaximizeMode(); |
274 } | 203 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 if (!base::CommandLine::ForCurrentProcess()-> | 261 if (!base::CommandLine::ForCurrentProcess()-> |
333 HasSwitch(switches::kAshEnableTouchViewTesting)) { | 262 HasSwitch(switches::kAshEnableTouchViewTesting)) { |
334 EnterMaximizeMode(); | 263 EnterMaximizeMode(); |
335 } | 264 } |
336 #if defined(USE_X11) | 265 #if defined(USE_X11) |
337 event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardX11); | 266 event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardX11); |
338 #endif | 267 #endif |
339 } | 268 } |
340 } | 269 } |
341 | 270 |
342 void MaximizeModeController::HandleScreenRotation(const gfx::Vector3dF& lid) { | |
343 bool maximize_mode_engaged = IsMaximizeModeWindowManagerEnabled(); | |
344 | |
345 // TODO(jonross): track the updated rotation angle even when locked. So that | |
346 // when rotation lock is removed the accelerometer rotation can be applied | |
347 // without waiting for the next update. | |
348 if (!maximize_mode_engaged || rotation_locked_) | |
349 return; | |
350 | |
351 DisplayManager* display_manager = | |
352 Shell::GetInstance()->display_manager(); | |
353 gfx::Display::Rotation current_rotation = display_manager->GetDisplayInfo( | |
354 gfx::Display::InternalDisplayId()).rotation(); | |
355 | |
356 // After determining maximize mode state, determine if the screen should | |
357 // be rotated. | |
358 gfx::Vector3dF lid_flattened(lid.x(), lid.y(), 0.0f); | |
359 float lid_flattened_length = lid_flattened.Length(); | |
360 // When the lid is close to being flat, don't change rotation as it is too | |
361 // sensitive to slight movements. | |
362 if (lid_flattened_length < kMinimumAccelerationScreenRotation) | |
363 return; | |
364 | |
365 // The reference vector is the angle of gravity when the device is rotated | |
366 // clockwise by 45 degrees. Computing the angle between this vector and | |
367 // gravity we can easily determine the expected display rotation. | |
368 static const gfx::Vector3dF rotation_reference(-1.0f, -1.0f, 0.0f); | |
369 | |
370 // Set the down vector to match the expected direction of gravity given the | |
371 // last configured rotation. This is used to enforce a stickiness that the | |
372 // user must overcome to rotate the display and prevents frequent rotations | |
373 // when holding the device near 45 degrees. | |
374 gfx::Vector3dF down(0.0f, 0.0f, 0.0f); | |
375 if (current_rotation == gfx::Display::ROTATE_0) | |
376 down.set_y(-1.0f); | |
377 else if (current_rotation == gfx::Display::ROTATE_90) | |
378 down.set_x(-1.0f); | |
379 else if (current_rotation == gfx::Display::ROTATE_180) | |
380 down.set_y(1.0f); | |
381 else | |
382 down.set_x(1.0f); | |
383 | |
384 // Don't rotate if the screen has not passed the threshold. | |
385 if (AngleBetweenVectorsInDegrees(down, lid_flattened) < | |
386 kDisplayRotationStickyAngleDegrees) { | |
387 return; | |
388 } | |
389 | |
390 float angle = ClockwiseAngleBetweenVectorsInDegrees(rotation_reference, | |
391 lid_flattened, gfx::Vector3dF(0.0f, 0.0f, -1.0f)); | |
392 | |
393 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; | |
394 if (angle < 90.0f) | |
395 new_rotation = gfx::Display::ROTATE_0; | |
396 else if (angle < 180.0f) | |
397 new_rotation = gfx::Display::ROTATE_270; | |
398 else if (angle < 270.0f) | |
399 new_rotation = gfx::Display::ROTATE_180; | |
400 | |
401 if (new_rotation != current_rotation) | |
402 SetDisplayRotation(display_manager, new_rotation); | |
403 } | |
404 | |
405 void MaximizeModeController::SetDisplayRotation( | |
406 DisplayManager* display_manager, | |
407 gfx::Display::Rotation rotation) { | |
408 base::AutoReset<bool> auto_ignore_display_configuration_updates( | |
409 &ignore_display_configuration_updates_, true); | |
410 current_rotation_ = rotation; | |
411 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | |
412 rotation); | |
413 } | |
414 | |
415 void MaximizeModeController::EnterMaximizeMode() { | 271 void MaximizeModeController::EnterMaximizeMode() { |
416 if (IsMaximizeModeWindowManagerEnabled()) | 272 if (IsMaximizeModeWindowManagerEnabled()) |
417 return; | 273 return; |
418 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
419 if (display_manager->HasInternalDisplay()) { | |
420 current_rotation_ = user_rotation_ = display_manager-> | |
421 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | |
422 LoadDisplayRotationProperties(); | |
423 } | |
424 EnableMaximizeModeWindowManager(true); | 274 EnableMaximizeModeWindowManager(true); |
425 Shell::GetInstance()->display_controller()->AddObserver(this); | |
426 } | 275 } |
427 | 276 |
428 void MaximizeModeController::LeaveMaximizeMode() { | 277 void MaximizeModeController::LeaveMaximizeMode() { |
429 if (!IsMaximizeModeWindowManagerEnabled()) | 278 if (!IsMaximizeModeWindowManagerEnabled()) |
430 return; | 279 return; |
431 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
432 if (display_manager->HasInternalDisplay()) { | |
433 gfx::Display::Rotation current_rotation = display_manager-> | |
434 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | |
435 if (current_rotation != user_rotation_) | |
436 SetDisplayRotation(display_manager, user_rotation_); | |
437 } | |
438 if (!shutting_down_) | |
439 SetRotationLocked(false); | |
440 EnableMaximizeModeWindowManager(false); | 280 EnableMaximizeModeWindowManager(false); |
441 Shell::GetInstance()->display_controller()->RemoveObserver(this); | |
442 } | 281 } |
443 | 282 |
444 // Called after maximize mode has started, windows might still animate though. | 283 // Called after maximize mode has started, windows might still animate though. |
445 void MaximizeModeController::OnMaximizeModeStarted() { | 284 void MaximizeModeController::OnMaximizeModeStarted() { |
446 RecordTouchViewStateTransition(); | 285 RecordTouchViewStateTransition(); |
447 } | 286 } |
448 | 287 |
449 // Called after maximize mode has ended, windows might still be returning to | 288 // Called after maximize mode has ended, windows might still be returning to |
450 // their original position. | 289 // their original position. |
451 void MaximizeModeController::OnMaximizeModeEnded() { | 290 void MaximizeModeController::OnMaximizeModeEnded() { |
452 RecordTouchViewStateTransition(); | 291 RecordTouchViewStateTransition(); |
453 } | 292 } |
454 | 293 |
455 void MaximizeModeController::RecordTouchViewStateTransition() { | 294 void MaximizeModeController::RecordTouchViewStateTransition() { |
456 if (CanEnterMaximizeMode()) { | 295 if (CanEnterMaximizeMode()) { |
457 base::Time current_time = base::Time::Now(); | 296 base::Time current_time = base::Time::Now(); |
458 base::TimeDelta delta = current_time - last_touchview_transition_time_; | 297 base::TimeDelta delta = current_time - last_touchview_transition_time_; |
459 if (IsMaximizeModeWindowManagerEnabled()) { | 298 if (IsMaximizeModeWindowManagerEnabled()) { |
460 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewInactive", delta); | 299 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewInactive", delta); |
461 total_non_touchview_time_ += delta; | 300 total_non_touchview_time_ += delta; |
462 } else { | 301 } else { |
463 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewActive", delta); | 302 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewActive", delta); |
464 total_touchview_time_ += delta; | 303 total_touchview_time_ += delta; |
465 } | 304 } |
466 last_touchview_transition_time_ = current_time; | 305 last_touchview_transition_time_ = current_time; |
467 } | 306 } |
468 } | 307 } |
469 | 308 |
470 void MaximizeModeController::LoadDisplayRotationProperties() { | |
471 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
472 if (!display_manager->registered_internal_display_rotation_lock()) | |
473 return; | |
474 | |
475 SetDisplayRotation(display_manager, | |
476 display_manager->registered_internal_display_rotation()); | |
477 SetRotationLocked(true); | |
478 } | |
479 | |
480 void MaximizeModeController::OnAppTerminating() { | 309 void MaximizeModeController::OnAppTerminating() { |
481 if (CanEnterMaximizeMode()) { | 310 if (CanEnterMaximizeMode()) { |
482 RecordTouchViewStateTransition(); | 311 RecordTouchViewStateTransition(); |
483 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewActiveTotal", | 312 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewActiveTotal", |
484 total_touchview_time_.InMinutes(), | 313 total_touchview_time_.InMinutes(), |
485 1, base::TimeDelta::FromDays(7).InMinutes(), 50); | 314 1, base::TimeDelta::FromDays(7).InMinutes(), 50); |
486 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewInactiveTotal", | 315 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewInactiveTotal", |
487 total_non_touchview_time_.InMinutes(), | 316 total_non_touchview_time_.InMinutes(), |
488 1, base::TimeDelta::FromDays(7).InMinutes(), 50); | 317 1, base::TimeDelta::FromDays(7).InMinutes(), 50); |
489 base::TimeDelta total_runtime = total_touchview_time_ + | 318 base::TimeDelta total_runtime = total_touchview_time_ + |
490 total_non_touchview_time_; | 319 total_non_touchview_time_; |
491 if (total_runtime.InSeconds() > 0) { | 320 if (total_runtime.InSeconds() > 0) { |
492 UMA_HISTOGRAM_PERCENTAGE("Ash.TouchView.TouchViewActivePercentage", | 321 UMA_HISTOGRAM_PERCENTAGE("Ash.TouchView.TouchViewActivePercentage", |
493 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds()); | 322 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds()); |
494 } | 323 } |
495 } | 324 } |
496 Shell::GetInstance()->display_controller()->RemoveObserver(this); | |
497 } | 325 } |
498 | 326 |
499 bool MaximizeModeController::WasLidOpenedRecently() const { | 327 bool MaximizeModeController::WasLidOpenedRecently() const { |
500 if (last_lid_open_time_.is_null()) | 328 if (last_lid_open_time_.is_null()) |
501 return false; | 329 return false; |
502 | 330 |
503 base::TimeTicks now = tick_clock_->NowTicks(); | 331 base::TimeTicks now = tick_clock_->NowTicks(); |
504 DCHECK(now >= last_lid_open_time_); | 332 DCHECK(now >= last_lid_open_time_); |
505 base::TimeDelta elapsed_time = now - last_lid_open_time_; | 333 base::TimeDelta elapsed_time = now - last_lid_open_time_; |
506 return elapsed_time <= kLidRecentlyOpenedDuration; | 334 return elapsed_time <= kLidRecentlyOpenedDuration; |
507 } | 335 } |
508 | 336 |
509 void MaximizeModeController::SetTickClockForTest( | 337 void MaximizeModeController::SetTickClockForTest( |
510 scoped_ptr<base::TickClock> tick_clock) { | 338 scoped_ptr<base::TickClock> tick_clock) { |
511 DCHECK(tick_clock_); | 339 DCHECK(tick_clock_); |
512 tick_clock_ = tick_clock.Pass(); | 340 tick_clock_ = tick_clock.Pass(); |
513 } | 341 } |
514 | 342 |
515 } // namespace ash | 343 } // namespace ash |
OLD | NEW |