Skip to content

Commit 6013d8c

Browse files
committed
Fix DPI scaling on TVDPI
Bug: 6891214 tvdpi has a density of 1.3312501 which we fail on as we assume you can take density and multiply by 100, cast to an int, and divide by 100f to get back to the original density. Force this assumption to be true by truncating density Change-Id: I0caeb7768ee002f935b41c77a5579ffeed491f82
1 parent 5dbeb6a commit 6013d8c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

core/java/android/webkit/WebViewCore.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,6 +2536,9 @@ private void setupViewport(boolean updateViewState) {
25362536
adjust = (float) mContext.getResources().getDisplayMetrics().densityDpi
25372537
/ mViewportDensityDpi;
25382538
}
2539+
// We make bad assumptions about multiplying and dividing by 100, force
2540+
// them to be true with this hack
2541+
adjust = ((int) (adjust * 100)) / 100.0f;
25392542
// Remove any update density messages in flight.
25402543
// If the density is indeed different from WebView's default scale,
25412544
// a new message will be queued.

core/java/android/webkit/ZoomManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ private void setDefaultZoomScale(float defaultScale) {
287287
if (!exceedsMinScaleIncrement(mMinZoomScale, mMaxZoomScale)) {
288288
mMaxZoomScale = mMinZoomScale;
289289
}
290+
sanitizeMinMaxScales();
290291
}
291292

292293
public final float getScale() {
@@ -909,6 +910,14 @@ public void onScaleEnd(ScaleGestureDetector detector) {
909910
}
910911
}
911912

913+
private void sanitizeMinMaxScales() {
914+
if (mMinZoomScale > mMaxZoomScale) {
915+
Log.w(LOGTAG, "mMinZoom > mMaxZoom!!! " + mMinZoomScale + " > " + mMaxZoomScale,
916+
new Exception());
917+
mMaxZoomScale = mMinZoomScale;
918+
}
919+
}
920+
912921
public void onSizeChanged(int w, int h, int ow, int oh) {
913922
// reset zoom and anchor to the top left corner of the screen
914923
// unless we are already zooming
@@ -933,6 +942,7 @@ public void onSizeChanged(int w, int h, int ow, int oh) {
933942
if (mInitialScale > 0 && mInitialScale < mMinZoomScale) {
934943
mMinZoomScale = mInitialScale;
935944
}
945+
sanitizeMinMaxScales();
936946
}
937947

938948
dismissZoomPicker();
@@ -1004,6 +1014,7 @@ public void updateZoomRange(WebViewCore.ViewState viewState,
10041014
} else {
10051015
mMaxZoomScale = viewState.mMaxScale;
10061016
}
1017+
sanitizeMinMaxScales();
10071018
}
10081019

10091020
/**
@@ -1033,6 +1044,7 @@ public boolean onNewPicture(WebViewCore.DrawData drawData) {
10331044
if (!mMinZoomScaleFixed || settings.getUseWideViewPort()) {
10341045
mMinZoomScale = newZoomOverviewScale;
10351046
mMaxZoomScale = Math.max(mMaxZoomScale, mMinZoomScale);
1047+
sanitizeMinMaxScales();
10361048
}
10371049
// fit the content width to the current view for the first new picture
10381050
// after first layout.
@@ -1113,6 +1125,7 @@ public void onFirstLayout(WebViewCore.DrawData drawData) {
11131125
mMinZoomScale = (mInitialScale > 0) ?
11141126
Math.min(mInitialScale, overviewScale) : overviewScale;
11151127
mMaxZoomScale = Math.max(mMaxZoomScale, mMinZoomScale);
1128+
sanitizeMinMaxScales();
11161129
}
11171130

11181131
if (!mWebView.drawHistory()) {

0 commit comments

Comments
 (0)