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/display/screen_orientation_controller_chromeos.h" | 5 #include "ash/display/screen_orientation_controller_chromeos.h" |
6 | 6 |
7 #include "ash/common/ash_switches.h" | 7 #include "ash/common/ash_switches.h" |
8 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 8 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
9 #include "ash/common/wm/mru_window_tracker.h" | |
10 #include "ash/common/wm/window_state.h" | |
9 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
10 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
11 #include "ash/display/display_configuration_controller.h" | 13 #include "ash/display/display_configuration_controller.h" |
14 #include "ash/shared/app_types.h" | |
12 #include "ash/shell.h" | 15 #include "ash/shell.h" |
13 #include "base/auto_reset.h" | 16 #include "base/auto_reset.h" |
14 #include "base/command_line.h" | 17 #include "base/command_line.h" |
15 #include "chromeos/accelerometer/accelerometer_reader.h" | 18 #include "chromeos/accelerometer/accelerometer_reader.h" |
16 #include "chromeos/accelerometer/accelerometer_types.h" | 19 #include "chromeos/accelerometer/accelerometer_types.h" |
17 #include "ui/chromeos/accelerometer/accelerometer_util.h" | 20 #include "ui/chromeos/accelerometer/accelerometer_util.h" |
18 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
19 #include "ui/display/manager/display_manager.h" | 22 #include "ui/display/manager/display_manager.h" |
20 #include "ui/display/manager/managed_display_info.h" | 23 #include "ui/display/manager/managed_display_info.h" |
21 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 Shell::GetInstance()->activation_client()->RemoveObserver(this); | 110 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
108 window->aura_window()->RemoveObserver(this); | 111 window->aura_window()->RemoveObserver(this); |
109 ApplyLockForActiveWindow(); | 112 ApplyLockForActiveWindow(); |
110 } | 113 } |
111 | 114 |
112 void ScreenOrientationController::UnlockAll() { | 115 void ScreenOrientationController::UnlockAll() { |
113 for (auto pair : locking_windows_) | 116 for (auto pair : locking_windows_) |
114 pair.first->aura_window()->RemoveObserver(this); | 117 pair.first->aura_window()->RemoveObserver(this); |
115 locking_windows_.clear(); | 118 locking_windows_.clear(); |
116 Shell::GetInstance()->activation_client()->RemoveObserver(this); | 119 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
117 SetRotationLocked(false); | 120 SetRotationLockedInternal(false); |
118 if (user_rotation_ != current_rotation_) | 121 if (user_rotation_ != current_rotation_) |
119 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); | 122 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); |
120 } | 123 } |
121 | 124 |
122 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { | 125 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { |
123 return WmShell::Get() | 126 return WmShell::Get() |
124 ->maximize_mode_controller() | 127 ->maximize_mode_controller() |
125 ->IsMaximizeModeWindowManagerEnabled() && | 128 ->IsMaximizeModeWindowManagerEnabled() && |
126 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 129 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
127 switches::kAshDisableScreenOrientationLock); | 130 switches::kAshDisableScreenOrientationLock); |
128 } | 131 } |
129 | 132 |
130 void ScreenOrientationController::SetRotationLocked(bool rotation_locked) { | 133 void ScreenOrientationController::ToggleUserRotationLock() { |
131 if (rotation_locked_ == rotation_locked) | 134 if (user_rotation_locked()) { |
132 return; | 135 user_locked_orientation_ = blink::WebScreenOrientationLockAny; |
133 rotation_locked_ = rotation_locked; | 136 } else { |
134 if (!rotation_locked_) | 137 display::Display::Rotation current_rotation = |
135 rotation_locked_orientation_ = blink::WebScreenOrientationLockAny; | 138 WmShell::Get() |
139 ->GetDisplayInfo(display::Display::InternalDisplayId()) | |
140 .GetActiveRotation(); | |
141 blink::WebScreenOrientationLockType natural = | |
142 GetDisplayNaturalOrientation(); | |
143 if (natural == blink::WebScreenOrientationLockLandscape) { | |
144 switch (current_rotation) { | |
145 case display::Display::ROTATE_0: | |
146 user_locked_orientation_ = | |
147 blink::WebScreenOrientationLockLandscapePrimary; | |
148 break; | |
149 case display::Display::ROTATE_90: | |
150 user_locked_orientation_ = | |
151 blink::WebScreenOrientationLockPortraitPrimary; | |
152 break; | |
153 case display::Display::ROTATE_180: | |
154 user_locked_orientation_ = | |
155 blink::WebScreenOrientationLockLandscapeSecondary; | |
156 break; | |
157 case display::Display::ROTATE_270: | |
158 user_locked_orientation_ = | |
159 blink::WebScreenOrientationLockPortraitSecondary; | |
160 break; | |
161 } | |
162 } else { // Natural portrait | |
163 switch (current_rotation) { | |
164 case display::Display::ROTATE_0: | |
165 user_locked_orientation_ = | |
166 blink::WebScreenOrientationLockPortraitPrimary; | |
167 break; | |
168 case display::Display::ROTATE_90: | |
169 user_locked_orientation_ = | |
170 blink::WebScreenOrientationLockLandscapePrimary; | |
171 break; | |
172 case display::Display::ROTATE_180: | |
173 user_locked_orientation_ = | |
174 blink::WebScreenOrientationLockPortraitSecondary; | |
175 break; | |
176 case display::Display::ROTATE_270: | |
177 user_locked_orientation_ = | |
178 blink::WebScreenOrientationLockLandscapeSecondary; | |
179 break; | |
180 } | |
181 } | |
182 } | |
183 ApplyLockForActiveWindow(); | |
184 | |
136 for (auto& observer : observers_) | 185 for (auto& observer : observers_) |
137 observer.OnRotationLockChanged(rotation_locked_); | 186 observer.OnUserRotationLockChanged(); |
138 if (!display::Display::HasInternalDisplay()) | |
139 return; | |
140 base::AutoReset<bool> auto_ignore_display_configuration_updates( | |
141 &ignore_display_configuration_updates_, true); | |
142 Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties( | |
jonross
2017/03/21 14:56:43
Were you planning to land this in a follow up chan
oshima
2017/03/21 15:10:57
Yes. I mentioned it in the CL description.
(note t
jonross
2017/03/22 23:51:55
SGTM
| |
143 rotation_locked_, current_rotation_); | |
144 } | |
145 | |
146 void ScreenOrientationController::SetDisplayRotation( | |
147 display::Display::Rotation rotation, | |
148 display::Display::RotationSource source) { | |
149 if (!display::Display::HasInternalDisplay()) | |
150 return; | |
151 current_rotation_ = rotation; | |
152 base::AutoReset<bool> auto_ignore_display_configuration_updates( | |
153 &ignore_display_configuration_updates_, true); | |
154 | |
155 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( | |
156 display::Display::InternalDisplayId(), rotation, source); | |
157 } | 187 } |
158 | 188 |
159 void ScreenOrientationController::OnWindowActivated(ActivationReason reason, | 189 void ScreenOrientationController::OnWindowActivated(ActivationReason reason, |
160 aura::Window* gained_active, | 190 aura::Window* gained_active, |
161 aura::Window* lost_active) { | 191 aura::Window* lost_active) { |
162 ApplyLockForActiveWindow(); | 192 ApplyLockForActiveWindow(); |
163 } | 193 } |
164 | 194 |
165 void ScreenOrientationController::OnWindowDestroying(aura::Window* window) { | 195 void ScreenOrientationController::OnWindowDestroying(aura::Window* window) { |
166 UnlockOrientationForWindow(WmWindow::Get(window)); | 196 UnlockOrientationForWindow(WmWindow::Get(window)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 void ScreenOrientationController::OnDisplayConfigurationChanged() { | 228 void ScreenOrientationController::OnDisplayConfigurationChanged() { |
199 if (ignore_display_configuration_updates_) | 229 if (ignore_display_configuration_updates_) |
200 return; | 230 return; |
201 if (!display::Display::HasInternalDisplay()) | 231 if (!display::Display::HasInternalDisplay()) |
202 return; | 232 return; |
203 display::Display::Rotation user_rotation = | 233 display::Display::Rotation user_rotation = |
204 WmShell::Get() | 234 WmShell::Get() |
205 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 235 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
206 .GetActiveRotation(); | 236 .GetActiveRotation(); |
207 if (user_rotation != current_rotation_) { | 237 if (user_rotation != current_rotation_) { |
238 // TODO(oshima): We should disable the orientation change in settings | |
239 // because application may not work correctly. | |
240 | |
208 // A user may change other display configuration settings. When the user | 241 // A user may change other display configuration settings. When the user |
209 // does change the rotation setting, then lock rotation to prevent the | 242 // does change the rotation setting, then lock rotation to prevent the |
210 // accelerometer from erasing their change. | 243 // accelerometer from erasing their change. |
211 SetRotationLocked(true); | 244 SetRotationLockedInternal(true); |
jonross
2017/03/21 14:56:43
So currently we have been treating the settings ap
oshima
2017/03/21 15:10:57
I'll make two changes:
- Disable the rotation chan
jonross
2017/03/22 23:51:55
SGTM
| |
212 user_rotation_ = current_rotation_ = user_rotation; | 245 user_rotation_ = current_rotation_ = user_rotation; |
213 } | 246 } |
214 } | 247 } |
215 | 248 |
216 void ScreenOrientationController::OnMaximizeModeStarted() { | 249 void ScreenOrientationController::OnMaximizeModeStarted() { |
217 // Do not exit early, as the internal display can be determined after Maximize | 250 // Do not exit early, as the internal display can be determined after Maximize |
218 // Mode has started. (chrome-os-partner:38796) | 251 // Mode has started. (chrome-os-partner:38796) |
219 // Always start observing. | 252 // Always start observing. |
220 if (display::Display::HasInternalDisplay()) { | 253 if (display::Display::HasInternalDisplay()) { |
221 current_rotation_ = user_rotation_ = | 254 current_rotation_ = user_rotation_ = |
222 WmShell::Get() | 255 WmShell::Get() |
223 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 256 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
224 .GetActiveRotation(); | 257 .GetActiveRotation(); |
225 } | 258 } |
226 if (!rotation_locked_) | 259 if (!rotation_locked_) |
227 LoadDisplayRotationProperties(); | 260 LoadDisplayRotationProperties(); |
228 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); | 261 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); |
229 WmShell::Get()->AddDisplayObserver(this); | 262 WmShell::Get()->AddDisplayObserver(this); |
230 } | 263 } |
231 | 264 |
232 void ScreenOrientationController::OnMaximizeModeEnded() { | 265 void ScreenOrientationController::OnMaximizeModeEnded() { |
233 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); | 266 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); |
234 WmShell::Get()->RemoveDisplayObserver(this); | 267 WmShell::Get()->RemoveDisplayObserver(this); |
235 if (current_rotation_ != user_rotation_) | 268 if (current_rotation_ != user_rotation_) |
236 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); | 269 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); |
237 } | 270 } |
238 | 271 |
272 void ScreenOrientationController::SetDisplayRotation( | |
273 display::Display::Rotation rotation, | |
274 display::Display::RotationSource source) { | |
275 if (!display::Display::HasInternalDisplay()) | |
276 return; | |
277 current_rotation_ = rotation; | |
278 base::AutoReset<bool> auto_ignore_display_configuration_updates( | |
279 &ignore_display_configuration_updates_, true); | |
280 | |
281 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( | |
282 display::Display::InternalDisplayId(), rotation, source); | |
283 } | |
284 | |
285 void ScreenOrientationController::SetRotationLockedInternal( | |
286 bool rotation_locked) { | |
287 if (rotation_locked_ == rotation_locked) | |
288 return; | |
289 rotation_locked_ = rotation_locked; | |
290 if (!rotation_locked_) | |
291 rotation_locked_orientation_ = blink::WebScreenOrientationLockAny; | |
292 if (!display::Display::HasInternalDisplay()) | |
293 return; | |
294 base::AutoReset<bool> auto_ignore_display_configuration_updates( | |
295 &ignore_display_configuration_updates_, true); | |
296 Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties( | |
297 rotation_locked_, current_rotation_); | |
298 } | |
299 | |
239 void ScreenOrientationController::LockRotation( | 300 void ScreenOrientationController::LockRotation( |
240 display::Display::Rotation rotation, | 301 display::Display::Rotation rotation, |
241 display::Display::RotationSource source) { | 302 display::Display::RotationSource source) { |
242 SetRotationLocked(true); | 303 SetRotationLockedInternal(true); |
243 SetDisplayRotation(rotation, source); | 304 SetDisplayRotation(rotation, source); |
244 } | 305 } |
245 | 306 |
246 void ScreenOrientationController::LockRotationToOrientation( | 307 void ScreenOrientationController::LockRotationToOrientation( |
247 blink::WebScreenOrientationLockType lock_orientation) { | 308 blink::WebScreenOrientationLockType lock_orientation) { |
248 rotation_locked_orientation_ = lock_orientation; | 309 rotation_locked_orientation_ = lock_orientation; |
249 switch (lock_orientation) { | 310 switch (lock_orientation) { |
250 case blink::WebScreenOrientationLockAny: | 311 case blink::WebScreenOrientationLockAny: |
251 SetRotationLocked(false); | 312 SetRotationLockedInternal(false); |
252 break; | 313 break; |
253 case blink::WebScreenOrientationLockDefault: | 314 case blink::WebScreenOrientationLockDefault: |
254 NOTREACHED(); | 315 NOTREACHED(); |
255 break; | 316 break; |
256 case blink::WebScreenOrientationLockPortraitPrimary: | 317 case blink::WebScreenOrientationLockPortraitPrimary: |
257 LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait); | 318 LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait); |
258 break; | 319 break; |
259 case blink::WebScreenOrientationLockLandscape: | 320 case blink::WebScreenOrientationLockLandscape: |
260 case blink::WebScreenOrientationLockPortrait: | 321 case blink::WebScreenOrientationLockPortrait: |
261 LockToRotationMatchingOrientation(lock_orientation); | 322 LockToRotationMatchingOrientation(lock_orientation); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 if (!display::Display::HasInternalDisplay()) | 364 if (!display::Display::HasInternalDisplay()) |
304 return; | 365 return; |
305 | 366 |
306 display::Display::Rotation rotation = | 367 display::Display::Rotation rotation = |
307 WmShell::Get() | 368 WmShell::Get() |
308 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 369 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
309 .GetActiveRotation(); | 370 .GetActiveRotation(); |
310 if (natural_orientation_ == lock_orientation) { | 371 if (natural_orientation_ == lock_orientation) { |
311 if (rotation == display::Display::ROTATE_0 || | 372 if (rotation == display::Display::ROTATE_0 || |
312 rotation == display::Display::ROTATE_180) { | 373 rotation == display::Display::ROTATE_180) { |
313 SetRotationLocked(true); | 374 SetRotationLockedInternal(true); |
314 } else { | 375 } else { |
315 LockRotation(display::Display::ROTATE_0, | 376 LockRotation(display::Display::ROTATE_0, |
316 display::Display::ROTATION_SOURCE_ACTIVE); | 377 display::Display::ROTATION_SOURCE_ACTIVE); |
317 } | 378 } |
318 } else { | 379 } else { |
319 if (rotation == display::Display::ROTATE_90 || | 380 if (rotation == display::Display::ROTATE_90 || |
320 rotation == display::Display::ROTATE_270) { | 381 rotation == display::Display::ROTATE_270) { |
321 SetRotationLocked(true); | 382 SetRotationLockedInternal(true); |
322 } else { | 383 } else { |
323 LockRotation(display::Display::ROTATE_90, | 384 LockRotation(display::Display::ROTATE_90, |
324 display::Display::ROTATION_SOURCE_ACTIVE); | 385 display::Display::ROTATION_SOURCE_ACTIVE); |
325 } | 386 } |
326 } | 387 } |
327 } | 388 } |
328 | 389 |
329 void ScreenOrientationController::HandleScreenRotation( | 390 void ScreenOrientationController::HandleScreenRotation( |
330 const chromeos::AccelerometerReading& lid) { | 391 const chromeos::AccelerometerReading& lid) { |
331 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f); | 392 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 } | 439 } |
379 } | 440 } |
380 | 441 |
381 void ScreenOrientationController::LoadDisplayRotationProperties() { | 442 void ScreenOrientationController::LoadDisplayRotationProperties() { |
382 display::DisplayManager* display_manager = | 443 display::DisplayManager* display_manager = |
383 Shell::GetInstance()->display_manager(); | 444 Shell::GetInstance()->display_manager(); |
384 if (!display_manager->registered_internal_display_rotation_lock()) | 445 if (!display_manager->registered_internal_display_rotation_lock()) |
385 return; | 446 return; |
386 SetDisplayRotation(display_manager->registered_internal_display_rotation(), | 447 SetDisplayRotation(display_manager->registered_internal_display_rotation(), |
387 display::Display::ROTATION_SOURCE_ACCELEROMETER); | 448 display::Display::ROTATION_SOURCE_ACCELEROMETER); |
388 SetRotationLocked(true); | 449 SetRotationLockedInternal(true); |
389 } | 450 } |
390 | 451 |
391 void ScreenOrientationController::ApplyLockForActiveWindow() { | 452 void ScreenOrientationController::ApplyLockForActiveWindow() { |
392 WmWindow* active_window = WmShell::Get()->GetActiveWindow(); | 453 MruWindowTracker::WindowList mru_windows( |
393 if (active_window) { | 454 WmShell::Get()->mru_window_tracker()->BuildMruWindowList()); |
394 for (auto const& windows : locking_windows_) { | 455 |
395 if (windows.first->GetTargetVisibility() && | 456 for (WmWindow* window : mru_windows) { |
396 active_window->Contains(windows.first)) { | 457 if (!window->GetTargetVisibility()) |
397 LockRotationToOrientation(windows.second); | 458 continue; |
459 // TODO(oshima): If the application's orientation is landscape | |
460 // and user_locked_orientation_ is landscape primary or secondary, | |
461 // it should lock to the specific orientation. (and same for portrait). | |
462 for (auto const& pair : locking_windows_) { | |
jonross
2017/03/21 14:56:43
The ARC++ app windows are being registered with lo
oshima
2017/03/21 15:10:57
Yes, ARC++ apps always set the orientation.
jonross
2017/03/22 23:51:55
Good to know, I wasn't 100% which path the took. S
| |
463 if (pair.first->GetTargetVisibility() && window->Contains(pair.first)) { | |
464 LockRotationToOrientation(pair.second == | |
465 blink::WebScreenOrientationLockAny | |
466 ? user_locked_orientation_ | |
467 : pair.second); | |
398 return; | 468 return; |
399 } | 469 } |
400 } | 470 } |
471 // The default orientation for all chrome browser/apps windows is | |
472 // ANY, so use the user_locked_orientation_; | |
473 if (window->GetTargetVisibility() && | |
474 static_cast<AppType>(window->GetAppType()) != AppType::OTHERS) { | |
475 LockRotationToOrientation(user_locked_orientation_); | |
476 return; | |
477 } | |
401 } | 478 } |
402 SetRotationLocked(false); | 479 LockRotationToOrientation(user_locked_orientation_); |
403 } | 480 } |
404 | 481 |
405 bool ScreenOrientationController::IsRotationAllowedInLockedState( | 482 bool ScreenOrientationController::IsRotationAllowedInLockedState( |
406 display::Display::Rotation rotation) { | 483 display::Display::Rotation rotation) { |
407 if (!rotation_locked_) | 484 if (!rotation_locked_) |
408 return true; | 485 return true; |
409 | 486 |
410 if (!CanRotateInLockedState()) | 487 if (!CanRotateInLockedState()) |
411 return false; | 488 return false; |
412 | 489 |
413 if (natural_orientation_ == rotation_locked_orientation_) { | 490 if (natural_orientation_ == rotation_locked_orientation_) { |
414 return rotation == display::Display::ROTATE_0 || | 491 return rotation == display::Display::ROTATE_0 || |
415 rotation == display::Display::ROTATE_180; | 492 rotation == display::Display::ROTATE_180; |
416 } else { | 493 } else { |
417 return rotation == display::Display::ROTATE_90 || | 494 return rotation == display::Display::ROTATE_90 || |
418 rotation == display::Display::ROTATE_270; | 495 rotation == display::Display::ROTATE_270; |
419 } | 496 } |
420 return false; | 497 return false; |
421 } | 498 } |
422 | 499 |
423 bool ScreenOrientationController::CanRotateInLockedState() { | 500 bool ScreenOrientationController::CanRotateInLockedState() { |
424 return rotation_locked_orientation_ == | 501 return rotation_locked_orientation_ == |
425 blink::WebScreenOrientationLockLandscape || | 502 blink::WebScreenOrientationLockLandscape || |
426 rotation_locked_orientation_ == | 503 rotation_locked_orientation_ == |
427 blink::WebScreenOrientationLockPortrait; | 504 blink::WebScreenOrientationLockPortrait; |
428 } | 505 } |
429 | 506 |
430 } // namespace ash | 507 } // namespace ash |
OLD | NEW |