Chromium Code Reviews| OLD | NEW |
|---|---|
| (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); | |
|
Avi (use Gerrit)
2016/03/02 19:28:20
Multiple-line if() blocks need {}.
aleksandar.stojiljkovic
2016/03/02 19:47:20
Done.
| |
| 34 if (landscape) | |
| 35 *landscape = (dm.dmPelsWidth > dm.dmPelsHeight); | |
| 36 } | |
| 37 | |
| 38 void ScreenOrientationDelegateWin::Lock( | |
| 39 content::WebContents* web_contents, | |
| 40 blink::WebScreenOrientationLockType lock_orientation) { | |
| 41 ORIENTATION_PREFERENCE prefs = ORIENTATION_PREFERENCE_NONE; | |
| 42 bool landscape = true; | |
| 43 bool flipped = false; | |
| 44 switch (lock_orientation) { | |
| 45 case blink::WebScreenOrientationLockPortraitPrimary: | |
| 46 prefs = ORIENTATION_PREFERENCE_PORTRAIT; | |
| 47 break; | |
| 48 case blink::WebScreenOrientationLockPortraitSecondary: | |
| 49 prefs = ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED; | |
| 50 break; | |
| 51 case blink::WebScreenOrientationLockLandscapePrimary: | |
| 52 prefs = ORIENTATION_PREFERENCE_LANDSCAPE; | |
| 53 break; | |
| 54 case blink::WebScreenOrientationLockLandscapeSecondary: | |
| 55 prefs = ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED; | |
| 56 break; | |
| 57 case blink::WebScreenOrientationLockPortrait: | |
| 58 GetCurrentDisplaySettings(&landscape, &flipped); | |
| 59 prefs = (flipped && !landscape) ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED : | |
| 60 ORIENTATION_PREFERENCE_PORTRAIT; | |
| 61 break; | |
| 62 case blink::WebScreenOrientationLockLandscape: | |
| 63 GetCurrentDisplaySettings(&landscape, &flipped); | |
| 64 prefs = (flipped && landscape) ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED : | |
| 65 ORIENTATION_PREFERENCE_LANDSCAPE; | |
| 66 break; | |
| 67 case blink::WebScreenOrientationLockNatural: | |
| 68 GetCurrentDisplaySettings(&landscape, &flipped); | |
| 69 prefs = landscape ? ORIENTATION_PREFERENCE_LANDSCAPE : | |
| 70 ORIENTATION_PREFERENCE_PORTRAIT; | |
| 71 break; | |
| 72 case blink::WebScreenOrientationLockAny: | |
| 73 GetCurrentDisplaySettings(&landscape, &flipped); | |
| 74 if (landscape) { | |
| 75 prefs = flipped ? ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED : | |
| 76 ORIENTATION_PREFERENCE_LANDSCAPE; | |
| 77 } else { | |
| 78 prefs = flipped ? ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED : | |
| 79 ORIENTATION_PREFERENCE_PORTRAIT; | |
| 80 } | |
| 81 break; | |
| 82 case blink::WebScreenOrientationLockDefault: | |
| 83 default: | |
| 84 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.
| |
| 85 } | |
| 86 SetDisplayAutoRotationPreferences(prefs); | |
| 87 } | |
| 88 | |
| 89 bool ScreenOrientationDelegateWin::ScreenOrientationProviderSupported() { | |
| 90 AR_STATE autoRotationState; | |
| 91 ZeroMemory(&autoRotationState, sizeof(AR_STATE)); | |
| 92 return (GetAutoRotationState(&autoRotationState) | |
| 93 && (autoRotationState == AR_ENABLED)); | |
| 94 } | |
| 95 | |
| 96 void ScreenOrientationDelegateWin::Unlock( | |
| 97 content::WebContents* web_contents) { | |
| 98 SetDisplayAutoRotationPreferences(ORIENTATION_PREFERENCE_NONE); | |
| 99 } | |
| 100 | |
| 101 } // namespace content | |
| OLD | NEW |