Merge change 4793 into donut
* changes: dpi changes for webview
This commit is contained in:
@@ -395,22 +395,27 @@ public class WebView extends AbsoluteLayout
|
|||||||
// width which view is considered to be fully zoomed out
|
// width which view is considered to be fully zoomed out
|
||||||
static final int ZOOM_OUT_WIDTH = 1008;
|
static final int ZOOM_OUT_WIDTH = 1008;
|
||||||
|
|
||||||
private static final float DEFAULT_MAX_ZOOM_SCALE = 4.0f;
|
// default scale limit. Depending on the display density
|
||||||
private static final float DEFAULT_MIN_ZOOM_SCALE = 0.25f;
|
private static float DEFAULT_MAX_ZOOM_SCALE;
|
||||||
|
private static float DEFAULT_MIN_ZOOM_SCALE;
|
||||||
// scale limit, which can be set through viewport meta tag in the web page
|
// scale limit, which can be set through viewport meta tag in the web page
|
||||||
private float mMaxZoomScale = DEFAULT_MAX_ZOOM_SCALE;
|
private float mMaxZoomScale;
|
||||||
private float mMinZoomScale = DEFAULT_MIN_ZOOM_SCALE;
|
private float mMinZoomScale;
|
||||||
private boolean mMinZoomScaleFixed = false;
|
private boolean mMinZoomScaleFixed = false;
|
||||||
|
|
||||||
// initial scale in percent. 0 means using default.
|
// initial scale in percent. 0 means using default.
|
||||||
private int mInitialScale = 0;
|
private int mInitialScale = 0;
|
||||||
|
|
||||||
|
// default scale. Depending on the display density.
|
||||||
|
static int DEFAULT_SCALE_PERCENT;
|
||||||
|
private float DEFAULT_SCALE;
|
||||||
|
|
||||||
// set to true temporarily while the zoom control is being dragged
|
// set to true temporarily while the zoom control is being dragged
|
||||||
private boolean mPreviewZoomOnly = false;
|
private boolean mPreviewZoomOnly = false;
|
||||||
|
|
||||||
// computed scale and inverse, from mZoomWidth.
|
// computed scale and inverse, from mZoomWidth.
|
||||||
private float mActualScale = 1;
|
private float mActualScale;
|
||||||
private float mInvActualScale = 1;
|
private float mInvActualScale;
|
||||||
// if this is non-zero, it is used on drawing rather than mActualScale
|
// if this is non-zero, it is used on drawing rather than mActualScale
|
||||||
private float mZoomScale;
|
private float mZoomScale;
|
||||||
private float mInvInitialZoomScale;
|
private float mInvInitialZoomScale;
|
||||||
@@ -635,7 +640,7 @@ public class WebView extends AbsoluteLayout
|
|||||||
mZoomFitPageButton.setOnClickListener(
|
mZoomFitPageButton.setOnClickListener(
|
||||||
new View.OnClickListener() {
|
new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
zoomWithPreview(1f);
|
zoomWithPreview(DEFAULT_SCALE);
|
||||||
updateZoomButtonsEnabled();
|
updateZoomButtonsEnabled();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -658,7 +663,7 @@ public class WebView extends AbsoluteLayout
|
|||||||
// or out.
|
// or out.
|
||||||
mZoomButtonsController.setZoomInEnabled(canZoomIn);
|
mZoomButtonsController.setZoomInEnabled(canZoomIn);
|
||||||
mZoomButtonsController.setZoomOutEnabled(canZoomOut);
|
mZoomButtonsController.setZoomOutEnabled(canZoomOut);
|
||||||
mZoomFitPageButton.setEnabled(mActualScale != 1);
|
mZoomFitPageButton.setEnabled(mActualScale != DEFAULT_SCALE);
|
||||||
}
|
}
|
||||||
mZoomOverviewButton.setVisibility(canZoomScrollOut() ? View.VISIBLE:
|
mZoomOverviewButton.setVisibility(canZoomScrollOut() ? View.VISIBLE:
|
||||||
View.GONE);
|
View.GONE);
|
||||||
@@ -674,10 +679,19 @@ public class WebView extends AbsoluteLayout
|
|||||||
final int slop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
|
final int slop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
|
||||||
mTouchSlopSquare = slop * slop;
|
mTouchSlopSquare = slop * slop;
|
||||||
mMinLockSnapReverseDistance = slop;
|
mMinLockSnapReverseDistance = slop;
|
||||||
|
final float density = getContext().getResources().getDisplayMetrics().density;
|
||||||
// use one line height, 16 based on our current default font, for how
|
// use one line height, 16 based on our current default font, for how
|
||||||
// far we allow a touch be away from the edge of a link
|
// far we allow a touch be away from the edge of a link
|
||||||
mNavSlop = (int) (16 * getContext().getResources()
|
mNavSlop = (int) (16 * density);
|
||||||
.getDisplayMetrics().density);
|
// density adjusted scale factors
|
||||||
|
DEFAULT_SCALE_PERCENT = (int) (100 * density);
|
||||||
|
DEFAULT_SCALE = density;
|
||||||
|
mActualScale = density;
|
||||||
|
mInvActualScale = 1 / density;
|
||||||
|
DEFAULT_MAX_ZOOM_SCALE = 4.0f * density;
|
||||||
|
DEFAULT_MIN_ZOOM_SCALE = 0.25f * density;
|
||||||
|
mMaxZoomScale = DEFAULT_MAX_ZOOM_SCALE;
|
||||||
|
mMinZoomScale = DEFAULT_MIN_ZOOM_SCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ boolean onSavePassword(String schemePlusHost, String username,
|
/* package */ boolean onSavePassword(String schemePlusHost, String username,
|
||||||
@@ -4157,9 +4171,9 @@ public class WebView extends AbsoluteLayout
|
|||||||
private boolean zoomWithPreview(float scale) {
|
private boolean zoomWithPreview(float scale) {
|
||||||
float oldScale = mActualScale;
|
float oldScale = mActualScale;
|
||||||
|
|
||||||
// snap to 100% if it is close
|
// snap to DEFAULT_SCALE if it is close
|
||||||
if (scale > 0.95f && scale < 1.05f) {
|
if (scale > (DEFAULT_SCALE - 0.05) && scale < (DEFAULT_SCALE + 0.05)) {
|
||||||
scale = 1.0f;
|
scale = DEFAULT_SCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
setNewZoomScale(scale, false);
|
setNewZoomScale(scale, false);
|
||||||
@@ -4674,8 +4688,8 @@ public class WebView extends AbsoluteLayout
|
|||||||
}
|
}
|
||||||
int initialScale = msg.arg1;
|
int initialScale = msg.arg1;
|
||||||
int viewportWidth = msg.arg2;
|
int viewportWidth = msg.arg2;
|
||||||
// by default starting a new page with 100% zoom scale.
|
// start a new page with DEFAULT_SCALE zoom scale.
|
||||||
float scale = 1.0f;
|
float scale = DEFAULT_SCALE;
|
||||||
if (mInitialScale > 0) {
|
if (mInitialScale > 0) {
|
||||||
scale = mInitialScale / 100.0f;
|
scale = mInitialScale / 100.0f;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ final class WebViewCore {
|
|||||||
|
|
||||||
private boolean mViewportUserScalable = true;
|
private boolean mViewportUserScalable = true;
|
||||||
|
|
||||||
private int mRestoredScale = 100;
|
private int mRestoredScale = WebView.DEFAULT_SCALE_PERCENT;
|
||||||
private int mRestoredX = 0;
|
private int mRestoredX = 0;
|
||||||
private int mRestoredY = 0;
|
private int mRestoredY = 0;
|
||||||
|
|
||||||
@@ -1563,16 +1563,16 @@ final class WebViewCore {
|
|||||||
// infer the values if they are not defined.
|
// infer the values if they are not defined.
|
||||||
if (mViewportWidth == 0) {
|
if (mViewportWidth == 0) {
|
||||||
if (mViewportInitialScale == 0) {
|
if (mViewportInitialScale == 0) {
|
||||||
mViewportInitialScale = 100;
|
mViewportInitialScale = WebView.DEFAULT_SCALE_PERCENT;
|
||||||
}
|
}
|
||||||
if (mViewportMinimumScale == 0) {
|
if (mViewportMinimumScale == 0) {
|
||||||
mViewportMinimumScale = 100;
|
mViewportMinimumScale = WebView.DEFAULT_SCALE_PERCENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mViewportUserScalable == false) {
|
if (mViewportUserScalable == false) {
|
||||||
mViewportInitialScale = 100;
|
mViewportInitialScale = WebView.DEFAULT_SCALE_PERCENT;
|
||||||
mViewportMinimumScale = 100;
|
mViewportMinimumScale = WebView.DEFAULT_SCALE_PERCENT;
|
||||||
mViewportMaximumScale = 100;
|
mViewportMaximumScale = WebView.DEFAULT_SCALE_PERCENT;
|
||||||
}
|
}
|
||||||
if (mViewportMinimumScale > mViewportInitialScale) {
|
if (mViewportMinimumScale > mViewportInitialScale) {
|
||||||
if (mViewportInitialScale == 0) {
|
if (mViewportInitialScale == 0) {
|
||||||
@@ -1588,7 +1588,8 @@ final class WebViewCore {
|
|||||||
mViewportInitialScale = mViewportMaximumScale;
|
mViewportInitialScale = mViewportMaximumScale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mViewportWidth < 0 && mViewportInitialScale == 100) {
|
if (mViewportWidth < 0
|
||||||
|
&& mViewportInitialScale == WebView.DEFAULT_SCALE_PERCENT) {
|
||||||
mViewportWidth = 0;
|
mViewportWidth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user