Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(681)

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller.cc

Issue 759063002: Move Screen Rotation from MaximizeModeController to ScreenOrientationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change similarity to account for moved files Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 22 matching lines...) Expand all
48 const float kMinStableAngle = 20.0f; 47 const float kMinStableAngle = 20.0f;
49 const float kMaxStableAngle = 340.0f; 48 const float kMaxStableAngle = 340.0f;
50 49
51 // The time duration to consider the lid to be recently opened. 50 // The time duration to consider the lid to be recently opened.
52 // This is used to prevent entering maximize mode if an erroneous accelerometer 51 // This is used to prevent entering maximize mode if an erroneous accelerometer
53 // reading makes the lid appear to be fully open when the user is opening the 52 // reading makes the lid appear to be fully open when the user is opening the
54 // lid from a closed position. 53 // lid from a closed position.
55 const base::TimeDelta kLidRecentlyOpenedDuration = 54 const base::TimeDelta kLidRecentlyOpenedDuration =
56 base::TimeDelta::FromSeconds(2); 55 base::TimeDelta::FromSeconds(2);
57 56
58 // The mean acceleration due to gravity on Earth in m/s^2.
59 const float kMeanGravity = 9.80665f;
60
61 // When the device approaches vertical orientation (i.e. portrait orientation) 57 // When the device approaches vertical orientation (i.e. portrait orientation)
62 // the accelerometers for the base and lid approach the same values (i.e. 58 // the accelerometers for the base and lid approach the same values (i.e.
63 // gravity pointing in the direction of the hinge). When this happens we cannot 59 // gravity pointing in the direction of the hinge). When this happens we cannot
64 // compute the hinge angle reliably and must turn ignore accelerometer readings. 60 // compute the hinge angle reliably and must turn ignore accelerometer readings.
65 // This is the minimum acceleration perpendicular to the hinge under which to 61 // This is the minimum acceleration perpendicular to the hinge under which to
66 // detect hinge angle in m/s^2. 62 // detect hinge angle in m/s^2.
67 const float kHingeAngleDetectionThreshold = 2.5f; 63 const float kHingeAngleDetectionThreshold = 2.5f;
68 64
69 // The maximum deviation from the acceleration expected due to gravity under
70 // which to detect hinge angle and screen rotation in m/s^2
71 const float kDeviationFromGravityThreshold = 1.0f;
72
73 // The maximum deviation between the magnitude of the two accelerometers under 65 // 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 66 // 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 67 // accelerometers are attached to the same physical device and so should be
76 // under the same acceleration. 68 // under the same acceleration.
77 const float kNoisyMagnitudeDeviation = 1.0f; 69 const float kNoisyMagnitudeDeviation = 1.0f;
78 70
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; 71 const float kRadiansToDegrees = 180.0f / 3.14159265f;
91 72
92 // Returns the angle between |base| and |other| in degrees. 73 // Returns the angle between |base| and |other| in degrees.
93 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, 74 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,
94 const gfx::Vector3dF& other) { 75 const gfx::Vector3dF& other) {
95 return acos(gfx::DotProduct(base, other) / 76 return acos(gfx::DotProduct(base, other) /
96 base.Length() / other.Length()) * kRadiansToDegrees; 77 base.Length() / other.Length()) * kRadiansToDegrees;
97 } 78 }
98 79
99 // Returns the clockwise angle between |base| and |other| where |normal| is the 80 // Returns the clockwise angle between |base| and |other| where |normal| is the
100 // normal of the virtual surface to measure clockwise according to. 81 // normal of the virtual surface to measure clockwise according to.
101 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, 82 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,
102 const gfx::Vector3dF& other, 83 const gfx::Vector3dF& other,
103 const gfx::Vector3dF& normal) { 84 const gfx::Vector3dF& normal) {
104 float angle = AngleBetweenVectorsInDegrees(base, other); 85 float angle = AngleBetweenVectorsInDegrees(base, other);
105 gfx::Vector3dF cross(base); 86 gfx::Vector3dF cross(base);
106 cross.Cross(other); 87 cross.Cross(other);
107 // If the dot product of this cross product is normal, it means that the 88 // 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 89 // shortest angle between |base| and |other| was counterclockwise with respect
109 // to the surface represented by |normal| and this angle must be reversed. 90 // to the surface represented by |normal| and this angle must be reversed.
110 if (gfx::DotProduct(cross, normal) > 0.0f) 91 if (gfx::DotProduct(cross, normal) > 0.0f)
111 angle = 360.0f - angle; 92 angle = 360.0f - angle;
112 return angle; 93 return angle;
113 } 94 }
114 95
115 } // namespace 96 } // namespace
116 97
117 MaximizeModeController::MaximizeModeController() 98 MaximizeModeController::MaximizeModeController()
118 : rotation_locked_(false), 99 : have_seen_accelerometer_data_(false),
119 have_seen_accelerometer_data_(false),
120 ignore_display_configuration_updates_(false),
121 lid_open_past_180_(false), 100 lid_open_past_180_(false),
122 shutting_down_(false),
123 user_rotation_(gfx::Display::ROTATE_0),
124 last_touchview_transition_time_(base::Time::Now()), 101 last_touchview_transition_time_(base::Time::Now()),
125 tick_clock_(new base::DefaultTickClock()), 102 tick_clock_(new base::DefaultTickClock()),
126 lid_is_closed_(false) { 103 lid_is_closed_(false) {
127 Shell::GetInstance()->accelerometer_controller()->AddObserver(this); 104 Shell::GetInstance()->accelerometer_controller()->AddObserver(this);
128 Shell::GetInstance()->AddShellObserver(this); 105 Shell::GetInstance()->AddShellObserver(this);
129 #if defined(OS_CHROMEOS) 106 #if defined(OS_CHROMEOS)
130 chromeos::DBusThreadManager::Get()-> 107 chromeos::DBusThreadManager::Get()->
131 GetPowerManagerClient()->AddObserver(this); 108 GetPowerManagerClient()->AddObserver(this);
132 #endif // OS_CHROMEOS 109 #endif // OS_CHROMEOS
133 } 110 }
134 111
135 MaximizeModeController::~MaximizeModeController() { 112 MaximizeModeController::~MaximizeModeController() {
136 Shell::GetInstance()->RemoveShellObserver(this); 113 Shell::GetInstance()->RemoveShellObserver(this);
137 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this); 114 Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
138 #if defined(OS_CHROMEOS) 115 #if defined(OS_CHROMEOS)
139 chromeos::DBusThreadManager::Get()-> 116 chromeos::DBusThreadManager::Get()->
140 GetPowerManagerClient()->RemoveObserver(this); 117 GetPowerManagerClient()->RemoveObserver(this);
141 #endif // OS_CHROMEOS 118 #endif // OS_CHROMEOS
142 } 119 }
143 120
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() { 121 bool MaximizeModeController::CanEnterMaximizeMode() {
170 // If we have ever seen accelerometer data, then HandleHingeRotation may 122 // If we have ever seen accelerometer data, then HandleHingeRotation may
171 // trigger maximize mode at some point in the future. 123 // trigger maximize mode at some point in the future.
172 // The --enable-touch-view-testing switch can also mean that we may enter 124 // The --enable-touch-view-testing switch can also mean that we may enter
173 // maximize mode. 125 // maximize mode.
174 return have_seen_accelerometer_data_ || 126 return have_seen_accelerometer_data_ ||
175 base::CommandLine::ForCurrentProcess()->HasSwitch( 127 base::CommandLine::ForCurrentProcess()->HasSwitch(
176 switches::kAshEnableTouchViewTesting); 128 switches::kAshEnableTouchViewTesting);
177 } 129 }
178 130
(...skipping 11 matching lines...) Expand all
190 142
191 bool MaximizeModeController::IsMaximizeModeWindowManagerEnabled() const { 143 bool MaximizeModeController::IsMaximizeModeWindowManagerEnabled() const {
192 return maximize_mode_window_manager_.get() != NULL; 144 return maximize_mode_window_manager_.get() != NULL;
193 } 145 }
194 146
195 void MaximizeModeController::AddWindow(aura::Window* window) { 147 void MaximizeModeController::AddWindow(aura::Window* window) {
196 if (IsMaximizeModeWindowManagerEnabled()) 148 if (IsMaximizeModeWindowManagerEnabled())
197 maximize_mode_window_manager_->AddWindow(window); 149 maximize_mode_window_manager_->AddWindow(window);
198 } 150 }
199 151
200 void MaximizeModeController::Shutdown() {
201 shutting_down_ = true;
202 LeaveMaximizeMode();
203 }
204
205 void MaximizeModeController::OnAccelerometerUpdated( 152 void MaximizeModeController::OnAccelerometerUpdated(
206 const ui::AccelerometerUpdate& update) { 153 const ui::AccelerometerUpdate& update) {
207 bool first_accelerometer_update = !have_seen_accelerometer_data_; 154 bool first_accelerometer_update = !have_seen_accelerometer_data_;
208 have_seen_accelerometer_data_ = true; 155 have_seen_accelerometer_data_ = true;
209 156
210 // Ignore the reading if it appears unstable. The reading is considered 157 if (!update.has(ui::ACCELEROMETER_SOURCE_SCREEN))
211 // unstable if it deviates too much from gravity and/or the magnitude of the 158 return;
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 159
218 // Whether or not we enter maximize mode affects whether we handle screen 160 // Whether or not we enter maximize mode affects whether we handle screen
219 // rotation, so determine whether to enter maximize mode first. 161 // rotation, so determine whether to enter maximize mode first.
220 if (!update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) { 162 if (!update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) {
221 if (first_accelerometer_update && 163 if (first_accelerometer_update &&
222 update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) { 164 update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) {
flackr 2014/12/12 20:46:06 nit: already checked that it has source screen on
jonross 2015/01/06 19:56:10 Done.
223 EnterMaximizeMode(); 165 EnterMaximizeMode();
224 } 166 }
225 } else { // update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) 167 } else if (update.IsReadingStable(ui::ACCELEROMETER_SOURCE_SCREEN) &&
226 float base_magnitude = 168 update.IsReadingStable(
227 update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD).Length(); 169 ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD) &&
228 bool base_angle_stable = lid_stable && 170 std::abs(update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)
229 std::abs(base_magnitude - lid_magnitude) <= kNoisyMagnitudeDeviation && 171 .Length() -
230 std::abs(base_magnitude - kMeanGravity) <= 172 update.get(ui::ACCELEROMETER_SOURCE_SCREEN).Length()) <=
231 kDeviationFromGravityThreshold; 173 kNoisyMagnitudeDeviation) {
232 if (base_angle_stable) { 174 // update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)
233 HandleHingeRotation( 175 // Ignore the reading if it appears unstable. The reading is considered
234 update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD), 176 // unstable if it deviates too much from gravity and/or the magnitude of the
235 update.get(ui::ACCELEROMETER_SOURCE_SCREEN)); 177 // reading from the lid differs too much from the reading from the base.
236 } 178 HandleHingeRotation(update.get(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD),
237 } 179 update.get(ui::ACCELEROMETER_SOURCE_SCREEN));
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 } 180 }
249 } 181 }
250 182
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 }
266
267 #if defined(OS_CHROMEOS) 183 #if defined(OS_CHROMEOS)
268 void MaximizeModeController::LidEventReceived(bool open, 184 void MaximizeModeController::LidEventReceived(bool open,
269 const base::TimeTicks& time) { 185 const base::TimeTicks& time) {
270 if (open) 186 if (open)
271 last_lid_open_time_ = time; 187 last_lid_open_time_ = time;
272 lid_is_closed_ = !open; 188 lid_is_closed_ = !open;
273 LeaveMaximizeMode(); 189 LeaveMaximizeMode();
274 } 190 }
275 191
276 void MaximizeModeController::SuspendImminent() { 192 void MaximizeModeController::SuspendImminent() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 if (!base::CommandLine::ForCurrentProcess()-> 248 if (!base::CommandLine::ForCurrentProcess()->
333 HasSwitch(switches::kAshEnableTouchViewTesting)) { 249 HasSwitch(switches::kAshEnableTouchViewTesting)) {
334 EnterMaximizeMode(); 250 EnterMaximizeMode();
335 } 251 }
336 #if defined(USE_X11) 252 #if defined(USE_X11)
337 event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardX11); 253 event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardX11);
338 #endif 254 #endif
339 } 255 }
340 } 256 }
341 257
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() { 258 void MaximizeModeController::EnterMaximizeMode() {
416 if (IsMaximizeModeWindowManagerEnabled()) 259 if (IsMaximizeModeWindowManagerEnabled())
417 return; 260 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); 261 EnableMaximizeModeWindowManager(true);
425 Shell::GetInstance()->display_controller()->AddObserver(this);
426 } 262 }
427 263
428 void MaximizeModeController::LeaveMaximizeMode() { 264 void MaximizeModeController::LeaveMaximizeMode() {
429 if (!IsMaximizeModeWindowManagerEnabled()) 265 if (!IsMaximizeModeWindowManagerEnabled())
430 return; 266 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); 267 EnableMaximizeModeWindowManager(false);
441 Shell::GetInstance()->display_controller()->RemoveObserver(this);
442 } 268 }
443 269
444 // Called after maximize mode has started, windows might still animate though. 270 // Called after maximize mode has started, windows might still animate though.
445 void MaximizeModeController::OnMaximizeModeStarted() { 271 void MaximizeModeController::OnMaximizeModeStarted() {
446 RecordTouchViewStateTransition(); 272 RecordTouchViewStateTransition();
447 } 273 }
448 274
449 // Called after maximize mode has ended, windows might still be returning to 275 // Called after maximize mode has ended, windows might still be returning to
450 // their original position. 276 // their original position.
451 void MaximizeModeController::OnMaximizeModeEnded() { 277 void MaximizeModeController::OnMaximizeModeEnded() {
452 RecordTouchViewStateTransition(); 278 RecordTouchViewStateTransition();
453 } 279 }
454 280
455 void MaximizeModeController::RecordTouchViewStateTransition() { 281 void MaximizeModeController::RecordTouchViewStateTransition() {
456 if (CanEnterMaximizeMode()) { 282 if (CanEnterMaximizeMode()) {
457 base::Time current_time = base::Time::Now(); 283 base::Time current_time = base::Time::Now();
458 base::TimeDelta delta = current_time - last_touchview_transition_time_; 284 base::TimeDelta delta = current_time - last_touchview_transition_time_;
459 if (IsMaximizeModeWindowManagerEnabled()) { 285 if (IsMaximizeModeWindowManagerEnabled()) {
460 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewInactive", delta); 286 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewInactive", delta);
461 total_non_touchview_time_ += delta; 287 total_non_touchview_time_ += delta;
462 } else { 288 } else {
463 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewActive", delta); 289 UMA_HISTOGRAM_LONG_TIMES("Ash.TouchView.TouchViewActive", delta);
464 total_touchview_time_ += delta; 290 total_touchview_time_ += delta;
465 } 291 }
466 last_touchview_transition_time_ = current_time; 292 last_touchview_transition_time_ = current_time;
467 } 293 }
468 } 294 }
469 295
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() { 296 void MaximizeModeController::OnAppTerminating() {
481 if (CanEnterMaximizeMode()) { 297 if (CanEnterMaximizeMode()) {
482 RecordTouchViewStateTransition(); 298 RecordTouchViewStateTransition();
483 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewActiveTotal", 299 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewActiveTotal",
484 total_touchview_time_.InMinutes(), 300 total_touchview_time_.InMinutes(),
485 1, base::TimeDelta::FromDays(7).InMinutes(), 50); 301 1, base::TimeDelta::FromDays(7).InMinutes(), 50);
486 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewInactiveTotal", 302 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchView.TouchViewInactiveTotal",
487 total_non_touchview_time_.InMinutes(), 303 total_non_touchview_time_.InMinutes(),
488 1, base::TimeDelta::FromDays(7).InMinutes(), 50); 304 1, base::TimeDelta::FromDays(7).InMinutes(), 50);
489 base::TimeDelta total_runtime = total_touchview_time_ + 305 base::TimeDelta total_runtime = total_touchview_time_ +
490 total_non_touchview_time_; 306 total_non_touchview_time_;
491 if (total_runtime.InSeconds() > 0) { 307 if (total_runtime.InSeconds() > 0) {
492 UMA_HISTOGRAM_PERCENTAGE("Ash.TouchView.TouchViewActivePercentage", 308 UMA_HISTOGRAM_PERCENTAGE("Ash.TouchView.TouchViewActivePercentage",
493 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds()); 309 100 * total_touchview_time_.InSeconds() / total_runtime.InSeconds());
494 } 310 }
495 } 311 }
496 Shell::GetInstance()->display_controller()->RemoveObserver(this);
497 } 312 }
498 313
499 bool MaximizeModeController::WasLidOpenedRecently() const { 314 bool MaximizeModeController::WasLidOpenedRecently() const {
500 if (last_lid_open_time_.is_null()) 315 if (last_lid_open_time_.is_null())
501 return false; 316 return false;
502 317
503 base::TimeTicks now = tick_clock_->NowTicks(); 318 base::TimeTicks now = tick_clock_->NowTicks();
504 DCHECK(now >= last_lid_open_time_); 319 DCHECK(now >= last_lid_open_time_);
505 base::TimeDelta elapsed_time = now - last_lid_open_time_; 320 base::TimeDelta elapsed_time = now - last_lid_open_time_;
506 return elapsed_time <= kLidRecentlyOpenedDuration; 321 return elapsed_time <= kLidRecentlyOpenedDuration;
507 } 322 }
508 323
509 void MaximizeModeController::SetTickClockForTest( 324 void MaximizeModeController::SetTickClockForTest(
510 scoped_ptr<base::TickClock> tick_clock) { 325 scoped_ptr<base::TickClock> tick_clock) {
511 DCHECK(tick_clock_); 326 DCHECK(tick_clock_);
512 tick_clock_ = tick_clock.Pass(); 327 tick_clock_ = tick_clock.Pass();
513 } 328 }
514 329
515 } // namespace ash 330 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698