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

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: Review #4 and #5 fixes. Thanks @avi. 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 #include "content/public/browser/screen_orientation_provider.h"
9
10 namespace content {
11
12 ScreenOrientationDelegateWin::ScreenOrientationDelegateWin() {
13 content::ScreenOrientationProvider::SetDelegate(this);
14 }
15
16 ScreenOrientationDelegateWin::~ScreenOrientationDelegateWin() {
17 content::ScreenOrientationProvider::SetDelegate(nullptr);
18 }
19
20 bool ScreenOrientationDelegateWin::FullScreenRequired(
21 content::WebContents* web_contents) {
22 return false;
23 }
24
25 static void GetCurrentDisplaySettings(bool *landscape, bool *flipped) {
26 DEVMODE dm;
27 ZeroMemory(&dm, sizeof(dm));
28 dm.dmSize = sizeof(dm);
29 if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
30 return;
31 if (flipped) {
32 *flipped = (dm.dmDisplayOrientation == DMDO_270
33 || dm.dmDisplayOrientation == DMDO_180);
34 }
35 if (landscape)
36 *landscape = (dm.dmPelsWidth > dm.dmPelsHeight);
37 }
38
39 void ScreenOrientationDelegateWin::Lock(
40 content::WebContents* web_contents,
41 blink::WebScreenOrientationLockType lock_orientation) {
42 ORIENTATION_PREFERENCE prefs = ORIENTATION_PREFERENCE_NONE;
43 bool landscape = true;
44 bool flipped = false;
45 switch (lock_orientation) {
46 case blink::WebScreenOrientationLockPortraitPrimary:
47 prefs = ORIENTATION_PREFERENCE_PORTRAIT;
48 break;
49 case blink::WebScreenOrientationLockPortraitSecondary:
50 prefs = ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED;
51 break;
52 case blink::WebScreenOrientationLockLandscapePrimary:
53 prefs = ORIENTATION_PREFERENCE_LANDSCAPE;
54 break;
55 case blink::WebScreenOrientationLockLandscapeSecondary:
56 prefs = ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED;
57 break;
58 case blink::WebScreenOrientationLockPortrait:
59 GetCurrentDisplaySettings(&landscape, &flipped);
60 prefs = (flipped && !landscape) ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
61 : ORIENTATION_PREFERENCE_PORTRAIT;
62 break;
63 case blink::WebScreenOrientationLockLandscape:
64 GetCurrentDisplaySettings(&landscape, &flipped);
65 prefs = (flipped && landscape) ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
66 : ORIENTATION_PREFERENCE_LANDSCAPE;
67 break;
68 case blink::WebScreenOrientationLockNatural:
69 GetCurrentDisplaySettings(&landscape, &flipped);
70 prefs = landscape ? ORIENTATION_PREFERENCE_LANDSCAPE
71 : ORIENTATION_PREFERENCE_PORTRAIT;
72 break;
73 case blink::WebScreenOrientationLockAny:
74 GetCurrentDisplaySettings(&landscape, &flipped);
75 if (landscape) {
76 prefs = flipped ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
77 : ORIENTATION_PREFERENCE_LANDSCAPE;
78 } else {
79 prefs = flipped ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
80 : ORIENTATION_PREFERENCE_PORTRAIT;
81 }
82 break;
83 case blink::WebScreenOrientationLockDefault:
84 default:
85 break;
86 }
87 SetDisplayAutoRotationPreferences(prefs);
88 }
89
90 bool ScreenOrientationDelegateWin::ScreenOrientationProviderSupported() {
91 AR_STATE autoRotationState;
92 ZeroMemory(&autoRotationState, sizeof(AR_STATE));
93 return (GetAutoRotationState(&autoRotationState)
94 && (autoRotationState == AR_ENABLED));
aleksandar.stojiljkovic 2016/03/03 20:34:36 It might be better to change this to: && !(autoRot
95 }
96
97 void ScreenOrientationDelegateWin::Unlock(
98 content::WebContents* web_contents) {
99 SetDisplayAutoRotationPreferences(ORIENTATION_PREFERENCE_NONE);
100 }
101
102 } // 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