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

Side by Side Diff: content/browser/screen_orientation/screen_orientation_delegate_win.cc

Issue 2761213003: Revert of Screen.orientation lock API implementation for Windows8 and later. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add 702435 to commit message Created 3 years, 9 months 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 | « content/browser/screen_orientation/screen_orientation_delegate_win.h ('k') | no next file » | 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 2016 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 "content/browser/screen_orientation/screen_orientation_delegate_win.h"
6
7 #include <windows.h>
8
9 #include "content/browser/screen_orientation/screen_orientation_provider.h"
10
11 namespace {
12
13 // SetDisplayAutoRotationPreferences is available on Windows 8 and after.
14 void SetDisplayAutoRotationPreferencesWrapper(
15 ORIENTATION_PREFERENCE orientation) {
16 using SetDisplayAutoRotationPreferencesPtr =
17 void(WINAPI*)(ORIENTATION_PREFERENCE);
18 static SetDisplayAutoRotationPreferencesPtr
19 set_display_auto_rotation_preferences_func =
20 reinterpret_cast<SetDisplayAutoRotationPreferencesPtr>(
21 GetProcAddress(GetModuleHandleA("user32.dll"),
22 "SetDisplayAutoRotationPreferences"));
23 if (set_display_auto_rotation_preferences_func)
24 set_display_auto_rotation_preferences_func(orientation);
25 }
26
27 // GetAutoRotationState is available on Windows 8 and after.
28 BOOL GetAutoRotationStateWrapper(PAR_STATE state) {
29 using GetAutoRotationStatePtr = BOOL(WINAPI*)(PAR_STATE);
30 static GetAutoRotationStatePtr get_auto_rotation_state_func =
31 reinterpret_cast<GetAutoRotationStatePtr>(GetProcAddress(
32 GetModuleHandleA("user32.dll"), "GetAutoRotationState"));
33 if (get_auto_rotation_state_func)
34 return get_auto_rotation_state_func(state);
35 return FALSE;
36 }
37
38 bool GetDisplayOrientation(bool* landscape, bool* flipped) {
39 DEVMODE dm = {};
40 dm.dmSize = sizeof(dm);
41 if (!EnumDisplaySettings(nullptr, ENUM_CURRENT_SETTINGS, &dm))
42 return false;
43 *flipped = (dm.dmDisplayOrientation == DMDO_270 ||
44 dm.dmDisplayOrientation == DMDO_180);
45 *landscape = (dm.dmPelsWidth > dm.dmPelsHeight);
46 return true;
47 }
48
49 } // namespace
50
51 namespace content {
52
53 ScreenOrientationDelegateWin::ScreenOrientationDelegateWin() {
54 ScreenOrientationProvider::SetDelegate(this);
55 }
56
57 ScreenOrientationDelegateWin::~ScreenOrientationDelegateWin() {
58 ScreenOrientationProvider::SetDelegate(nullptr);
59 }
60
61 bool ScreenOrientationDelegateWin::FullScreenRequired(
62 WebContents* web_contents) {
63 return false;
64 }
65
66 void ScreenOrientationDelegateWin::Lock(
67 WebContents* web_contents,
68 blink::WebScreenOrientationLockType lock_orientation) {
69 ORIENTATION_PREFERENCE prefs = ORIENTATION_PREFERENCE_NONE;
70 bool landscape = true;
71 bool flipped = false;
72 switch (lock_orientation) {
73 case blink::WebScreenOrientationLockPortraitPrimary:
74 prefs = ORIENTATION_PREFERENCE_PORTRAIT;
75 break;
76 case blink::WebScreenOrientationLockPortraitSecondary:
77 prefs = ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED;
78 break;
79 case blink::WebScreenOrientationLockLandscapePrimary:
80 prefs = ORIENTATION_PREFERENCE_LANDSCAPE;
81 break;
82 case blink::WebScreenOrientationLockLandscapeSecondary:
83 prefs = ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED;
84 break;
85 case blink::WebScreenOrientationLockPortrait:
86 if (!GetDisplayOrientation(&landscape, &flipped))
87 return;
88 prefs = (flipped && !landscape) ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
89 : ORIENTATION_PREFERENCE_PORTRAIT;
90 break;
91 case blink::WebScreenOrientationLockLandscape:
92 if (!GetDisplayOrientation(&landscape, &flipped))
93 return;
94 prefs = (flipped && landscape) ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
95 : ORIENTATION_PREFERENCE_LANDSCAPE;
96 break;
97 case blink::WebScreenOrientationLockNatural:
98 if (!GetDisplayOrientation(&landscape, &flipped))
99 return;
100 prefs = landscape ? ORIENTATION_PREFERENCE_LANDSCAPE
101 : ORIENTATION_PREFERENCE_PORTRAIT;
102 break;
103 case blink::WebScreenOrientationLockAny:
104 if (!GetDisplayOrientation(&landscape, &flipped))
105 return;
106 if (landscape) {
107 prefs = flipped ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
108 : ORIENTATION_PREFERENCE_LANDSCAPE;
109 } else {
110 prefs = flipped ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
111 : ORIENTATION_PREFERENCE_PORTRAIT;
112 }
113 break;
114 case blink::WebScreenOrientationLockDefault:
115 default:
116 break;
117 }
118 SetDisplayAutoRotationPreferencesWrapper(prefs);
119 }
120
121 bool ScreenOrientationDelegateWin::ScreenOrientationProviderSupported() {
122 AR_STATE auto_rotation_state = {};
123 return (GetAutoRotationStateWrapper(&auto_rotation_state) &&
124 !(auto_rotation_state & AR_NOSENSOR) &&
125 !(auto_rotation_state & AR_NOT_SUPPORTED) &&
126 !(auto_rotation_state & AR_MULTIMON));
127 }
128
129 void ScreenOrientationDelegateWin::Unlock(WebContents* web_contents) {
130 SetDisplayAutoRotationPreferencesWrapper(ORIENTATION_PREFERENCE_NONE);
131 }
132
133 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/screen_orientation/screen_orientation_delegate_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698