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

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: Restrict Rotation Locking to a single window 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
« no previous file with comments | « ash/display/screen_orientation_delegate_chromeos.h ('k') | ash/shell.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 "content/public/browser/web_contents.h"
13 #include "ui/aura/window.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/geometry/size.h"
16
17 namespace {
18
19 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() {
20 ash::DisplayManager* display_manager =
21 ash::Shell::GetInstance()->display_manager();
22 if (display_manager->HasInternalDisplay()) {
23 ash::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) &&
29 size.height() >= size.width()) ||
30 ((rotation == gfx::Display::ROTATE_90 ||
31 rotation == gfx::Display::ROTATE_270) &&
32 size.height() < size.width())) {
33 return blink::WebScreenOrientationLockPortrait;
34 }
35 }
36 return blink::WebScreenOrientationLockLandscape;
37 }
38
39 } // namespace
40
41 namespace ash {
42
43 ScreenOrientationDelegate::ScreenOrientationDelegate()
44 : locking_window_(NULL),
45 natural_orientation_(GetDisplayNaturalOrientation()) {
46 content::ScreenOrientationProvider::SetDelegate(this);
47 }
48
49 ScreenOrientationDelegate::~ScreenOrientationDelegate() {
50 content::ScreenOrientationProvider::SetDelegate(NULL);
51 }
52
53 bool ScreenOrientationDelegate::FullScreenRequired(
54 content::WebContents* web_contents) {
55 return true;
56 }
57
58 bool ScreenOrientationDelegate::Lock(content::WebContents* web_contents,
59 blink::WebScreenOrientationLockType lock_orientation) {
60 aura::Window* requesting_window = web_contents->GetNativeView();
61
62 // TODO(jonross): Track one rotation lock per window. When the active window
63 // changes apply any corresponding rotation lock.
64 if (!locking_window_)
65 locking_window_ = requesting_window;
66 else if (requesting_window != locking_window_)
67 return false;
flackr 2014/10/29 16:50:47 Until we get the more complex model using, since t
jonross 2014/10/29 18:34:02 Slightly different check added to exit. Will exit
flackr 2014/10/29 18:52:48 Looks like it effectively evaluates to the same.
68
69 // TODO(jonross): Make ScreenOrientationDelegate responsible for rotation
70 // lock. Have MaximizeModeController, and TrayRotationLock both use it
71 // instead.
72 MaximizeModeController* controller =
73 Shell::GetInstance()->maximize_mode_controller();
74 switch (lock_orientation) {
75 case blink::WebScreenOrientationLockAny:
76 controller->SetRotationLocked(false);
77 locking_window_ = NULL;
78 break;
79 case blink::WebScreenOrientationLockDefault:
80 NOTREACHED();
81 break;
82 case blink::WebScreenOrientationLockPortraitPrimary:
83 LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait);
84 break;
85 case blink::WebScreenOrientationLockPortrait:
86 LockToRotationMatchingOrientation(lock_orientation);
87 break;
88 case blink::WebScreenOrientationLockPortraitSecondary:
89 LockRotationToSecondaryOrientation(
90 blink::WebScreenOrientationLockPortrait);
91 break;
92 case blink::WebScreenOrientationLockLandscapeSecondary:
93 LockRotationToSecondaryOrientation(
94 blink::WebScreenOrientationLockLandscape);
95 break;
96 case blink::WebScreenOrientationLockLandscapePrimary:
97 LockRotationToPrimaryOrientation(
98 blink::WebScreenOrientationLockLandscape);
99 break;
100 case blink::WebScreenOrientationLockLandscape:
101 LockToRotationMatchingOrientation(lock_orientation);
102 break;
103 case blink::WebScreenOrientationLockNatural:
104 controller->LockRotation(gfx::Display::ROTATE_0);
105 break;
106 default:
107 NOTREACHED();
108 break;
109 }
110 return true;
111 }
112
113 bool ScreenOrientationDelegate::ScreenOrientationProviderSupported() {
114 return Shell::GetInstance()->maximize_mode_controller()->
115 IsMaximizeModeWindowManagerEnabled();
116 }
117
118 void ScreenOrientationDelegate::Unlock(content::WebContents* web_contents) {
119 aura::Window* requesting_window = web_contents->GetNativeView();
120 if (requesting_window != locking_window_)
121 return;
122 locking_window_ = NULL;
123 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(false);
124 }
125
126 void ScreenOrientationDelegate::LockRotationToPrimaryOrientation(
127 blink::WebScreenOrientationLockType lock_orientation) {
128 Shell::GetInstance()->maximize_mode_controller()->
129 LockRotation(natural_orientation_ == lock_orientation ?
130 gfx::Display::ROTATE_0 :
131 gfx::Display::ROTATE_90);
132 }
133
134 void ScreenOrientationDelegate::LockRotationToSecondaryOrientation(
135 blink::WebScreenOrientationLockType lock_orientation) {
136 Shell::GetInstance()->maximize_mode_controller()->
137 LockRotation(natural_orientation_ == lock_orientation ?
138 gfx::Display::ROTATE_180 :
139 gfx::Display::ROTATE_270);
140 }
141
142 void ScreenOrientationDelegate::LockToRotationMatchingOrientation(
143 blink::WebScreenOrientationLockType lock_orientation) {
144 // TODO(jonross): Update MaximizeModeController to allow rotation between
145 // two angles of an orientation (e.g. from ROTATE_0 to ROTATE_180, and from
146 // ROTATE_90 to ROTATE_270)
147 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
148 if (!display_manager->HasInternalDisplay())
149 return;
150
151 gfx::Display::Rotation rotation = display_manager->
152 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
153 MaximizeModeController* controller =
154 Shell::GetInstance()->maximize_mode_controller();
155 if (natural_orientation_ == lock_orientation) {
156 if (rotation == gfx::Display::ROTATE_0 ||
157 rotation == gfx::Display::ROTATE_180) {
158 controller->SetRotationLocked(true);
159 } else {
160 controller->LockRotation(gfx::Display::ROTATE_0);
161 }
162 } else {
163 if (rotation == gfx::Display::ROTATE_90 ||
164 rotation == gfx::Display::ROTATE_270) {
165 controller->SetRotationLocked(true);
166 } else {
167 controller->LockRotation(gfx::Display::ROTATE_90);
168 }
169 }
170 }
171
172 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/screen_orientation_delegate_chromeos.h ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698