Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(904)

Unified Diff: content/renderer/renderer_webkitplatformsupport_impl.cc

Issue 268673015: Support screen.lockOrientation() / screen.unlockOrientation() when running layout tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/renderer_webkitplatformsupport_impl.cc
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc
index b507a732a1eacb48b0ecdf3cac6f32fa3f736a22..f1bb5d94291a29b09e74b73c812aefe69c459017 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.cc
+++ b/content/renderer/renderer_webkitplatformsupport_impl.cc
@@ -145,6 +145,12 @@ base::LazyInstance<blink::WebDeviceMotionData>::Leaky
g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<blink::WebDeviceOrientationData>::Leaky
g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER;
+static blink::WebScreenOrientationLockType g_test_current_screen_lock =
+ blink::WebScreenOrientationLockDefault;
+static blink::WebScreenOrientationType g_test_device_screen_orientation =
+ blink::WebScreenOrientationPortraitPrimary;
+static blink::WebScreenOrientationType g_test_current_screen_orientation =
+ blink::WebScreenOrientationPortraitPrimary;
static blink::WebScreenOrientationListener*
g_test_screen_orientation_listener = NULL;
@@ -1138,10 +1144,82 @@ void RendererWebKitPlatformSupportImpl::setScreenOrientationListener(
screen_orientation_dispatcher_->setListener(listener);
}
+namespace {
+
+bool isScreenOrientationAllowedByTestingLock(blink::WebScreenOrientationType
jochen (gone - plz use gerrit) 2014/05/06 15:59:01 that doesn't look correctly wrapped, did you use c
Inactive 2014/05/06 16:26:22 I am not familiar with the Chromium-side coding st
Inactive 2014/05/06 16:56:45 Done.
+ orientation)
+{
+ if (g_test_current_screen_lock == blink::WebScreenOrientationLockDefault ||
+ g_test_current_screen_lock == blink::WebScreenOrientationLockAny)
+ return true;
+
+ switch (orientation) {
+ case blink::WebScreenOrientationPortraitPrimary:
+ return g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockPortraitPrimary
+ || g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockPortrait;
+ case blink::WebScreenOrientationPortraitSecondary:
+ return g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockPortraitSecondary
+ || g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockPortrait;
+ case blink::WebScreenOrientationLandscapePrimary:
+ return g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockLandscapePrimary
+ || g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockLandscape;
+ case blink::WebScreenOrientationLandscapeSecondary:
+ return g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockLandscapeSecondary
+ || g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockLandscape;
+ default:
+ return false;
+ }
+}
+
+blink::WebScreenOrientationType suitableScreenOrientationForTestingLock()
+{
+ switch(g_test_current_screen_lock) {
+ case blink::WebScreenOrientationLockPortraitSecondary:
+ return blink::WebScreenOrientationPortraitSecondary;
+ case blink::WebScreenOrientationLockLandscapePrimary:
+ case blink::WebScreenOrientationLockLandscape:
+ return blink::WebScreenOrientationLandscapePrimary;
+ case blink::WebScreenOrientationLockLandscapeSecondary:
+ return blink::WebScreenOrientationLandscapePrimary;
+ default:
+ return blink::WebScreenOrientationPortraitPrimary;
+ }
+}
+
+void updateScreenOrientationForTesting(blink::WebScreenOrientationType
+ orientation)
+{
+ if (orientation == g_test_current_screen_orientation)
+ return;
+ g_test_current_screen_orientation = orientation;
+ if (g_test_screen_orientation_listener)
+ g_test_screen_orientation_listener->didChangeScreenOrientation(orientation);
+}
+
+} // namespace
+
void RendererWebKitPlatformSupportImpl::lockOrientation(
blink::WebScreenOrientationLockType orientation) {
if (RenderThreadImpl::current() &&
RenderThreadImpl::current()->layout_test_mode()) {
+ g_test_current_screen_lock = orientation;
+ if (!isScreenOrientationAllowedByTestingLock(
+ g_test_current_screen_orientation)) {
+ g_test_current_screen_orientation =
+ suitableScreenOrientationForTestingLock();
+ if (g_test_screen_orientation_listener) {
+ g_test_screen_orientation_listener->didChangeScreenOrientation(
+ g_test_current_screen_orientation);
+ }
+ }
return;
}
RenderThread::Get()->Send(new ScreenOrientationHostMsg_Lock(orientation));
@@ -1150,6 +1228,12 @@ void RendererWebKitPlatformSupportImpl::lockOrientation(
void RendererWebKitPlatformSupportImpl::unlockOrientation() {
if (RenderThreadImpl::current() &&
RenderThreadImpl::current()->layout_test_mode()) {
+ bool should_update_current_screen_orientation =
+ !isScreenOrientationAllowedByTestingLock(
+ g_test_device_screen_orientation);
+ g_test_current_screen_lock = blink::WebScreenOrientationLockDefault;
+ if (should_update_current_screen_orientation)
+ updateScreenOrientationForTesting(g_test_device_screen_orientation);
return;
}
RenderThread::Get()->Send(new ScreenOrientationHostMsg_Unlock);
@@ -1158,9 +1242,10 @@ void RendererWebKitPlatformSupportImpl::unlockOrientation() {
// static
void RendererWebKitPlatformSupportImpl::SetMockScreenOrientationForTesting(
blink::WebScreenOrientationType orientation) {
- if (!g_test_screen_orientation_listener)
+ g_test_device_screen_orientation = orientation;
+ if (!isScreenOrientationAllowedByTestingLock(orientation))
return;
- g_test_screen_orientation_listener->didChangeScreenOrientation(orientation);
+ updateScreenOrientationForTesting(g_test_device_screen_orientation);
}
//------------------------------------------------------------------------------
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698