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

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

Issue 2895713002: [mus+ash] Removes WmWindow from ash/wm/mru_window_tracker and overview mode (Closed)
Patch Set: Address nits, unit_tests target compiles Created 3 years, 7 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/display/screen_orientation_controller_chromeos.h" 5 #include "ash/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_configuration_controller.h" 8 #include "ash/display/display_configuration_controller.h"
9 #include "ash/shared/app_types.h" 9 #include "ash/shared/app_types.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_port.h" 11 #include "ash/shell_port.h"
12 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 12 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
13 #include "ash/wm/mru_window_tracker.h" 13 #include "ash/wm/mru_window_tracker.h"
14 #include "ash/wm/window_state.h" 14 #include "ash/wm/window_state.h"
15 #include "ash/wm_window.h"
16 #include "base/auto_reset.h" 15 #include "base/auto_reset.h"
17 #include "base/command_line.h" 16 #include "base/command_line.h"
18 #include "chromeos/accelerometer/accelerometer_reader.h" 17 #include "chromeos/accelerometer/accelerometer_reader.h"
19 #include "chromeos/accelerometer/accelerometer_types.h" 18 #include "chromeos/accelerometer/accelerometer_types.h"
19 #include "ui/aura/client/aura_constants.h"
20 #include "ui/chromeos/accelerometer/accelerometer_util.h" 20 #include "ui/chromeos/accelerometer/accelerometer_util.h"
21 #include "ui/display/display.h" 21 #include "ui/display/display.h"
22 #include "ui/display/manager/display_manager.h" 22 #include "ui/display/manager/display_manager.h"
23 #include "ui/display/manager/managed_display_info.h" 23 #include "ui/display/manager/managed_display_info.h"
24 #include "ui/gfx/geometry/size.h" 24 #include "ui/gfx/geometry/size.h"
25 #include "ui/wm/public/activation_client.h" 25 #include "ui/wm/public/activation_client.h"
26 26
27 namespace ash { 27 namespace ash {
28 28
29 namespace { 29 namespace {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 current_rotation_(display::Display::ROTATE_0) { 162 current_rotation_(display::Display::ROTATE_0) {
163 Shell::Get()->AddShellObserver(this); 163 Shell::Get()->AddShellObserver(this);
164 } 164 }
165 165
166 ScreenOrientationController::~ScreenOrientationController() { 166 ScreenOrientationController::~ScreenOrientationController() {
167 Shell::Get()->RemoveShellObserver(this); 167 Shell::Get()->RemoveShellObserver(this);
168 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); 168 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this);
169 ShellPort::Get()->RemoveDisplayObserver(this); 169 ShellPort::Get()->RemoveDisplayObserver(this);
170 Shell::Get()->activation_client()->RemoveObserver(this); 170 Shell::Get()->activation_client()->RemoveObserver(this);
171 for (auto& windows : lock_info_map_) 171 for (auto& windows : lock_info_map_)
172 windows.first->aura_window()->RemoveObserver(this); 172 windows.first->RemoveObserver(this);
173 } 173 }
174 174
175 void ScreenOrientationController::AddObserver(Observer* observer) { 175 void ScreenOrientationController::AddObserver(Observer* observer) {
176 observers_.AddObserver(observer); 176 observers_.AddObserver(observer);
177 } 177 }
178 178
179 void ScreenOrientationController::RemoveObserver(Observer* observer) { 179 void ScreenOrientationController::RemoveObserver(Observer* observer) {
180 observers_.RemoveObserver(observer); 180 observers_.RemoveObserver(observer);
181 } 181 }
182 182
183 void ScreenOrientationController::LockOrientationForWindow( 183 void ScreenOrientationController::LockOrientationForWindow(
184 WmWindow* requesting_window, 184 aura::Window* requesting_window,
185 blink::WebScreenOrientationLockType lock_orientation, 185 blink::WebScreenOrientationLockType lock_orientation,
186 LockCompletionBehavior lock_completion_behavior) { 186 LockCompletionBehavior lock_completion_behavior) {
187 if (lock_info_map_.empty()) 187 if (lock_info_map_.empty())
188 Shell::Get()->activation_client()->AddObserver(this); 188 Shell::Get()->activation_client()->AddObserver(this);
189 189
190 if (!requesting_window->aura_window()->HasObserver(this)) 190 if (!requesting_window->HasObserver(this))
191 requesting_window->aura_window()->AddObserver(this); 191 requesting_window->AddObserver(this);
192 lock_info_map_[requesting_window] = 192 lock_info_map_[requesting_window] =
193 LockInfo(lock_orientation, lock_completion_behavior); 193 LockInfo(lock_orientation, lock_completion_behavior);
194 194
195 ApplyLockForActiveWindow(); 195 ApplyLockForActiveWindow();
196 } 196 }
197 197
198 void ScreenOrientationController::UnlockOrientationForWindow(WmWindow* window) { 198 void ScreenOrientationController::UnlockOrientationForWindow(
199 aura::Window* window) {
199 lock_info_map_.erase(window); 200 lock_info_map_.erase(window);
200 if (lock_info_map_.empty()) 201 if (lock_info_map_.empty())
201 Shell::Get()->activation_client()->RemoveObserver(this); 202 Shell::Get()->activation_client()->RemoveObserver(this);
202 window->aura_window()->RemoveObserver(this); 203 window->RemoveObserver(this);
203 ApplyLockForActiveWindow(); 204 ApplyLockForActiveWindow();
204 } 205 }
205 206
206 void ScreenOrientationController::UnlockAll() { 207 void ScreenOrientationController::UnlockAll() {
207 for (auto pair : lock_info_map_) 208 for (auto pair : lock_info_map_)
208 pair.first->aura_window()->RemoveObserver(this); 209 pair.first->RemoveObserver(this);
209 lock_info_map_.clear(); 210 lock_info_map_.clear();
210 Shell::Get()->activation_client()->RemoveObserver(this); 211 Shell::Get()->activation_client()->RemoveObserver(this);
211 SetRotationLockedInternal(false); 212 SetRotationLockedInternal(false);
212 if (user_rotation_ != current_rotation_) 213 if (user_rotation_ != current_rotation_)
213 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER); 214 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER);
214 } 215 }
215 216
216 bool ScreenOrientationController::ScreenOrientationProviderSupported() const { 217 bool ScreenOrientationController::ScreenOrientationProviderSupported() const {
217 return Shell::Get() 218 return Shell::Get()
218 ->maximize_mode_controller() 219 ->maximize_mode_controller()
(...skipping 23 matching lines...) Expand all
242 SetLockToOrientation(RotationToOrientation(rotation)); 243 SetLockToOrientation(RotationToOrientation(rotation));
243 } 244 }
244 245
245 void ScreenOrientationController::OnWindowActivated(ActivationReason reason, 246 void ScreenOrientationController::OnWindowActivated(ActivationReason reason,
246 aura::Window* gained_active, 247 aura::Window* gained_active,
247 aura::Window* lost_active) { 248 aura::Window* lost_active) {
248 ApplyLockForActiveWindow(); 249 ApplyLockForActiveWindow();
249 } 250 }
250 251
251 void ScreenOrientationController::OnWindowDestroying(aura::Window* window) { 252 void ScreenOrientationController::OnWindowDestroying(aura::Window* window) {
252 UnlockOrientationForWindow(WmWindow::Get(window)); 253 UnlockOrientationForWindow(window);
253 } 254 }
254 255
255 // Currently contents::WebContents will only be able to lock rotation while 256 // Currently contents::WebContents will only be able to lock rotation while
256 // fullscreen. In this state a user cannot click on the tab strip to change. If 257 // fullscreen. In this state a user cannot click on the tab strip to change. If
257 // this becomes supported for non-fullscreen tabs then the following interferes 258 // this becomes supported for non-fullscreen tabs then the following interferes
258 // with TabDragController. OnWindowVisibilityChanged is called between a mouse 259 // with TabDragController. OnWindowVisibilityChanged is called between a mouse
259 // down and mouse up. The rotation this triggers leads to a coordinate space 260 // down and mouse up. The rotation this triggers leads to a coordinate space
260 // change in the middle of an event. Causes the tab to separate from the tab 261 // change in the middle of an event. Causes the tab to separate from the tab
261 // strip. 262 // strip.
262 void ScreenOrientationController::OnWindowVisibilityChanged( 263 void ScreenOrientationController::OnWindowVisibilityChanged(
263 aura::Window* window, 264 aura::Window* window,
264 bool visible) { 265 bool visible) {
265 if (lock_info_map_.find(WmWindow::Get(window)) == lock_info_map_.end()) 266 if (lock_info_map_.find(window) == lock_info_map_.end())
266 return; 267 return;
267 ApplyLockForActiveWindow(); 268 ApplyLockForActiveWindow();
268 } 269 }
269 270
270 void ScreenOrientationController::OnAccelerometerUpdated( 271 void ScreenOrientationController::OnAccelerometerUpdated(
271 scoped_refptr<const chromeos::AccelerometerUpdate> update) { 272 scoped_refptr<const chromeos::AccelerometerUpdate> update) {
272 if (rotation_locked_ && !CanRotateInLockedState()) 273 if (rotation_locked_ && !CanRotateInLockedState())
273 return; 274 return;
274 if (!update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN)) 275 if (!update->has(chromeos::ACCELEROMETER_SOURCE_SCREEN))
275 return; 276 return;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 if (!display_manager->registered_internal_display_rotation_lock()) 519 if (!display_manager->registered_internal_display_rotation_lock())
519 return; 520 return;
520 user_locked_orientation_ = RotationToOrientation( 521 user_locked_orientation_ = RotationToOrientation(
521 display_manager->registered_internal_display_rotation()); 522 display_manager->registered_internal_display_rotation());
522 } 523 }
523 524
524 void ScreenOrientationController::ApplyLockForActiveWindow() { 525 void ScreenOrientationController::ApplyLockForActiveWindow() {
525 MruWindowTracker::WindowList mru_windows( 526 MruWindowTracker::WindowList mru_windows(
526 Shell::Get()->mru_window_tracker()->BuildMruWindowList()); 527 Shell::Get()->mru_window_tracker()->BuildMruWindowList());
527 528
528 for (WmWindow* window : mru_windows) { 529 for (auto* window : mru_windows) {
529 if (!window->GetTargetVisibility()) 530 if (!window->TargetVisibility())
530 continue; 531 continue;
531 for (auto& pair : lock_info_map_) { 532 for (auto& pair : lock_info_map_) {
532 if (pair.first->GetTargetVisibility() && window->Contains(pair.first)) { 533 if (pair.first->TargetVisibility() && window->Contains(pair.first)) {
533 LockRotationToOrientation(ResolveOrientationLock( 534 LockRotationToOrientation(ResolveOrientationLock(
534 pair.second.orientation, user_locked_orientation_)); 535 pair.second.orientation, user_locked_orientation_));
535 if (pair.second.lock_completion_behavior == 536 if (pair.second.lock_completion_behavior ==
536 LockCompletionBehavior::DisableSensor) { 537 LockCompletionBehavior::DisableSensor) {
537 pair.second.orientation = RotationToOrientation(current_rotation_); 538 pair.second.orientation = RotationToOrientation(current_rotation_);
538 pair.second.lock_completion_behavior = LockCompletionBehavior::None; 539 pair.second.lock_completion_behavior = LockCompletionBehavior::None;
539 LockRotationToOrientation(pair.second.orientation); 540 LockRotationToOrientation(pair.second.orientation);
540 } 541 }
541 return; 542 return;
542 } 543 }
543 } 544 }
544 // The default orientation for all chrome browser/apps windows is 545 // The default orientation for all chrome browser/apps windows is
545 // ANY, so use the user_locked_orientation_; 546 // ANY, so use the user_locked_orientation_;
546 if (window->GetTargetVisibility() && 547 if (window->TargetVisibility() &&
547 static_cast<AppType>(window->GetAppType()) != AppType::OTHERS) { 548 static_cast<AppType>(window->GetProperty(aura::client::kAppType)) !=
549 AppType::OTHERS) {
548 LockRotationToOrientation(user_locked_orientation_); 550 LockRotationToOrientation(user_locked_orientation_);
549 return; 551 return;
550 } 552 }
551 } 553 }
552 LockRotationToOrientation(user_locked_orientation_); 554 LockRotationToOrientation(user_locked_orientation_);
553 } 555 }
554 556
555 bool ScreenOrientationController::IsRotationAllowedInLockedState( 557 bool ScreenOrientationController::IsRotationAllowedInLockedState(
556 display::Display::Rotation rotation) { 558 display::Display::Rotation rotation) {
557 if (!rotation_locked_) 559 if (!rotation_locked_)
(...skipping 18 matching lines...) Expand all
576 } 578 }
577 579
578 bool ScreenOrientationController::CanRotateInLockedState() { 580 bool ScreenOrientationController::CanRotateInLockedState() {
579 return rotation_locked_orientation_ == 581 return rotation_locked_orientation_ ==
580 blink::kWebScreenOrientationLockLandscape || 582 blink::kWebScreenOrientationLockLandscape ||
581 rotation_locked_orientation_ == 583 rotation_locked_orientation_ ==
582 blink::kWebScreenOrientationLockPortrait; 584 blink::kWebScreenOrientationLockPortrait;
583 } 585 }
584 586
585 } // namespace ash 587 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698