Index: ash/system/chromeos/screen_orientation/screen_orientation_delegate_ash.cc |
diff --git a/ash/system/chromeos/screen_orientation/screen_orientation_delegate_ash.cc b/ash/system/chromeos/screen_orientation/screen_orientation_delegate_ash.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9626c768c15765c5c6cfb0b8fdf2a40acbc5e2f3 |
--- /dev/null |
+++ b/ash/system/chromeos/screen_orientation/screen_orientation_delegate_ash.cc |
@@ -0,0 +1,138 @@ |
+// Copyright 2014 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 "ash/system/chromeos/screen_orientation/screen_orientation_delegate_ash.h" |
flackr
2014/10/14 20:08:17
This should maybe be in ash/display/screen_orienta
jonross
2014/10/22 18:45:30
Done.
|
+ |
+#include "ash/display/display_info.h" |
+#include "ash/display/display_manager.h" |
+#include "ash/shell.h" |
+#include "ash/wm/maximize_mode/maximize_mode_controller.h" |
+#include "content/public/browser/screen_orientation_provider.h" |
+#include "ui/gfx/display.h" |
+#include "ui/gfx/geometry/size.h" |
+ |
+namespace ash { |
+ |
+ScreenOrientationDelegateAsh::ScreenOrientationDelegateAsh() |
+ : natural_orientation_(blink::WebScreenOrientationLockLandscape) { |
+ content::ScreenOrientationProvider::SetDelegate(this); |
+ |
+ DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
+ if (display_manager->HasInternalDisplay()) { |
+ DisplayInfo info = |
+ display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()); |
+ gfx::Display::Rotation rotation = info.rotation(); |
+ gfx::Size size = info.size_in_pixel(); |
+ if (((rotation == gfx::Display::ROTATE_0 || |
+ rotation == gfx::Display::ROTATE_180) && |
mlamouri (slow - plz ping)
2014/10/15 15:39:33
nit: one space is missing to align this line
jonross
2014/10/22 18:45:30
Done.
|
+ size.height() >= size.width()) || |
+ ((rotation == gfx::Display::ROTATE_90 || |
+ rotation == gfx::Display::ROTATE_270) && |
+ size.height() < size.width())) { |
+ natural_orientation_ = blink::WebScreenOrientationLockPortrait; |
+ } |
+ } |
flackr
2014/10/14 20:08:18
Move this to a helper function (GetDisplayNaturalO
mlamouri (slow - plz ping)
2014/10/15 15:39:33
+1 with that, it would make this algorithm a bit m
jonross
2014/10/22 18:45:30
Done.
|
+} |
+ |
+ScreenOrientationDelegateAsh::~ScreenOrientationDelegateAsh() { |
+ content::ScreenOrientationProvider::SetDelegate(NULL); |
+} |
+ |
+bool ScreenOrientationDelegateAsh::FullScreenRequired( |
+ content::WebContents* web_contents) { |
+ return true; |
+} |
+ |
+void ScreenOrientationDelegateAsh::Lock( |
+ blink::WebScreenOrientationLockType lock_orientation) { |
+ MaximizeModeController* controller = |
+ Shell::GetInstance()->maximize_mode_controller(); |
+ switch (lock_orientation) { |
+ case blink::WebScreenOrientationLockAny: |
+ case blink::WebScreenOrientationLockDefault: |
+ DCHECK(!controller->rotation_locked()); |
flackr
2014/10/14 20:08:17
Won't this be true if the user manually locked a r
mlamouri (slow - plz ping)
2014/10/15 15:39:33
LockDefault is not expected to be called. You shou
jonross
2014/10/22 18:45:30
Since it should not be called I'll use NOTREACHED,
|
+ break; |
+ case blink::WebScreenOrientationLockPortraitPrimary: |
+ LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait); |
+ break; |
+ case blink::WebScreenOrientationLockPortrait: |
+ LockToRotationMatchingOrientation(lock_orientation); |
+ break; |
+ case blink::WebScreenOrientationLockPortraitSecondary: |
+ LockRotationToSecondaryOrientation( |
+ blink::WebScreenOrientationLockPortrait); |
+ break; |
+ case blink::WebScreenOrientationLockLandscapeSecondary: |
+ LockRotationToSecondaryOrientation( |
+ blink::WebScreenOrientationLockLandscape); |
+ break; |
+ case blink::WebScreenOrientationLockLandscapePrimary: |
+ LockRotationToPrimaryOrientation( |
+ blink::WebScreenOrientationLockLandscape); |
+ break; |
+ case blink::WebScreenOrientationLockLandscape: |
+ LockToRotationMatchingOrientation(lock_orientation); |
+ break; |
+ case blink::WebScreenOrientationLockNatural: |
+ default: |
flackr
2014/10/14 20:08:18
Should probably handle all expected WebScreenOrien
mlamouri (slow - plz ping)
2014/10/15 15:39:33
+1
jonross
2014/10/22 18:45:30
Done.
|
+ controller->LockRotation(gfx::Display::ROTATE_0); |
+ break; |
+ } |
+} |
+ |
+bool ScreenOrientationDelegateAsh::ScreenOrientationProviderSupported() { |
+ return Shell::GetInstance()->maximize_mode_controller()-> |
+ IsMaximizeModeWindowManagerEnabled(); |
+} |
+ |
+void ScreenOrientationDelegateAsh::Unlock() { |
+ Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(false); |
flackr
2014/10/14 20:08:17
How does this interact with a user-locked orientat
|
+} |
+ |
+void ScreenOrientationDelegateAsh::LockRotationToPrimaryOrientation( |
+ blink::WebScreenOrientationLockType lock_orientation) { |
+ Shell::GetInstance()->maximize_mode_controller()-> |
+ LockRotation(natural_orientation_ == lock_orientation ? |
+ gfx::Display::ROTATE_0 : |
+ gfx::Display::ROTATE_90); |
+} |
+ |
+void ScreenOrientationDelegateAsh::LockRotationToSecondaryOrientation( |
+ blink::WebScreenOrientationLockType lock_orientation) { |
+ Shell::GetInstance()->maximize_mode_controller()-> |
+ LockRotation(natural_orientation_ == lock_orientation ? |
+ gfx::Display::ROTATE_180 : |
+ gfx::Display::ROTATE_270); |
+} |
+ |
+void ScreenOrientationDelegateAsh::LockToRotationMatchingOrientation( |
+ blink::WebScreenOrientationLockType lock_orientation) { |
+ //TODO(jonross): Update MaximizeModeController to allow rotation between |
+ // two angles of an orientation. |
flackr
2014/10/14 20:08:17
I'm a little unclear on what you mean here? Can yo
jonross
2014/10/22 18:45:30
Correct, it would be to allow the web page to lock
|
+ DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
+ if (!display_manager->HasInternalDisplay()) |
+ return; |
mlamouri (slow - plz ping)
2014/10/15 15:39:33
I'm a bit confused by that. Is it expected? I mean
jonross
2014/10/22 18:45:30
This is a valid state for unit tests on ash. Since
|
+ |
+ gfx::Display::Rotation rotation = display_manager-> |
+ GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); |
+ MaximizeModeController* controller = |
+ Shell::GetInstance()->maximize_mode_controller(); |
+ if (natural_orientation_ == lock_orientation) { |
+ if (rotation == gfx::Display::ROTATE_0 || |
+ rotation == gfx::Display::ROTATE_180){ |
+ controller->SetRotationLocked(true); |
+ } else { |
+ controller->LockRotation(gfx::Display::ROTATE_0); |
+ } |
+ } else { |
+ if (rotation == gfx::Display::ROTATE_90 || |
+ rotation == gfx::Display::ROTATE_270) { |
+ controller->SetRotationLocked(true); |
+ } else { |
+ controller->LockRotation(gfx::Display::ROTATE_90); |
+ } |
+ } |
+} |
+ |
+} // namespace ash |