Bug 1180295 - Store the viewport width and height as integers instead of floats in ImmutableViewportMetrics. r=rbarker

--HG--
extra : commitid : 8UdQhaVHspN
This commit is contained in:
Kartikaya Gupta 2015-08-18 14:27:19 -04:00
Родитель 33054ab6d5
Коммит 29e63f503a
9 изменённых файлов: 77 добавлений и 63 удалений

Просмотреть файл

@ -1602,7 +1602,7 @@ public class BrowserApp extends GeckoApp
boolean shortPage = metrics.getPageHeight() < metrics.getHeight();
boolean toolbarMostlyVisible = toolbarTranslation < (mToolbarHeight / 2);
boolean atBottomOfLongPage = (metrics.pageRectBottom == metrics.viewportRectBottom)
boolean atBottomOfLongPage = (metrics.pageRectBottom == metrics.viewportRectBottom())
&& (metrics.pageRectBottom > 2 * metrics.getHeight());
Log.v(LOGTAG, "On pan/zoom stopped, short page: " + shortPage
+ "; toolbarMostlyVisible: " + toolbarMostlyVisible

Просмотреть файл

@ -181,8 +181,8 @@ final class DisplayPortCalculator {
private static DisplayPortMetrics getTileAlignedDisplayPortMetrics(RectF margins, float zoom, ImmutableViewportMetrics metrics) {
float left = metrics.viewportRectLeft - margins.left;
float top = metrics.viewportRectTop - margins.top;
float right = metrics.viewportRectRight + margins.right;
float bottom = metrics.viewportRectBottom + margins.bottom;
float right = metrics.viewportRectRight() + margins.right;
float bottom = metrics.viewportRectBottom() + margins.bottom;
left = (float) Math.max(metrics.pageRectLeft, TILE_SIZE * Math.floor(left / TILE_SIZE));
top = (float) Math.max(metrics.pageRectTop, TILE_SIZE * Math.floor(top / TILE_SIZE));
right = (float) Math.min(metrics.pageRectRight, TILE_SIZE * Math.ceil(right / TILE_SIZE));
@ -201,9 +201,9 @@ final class DisplayPortCalculator {
// and rightOverflow can be greater than zero, and at most one of topOverflow and bottomOverflow
// can be greater than zero, because of the assumption described in the method javadoc.
float leftOverflow = metrics.pageRectLeft - (metrics.viewportRectLeft - margins.left);
float rightOverflow = (metrics.viewportRectRight + margins.right) - metrics.pageRectRight;
float rightOverflow = (metrics.viewportRectRight() + margins.right) - metrics.pageRectRight;
float topOverflow = metrics.pageRectTop - (metrics.viewportRectTop - margins.top);
float bottomOverflow = (metrics.viewportRectBottom + margins.bottom) - metrics.pageRectBottom;
float bottomOverflow = (metrics.viewportRectBottom() + margins.bottom) - metrics.pageRectBottom;
// if the margins overflow the page bounds, shift them to other side on the same axis
if (leftOverflow > 0) {
@ -246,8 +246,8 @@ final class DisplayPortCalculator {
public DisplayPortMetrics calculate(ImmutableViewportMetrics metrics, PointF velocity) {
return new DisplayPortMetrics(metrics.viewportRectLeft,
metrics.viewportRectTop,
metrics.viewportRectRight,
metrics.viewportRectBottom,
metrics.viewportRectRight(),
metrics.viewportRectBottom(),
metrics.zoomFactor);
}
@ -445,8 +445,8 @@ final class DisplayPortCalculator {
RectF adjustedViewport = new RectF(
metrics.viewportRectLeft - dangerMargins.left,
metrics.viewportRectTop - dangerMargins.top,
metrics.viewportRectRight + dangerMargins.right,
metrics.viewportRectBottom + dangerMargins.bottom);
metrics.viewportRectRight() + dangerMargins.right,
metrics.viewportRectBottom() + dangerMargins.bottom);
return !displayPort.contains(adjustedViewport);
}
@ -588,8 +588,8 @@ final class DisplayPortCalculator {
DisplayPortMetrics dpMetrics = new DisplayPortMetrics(
metrics.viewportRectLeft - margins.left,
metrics.viewportRectTop - margins.top,
metrics.viewportRectRight + margins.right,
metrics.viewportRectBottom + margins.bottom,
metrics.viewportRectRight() + margins.right,
metrics.viewportRectBottom() + margins.bottom,
displayResolution);
return dpMetrics;
}

Просмотреть файл

@ -408,7 +408,7 @@ class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
default:
case UPDATE:
// Keep the old viewport size
newMetrics = messageMetrics.setViewportSize(oldMetrics.getWidth(), oldMetrics.getHeight());
newMetrics = messageMetrics.setViewportSize(oldMetrics.viewportRectWidth, oldMetrics.viewportRectHeight);
if (!oldMetrics.fuzzyEquals(newMetrics)) {
abortPanZoomAnimation();
}
@ -547,8 +547,8 @@ class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
// the page fall outside of the display-port.
if (Math.max(viewportMetrics.viewportRectLeft, viewportMetrics.pageRectLeft) + 1 < x ||
Math.max(viewportMetrics.viewportRectTop, viewportMetrics.pageRectTop) + 1 < y ||
Math.min(viewportMetrics.viewportRectRight, viewportMetrics.pageRectRight) - 1 > x + width ||
Math.min(viewportMetrics.viewportRectBottom, viewportMetrics.pageRectBottom) - 1 > y + height) {
Math.min(viewportMetrics.viewportRectRight(), viewportMetrics.pageRectRight) - 1 > x + width ||
Math.min(viewportMetrics.viewportRectBottom(), viewportMetrics.pageRectBottom) - 1 > y + height) {
Log.d(LOGTAG, "Aborting update due to viewport not in display-port");
mProgressiveUpdateData.abort = true;
@ -850,7 +850,7 @@ class GeckoLayerClient implements LayerView.Listener, PanZoomTarget
// updated is in GeckoLayerClient.setViewportSize, and the only place the margins should
// ever be updated is in GeckoLayerClient.setFixedLayerMargins; both of these assign to
// mViewportMetrics directly.
metrics = metrics.setViewportSize(mViewportMetrics.getWidth(), mViewportMetrics.getHeight());
metrics = metrics.setViewportSize(mViewportMetrics.viewportRectWidth, mViewportMetrics.viewportRectHeight);
metrics = metrics.setMarginsFrom(mViewportMetrics);
mViewportMetrics = metrics;

Просмотреть файл

@ -31,8 +31,9 @@ public class ImmutableViewportMetrics {
public final float cssPageRectBottom;
public final float viewportRectLeft;
public final float viewportRectTop;
public final float viewportRectRight;
public final float viewportRectBottom;
public final int viewportRectWidth;
public final int viewportRectHeight;
public final float marginLeft;
public final float marginTop;
public final float marginRight;
@ -43,8 +44,10 @@ public class ImmutableViewportMetrics {
public ImmutableViewportMetrics(DisplayMetrics metrics) {
viewportRectLeft = pageRectLeft = cssPageRectLeft = 0;
viewportRectTop = pageRectTop = cssPageRectTop = 0;
viewportRectRight = pageRectRight = cssPageRectRight = metrics.widthPixels;
viewportRectBottom = pageRectBottom = cssPageRectBottom = metrics.heightPixels;
viewportRectWidth = metrics.widthPixels;
viewportRectHeight = metrics.heightPixels;
pageRectRight = cssPageRectRight = metrics.widthPixels;
pageRectBottom = cssPageRectBottom = metrics.heightPixels;
marginLeft = marginTop = marginRight = marginBottom = 0;
zoomFactor = 1.0f;
isRTL = false;
@ -57,21 +60,21 @@ public class ImmutableViewportMetrics {
public ImmutableViewportMetrics(float aPageRectLeft, float aPageRectTop,
float aPageRectRight, float aPageRectBottom, float aCssPageRectLeft,
float aCssPageRectTop, float aCssPageRectRight, float aCssPageRectBottom,
float aViewportRectLeft, float aViewportRectTop, float aViewportRectRight,
float aViewportRectBottom, float aZoomFactor)
float aViewportRectLeft, float aViewportRectTop, int aViewportRectWidth,
int aViewportRectHeight, float aZoomFactor)
{
this(aPageRectLeft, aPageRectTop,
aPageRectRight, aPageRectBottom, aCssPageRectLeft,
aCssPageRectTop, aCssPageRectRight, aCssPageRectBottom,
aViewportRectLeft, aViewportRectTop, aViewportRectRight,
aViewportRectBottom, 0.0f, 0.0f, 0.0f, 0.0f, aZoomFactor, false);
aViewportRectLeft, aViewportRectTop, aViewportRectWidth,
aViewportRectHeight, 0.0f, 0.0f, 0.0f, 0.0f, aZoomFactor, false);
}
private ImmutableViewportMetrics(float aPageRectLeft, float aPageRectTop,
float aPageRectRight, float aPageRectBottom, float aCssPageRectLeft,
float aCssPageRectTop, float aCssPageRectRight, float aCssPageRectBottom,
float aViewportRectLeft, float aViewportRectTop, float aViewportRectRight,
float aViewportRectBottom, float aMarginLeft,
float aViewportRectLeft, float aViewportRectTop, int aViewportRectWidth,
int aViewportRectHeight, float aMarginLeft,
float aMarginTop, float aMarginRight,
float aMarginBottom, float aZoomFactor, boolean aIsRTL)
{
@ -85,8 +88,8 @@ public class ImmutableViewportMetrics {
cssPageRectBottom = aCssPageRectBottom;
viewportRectLeft = aViewportRectLeft;
viewportRectTop = aViewportRectTop;
viewportRectRight = aViewportRectRight;
viewportRectBottom = aViewportRectBottom;
viewportRectWidth = aViewportRectWidth;
viewportRectHeight = aViewportRectHeight;
marginLeft = aMarginLeft;
marginTop = aMarginTop;
marginRight = aMarginRight;
@ -96,19 +99,27 @@ public class ImmutableViewportMetrics {
}
public float getWidth() {
return viewportRectRight - viewportRectLeft;
return viewportRectWidth;
}
public float getHeight() {
return viewportRectBottom - viewportRectTop;
return viewportRectHeight;
}
public float viewportRectRight() {
return viewportRectLeft + viewportRectWidth;
}
public float viewportRectBottom() {
return viewportRectTop + viewportRectHeight;
}
public float getWidthWithoutMargins() {
return viewportRectRight - viewportRectLeft - marginLeft - marginRight;
return viewportRectWidth - marginLeft - marginRight;
}
public float getHeightWithoutMargins() {
return viewportRectBottom - viewportRectTop - marginTop - marginBottom;
return viewportRectHeight - marginTop - marginBottom;
}
public PointF getOrigin() {
@ -123,14 +134,14 @@ public class ImmutableViewportMetrics {
}
public FloatSize getSize() {
return new FloatSize(viewportRectRight - viewportRectLeft, viewportRectBottom - viewportRectTop);
return new FloatSize(viewportRectWidth, viewportRectHeight);
}
public RectF getViewport() {
return new RectF(viewportRectLeft,
viewportRectTop,
viewportRectRight,
viewportRectBottom);
viewportRectRight(),
viewportRectBottom());
}
public RectF getCssViewport() {
@ -164,8 +175,8 @@ public class ImmutableViewportMetrics {
public RectF getOverscroll() {
return new RectF(Math.max(0, pageRectLeft - viewportRectLeft),
Math.max(0, pageRectTop - viewportRectTop),
Math.max(0, viewportRectRight - pageRectRight),
Math.max(0, viewportRectBottom - pageRectBottom));
Math.max(0, viewportRectRight() - pageRectRight),
Math.max(0, viewportRectBottom() - pageRectBottom));
}
/*
@ -185,8 +196,8 @@ public class ImmutableViewportMetrics {
FloatUtils.interpolate(cssPageRectBottom, to.cssPageRectBottom, t),
FloatUtils.interpolate(viewportRectLeft, to.viewportRectLeft, t),
FloatUtils.interpolate(viewportRectTop, to.viewportRectTop, t),
FloatUtils.interpolate(viewportRectRight, to.viewportRectRight, t),
FloatUtils.interpolate(viewportRectBottom, to.viewportRectBottom, t),
(int)FloatUtils.interpolate(viewportRectWidth, to.viewportRectWidth, t),
(int)FloatUtils.interpolate(viewportRectHeight, to.viewportRectHeight, t),
FloatUtils.interpolate(marginLeft, to.marginLeft, t),
FloatUtils.interpolate(marginTop, to.marginTop, t),
FloatUtils.interpolate(marginRight, to.marginRight, t),
@ -195,15 +206,15 @@ public class ImmutableViewportMetrics {
t >= 0.5 ? to.isRTL : isRTL);
}
public ImmutableViewportMetrics setViewportSize(float width, float height) {
if (FloatUtils.fuzzyEquals(width, getWidth()) && FloatUtils.fuzzyEquals(height, getHeight())) {
public ImmutableViewportMetrics setViewportSize(int width, int height) {
if (width == viewportRectWidth && height == viewportRectHeight) {
return this;
}
return new ImmutableViewportMetrics(
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
viewportRectLeft, viewportRectTop, viewportRectLeft + width, viewportRectTop + height,
viewportRectLeft, viewportRectTop, width, height,
marginLeft, marginTop, marginRight, marginBottom,
zoomFactor, isRTL);
}
@ -212,7 +223,7 @@ public class ImmutableViewportMetrics {
return new ImmutableViewportMetrics(
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
newOriginX, newOriginY, newOriginX + getWidth(), newOriginY + getHeight(),
newOriginX, newOriginY, viewportRectWidth, viewportRectHeight,
marginLeft, marginTop, marginRight, marginBottom,
zoomFactor, isRTL);
}
@ -221,7 +232,7 @@ public class ImmutableViewportMetrics {
return new ImmutableViewportMetrics(
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
viewportRectLeft, viewportRectTop, viewportRectRight, viewportRectBottom,
viewportRectLeft, viewportRectTop, viewportRectWidth, viewportRectHeight,
marginLeft, marginTop, marginRight, marginBottom,
newZoomFactor, isRTL);
}
@ -245,7 +256,7 @@ public class ImmutableViewportMetrics {
return new ImmutableViewportMetrics(
pageRect.left, pageRect.top, pageRect.right, pageRect.bottom,
cssPageRect.left, cssPageRect.top, cssPageRect.right, cssPageRect.bottom,
viewportRectLeft, viewportRectTop, viewportRectRight, viewportRectBottom,
viewportRectLeft, viewportRectTop, viewportRectWidth, viewportRectHeight,
marginLeft, marginTop, marginRight, marginBottom,
zoomFactor, isRTL);
}
@ -261,7 +272,7 @@ public class ImmutableViewportMetrics {
return new ImmutableViewportMetrics(
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
viewportRectLeft, viewportRectTop, viewportRectRight, viewportRectBottom,
viewportRectLeft, viewportRectTop, viewportRectWidth, viewportRectHeight,
left, top, right, bottom, zoomFactor, isRTL);
}
@ -280,7 +291,7 @@ public class ImmutableViewportMetrics {
return new ImmutableViewportMetrics(
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
viewportRectLeft, viewportRectTop, viewportRectRight, viewportRectBottom,
viewportRectLeft, viewportRectTop, viewportRectWidth, viewportRectHeight,
marginLeft, marginTop, marginRight, marginBottom, zoomFactor, aIsRTL);
}
@ -304,7 +315,7 @@ public class ImmutableViewportMetrics {
return new ImmutableViewportMetrics(
newPageRectLeft, newPageRectTop, newPageRectRight, newPageRectBottom,
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
origin.x, origin.y, origin.x + getWidth(), origin.y + getHeight(),
origin.x, origin.y, viewportRectWidth, viewportRectHeight,
marginLeft, marginTop, marginRight, marginBottom,
newZoomFactor, isRTL);
}
@ -326,10 +337,12 @@ public class ImmutableViewportMetrics {
if (newViewport.top < pageRectTop)
newViewport.offset(0, pageRectTop - newViewport.top);
// Note that since newViewport is only translated around, the viewport's
// width and height are unchanged.
return new ImmutableViewportMetrics(
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
newViewport.left, newViewport.top, newViewport.right, newViewport.bottom,
newViewport.left, newViewport.top, viewportRectWidth, viewportRectHeight,
marginLeft, marginTop, marginRight, marginBottom,
zoomFactor, isRTL);
}
@ -356,15 +369,15 @@ public class ImmutableViewportMetrics {
&& FloatUtils.fuzzyEquals(cssPageRectBottom, other.cssPageRectBottom)
&& FloatUtils.fuzzyEquals(viewportRectLeft, other.viewportRectLeft)
&& FloatUtils.fuzzyEquals(viewportRectTop, other.viewportRectTop)
&& FloatUtils.fuzzyEquals(viewportRectRight, other.viewportRectRight)
&& FloatUtils.fuzzyEquals(viewportRectBottom, other.viewportRectBottom)
&& viewportRectWidth == other.viewportRectWidth
&& viewportRectHeight == other.viewportRectHeight
&& FloatUtils.fuzzyEquals(zoomFactor, other.zoomFactor);
}
@Override
public String toString() {
return "ImmutableViewportMetrics v=(" + viewportRectLeft + "," + viewportRectTop + ","
+ viewportRectRight + "," + viewportRectBottom + ") p=(" + pageRectLeft + ","
+ viewportRectWidth + "x" + viewportRectHeight + ") p=(" + pageRectLeft + ","
+ pageRectTop + "," + pageRectRight + "," + pageRectBottom + ") c=("
+ cssPageRectLeft + "," + cssPageRectTop + "," + cssPageRectRight + ","
+ cssPageRectBottom + ") m=(" + marginLeft + ","

Просмотреть файл

@ -233,7 +233,7 @@ public class LayerMarginsAnimator {
aDx = scrollMargin(newMarginsX, aDx,
overscroll.left, overscroll.right,
mTouchTravelDistance.x,
aMetrics.viewportRectLeft, aMetrics.viewportRectRight,
aMetrics.viewportRectLeft, aMetrics.viewportRectRight(),
aMetrics.pageRectLeft, aMetrics.pageRectRight,
mMaxMargins.left, mMaxMargins.right,
aMetrics.isRTL);
@ -242,7 +242,7 @@ public class LayerMarginsAnimator {
aDy = scrollMargin(newMarginsY, aDy,
overscroll.top, overscroll.bottom,
mTouchTravelDistance.y,
aMetrics.viewportRectTop, aMetrics.viewportRectBottom,
aMetrics.viewportRectTop, aMetrics.viewportRectBottom(),
aMetrics.pageRectTop, aMetrics.pageRectBottom,
mMaxMargins.top, mMaxMargins.bottom,
false);

Просмотреть файл

@ -1888,7 +1888,8 @@ AndroidBridge::GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDispla
JNIEnv* const env = jni::GetGeckoThreadEnv();
AutoLocalJNIFrame jniFrame(env, 1);
float x, y, width, height,
int width, height;
float x, y,
pageLeft, pageTop, pageRight, pageBottom,
cssPageLeft, cssPageTop, cssPageRight, cssPageBottom,
zoom;
@ -1909,7 +1910,7 @@ AndroidBridge::GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDispla
auto jmetrics = ImmutableViewportMetrics::New(
pageLeft, pageTop, pageRight, pageBottom,
cssPageLeft, cssPageTop, cssPageRight, cssPageBottom,
x, y, x + width, y + height,
x, y, width, height,
zoom);
DisplayPortMetrics::LocalRef displayPortMetrics = mLayerClient->GetDisplayPort(

Просмотреть файл

@ -1137,7 +1137,7 @@ constexpr char ImmutableViewportMetrics::name[];
constexpr char ImmutableViewportMetrics::New_t::name[];
constexpr char ImmutableViewportMetrics::New_t::signature[];
auto ImmutableViewportMetrics::New(float a0, float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12) -> ImmutableViewportMetrics::LocalRef
auto ImmutableViewportMetrics::New(float a0, float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, int32_t a10, int32_t a11, float a12) -> ImmutableViewportMetrics::LocalRef
{
return mozilla::jni::Constructor<New_t>::Call(nullptr, nullptr, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
}

Просмотреть файл

@ -2739,19 +2739,19 @@ public:
float,
float,
float,
float,
float,
int32_t,
int32_t,
float> Args;
static constexpr char name[] = "<init>";
static constexpr char signature[] =
"(FFFFFFFFFFFFF)V";
"(FFFFFFFFFFIIF)V";
static const bool isStatic = false;
static const bool isMultithreaded = true;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
static auto New(float, float, float, float, float, float, float, float, float, float, float, float, float) -> ImmutableViewportMetrics::LocalRef;
static auto New(float, float, float, float, float, float, float, float, float, float, int32_t, int32_t, float) -> ImmutableViewportMetrics::LocalRef;
};

Просмотреть файл

@ -38,12 +38,12 @@ interface nsIAndroidBrowserApp : nsISupports {
nsIUITelemetryObserver getUITelemetryObserver();
};
[scriptable, uuid(59cfcb35-69b7-47b2-8155-32b193272666)]
[scriptable, uuid(92ae801d-da9c-4a24-b2b6-344c4af7008b)]
interface nsIAndroidViewport : nsISupports {
readonly attribute float x;
readonly attribute float y;
readonly attribute float width;
readonly attribute float height;
readonly attribute int32_t width;
readonly attribute int32_t height;
readonly attribute float pageLeft;
readonly attribute float pageTop;
readonly attribute float pageRight;