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); |
} |
//------------------------------------------------------------------------------ |