OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/system/chromeos/screen_orientation/screen_orientation_delegate_ash .h" | |
flackr
2014/10/14 20:08:17
This should maybe be in ash/display/screen_orienta
jonross
2014/10/22 18:45:30
Done.
| |
6 | |
7 #include "ash/display/display_info.h" | |
8 #include "ash/display/display_manager.h" | |
9 #include "ash/shell.h" | |
10 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
11 #include "content/public/browser/screen_orientation_provider.h" | |
12 #include "ui/gfx/display.h" | |
13 #include "ui/gfx/geometry/size.h" | |
14 | |
15 namespace ash { | |
16 | |
17 ScreenOrientationDelegateAsh::ScreenOrientationDelegateAsh() | |
18 : natural_orientation_(blink::WebScreenOrientationLockLandscape) { | |
19 content::ScreenOrientationProvider::SetDelegate(this); | |
20 | |
21 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
22 if (display_manager->HasInternalDisplay()) { | |
23 DisplayInfo info = | |
24 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()); | |
25 gfx::Display::Rotation rotation = info.rotation(); | |
26 gfx::Size size = info.size_in_pixel(); | |
27 if (((rotation == gfx::Display::ROTATE_0 || | |
28 rotation == gfx::Display::ROTATE_180) && | |
mlamouri (slow - plz ping)
2014/10/15 15:39:33
nit: one space is missing to align this line
jonross
2014/10/22 18:45:30
Done.
| |
29 size.height() >= size.width()) || | |
30 ((rotation == gfx::Display::ROTATE_90 || | |
31 rotation == gfx::Display::ROTATE_270) && | |
32 size.height() < size.width())) { | |
33 natural_orientation_ = blink::WebScreenOrientationLockPortrait; | |
34 } | |
35 } | |
flackr
2014/10/14 20:08:18
Move this to a helper function (GetDisplayNaturalO
mlamouri (slow - plz ping)
2014/10/15 15:39:33
+1 with that, it would make this algorithm a bit m
jonross
2014/10/22 18:45:30
Done.
| |
36 } | |
37 | |
38 ScreenOrientationDelegateAsh::~ScreenOrientationDelegateAsh() { | |
39 content::ScreenOrientationProvider::SetDelegate(NULL); | |
40 } | |
41 | |
42 bool ScreenOrientationDelegateAsh::FullScreenRequired( | |
43 content::WebContents* web_contents) { | |
44 return true; | |
45 } | |
46 | |
47 void ScreenOrientationDelegateAsh::Lock( | |
48 blink::WebScreenOrientationLockType lock_orientation) { | |
49 MaximizeModeController* controller = | |
50 Shell::GetInstance()->maximize_mode_controller(); | |
51 switch (lock_orientation) { | |
52 case blink::WebScreenOrientationLockAny: | |
53 case blink::WebScreenOrientationLockDefault: | |
54 DCHECK(!controller->rotation_locked()); | |
flackr
2014/10/14 20:08:17
Won't this be true if the user manually locked a r
mlamouri (slow - plz ping)
2014/10/15 15:39:33
LockDefault is not expected to be called. You shou
jonross
2014/10/22 18:45:30
Since it should not be called I'll use NOTREACHED,
| |
55 break; | |
56 case blink::WebScreenOrientationLockPortraitPrimary: | |
57 LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait); | |
58 break; | |
59 case blink::WebScreenOrientationLockPortrait: | |
60 LockToRotationMatchingOrientation(lock_orientation); | |
61 break; | |
62 case blink::WebScreenOrientationLockPortraitSecondary: | |
63 LockRotationToSecondaryOrientation( | |
64 blink::WebScreenOrientationLockPortrait); | |
65 break; | |
66 case blink::WebScreenOrientationLockLandscapeSecondary: | |
67 LockRotationToSecondaryOrientation( | |
68 blink::WebScreenOrientationLockLandscape); | |
69 break; | |
70 case blink::WebScreenOrientationLockLandscapePrimary: | |
71 LockRotationToPrimaryOrientation( | |
72 blink::WebScreenOrientationLockLandscape); | |
73 break; | |
74 case blink::WebScreenOrientationLockLandscape: | |
75 LockToRotationMatchingOrientation(lock_orientation); | |
76 break; | |
77 case blink::WebScreenOrientationLockNatural: | |
78 default: | |
flackr
2014/10/14 20:08:18
Should probably handle all expected WebScreenOrien
mlamouri (slow - plz ping)
2014/10/15 15:39:33
+1
jonross
2014/10/22 18:45:30
Done.
| |
79 controller->LockRotation(gfx::Display::ROTATE_0); | |
80 break; | |
81 } | |
82 } | |
83 | |
84 bool ScreenOrientationDelegateAsh::ScreenOrientationProviderSupported() { | |
85 return Shell::GetInstance()->maximize_mode_controller()-> | |
86 IsMaximizeModeWindowManagerEnabled(); | |
87 } | |
88 | |
89 void ScreenOrientationDelegateAsh::Unlock() { | |
90 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(false); | |
flackr
2014/10/14 20:08:17
How does this interact with a user-locked orientat
| |
91 } | |
92 | |
93 void ScreenOrientationDelegateAsh::LockRotationToPrimaryOrientation( | |
94 blink::WebScreenOrientationLockType lock_orientation) { | |
95 Shell::GetInstance()->maximize_mode_controller()-> | |
96 LockRotation(natural_orientation_ == lock_orientation ? | |
97 gfx::Display::ROTATE_0 : | |
98 gfx::Display::ROTATE_90); | |
99 } | |
100 | |
101 void ScreenOrientationDelegateAsh::LockRotationToSecondaryOrientation( | |
102 blink::WebScreenOrientationLockType lock_orientation) { | |
103 Shell::GetInstance()->maximize_mode_controller()-> | |
104 LockRotation(natural_orientation_ == lock_orientation ? | |
105 gfx::Display::ROTATE_180 : | |
106 gfx::Display::ROTATE_270); | |
107 } | |
108 | |
109 void ScreenOrientationDelegateAsh::LockToRotationMatchingOrientation( | |
110 blink::WebScreenOrientationLockType lock_orientation) { | |
111 //TODO(jonross): Update MaximizeModeController to allow rotation between | |
112 // two angles of an orientation. | |
flackr
2014/10/14 20:08:17
I'm a little unclear on what you mean here? Can yo
jonross
2014/10/22 18:45:30
Correct, it would be to allow the web page to lock
| |
113 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
114 if (!display_manager->HasInternalDisplay()) | |
115 return; | |
mlamouri (slow - plz ping)
2014/10/15 15:39:33
I'm a bit confused by that. Is it expected? I mean
jonross
2014/10/22 18:45:30
This is a valid state for unit tests on ash. Since
| |
116 | |
117 gfx::Display::Rotation rotation = display_manager-> | |
118 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | |
119 MaximizeModeController* controller = | |
120 Shell::GetInstance()->maximize_mode_controller(); | |
121 if (natural_orientation_ == lock_orientation) { | |
122 if (rotation == gfx::Display::ROTATE_0 || | |
123 rotation == gfx::Display::ROTATE_180){ | |
124 controller->SetRotationLocked(true); | |
125 } else { | |
126 controller->LockRotation(gfx::Display::ROTATE_0); | |
127 } | |
128 } else { | |
129 if (rotation == gfx::Display::ROTATE_90 || | |
130 rotation == gfx::Display::ROTATE_270) { | |
131 controller->SetRotationLocked(true); | |
132 } else { | |
133 controller->LockRotation(gfx::Display::ROTATE_90); | |
134 } | |
135 } | |
136 } | |
137 | |
138 } // namespace ash | |
OLD | NEW |