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

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: Review #4 and #5 fixes. Thanks @avi. Created 4 years, 10 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
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..71b381caf90c361784d793984fe93a3e50aeec7b
--- /dev/null
+++ b/content/browser/screen_orientation/screen_orientation_delegate_win.cc
@@ -0,0 +1,102 @@
+// 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 content {
+
+ScreenOrientationDelegateWin::ScreenOrientationDelegateWin() {
+ content::ScreenOrientationProvider::SetDelegate(this);
+}
+
+ScreenOrientationDelegateWin::~ScreenOrientationDelegateWin() {
+ content::ScreenOrientationProvider::SetDelegate(nullptr);
+}
+
+bool ScreenOrientationDelegateWin::FullScreenRequired(
+ content::WebContents* web_contents) {
+ return false;
+}
+
+static void GetCurrentDisplaySettings(bool *landscape, bool *flipped) {
+ DEVMODE dm;
+ ZeroMemory(&dm, sizeof(dm));
+ dm.dmSize = sizeof(dm);
+ if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
+ return;
+ if (flipped) {
+ *flipped = (dm.dmDisplayOrientation == DMDO_270
+ || dm.dmDisplayOrientation == DMDO_180);
+ }
+ if (landscape)
+ *landscape = (dm.dmPelsWidth > dm.dmPelsHeight);
+}
+
+void ScreenOrientationDelegateWin::Lock(
+ content::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:
+ GetCurrentDisplaySettings(&landscape, &flipped);
+ prefs = (flipped && !landscape) ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED
+ : ORIENTATION_PREFERENCE_PORTRAIT;
+ break;
+ case blink::WebScreenOrientationLockLandscape:
+ GetCurrentDisplaySettings(&landscape, &flipped);
+ prefs = (flipped && landscape) ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED
+ : ORIENTATION_PREFERENCE_LANDSCAPE;
+ break;
+ case blink::WebScreenOrientationLockNatural:
+ GetCurrentDisplaySettings(&landscape, &flipped);
+ prefs = landscape ? ORIENTATION_PREFERENCE_LANDSCAPE
+ : ORIENTATION_PREFERENCE_PORTRAIT;
+ break;
+ case blink::WebScreenOrientationLockAny:
+ GetCurrentDisplaySettings(&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;
+ }
+ SetDisplayAutoRotationPreferences(prefs);
+}
+
+bool ScreenOrientationDelegateWin::ScreenOrientationProviderSupported() {
+ AR_STATE autoRotationState;
+ ZeroMemory(&autoRotationState, sizeof(AR_STATE));
+ return (GetAutoRotationState(&autoRotationState)
+ && (autoRotationState == AR_ENABLED));
aleksandar.stojiljkovic 2016/03/03 20:34:36 It might be better to change this to: && !(autoRot
+}
+
+void ScreenOrientationDelegateWin::Unlock(
+ content::WebContents* web_contents) {
+ SetDisplayAutoRotationPreferences(ORIENTATION_PREFERENCE_NONE);
+}
+
+} // namespace content
« 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