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

Side by Side Diff: ash/content/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: 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/content/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 }
42 NOTREACHED();
43 }
44
45 } // namespace
46
47 namespace ash {
48
49 ScreenOrientationDelegate::ScreenOrientationDelegate()
50 : locking_window_(NULL),
51 natural_orientation_(GetDisplayNaturalOrientation()) {
52 content::ScreenOrientationProvider::SetDelegate(this);
53 }
54
55 ScreenOrientationDelegate::~ScreenOrientationDelegate() {
56 content::ScreenOrientationProvider::SetDelegate(NULL);
57 }
58
59 bool ScreenOrientationDelegate::FullScreenRequired(
60 content::WebContents* web_contents) {
61 return true;
62 }
63
64 void ScreenOrientationDelegate::Lock(
65 content::WebContents* web_contents,
66 blink::WebScreenOrientationLockType lock_orientation) {
67 aura::Window* requesting_window = web_contents->GetNativeView();
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
75 // TODO(jonross): Track one rotation lock per window. When the active window
76 // changes apply any corresponding rotation lock.
77 if (!locking_window_)
78 locking_window_ = requesting_window;
79 else if (requesting_window != locking_window_)
80 return;
81
82 switch (lock_orientation) {
83 case blink::WebScreenOrientationLockAny:
84 controller->SetRotationLocked(false);
85 locking_window_ = NULL;
86 break;
87 case blink::WebScreenOrientationLockDefault:
88 NOTREACHED();
89 break;
90 case blink::WebScreenOrientationLockPortraitPrimary:
91 LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait);
92 break;
93 case blink::WebScreenOrientationLockLandscape:
94 case blink::WebScreenOrientationLockPortrait:
95 LockToRotationMatchingOrientation(lock_orientation);
96 break;
97 case blink::WebScreenOrientationLockPortraitSecondary:
98 LockRotationToSecondaryOrientation(
99 blink::WebScreenOrientationLockPortrait);
100 break;
101 case blink::WebScreenOrientationLockLandscapeSecondary:
102 LockRotationToSecondaryOrientation(
103 blink::WebScreenOrientationLockLandscape);
104 break;
105 case blink::WebScreenOrientationLockLandscapePrimary:
106 LockRotationToPrimaryOrientation(
107 blink::WebScreenOrientationLockLandscape);
108 break;
109 case blink::WebScreenOrientationLockNatural:
110 controller->LockRotation(gfx::Display::ROTATE_0);
111 break;
112 default:
113 NOTREACHED();
114 break;
115 }
116 }
117
118 bool ScreenOrientationDelegate::ScreenOrientationProviderSupported() {
119 return Shell::GetInstance()
120 ->maximize_mode_controller()
121 ->IsMaximizeModeWindowManagerEnabled() &&
122 CommandLine::ForCurrentProcess()->HasSwitch(
123 switches::kAshEnableTouchViewTesting);
124 }
125
126 void ScreenOrientationDelegate::Unlock(content::WebContents* web_contents) {
127 aura::Window* requesting_window = web_contents->GetNativeView();
128 if (requesting_window != locking_window_)
129 return;
130 locking_window_ = NULL;
131 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(false);
132 }
133
134 void ScreenOrientationDelegate::LockRotationToPrimaryOrientation(
135 blink::WebScreenOrientationLockType lock_orientation) {
136 Shell::GetInstance()->maximize_mode_controller()->LockRotation(
137 natural_orientation_ == lock_orientation ? gfx::Display::ROTATE_0
138 : gfx::Display::ROTATE_90);
139 }
140
141 void ScreenOrientationDelegate::LockRotationToSecondaryOrientation(
142 blink::WebScreenOrientationLockType lock_orientation) {
143 Shell::GetInstance()->maximize_mode_controller()->LockRotation(
144 natural_orientation_ == lock_orientation ? gfx::Display::ROTATE_180
145 : gfx::Display::ROTATE_270);
146 }
147
148 void ScreenOrientationDelegate::LockToRotationMatchingOrientation(
149 blink::WebScreenOrientationLockType lock_orientation) {
150 // TODO(jonross): Update MaximizeModeController to allow rotation between
151 // two angles of an orientation (e.g. from ROTATE_0 to ROTATE_180, and from
152 // ROTATE_90 to ROTATE_270)
153 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
154 if (!display_manager->HasInternalDisplay())
155 return;
156
157 gfx::Display::Rotation rotation =
158 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId())
159 .rotation();
160 MaximizeModeController* controller =
161 Shell::GetInstance()->maximize_mode_controller();
162 if (natural_orientation_ == lock_orientation) {
163 if (rotation == gfx::Display::ROTATE_0 ||
164 rotation == gfx::Display::ROTATE_180) {
165 controller->SetRotationLocked(true);
166 } else {
167 controller->LockRotation(gfx::Display::ROTATE_0);
168 }
169 } else {
170 if (rotation == gfx::Display::ROTATE_90 ||
171 rotation == gfx::Display::ROTATE_270) {
172 controller->SetRotationLocked(true);
173 } else {
174 controller->LockRotation(gfx::Display::ROTATE_90);
175 }
176 }
177 }
178
179 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698