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..4997b649029669a6dfe003d4f8fe77c05979ae8a |
| --- /dev/null |
| +++ b/content/browser/screen_orientation/screen_orientation_delegate_win.cc |
| @@ -0,0 +1,129 @@ |
| +// 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> |
|
sky
2016/03/04 23:37:36
nit: newline between 7/8.
aleksandar.stojiljkovic
2016/03/06 10:34:15
Done.
|
| +#include "content/public/browser/screen_orientation_provider.h" |
| + |
| +namespace content { |
| + |
| +ScreenOrientationDelegateWin::ScreenOrientationDelegateWin() { |
| + 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.
|
| +} |
| + |
| +ScreenOrientationDelegateWin::~ScreenOrientationDelegateWin() { |
| + content::ScreenOrientationProvider::SetDelegate(nullptr); |
|
mlamouri (slow - plz ping)
2016/03/05 00:39:14
ditto
aleksandar.stojiljkovic
2016/03/06 10:34:15
Done.
|
| +} |
| + |
| +bool ScreenOrientationDelegateWin::FullScreenRequired( |
| + 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.
|
| + return false; |
| +} |
| + |
| +// SetDisplayAutoRotationPreferences is available on Windows 8 and after. |
| +static void SetDisplayAutoRotationPreferencesWrapper( |
| + 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.
|
| + typedef void(WINAPI *SetDisplayAutoRotationPreferencesPtr)( |
| + 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); |
|
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
|
| +} |
| + |
| +// GetAutoRotationState is available on Windows 8 and after. |
| +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.
|
| + typedef BOOL(WINAPI *GetAutoRotationStatePtr)(PAR_STATE); |
|
sky
2016/03/04 23:37:36
typedef->using
aleksandar.stojiljkovic
2016/03/06 10:34:15
Done.
|
| + 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(pState); |
| + return FALSE; |
| +} |
| + |
| +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.
|
| + DEVMODE dm; |
| + ZeroMemory(&dm, sizeof(dm)); |
| + dm.dmSize = sizeof(dm); |
| + 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
|
| + return; |
| + 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.
|
| + *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
|
| + || 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: |
|
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
|
| + 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; |
| + } |
| + SetDisplayAutoRotationPreferencesWrapper(prefs); |
| +} |
| + |
| +bool ScreenOrientationDelegateWin::ScreenOrientationProviderSupported() { |
| + AR_STATE autoRotationState; |
|
sky
2016/03/04 23:37:36
auto_rotation_state
aleksandar.stojiljkovic
2016/03/06 10:34:15
Done.
|
| + ZeroMemory(&autoRotationState, sizeof(AR_STATE)); |
| + return (GetAutoRotationStateWrapper(&autoRotationState) |
| + && !(autoRotationState & AR_NOSENSOR) |
| + && !(autoRotationState & AR_NOT_SUPPORTED)); |
| +} |
| + |
| +void ScreenOrientationDelegateWin::Unlock( |
| + content::WebContents* web_contents) { |
| + SetDisplayAutoRotationPreferencesWrapper(ORIENTATION_PREFERENCE_NONE); |
| +} |
| + |
| +} // namespace content |