diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java index f4e6cd35e909ab..a6cbc037a22d2a 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java @@ -6,9 +6,12 @@ import android.content.Context; import android.os.Build; +import android.os.SystemClock; import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.SmallTest; import android.util.Pair; +import android.view.MotionEvent; import android.webkit.WebSettings; import org.apache.http.Header; @@ -2362,6 +2365,35 @@ public void testUseWideViewportLayoutWidth() throws Throwable { assertEquals(viewportTagSpecifiedWidth, getTitleOnUiThread(awContents)); } + @MediumTest + @Feature({"AndroidWebView", "Preferences"}) + public void testUseWideViewportControlsDoubleTabToZoom() throws Throwable { + final TestAwContentsClient contentClient = new TestAwContentsClient(); + final AwTestContainerView testContainerView = + createAwTestContainerViewOnMainSync(contentClient); + final AwContents awContents = testContainerView.getAwContents(); + ContentSettings settings = getContentSettingsOnUiThread(awContents); + CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHelper(); + + final String page = "Page Text"; + assertFalse(settings.getUseWideViewPort()); + loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false); + final float initialScale = getScaleOnUiThread(awContents); + simulateDoubleTapCenterOfWebViewOnUiThread(testContainerView); + Thread.sleep(1000); + assertEquals(initialScale, getScaleOnUiThread(awContents)); + + settings.setUseWideViewPort(true); + awContents.getSettings().setEnableFixedLayoutMode(true); + loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false); + int onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().getCallCount(); + simulateDoubleTapCenterOfWebViewOnUiThread(testContainerView); + contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount); + final float zoomedOutScale = getScaleOnUiThread(awContents); + assertTrue("zoomedOut: " + zoomedOutScale + ", initial: " + initialScale, + zoomedOutScale < initialScale); + } + @SmallTest @Feature({"AndroidWebView", "Preferences"}) public void testLoadWithOverviewModeWithTwoViews() throws Throwable { @@ -2662,4 +2694,30 @@ public Float call() throws Exception { } }); } + + private void simulateDoubleTapCenterOfWebViewOnUiThread(final AwTestContainerView webView) + throws Throwable { + final AwContents awContents = webView.getAwContents(); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + long firstTapTime = SystemClock.uptimeMillis(); + float x = (float)(webView.getRight() - webView.getLeft()) / 2; + float y = (float)(webView.getBottom() - webView.getTop()) / 2; + awContents.onTouchEvent(MotionEvent.obtain( + firstTapTime, firstTapTime, MotionEvent.ACTION_DOWN, + x, y, 0)); + awContents.onTouchEvent(MotionEvent.obtain( + firstTapTime, firstTapTime, MotionEvent.ACTION_UP, + x, y, 0)); + long secondTapTime = firstTapTime + 200; + awContents.onTouchEvent(MotionEvent.obtain( + secondTapTime, secondTapTime, MotionEvent.ACTION_DOWN, + x, y, 0)); + awContents.onTouchEvent(MotionEvent.obtain( + secondTapTime, secondTapTime, MotionEvent.ACTION_UP, + x, y, 0)); + } + }); + } } diff --git a/content/browser/android/content_settings.cc b/content/browser/android/content_settings.cc index 581a85f7727712..691f22cf5ba72a 100644 --- a/content/browser/android/content_settings.cc +++ b/content/browser/android/content_settings.cc @@ -406,6 +406,7 @@ void ContentSettings::SyncToNativeImpl() { prefs.viewport_enabled = env->GetBooleanField( obj, field_ids_->use_wide_viewport); + prefs.double_tap_to_zoom_enabled = prefs.viewport_enabled; prefs.initialize_at_minimum_page_scale = env->GetBooleanField( obj, field_ids_->load_with_overview_mode); diff --git a/content/public/common/common_param_traits_macros.h b/content/public/common/common_param_traits_macros.h index 57384b270ddbd8..74825023c14811 100644 --- a/content/public/common/common_param_traits_macros.h +++ b/content/public/common/common_param_traits_macros.h @@ -198,6 +198,7 @@ IPC_STRUCT_TRAITS_BEGIN(webkit_glue::WebPreferences) IPC_STRUCT_TRAITS_MEMBER(text_autosizing_enabled) IPC_STRUCT_TRAITS_MEMBER(font_scale_factor) IPC_STRUCT_TRAITS_MEMBER(force_enable_zoom) + IPC_STRUCT_TRAITS_MEMBER(double_tap_to_zoom_enabled) IPC_STRUCT_TRAITS_MEMBER(user_gesture_required_for_media_playback) #endif IPC_STRUCT_TRAITS_END() diff --git a/webkit/glue/webpreferences.cc b/webkit/glue/webpreferences.cc index a0933a9b651cd5..8fbde8cb0472a5 100644 --- a/webkit/glue/webpreferences.cc +++ b/webkit/glue/webpreferences.cc @@ -140,6 +140,7 @@ WebPreferences::WebPreferences() text_autosizing_enabled(true), font_scale_factor(1.0f), force_enable_zoom(false), + double_tap_to_zoom_enabled(true), user_gesture_required_for_media_playback(true) #endif { @@ -458,7 +459,7 @@ void WebPreferences::Apply(WebView* web_view) const { settings->setTextAutosizingFontScaleFactor(font_scale_factor); web_view->setIgnoreViewportTagMaximumScale(force_enable_zoom); settings->setAutoZoomFocusedNodeToLegibleScale(true); - settings->setDoubleTapToZoomEnabled(true); + settings->setDoubleTapToZoomEnabled(double_tap_to_zoom_enabled); settings->setMediaPlaybackRequiresUserGesture( user_gesture_required_for_media_playback); #endif diff --git a/webkit/glue/webpreferences.h b/webkit/glue/webpreferences.h index fe4acc81abb500..b9ee6b417bf362 100644 --- a/webkit/glue/webpreferences.h +++ b/webkit/glue/webpreferences.h @@ -160,6 +160,7 @@ struct WEBKIT_GLUE_EXPORT WebPreferences { bool text_autosizing_enabled; float font_scale_factor; bool force_enable_zoom; + bool double_tap_to_zoom_enabled; bool user_gesture_required_for_media_playback; #endif