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

Side by Side Diff: ash/content/display/screen_orientation_controller_chromeos.cc

Issue 1071353003: Prevent DisplayPreferences from saving incorrect rotations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months 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/content/display/screen_orientation_controller_chromeos.h" 5 #include "ash/content/display/screen_orientation_controller_chromeos.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/display/display_info.h" 8 #include "ash/display/display_info.h"
9 #include "ash/display/display_manager.h" 9 #include "ash/display/display_manager.h"
10 #include "ash/rotator/screen_rotation_animator.h" 10 #include "ash/rotator/screen_rotation_animator.h"
(...skipping 27 matching lines...) Expand all
38 38
39 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { 39 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() {
40 ash::DisplayManager* display_manager = 40 ash::DisplayManager* display_manager =
41 ash::Shell::GetInstance()->display_manager(); 41 ash::Shell::GetInstance()->display_manager();
42 if (!display_manager->HasInternalDisplay()) 42 if (!display_manager->HasInternalDisplay())
43 return blink::WebScreenOrientationLockLandscape; 43 return blink::WebScreenOrientationLockLandscape;
44 44
45 ash::DisplayInfo info = 45 ash::DisplayInfo info =
46 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()); 46 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId());
47 gfx::Size size = info.size_in_pixel(); 47 gfx::Size size = info.size_in_pixel();
48 switch (info.rotation()) { 48 switch (info.Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE)) {
49 case gfx::Display::ROTATE_0: 49 case gfx::Display::ROTATE_0:
50 case gfx::Display::ROTATE_180: 50 case gfx::Display::ROTATE_180:
51 return size.height() >= size.width() 51 return size.height() >= size.width()
52 ? blink::WebScreenOrientationLockPortrait 52 ? blink::WebScreenOrientationLockPortrait
53 : blink::WebScreenOrientationLockLandscape; 53 : blink::WebScreenOrientationLockLandscape;
54 case gfx::Display::ROTATE_90: 54 case gfx::Display::ROTATE_90:
55 case gfx::Display::ROTATE_270: 55 case gfx::Display::ROTATE_270:
56 return size.height() < size.width() 56 return size.height() < size.width()
57 ? blink::WebScreenOrientationLockPortrait 57 ? blink::WebScreenOrientationLockPortrait
58 : blink::WebScreenOrientationLockLandscape; 58 : blink::WebScreenOrientationLockLandscape;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 105 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
106 if (!display_manager->HasInternalDisplay()) 106 if (!display_manager->HasInternalDisplay())
107 return; 107 return;
108 base::AutoReset<bool> auto_ignore_display_configuration_updates( 108 base::AutoReset<bool> auto_ignore_display_configuration_updates(
109 &ignore_display_configuration_updates_, true); 109 &ignore_display_configuration_updates_, true);
110 display_manager->RegisterDisplayRotationProperties(rotation_locked_, 110 display_manager->RegisterDisplayRotationProperties(rotation_locked_,
111 current_rotation_); 111 current_rotation_);
112 } 112 }
113 113
114 void ScreenOrientationController::SetDisplayRotation( 114 void ScreenOrientationController::SetDisplayRotation(
115 gfx::Display::Rotation rotation) { 115 gfx::Display::Rotation rotation,
116 gfx::Display::RotationSource source) {
116 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 117 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
117 if (!display_manager->HasInternalDisplay()) 118 if (!display_manager->HasInternalDisplay())
118 return; 119 return;
119 current_rotation_ = rotation; 120 current_rotation_ = rotation;
120 base::AutoReset<bool> auto_ignore_display_configuration_updates( 121 base::AutoReset<bool> auto_ignore_display_configuration_updates(
121 &ignore_display_configuration_updates_, true); 122 &ignore_display_configuration_updates_, true);
122 ash::ScreenRotationAnimator(gfx::Display::InternalDisplayId()) 123 ash::ScreenRotationAnimator(gfx::Display::InternalDisplayId())
123 .Rotate(rotation); 124 .Rotate(rotation, source);
124 } 125 }
125 126
126 void ScreenOrientationController::OnWindowActivated(aura::Window* gained_active, 127 void ScreenOrientationController::OnWindowActivated(aura::Window* gained_active,
127 aura::Window* lost_active) { 128 aura::Window* lost_active) {
128 ApplyLockForActiveWindow(); 129 ApplyLockForActiveWindow();
129 } 130 }
130 131
131 // Currently contents::WebContents will only be able to lock rotation while 132 // Currently contents::WebContents will only be able to lock rotation while
132 // fullscreen. In this state a user cannot click on the tab strip to change. If 133 // fullscreen. In this state a user cannot click on the tab strip to change. If
133 // this becomes supported for non-fullscreen tabs then the following interferes 134 // this becomes supported for non-fullscreen tabs then the following interferes
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 RemoveLockingWindow(requesting_window); 194 RemoveLockingWindow(requesting_window);
194 } 195 }
195 196
196 void ScreenOrientationController::OnDisplayConfigurationChanged() { 197 void ScreenOrientationController::OnDisplayConfigurationChanged() {
197 if (ignore_display_configuration_updates_) 198 if (ignore_display_configuration_updates_)
198 return; 199 return;
199 gfx::Display::Rotation user_rotation = 200 gfx::Display::Rotation user_rotation =
200 Shell::GetInstance() 201 Shell::GetInstance()
201 ->display_manager() 202 ->display_manager()
202 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) 203 ->GetDisplayInfo(gfx::Display::InternalDisplayId())
203 .rotation(); 204 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE);
204 if (user_rotation != current_rotation_) { 205 if (user_rotation != current_rotation_) {
205 // A user may change other display configuration settings. When the user 206 // A user may change other display configuration settings. When the user
206 // does change the rotation setting, then lock rotation to prevent the 207 // does change the rotation setting, then lock rotation to prevent the
207 // accelerometer from erasing their change. 208 // accelerometer from erasing their change.
208 SetRotationLocked(true); 209 SetRotationLocked(true);
209 user_rotation_ = current_rotation_ = user_rotation; 210 user_rotation_ = current_rotation_ = user_rotation;
210 } 211 }
211 } 212 }
212 213
213 void ScreenOrientationController::OnMaximizeModeStarted() { 214 void ScreenOrientationController::OnMaximizeModeStarted() {
214 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 215 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
215 if (!display_manager->HasInternalDisplay()) 216 if (!display_manager->HasInternalDisplay())
216 return; 217 return;
217 current_rotation_ = user_rotation_ = 218 current_rotation_ = user_rotation_ =
218 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) 219 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId())
219 .rotation(); 220 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE);
220 if (!rotation_locked_) 221 if (!rotation_locked_)
221 LoadDisplayRotationProperties(); 222 LoadDisplayRotationProperties();
222 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); 223 chromeos::AccelerometerReader::GetInstance()->AddObserver(this);
223 Shell::GetInstance()->display_controller()->AddObserver(this); 224 Shell::GetInstance()->display_controller()->AddObserver(this);
224 } 225 }
225 226
226 void ScreenOrientationController::OnMaximizeModeEnded() { 227 void ScreenOrientationController::OnMaximizeModeEnded() {
227 if (!Shell::GetInstance()->display_manager()->HasInternalDisplay()) 228 if (!Shell::GetInstance()->display_manager()->HasInternalDisplay())
228 return; 229 return;
229 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); 230 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this);
230 Shell::GetInstance()->display_controller()->RemoveObserver(this); 231 Shell::GetInstance()->display_controller()->RemoveObserver(this);
231 if (current_rotation_ != user_rotation_) 232 if (current_rotation_ != user_rotation_)
232 SetDisplayRotation(user_rotation_); 233 SetDisplayRotation(user_rotation_, gfx::Display::ROTATION_SOURCE_USER);
233 } 234 }
234 235
235 void ScreenOrientationController::LockRotation( 236 void ScreenOrientationController::LockRotation(
236 gfx::Display::Rotation rotation) { 237 gfx::Display::Rotation rotation,
238 gfx::Display::RotationSource source) {
237 SetRotationLocked(true); 239 SetRotationLocked(true);
238 SetDisplayRotation(rotation); 240 SetDisplayRotation(rotation, source);
239 } 241 }
240 242
241 void ScreenOrientationController::LockRotationToOrientation( 243 void ScreenOrientationController::LockRotationToOrientation(
242 blink::WebScreenOrientationLockType lock_orientation) { 244 blink::WebScreenOrientationLockType lock_orientation) {
243 rotation_locked_orientation_ = lock_orientation; 245 rotation_locked_orientation_ = lock_orientation;
244 switch (lock_orientation) { 246 switch (lock_orientation) {
245 case blink::WebScreenOrientationLockAny: 247 case blink::WebScreenOrientationLockAny:
246 SetRotationLocked(false); 248 SetRotationLocked(false);
247 break; 249 break;
248 case blink::WebScreenOrientationLockDefault: 250 case blink::WebScreenOrientationLockDefault:
(...skipping 12 matching lines...) Expand all
261 break; 263 break;
262 case blink::WebScreenOrientationLockLandscapeSecondary: 264 case blink::WebScreenOrientationLockLandscapeSecondary:
263 LockRotationToSecondaryOrientation( 265 LockRotationToSecondaryOrientation(
264 blink::WebScreenOrientationLockLandscape); 266 blink::WebScreenOrientationLockLandscape);
265 break; 267 break;
266 case blink::WebScreenOrientationLockLandscapePrimary: 268 case blink::WebScreenOrientationLockLandscapePrimary:
267 LockRotationToPrimaryOrientation( 269 LockRotationToPrimaryOrientation(
268 blink::WebScreenOrientationLockLandscape); 270 blink::WebScreenOrientationLockLandscape);
269 break; 271 break;
270 case blink::WebScreenOrientationLockNatural: 272 case blink::WebScreenOrientationLockNatural:
271 LockRotation(gfx::Display::ROTATE_0); 273 LockRotation(gfx::Display::ROTATE_0,
274 gfx::Display::ROTATION_SOURCE_ACTIVE);
272 break; 275 break;
273 default: 276 default:
274 NOTREACHED(); 277 NOTREACHED();
275 break; 278 break;
276 } 279 }
277 } 280 }
278 281
279 void ScreenOrientationController::LockRotationToPrimaryOrientation( 282 void ScreenOrientationController::LockRotationToPrimaryOrientation(
280 blink::WebScreenOrientationLockType lock_orientation) { 283 blink::WebScreenOrientationLockType lock_orientation) {
281 LockRotation(natural_orientation_ == lock_orientation 284 LockRotation(natural_orientation_ == lock_orientation
282 ? gfx::Display::ROTATE_0 285 ? gfx::Display::ROTATE_0
283 : gfx::Display::ROTATE_90); 286 : gfx::Display::ROTATE_90,
287 gfx::Display::ROTATION_SOURCE_ACTIVE);
284 } 288 }
285 289
286 void ScreenOrientationController::LockRotationToSecondaryOrientation( 290 void ScreenOrientationController::LockRotationToSecondaryOrientation(
287 blink::WebScreenOrientationLockType lock_orientation) { 291 blink::WebScreenOrientationLockType lock_orientation) {
288 LockRotation(natural_orientation_ == lock_orientation 292 LockRotation(natural_orientation_ == lock_orientation
289 ? gfx::Display::ROTATE_180 293 ? gfx::Display::ROTATE_180
290 : gfx::Display::ROTATE_270); 294 : gfx::Display::ROTATE_270,
295 gfx::Display::ROTATION_SOURCE_ACTIVE);
291 } 296 }
292 297
293 void ScreenOrientationController::LockToRotationMatchingOrientation( 298 void ScreenOrientationController::LockToRotationMatchingOrientation(
294 blink::WebScreenOrientationLockType lock_orientation) { 299 blink::WebScreenOrientationLockType lock_orientation) {
295 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 300 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
296 if (!display_manager->HasInternalDisplay()) 301 if (!display_manager->HasInternalDisplay())
297 return; 302 return;
298 303
299 gfx::Display::Rotation rotation = 304 gfx::Display::Rotation rotation =
300 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) 305 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId())
301 .rotation(); 306 .Rotation(gfx::Display::ROTATION_SOURCE_ACTIVE);
302 if (natural_orientation_ == lock_orientation) { 307 if (natural_orientation_ == lock_orientation) {
303 if (rotation == gfx::Display::ROTATE_0 || 308 if (rotation == gfx::Display::ROTATE_0 ||
304 rotation == gfx::Display::ROTATE_180) { 309 rotation == gfx::Display::ROTATE_180) {
305 SetRotationLocked(true); 310 SetRotationLocked(true);
306 } else { 311 } else {
307 LockRotation(gfx::Display::ROTATE_0); 312 LockRotation(gfx::Display::ROTATE_0,
313 gfx::Display::ROTATION_SOURCE_ACTIVE);
308 } 314 }
309 } else { 315 } else {
310 if (rotation == gfx::Display::ROTATE_90 || 316 if (rotation == gfx::Display::ROTATE_90 ||
311 rotation == gfx::Display::ROTATE_270) { 317 rotation == gfx::Display::ROTATE_270) {
312 SetRotationLocked(true); 318 SetRotationLocked(true);
313 } else { 319 } else {
314 LockRotation(gfx::Display::ROTATE_90); 320 LockRotation(gfx::Display::ROTATE_90,
321 gfx::Display::ROTATION_SOURCE_ACTIVE);
315 } 322 }
316 } 323 }
317 } 324 }
318 325
319 void ScreenOrientationController::HandleScreenRotation( 326 void ScreenOrientationController::HandleScreenRotation(
320 const chromeos::AccelerometerReading& lid) { 327 const chromeos::AccelerometerReading& lid) {
321 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f); 328 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f);
322 float lid_flattened_length = lid_flattened.Length(); 329 float lid_flattened_length = lid_flattened.Length();
323 // When the lid is close to being flat, don't change rotation as it is too 330 // When the lid is close to being flat, don't change rotation as it is too
324 // sensitive to slight movements. 331 // sensitive to slight movements.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; 363 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90;
357 if (angle < 90.0f) 364 if (angle < 90.0f)
358 new_rotation = gfx::Display::ROTATE_0; 365 new_rotation = gfx::Display::ROTATE_0;
359 else if (angle < 180.0f) 366 else if (angle < 180.0f)
360 new_rotation = gfx::Display::ROTATE_270; 367 new_rotation = gfx::Display::ROTATE_270;
361 else if (angle < 270.0f) 368 else if (angle < 270.0f)
362 new_rotation = gfx::Display::ROTATE_180; 369 new_rotation = gfx::Display::ROTATE_180;
363 370
364 if (new_rotation != current_rotation_ && 371 if (new_rotation != current_rotation_ &&
365 IsRotationAllowedInLockedState(new_rotation)) 372 IsRotationAllowedInLockedState(new_rotation))
366 SetDisplayRotation(new_rotation); 373 SetDisplayRotation(new_rotation,
374 gfx::Display::ROTATION_SOURCE_ACCELEROMETER);
367 } 375 }
368 376
369 void ScreenOrientationController::LoadDisplayRotationProperties() { 377 void ScreenOrientationController::LoadDisplayRotationProperties() {
370 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 378 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
371 if (!display_manager->registered_internal_display_rotation_lock()) 379 if (!display_manager->registered_internal_display_rotation_lock())
372 return; 380 return;
373 SetDisplayRotation(display_manager->registered_internal_display_rotation()); 381 SetDisplayRotation(display_manager->registered_internal_display_rotation(),
382 gfx::Display::ROTATION_SOURCE_ACCELEROMETER);
374 SetRotationLocked(true); 383 SetRotationLocked(true);
375 } 384 }
376 385
377 void ScreenOrientationController::ApplyLockForActiveWindow() { 386 void ScreenOrientationController::ApplyLockForActiveWindow() {
378 aura::Window* active_window = 387 aura::Window* active_window =
379 Shell::GetInstance()->activation_client()->GetActiveWindow(); 388 Shell::GetInstance()->activation_client()->GetActiveWindow();
380 for (auto const& windows : locking_windows_) { 389 for (auto const& windows : locking_windows_) {
381 if (windows.first->TargetVisibility() && 390 if (windows.first->TargetVisibility() &&
382 active_window->Contains(windows.first)) { 391 active_window->Contains(windows.first)) {
383 LockRotationToOrientation(windows.second); 392 LockRotationToOrientation(windows.second);
(...skipping 30 matching lines...) Expand all
414 } 423 }
415 424
416 bool ScreenOrientationController::CanRotateInLockedState() { 425 bool ScreenOrientationController::CanRotateInLockedState() {
417 return rotation_locked_orientation_ == 426 return rotation_locked_orientation_ ==
418 blink::WebScreenOrientationLockLandscape || 427 blink::WebScreenOrientationLockLandscape ||
419 rotation_locked_orientation_ == 428 rotation_locked_orientation_ ==
420 blink::WebScreenOrientationLockPortrait; 429 blink::WebScreenOrientationLockPortrait;
421 } 430 }
422 431
423 } // namespace ash 432 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698