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

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: Runtime resolving of GetAutoRotationState and SetDisplayAutoRotationPreferences - not available in Windows7 user32.dll 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>
sky 2016/03/04 23:37:36 nit: newline between 7/8.
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
8 #include "content/public/browser/screen_orientation_provider.h"
9
10 namespace content {
11
12 ScreenOrientationDelegateWin::ScreenOrientationDelegateWin() {
13 content::ScreenOrientationProvider::SetDelegate(this);
mlamouri (slow - plz ping) 2016/03/05 00:39:14 nit: no need for "content::"
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
14 }
15
16 ScreenOrientationDelegateWin::~ScreenOrientationDelegateWin() {
17 content::ScreenOrientationProvider::SetDelegate(nullptr);
mlamouri (slow - plz ping) 2016/03/05 00:39:14 ditto
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
18 }
19
20 bool ScreenOrientationDelegateWin::FullScreenRequired(
21 content::WebContents* web_contents) {
mlamouri (slow - plz ping) 2016/03/05 00:39:14 ditto (and probably some more below this)
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
22 return false;
23 }
24
25 // SetDisplayAutoRotationPreferences is available on Windows 8 and after.
26 static void SetDisplayAutoRotationPreferencesWrapper(
27 ORIENTATION_PREFERENCE orientation) {
sky 2016/03/04 23:37:35 nit: run git cl format as your formatting is off h
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
28 typedef void(WINAPI *SetDisplayAutoRotationPreferencesPtr)(
29 ORIENTATION_PREFERENCE);
30 static SetDisplayAutoRotationPreferencesPtr
31 set_display_auto_rotation_preferences_func =
32 reinterpret_cast<SetDisplayAutoRotationPreferencesPtr>(
33 GetProcAddress(GetModuleHandleA("user32.dll"),
34 "SetDisplayAutoRotationPreferences"));
35 if (set_display_auto_rotation_preferences_func)
36 set_display_auto_rotation_preferences_func(orientation);
sky 2016/03/04 23:37:36 How come the docs for this say it takes a pointer?
aleksandar.stojiljkovic 2016/03/06 10:34:15 Documentation is wrong there. A place where is it
37 }
38
39 // GetAutoRotationState is available on Windows 8 and after.
40 static BOOL GetAutoRotationStateWrapper(PAR_STATE pState) {
sky 2016/03/04 23:37:36 p_state
sky 2016/03/04 23:37:36 Is there a reason to use windows types here rather
aleksandar.stojiljkovic 2016/03/06 10:34:15 As it is a wrapper, wanted to keep the same signat
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
41 typedef BOOL(WINAPI *GetAutoRotationStatePtr)(PAR_STATE);
sky 2016/03/04 23:37:36 typedef->using
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
42 static GetAutoRotationStatePtr get_auto_rotation_state_func =
43 reinterpret_cast<GetAutoRotationStatePtr>(
44 GetProcAddress(GetModuleHandleA("user32.dll"),
45 "GetAutoRotationState"));
46 if (get_auto_rotation_state_func)
47 return get_auto_rotation_state_func(pState);
48 return FALSE;
49 }
50
51 static void GetCurrentDisplaySettings(bool *landscape, bool *flipped) {
sky 2016/03/04 23:37:36 Generally we put functions like this in an anonymo
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
52 DEVMODE dm;
53 ZeroMemory(&dm, sizeof(dm));
54 dm.dmSize = sizeof(dm);
55 if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
sky 2016/03/04 23:37:36 Why do you use current and not the display the Web
sky 2016/03/04 23:37:36 nullptr
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
aleksandar.stojiljkovic 2016/03/06 10:34:15 I have renamed the method GetCurrentDisplaySetting
sky 2016/03/07 16:20:30 Again, why wouldn't you want to use the monitor th
56 return;
57 if (flipped) {
sky 2016/03/04 23:37:36 You always pass in non-null, so why check the vari
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
58 *flipped = (dm.dmDisplayOrientation == DMDO_270
sky 2016/03/04 23:37:36 Why not 90?
mlamouri (slow - plz ping) 2016/03/05 00:39:14 90 is "landscape-primary" and 270 "landscape-secon
59 || dm.dmDisplayOrientation == DMDO_180);
60 }
61 if (landscape)
62 *landscape = (dm.dmPelsWidth > dm.dmPelsHeight);
63 }
64
65 void ScreenOrientationDelegateWin::Lock(
66 content::WebContents* web_contents,
67 blink::WebScreenOrientationLockType lock_orientation) {
68 ORIENTATION_PREFERENCE prefs = ORIENTATION_PREFERENCE_NONE;
69 bool landscape = true;
70 bool flipped = false;
71 switch (lock_orientation) {
72 case blink::WebScreenOrientationLockPortraitPrimary:
73 prefs = ORIENTATION_PREFERENCE_PORTRAIT;
74 break;
75 case blink::WebScreenOrientationLockPortraitSecondary:
76 prefs = ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED;
77 break;
78 case blink::WebScreenOrientationLockLandscapePrimary:
79 prefs = ORIENTATION_PREFERENCE_LANDSCAPE;
80 break;
81 case blink::WebScreenOrientationLockLandscapeSecondary:
sky 2016/03/04 23:37:36 What do primary and secondary mean in this context
aleksandar.stojiljkovic 2016/03/06 10:34:15 Got the information from spec [1] and copied the l
82 prefs = ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED;
83 break;
84 case blink::WebScreenOrientationLockPortrait:
85 GetCurrentDisplaySettings(&landscape, &flipped);
86 prefs = (flipped && !landscape) ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
87 : ORIENTATION_PREFERENCE_PORTRAIT;
88 break;
89 case blink::WebScreenOrientationLockLandscape:
90 GetCurrentDisplaySettings(&landscape, &flipped);
91 prefs = (flipped && landscape) ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
92 : ORIENTATION_PREFERENCE_LANDSCAPE;
93 break;
94 case blink::WebScreenOrientationLockNatural:
95 GetCurrentDisplaySettings(&landscape, &flipped);
96 prefs = landscape ? ORIENTATION_PREFERENCE_LANDSCAPE
97 : ORIENTATION_PREFERENCE_PORTRAIT;
98 break;
99 case blink::WebScreenOrientationLockAny:
100 GetCurrentDisplaySettings(&landscape, &flipped);
101 if (landscape) {
102 prefs = flipped ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
103 : ORIENTATION_PREFERENCE_LANDSCAPE;
104 } else {
105 prefs = flipped ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
106 : ORIENTATION_PREFERENCE_PORTRAIT;
107 }
108 break;
109 case blink::WebScreenOrientationLockDefault:
110 default:
111 break;
112 }
113 SetDisplayAutoRotationPreferencesWrapper(prefs);
114 }
115
116 bool ScreenOrientationDelegateWin::ScreenOrientationProviderSupported() {
117 AR_STATE autoRotationState;
sky 2016/03/04 23:37:36 auto_rotation_state
aleksandar.stojiljkovic 2016/03/06 10:34:15 Done.
118 ZeroMemory(&autoRotationState, sizeof(AR_STATE));
119 return (GetAutoRotationStateWrapper(&autoRotationState)
120 && !(autoRotationState & AR_NOSENSOR)
121 && !(autoRotationState & AR_NOT_SUPPORTED));
122 }
123
124 void ScreenOrientationDelegateWin::Unlock(
125 content::WebContents* web_contents) {
126 SetDisplayAutoRotationPreferencesWrapper(ORIENTATION_PREFERENCE_NONE);
127 }
128
129 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/screen_orientation/screen_orientation_delegate_win.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698