Chromium Code Reviews| Index: content/renderer/renderer_webkitplatformsupport_impl.cc |
| diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc |
| index 8df6722610c81ed64c8b1f133d841b8264d60737..70e99896fd5d76b28497cba4e9e2cf7b01c9f5a1 100644 |
| --- a/content/renderer/renderer_webkitplatformsupport_impl.cc |
| +++ b/content/renderer/renderer_webkitplatformsupport_impl.cc |
| @@ -150,6 +150,20 @@ static blink::WebScreenOrientationListener* |
| //------------------------------------------------------------------------------ |
| +class ScreenOrientationDataForTesting { |
|
jochen (gone - plz use gerrit)
2014/05/08 07:12:49
can you move this class and the lazy instance abov
Inactive
2014/05/08 20:07:47
Done.
|
| + public: |
| + ScreenOrientationDataForTesting() |
| + : current_lock(blink::WebScreenOrientationLockDefault), |
| + device_orientation(blink::WebScreenOrientationPortraitPrimary), |
| + current_orientation(blink::WebScreenOrientationPortraitPrimary) {} |
| + |
| + blink::WebScreenOrientationLockType current_lock; |
| + blink::WebScreenOrientationType device_orientation; |
| + blink::WebScreenOrientationType current_orientation; |
| +}; |
| +base::LazyInstance<ScreenOrientationDataForTesting>::Leaky |
| + g_test_screen_orientation_data = LAZY_INSTANCE_INITIALIZER; |
| + |
| class RendererWebKitPlatformSupportImpl::MimeRegistry |
| : public SimpleWebMimeRegistryImpl { |
| public: |
| @@ -1078,6 +1092,12 @@ void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting( |
| g_test_device_motion_data.Get() = data; |
| } |
| +// static |
| +void RendererWebKitPlatformSupportImpl::ResetMockScreenOrientationForTesting() |
| +{ |
| + g_test_screen_orientation_data.Get() = ScreenOrientationDataForTesting(); |
| +} |
| + |
| //------------------------------------------------------------------------------ |
| void RendererWebKitPlatformSupportImpl::setDeviceOrientationListener( |
| @@ -1138,10 +1158,84 @@ void RendererWebKitPlatformSupportImpl::setScreenOrientationListener( |
| screen_orientation_dispatcher_->setListener(listener); |
| } |
| +namespace { |
| + |
| +bool IsScreenOrientationAllowedByTestingLock( |
|
jochen (gone - plz use gerrit)
2014/05/08 07:12:49
can these now be members on the ScreenOrientatinoD
Inactive
2014/05/08 20:07:47
Done.
|
| + blink::WebScreenOrientationType orientation) { |
| + if (g_test_screen_orientation_data.Get().current_lock == |
| + blink::WebScreenOrientationLockDefault || |
| + g_test_screen_orientation_data.Get().current_lock == |
| + blink::WebScreenOrientationLockAny) { |
| + return true; |
| + } |
| + |
| + switch (orientation) { |
| + case blink::WebScreenOrientationPortraitPrimary: |
| + return g_test_screen_orientation_data.Get().current_lock == |
| + blink::WebScreenOrientationLockPortraitPrimary || |
| + g_test_screen_orientation_data.Get().current_lock == |
| + blink::WebScreenOrientationLockPortrait; |
| + case blink::WebScreenOrientationPortraitSecondary: |
| + return g_test_screen_orientation_data.Get().current_lock == |
| + blink::WebScreenOrientationLockPortraitSecondary || |
| + g_test_screen_orientation_data.Get().current_lock == |
| + blink::WebScreenOrientationLockPortrait; |
| + case blink::WebScreenOrientationLandscapePrimary: |
| + return g_test_screen_orientation_data.Get().current_lock == |
| + blink::WebScreenOrientationLockLandscapePrimary || |
| + g_test_screen_orientation_data.Get().current_lock == |
| + blink::WebScreenOrientationLockLandscape; |
| + case blink::WebScreenOrientationLandscapeSecondary: |
| + return g_test_screen_orientation_data.Get().current_lock == |
| + blink::WebScreenOrientationLockLandscapeSecondary || |
| + g_test_screen_orientation_data.Get().current_lock == |
| + blink::WebScreenOrientationLockLandscape; |
| + default: |
| + return false; |
| + } |
| +} |
| + |
| +blink::WebScreenOrientationType SuitableScreenOrientationForTestingLock() { |
| + switch (g_test_screen_orientation_data.Get().current_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_screen_orientation_data.Get().current_orientation) |
| + return; |
| + g_test_screen_orientation_data.Get().current_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_screen_orientation_data.Get().current_lock = orientation; |
| + if (!IsScreenOrientationAllowedByTestingLock( |
| + g_test_screen_orientation_data.Get().current_orientation)) { |
| + g_test_screen_orientation_data.Get().current_orientation = |
| + SuitableScreenOrientationForTestingLock(); |
| + if (g_test_screen_orientation_listener) { |
| + g_test_screen_orientation_listener->didChangeScreenOrientation( |
| + g_test_screen_orientation_data.Get().current_orientation); |
| + } |
| + } |
| return; |
| } |
| RenderThread::Get()->Send(new ScreenOrientationHostMsg_Lock(orientation)); |
| @@ -1150,6 +1244,15 @@ void RendererWebKitPlatformSupportImpl::lockOrientation( |
| void RendererWebKitPlatformSupportImpl::unlockOrientation() { |
| if (RenderThreadImpl::current() && |
| RenderThreadImpl::current()->layout_test_mode()) { |
| + bool should_update_current_screen_orientation = |
| + !IsScreenOrientationAllowedByTestingLock( |
| + g_test_screen_orientation_data.Get().device_orientation); |
| + g_test_screen_orientation_data.Get().current_lock = |
| + blink::WebScreenOrientationLockDefault; |
| + if (should_update_current_screen_orientation) { |
| + UpdateScreenOrientationForTesting( |
| + g_test_screen_orientation_data.Get().device_orientation); |
| + } |
| return; |
| } |
| RenderThread::Get()->Send(new ScreenOrientationHostMsg_Unlock); |
| @@ -1158,9 +1261,11 @@ void RendererWebKitPlatformSupportImpl::unlockOrientation() { |
| // static |
| void RendererWebKitPlatformSupportImpl::SetMockScreenOrientationForTesting( |
| blink::WebScreenOrientationType orientation) { |
| - if (!g_test_screen_orientation_listener) |
| + g_test_screen_orientation_data.Get().device_orientation = orientation; |
| + if (!IsScreenOrientationAllowedByTestingLock(orientation)) |
| return; |
| - g_test_screen_orientation_listener->didChangeScreenOrientation(orientation); |
| + UpdateScreenOrientationForTesting( |
| + g_test_screen_orientation_data.Get().device_orientation); |
| } |
| //------------------------------------------------------------------------------ |