Commit f553d08d authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Chrome OS: restore screen orientation delegate for classic Ash.

Mash implementation is a TODO.

Test: put in tablet mode, go to [1], press Lock in Current Orienation

[1] https://whatwebcando.today/screen-orientation.html

Bug: 889981
Change-Id: I19192a92ba927eba76c63089fa57c1288b34ff1c
Reviewed-on: https://chromium-review.googlesource.com/1252525
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595526}
parent bd92eff9
...@@ -1466,8 +1466,6 @@ component("ash_with_content") { ...@@ -1466,8 +1466,6 @@ component("ash_with_content") {
"content/keyboard_overlay/keyboard_overlay_delegate.h", "content/keyboard_overlay/keyboard_overlay_delegate.h",
"content/keyboard_overlay/keyboard_overlay_view.cc", "content/keyboard_overlay/keyboard_overlay_view.cc",
"content/keyboard_overlay/keyboard_overlay_view.h", "content/keyboard_overlay/keyboard_overlay_view.h",
"content/screen_orientation_delegate_chromeos.cc",
"content/screen_orientation_delegate_chromeos.h",
] ]
defines = [ "ASH_WITH_CONTENT_IMPLEMENTATION" ] defines = [ "ASH_WITH_CONTENT_IMPLEMENTATION" ]
...@@ -1619,7 +1617,7 @@ copy("dbus_service_files") { ...@@ -1619,7 +1617,7 @@ copy("dbus_service_files") {
# need or use content and should be placed in |ash_unittests| instead. # need or use content and should be placed in |ash_unittests| instead.
test("ash_content_unittests") { test("ash_content_unittests") {
sources = [ sources = [
"content/display/screen_orientation_controller_chromeos_unittest.cc", "content/display/screen_orientation_controller_unittest.cc",
"content/keyboard_overlay/keyboard_overlay_delegate_unittest.cc", "content/keyboard_overlay/keyboard_overlay_delegate_unittest.cc",
"content/keyboard_overlay/keyboard_overlay_view_unittest.cc", "content/keyboard_overlay/keyboard_overlay_view_unittest.cc",
"test/ash_unittests.cc", "test/ash_unittests.cc",
......
specific_include_rules = { specific_include_rules = {
"screen_orientation_controller_chromeos_unittest.cc": [ "screen_orientation_controller_unittest.cc": [
"+content/public/browser/browser_context.h", "+content/public/browser/browser_context.h",
"+content/public/browser/web_contents.h", "+content/public/browser/web_contents.h",
"+third_party/blink/public/common/screen_orientation/web_screen_orientation_lock_type.h", "+third_party/blink/public/common/screen_orientation/web_screen_orientation_lock_type.h",
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "ash/content/screen_orientation_delegate_chromeos.h"
#include "ash/display/screen_orientation_controller.h" #include "ash/display/screen_orientation_controller.h"
#include "ash/display/screen_orientation_controller_test_api.h" #include "ash/display/screen_orientation_controller_test_api.h"
#include "ash/public/cpp/app_types.h" #include "ash/public/cpp/app_types.h"
...@@ -43,6 +42,8 @@ ...@@ -43,6 +42,8 @@
namespace ash { namespace ash {
using WebContents = content::WebContents;
namespace { namespace {
const float kDegreesToRadians = 3.1415926f / 180.0f; const float kDegreesToRadians = 3.1415926f / 180.0f;
...@@ -86,8 +87,7 @@ void TriggerLidUpdate(const gfx::Vector3dF& lid) { ...@@ -86,8 +87,7 @@ void TriggerLidUpdate(const gfx::Vector3dF& lid) {
// Attaches the NativeView of |web_contents| to |parent| without changing the // Attaches the NativeView of |web_contents| to |parent| without changing the
// currently active window. // currently active window.
void AttachWebContents(content::WebContents* web_contents, void AttachWebContents(WebContents* web_contents, aura::Window* parent) {
aura::Window* parent) {
aura::Window* window = web_contents->GetNativeView(); aura::Window* window = web_contents->GetNativeView();
window->Show(); window->Show();
parent->AddChild(window); parent->AddChild(window);
...@@ -95,12 +95,48 @@ void AttachWebContents(content::WebContents* web_contents, ...@@ -95,12 +95,48 @@ void AttachWebContents(content::WebContents* web_contents,
// Attaches the NativeView of |web_contents| to |parent|, ensures that it is // Attaches the NativeView of |web_contents| to |parent|, ensures that it is
// visible, and activates the parent window. // visible, and activates the parent window.
void AttachAndActivateWebContents(content::WebContents* web_contents, void AttachAndActivateWebContents(WebContents* web_contents,
aura::Window* parent) { aura::Window* parent) {
AttachWebContents(web_contents, parent); AttachWebContents(web_contents, parent);
Shell::Get()->activation_client()->ActivateWindow(parent); Shell::Get()->activation_client()->ActivateWindow(parent);
} }
ash::OrientationLockType ToAshOrientationLockType(
blink::WebScreenOrientationLockType blink_orientation_lock) {
switch (blink_orientation_lock) {
case blink::kWebScreenOrientationLockDefault:
case blink::kWebScreenOrientationLockAny:
return ash::OrientationLockType::kAny;
case blink::kWebScreenOrientationLockPortrait:
return ash::OrientationLockType::kPortrait;
case blink::kWebScreenOrientationLockPortraitPrimary:
return ash::OrientationLockType::kPortraitPrimary;
case blink::kWebScreenOrientationLockPortraitSecondary:
return ash::OrientationLockType::kPortraitSecondary;
case blink::kWebScreenOrientationLockLandscape:
return ash::OrientationLockType::kLandscape;
case blink::kWebScreenOrientationLockLandscapePrimary:
return ash::OrientationLockType::kLandscapePrimary;
case blink::kWebScreenOrientationLockLandscapeSecondary:
return ash::OrientationLockType::kLandscapeSecondary;
case blink::kWebScreenOrientationLockNatural:
return ash::OrientationLockType::kNatural;
}
return ash::OrientationLockType::kAny;
}
void Lock(WebContents* web_contents,
blink::WebScreenOrientationLockType orientation_lock) {
Shell::Get()->screen_orientation_controller()->LockOrientationForWindow(
web_contents->GetNativeView(),
ToAshOrientationLockType(orientation_lock));
}
void Unlock(WebContents* web_contents) {
Shell::Get()->screen_orientation_controller()->UnlockOrientationForWindow(
web_contents->GetNativeView());
}
} // namespace } // namespace
class ScreenOrientationControllerTest : public AshTestBase { class ScreenOrientationControllerTest : public AshTestBase {
...@@ -108,15 +144,13 @@ class ScreenOrientationControllerTest : public AshTestBase { ...@@ -108,15 +144,13 @@ class ScreenOrientationControllerTest : public AshTestBase {
ScreenOrientationControllerTest(); ScreenOrientationControllerTest();
~ScreenOrientationControllerTest() override; ~ScreenOrientationControllerTest() override;
content::ScreenOrientationDelegate* delegate() { return &delegate_; } // Creates and initializes and empty WebContents that is backed by a
// Creates and initializes and empty content::WebContents that is backed by a
// content::BrowserContext and that has an aura::Window. // content::BrowserContext and that has an aura::Window.
std::unique_ptr<content::WebContents> CreateWebContents(); std::unique_ptr<WebContents> CreateWebContents();
// Creates a secondary content::WebContents, with a separate // Creates a secondary WebContents, with a separate
// content::BrowserContext. // content::BrowserContext.
std::unique_ptr<content::WebContents> CreateSecondaryWebContents(); std::unique_ptr<WebContents> CreateSecondaryWebContents();
// AshTestBase: // AshTestBase:
void SetUp() override; void SetUp() override;
...@@ -149,14 +183,12 @@ class ScreenOrientationControllerTest : public AshTestBase { ...@@ -149,14 +183,12 @@ class ScreenOrientationControllerTest : public AshTestBase {
} }
private: private:
ScreenOrientationDelegateChromeos delegate_;
content::TestBrowserContext browser_context_; content::TestBrowserContext browser_context_;
// Optional content::BrowserContext used for two window tests. // Optional content::BrowserContext used for two window tests.
std::unique_ptr<content::BrowserContext> secondary_browser_context_; std::unique_ptr<content::BrowserContext> secondary_browser_context_;
// Setups underlying content layer so that content::WebContents can be // Setups underlying content layer so that WebContents can be
// generated. // generated.
std::unique_ptr<views::WebViewTestHelper> webview_test_helper_; std::unique_ptr<views::WebViewTestHelper> webview_test_helper_;
...@@ -169,13 +201,13 @@ ScreenOrientationControllerTest::ScreenOrientationControllerTest() { ...@@ -169,13 +201,13 @@ ScreenOrientationControllerTest::ScreenOrientationControllerTest() {
ScreenOrientationControllerTest::~ScreenOrientationControllerTest() = default; ScreenOrientationControllerTest::~ScreenOrientationControllerTest() = default;
std::unique_ptr<content::WebContents> std::unique_ptr<WebContents>
ScreenOrientationControllerTest::CreateWebContents() { ScreenOrientationControllerTest::CreateWebContents() {
return content::WebContentsTester::CreateTestWebContents(&browser_context_, return content::WebContentsTester::CreateTestWebContents(&browser_context_,
nullptr); nullptr);
} }
std::unique_ptr<content::WebContents> std::unique_ptr<WebContents>
ScreenOrientationControllerTest::CreateSecondaryWebContents() { ScreenOrientationControllerTest::CreateSecondaryWebContents() {
secondary_browser_context_.reset(new content::TestBrowserContext()); secondary_browser_context_.reset(new content::TestBrowserContext());
return content::WebContentsTester::CreateTestWebContents( return content::WebContentsTester::CreateTestWebContents(
...@@ -191,108 +223,108 @@ void ScreenOrientationControllerTest::SetUp() { ...@@ -191,108 +223,108 @@ void ScreenOrientationControllerTest::SetUp() {
SetRunningOutsideAsh(); SetRunningOutsideAsh();
} }
// Tests that a content::WebContents can lock rotation. // Tests that a WebContents can lock rotation.
TEST_F(ScreenOrientationControllerTest, LockOrientation) { TEST_F(ScreenOrientationControllerTest, LockOrientation) {
EnableTabletMode(true); EnableTabletMode(true);
std::unique_ptr<content::WebContents> content(CreateWebContents()); std::unique_ptr<WebContents> content(CreateWebContents());
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
ASSERT_NE(nullptr, content->GetNativeView()); ASSERT_NE(nullptr, content->GetNativeView());
ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
ASSERT_FALSE(RotationLocked()); ASSERT_FALSE(RotationLocked());
AttachAndActivateWebContents(content.get(), focus_window.get()); AttachAndActivateWebContents(content.get(), focus_window.get());
delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); Lock(content.get(), blink::kWebScreenOrientationLockLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked()); EXPECT_TRUE(RotationLocked());
} }
// Tests that a content::WebContents can unlock rotation. // Tests that a WebContents can unlock rotation.
TEST_F(ScreenOrientationControllerTest, Unlock) { TEST_F(ScreenOrientationControllerTest, Unlock) {
EnableTabletMode(true); EnableTabletMode(true);
std::unique_ptr<content::WebContents> content(CreateWebContents()); std::unique_ptr<WebContents> content(CreateWebContents());
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
ASSERT_NE(nullptr, content->GetNativeView()); ASSERT_NE(nullptr, content->GetNativeView());
ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
ASSERT_FALSE(RotationLocked()); ASSERT_FALSE(RotationLocked());
AttachAndActivateWebContents(content.get(), focus_window.get()); AttachAndActivateWebContents(content.get(), focus_window.get());
delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); Lock(content.get(), blink::kWebScreenOrientationLockLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked()); EXPECT_TRUE(RotationLocked());
delegate()->Unlock(content.get()); Unlock(content.get());
EXPECT_FALSE(RotationLocked()); EXPECT_FALSE(RotationLocked());
} }
// Tests that a content::WebContents is able to change the orientation of the // Tests that a WebContents is able to change the orientation of the
// display after having locked rotation. // display after having locked rotation.
TEST_F(ScreenOrientationControllerTest, OrientationChanges) { TEST_F(ScreenOrientationControllerTest, OrientationChanges) {
EnableTabletMode(true); EnableTabletMode(true);
std::unique_ptr<content::WebContents> content(CreateWebContents()); std::unique_ptr<WebContents> content(CreateWebContents());
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
ASSERT_NE(nullptr, content->GetNativeView()); ASSERT_NE(nullptr, content->GetNativeView());
ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
ASSERT_FALSE(RotationLocked()); ASSERT_FALSE(RotationLocked());
AttachAndActivateWebContents(content.get(), focus_window.get()); AttachAndActivateWebContents(content.get(), focus_window.get());
delegate()->Lock(content.get(), blink::kWebScreenOrientationLockPortrait); Lock(content.get(), blink::kWebScreenOrientationLockPortrait);
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked()); EXPECT_TRUE(RotationLocked());
delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); Lock(content.get(), blink::kWebScreenOrientationLockLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
} }
// Tests that orientation can only be set by the first content::WebContents that // Tests that orientation can only be set by the first WebContents that
// has set a rotation lock. // has set a rotation lock.
TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) { TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) {
EnableTabletMode(true); EnableTabletMode(true);
std::unique_ptr<content::WebContents> content1(CreateWebContents()); std::unique_ptr<WebContents> content1(CreateWebContents());
std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); std::unique_ptr<WebContents> content2(CreateSecondaryWebContents());
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
AttachAndActivateWebContents(content1.get(), focus_window1.get()); AttachAndActivateWebContents(content1.get(), focus_window1.get());
AttachWebContents(content2.get(), focus_window2.get()); AttachWebContents(content2.get(), focus_window2.get());
delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockLandscape); Lock(content1.get(), blink::kWebScreenOrientationLockLandscape);
delegate()->Lock(content2.get(), blink::kWebScreenOrientationLockPortrait); Lock(content2.get(), blink::kWebScreenOrientationLockPortrait);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
} }
// Tests that only the content::WebContents that set a rotation lock can perform // Tests that only the WebContents that set a rotation lock can perform
// an unlock. // an unlock.
TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) { TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) {
EnableTabletMode(true); EnableTabletMode(true);
std::unique_ptr<content::WebContents> content1(CreateWebContents()); std::unique_ptr<WebContents> content1(CreateWebContents());
std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); std::unique_ptr<WebContents> content2(CreateSecondaryWebContents());
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
AttachAndActivateWebContents(content1.get(), focus_window1.get()); AttachAndActivateWebContents(content1.get(), focus_window1.get());
AttachWebContents(content2.get(), focus_window2.get()); AttachWebContents(content2.get(), focus_window2.get());
delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockLandscape); Lock(content1.get(), blink::kWebScreenOrientationLockLandscape);
delegate()->Unlock(content2.get()); Unlock(content2.get());
EXPECT_TRUE(RotationLocked()); EXPECT_TRUE(RotationLocked());
} }
// Tests that a rotation lock is applied only while the content::WebContents are // Tests that a rotation lock is applied only while the WebContents are
// a part of the active window. // a part of the active window.
TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateLock) { TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateLock) {
EnableTabletMode(true); EnableTabletMode(true);
std::unique_ptr<content::WebContents> content(CreateWebContents()); std::unique_ptr<WebContents> content(CreateWebContents());
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
AttachAndActivateWebContents(content.get(), focus_window1.get()); AttachAndActivateWebContents(content.get(), focus_window1.get());
delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); Lock(content.get(), blink::kWebScreenOrientationLockLandscape);
ASSERT_TRUE(RotationLocked()); ASSERT_TRUE(RotationLocked());
::wm::ActivationClient* activation_client = Shell::Get()->activation_client(); ::wm::ActivationClient* activation_client = Shell::Get()->activation_client();
...@@ -308,15 +340,15 @@ TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateLock) { ...@@ -308,15 +340,15 @@ TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateLock) {
TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) { TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) {
EnableTabletMode(true); EnableTabletMode(true);
std::unique_ptr<content::WebContents> content1(CreateWebContents()); std::unique_ptr<WebContents> content1(CreateWebContents());
std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); std::unique_ptr<WebContents> content2(CreateSecondaryWebContents());
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
AttachAndActivateWebContents(content1.get(), focus_window1.get()); AttachAndActivateWebContents(content1.get(), focus_window1.get());
AttachWebContents(content2.get(), focus_window2.get()); AttachWebContents(content2.get(), focus_window2.get());
delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockLandscape); Lock(content1.get(), blink::kWebScreenOrientationLockLandscape);
delegate()->Lock(content2.get(), blink::kWebScreenOrientationLockPortrait); Lock(content2.get(), blink::kWebScreenOrientationLockPortrait);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
::wm::ActivationClient* activation_client = Shell::Get()->activation_client(); ::wm::ActivationClient* activation_client = Shell::Get()->activation_client();
...@@ -334,10 +366,10 @@ TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) { ...@@ -334,10 +366,10 @@ TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) {
TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) { TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) {
EnableTabletMode(true); EnableTabletMode(true);
std::unique_ptr<content::WebContents> content(CreateWebContents()); std::unique_ptr<WebContents> content(CreateWebContents());
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
AttachAndActivateWebContents(content.get(), focus_window.get()); AttachAndActivateWebContents(content.get(), focus_window.get());
delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); Lock(content.get(), blink::kWebScreenOrientationLockLandscape);
EXPECT_TRUE(RotationLocked()); EXPECT_TRUE(RotationLocked());
aura::Window* window = content->GetNativeView(); aura::Window* window = content->GetNativeView();
...@@ -353,12 +385,12 @@ TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) { ...@@ -353,12 +385,12 @@ TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) {
TEST_F(ScreenOrientationControllerTest, WindowDestructionRemovesLock) { TEST_F(ScreenOrientationControllerTest, WindowDestructionRemovesLock) {
EnableTabletMode(true); EnableTabletMode(true);
std::unique_ptr<content::WebContents> content(CreateWebContents()); std::unique_ptr<WebContents> content(CreateWebContents());
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
AttachAndActivateWebContents(content.get(), focus_window1.get()); AttachAndActivateWebContents(content.get(), focus_window1.get());
delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); Lock(content.get(), blink::kWebScreenOrientationLockLandscape);
ASSERT_TRUE(RotationLocked()); ASSERT_TRUE(RotationLocked());
focus_window1->RemoveChild(content->GetNativeView()); focus_window1->RemoveChild(content->GetNativeView());
...@@ -548,12 +580,12 @@ TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) { ...@@ -548,12 +580,12 @@ TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) {
// Tests that when the orientation lock is set to Landscape, that rotation can // Tests that when the orientation lock is set to Landscape, that rotation can
// be done between the two angles of the orientation. // be done between the two angles of the orientation.
TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) {
std::unique_ptr<content::WebContents> content(CreateWebContents()); std::unique_ptr<WebContents> content(CreateWebContents());
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
EnableTabletMode(true); EnableTabletMode(true);
AttachAndActivateWebContents(content.get(), focus_window.get()); AttachAndActivateWebContents(content.get(), focus_window.get());
delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); Lock(content.get(), blink::kWebScreenOrientationLockLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked()); EXPECT_TRUE(RotationLocked());
...@@ -568,15 +600,15 @@ TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { ...@@ -568,15 +600,15 @@ TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) {
EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
} }
// Tests that when the orientation lock is set to Portrait, that rotaiton can be // Tests that when the orientation lock is set to Portrait, that rotation can be
// done between the two angles of the orientation. // done between the two angles of the orientation.
TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) {
std::unique_ptr<content::WebContents> content(CreateWebContents()); std::unique_ptr<WebContents> content(CreateWebContents());
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
EnableTabletMode(true); EnableTabletMode(true);
AttachAndActivateWebContents(content.get(), focus_window.get()); AttachAndActivateWebContents(content.get(), focus_window.get());
delegate()->Lock(content.get(), blink::kWebScreenOrientationLockPortrait); Lock(content.get(), blink::kWebScreenOrientationLockPortrait);
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked()); EXPECT_TRUE(RotationLocked());
...@@ -594,13 +626,12 @@ TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { ...@@ -594,13 +626,12 @@ TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) {
// Tests that for an orientation lock which does not allow rotation, that the // Tests that for an orientation lock which does not allow rotation, that the
// display rotation remains constant. // display rotation remains constant.
TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) {
std::unique_ptr<content::WebContents> content(CreateWebContents()); std::unique_ptr<WebContents> content(CreateWebContents());
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
EnableTabletMode(true); EnableTabletMode(true);
AttachAndActivateWebContents(content.get(), focus_window.get()); AttachAndActivateWebContents(content.get(), focus_window.get());
delegate()->Lock(content.get(), Lock(content.get(), blink::kWebScreenOrientationLockPortraitPrimary);
blink::kWebScreenOrientationLockPortraitPrimary);
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked()); EXPECT_TRUE(RotationLocked());
...@@ -613,16 +644,16 @@ TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { ...@@ -613,16 +644,16 @@ TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) {
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
} }
// Tests that after a content::WebContents has applied an orientation lock which // Tests that after a WebContents has applied an orientation lock which
// supports rotation, that a user rotation lock does not allow rotation. // supports rotation, that a user rotation lock does not allow rotation.
TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) {
std::unique_ptr<content::WebContents> content(CreateWebContents()); std::unique_ptr<WebContents> content(CreateWebContents());
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
EnableTabletMode(true); EnableTabletMode(true);
AttachAndActivateWebContents(content.get(), focus_window.get()); AttachAndActivateWebContents(content.get(), focus_window.get());
delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); Lock(content.get(), blink::kWebScreenOrientationLockLandscape);
delegate()->Unlock(content.get()); Unlock(content.get());
SetUserRotationLocked(true); SetUserRotationLocked(true);
EXPECT_TRUE(RotationLocked()); EXPECT_TRUE(RotationLocked());
...@@ -723,8 +754,8 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLockedOrientation) { ...@@ -723,8 +754,8 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLockedOrientation) {
TEST_F(ScreenOrientationControllerTest, UserRotationLock) { TEST_F(ScreenOrientationControllerTest, UserRotationLock) {
EnableTabletMode(true); EnableTabletMode(true);
std::unique_ptr<content::WebContents> content1(CreateWebContents()); std::unique_ptr<WebContents> content1(CreateWebContents());
std::unique_ptr<content::WebContents> content2(CreateSecondaryWebContents()); std::unique_ptr<WebContents> content2(CreateSecondaryWebContents());
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0)); std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1)); std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
ASSERT_NE(content1->GetNativeView(), content2->GetNativeView()); ASSERT_NE(content1->GetNativeView(), content2->GetNativeView());
...@@ -742,7 +773,7 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLock) { ...@@ -742,7 +773,7 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLock) {
orientation_controller->ToggleUserRotationLock(); orientation_controller->ToggleUserRotationLock();
ASSERT_TRUE(orientation_controller->user_rotation_locked()); ASSERT_TRUE(orientation_controller->user_rotation_locked());
delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockPortrait); Lock(content1.get(), blink::kWebScreenOrientationLockPortrait);
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
...@@ -764,10 +795,10 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLock) { ...@@ -764,10 +795,10 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLock) {
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
// Application forced to be landscape. // Application forced to be landscape.
delegate()->Lock(content2.get(), blink::kWebScreenOrientationLockLandscape); Lock(content2.get(), blink::kWebScreenOrientationLockLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockAny); Lock(content1.get(), blink::kWebScreenOrientationLockAny);
activation_client->ActivateWindow(focus_window1.get()); activation_client->ActivateWindow(focus_window1.get());
// Switching back to any will rotate to user rotation. // Switching back to any will rotate to user rotation.
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
......
...@@ -1494,6 +1494,8 @@ jumbo_split_static_library("ui") { ...@@ -1494,6 +1494,8 @@ jumbo_split_static_library("ui") {
"ash/network/network_state_notifier.h", "ash/network/network_state_notifier.h",
"ash/network/tether_notification_presenter.cc", "ash/network/tether_notification_presenter.cc",
"ash/network/tether_notification_presenter.h", "ash/network/tether_notification_presenter.h",
"ash/screen_orientation_delegate_chromeos.cc",
"ash/screen_orientation_delegate_chromeos.h",
"ash/session_controller_client.cc", "ash/session_controller_client.cc",
"ash/session_controller_client.h", "ash/session_controller_client.h",
"ash/session_util.cc", "ash/session_util.cc",
......
...@@ -49,6 +49,10 @@ specific_include_rules = { ...@@ -49,6 +49,10 @@ specific_include_rules = {
# https://crbug.com/665064 # https://crbug.com/665064
"+ash/shell_delegate.h", "+ash/shell_delegate.h",
], ],
"screen_orientation_delegate_chromeos.cc": [
"+ash/display/screen_orientation_controller.h",
"+ash/shell.h",
],
# For ash::Shell::GetContainer (!mash) # For ash::Shell::GetContainer (!mash)
"system_tray_client\.cc": [ "system_tray_client\.cc": [
"+ash/shell.h", "+ash/shell.h",
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "chrome/browser/ui/ash/network/data_promo_notification.h" #include "chrome/browser/ui/ash/network/data_promo_notification.h"
#include "chrome/browser/ui/ash/network/network_connect_delegate_chromeos.h" #include "chrome/browser/ui/ash/network/network_connect_delegate_chromeos.h"
#include "chrome/browser/ui/ash/network/network_portal_notification_controller.h" #include "chrome/browser/ui/ash/network/network_portal_notification_controller.h"
#include "chrome/browser/ui/ash/screen_orientation_delegate_chromeos.h"
#include "chrome/browser/ui/ash/session_controller_client.h" #include "chrome/browser/ui/ash/session_controller_client.h"
#include "chrome/browser/ui/ash/system_tray_client.h" #include "chrome/browser/ui/ash/system_tray_client.h"
#include "chrome/browser/ui/ash/tab_scrubber.h" #include "chrome/browser/ui/ash/tab_scrubber.h"
...@@ -205,6 +206,13 @@ void ChromeBrowserMainExtraPartsAsh::PreProfileInit() { ...@@ -205,6 +206,13 @@ void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
std::move(user_activity_monitor), user_activity_detector_.get()); std::move(user_activity_monitor), user_activity_detector_.get());
} }
// TODO(estade): implement ScreenOrientationDelegateChromeos for Mash and
// remove this condition.
if (!features::IsUsingWindowService()) {
screen_orientation_delegate_ =
std::make_unique<ScreenOrientationDelegateChromeos>();
}
app_list_client_ = std::make_unique<AppListClientImpl>(); app_list_client_ = std::make_unique<AppListClientImpl>();
// Must be available at login screen, so initialize before profile. // Must be available at login screen, so initialize before profile.
......
...@@ -44,6 +44,7 @@ class LoginScreenClient; ...@@ -44,6 +44,7 @@ class LoginScreenClient;
class MediaClient; class MediaClient;
class NetworkConnectDelegateChromeOS; class NetworkConnectDelegateChromeOS;
class NightLightClient; class NightLightClient;
class ScreenOrientationDelegateChromeos;
class SessionControllerClient; class SessionControllerClient;
class SystemTrayClient; class SystemTrayClient;
class TabletModeClient; class TabletModeClient;
...@@ -97,6 +98,8 @@ class ChromeBrowserMainExtraPartsAsh : public ChromeBrowserMainExtraParts { ...@@ -97,6 +98,8 @@ class ChromeBrowserMainExtraPartsAsh : public ChromeBrowserMainExtraParts {
std::unique_ptr<AppListClientImpl> app_list_client_; std::unique_ptr<AppListClientImpl> app_list_client_;
std::unique_ptr<ChromeNewWindowClient> chrome_new_window_client_; std::unique_ptr<ChromeNewWindowClient> chrome_new_window_client_;
std::unique_ptr<ImeControllerClient> ime_controller_client_; std::unique_ptr<ImeControllerClient> ime_controller_client_;
std::unique_ptr<ScreenOrientationDelegateChromeos>
screen_orientation_delegate_;
std::unique_ptr<SessionControllerClient> session_controller_client_; std::unique_ptr<SessionControllerClient> session_controller_client_;
std::unique_ptr<SystemTrayClient> system_tray_client_; std::unique_ptr<SystemTrayClient> system_tray_client_;
std::unique_ptr<TabletModeClient> tablet_mode_client_; std::unique_ptr<TabletModeClient> tablet_mode_client_;
......
...@@ -2,37 +2,37 @@ ...@@ -2,37 +2,37 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ash/content/screen_orientation_delegate_chromeos.h" #include "chrome/browser/ui/ash/screen_orientation_delegate_chromeos.h"
#include "ash/display/screen_orientation_controller.h" #include "ash/display/screen_orientation_controller.h" // mash-ok
#include "ash/shell.h" #include "ash/shell.h" // mash-ok
#include "chrome/browser/ui/ash/tablet_mode_client.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
namespace ash {
namespace { namespace {
OrientationLockType ToAshOrientationLockType( ash::OrientationLockType ToAshOrientationLockType(
blink::WebScreenOrientationLockType blink_orientation_lock) { blink::WebScreenOrientationLockType blink_orientation_lock) {
switch (blink_orientation_lock) { switch (blink_orientation_lock) {
case blink::kWebScreenOrientationLockDefault: case blink::kWebScreenOrientationLockDefault:
case blink::kWebScreenOrientationLockAny: case blink::kWebScreenOrientationLockAny:
return OrientationLockType::kAny; return ash::OrientationLockType::kAny;
case blink::kWebScreenOrientationLockPortrait: case blink::kWebScreenOrientationLockPortrait:
return OrientationLockType::kPortrait; return ash::OrientationLockType::kPortrait;
case blink::kWebScreenOrientationLockPortraitPrimary: case blink::kWebScreenOrientationLockPortraitPrimary:
return OrientationLockType::kPortraitPrimary; return ash::OrientationLockType::kPortraitPrimary;
case blink::kWebScreenOrientationLockPortraitSecondary: case blink::kWebScreenOrientationLockPortraitSecondary:
return OrientationLockType::kPortraitSecondary; return ash::OrientationLockType::kPortraitSecondary;
case blink::kWebScreenOrientationLockLandscape: case blink::kWebScreenOrientationLockLandscape:
return OrientationLockType::kLandscape; return ash::OrientationLockType::kLandscape;
case blink::kWebScreenOrientationLockLandscapePrimary: case blink::kWebScreenOrientationLockLandscapePrimary:
return OrientationLockType::kLandscapePrimary; return ash::OrientationLockType::kLandscapePrimary;
case blink::kWebScreenOrientationLockLandscapeSecondary: case blink::kWebScreenOrientationLockLandscapeSecondary:
return OrientationLockType::kLandscapeSecondary; return ash::OrientationLockType::kLandscapeSecondary;
case blink::kWebScreenOrientationLockNatural: case blink::kWebScreenOrientationLockNatural:
return OrientationLockType::kNatural; return ash::OrientationLockType::kNatural;
} }
return OrientationLockType::kAny; return ash::OrientationLockType::kAny;
} }
} // namespace } // namespace
...@@ -53,21 +53,19 @@ bool ScreenOrientationDelegateChromeos::FullScreenRequired( ...@@ -53,21 +53,19 @@ bool ScreenOrientationDelegateChromeos::FullScreenRequired(
void ScreenOrientationDelegateChromeos::Lock( void ScreenOrientationDelegateChromeos::Lock(
content::WebContents* web_contents, content::WebContents* web_contents,
blink::WebScreenOrientationLockType orientation_lock) { blink::WebScreenOrientationLockType orientation_lock) {
Shell::Get()->screen_orientation_controller()->LockOrientationForWindow( ash::Shell::Get()->screen_orientation_controller()->LockOrientationForWindow(
web_contents->GetNativeView(), web_contents->GetNativeView(),
ToAshOrientationLockType(orientation_lock)); ToAshOrientationLockType(orientation_lock));
} }
bool ScreenOrientationDelegateChromeos::ScreenOrientationProviderSupported() { bool ScreenOrientationDelegateChromeos::ScreenOrientationProviderSupported() {
return Shell::Get() return TabletModeClient::Get() &&
->screen_orientation_controller() TabletModeClient::Get()->tablet_mode_enabled();
->ScreenOrientationProviderSupported();
} }
void ScreenOrientationDelegateChromeos::Unlock( void ScreenOrientationDelegateChromeos::Unlock(
content::WebContents* web_contents) { content::WebContents* web_contents) {
Shell::Get()->screen_orientation_controller()->UnlockOrientationForWindow( ash::Shell::Get()
web_contents->GetNativeView()); ->screen_orientation_controller()
->UnlockOrientationForWindow(web_contents->GetNativeView());
} }
} // namespace ash
...@@ -2,16 +2,14 @@ ...@@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef ASH_CONTENT_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ #ifndef CHROME_BROWSER_UI_ASH_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_
#define ASH_CONTENT_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ #define CHROME_BROWSER_UI_ASH_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_
#include "content/public/browser/screen_orientation_delegate.h" #include "content/public/browser/screen_orientation_delegate.h"
#include "ash/content/ash_with_content_export.h" // Chrome OS implementation for screen orientation JS api. TODO(estade):
// implement for Mash.
namespace ash { class ScreenOrientationDelegateChromeos
class ASH_WITH_CONTENT_EXPORT ScreenOrientationDelegateChromeos
: public content::ScreenOrientationDelegate { : public content::ScreenOrientationDelegate {
public: public:
ScreenOrientationDelegateChromeos(); ScreenOrientationDelegateChromeos();
...@@ -28,6 +26,4 @@ class ASH_WITH_CONTENT_EXPORT ScreenOrientationDelegateChromeos ...@@ -28,6 +26,4 @@ class ASH_WITH_CONTENT_EXPORT ScreenOrientationDelegateChromeos
DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDelegateChromeos); DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDelegateChromeos);
}; };
} // namespace ash #endif // CHROME_BROWSER_UI_ASH_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_
#endif // ASH_CONTENT_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment