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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/screen_orientation/screen_orientation_delegate_win.cc
diff --git a/content/browser/screen_orientation/screen_orientation_delegate_win.cc b/content/browser/screen_orientation/screen_orientation_delegate_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c8b3cc59cfce9f73e6e9129d6af4a70264f7ed68
--- /dev/null
+++ b/content/browser/screen_orientation/screen_orientation_delegate_win.cc
@@ -0,0 +1,130 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/screen_orientation/screen_orientation_delegate_win.h"
+
+#include <windows.h>
+
+#include "content/public/browser/screen_orientation_provider.h"
+
+namespace {
+
+// SetDisplayAutoRotationPreferences is available on Windows 8 and after.
+void SetDisplayAutoRotationPreferencesWrapper(
+ ORIENTATION_PREFERENCE orientation) {
+ using SetDisplayAutoRotationPreferencesPtr =
+ void(WINAPI*)(ORIENTATION_PREFERENCE);
+ static SetDisplayAutoRotationPreferencesPtr
+ set_display_auto_rotation_preferences_func =
+ reinterpret_cast<SetDisplayAutoRotationPreferencesPtr>(
+ GetProcAddress(GetModuleHandleA("user32.dll"),
+ "SetDisplayAutoRotationPreferences"));
+ if (set_display_auto_rotation_preferences_func)
+ set_display_auto_rotation_preferences_func(orientation);
+}
+
+// GetAutoRotationState is available on Windows 8 and after.
+BOOL GetAutoRotationStateWrapper(PAR_STATE state) {
+ using GetAutoRotationStatePtr = BOOL(WINAPI*)(PAR_STATE);
+ static GetAutoRotationStatePtr get_auto_rotation_state_func =
+ reinterpret_cast<GetAutoRotationStatePtr>(GetProcAddress(
+ GetModuleHandleA("user32.dll"), "GetAutoRotationState"));
+ if (get_auto_rotation_state_func)
+ return get_auto_rotation_state_func(state);
+ return FALSE;
+}
+
+void GetDisplayOrientation(bool* landscape, bool* flipped) {
+ 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.
+ ZeroMemory(&dm, sizeof(dm));
+ dm.dmSize = sizeof(dm);
+ if (!EnumDisplaySettings(nullptr, ENUM_CURRENT_SETTINGS, &dm))
+ 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
+ *flipped = (dm.dmDisplayOrientation == DMDO_270 ||
+ dm.dmDisplayOrientation == DMDO_180);
+ *landscape = (dm.dmPelsWidth > dm.dmPelsHeight);
+}
+
+} // namespace
+
+namespace content {
+
+ScreenOrientationDelegateWin::ScreenOrientationDelegateWin() {
+ ScreenOrientationProvider::SetDelegate(this);
+}
+
+ScreenOrientationDelegateWin::~ScreenOrientationDelegateWin() {
+ ScreenOrientationProvider::SetDelegate(nullptr);
+}
+
+bool ScreenOrientationDelegateWin::FullScreenRequired(
+ WebContents* web_contents) {
+ return false;
+}
+
+void ScreenOrientationDelegateWin::Lock(
+ WebContents* web_contents,
+ blink::WebScreenOrientationLockType lock_orientation) {
+ ORIENTATION_PREFERENCE prefs = ORIENTATION_PREFERENCE_NONE;
+ bool landscape = true;
+ bool flipped = false;
+ switch (lock_orientation) {
+ case blink::WebScreenOrientationLockPortraitPrimary:
+ prefs = ORIENTATION_PREFERENCE_PORTRAIT;
+ break;
+ case blink::WebScreenOrientationLockPortraitSecondary:
+ prefs = ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED;
+ break;
+ case blink::WebScreenOrientationLockLandscapePrimary:
+ prefs = ORIENTATION_PREFERENCE_LANDSCAPE;
+ break;
+ case blink::WebScreenOrientationLockLandscapeSecondary:
+ prefs = ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED;
+ break;
+ case blink::WebScreenOrientationLockPortrait:
+ GetDisplayOrientation(&landscape, &flipped);
+ prefs = (flipped && !landscape) ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
+ : ORIENTATION_PREFERENCE_PORTRAIT;
+ break;
+ case blink::WebScreenOrientationLockLandscape:
+ GetDisplayOrientation(&landscape, &flipped);
+ prefs = (flipped && landscape) ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
+ : ORIENTATION_PREFERENCE_LANDSCAPE;
+ break;
+ case blink::WebScreenOrientationLockNatural:
+ GetDisplayOrientation(&landscape, &flipped);
+ prefs = landscape ? ORIENTATION_PREFERENCE_LANDSCAPE
+ : ORIENTATION_PREFERENCE_PORTRAIT;
+ break;
+ case blink::WebScreenOrientationLockAny:
+ GetDisplayOrientation(&landscape, &flipped);
+ if (landscape) {
+ prefs = flipped ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
+ : ORIENTATION_PREFERENCE_LANDSCAPE;
+ } else {
+ prefs = flipped ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
+ : ORIENTATION_PREFERENCE_PORTRAIT;
+ }
+ break;
+ case blink::WebScreenOrientationLockDefault:
+ default:
+ break;
+ }
+ SetDisplayAutoRotationPreferencesWrapper(prefs);
+}
+
+bool ScreenOrientationDelegateWin::ScreenOrientationProviderSupported() {
+ 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.
+ ZeroMemory(&auto_rotation_state, sizeof(AR_STATE));
+ return (GetAutoRotationStateWrapper(&auto_rotation_state) &&
+ !(auto_rotation_state & AR_NOSENSOR) &&
+ !(auto_rotation_state & AR_NOT_SUPPORTED) &&
+ !(auto_rotation_state & AR_MULTIMON));
+}
+
+void ScreenOrientationDelegateWin::Unlock(WebContents* web_contents) {
+ SetDisplayAutoRotationPreferencesWrapper(ORIENTATION_PREFERENCE_NONE);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698