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" | 9 #include "ash/common/wm/mru_window_tracker.h" |
10 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 case display::Display::ROTATE_90: | 55 case display::Display::ROTATE_90: |
56 case display::Display::ROTATE_270: | 56 case display::Display::ROTATE_270: |
57 return size.height() < size.width() | 57 return size.height() < size.width() |
58 ? blink::WebScreenOrientationLockPortrait | 58 ? blink::WebScreenOrientationLockPortrait |
59 : blink::WebScreenOrientationLockLandscape; | 59 : blink::WebScreenOrientationLockLandscape; |
60 } | 60 } |
61 NOTREACHED(); | 61 NOTREACHED(); |
62 return blink::WebScreenOrientationLockLandscape; | 62 return blink::WebScreenOrientationLockLandscape; |
63 } | 63 } |
64 | 64 |
65 blink::WebScreenOrientationLockType RotationToOrientation( | |
66 display::Display::Rotation rotation) { | |
67 blink::WebScreenOrientationLockType natural = GetDisplayNaturalOrientation(); | |
68 if (natural == blink::WebScreenOrientationLockLandscape) { | |
69 switch (rotation) { | |
70 case display::Display::ROTATE_0: | |
71 return blink::WebScreenOrientationLockLandscapePrimary; | |
72 case display::Display::ROTATE_90: | |
73 return blink::WebScreenOrientationLockPortraitPrimary; | |
74 case display::Display::ROTATE_180: | |
75 return blink::WebScreenOrientationLockLandscapeSecondary; | |
76 case display::Display::ROTATE_270: | |
77 return blink::WebScreenOrientationLockPortraitSecondary; | |
78 } | |
79 } else { // Natural portrait | |
80 switch (rotation) { | |
81 case display::Display::ROTATE_0: | |
82 return blink::WebScreenOrientationLockPortraitPrimary; | |
83 case display::Display::ROTATE_90: | |
84 return blink::WebScreenOrientationLockLandscapePrimary; | |
85 case display::Display::ROTATE_180: | |
86 return blink::WebScreenOrientationLockPortraitSecondary; | |
87 case display::Display::ROTATE_270: | |
88 return blink::WebScreenOrientationLockLandscapeSecondary; | |
89 } | |
90 } | |
91 NOTREACHED(); | |
92 return blink::WebScreenOrientationLockAny; | |
93 } | |
94 | |
95 // Returns the rotation that matches the orientation type. | 65 // Returns the rotation that matches the orientation type. |
96 // Returns ROTATE_0 if the given orientation is ANY, which is used | 66 // Returns ROTATE_0 if the given orientation is ANY, which is used |
97 // to indicate that user didn't lock orientation. | 67 // to indicate that user didn't lock orientation. |
98 display::Display::Rotation OrientationToRotation( | 68 display::Display::Rotation OrientationToRotation( |
99 blink::WebScreenOrientationLockType orientation) { | 69 blink::WebScreenOrientationLockType orientation) { |
100 blink::WebScreenOrientationLockType natural = GetDisplayNaturalOrientation(); | 70 blink::WebScreenOrientationLockType natural = GetDisplayNaturalOrientation(); |
101 if (orientation == blink::WebScreenOrientationLockAny) { | 71 if (orientation == blink::WebScreenOrientationLockAny) { |
102 return display::Display::ROTATE_0; | 72 return display::Display::ROTATE_0; |
103 } | 73 } |
104 | 74 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 (app_requested == blink::WebScreenOrientationLockPortrait && | 116 (app_requested == blink::WebScreenOrientationLockPortrait && |
147 (lock == blink::WebScreenOrientationLockPortraitPrimary || | 117 (lock == blink::WebScreenOrientationLockPortraitPrimary || |
148 lock == blink::WebScreenOrientationLockPortraitSecondary))) { | 118 lock == blink::WebScreenOrientationLockPortraitSecondary))) { |
149 return lock; | 119 return lock; |
150 } | 120 } |
151 return app_requested; | 121 return app_requested; |
152 } | 122 } |
153 | 123 |
154 } // namespace | 124 } // namespace |
155 | 125 |
126 // static | |
127 blink::WebScreenOrientationLockType | |
128 ScreenOrientationController::RotationToOrientation( | |
129 display::Display::Rotation rotation) { | |
130 blink::WebScreenOrientationLockType natural = GetDisplayNaturalOrientation(); | |
131 if (natural == blink::WebScreenOrientationLockLandscape) { | |
132 switch (rotation) { | |
133 case display::Display::ROTATE_0: | |
134 return blink::WebScreenOrientationLockLandscapePrimary; | |
135 case display::Display::ROTATE_90: | |
136 return blink::WebScreenOrientationLockPortraitPrimary; | |
137 case display::Display::ROTATE_180: | |
138 return blink::WebScreenOrientationLockLandscapeSecondary; | |
139 case display::Display::ROTATE_270: | |
140 return blink::WebScreenOrientationLockPortraitSecondary; | |
141 } | |
142 } else { // Natural portrait | |
143 switch (rotation) { | |
144 case display::Display::ROTATE_0: | |
145 return blink::WebScreenOrientationLockPortraitPrimary; | |
146 case display::Display::ROTATE_90: | |
147 return blink::WebScreenOrientationLockLandscapePrimary; | |
148 case display::Display::ROTATE_180: | |
149 return blink::WebScreenOrientationLockPortraitSecondary; | |
150 case display::Display::ROTATE_270: | |
151 return blink::WebScreenOrientationLockLandscapeSecondary; | |
152 } | |
153 } | |
154 NOTREACHED(); | |
155 return blink::WebScreenOrientationLockAny; | |
156 } | |
157 | |
156 ScreenOrientationController::ScreenOrientationController() | 158 ScreenOrientationController::ScreenOrientationController() |
157 : natural_orientation_(GetDisplayNaturalOrientation()), | 159 : natural_orientation_(GetDisplayNaturalOrientation()), |
158 ignore_display_configuration_updates_(false), | 160 ignore_display_configuration_updates_(false), |
159 rotation_locked_(false), | 161 rotation_locked_(false), |
160 rotation_locked_orientation_(blink::WebScreenOrientationLockAny), | 162 rotation_locked_orientation_(blink::WebScreenOrientationLockAny), |
161 user_rotation_(display::Display::ROTATE_0), | 163 user_rotation_(display::Display::ROTATE_0), |
162 current_rotation_(display::Display::ROTATE_0) { | 164 current_rotation_(display::Display::ROTATE_0) { |
163 Shell::GetInstance()->AddShellObserver(this); | 165 Shell::GetInstance()->AddShellObserver(this); |
164 } | 166 } |
165 | 167 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 | 227 |
226 if (user_rotation_locked()) { | 228 if (user_rotation_locked()) { |
227 user_locked_orientation_ = blink::WebScreenOrientationLockAny; | 229 user_locked_orientation_ = blink::WebScreenOrientationLockAny; |
228 } else { | 230 } else { |
229 display::Display::Rotation current_rotation = | 231 display::Display::Rotation current_rotation = |
230 WmShell::Get() | 232 WmShell::Get() |
231 ->GetDisplayInfo(display::Display::InternalDisplayId()) | 233 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
232 .GetActiveRotation(); | 234 .GetActiveRotation(); |
233 user_locked_orientation_ = RotationToOrientation(current_rotation); | 235 user_locked_orientation_ = RotationToOrientation(current_rotation); |
234 } | 236 } |
237 SetLockToOrientation(user_locked_orientation_); | |
238 } | |
239 | |
240 void ScreenOrientationController::SetLockToOrientation( | |
241 blink::WebScreenOrientationLockType orientation) { | |
242 DCHECK(display::Display::HasInternalDisplay()); | |
oshima
2017/03/30 00:44:37
move SetLockToOrientation to private, and add
SetL
Qiang(Joe) Xu
2017/03/30 01:15:14
Done.
| |
243 user_locked_orientation_ = orientation; | |
235 base::AutoReset<bool> auto_ignore_display_configuration_updates( | 244 base::AutoReset<bool> auto_ignore_display_configuration_updates( |
236 &ignore_display_configuration_updates_, true); | 245 &ignore_display_configuration_updates_, true); |
237 Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties( | 246 Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties( |
238 user_rotation_locked(), OrientationToRotation(user_locked_orientation_)); | 247 user_rotation_locked(), OrientationToRotation(user_locked_orientation_)); |
239 | 248 |
240 ApplyLockForActiveWindow(); | 249 ApplyLockForActiveWindow(); |
241 for (auto& observer : observers_) | 250 for (auto& observer : observers_) |
242 observer.OnUserRotationLockChanged(); | 251 observer.OnUserRotationLockChanged(); |
243 } | 252 } |
244 | 253 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 } | 561 } |
553 | 562 |
554 bool ScreenOrientationController::CanRotateInLockedState() { | 563 bool ScreenOrientationController::CanRotateInLockedState() { |
555 return rotation_locked_orientation_ == | 564 return rotation_locked_orientation_ == |
556 blink::WebScreenOrientationLockLandscape || | 565 blink::WebScreenOrientationLockLandscape || |
557 rotation_locked_orientation_ == | 566 rotation_locked_orientation_ == |
558 blink::WebScreenOrientationLockPortrait; | 567 blink::WebScreenOrientationLockPortrait; |
559 } | 568 } |
560 | 569 |
561 } // namespace ash | 570 } // namespace ash |
OLD | NEW |