Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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/display/screen_orientation_delegate_chromeos.h" | |
| 6 | |
| 7 #include "ash/display/display_info.h" | |
| 8 #include "ash/display/display_manager.h" | |
| 9 #include "ash/shell.h" | |
| 10 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
| 11 #include "content/public/browser/screen_orientation_provider.h" | |
| 12 #include "ui/gfx/display.h" | |
| 13 #include "ui/gfx/geometry/size.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { | |
| 18 ash::DisplayManager* display_manager = | |
| 19 ash::Shell::GetInstance()->display_manager(); | |
| 20 if (display_manager->HasInternalDisplay()) { | |
| 21 ash::DisplayInfo info = | |
| 22 display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()); | |
| 23 gfx::Display::Rotation rotation = info.rotation(); | |
| 24 gfx::Size size = info.size_in_pixel(); | |
| 25 if (((rotation == gfx::Display::ROTATE_0 || | |
| 26 rotation == gfx::Display::ROTATE_180) && | |
| 27 size.height() >= size.width()) || | |
| 28 ((rotation == gfx::Display::ROTATE_90 || | |
| 29 rotation == gfx::Display::ROTATE_270) && | |
| 30 size.height() < size.width())) { | |
| 31 return blink::WebScreenOrientationLockPortrait; | |
| 32 } | |
| 33 } | |
| 34 return blink::WebScreenOrientationLockLandscape; | |
| 35 } | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 namespace ash { | |
| 40 | |
| 41 ScreenOrientationDelegate::ScreenOrientationDelegate() | |
| 42 : natural_orientation_(GetDisplayNaturalOrientation()) { | |
| 43 content::ScreenOrientationProvider::SetDelegate(this); | |
| 44 } | |
| 45 | |
| 46 ScreenOrientationDelegate::~ScreenOrientationDelegate() { | |
| 47 content::ScreenOrientationProvider::SetDelegate(NULL); | |
| 48 } | |
| 49 | |
| 50 bool ScreenOrientationDelegate::FullScreenRequired( | |
| 51 content::WebContents* web_contents) { | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 void ScreenOrientationDelegate::Lock( | |
| 56 blink::WebScreenOrientationLockType lock_orientation) { | |
| 57 MaximizeModeController* controller = | |
| 58 Shell::GetInstance()->maximize_mode_controller(); | |
|
flackr
2014/10/22 21:28:04
Copying my previous comment inline to help it gain
jonross
2014/10/23 16:38:08
I've added a TODO, as that change would need to to
| |
| 59 switch (lock_orientation) { | |
| 60 case blink::WebScreenOrientationLockAny: | |
| 61 controller->SetRotationLocked(false); | |
| 62 break; | |
| 63 case blink::WebScreenOrientationLockDefault: | |
| 64 NOTREACHED(); | |
| 65 break; | |
| 66 case blink::WebScreenOrientationLockPortraitPrimary: | |
| 67 LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait); | |
| 68 break; | |
| 69 case blink::WebScreenOrientationLockPortrait: | |
| 70 LockToRotationMatchingOrientation(lock_orientation); | |
| 71 break; | |
| 72 case blink::WebScreenOrientationLockPortraitSecondary: | |
| 73 LockRotationToSecondaryOrientation( | |
| 74 blink::WebScreenOrientationLockPortrait); | |
| 75 break; | |
| 76 case blink::WebScreenOrientationLockLandscapeSecondary: | |
| 77 LockRotationToSecondaryOrientation( | |
| 78 blink::WebScreenOrientationLockLandscape); | |
| 79 break; | |
| 80 case blink::WebScreenOrientationLockLandscapePrimary: | |
| 81 LockRotationToPrimaryOrientation( | |
| 82 blink::WebScreenOrientationLockLandscape); | |
| 83 break; | |
| 84 case blink::WebScreenOrientationLockLandscape: | |
| 85 LockToRotationMatchingOrientation(lock_orientation); | |
| 86 break; | |
| 87 case blink::WebScreenOrientationLockNatural: | |
| 88 controller->LockRotation(gfx::Display::ROTATE_0); | |
| 89 break; | |
| 90 default: | |
| 91 NOTREACHED(); | |
| 92 break; | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 bool ScreenOrientationDelegate::ScreenOrientationProviderSupported() { | |
| 97 return Shell::GetInstance()->maximize_mode_controller()-> | |
| 98 IsMaximizeModeWindowManagerEnabled(); | |
| 99 } | |
| 100 | |
| 101 void ScreenOrientationDelegate::Unlock() { | |
| 102 Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(false); | |
| 103 } | |
| 104 | |
| 105 void ScreenOrientationDelegate::LockRotationToPrimaryOrientation( | |
| 106 blink::WebScreenOrientationLockType lock_orientation) { | |
| 107 Shell::GetInstance()->maximize_mode_controller()-> | |
| 108 LockRotation(natural_orientation_ == lock_orientation ? | |
| 109 gfx::Display::ROTATE_0 : | |
| 110 gfx::Display::ROTATE_90); | |
| 111 } | |
| 112 | |
| 113 void ScreenOrientationDelegate::LockRotationToSecondaryOrientation( | |
| 114 blink::WebScreenOrientationLockType lock_orientation) { | |
| 115 Shell::GetInstance()->maximize_mode_controller()-> | |
| 116 LockRotation(natural_orientation_ == lock_orientation ? | |
| 117 gfx::Display::ROTATE_180 : | |
| 118 gfx::Display::ROTATE_270); | |
| 119 } | |
| 120 | |
| 121 void ScreenOrientationDelegate::LockToRotationMatchingOrientation( | |
| 122 blink::WebScreenOrientationLockType lock_orientation) { | |
| 123 // TODO(jonross): Update MaximizeModeController to allow rotation between | |
| 124 // two angles of an orientation (e.g. from ROTATE_0 to ROTATE_180, and from | |
| 125 // ROTATE_90 to ROTATE_270) | |
| 126 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 127 if (!display_manager->HasInternalDisplay()) | |
| 128 return; | |
| 129 | |
| 130 gfx::Display::Rotation rotation = display_manager-> | |
| 131 GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); | |
| 132 MaximizeModeController* controller = | |
| 133 Shell::GetInstance()->maximize_mode_controller(); | |
| 134 if (natural_orientation_ == lock_orientation) { | |
| 135 if (rotation == gfx::Display::ROTATE_0 || | |
| 136 rotation == gfx::Display::ROTATE_180) { | |
| 137 controller->SetRotationLocked(true); | |
| 138 } else { | |
| 139 controller->LockRotation(gfx::Display::ROTATE_0); | |
| 140 } | |
| 141 } else { | |
| 142 if (rotation == gfx::Display::ROTATE_90 || | |
| 143 rotation == gfx::Display::ROTATE_270) { | |
| 144 controller->SetRotationLocked(true); | |
| 145 } else { | |
| 146 controller->LockRotation(gfx::Display::ROTATE_90); | |
| 147 } | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 } // namespace ash | |
| OLD | NEW |