Chromium Code Reviews| 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..7b47f715451c71cbebd0864bfc72ee729c0eacac |
| --- /dev/null |
| +++ b/content/browser/screen_orientation/screen_orientation_delegate_win.cc |
| @@ -0,0 +1,101 @@ |
| +// 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); |
|
Avi (use Gerrit)
2016/03/02 19:28:20
Multiple-line if() blocks need {}.
aleksandar.stojiljkovic
2016/03/02 19:47:20
Done.
|
| + 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; |
|
Avi (use Gerrit)
2016/03/02 19:28:20
Switch statements need indenting.
https://google.
aleksandar.stojiljkovic
2016/03/02 19:47:20
Done.
|
| + } |
| + SetDisplayAutoRotationPreferences(prefs); |
| +} |
| + |
| +bool ScreenOrientationDelegateWin::ScreenOrientationProviderSupported() { |
| + AR_STATE autoRotationState; |
| + ZeroMemory(&autoRotationState, sizeof(AR_STATE)); |
| + return (GetAutoRotationState(&autoRotationState) |
| + && (autoRotationState == AR_ENABLED)); |
| +} |
| + |
| +void ScreenOrientationDelegateWin::Unlock( |
| + content::WebContents* web_contents) { |
| + SetDisplayAutoRotationPreferences(ORIENTATION_PREFERENCE_NONE); |
| +} |
| + |
| +} // namespace content |