2012-03-02 19:31:27 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko.gfx;
|
|
|
|
|
2012-11-07 16:47:07 +00:00
|
|
|
import org.mozilla.gecko.util.FloatUtils;
|
|
|
|
|
2012-03-02 19:31:27 +00:00
|
|
|
import android.graphics.PointF;
|
|
|
|
import android.graphics.RectF;
|
2012-11-07 16:47:08 +00:00
|
|
|
import android.util.DisplayMetrics;
|
2012-03-02 19:31:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ImmutableViewportMetrics are used to store the viewport metrics
|
|
|
|
* in way that we can access a version of them from multiple threads
|
|
|
|
* without having to take a lock
|
|
|
|
*/
|
|
|
|
public class ImmutableViewportMetrics {
|
|
|
|
|
|
|
|
// We need to flatten the RectF and FloatSize structures
|
|
|
|
// because Java doesn't have the concept of const classes
|
2012-05-23 14:49:52 +00:00
|
|
|
public final float pageRectLeft;
|
|
|
|
public final float pageRectTop;
|
|
|
|
public final float pageRectRight;
|
|
|
|
public final float pageRectBottom;
|
|
|
|
public final float cssPageRectLeft;
|
|
|
|
public final float cssPageRectTop;
|
|
|
|
public final float cssPageRectRight;
|
|
|
|
public final float cssPageRectBottom;
|
2012-03-02 19:31:27 +00:00
|
|
|
public final float viewportRectLeft;
|
2012-05-23 15:08:19 +00:00
|
|
|
public final float viewportRectTop;
|
2012-05-23 14:49:52 +00:00
|
|
|
public final float viewportRectRight;
|
|
|
|
public final float viewportRectBottom;
|
2013-04-25 17:47:08 +00:00
|
|
|
public final float marginLeft;
|
|
|
|
public final float marginTop;
|
|
|
|
public final float marginRight;
|
|
|
|
public final float marginBottom;
|
2012-03-02 19:31:27 +00:00
|
|
|
public final float zoomFactor;
|
2013-04-25 17:47:08 +00:00
|
|
|
public final boolean isRTL;
|
2012-03-02 19:31:27 +00:00
|
|
|
|
2012-11-07 16:47:08 +00:00
|
|
|
public ImmutableViewportMetrics(DisplayMetrics metrics) {
|
|
|
|
viewportRectLeft = pageRectLeft = cssPageRectLeft = 0;
|
|
|
|
viewportRectTop = pageRectTop = cssPageRectTop = 0;
|
|
|
|
viewportRectRight = pageRectRight = cssPageRectRight = metrics.widthPixels;
|
|
|
|
viewportRectBottom = pageRectBottom = cssPageRectBottom = metrics.heightPixels;
|
2013-04-25 17:47:08 +00:00
|
|
|
marginLeft = marginTop = marginRight = marginBottom = 0;
|
2012-11-07 16:47:08 +00:00
|
|
|
zoomFactor = 1.0f;
|
2013-04-25 17:47:08 +00:00
|
|
|
isRTL = false;
|
2012-03-02 19:31:27 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
/** This constructor is used by native code in AndroidJavaWrappers.cpp, be
|
|
|
|
* careful when modifying the signature.
|
|
|
|
*/
|
2012-11-07 16:47:07 +00:00
|
|
|
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 aZoomFactor)
|
2013-03-07 10:17:33 +00:00
|
|
|
{
|
|
|
|
this(aPageRectLeft, aPageRectTop,
|
|
|
|
aPageRectRight, aPageRectBottom, aCssPageRectLeft,
|
|
|
|
aCssPageRectTop, aCssPageRectRight, aCssPageRectBottom,
|
|
|
|
aViewportRectLeft, aViewportRectTop, aViewportRectRight,
|
2013-04-25 17:47:08 +00:00
|
|
|
aViewportRectBottom, 0.0f, 0.0f, 0.0f, 0.0f, aZoomFactor, false);
|
2013-03-07 10:17:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private ImmutableViewportMetrics(float aPageRectLeft, float aPageRectTop,
|
|
|
|
float aPageRectRight, float aPageRectBottom, float aCssPageRectLeft,
|
|
|
|
float aCssPageRectTop, float aCssPageRectRight, float aCssPageRectBottom,
|
|
|
|
float aViewportRectLeft, float aViewportRectTop, float aViewportRectRight,
|
2013-04-25 17:47:08 +00:00
|
|
|
float aViewportRectBottom, float aMarginLeft,
|
|
|
|
float aMarginTop, float aMarginRight,
|
|
|
|
float aMarginBottom, float aZoomFactor, boolean aIsRTL)
|
2012-11-07 16:47:07 +00:00
|
|
|
{
|
|
|
|
pageRectLeft = aPageRectLeft;
|
|
|
|
pageRectTop = aPageRectTop;
|
|
|
|
pageRectRight = aPageRectRight;
|
|
|
|
pageRectBottom = aPageRectBottom;
|
|
|
|
cssPageRectLeft = aCssPageRectLeft;
|
|
|
|
cssPageRectTop = aCssPageRectTop;
|
|
|
|
cssPageRectRight = aCssPageRectRight;
|
|
|
|
cssPageRectBottom = aCssPageRectBottom;
|
|
|
|
viewportRectLeft = aViewportRectLeft;
|
|
|
|
viewportRectTop = aViewportRectTop;
|
|
|
|
viewportRectRight = aViewportRectRight;
|
|
|
|
viewportRectBottom = aViewportRectBottom;
|
2013-04-25 17:47:08 +00:00
|
|
|
marginLeft = aMarginLeft;
|
|
|
|
marginTop = aMarginTop;
|
|
|
|
marginRight = aMarginRight;
|
|
|
|
marginBottom = aMarginBottom;
|
2012-11-07 16:47:07 +00:00
|
|
|
zoomFactor = aZoomFactor;
|
2013-04-25 17:47:08 +00:00
|
|
|
isRTL = aIsRTL;
|
2012-11-07 16:47:07 +00:00
|
|
|
}
|
|
|
|
|
2012-03-12 16:03:38 +00:00
|
|
|
public float getWidth() {
|
|
|
|
return viewportRectRight - viewportRectLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getHeight() {
|
|
|
|
return viewportRectBottom - viewportRectTop;
|
|
|
|
}
|
|
|
|
|
2013-03-25 18:13:59 +00:00
|
|
|
public float getWidthWithoutMargins() {
|
2013-04-25 17:47:08 +00:00
|
|
|
return viewportRectRight - viewportRectLeft - marginLeft - marginRight;
|
2013-03-25 18:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public float getHeightWithoutMargins() {
|
2013-04-25 17:47:08 +00:00
|
|
|
return viewportRectBottom - viewportRectTop - marginTop - marginBottom;
|
2013-03-25 18:13:59 +00:00
|
|
|
}
|
|
|
|
|
2012-03-02 19:31:27 +00:00
|
|
|
public PointF getOrigin() {
|
|
|
|
return new PointF(viewportRectLeft, viewportRectTop);
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
public PointF getMarginOffset() {
|
|
|
|
if (isRTL) {
|
|
|
|
return new PointF(marginLeft - marginRight, marginTop);
|
|
|
|
}
|
|
|
|
return new PointF(marginLeft, marginTop);
|
|
|
|
}
|
|
|
|
|
2012-03-02 19:31:27 +00:00
|
|
|
public FloatSize getSize() {
|
|
|
|
return new FloatSize(viewportRectRight - viewportRectLeft, viewportRectBottom - viewportRectTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
public RectF getViewport() {
|
|
|
|
return new RectF(viewportRectLeft,
|
|
|
|
viewportRectTop,
|
|
|
|
viewportRectRight,
|
|
|
|
viewportRectBottom);
|
|
|
|
}
|
|
|
|
|
2012-04-14 17:18:10 +00:00
|
|
|
public RectF getCssViewport() {
|
|
|
|
return RectUtils.scale(getViewport(), 1/zoomFactor);
|
|
|
|
}
|
|
|
|
|
2012-05-23 14:49:52 +00:00
|
|
|
public RectF getPageRect() {
|
|
|
|
return new RectF(pageRectLeft, pageRectTop, pageRectRight, pageRectBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getPageWidth() {
|
|
|
|
return pageRectRight - pageRectLeft;
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
public float getPageWidthWithMargins() {
|
|
|
|
return (pageRectRight - pageRectLeft) + marginLeft + marginRight;
|
|
|
|
}
|
|
|
|
|
2012-05-23 14:49:52 +00:00
|
|
|
public float getPageHeight() {
|
|
|
|
return pageRectBottom - pageRectTop;
|
2012-03-02 19:31:27 +00:00
|
|
|
}
|
2012-04-12 20:00:56 +00:00
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
public float getPageHeightWithMargins() {
|
|
|
|
return (pageRectBottom - pageRectTop) + marginTop + marginBottom;
|
|
|
|
}
|
|
|
|
|
2012-05-23 14:49:52 +00:00
|
|
|
public RectF getCssPageRect() {
|
|
|
|
return new RectF(cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom);
|
2012-04-12 20:00:56 +00:00
|
|
|
}
|
2012-04-24 03:52:58 +00:00
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2012-11-07 16:47:07 +00:00
|
|
|
/*
|
|
|
|
* Returns the viewport metrics that represent a linear transition between "this" and "to" at
|
|
|
|
* time "t", which is on the scale [0, 1). This function interpolates all values stored in
|
|
|
|
* the viewport metrics.
|
|
|
|
*/
|
|
|
|
public ImmutableViewportMetrics interpolate(ImmutableViewportMetrics to, float t) {
|
|
|
|
return new ImmutableViewportMetrics(
|
|
|
|
FloatUtils.interpolate(pageRectLeft, to.pageRectLeft, t),
|
|
|
|
FloatUtils.interpolate(pageRectTop, to.pageRectTop, t),
|
|
|
|
FloatUtils.interpolate(pageRectRight, to.pageRectRight, t),
|
|
|
|
FloatUtils.interpolate(pageRectBottom, to.pageRectBottom, t),
|
|
|
|
FloatUtils.interpolate(cssPageRectLeft, to.cssPageRectLeft, t),
|
|
|
|
FloatUtils.interpolate(cssPageRectTop, to.cssPageRectTop, t),
|
|
|
|
FloatUtils.interpolate(cssPageRectRight, to.cssPageRectRight, t),
|
|
|
|
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),
|
2013-04-25 17:47:08 +00:00
|
|
|
FloatUtils.interpolate(marginLeft, to.marginLeft, t),
|
|
|
|
FloatUtils.interpolate(marginTop, to.marginTop, t),
|
|
|
|
FloatUtils.interpolate(marginRight, to.marginRight, t),
|
|
|
|
FloatUtils.interpolate(marginBottom, to.marginBottom, t),
|
|
|
|
FloatUtils.interpolate(zoomFactor, to.zoomFactor, t),
|
|
|
|
t >= 0.5 ? to.isRTL : isRTL);
|
2012-11-07 16:47:07 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 16:47:08 +00:00
|
|
|
public ImmutableViewportMetrics setViewportSize(float width, float height) {
|
2013-04-01 14:17:03 +00:00
|
|
|
if (FloatUtils.fuzzyEquals(width, getWidth()) && FloatUtils.fuzzyEquals(height, getHeight())) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2012-11-07 16:47:08 +00:00
|
|
|
return new ImmutableViewportMetrics(
|
|
|
|
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
|
|
|
|
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
|
2012-11-07 16:47:08 +00:00
|
|
|
viewportRectLeft, viewportRectTop, viewportRectLeft + width, viewportRectTop + height,
|
2013-04-25 17:47:08 +00:00
|
|
|
marginLeft, marginTop, marginRight, marginBottom,
|
|
|
|
zoomFactor, isRTL);
|
2012-11-07 16:47:08 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 16:47:08 +00:00
|
|
|
public ImmutableViewportMetrics setViewportOrigin(float newOriginX, float newOriginY) {
|
|
|
|
return new ImmutableViewportMetrics(
|
|
|
|
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
|
|
|
|
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
|
|
|
|
newOriginX, newOriginY, newOriginX + getWidth(), newOriginY + getHeight(),
|
2013-04-25 17:47:08 +00:00
|
|
|
marginLeft, marginTop, marginRight, marginBottom,
|
|
|
|
zoomFactor, isRTL);
|
2012-11-07 16:47:08 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 16:47:08 +00:00
|
|
|
public ImmutableViewportMetrics setZoomFactor(float newZoomFactor) {
|
|
|
|
return new ImmutableViewportMetrics(
|
|
|
|
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
|
|
|
|
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
|
|
|
|
viewportRectLeft, viewportRectTop, viewportRectRight, viewportRectBottom,
|
2013-04-25 17:47:08 +00:00
|
|
|
marginLeft, marginTop, marginRight, marginBottom,
|
|
|
|
newZoomFactor, isRTL);
|
2012-11-07 16:47:08 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 16:47:17 +00:00
|
|
|
public ImmutableViewportMetrics offsetViewportBy(float dx, float dy) {
|
|
|
|
return setViewportOrigin(viewportRectLeft + dx, viewportRectTop + dy);
|
2012-11-07 16:47:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
public ImmutableViewportMetrics offsetViewportByAndClamp(float dx, float dy) {
|
|
|
|
if (isRTL) {
|
|
|
|
return setViewportOrigin(
|
|
|
|
Math.min(pageRectRight - getWidthWithoutMargins(), Math.max(viewportRectLeft + dx, pageRectLeft)),
|
|
|
|
Math.max(pageRectTop, Math.min(viewportRectTop + dy, pageRectBottom - getHeightWithoutMargins())));
|
|
|
|
}
|
|
|
|
return setViewportOrigin(
|
|
|
|
Math.max(pageRectLeft, Math.min(viewportRectLeft + dx, pageRectRight - getWidthWithoutMargins())),
|
|
|
|
Math.max(pageRectTop, Math.min(viewportRectTop + dy, pageRectBottom - getHeightWithoutMargins())));
|
|
|
|
}
|
|
|
|
|
2012-11-07 16:47:08 +00:00
|
|
|
public ImmutableViewportMetrics setPageRect(RectF pageRect, RectF cssPageRect) {
|
|
|
|
return new ImmutableViewportMetrics(
|
|
|
|
pageRect.left, pageRect.top, pageRect.right, pageRect.bottom,
|
|
|
|
cssPageRect.left, cssPageRect.top, cssPageRect.right, cssPageRect.bottom,
|
|
|
|
viewportRectLeft, viewportRectTop, viewportRectRight, viewportRectBottom,
|
2013-04-25 17:47:08 +00:00
|
|
|
marginLeft, marginTop, marginRight, marginBottom,
|
|
|
|
zoomFactor, isRTL);
|
2012-11-07 16:47:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
public ImmutableViewportMetrics setMargins(float left, float top, float right, float bottom) {
|
|
|
|
if (FloatUtils.fuzzyEquals(left, marginLeft)
|
|
|
|
&& FloatUtils.fuzzyEquals(top, marginTop)
|
|
|
|
&& FloatUtils.fuzzyEquals(right, marginRight)
|
|
|
|
&& FloatUtils.fuzzyEquals(bottom, marginBottom)) {
|
2013-04-01 14:17:38 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-03-07 10:17:33 +00:00
|
|
|
return new ImmutableViewportMetrics(
|
|
|
|
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
|
|
|
|
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
|
|
|
|
viewportRectLeft, viewportRectTop, viewportRectRight, viewportRectBottom,
|
2013-04-25 17:47:08 +00:00
|
|
|
left, top, right, bottom, zoomFactor, isRTL);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ImmutableViewportMetrics setMarginsFrom(ImmutableViewportMetrics fromMetrics) {
|
|
|
|
return setMargins(fromMetrics.marginLeft,
|
|
|
|
fromMetrics.marginTop,
|
|
|
|
fromMetrics.marginRight,
|
|
|
|
fromMetrics.marginBottom);
|
2013-03-07 10:17:33 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
public ImmutableViewportMetrics setIsRTL(boolean aIsRTL) {
|
|
|
|
if (isRTL == aIsRTL) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ImmutableViewportMetrics(
|
|
|
|
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
|
|
|
|
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
|
|
|
|
viewportRectLeft, viewportRectTop, viewportRectRight, viewportRectBottom,
|
|
|
|
marginLeft, marginTop, marginRight, marginBottom, zoomFactor, aIsRTL);
|
2013-03-07 10:17:33 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 16:47:08 +00:00
|
|
|
/* This will set the zoom factor and re-scale page-size and viewport offset
|
|
|
|
* accordingly. The given focus will remain at the same point on the screen
|
|
|
|
* after scaling.
|
|
|
|
*/
|
|
|
|
public ImmutableViewportMetrics scaleTo(float newZoomFactor, PointF focus) {
|
|
|
|
// cssPageRect* is invariant, since we're setting the scale factor
|
|
|
|
// here. The page rect is based on the CSS page rect.
|
|
|
|
float newPageRectLeft = cssPageRectLeft * newZoomFactor;
|
|
|
|
float newPageRectTop = cssPageRectTop * newZoomFactor;
|
|
|
|
float newPageRectRight = cssPageRectLeft + ((cssPageRectRight - cssPageRectLeft) * newZoomFactor);
|
|
|
|
float newPageRectBottom = cssPageRectTop + ((cssPageRectBottom - cssPageRectTop) * newZoomFactor);
|
|
|
|
|
|
|
|
PointF origin = getOrigin();
|
|
|
|
origin.offset(focus.x, focus.y);
|
|
|
|
origin = PointUtils.scale(origin, newZoomFactor / zoomFactor);
|
|
|
|
origin.offset(-focus.x, -focus.y);
|
|
|
|
|
|
|
|
return new ImmutableViewportMetrics(
|
|
|
|
newPageRectLeft, newPageRectTop, newPageRectRight, newPageRectBottom,
|
|
|
|
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
|
|
|
|
origin.x, origin.y, origin.x + getWidth(), origin.y + getHeight(),
|
2013-04-25 17:47:08 +00:00
|
|
|
marginLeft, marginTop, marginRight, marginBottom,
|
|
|
|
newZoomFactor, isRTL);
|
2012-11-07 16:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Clamps the viewport to remain within the page rect. */
|
2013-03-07 10:17:33 +00:00
|
|
|
private ImmutableViewportMetrics clamp(float marginLeft, float marginTop,
|
|
|
|
float marginRight, float marginBottom) {
|
2012-11-07 16:47:08 +00:00
|
|
|
RectF newViewport = getViewport();
|
2013-04-25 17:47:08 +00:00
|
|
|
PointF offset = getMarginOffset();
|
2012-11-07 16:47:08 +00:00
|
|
|
|
|
|
|
// The viewport bounds ought to never exceed the page bounds.
|
2013-04-25 17:47:08 +00:00
|
|
|
if (newViewport.right > pageRectRight + marginLeft + marginRight)
|
|
|
|
newViewport.offset((pageRectRight + marginLeft + marginRight) - newViewport.right, 0);
|
|
|
|
if (newViewport.left < pageRectLeft)
|
|
|
|
newViewport.offset(pageRectLeft - newViewport.left, 0);
|
2012-11-07 16:47:08 +00:00
|
|
|
|
2013-04-25 17:47:08 +00:00
|
|
|
if (newViewport.bottom > pageRectBottom + marginTop + marginBottom)
|
|
|
|
newViewport.offset(0, (pageRectBottom + marginTop + marginBottom) - newViewport.bottom);
|
|
|
|
if (newViewport.top < pageRectTop)
|
|
|
|
newViewport.offset(0, pageRectTop - newViewport.top);
|
2012-11-07 16:47:08 +00:00
|
|
|
|
2012-11-07 16:47:08 +00:00
|
|
|
return new ImmutableViewportMetrics(
|
|
|
|
pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
|
|
|
|
cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
|
2012-11-07 16:47:08 +00:00
|
|
|
newViewport.left, newViewport.top, newViewport.right, newViewport.bottom,
|
2013-04-25 17:47:08 +00:00
|
|
|
marginLeft, marginTop, marginRight, marginBottom,
|
|
|
|
zoomFactor, isRTL);
|
2012-11-07 16:47:08 +00:00
|
|
|
}
|
|
|
|
|
2013-03-07 10:17:33 +00:00
|
|
|
public ImmutableViewportMetrics clamp() {
|
|
|
|
return clamp(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ImmutableViewportMetrics clampWithMargins() {
|
2013-04-25 17:47:08 +00:00
|
|
|
return clamp(marginLeft, marginTop,
|
|
|
|
marginRight, marginBottom);
|
2013-03-07 10:17:33 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 16:47:07 +00:00
|
|
|
public boolean fuzzyEquals(ImmutableViewportMetrics other) {
|
2012-12-21 20:50:49 +00:00
|
|
|
// Don't bother checking the pageRectXXX values because they are a product
|
|
|
|
// of the cssPageRectXXX values and the zoomFactor, except with more rounding
|
|
|
|
// error. Checking those is both inefficient and can lead to false negatives.
|
2013-03-07 10:17:33 +00:00
|
|
|
//
|
2013-04-25 17:47:08 +00:00
|
|
|
// This doesn't return false if the margins differ as none of the users
|
|
|
|
// of this function are interested in the margins in that way.
|
2012-12-21 20:50:49 +00:00
|
|
|
return FloatUtils.fuzzyEquals(cssPageRectLeft, other.cssPageRectLeft)
|
2012-11-07 16:47:07 +00:00
|
|
|
&& FloatUtils.fuzzyEquals(cssPageRectTop, other.cssPageRectTop)
|
|
|
|
&& FloatUtils.fuzzyEquals(cssPageRectRight, other.cssPageRectRight)
|
|
|
|
&& 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)
|
|
|
|
&& FloatUtils.fuzzyEquals(zoomFactor, other.zoomFactor);
|
|
|
|
}
|
|
|
|
|
2012-04-24 03:52:58 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "ImmutableViewportMetrics v=(" + viewportRectLeft + "," + viewportRectTop + ","
|
2012-05-23 14:49:52 +00:00
|
|
|
+ viewportRectRight + "," + viewportRectBottom + ") p=(" + pageRectLeft + ","
|
|
|
|
+ pageRectTop + "," + pageRectRight + "," + pageRectBottom + ") c=("
|
|
|
|
+ cssPageRectLeft + "," + cssPageRectTop + "," + cssPageRectRight + ","
|
2013-04-25 17:47:08 +00:00
|
|
|
+ cssPageRectBottom + ") m=(" + marginLeft + ","
|
|
|
|
+ marginTop + "," + marginRight + ","
|
|
|
|
+ marginBottom + ") z=" + zoomFactor + ", rtl=" + isRTL;
|
2012-04-24 03:52:58 +00:00
|
|
|
}
|
2012-03-02 19:31:27 +00:00
|
|
|
}
|