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

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: 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/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 {
16
17 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() {
18 ash::DisplayManager* display_manager =
19 ash::Shell::GetInstance()->display_manager();
20 if (display_manager->HasInternalDisplay()) {
21 ash::DisplayInfo info =
22 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId());
23 gfx::Display::Rotation rotation = info.rotation();
24 gfx::Size size = info.size_in_pixel();
25 if (((rotation == gfx::Display::ROTATE_0 ||
26 rotation == gfx::Display::ROTATE_180) &&
27 size.height() >= size.width()) ||
28 ((rotation == gfx::Display::ROTATE_90 ||
29 rotation == gfx::Display::ROTATE_270) &&
30 size.height() < size.width())) {
31 return blink::WebScreenOrientationLockPortrait;
32 }
33 }
34 return blink::WebScreenOrientationLockLandscape;
35 }
36
37 } // namespace
38
39 namespace ash {
40
41 ScreenOrientationDelegate::ScreenOrientationDelegate()
42 : natural_orientation_(GetDisplayNaturalOrientation()) {
43 content::ScreenOrientationProvider::SetDelegate(this);
44 }
45
46 ScreenOrientationDelegate::~ScreenOrientationDelegate() {
47 content::ScreenOrientationProvider::SetDelegate(NULL);
48 }
49
50 bool ScreenOrientationDelegate::FullScreenRequired(
51 content::WebContents* web_contents) {
52 return true;
53 }
54
55 void ScreenOrientationDelegate::Lock(
56 blink::WebScreenOrientationLockType lock_orientation) {
57 // TODO(jonross): Make ScreenOrientationDelegate responsible for rotation
58 // lock. Have MaximizeModeController, and TrayRotationLock both use it
59 // instead.
60 MaximizeModeController* controller =
61 Shell::GetInstance()->maximize_mode_controller();
62 switch (lock_orientation) {
63 case blink::WebScreenOrientationLockAny:
64 controller->SetRotationLocked(false);
65 break;
66 case blink::WebScreenOrientationLockDefault:
67 NOTREACHED();
68 break;
69 case blink::WebScreenOrientationLockPortraitPrimary:
70 LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait);
71 break;
72 case blink::WebScreenOrientationLockPortrait:
73 LockToRotationMatchingOrientation(lock_orientation);
74 break;
75 case blink::WebScreenOrientationLockPortraitSecondary:
76 LockRotationToSecondaryOrientation(
77 blink::WebScreenOrientationLockPortrait);
78 break;
79 case blink::WebScreenOrientationLockLandscapeSecondary:
80 LockRotationToSecondaryOrientation(
81 blink::WebScreenOrientationLockLandscape);
82 break;
83 case blink::WebScreenOrientationLockLandscapePrimary:
84 LockRotationToPrimaryOrientation(
85 blink::WebScreenOrientationLockLandscape);
86 break;
87 case blink::WebScreenOrientationLockLandscape:
88 LockToRotationMatchingOrientation(lock_orientation);
89 break;
90 case blink::WebScreenOrientationLockNatural:
91 controller->LockRotation(gfx::Display::ROTATE_0);
92 break;
93 default:
94 NOTREACHED();
95 break;
96 }
97 }
98
99 bool ScreenOrientationDelegate::ScreenOrientationProviderSupported() {
100 return Shell::GetInstance()->maximize_mode_controller()->
101 IsMaximizeModeWindowManagerEnabled();
102 }
103
104 void ScreenOrientationDelegate::Unlock() {
105 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(false);
106 }
107
108 void ScreenOrientationDelegate::LockRotationToPrimaryOrientation(
109 blink::WebScreenOrientationLockType lock_orientation) {
110 Shell::GetInstance()->maximize_mode_controller()->
111 LockRotation(natural_orientation_ == lock_orientation ?
112 gfx::Display::ROTATE_0 :
113 gfx::Display::ROTATE_90);
114 }
115
116 void ScreenOrientationDelegate::LockRotationToSecondaryOrientation(
117 blink::WebScreenOrientationLockType lock_orientation) {
118 Shell::GetInstance()->maximize_mode_controller()->
119 LockRotation(natural_orientation_ == lock_orientation ?
120 gfx::Display::ROTATE_180 :
121 gfx::Display::ROTATE_270);
122 }
123
124 void ScreenOrientationDelegate::LockToRotationMatchingOrientation(
125 blink::WebScreenOrientationLockType lock_orientation) {
126 // TODO(jonross): Update MaximizeModeController to allow rotation between
127 // two angles of an orientation (e.g. from ROTATE_0 to ROTATE_180, and from
128 // ROTATE_90 to ROTATE_270)
129 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
130 if (!display_manager->HasInternalDisplay())
131 return;
132
133 gfx::Display::Rotation rotation = display_manager->
134 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation();
135 MaximizeModeController* controller =
136 Shell::GetInstance()->maximize_mode_controller();
137 if (natural_orientation_ == lock_orientation) {
138 if (rotation == gfx::Display::ROTATE_0 ||
139 rotation == gfx::Display::ROTATE_180) {
140 controller->SetRotationLocked(true);
141 } else {
142 controller->LockRotation(gfx::Display::ROTATE_0);
143 }
144 } else {
145 if (rotation == gfx::Display::ROTATE_90 ||
146 rotation == gfx::Display::ROTATE_270) {
147 controller->SetRotationLocked(true);
148 } else {
149 controller->LockRotation(gfx::Display::ROTATE_90);
150 }
151 }
152 }
153
154 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698