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

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

Powered by Google App Engine
This is Rietveld 408576698