Add support for force-enabling zoom

Adds an option in WebSettings that causes WebView to ignore the
 user-scalable option on the viewport metatag

Change-Id: Ia850489811a6617a8c17ec6cb17e0a65400f55f0
This commit is contained in:
John Reck
2011-04-26 16:57:46 -07:00
parent 2d039219ad
commit 7818aaa14a
2 changed files with 43 additions and 4 deletions

View File

@@ -219,6 +219,7 @@ public class WebSettings {
private boolean mAllowContentAccess = true;
private boolean mLoadWithOverviewMode = false;
private boolean mEnableSmoothTransition = false;
private boolean mForceUserScalable = false;
// AutoFill Profile data
/**
@@ -1658,6 +1659,23 @@ public class WebSettings {
}
}
/**
* Returns whether the viewport metatag can disable zooming
* @hide
*/
public boolean forceUserScalable() {
return mForceUserScalable;
}
/**
* Sets whether viewport metatag can disable zooming.
* @param flag Whether or not to forceably enable user scalable.
* @hide
*/
public synchronized void setForceUserScalable(boolean flag) {
mForceUserScalable = flag;
}
synchronized void setSyntheticLinksEnabled(boolean flag) {
if (mSyntheticLinksEnabled != flag) {
mSyntheticLinksEnabled = flag;

View File

@@ -2253,6 +2253,27 @@ final class WebViewCore {
// set the viewport settings from WebKit
setViewportSettingsFromNative();
if (mSettings.forceUserScalable()) {
mViewportUserScalable = true;
if (mViewportInitialScale > 0) {
if (mViewportMinimumScale > 0) {
mViewportMinimumScale = Math.min(mViewportMinimumScale,
mViewportInitialScale / 2);
}
if (mViewportMaximumScale > 0) {
mViewportMaximumScale = Math.max(mViewportMaximumScale,
mViewportInitialScale * 2);
}
} else {
if (mViewportMinimumScale > 0) {
mViewportMinimumScale = Math.min(mViewportMinimumScale, 50);
}
if (mViewportMaximumScale > 0) {
mViewportMaximumScale = Math.max(mViewportMaximumScale, 200);
}
}
}
// adjust the default scale to match the densityDpi
float adjust = 1.0f;
if (mViewportDensityDpi == -1) {
@@ -2589,11 +2610,11 @@ final class WebViewCore {
// called by JNI
private Class<?> getPluginClass(String libName, String clsName) {
if (mWebView == null) {
return null;
}
PluginManager pluginManager = PluginManager.getInstance(null);
String pkgName = pluginManager.getPluginsAPKName(libName);
@@ -2601,7 +2622,7 @@ final class WebViewCore {
Log.w(LOGTAG, "Unable to resolve " + libName + " to a plugin APK");
return null;
}
try {
return pluginManager.getPluginClass(pkgName, clsName);
} catch (NameNotFoundException e) {
@@ -2656,7 +2677,7 @@ final class WebViewCore {
view.mView = pluginView;
return view;
}
// called by JNI. PluginWidget functions for creating an embedded View for
// the surface drawing model.
private ViewManager.ChildView addSurface(View pluginView, int x, int y,