resolved conflicts for merge of 0d8b77c2 to master

This commit is contained in:
Grace Kloba
2009-06-25 11:42:46 -07:00
3 changed files with 85 additions and 8 deletions

View File

@@ -69,7 +69,24 @@ public class WebSettings {
}
int value;
}
/**
* Enum for specifying the WebView's desired density.
* FAR makes 100% looking like in 240dpi
* MEDIUM makes 100% looking like in 160dpi
* CLOSE makes 100% looking like in 120dpi
* @hide Pending API council approval
*/
public enum ZoomDensity {
FAR(150), // 240dpi
MEDIUM(100), // 160dpi
CLOSE(75); // 120dpi
ZoomDensity(int size) {
value = size;
}
int value;
}
/**
* Default cache usage pattern Use with {@link #setCacheMode}.
*/
@@ -105,6 +122,8 @@ public class WebSettings {
LOW
}
// WebView associated with this WebSettings.
private WebView mWebView;
// BrowserFrame used to access the native frame pointer.
private BrowserFrame mBrowserFrame;
// Flag to prevent multiple SYNC messages at one time.
@@ -149,6 +168,7 @@ public class WebSettings {
// Don't need to synchronize the get/set methods as they
// are basic types, also none of these values are used in
// native WebCore code.
private ZoomDensity mDefaultZoom = ZoomDensity.MEDIUM;
private RenderPriority mRenderPriority = RenderPriority.NORMAL;
private int mOverrideCacheMode = LOAD_DEFAULT;
private boolean mSaveFormData = true;
@@ -246,9 +266,10 @@ public class WebSettings {
* Package constructor to prevent clients from creating a new settings
* instance.
*/
WebSettings(Context context) {
WebSettings(Context context, WebView webview) {
mEventHandler = new EventHandler();
mContext = context;
mWebView = webview;
mDefaultTextEncoding = context.getString(com.android.internal.
R.string.default_text_encoding);
@@ -455,6 +476,31 @@ public class WebSettings {
return mTextSize;
}
/**
* Set the default zoom density of the page. This should be called from UI
* thread.
* @param zoom A ZoomDensity value
* @see WebSettings.ZoomDensity
* @hide Pending API council approval
*/
public void setDefaultZoom(ZoomDensity zoom) {
if (mDefaultZoom != zoom) {
mDefaultZoom = zoom;
mWebView.updateDefaultZoomDensity(zoom.value);
}
}
/**
* Get the default zoom density of the page. This should be called from UI
* thread.
* @return A ZoomDensity value
* @see WebSettings.ZoomDensity
* @hide Pending API council approval
*/
public ZoomDensity getDefaultZoom() {
return mDefaultZoom;
}
/**
* Enables using light touches to make a selection and activate mouseovers.
*/

View File

@@ -502,7 +502,7 @@ public class WebView extends AbsoluteLayout
// default scale. Depending on the display density.
static int DEFAULT_SCALE_PERCENT;
private float DEFAULT_SCALE;
private float mDefaultScale;
// set to true temporarily while the zoom control is being dragged
private boolean mPreviewZoomOnly = false;
@@ -745,7 +745,7 @@ public class WebView extends AbsoluteLayout
mNavSlop = (int) (16 * density);
// density adjusted scale factors
DEFAULT_SCALE_PERCENT = (int) (100 * density);
DEFAULT_SCALE = density;
mDefaultScale = density;
mActualScale = density;
mInvActualScale = 1 / density;
DEFAULT_MAX_ZOOM_SCALE = 4.0f * density;
@@ -754,6 +754,23 @@ public class WebView extends AbsoluteLayout
mMinZoomScale = DEFAULT_MIN_ZOOM_SCALE;
}
/* package */void updateDefaultZoomDensity(int zoomDensity) {
final float density = getContext().getResources().getDisplayMetrics().density
* 100 / zoomDensity;
if (Math.abs(density - mDefaultScale) > 0.01) {
float scaleFactor = density / mDefaultScale;
// adjust the limits
mNavSlop = (int) (16 * density);
DEFAULT_SCALE_PERCENT = (int) (100 * density);
DEFAULT_MAX_ZOOM_SCALE = 4.0f * density;
DEFAULT_MIN_ZOOM_SCALE = 0.25f * density;
mDefaultScale = density;
mMaxZoomScale *= scaleFactor;
mMinZoomScale *= scaleFactor;
setNewZoomScale(mActualScale * scaleFactor, false);
}
}
/* package */ boolean onSavePassword(String schemePlusHost, String username,
String password, final Message resumeMsg) {
boolean rVal = false;
@@ -4238,8 +4255,8 @@ public class WebView extends AbsoluteLayout
float oldScale = mActualScale;
// snap to DEFAULT_SCALE if it is close
if (scale > (DEFAULT_SCALE - 0.05) && scale < (DEFAULT_SCALE + 0.05)) {
scale = DEFAULT_SCALE;
if (scale > (mDefaultScale - 0.05) && scale < (mDefaultScale + 0.05)) {
scale = mDefaultScale;
}
setNewZoomScale(scale, false);
@@ -4769,7 +4786,7 @@ public class WebView extends AbsoluteLayout
int initialScale = msg.arg1;
int viewportWidth = msg.arg2;
// start a new page with DEFAULT_SCALE zoom scale.
float scale = DEFAULT_SCALE;
float scale = mDefaultScale;
if (mInitialScale > 0) {
scale = mInitialScale / 100.0f;
} else {

View File

@@ -136,7 +136,7 @@ final class WebViewCore {
// ready.
mEventHub = new EventHub();
// Create a WebSettings object for maintaining all settings
mSettings = new WebSettings(mContext);
mSettings = new WebSettings(mContext, mWebView);
// The WebIconDatabase needs to be initialized within the UI thread so
// just request the instance here.
WebIconDatabase.getInstance();
@@ -1618,6 +1618,20 @@ final class WebViewCore {
// set the viewport settings from WebKit
setViewportSettingsFromNative();
// adjust the default scale to match the density
if (WebView.DEFAULT_SCALE_PERCENT != 100) {
float adjust = WebView.DEFAULT_SCALE_PERCENT / 100;
if (mViewportInitialScale > 0) {
mViewportInitialScale *= adjust;
}
if (mViewportMinimumScale > 0) {
mViewportMinimumScale *= adjust;
}
if (mViewportMaximumScale > 0) {
mViewportMaximumScale *= adjust;
}
}
// infer the values if they are not defined.
if (mViewportWidth == 0) {
if (mViewportInitialScale == 0) {