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/content/display/screen_orientation_delegate_chromeos.h" | 5 #include "ash/content/display/screen_orientation_delegate_chromeos.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/display_info.h" | 8 #include "ash/display/display_info.h" |
9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 11 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
flackr
2014/11/27 15:39:15
Obsolete?
jonross
2014/12/10 17:57:30
Nope, used in ScreenOrientationDelegate::ScreenOri
| |
12 #include "base/auto_reset.h" | |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "content/public/browser/screen_orientation_provider.h" | 14 #include "content/public/browser/screen_orientation_provider.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
16 #include "ui/gfx/display.h" | 17 #include "ui/gfx/display.h" |
17 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { | 22 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { |
(...skipping 20 matching lines...) Expand all Loading... | |
42 NOTREACHED(); | 43 NOTREACHED(); |
43 return blink::WebScreenOrientationLockLandscape; | 44 return blink::WebScreenOrientationLockLandscape; |
44 } | 45 } |
45 | 46 |
46 } // namespace | 47 } // namespace |
47 | 48 |
48 namespace ash { | 49 namespace ash { |
49 | 50 |
50 ScreenOrientationDelegate::ScreenOrientationDelegate() | 51 ScreenOrientationDelegate::ScreenOrientationDelegate() |
51 : locking_window_(NULL), | 52 : locking_window_(NULL), |
52 natural_orientation_(GetDisplayNaturalOrientation()) { | 53 natural_orientation_(GetDisplayNaturalOrientation()), |
54 ignore_display_configuration_updates_(false), | |
55 rotation_locked_(false) { | |
53 content::ScreenOrientationProvider::SetDelegate(this); | 56 content::ScreenOrientationProvider::SetDelegate(this); |
54 } | 57 } |
55 | 58 |
56 ScreenOrientationDelegate::~ScreenOrientationDelegate() { | 59 ScreenOrientationDelegate::~ScreenOrientationDelegate() { |
57 content::ScreenOrientationProvider::SetDelegate(NULL); | 60 content::ScreenOrientationProvider::SetDelegate(NULL); |
58 } | 61 } |
59 | 62 |
63 void ScreenOrientationDelegate::AddObserver(Observer* observer) { | |
64 observers_.AddObserver(observer); | |
65 } | |
66 | |
67 void ScreenOrientationDelegate::RemoveObserver(Observer* observer) { | |
68 observers_.RemoveObserver(observer); | |
69 } | |
70 | |
71 void ScreenOrientationDelegate::SetRotationLocked(bool rotation_locked) { | |
72 if (rotation_locked_ == rotation_locked) | |
73 return; | |
74 base::AutoReset<bool> auto_ignore_display_configuration_updates( | |
flackr
2014/11/27 15:39:15
Can you scope this to just the call which triggers
jonross
2014/12/10 17:57:30
Done.
| |
75 &ignore_display_configuration_updates_, true); | |
76 rotation_locked_ = rotation_locked; | |
77 FOR_EACH_OBSERVER(Observer, observers_, | |
78 OnRotationLockChanged(rotation_locked_)); | |
79 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
80 if (!display_manager->HasInternalDisplay()) | |
81 return; | |
82 gfx::Display::Rotation current_rotation = | |
83 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) | |
84 .rotation(); | |
85 display_manager->RegisterDisplayRotationProperties(rotation_locked_, | |
86 current_rotation); | |
87 } | |
88 | |
89 void ScreenOrientationDelegate::SetDisplayRotation( | |
90 gfx::Display::Rotation rotation) { | |
91 base::AutoReset<bool> auto_ignore_display_configuration_updates( | |
92 &ignore_display_configuration_updates_, true); | |
93 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
94 if (!display_manager->HasInternalDisplay()) | |
95 return; | |
96 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(), | |
97 rotation); | |
98 } | |
99 | |
60 bool ScreenOrientationDelegate::FullScreenRequired( | 100 bool ScreenOrientationDelegate::FullScreenRequired( |
61 content::WebContents* web_contents) { | 101 content::WebContents* web_contents) { |
62 return true; | 102 return true; |
63 } | 103 } |
64 | 104 |
65 void ScreenOrientationDelegate::Lock( | 105 void ScreenOrientationDelegate::Lock( |
66 content::WebContents* web_contents, | 106 content::WebContents* web_contents, |
67 blink::WebScreenOrientationLockType lock_orientation) { | 107 blink::WebScreenOrientationLockType lock_orientation) { |
68 aura::Window* requesting_window = web_contents->GetNativeView(); | 108 aura::Window* requesting_window = web_contents->GetNativeView(); |
69 | |
70 // TODO(jonross): Make ScreenOrientationDelegate responsible for rotation | |
71 // lock. Have MaximizeModeController, and TrayRotationLock both use it | |
72 // instead. | |
73 MaximizeModeController* controller = | |
74 Shell::GetInstance()->maximize_mode_controller(); | |
75 | |
76 // TODO(jonross): Track one rotation lock per window. When the active window | 109 // TODO(jonross): Track one rotation lock per window. When the active window |
77 // changes apply any corresponding rotation lock. | 110 // changes apply any corresponding rotation lock. |
78 if (!locking_window_) | 111 if (!locking_window_) |
79 locking_window_ = requesting_window; | 112 locking_window_ = requesting_window; |
80 else if (requesting_window != locking_window_) | 113 else if (requesting_window != locking_window_) |
81 return; | 114 return; |
82 | 115 |
83 switch (lock_orientation) { | 116 switch (lock_orientation) { |
84 case blink::WebScreenOrientationLockAny: | 117 case blink::WebScreenOrientationLockAny: |
85 controller->SetRotationLocked(false); | 118 SetRotationLocked(false); |
86 locking_window_ = NULL; | 119 locking_window_ = NULL; |
87 break; | 120 break; |
88 case blink::WebScreenOrientationLockDefault: | 121 case blink::WebScreenOrientationLockDefault: |
89 NOTREACHED(); | 122 NOTREACHED(); |
90 break; | 123 break; |
91 case blink::WebScreenOrientationLockPortraitPrimary: | 124 case blink::WebScreenOrientationLockPortraitPrimary: |
92 LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait); | 125 LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait); |
93 break; | 126 break; |
94 case blink::WebScreenOrientationLockLandscape: | 127 case blink::WebScreenOrientationLockLandscape: |
95 case blink::WebScreenOrientationLockPortrait: | 128 case blink::WebScreenOrientationLockPortrait: |
96 LockToRotationMatchingOrientation(lock_orientation); | 129 LockToRotationMatchingOrientation(lock_orientation); |
97 break; | 130 break; |
98 case blink::WebScreenOrientationLockPortraitSecondary: | 131 case blink::WebScreenOrientationLockPortraitSecondary: |
99 LockRotationToSecondaryOrientation( | 132 LockRotationToSecondaryOrientation( |
100 blink::WebScreenOrientationLockPortrait); | 133 blink::WebScreenOrientationLockPortrait); |
101 break; | 134 break; |
102 case blink::WebScreenOrientationLockLandscapeSecondary: | 135 case blink::WebScreenOrientationLockLandscapeSecondary: |
103 LockRotationToSecondaryOrientation( | 136 LockRotationToSecondaryOrientation( |
104 blink::WebScreenOrientationLockLandscape); | 137 blink::WebScreenOrientationLockLandscape); |
105 break; | 138 break; |
106 case blink::WebScreenOrientationLockLandscapePrimary: | 139 case blink::WebScreenOrientationLockLandscapePrimary: |
107 LockRotationToPrimaryOrientation( | 140 LockRotationToPrimaryOrientation( |
108 blink::WebScreenOrientationLockLandscape); | 141 blink::WebScreenOrientationLockLandscape); |
109 break; | 142 break; |
110 case blink::WebScreenOrientationLockNatural: | 143 case blink::WebScreenOrientationLockNatural: |
111 controller->LockRotation(gfx::Display::ROTATE_0); | 144 LockRotation(gfx::Display::ROTATE_0); |
112 break; | 145 break; |
113 default: | 146 default: |
114 NOTREACHED(); | 147 NOTREACHED(); |
115 break; | 148 break; |
116 } | 149 } |
117 } | 150 } |
118 | 151 |
119 bool ScreenOrientationDelegate::ScreenOrientationProviderSupported() { | 152 bool ScreenOrientationDelegate::ScreenOrientationProviderSupported() { |
120 return Shell::GetInstance() | 153 return Shell::GetInstance() |
121 ->maximize_mode_controller() | 154 ->maximize_mode_controller() |
122 ->IsMaximizeModeWindowManagerEnabled() && | 155 ->IsMaximizeModeWindowManagerEnabled() && |
123 CommandLine::ForCurrentProcess()->HasSwitch( | 156 CommandLine::ForCurrentProcess()->HasSwitch( |
124 switches::kAshEnableTouchViewTesting); | 157 switches::kAshEnableTouchViewTesting); |
125 } | 158 } |
126 | 159 |
127 void ScreenOrientationDelegate::Unlock(content::WebContents* web_contents) { | 160 void ScreenOrientationDelegate::Unlock(content::WebContents* web_contents) { |
128 aura::Window* requesting_window = web_contents->GetNativeView(); | 161 aura::Window* requesting_window = web_contents->GetNativeView(); |
129 if (requesting_window != locking_window_) | 162 if (requesting_window != locking_window_) |
130 return; | 163 return; |
131 locking_window_ = NULL; | 164 locking_window_ = NULL; |
132 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(false); | 165 SetRotationLocked(false); |
166 } | |
167 | |
168 void ScreenOrientationDelegate::LockRotation(gfx::Display::Rotation rotation) { | |
169 SetRotationLocked(true); | |
170 SetDisplayRotation(rotation); | |
133 } | 171 } |
134 | 172 |
135 void ScreenOrientationDelegate::LockRotationToPrimaryOrientation( | 173 void ScreenOrientationDelegate::LockRotationToPrimaryOrientation( |
136 blink::WebScreenOrientationLockType lock_orientation) { | 174 blink::WebScreenOrientationLockType lock_orientation) { |
137 Shell::GetInstance()->maximize_mode_controller()->LockRotation( | 175 LockRotation(natural_orientation_ == lock_orientation |
138 natural_orientation_ == lock_orientation ? gfx::Display::ROTATE_0 | 176 ? gfx::Display::ROTATE_0 |
139 : gfx::Display::ROTATE_90); | 177 : gfx::Display::ROTATE_90); |
140 } | 178 } |
141 | 179 |
142 void ScreenOrientationDelegate::LockRotationToSecondaryOrientation( | 180 void ScreenOrientationDelegate::LockRotationToSecondaryOrientation( |
143 blink::WebScreenOrientationLockType lock_orientation) { | 181 blink::WebScreenOrientationLockType lock_orientation) { |
144 Shell::GetInstance()->maximize_mode_controller()->LockRotation( | 182 LockRotation(natural_orientation_ == lock_orientation |
145 natural_orientation_ == lock_orientation ? gfx::Display::ROTATE_180 | 183 ? gfx::Display::ROTATE_180 |
146 : gfx::Display::ROTATE_270); | 184 : gfx::Display::ROTATE_270); |
147 } | 185 } |
148 | 186 |
149 void ScreenOrientationDelegate::LockToRotationMatchingOrientation( | 187 void ScreenOrientationDelegate::LockToRotationMatchingOrientation( |
150 blink::WebScreenOrientationLockType lock_orientation) { | 188 blink::WebScreenOrientationLockType lock_orientation) { |
151 // TODO(jonross): Update MaximizeModeController to allow rotation between | 189 // TODO(jonross): Update MaximizeModeController to allow rotation between |
152 // two angles of an orientation (e.g. from ROTATE_0 to ROTATE_180, and from | 190 // two angles of an orientation (e.g. from ROTATE_0 to ROTATE_180, and from |
153 // ROTATE_90 to ROTATE_270) | 191 // ROTATE_90 to ROTATE_270) |
154 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 192 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
155 if (!display_manager->HasInternalDisplay()) | 193 if (!display_manager->HasInternalDisplay()) |
156 return; | 194 return; |
157 | 195 |
158 gfx::Display::Rotation rotation = | 196 gfx::Display::Rotation rotation = |
159 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) | 197 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
160 .rotation(); | 198 .rotation(); |
161 MaximizeModeController* controller = | |
162 Shell::GetInstance()->maximize_mode_controller(); | |
163 if (natural_orientation_ == lock_orientation) { | 199 if (natural_orientation_ == lock_orientation) { |
164 if (rotation == gfx::Display::ROTATE_0 || | 200 if (rotation == gfx::Display::ROTATE_0 || |
165 rotation == gfx::Display::ROTATE_180) { | 201 rotation == gfx::Display::ROTATE_180) { |
166 controller->SetRotationLocked(true); | 202 SetRotationLocked(true); |
167 } else { | 203 } else { |
168 controller->LockRotation(gfx::Display::ROTATE_0); | 204 LockRotation(gfx::Display::ROTATE_0); |
169 } | 205 } |
170 } else { | 206 } else { |
171 if (rotation == gfx::Display::ROTATE_90 || | 207 if (rotation == gfx::Display::ROTATE_90 || |
172 rotation == gfx::Display::ROTATE_270) { | 208 rotation == gfx::Display::ROTATE_270) { |
173 controller->SetRotationLocked(true); | 209 SetRotationLocked(true); |
174 } else { | 210 } else { |
175 controller->LockRotation(gfx::Display::ROTATE_90); | 211 LockRotation(gfx::Display::ROTATE_90); |
176 } | 212 } |
177 } | 213 } |
178 } | 214 } |
179 | 215 |
180 } // namespace ash | 216 } // namespace ash |
OLD | NEW |