ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 1 | // Copyright 2015 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 "ash/content/screen_orientation_delegate_chromeos.h" |
| 6 | |
Mitsuru Oshima | ddfde355 | 2018-03-22 09:12:13 | [diff] [blame] | 7 | #include "ash/display/screen_orientation_controller.h" |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 8 | #include "ash/shell.h" |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 9 | #include "content/public/browser/web_contents.h" |
| 10 | |
| 11 | namespace ash { |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 12 | namespace { |
| 13 | |
| 14 | OrientationLockType ToAshOrientationLockType( |
| 15 | blink::WebScreenOrientationLockType blink_orientation_lock) { |
| 16 | switch (blink_orientation_lock) { |
| 17 | case blink::kWebScreenOrientationLockDefault: |
| 18 | case blink::kWebScreenOrientationLockAny: |
| 19 | return OrientationLockType::kAny; |
| 20 | case blink::kWebScreenOrientationLockPortrait: |
| 21 | return OrientationLockType::kPortrait; |
| 22 | case blink::kWebScreenOrientationLockPortraitPrimary: |
| 23 | return OrientationLockType::kPortraitPrimary; |
| 24 | case blink::kWebScreenOrientationLockPortraitSecondary: |
| 25 | return OrientationLockType::kPortraitSecondary; |
| 26 | case blink::kWebScreenOrientationLockLandscape: |
| 27 | return OrientationLockType::kLandscape; |
| 28 | case blink::kWebScreenOrientationLockLandscapePrimary: |
| 29 | return OrientationLockType::kLandscapePrimary; |
| 30 | case blink::kWebScreenOrientationLockLandscapeSecondary: |
| 31 | return OrientationLockType::kLandscapeSecondary; |
| 32 | case blink::kWebScreenOrientationLockNatural: |
| 33 | return OrientationLockType::kNatural; |
| 34 | } |
| 35 | return OrientationLockType::kAny; |
| 36 | } |
| 37 | |
| 38 | } // namespace |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 39 | |
| 40 | ScreenOrientationDelegateChromeos::ScreenOrientationDelegateChromeos() { |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 41 | content::WebContents::SetScreenOrientationDelegate(this); |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 42 | } |
msw | a8c8a55 | 2016-07-13 02:22:20 | [diff] [blame] | 43 | |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 44 | ScreenOrientationDelegateChromeos::~ScreenOrientationDelegateChromeos() { |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 45 | content::WebContents::SetScreenOrientationDelegate(nullptr); |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | bool ScreenOrientationDelegateChromeos::FullScreenRequired( |
| 49 | content::WebContents* web_contents) { |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | void ScreenOrientationDelegateChromeos::Lock( |
| 54 | content::WebContents* web_contents, |
Mitsuru Oshima | c6b5111 | 2018-03-19 21:05:29 | [diff] [blame] | 55 | blink::WebScreenOrientationLockType orientation_lock) { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 56 | Shell::Get()->screen_orientation_controller()->LockOrientationForWindow( |
Mitsuru Oshima | 850d972 | 2018-03-21 21:24:20 | [diff] [blame] | 57 | web_contents->GetNativeView(), |
| 58 | ToAshOrientationLockType(orientation_lock)); |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | bool ScreenOrientationDelegateChromeos::ScreenOrientationProviderSupported() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 62 | return Shell::Get() |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 63 | ->screen_orientation_controller() |
| 64 | ->ScreenOrientationProviderSupported(); |
| 65 | } |
msw | a8c8a55 | 2016-07-13 02:22:20 | [diff] [blame] | 66 | |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 67 | void ScreenOrientationDelegateChromeos::Unlock( |
| 68 | content::WebContents* web_contents) { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 69 | Shell::Get()->screen_orientation_controller()->UnlockOrientationForWindow( |
varkha | 843aa52 | 2017-05-24 16:05:59 | [diff] [blame] | 70 | web_contents->GetNativeView()); |
ben | f6de985 | 2015-10-06 21:29:28 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | } // namespace ash |