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

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

Issue 1924703002: Rename gfx::Display/Screen to display::Display/Screen in ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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/display/display_info.h" 9 #include "ash/display/display_info.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 12 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
13 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "chromeos/accelerometer/accelerometer_reader.h" 15 #include "chromeos/accelerometer/accelerometer_reader.h"
16 #include "chromeos/accelerometer/accelerometer_types.h" 16 #include "chromeos/accelerometer/accelerometer_types.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/aura/window_observer.h" 18 #include "ui/aura/window_observer.h"
19 #include "ui/chromeos/accelerometer/accelerometer_util.h" 19 #include "ui/chromeos/accelerometer/accelerometer_util.h"
20 #include "ui/gfx/display.h" 20 #include "ui/display/display.h"
21 #include "ui/gfx/geometry/size.h" 21 #include "ui/gfx/geometry/size.h"
22 #include "ui/wm/public/activation_client.h" 22 #include "ui/wm/public/activation_client.h"
23 23
24 namespace { 24 namespace {
25 25
26 // The angle which the screen has to be rotated past before the display will 26 // The angle which the screen has to be rotated past before the display will
27 // rotate to match it (i.e. 45.0f is no stickiness). 27 // rotate to match it (i.e. 45.0f is no stickiness).
28 const float kDisplayRotationStickyAngleDegrees = 60.0f; 28 const float kDisplayRotationStickyAngleDegrees = 60.0f;
29 29
30 // The minimum acceleration in m/s^2 in a direction required to trigger screen 30 // The minimum acceleration in m/s^2 in a direction required to trigger screen
31 // rotation. This prevents rapid toggling of rotation when the device is near 31 // rotation. This prevents rapid toggling of rotation when the device is near
32 // flat and there is very little screen aligned force on it. The value is 32 // flat and there is very little screen aligned force on it. The value is
33 // effectively the sine of the rise angle required times the acceleration due 33 // effectively the sine of the rise angle required times the acceleration due
34 // to gravity, with the current value requiring at least a 25 degree rise. 34 // to gravity, with the current value requiring at least a 25 degree rise.
35 const float kMinimumAccelerationScreenRotation = 4.2f; 35 const float kMinimumAccelerationScreenRotation = 4.2f;
36 36
37 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { 37 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() {
38 if (!gfx::Display::HasInternalDisplay()) 38 if (!display::Display::HasInternalDisplay())
39 return blink::WebScreenOrientationLockLandscape; 39 return blink::WebScreenOrientationLockLandscape;
40 40
41 ash::DisplayInfo info = 41 ash::DisplayInfo info =
42 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo( 42 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo(
43 gfx::Display::InternalDisplayId()); 43 display::Display::InternalDisplayId());
44 gfx::Size size = info.size_in_pixel(); 44 gfx::Size size = info.size_in_pixel();
45 switch (info.GetActiveRotation()) { 45 switch (info.GetActiveRotation()) {
46 case gfx::Display::ROTATE_0: 46 case display::Display::ROTATE_0:
47 case gfx::Display::ROTATE_180: 47 case display::Display::ROTATE_180:
48 return size.height() >= size.width() 48 return size.height() >= size.width()
49 ? blink::WebScreenOrientationLockPortrait 49 ? blink::WebScreenOrientationLockPortrait
50 : blink::WebScreenOrientationLockLandscape; 50 : blink::WebScreenOrientationLockLandscape;
51 case gfx::Display::ROTATE_90: 51 case display::Display::ROTATE_90:
52 case gfx::Display::ROTATE_270: 52 case display::Display::ROTATE_270:
53 return size.height() < size.width() 53 return size.height() < size.width()
54 ? blink::WebScreenOrientationLockPortrait 54 ? blink::WebScreenOrientationLockPortrait
55 : blink::WebScreenOrientationLockLandscape; 55 : blink::WebScreenOrientationLockLandscape;
56 } 56 }
57 NOTREACHED(); 57 NOTREACHED();
58 return blink::WebScreenOrientationLockLandscape; 58 return blink::WebScreenOrientationLockLandscape;
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 namespace ash { 63 namespace ash {
64 64
65 ScreenOrientationController::ScreenOrientationController() 65 ScreenOrientationController::ScreenOrientationController()
66 : natural_orientation_(GetDisplayNaturalOrientation()), 66 : natural_orientation_(GetDisplayNaturalOrientation()),
67 ignore_display_configuration_updates_(false), 67 ignore_display_configuration_updates_(false),
68 rotation_locked_(false), 68 rotation_locked_(false),
69 rotation_locked_orientation_(blink::WebScreenOrientationLockAny), 69 rotation_locked_orientation_(blink::WebScreenOrientationLockAny),
70 user_rotation_(gfx::Display::ROTATE_0), 70 user_rotation_(display::Display::ROTATE_0),
71 current_rotation_(gfx::Display::ROTATE_0) { 71 current_rotation_(display::Display::ROTATE_0) {
72 Shell::GetInstance()->AddShellObserver(this); 72 Shell::GetInstance()->AddShellObserver(this);
73 } 73 }
74 74
75 ScreenOrientationController::~ScreenOrientationController() { 75 ScreenOrientationController::~ScreenOrientationController() {
76 Shell::GetInstance()->RemoveShellObserver(this); 76 Shell::GetInstance()->RemoveShellObserver(this);
77 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); 77 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this);
78 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); 78 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this);
79 Shell::GetInstance()->activation_client()->RemoveObserver(this); 79 Shell::GetInstance()->activation_client()->RemoveObserver(this);
80 for (auto& windows : locking_windows_) 80 for (auto& windows : locking_windows_)
81 windows.first->RemoveObserver(this); 81 windows.first->RemoveObserver(this);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 120 }
121 121
122 void ScreenOrientationController::SetRotationLocked(bool rotation_locked) { 122 void ScreenOrientationController::SetRotationLocked(bool rotation_locked) {
123 if (rotation_locked_ == rotation_locked) 123 if (rotation_locked_ == rotation_locked)
124 return; 124 return;
125 rotation_locked_ = rotation_locked; 125 rotation_locked_ = rotation_locked;
126 if (!rotation_locked_) 126 if (!rotation_locked_)
127 rotation_locked_orientation_ = blink::WebScreenOrientationLockAny; 127 rotation_locked_orientation_ = blink::WebScreenOrientationLockAny;
128 FOR_EACH_OBSERVER(Observer, observers_, 128 FOR_EACH_OBSERVER(Observer, observers_,
129 OnRotationLockChanged(rotation_locked_)); 129 OnRotationLockChanged(rotation_locked_));
130 if (!gfx::Display::HasInternalDisplay()) 130 if (!display::Display::HasInternalDisplay())
131 return; 131 return;
132 base::AutoReset<bool> auto_ignore_display_configuration_updates( 132 base::AutoReset<bool> auto_ignore_display_configuration_updates(
133 &ignore_display_configuration_updates_, true); 133 &ignore_display_configuration_updates_, true);
134 Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties( 134 Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties(
135 rotation_locked_, current_rotation_); 135 rotation_locked_, current_rotation_);
136 } 136 }
137 137
138 void ScreenOrientationController::SetDisplayRotation( 138 void ScreenOrientationController::SetDisplayRotation(
139 gfx::Display::Rotation rotation, 139 display::Display::Rotation rotation,
140 gfx::Display::RotationSource source) { 140 display::Display::RotationSource source) {
141 if (!gfx::Display::HasInternalDisplay()) 141 if (!display::Display::HasInternalDisplay())
142 return; 142 return;
143 current_rotation_ = rotation; 143 current_rotation_ = rotation;
144 base::AutoReset<bool> auto_ignore_display_configuration_updates( 144 base::AutoReset<bool> auto_ignore_display_configuration_updates(
145 &ignore_display_configuration_updates_, true); 145 &ignore_display_configuration_updates_, true);
146 146
147 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation( 147 Shell::GetInstance()->display_configuration_controller()->SetDisplayRotation(
148 gfx::Display::InternalDisplayId(), rotation, source, 148 display::Display::InternalDisplayId(), rotation, source,
149 true /* user_action */); 149 true /* user_action */);
150 } 150 }
151 151
152 void ScreenOrientationController::OnWindowActivated( 152 void ScreenOrientationController::OnWindowActivated(
153 aura::client::ActivationChangeObserver::ActivationReason reason, 153 aura::client::ActivationChangeObserver::ActivationReason reason,
154 aura::Window* gained_active, 154 aura::Window* gained_active,
155 aura::Window* lost_active) { 155 aura::Window* lost_active) {
156 ApplyLockForActiveWindow(); 156 ApplyLockForActiveWindow();
157 } 157 }
158 158
(...skipping 26 matching lines...) Expand all
185 // unstable if it deviates too much from gravity 185 // unstable if it deviates too much from gravity
186 if (ui::IsAccelerometerReadingStable(*update, 186 if (ui::IsAccelerometerReadingStable(*update,
187 chromeos::ACCELEROMETER_SOURCE_SCREEN)) { 187 chromeos::ACCELEROMETER_SOURCE_SCREEN)) {
188 HandleScreenRotation(update->get(chromeos::ACCELEROMETER_SOURCE_SCREEN)); 188 HandleScreenRotation(update->get(chromeos::ACCELEROMETER_SOURCE_SCREEN));
189 } 189 }
190 } 190 }
191 191
192 void ScreenOrientationController::OnDisplayConfigurationChanged() { 192 void ScreenOrientationController::OnDisplayConfigurationChanged() {
193 if (ignore_display_configuration_updates_) 193 if (ignore_display_configuration_updates_)
194 return; 194 return;
195 if (!gfx::Display::HasInternalDisplay()) 195 if (!display::Display::HasInternalDisplay())
196 return; 196 return;
197 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 197 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
198 gfx::Display::Rotation user_rotation = 198 display::Display::Rotation user_rotation =
199 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) 199 display_manager->GetDisplayInfo(display::Display::InternalDisplayId())
200 .GetActiveRotation(); 200 .GetActiveRotation();
201 if (user_rotation != current_rotation_) { 201 if (user_rotation != current_rotation_) {
202 // A user may change other display configuration settings. When the user 202 // A user may change other display configuration settings. When the user
203 // does change the rotation setting, then lock rotation to prevent the 203 // does change the rotation setting, then lock rotation to prevent the
204 // accelerometer from erasing their change. 204 // accelerometer from erasing their change.
205 SetRotationLocked(true); 205 SetRotationLocked(true);
206 user_rotation_ = current_rotation_ = user_rotation; 206 user_rotation_ = current_rotation_ = user_rotation;
207 } 207 }
208 } 208 }
209 209
210 void ScreenOrientationController::OnMaximizeModeStarted() { 210 void ScreenOrientationController::OnMaximizeModeStarted() {
211 // Do not exit early, as the internal display can be determined after Maximize 211 // Do not exit early, as the internal display can be determined after Maximize
212 // Mode has started. (chrome-os-partner:38796) 212 // Mode has started. (chrome-os-partner:38796)
213 // Always start observing. 213 // Always start observing.
214 if (gfx::Display::HasInternalDisplay()) { 214 if (display::Display::HasInternalDisplay()) {
215 current_rotation_ = user_rotation_ = 215 current_rotation_ = user_rotation_ =
216 Shell::GetInstance() 216 Shell::GetInstance()
217 ->display_manager() 217 ->display_manager()
218 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) 218 ->GetDisplayInfo(display::Display::InternalDisplayId())
219 .GetActiveRotation(); 219 .GetActiveRotation();
220 } 220 }
221 if (!rotation_locked_) 221 if (!rotation_locked_)
222 LoadDisplayRotationProperties(); 222 LoadDisplayRotationProperties();
223 chromeos::AccelerometerReader::GetInstance()->AddObserver(this); 223 chromeos::AccelerometerReader::GetInstance()->AddObserver(this);
224 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); 224 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this);
225 } 225 }
226 226
227 void ScreenOrientationController::OnMaximizeModeEnded() { 227 void ScreenOrientationController::OnMaximizeModeEnded() {
228 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this); 228 chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this);
229 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); 229 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this);
230 if (current_rotation_ != user_rotation_) 230 if (current_rotation_ != user_rotation_)
231 SetDisplayRotation(user_rotation_, gfx::Display::ROTATION_SOURCE_USER); 231 SetDisplayRotation(user_rotation_, display::Display::ROTATION_SOURCE_USER);
232 } 232 }
233 233
234 void ScreenOrientationController::LockRotation( 234 void ScreenOrientationController::LockRotation(
235 gfx::Display::Rotation rotation, 235 display::Display::Rotation rotation,
236 gfx::Display::RotationSource source) { 236 display::Display::RotationSource source) {
237 SetRotationLocked(true); 237 SetRotationLocked(true);
238 SetDisplayRotation(rotation, source); 238 SetDisplayRotation(rotation, source);
239 } 239 }
240 240
241 void ScreenOrientationController::LockRotationToOrientation( 241 void ScreenOrientationController::LockRotationToOrientation(
242 blink::WebScreenOrientationLockType lock_orientation) { 242 blink::WebScreenOrientationLockType lock_orientation) {
243 rotation_locked_orientation_ = lock_orientation; 243 rotation_locked_orientation_ = lock_orientation;
244 switch (lock_orientation) { 244 switch (lock_orientation) {
245 case blink::WebScreenOrientationLockAny: 245 case blink::WebScreenOrientationLockAny:
246 SetRotationLocked(false); 246 SetRotationLocked(false);
(...skipping 14 matching lines...) Expand all
261 break; 261 break;
262 case blink::WebScreenOrientationLockLandscapeSecondary: 262 case blink::WebScreenOrientationLockLandscapeSecondary:
263 LockRotationToSecondaryOrientation( 263 LockRotationToSecondaryOrientation(
264 blink::WebScreenOrientationLockLandscape); 264 blink::WebScreenOrientationLockLandscape);
265 break; 265 break;
266 case blink::WebScreenOrientationLockLandscapePrimary: 266 case blink::WebScreenOrientationLockLandscapePrimary:
267 LockRotationToPrimaryOrientation( 267 LockRotationToPrimaryOrientation(
268 blink::WebScreenOrientationLockLandscape); 268 blink::WebScreenOrientationLockLandscape);
269 break; 269 break;
270 case blink::WebScreenOrientationLockNatural: 270 case blink::WebScreenOrientationLockNatural:
271 LockRotation(gfx::Display::ROTATE_0, 271 LockRotation(display::Display::ROTATE_0,
272 gfx::Display::ROTATION_SOURCE_ACTIVE); 272 display::Display::ROTATION_SOURCE_ACTIVE);
273 break; 273 break;
274 default: 274 default:
275 NOTREACHED(); 275 NOTREACHED();
276 break; 276 break;
277 } 277 }
278 } 278 }
279 279
280 void ScreenOrientationController::LockRotationToPrimaryOrientation( 280 void ScreenOrientationController::LockRotationToPrimaryOrientation(
281 blink::WebScreenOrientationLockType lock_orientation) { 281 blink::WebScreenOrientationLockType lock_orientation) {
282 LockRotation(natural_orientation_ == lock_orientation 282 LockRotation(natural_orientation_ == lock_orientation
283 ? gfx::Display::ROTATE_0 283 ? display::Display::ROTATE_0
284 : gfx::Display::ROTATE_90, 284 : display::Display::ROTATE_90,
285 gfx::Display::ROTATION_SOURCE_ACTIVE); 285 display::Display::ROTATION_SOURCE_ACTIVE);
286 } 286 }
287 287
288 void ScreenOrientationController::LockRotationToSecondaryOrientation( 288 void ScreenOrientationController::LockRotationToSecondaryOrientation(
289 blink::WebScreenOrientationLockType lock_orientation) { 289 blink::WebScreenOrientationLockType lock_orientation) {
290 LockRotation(natural_orientation_ == lock_orientation 290 LockRotation(natural_orientation_ == lock_orientation
291 ? gfx::Display::ROTATE_180 291 ? display::Display::ROTATE_180
292 : gfx::Display::ROTATE_270, 292 : display::Display::ROTATE_270,
293 gfx::Display::ROTATION_SOURCE_ACTIVE); 293 display::Display::ROTATION_SOURCE_ACTIVE);
294 } 294 }
295 295
296 void ScreenOrientationController::LockToRotationMatchingOrientation( 296 void ScreenOrientationController::LockToRotationMatchingOrientation(
297 blink::WebScreenOrientationLockType lock_orientation) { 297 blink::WebScreenOrientationLockType lock_orientation) {
298 if (!gfx::Display::HasInternalDisplay()) 298 if (!display::Display::HasInternalDisplay())
299 return; 299 return;
300 300
301 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 301 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
302 gfx::Display::Rotation rotation = 302 display::Display::Rotation rotation =
303 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) 303 display_manager->GetDisplayInfo(display::Display::InternalDisplayId())
304 .GetActiveRotation(); 304 .GetActiveRotation();
305 if (natural_orientation_ == lock_orientation) { 305 if (natural_orientation_ == lock_orientation) {
306 if (rotation == gfx::Display::ROTATE_0 || 306 if (rotation == display::Display::ROTATE_0 ||
307 rotation == gfx::Display::ROTATE_180) { 307 rotation == display::Display::ROTATE_180) {
308 SetRotationLocked(true); 308 SetRotationLocked(true);
309 } else { 309 } else {
310 LockRotation(gfx::Display::ROTATE_0, 310 LockRotation(display::Display::ROTATE_0,
311 gfx::Display::ROTATION_SOURCE_ACTIVE); 311 display::Display::ROTATION_SOURCE_ACTIVE);
312 } 312 }
313 } else { 313 } else {
314 if (rotation == gfx::Display::ROTATE_90 || 314 if (rotation == display::Display::ROTATE_90 ||
315 rotation == gfx::Display::ROTATE_270) { 315 rotation == display::Display::ROTATE_270) {
316 SetRotationLocked(true); 316 SetRotationLocked(true);
317 } else { 317 } else {
318 LockRotation(gfx::Display::ROTATE_90, 318 LockRotation(display::Display::ROTATE_90,
319 gfx::Display::ROTATION_SOURCE_ACTIVE); 319 display::Display::ROTATION_SOURCE_ACTIVE);
320 } 320 }
321 } 321 }
322 } 322 }
323 323
324 void ScreenOrientationController::HandleScreenRotation( 324 void ScreenOrientationController::HandleScreenRotation(
325 const chromeos::AccelerometerReading& lid) { 325 const chromeos::AccelerometerReading& lid) {
326 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f); 326 gfx::Vector3dF lid_flattened(lid.x, lid.y, 0.0f);
327 float lid_flattened_length = lid_flattened.Length(); 327 float lid_flattened_length = lid_flattened.Length();
328 // When the lid is close to being flat, don't change rotation as it is too 328 // When the lid is close to being flat, don't change rotation as it is too
329 // sensitive to slight movements. 329 // sensitive to slight movements.
330 if (lid_flattened_length < kMinimumAccelerationScreenRotation) 330 if (lid_flattened_length < kMinimumAccelerationScreenRotation)
331 return; 331 return;
332 332
333 // The reference vector is the angle of gravity when the device is rotated 333 // The reference vector is the angle of gravity when the device is rotated
334 // clockwise by 45 degrees. Computing the angle between this vector and 334 // clockwise by 45 degrees. Computing the angle between this vector and
335 // gravity we can easily determine the expected display rotation. 335 // gravity we can easily determine the expected display rotation.
336 static const gfx::Vector3dF rotation_reference(-1.0f, 1.0f, 0.0f); 336 static const gfx::Vector3dF rotation_reference(-1.0f, 1.0f, 0.0f);
337 337
338 // Set the down vector to match the expected direction of gravity given the 338 // Set the down vector to match the expected direction of gravity given the
339 // last configured rotation. This is used to enforce a stickiness that the 339 // last configured rotation. This is used to enforce a stickiness that the
340 // user must overcome to rotate the display and prevents frequent rotations 340 // user must overcome to rotate the display and prevents frequent rotations
341 // when holding the device near 45 degrees. 341 // when holding the device near 45 degrees.
342 gfx::Vector3dF down(0.0f, 0.0f, 0.0f); 342 gfx::Vector3dF down(0.0f, 0.0f, 0.0f);
343 if (current_rotation_ == gfx::Display::ROTATE_0) 343 if (current_rotation_ == display::Display::ROTATE_0)
344 down.set_y(1.0f); 344 down.set_y(1.0f);
345 else if (current_rotation_ == gfx::Display::ROTATE_90) 345 else if (current_rotation_ == display::Display::ROTATE_90)
346 down.set_x(1.0f); 346 down.set_x(1.0f);
347 else if (current_rotation_ == gfx::Display::ROTATE_180) 347 else if (current_rotation_ == display::Display::ROTATE_180)
348 down.set_y(-1.0f); 348 down.set_y(-1.0f);
349 else 349 else
350 down.set_x(-1.0f); 350 down.set_x(-1.0f);
351 351
352 // Don't rotate if the screen has not passed the threshold. 352 // Don't rotate if the screen has not passed the threshold.
353 if (gfx::AngleBetweenVectorsInDegrees(down, lid_flattened) < 353 if (gfx::AngleBetweenVectorsInDegrees(down, lid_flattened) <
354 kDisplayRotationStickyAngleDegrees) { 354 kDisplayRotationStickyAngleDegrees) {
355 return; 355 return;
356 } 356 }
357 357
358 float angle = gfx::ClockwiseAngleBetweenVectorsInDegrees( 358 float angle = gfx::ClockwiseAngleBetweenVectorsInDegrees(
359 rotation_reference, lid_flattened, gfx::Vector3dF(0.0f, 0.0f, 1.0f)); 359 rotation_reference, lid_flattened, gfx::Vector3dF(0.0f, 0.0f, 1.0f));
360 360
361 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_270; 361 display::Display::Rotation new_rotation = display::Display::ROTATE_270;
362 if (angle < 90.0f) 362 if (angle < 90.0f)
363 new_rotation = gfx::Display::ROTATE_0; 363 new_rotation = display::Display::ROTATE_0;
364 else if (angle < 180.0f) 364 else if (angle < 180.0f)
365 new_rotation = gfx::Display::ROTATE_90; 365 new_rotation = display::Display::ROTATE_90;
366 else if (angle < 270.0f) 366 else if (angle < 270.0f)
367 new_rotation = gfx::Display::ROTATE_180; 367 new_rotation = display::Display::ROTATE_180;
368 368
369 if (new_rotation != current_rotation_ && 369 if (new_rotation != current_rotation_ &&
370 IsRotationAllowedInLockedState(new_rotation)) { 370 IsRotationAllowedInLockedState(new_rotation)) {
371 SetDisplayRotation(new_rotation, 371 SetDisplayRotation(new_rotation,
372 gfx::Display::ROTATION_SOURCE_ACCELEROMETER); 372 display::Display::ROTATION_SOURCE_ACCELEROMETER);
373 } 373 }
374 } 374 }
375 375
376 void ScreenOrientationController::LoadDisplayRotationProperties() { 376 void ScreenOrientationController::LoadDisplayRotationProperties() {
377 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 377 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
378 if (!display_manager->registered_internal_display_rotation_lock()) 378 if (!display_manager->registered_internal_display_rotation_lock())
379 return; 379 return;
380 SetDisplayRotation(display_manager->registered_internal_display_rotation(), 380 SetDisplayRotation(display_manager->registered_internal_display_rotation(),
381 gfx::Display::ROTATION_SOURCE_ACCELEROMETER); 381 display::Display::ROTATION_SOURCE_ACCELEROMETER);
382 SetRotationLocked(true); 382 SetRotationLocked(true);
383 } 383 }
384 384
385 void ScreenOrientationController::ApplyLockForActiveWindow() { 385 void ScreenOrientationController::ApplyLockForActiveWindow() {
386 aura::Window* active_window = 386 aura::Window* active_window =
387 Shell::GetInstance()->activation_client()->GetActiveWindow(); 387 Shell::GetInstance()->activation_client()->GetActiveWindow();
388 for (auto const& windows : locking_windows_) { 388 for (auto const& windows : locking_windows_) {
389 if (windows.first->TargetVisibility() && 389 if (windows.first->TargetVisibility() &&
390 active_window->Contains(windows.first)) { 390 active_window->Contains(windows.first)) {
391 LockRotationToOrientation(windows.second); 391 LockRotationToOrientation(windows.second);
392 return; 392 return;
393 } 393 }
394 } 394 }
395 SetRotationLocked(false); 395 SetRotationLocked(false);
396 } 396 }
397 397
398 bool ScreenOrientationController::IsRotationAllowedInLockedState( 398 bool ScreenOrientationController::IsRotationAllowedInLockedState(
399 gfx::Display::Rotation rotation) { 399 display::Display::Rotation rotation) {
400 if (!rotation_locked_) 400 if (!rotation_locked_)
401 return true; 401 return true;
402 402
403 if (!CanRotateInLockedState()) 403 if (!CanRotateInLockedState())
404 return false; 404 return false;
405 405
406 if (natural_orientation_ == rotation_locked_orientation_) { 406 if (natural_orientation_ == rotation_locked_orientation_) {
407 return rotation == gfx::Display::ROTATE_0 || 407 return rotation == display::Display::ROTATE_0 ||
408 rotation == gfx::Display::ROTATE_180; 408 rotation == display::Display::ROTATE_180;
409 } else { 409 } else {
410 return rotation == gfx::Display::ROTATE_90 || 410 return rotation == display::Display::ROTATE_90 ||
411 rotation == gfx::Display::ROTATE_270; 411 rotation == display::Display::ROTATE_270;
412 } 412 }
413 return false; 413 return false;
414 } 414 }
415 415
416 bool ScreenOrientationController::CanRotateInLockedState() { 416 bool ScreenOrientationController::CanRotateInLockedState() {
417 return rotation_locked_orientation_ == 417 return rotation_locked_orientation_ ==
418 blink::WebScreenOrientationLockLandscape || 418 blink::WebScreenOrientationLockLandscape ||
419 rotation_locked_orientation_ == 419 rotation_locked_orientation_ ==
420 blink::WebScreenOrientationLockPortrait; 420 blink::WebScreenOrientationLockPortrait;
421 } 421 }
422 422
423 } // namespace ash 423 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/screen_orientation_controller_chromeos.h ('k') | ash/display/screen_position_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698