Skip to content

Commit

Permalink
[Android WebView] Turn off "double-tap-to-zoom" together with UseWide…
Browse files Browse the repository at this point in the history
…Viewport

Android WebView classic disables the "double-tap-to-zoom" gesture
when WebSettings.UseWideViewport is disabled.

Currently, for Android "double-tab-to-zoom" is always enabled.
This patch makes the setting controllable from the browser side
and updates it appropriately.


Review URL: https://chromiumcodereview.appspot.com/12330172

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185909 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mnaganov@chromium.org committed Mar 4, 2013
1 parent bdb460b commit 3608267
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "<html><body>Page Text</body></html>";
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 {
Expand Down Expand Up @@ -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));
}
});
}
}
1 change: 1 addition & 0 deletions content/browser/android/content_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions content/public/common/common_param_traits_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion webkit/glue/webpreferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions webkit/glue/webpreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3608267

Please sign in to comment.