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/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 Loading... |
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.GetActiveRotation()) { | 48 switch (info.rotation()) { |
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 Loading... |
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) { | |
117 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 116 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
118 if (!display_manager->HasInternalDisplay()) | 117 if (!display_manager->HasInternalDisplay()) |
119 return; | 118 return; |
120 current_rotation_ = rotation; | 119 current_rotation_ = rotation; |
121 base::AutoReset<bool> auto_ignore_display_configuration_updates( | 120 base::AutoReset<bool> auto_ignore_display_configuration_updates( |
122 &ignore_display_configuration_updates_, true); | 121 &ignore_display_configuration_updates_, true); |
123 ash::ScreenRotationAnimator(gfx::Display::InternalDisplayId()) | 122 ash::ScreenRotationAnimator(gfx::Display::InternalDisplayId()) |
124 .Rotate(rotation, source); | 123 .Rotate(rotation); |
125 } | 124 } |
126 | 125 |
127 void ScreenOrientationController::OnWindowActivated(aura::Window* gained_active, | 126 void ScreenOrientationController::OnWindowActivated(aura::Window* gained_active, |
128 aura::Window* lost_active) { | 127 aura::Window* lost_active) { |
129 ApplyLockForActiveWindow(); | 128 ApplyLockForActiveWindow(); |
130 } | 129 } |
131 | 130 |
132 // Currently contents::WebContents will only be able to lock rotation while | 131 // Currently contents::WebContents will only be able to lock rotation while |
133 // fullscreen. In this state a user cannot click on the tab strip to change. If | 132 // fullscreen. In this state a user cannot click on the tab strip to change. If |
134 // this becomes supported for non-fullscreen tabs then the following interferes | 133 // this becomes supported for non-fullscreen tabs then the following interferes |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 } | 194 } |
196 | 195 |
197 void ScreenOrientationController::OnDisplayConfigurationChanged() { | 196 void ScreenOrientationController::OnDisplayConfigurationChanged() { |
198 if (ignore_display_configuration_updates_) | 197 if (ignore_display_configuration_updates_) |
199 return; | 198 return; |
200 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 199 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
201 if (!display_manager->HasInternalDisplay()) | 200 if (!display_manager->HasInternalDisplay()) |
202 return; | 201 return; |
203 gfx::Display::Rotation user_rotation = | 202 gfx::Display::Rotation user_rotation = |
204 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) | 203 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
205 .GetActiveRotation(); | 204 .rotation(); |
206 if (user_rotation != current_rotation_) { | 205 if (user_rotation != current_rotation_) { |
207 // A user may change other display configuration settings. When the user | 206 // A user may change other display configuration settings. When the user |
208 // does change the rotation setting, then lock rotation to prevent the | 207 // does change the rotation setting, then lock rotation to prevent the |
209 // accelerometer from erasing their change. | 208 // accelerometer from erasing their change. |
210 SetRotationLocked(true); | 209 SetRotationLocked(true); |
211 user_rotation_ = current_rotation_ = user_rotation; | 210 user_rotation_ = current_rotation_ = user_rotation; |
212 } | 211 } |
213 } | 212 } |
214 | 213 |
215 void ScreenOrientationController::OnMaximizeModeStarted() { | 214 void ScreenOrientationController::OnMaximizeModeStarted() { |
216 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 215 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
217 // Do not exit early, as the internal display can be determined after Maximize | 216 // Do not exit early, as the internal display can be determined after Maximize |
218 // Mode has started. (chrome-os-partner:38796) | 217 // Mode has started. (chrome-os-partner:38796) |
219 // Always start observing. | 218 // Always start observing. |
220 if (display_manager->HasInternalDisplay()) { | 219 if (display_manager->HasInternalDisplay()) { |
221 current_rotation_ = user_rotation_ = | 220 current_rotation_ = user_rotation_ = |
222 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) | 221 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
223 .GetActiveRotation(); | 222 .rotation(); |
224 } | 223 } |
225 if (!rotation_locked_) | 224 if (!rotation_locked_) |
226 LoadDisplayRotationProperties(); | 225 LoadDisplayRotationProperties(); |
227 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); | 226 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); |
228 Shell::GetInstance()->display_controller()->AddObserver(this); | 227 Shell::GetInstance()->display_controller()->AddObserver(this); |
229 } | 228 } |
230 | 229 |
231 void ScreenOrientationController::OnMaximizeModeEnded() { | 230 void ScreenOrientationController::OnMaximizeModeEnded() { |
232 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 231 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
233 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 232 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
234 if (current_rotation_ != user_rotation_) | 233 if (current_rotation_ != user_rotation_) |
235 SetDisplayRotation(user_rotation_, gfx::Display::ROTATION_SOURCE_USER); | 234 SetDisplayRotation(user_rotation_); |
236 } | 235 } |
237 | 236 |
238 void ScreenOrientationController::LockRotation( | 237 void ScreenOrientationController::LockRotation( |
239 gfx::Display::Rotation rotation, | 238 gfx::Display::Rotation rotation) { |
240 gfx::Display::RotationSource source) { | |
241 SetRotationLocked(true); | 239 SetRotationLocked(true); |
242 SetDisplayRotation(rotation, source); | 240 SetDisplayRotation(rotation); |
243 } | 241 } |
244 | 242 |
245 void ScreenOrientationController::LockRotationToOrientation( | 243 void ScreenOrientationController::LockRotationToOrientation( |
246 blink::WebScreenOrientationLockType lock_orientation) { | 244 blink::WebScreenOrientationLockType lock_orientation) { |
247 rotation_locked_orientation_ = lock_orientation; | 245 rotation_locked_orientation_ = lock_orientation; |
248 switch (lock_orientation) { | 246 switch (lock_orientation) { |
249 case blink::WebScreenOrientationLockAny: | 247 case blink::WebScreenOrientationLockAny: |
250 SetRotationLocked(false); | 248 SetRotationLocked(false); |
251 break; | 249 break; |
252 case blink::WebScreenOrientationLockDefault: | 250 case blink::WebScreenOrientationLockDefault: |
(...skipping 12 matching lines...) Expand all Loading... |
265 break; | 263 break; |
266 case blink::WebScreenOrientationLockLandscapeSecondary: | 264 case blink::WebScreenOrientationLockLandscapeSecondary: |
267 LockRotationToSecondaryOrientation( | 265 LockRotationToSecondaryOrientation( |
268 blink::WebScreenOrientationLockLandscape); | 266 blink::WebScreenOrientationLockLandscape); |
269 break; | 267 break; |
270 case blink::WebScreenOrientationLockLandscapePrimary: | 268 case blink::WebScreenOrientationLockLandscapePrimary: |
271 LockRotationToPrimaryOrientation( | 269 LockRotationToPrimaryOrientation( |
272 blink::WebScreenOrientationLockLandscape); | 270 blink::WebScreenOrientationLockLandscape); |
273 break; | 271 break; |
274 case blink::WebScreenOrientationLockNatural: | 272 case blink::WebScreenOrientationLockNatural: |
275 LockRotation(gfx::Display::ROTATE_0, | 273 LockRotation(gfx::Display::ROTATE_0); |
276 gfx::Display::ROTATION_SOURCE_ACTIVE); | |
277 break; | 274 break; |
278 default: | 275 default: |
279 NOTREACHED(); | 276 NOTREACHED(); |
280 break; | 277 break; |
281 } | 278 } |
282 } | 279 } |
283 | 280 |
284 void ScreenOrientationController::LockRotationToPrimaryOrientation( | 281 void ScreenOrientationController::LockRotationToPrimaryOrientation( |
285 blink::WebScreenOrientationLockType lock_orientation) { | 282 blink::WebScreenOrientationLockType lock_orientation) { |
286 LockRotation(natural_orientation_ == lock_orientation | 283 LockRotation(natural_orientation_ == lock_orientation |
287 ? gfx::Display::ROTATE_0 | 284 ? gfx::Display::ROTATE_0 |
288 : gfx::Display::ROTATE_90, | 285 : gfx::Display::ROTATE_90); |
289 gfx::Display::ROTATION_SOURCE_ACTIVE); | |
290 } | 286 } |
291 | 287 |
292 void ScreenOrientationController::LockRotationToSecondaryOrientation( | 288 void ScreenOrientationController::LockRotationToSecondaryOrientation( |
293 blink::WebScreenOrientationLockType lock_orientation) { | 289 blink::WebScreenOrientationLockType lock_orientation) { |
294 LockRotation(natural_orientation_ == lock_orientation | 290 LockRotation(natural_orientation_ == lock_orientation |
295 ? gfx::Display::ROTATE_180 | 291 ? gfx::Display::ROTATE_180 |
296 : gfx::Display::ROTATE_270, | 292 : gfx::Display::ROTATE_270); |
297 gfx::Display::ROTATION_SOURCE_ACTIVE); | |
298 } | 293 } |
299 | 294 |
300 void ScreenOrientationController::LockToRotationMatchingOrientation( | 295 void ScreenOrientationController::LockToRotationMatchingOrientation( |
301 blink::WebScreenOrientationLockType lock_orientation) { | 296 blink::WebScreenOrientationLockType lock_orientation) { |
302 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 297 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
303 if (!display_manager->HasInternalDisplay()) | 298 if (!display_manager->HasInternalDisplay()) |
304 return; | 299 return; |
305 | 300 |
306 gfx::Display::Rotation rotation = | 301 gfx::Display::Rotation rotation = |
307 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) | 302 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
308 .GetActiveRotation(); | 303 .rotation(); |
309 if (natural_orientation_ == lock_orientation) { | 304 if (natural_orientation_ == lock_orientation) { |
310 if (rotation == gfx::Display::ROTATE_0 || | 305 if (rotation == gfx::Display::ROTATE_0 || |
311 rotation == gfx::Display::ROTATE_180) { | 306 rotation == gfx::Display::ROTATE_180) { |
312 SetRotationLocked(true); | 307 SetRotationLocked(true); |
313 } else { | 308 } else { |
314 LockRotation(gfx::Display::ROTATE_0, | 309 LockRotation(gfx::Display::ROTATE_0); |
315 gfx::Display::ROTATION_SOURCE_ACTIVE); | |
316 } | 310 } |
317 } else { | 311 } else { |
318 if (rotation == gfx::Display::ROTATE_90 || | 312 if (rotation == gfx::Display::ROTATE_90 || |
319 rotation == gfx::Display::ROTATE_270) { | 313 rotation == gfx::Display::ROTATE_270) { |
320 SetRotationLocked(true); | 314 SetRotationLocked(true); |
321 } else { | 315 } else { |
322 LockRotation(gfx::Display::ROTATE_90, | 316 LockRotation(gfx::Display::ROTATE_90); |
323 gfx::Display::ROTATION_SOURCE_ACTIVE); | |
324 } | 317 } |
325 } | 318 } |
326 } | 319 } |
327 | 320 |
328 void ScreenOrientationController::HandleScreenRotation( | 321 void ScreenOrientationController::HandleScreenRotation( |
329 const chromeos::AccelerometerReading& lid) { | 322 const chromeos::AccelerometerReading& lid) { |
330 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f); | 323 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f); |
331 float lid_flattened_length = lid_flattened.Length(); | 324 float lid_flattened_length = lid_flattened.Length(); |
332 // When the lid is close to being flat, don't change rotation as it is too | 325 // When the lid is close to being flat, don't change rotation as it is too |
333 // sensitive to slight movements. | 326 // sensitive to slight movements. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; | 358 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_90; |
366 if (angle < 90.0f) | 359 if (angle < 90.0f) |
367 new_rotation = gfx::Display::ROTATE_0; | 360 new_rotation = gfx::Display::ROTATE_0; |
368 else if (angle < 180.0f) | 361 else if (angle < 180.0f) |
369 new_rotation = gfx::Display::ROTATE_270; | 362 new_rotation = gfx::Display::ROTATE_270; |
370 else if (angle < 270.0f) | 363 else if (angle < 270.0f) |
371 new_rotation = gfx::Display::ROTATE_180; | 364 new_rotation = gfx::Display::ROTATE_180; |
372 | 365 |
373 if (new_rotation != current_rotation_ && | 366 if (new_rotation != current_rotation_ && |
374 IsRotationAllowedInLockedState(new_rotation)) | 367 IsRotationAllowedInLockedState(new_rotation)) |
375 SetDisplayRotation(new_rotation, | 368 SetDisplayRotation(new_rotation); |
376 gfx::Display::ROTATION_SOURCE_ACCELEROMETER); | |
377 } | 369 } |
378 | 370 |
379 void ScreenOrientationController::LoadDisplayRotationProperties() { | 371 void ScreenOrientationController::LoadDisplayRotationProperties() { |
380 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 372 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
381 if (!display_manager->registered_internal_display_rotation_lock()) | 373 if (!display_manager->registered_internal_display_rotation_lock()) |
382 return; | 374 return; |
383 SetDisplayRotation(display_manager->registered_internal_display_rotation(), | 375 SetDisplayRotation(display_manager->registered_internal_display_rotation()); |
384 gfx::Display::ROTATION_SOURCE_ACCELEROMETER); | |
385 SetRotationLocked(true); | 376 SetRotationLocked(true); |
386 } | 377 } |
387 | 378 |
388 void ScreenOrientationController::ApplyLockForActiveWindow() { | 379 void ScreenOrientationController::ApplyLockForActiveWindow() { |
389 aura::Window* active_window = | 380 aura::Window* active_window = |
390 Shell::GetInstance()->activation_client()->GetActiveWindow(); | 381 Shell::GetInstance()->activation_client()->GetActiveWindow(); |
391 for (auto const& windows : locking_windows_) { | 382 for (auto const& windows : locking_windows_) { |
392 if (windows.first->TargetVisibility() && | 383 if (windows.first->TargetVisibility() && |
393 active_window->Contains(windows.first)) { | 384 active_window->Contains(windows.first)) { |
394 LockRotationToOrientation(windows.second); | 385 LockRotationToOrientation(windows.second); |
(...skipping 30 matching lines...) Expand all Loading... |
425 } | 416 } |
426 | 417 |
427 bool ScreenOrientationController::CanRotateInLockedState() { | 418 bool ScreenOrientationController::CanRotateInLockedState() { |
428 return rotation_locked_orientation_ == | 419 return rotation_locked_orientation_ == |
429 blink::WebScreenOrientationLockLandscape || | 420 blink::WebScreenOrientationLockLandscape || |
430 rotation_locked_orientation_ == | 421 rotation_locked_orientation_ == |
431 blink::WebScreenOrientationLockPortrait; | 422 blink::WebScreenOrientationLockPortrait; |
432 } | 423 } |
433 | 424 |
434 } // namespace ash | 425 } // namespace ash |
OLD | NEW |