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

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

Issue 1758823004: Screen.orientation lock API implementation for Windows8 and later. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable API in multi monitor case. Created 4 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
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/public/browser/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 void GetDisplayOrientation(bool* landscape, bool* flipped) {
39 DEVMODE dm;
cpu_(ooo_6.6-7.5) 2016/03/11 02:08:17 dm = {}; zeroes it out nicer.
aleksandar.stojiljkovic 2016/03/11 19:29:26 Done.
40 ZeroMemory(&dm, sizeof(dm));
41 dm.dmSize = sizeof(dm);
42 if (!EnumDisplaySettings(nullptr, ENUM_CURRENT_SETTINGS, &dm))
43 return;
cpu_(ooo_6.6-7.5) 2016/03/11 02:08:16 return false; else how is the caller telling succ
aleksandar.stojiljkovic 2016/03/11 19:29:26 Done. Calling method (ScreenOrientationDelegateWin
44 *flipped = (dm.dmDisplayOrientation == DMDO_270 ||
45 dm.dmDisplayOrientation == DMDO_180);
46 *landscape = (dm.dmPelsWidth > dm.dmPelsHeight);
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 GetDisplayOrientation(&landscape, &flipped);
87 prefs = (flipped && !landscape) ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
88 : ORIENTATION_PREFERENCE_PORTRAIT;
89 break;
90 case blink::WebScreenOrientationLockLandscape:
91 GetDisplayOrientation(&landscape, &flipped);
92 prefs = (flipped && landscape) ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
93 : ORIENTATION_PREFERENCE_LANDSCAPE;
94 break;
95 case blink::WebScreenOrientationLockNatural:
96 GetDisplayOrientation(&landscape, &flipped);
97 prefs = landscape ? ORIENTATION_PREFERENCE_LANDSCAPE
98 : ORIENTATION_PREFERENCE_PORTRAIT;
99 break;
100 case blink::WebScreenOrientationLockAny:
101 GetDisplayOrientation(&landscape, &flipped);
102 if (landscape) {
103 prefs = flipped ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
104 : ORIENTATION_PREFERENCE_LANDSCAPE;
105 } else {
106 prefs = flipped ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
107 : ORIENTATION_PREFERENCE_PORTRAIT;
108 }
109 break;
110 case blink::WebScreenOrientationLockDefault:
111 default:
112 break;
113 }
114 SetDisplayAutoRotationPreferencesWrapper(prefs);
115 }
116
117 bool ScreenOrientationDelegateWin::ScreenOrientationProviderSupported() {
118 AR_STATE auto_rotation_state;
cpu_(ooo_6.6-7.5) 2016/03/11 02:09:36 same here = {}
aleksandar.stojiljkovic 2016/03/11 19:29:26 Done.
119 ZeroMemory(&auto_rotation_state, sizeof(AR_STATE));
120 return (GetAutoRotationStateWrapper(&auto_rotation_state) &&
121 !(auto_rotation_state & AR_NOSENSOR) &&
122 !(auto_rotation_state & AR_NOT_SUPPORTED) &&
123 !(auto_rotation_state & AR_MULTIMON));
124 }
125
126 void ScreenOrientationDelegateWin::Unlock(WebContents* web_contents) {
127 SetDisplayAutoRotationPreferencesWrapper(ORIENTATION_PREFERENCE_NONE);
128 }
129
130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698