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

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

Issue 648733003: Implement ScreenOrientationDelegate on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Shift experimental feature to ash Created 6 years, 1 month 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
(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/display/screen_orientation_delegate_chromeos.h"
6
7 #include "ash/ash_switches.h"
8 #include "ash/display/display_info.h"
9 #include "ash/display/display_manager.h"
10 #include "ash/shell.h"
11 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
12 #include "base/command_line.h"
13 #include "content/public/browser/screen_orientation_provider.h"
14 #include "content/public/browser/web_contents.h"
15 #include "ui/aura/window.h"
16 #include "ui/gfx/display.h"
17 #include "ui/gfx/geometry/size.h"
18
19 namespace {
20
21 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() {
22 ash::DisplayManager* display_manager =
23 ash::Shell::GetInstance()->display_manager();
24 if (!display_manager->HasInternalDisplay())
25 return blink::WebScreenOrientationLockLandscape;
26
27 ash::DisplayInfo info =
28 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId());
29 gfx::Size size = info.size_in_pixel();
30 switch (info.rotation()) {
31 case gfx::Display::ROTATE_0:
32 case gfx::Display::ROTATE_180:
33 return size.height() >= size.width()
34 ? blink::WebScreenOrientationLockPortrait
35 : blink::WebScreenOrientationLockLandscape;
36 case gfx::Display::ROTATE_90:
37 case gfx::Display::ROTATE_270:
38 return size.height() < size.width()
39 ? blink::WebScreenOrientationLockPortrait
40 : blink::WebScreenOrientationLockLandscape;
41 default:
42 NOTREACHED();
mlamouri (slow - plz ping) 2014/11/06 22:56:52 nit: do you need a default here? Wouldn't the comp
jonross 2014/11/07 18:47:38 Done.
43 }
44
45 return blink::WebScreenOrientationLockLandscape;
mlamouri (slow - plz ping) 2014/11/06 22:56:53 nit: NOTREACHED()?
jonross 2014/11/07 18:47:38 Done.
46 }
47
48 } // namespace
49
50 namespace ash {
51
52 ScreenOrientationDelegate::ScreenOrientationDelegate()
53 : locking_window_(NULL),
54 natural_orientation_(GetDisplayNaturalOrientation()) {
55 content::ScreenOrientationProvider::SetDelegate(this);
56 }
57
58 ScreenOrientationDelegate::~ScreenOrientationDelegate() {
59 content::ScreenOrientationProvider::SetDelegate(NULL);
60 }
61
62 bool ScreenOrientationDelegate::FullScreenRequired(
63 content::WebContents* web_contents) {
64 return true;
65 }
66
67 void ScreenOrientationDelegate::Lock(
68 content::WebContents* web_contents,
69 blink::WebScreenOrientationLockType lock_orientation) {
70 aura::Window* requesting_window = web_contents->GetNativeView();
71
72 // TODO(jonross): Make ScreenOrientationDelegate responsible for rotation
73 // lock. Have MaximizeModeController, and TrayRotationLock both use it
74 // instead.
75 MaximizeModeController* controller =
76 Shell::GetInstance()->maximize_mode_controller();
77
78 // TODO(jonross): Track one rotation lock per window. When the active window
79 // changes apply any corresponding rotation lock.
80 if (!locking_window_) {
81 // Exit on user set rotation lock.
mlamouri (slow - plz ping) 2014/11/06 22:56:52 Is that on purpose? It's quite the opposite behavi
jonross 2014/11/07 18:47:38 We had planned this as a part of the temporary loc
82 if (controller->rotation_locked())
83 return;
84 locking_window_ = requesting_window;
85 } else if (requesting_window != locking_window_) {
86 return;
87 }
88
89 switch (lock_orientation) {
90 case blink::WebScreenOrientationLockAny:
91 controller->SetRotationLocked(false);
92 locking_window_ = NULL;
93 break;
94 case blink::WebScreenOrientationLockDefault:
95 NOTREACHED();
96 break;
97 case blink::WebScreenOrientationLockPortraitPrimary:
98 LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait);
99 break;
100 case blink::WebScreenOrientationLockLandscape:
101 case blink::WebScreenOrientationLockPortrait:
102 LockToRotationMatchingOrientation(lock_orientation);
103 break;
104 case blink::WebScreenOrientationLockPortraitSecondary:
105 LockRotationToSecondaryOrientation(
106 blink::WebScreenOrientationLockPortrait);
107 break;
108 case blink::WebScreenOrientationLockLandscapeSecondary:
109 LockRotationToSecondaryOrientation(
110 blink::WebScreenOrientationLockLandscape);
111 break;
112 case blink::WebScreenOrientationLockLandscapePrimary:
113 LockRotationToPrimaryOrientation(
114 blink::WebScreenOrientationLockLandscape);
115 break;
116 case blink::WebScreenOrientationLockNatural:
117 controller->LockRotation(gfx::Display::ROTATE_0);
118 break;
119 default:
120 NOTREACHED();
121 break;
122 }
123 }
124
125 bool ScreenOrientationDelegate::ScreenOrientationProviderSupported() {
126 return Shell::GetInstance()
127 ->maximize_mode_controller()
128 ->IsMaximizeModeWindowManagerEnabled() &&
129 CommandLine::ForCurrentProcess()->HasSwitch(
130 switches::kAshEnableTouchViewTesting);
131 }
132
133 void ScreenOrientationDelegate::Unlock(content::WebContents* web_contents) {
134 aura::Window* requesting_window = web_contents->GetNativeView();
135 if (requesting_window != locking_window_)
136 return;
137 locking_window_ = NULL;
138 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(false);
139 }
140
141 void ScreenOrientationDelegate::LockRotationToPrimaryOrientation(
142 blink::WebScreenOrientationLockType lock_orientation) {
143 Shell::GetInstance()->maximize_mode_controller()->LockRotation(
144 natural_orientation_ == lock_orientation ? gfx::Display::ROTATE_0
145 : gfx::Display::ROTATE_90);
146 }
147
148 void ScreenOrientationDelegate::LockRotationToSecondaryOrientation(
149 blink::WebScreenOrientationLockType lock_orientation) {
150 Shell::GetInstance()->maximize_mode_controller()->LockRotation(
151 natural_orientation_ == lock_orientation ? gfx::Display::ROTATE_180
152 : gfx::Display::ROTATE_270);
153 }
154
155 void ScreenOrientationDelegate::LockToRotationMatchingOrientation(
156 blink::WebScreenOrientationLockType lock_orientation) {
157 // TODO(jonross): Update MaximizeModeController to allow rotation between
158 // two angles of an orientation (e.g. from ROTATE_0 to ROTATE_180, and from
159 // ROTATE_90 to ROTATE_270)
160 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
161 if (!display_manager->HasInternalDisplay())
162 return;
163
164 gfx::Display::Rotation rotation =
165 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId())
166 .rotation();
167 MaximizeModeController* controller =
168 Shell::GetInstance()->maximize_mode_controller();
169 if (natural_orientation_ == lock_orientation) {
170 if (rotation == gfx::Display::ROTATE_0 ||
171 rotation == gfx::Display::ROTATE_180) {
172 controller->SetRotationLocked(true);
173 } else {
174 controller->LockRotation(gfx::Display::ROTATE_0);
175 }
176 } else {
177 if (rotation == gfx::Display::ROTATE_90 ||
178 rotation == gfx::Display::ROTATE_270) {
179 controller->SetRotationLocked(true);
180 } else {
181 controller->LockRotation(gfx::Display::ROTATE_90);
182 }
183 }
184 }
185
186 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/screen_orientation_delegate_chromeos.h ('k') | ash/display/screen_orientation_delegate_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698