зеркало из https://github.com/mozilla/gecko-dev.git
Bug 702416 - Replace FloatRect with android.graphics.RectF [r=pcwalton]
This commit is contained in:
Родитель
c1bba92a23
Коммит
4fbd70a78b
|
@ -41,7 +41,6 @@
|
|||
package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.gfx.GeckoSoftwareLayerClient;
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.LayerController;
|
||||
import org.mozilla.gecko.gfx.LayerView;
|
||||
|
@ -1742,9 +1741,9 @@ abstract public class GeckoApp
|
|||
originalY = aY;
|
||||
}
|
||||
|
||||
public void repositionFromVisibleRect(FloatRect rect) {
|
||||
x = originalX - (int)rect.x;
|
||||
y = originalY - (int)rect.y;
|
||||
public void repositionFromVisibleRect(RectF rect) {
|
||||
x = originalX - (int)rect.left;
|
||||
y = originalY - (int)rect.top;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ JAVAFILES = \
|
|||
gfx/BufferedCairoImage.java \
|
||||
gfx/CairoImage.java \
|
||||
gfx/CairoUtils.java \
|
||||
gfx/FloatRect.java \
|
||||
gfx/GeckoSoftwareLayerClient.java \
|
||||
gfx/InputConnectionHandler.java \
|
||||
gfx/IntSize.java \
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Android code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009-2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick Walton <pcwalton@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
|
||||
public class FloatRect {
|
||||
public final float x, y, width, height;
|
||||
|
||||
public FloatRect(float inX, float inY, float inWidth, float inHeight) {
|
||||
x = inX; y = inY; width = inWidth; height = inHeight;
|
||||
}
|
||||
|
||||
public FloatRect(Rect intRect) {
|
||||
x = intRect.left; y = intRect.top; width = intRect.width(); height = intRect.height();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof FloatRect))
|
||||
return false;
|
||||
FloatRect otherRect = (FloatRect)other;
|
||||
return x == otherRect.x && y == otherRect.y &&
|
||||
width == otherRect.width && height == otherRect.height;
|
||||
}
|
||||
|
||||
public float getRight() { return x + width; }
|
||||
public float getBottom() { return y + height; }
|
||||
|
||||
public PointF getOrigin() { return new PointF(x, y); }
|
||||
public PointF getCenter() { return new PointF(x + width / 2, y + height / 2); }
|
||||
|
||||
/** Returns the intersection of this rectangle with another rectangle. */
|
||||
public FloatRect intersect(FloatRect other) {
|
||||
float left = Math.max(x, other.x);
|
||||
float top = Math.max(y, other.y);
|
||||
float right = Math.min(getRight(), other.getRight());
|
||||
float bottom = Math.min(getBottom(), other.getBottom());
|
||||
return new FloatRect(left, top, Math.max(right - left, 0), Math.max(bottom - top, 0));
|
||||
}
|
||||
|
||||
/** Returns true if and only if the given rectangle is fully enclosed within this one. */
|
||||
public boolean contains(FloatRect other) {
|
||||
return x <= other.x && y <= other.y &&
|
||||
getRight() >= other.getRight() &&
|
||||
getBottom() >= other.getBottom();
|
||||
}
|
||||
|
||||
/** Contracts a rectangle by the given number of units in each direction, from the center. */
|
||||
public FloatRect contract(float lessWidth, float lessHeight) {
|
||||
float halfWidth = width / 2.0f - lessWidth, halfHeight = height / 2.0f - lessHeight;
|
||||
PointF center = getCenter();
|
||||
return new FloatRect(center.x - halfWidth, center.y - halfHeight,
|
||||
halfWidth * 2.0f, halfHeight * 2.0f);
|
||||
}
|
||||
|
||||
/** Scales all four dimensions of this rectangle by the given factor. */
|
||||
public FloatRect scaleAll(float factor) {
|
||||
return new FloatRect(x * factor, y * factor, width * factor, height * factor);
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +38,6 @@
|
|||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import org.mozilla.gecko.gfx.CairoImage;
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.LayerClient;
|
||||
import org.mozilla.gecko.gfx.LayerController;
|
||||
|
@ -50,7 +49,9 @@ import org.mozilla.gecko.GeckoAppShell;
|
|||
import org.mozilla.gecko.GeckoEvent;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.util.Log;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
@ -71,7 +72,7 @@ public class GeckoSoftwareLayerClient extends LayerClient {
|
|||
private SingleTileLayer mTileLayer;
|
||||
private ViewportController mViewportController;
|
||||
|
||||
private FloatRect mGeckoVisibleRect;
|
||||
private RectF mGeckoVisibleRect;
|
||||
/* The viewport rect that Gecko is currently displaying. */
|
||||
|
||||
private Rect mJSPanningToRect;
|
||||
|
@ -91,7 +92,7 @@ public class GeckoSoftwareLayerClient extends LayerClient {
|
|||
mContext = context;
|
||||
|
||||
mViewportController = new ViewportController(new IntSize(PAGE_WIDTH, PAGE_HEIGHT),
|
||||
new FloatRect(0, 0, 1, 1));
|
||||
new RectF(0, 0, 1, 1));
|
||||
|
||||
mWidth = LayerController.TILE_WIDTH;
|
||||
mHeight = LayerController.TILE_HEIGHT;
|
||||
|
@ -150,9 +151,9 @@ public class GeckoSoftwareLayerClient extends LayerClient {
|
|||
mViewportController.setVisibleRect(mGeckoVisibleRect);
|
||||
|
||||
if (mGeckoVisibleRect != null) {
|
||||
FloatRect layerRect = mViewportController.untransformVisibleRect(mGeckoVisibleRect,
|
||||
getPageSize());
|
||||
mTileLayer.origin = layerRect.getOrigin();
|
||||
RectF layerRect = mViewportController.untransformVisibleRect(mGeckoVisibleRect,
|
||||
getPageSize());
|
||||
mTileLayer.origin = new PointF(layerRect.left, layerRect.top);
|
||||
}
|
||||
|
||||
repaint(new Rect(x, y, x + width, y + height));
|
||||
|
@ -164,7 +165,7 @@ public class GeckoSoftwareLayerClient extends LayerClient {
|
|||
|
||||
/** Called whenever the chrome JS finishes panning or zooming to some location. */
|
||||
public void jsPanZoomCompleted(Rect rect) {
|
||||
mGeckoVisibleRect = new FloatRect(rect);
|
||||
mGeckoVisibleRect = new RectF(rect);
|
||||
if (mWaitingForJSPanZoom)
|
||||
render();
|
||||
}
|
||||
|
@ -208,12 +209,12 @@ public class GeckoSoftwareLayerClient extends LayerClient {
|
|||
@Override
|
||||
public void render() {
|
||||
LayerController layerController = getLayerController();
|
||||
FloatRect visibleRect = layerController.getVisibleRect();
|
||||
FloatRect tileRect = mViewportController.widenRect(visibleRect);
|
||||
RectF visibleRect = layerController.getVisibleRect();
|
||||
RectF tileRect = mViewportController.widenRect(visibleRect);
|
||||
tileRect = mViewportController.clampRect(tileRect);
|
||||
|
||||
IntSize pageSize = layerController.getPageSize();
|
||||
FloatRect viewportRect = mViewportController.transformVisibleRect(tileRect, pageSize);
|
||||
RectF viewportRect = mViewportController.transformVisibleRect(tileRect, pageSize);
|
||||
|
||||
/* Prevent null pointer exceptions at the start. */
|
||||
if (mGeckoVisibleRect == null)
|
||||
|
@ -234,8 +235,8 @@ public class GeckoSoftwareLayerClient extends LayerClient {
|
|||
/* Otherwise, we need to get Gecko's visible rect equal to our visible rect before we can
|
||||
* safely draw. If we're just waiting for chrome JavaScript to catch up, we do nothing.
|
||||
* This check avoids bombarding the chrome JavaScript with messages. */
|
||||
int viewportRectX = (int)Math.round(viewportRect.x);
|
||||
int viewportRectY = (int)Math.round(viewportRect.y);
|
||||
int viewportRectX = (int)Math.round(viewportRect.left);
|
||||
int viewportRectY = (int)Math.round(viewportRect.top);
|
||||
Rect panToRect = new Rect(viewportRectX, viewportRectY,
|
||||
viewportRectX + LayerController.TILE_WIDTH,
|
||||
viewportRectY + LayerController.TILE_HEIGHT);
|
||||
|
@ -258,7 +259,7 @@ public class GeckoSoftwareLayerClient extends LayerClient {
|
|||
}
|
||||
|
||||
/* Returns the dimensions of the box in page coordinates that the user is viewing. */
|
||||
private FloatRect getTransformedVisibleRect() {
|
||||
private RectF getTransformedVisibleRect() {
|
||||
LayerController layerController = getLayerController();
|
||||
return mViewportController.transformVisibleRect(layerController.getVisibleRect(),
|
||||
layerController.getPageSize());
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.Layer;
|
||||
import org.mozilla.gecko.gfx.LayerClient;
|
||||
|
@ -50,6 +49,7 @@ import android.graphics.Bitmap;
|
|||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.GestureDetector;
|
||||
|
@ -66,7 +66,7 @@ public class LayerController {
|
|||
private Layer mRootLayer; /* The root layer. */
|
||||
private LayerView mView; /* The main rendering view. */
|
||||
private Context mContext; /* The current context. */
|
||||
private FloatRect mVisibleRect; /* The current visible region. */
|
||||
private RectF mVisibleRect; /* The current visible region. */
|
||||
private IntSize mScreenSize; /* The screen size of the viewport. */
|
||||
private IntSize mPageSize; /* The current page size. */
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class LayerController {
|
|||
public LayerController(Context context) {
|
||||
mContext = context;
|
||||
|
||||
mVisibleRect = new FloatRect(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
mVisibleRect = new RectF(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
/* Gets filled in when the surface changes. */
|
||||
|
||||
mScreenSize = new IntSize(1, 1);
|
||||
|
@ -113,7 +113,7 @@ public class LayerController {
|
|||
public Layer getRoot() { return mRootLayer; }
|
||||
public LayerView getView() { return mView; }
|
||||
public Context getContext() { return mContext; }
|
||||
public FloatRect getVisibleRect() { return mVisibleRect; }
|
||||
public RectF getVisibleRect() { return mVisibleRect; }
|
||||
public IntSize getScreenSize() { return mScreenSize; }
|
||||
public IntSize getPageSize() { return mPageSize; }
|
||||
|
||||
|
@ -135,7 +135,7 @@ public class LayerController {
|
|||
* Note that the zoom factor of the layer controller differs from the zoom factor of the layer
|
||||
* client (i.e. the page).
|
||||
*/
|
||||
public float getZoomFactor() { return (float)mScreenSize.width / mVisibleRect.width; }
|
||||
public float getZoomFactor() { return (float)mScreenSize.width / mVisibleRect.width(); }
|
||||
|
||||
/**
|
||||
* The view calls this to indicate that the screen changed size.
|
||||
|
@ -148,7 +148,8 @@ public class LayerController {
|
|||
float zoomFactor = getZoomFactor(); /* Must come first. */
|
||||
|
||||
mScreenSize = new IntSize(width, height);
|
||||
setVisibleRect(mVisibleRect.x, mVisibleRect.y, width / zoomFactor, height / zoomFactor);
|
||||
setVisibleRect(mVisibleRect.left, mVisibleRect.top, width / zoomFactor,
|
||||
height / zoomFactor);
|
||||
|
||||
notifyLayerClientOfGeometryChange();
|
||||
}
|
||||
|
@ -158,11 +159,11 @@ public class LayerController {
|
|||
}
|
||||
|
||||
public void scrollTo(float x, float y) {
|
||||
setVisibleRect(x, y, mVisibleRect.width, mVisibleRect.height);
|
||||
setVisibleRect(x, y, mVisibleRect.width(), mVisibleRect.height());
|
||||
}
|
||||
|
||||
public void setVisibleRect(float x, float y, float width, float height) {
|
||||
mVisibleRect = new FloatRect(x, y, width, height);
|
||||
mVisibleRect = new RectF(x, y, x + width, y + height);
|
||||
setNeedsDisplay();
|
||||
GeckoApp.mAppContext.repositionPluginViews();
|
||||
}
|
||||
|
@ -174,10 +175,9 @@ public class LayerController {
|
|||
*/
|
||||
public void unzoom() {
|
||||
float zoomFactor = getZoomFactor();
|
||||
mVisibleRect = new FloatRect(Math.round(mVisibleRect.x * zoomFactor),
|
||||
Math.round(mVisibleRect.y * zoomFactor),
|
||||
mScreenSize.width,
|
||||
mScreenSize.height);
|
||||
float x = Math.round(mVisibleRect.left * zoomFactor);
|
||||
float y = Math.round(mVisibleRect.top * zoomFactor);
|
||||
mVisibleRect = new RectF(x, y, x + mScreenSize.width, y + mScreenSize.height);
|
||||
mPageSize = mPageSize.scale(zoomFactor);
|
||||
setNeedsDisplay();
|
||||
}
|
||||
|
@ -216,24 +216,25 @@ public class LayerController {
|
|||
return aboutToCheckerboard();
|
||||
}
|
||||
|
||||
private FloatRect getTileRect() {
|
||||
return new FloatRect(mRootLayer.origin.x, mRootLayer.origin.y, TILE_WIDTH, TILE_HEIGHT);
|
||||
private RectF getTileRect() {
|
||||
float x = mRootLayer.origin.x, y = mRootLayer.origin.y;
|
||||
return new RectF(x, y, x + TILE_WIDTH, y + TILE_HEIGHT);
|
||||
}
|
||||
|
||||
// Returns true if a checkerboard is about to be visible.
|
||||
private boolean aboutToCheckerboard() {
|
||||
Rect pageRect = new Rect(0, 0, mPageSize.width, mPageSize.height);
|
||||
Rect adjustedPageRect = RectUtils.contract(pageRect, DANGER_ZONE_X, DANGER_ZONE_Y);
|
||||
FloatRect visiblePageRect = mVisibleRect.intersect(new FloatRect(adjustedPageRect));
|
||||
FloatRect adjustedTileRect = getTileRect().contract(DANGER_ZONE_X, DANGER_ZONE_Y);
|
||||
RectF visiblePageRect = RectUtils.intersect(mVisibleRect, new RectF(adjustedPageRect));
|
||||
RectF adjustedTileRect = RectUtils.contract(getTileRect(), DANGER_ZONE_X, DANGER_ZONE_Y);
|
||||
return !adjustedTileRect.contains(visiblePageRect);
|
||||
}
|
||||
|
||||
/** Returns the given rect, clamped to the boundaries of a tile. */
|
||||
public FloatRect clampRect(FloatRect rect) {
|
||||
float x = clamp(0, rect.x, mPageSize.width - LayerController.TILE_WIDTH);
|
||||
float y = clamp(0, rect.y, mPageSize.height - LayerController.TILE_HEIGHT);
|
||||
return new FloatRect(x, y, rect.width, rect.height);
|
||||
public RectF clampRect(RectF rect) {
|
||||
float x = clamp(0, rect.left, mPageSize.width - LayerController.TILE_WIDTH);
|
||||
float y = clamp(0, rect.top, mPageSize.height - LayerController.TILE_HEIGHT);
|
||||
return new RectF(x, y, x + rect.width(), y + rect.height());
|
||||
}
|
||||
|
||||
private float clamp(float min, float value, float max) {
|
||||
|
@ -243,16 +244,16 @@ public class LayerController {
|
|||
}
|
||||
|
||||
// Returns the coordinates of a tile, scaled by the given factor, centered on the given rect.
|
||||
private static FloatRect widenRect(FloatRect rect, float scaleFactor) {
|
||||
PointF center = rect.getCenter();
|
||||
private static RectF widenRect(RectF rect, float scaleFactor) {
|
||||
PointF center = new PointF(rect.centerX(), rect.centerY());
|
||||
float halfTileWidth = TILE_WIDTH * scaleFactor / 2.0f;
|
||||
float halfTileHeight = TILE_HEIGHT * scaleFactor / 2.0f;
|
||||
return new FloatRect(center.x - halfTileWidth, center.y - halfTileHeight,
|
||||
halfTileWidth, halfTileHeight);
|
||||
return new RectF(rect.centerX() - halfTileWidth, rect.centerY() - halfTileHeight,
|
||||
rect.centerX() + halfTileWidth, rect.centerY() + halfTileHeight);
|
||||
}
|
||||
|
||||
/** Returns the coordinates of a tile centered on the given rect. */
|
||||
public static FloatRect widenRect(FloatRect rect) {
|
||||
public static RectF widenRect(RectF rect) {
|
||||
return widenRect(rect, 1.0f);
|
||||
}
|
||||
|
||||
|
@ -269,7 +270,8 @@ public class LayerController {
|
|||
|
||||
// Undo the transforms.
|
||||
PointF scaledPoint = PointUtils.scale(viewPoint, 1.0f / getZoomFactor());
|
||||
return PointUtils.subtract(PointUtils.add(mVisibleRect.getOrigin(), scaledPoint),
|
||||
return PointUtils.subtract(PointUtils.add(new PointF(mVisibleRect.left, mVisibleRect.top),
|
||||
scaledPoint),
|
||||
mRootLayer.origin);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import org.mozilla.gecko.gfx.BufferedCairoImage;
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.LayerController;
|
||||
import org.mozilla.gecko.gfx.LayerView;
|
||||
|
@ -49,6 +48,7 @@ import org.mozilla.gecko.gfx.TextLayer;
|
|||
import org.mozilla.gecko.gfx.TileLayer;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
|
@ -145,22 +145,22 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
|
|||
|
||||
private void setupPageTransform(GL10 gl) {
|
||||
LayerController controller = mView.getController();
|
||||
FloatRect visibleRect = controller.getVisibleRect();
|
||||
RectF visibleRect = controller.getVisibleRect();
|
||||
float zoomFactor = controller.getZoomFactor();
|
||||
|
||||
gl.glLoadIdentity();
|
||||
gl.glScalef(zoomFactor, zoomFactor, 1.0f);
|
||||
gl.glTranslatef(-visibleRect.x, -visibleRect.y, 0.0f);
|
||||
gl.glTranslatef(-visibleRect.left, -visibleRect.top, 0.0f);
|
||||
}
|
||||
|
||||
private Rect getPageRect() {
|
||||
LayerController controller = mView.getController();
|
||||
float zoomFactor = controller.getZoomFactor();
|
||||
FloatRect visibleRect = controller.getVisibleRect();
|
||||
RectF visibleRect = controller.getVisibleRect();
|
||||
IntSize pageSize = controller.getPageSize();
|
||||
|
||||
int x = (int)Math.round(-zoomFactor * visibleRect.x);
|
||||
int y = (int)Math.round(-zoomFactor * visibleRect.y);
|
||||
int x = (int)Math.round(-zoomFactor * visibleRect.left);
|
||||
int y = (int)Math.round(-zoomFactor * visibleRect.top);
|
||||
return new Rect(x, y,
|
||||
x + (int)Math.round(zoomFactor * pageSize.width),
|
||||
y + (int)Math.round(zoomFactor * pageSize.height));
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -62,4 +63,29 @@ public final class RectUtils {
|
|||
(int)Math.round((float)rect.right - halfLessWidth),
|
||||
(int)Math.round((float)rect.bottom - halfLessHeight));
|
||||
}
|
||||
|
||||
public static RectF contract(RectF rect, float lessWidth, float lessHeight) {
|
||||
float halfLessWidth = lessWidth / 2;
|
||||
float halfLessHeight = lessHeight / 2;
|
||||
return new RectF(rect.left + halfLessWidth,
|
||||
rect.top + halfLessHeight,
|
||||
rect.right - halfLessWidth,
|
||||
rect.bottom - halfLessHeight);
|
||||
}
|
||||
|
||||
public static RectF intersect(RectF one, RectF two) {
|
||||
float left = Math.max(one.left, two.left);
|
||||
float top = Math.max(one.top, two.top);
|
||||
float right = Math.min(one.right, two.right);
|
||||
float bottom = Math.min(one.bottom, two.bottom);
|
||||
return new RectF(left, top, Math.max(right, left), Math.max(bottom, top));
|
||||
}
|
||||
|
||||
public static RectF scale(RectF rect, float scale) {
|
||||
float x = rect.left * scale;
|
||||
float y = rect.top * scale;
|
||||
return new RectF(x, y,
|
||||
x + (rect.width() * scale),
|
||||
y + (rect.height() * scale));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,12 +38,12 @@
|
|||
package org.mozilla.gecko.ui;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.LayerController;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoEvent;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -276,16 +276,16 @@ public class PanZoomController
|
|||
// Populates the viewport info and length in the axes.
|
||||
private void populatePositionAndLength() {
|
||||
IntSize pageSize = mController.getPageSize();
|
||||
FloatRect visibleRect = mController.getVisibleRect();
|
||||
RectF visibleRect = mController.getVisibleRect();
|
||||
IntSize screenSize = mController.getScreenSize();
|
||||
|
||||
mX.setPageLength(pageSize.width);
|
||||
mX.viewportPos = visibleRect.x;
|
||||
mX.setViewportLength(visibleRect.width);
|
||||
mX.viewportPos = visibleRect.left;
|
||||
mX.setViewportLength(visibleRect.width());
|
||||
|
||||
mY.setPageLength(pageSize.height);
|
||||
mY.viewportPos = visibleRect.y;
|
||||
mY.setViewportLength(visibleRect.height);
|
||||
mY.viewportPos = visibleRect.top;
|
||||
mY.setViewportLength(visibleRect.height());
|
||||
}
|
||||
|
||||
// The callback that performs the fling animation.
|
||||
|
@ -566,11 +566,11 @@ public class PanZoomController
|
|||
@Override
|
||||
public boolean onScaleBegin(ScaleGestureDetector detector) {
|
||||
mState = PanZoomState.PINCHING;
|
||||
FloatRect initialZoomRect = mController.getVisibleRect();
|
||||
RectF initialZoomRect = mController.getVisibleRect();
|
||||
float initialZoom = mController.getZoomFactor();
|
||||
|
||||
mInitialZoomFocus = new PointF(initialZoomRect.x + (detector.getFocusX() / initialZoom),
|
||||
initialZoomRect.y + (detector.getFocusY() / initialZoom));
|
||||
mInitialZoomFocus = new PointF(initialZoomRect.left + (detector.getFocusX() / initialZoom),
|
||||
initialZoomRect.top + (detector.getFocusY() / initialZoom));
|
||||
mInitialZoomSpan = detector.getCurrentSpan() / initialZoom;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -38,16 +38,17 @@
|
|||
package org.mozilla.gecko.ui;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import android.graphics.RectF;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.LayerController;
|
||||
import org.mozilla.gecko.gfx.RectUtils;
|
||||
|
||||
/** Manages the dimensions of the page viewport. */
|
||||
public class ViewportController {
|
||||
private IntSize mPageSize;
|
||||
private FloatRect mVisibleRect;
|
||||
private RectF mVisibleRect;
|
||||
|
||||
public ViewportController(IntSize pageSize, FloatRect visibleRect) {
|
||||
public ViewportController(IntSize pageSize, RectF visibleRect) {
|
||||
mPageSize = pageSize;
|
||||
mVisibleRect = visibleRect;
|
||||
}
|
||||
|
@ -59,52 +60,51 @@ public class ViewportController {
|
|||
}
|
||||
|
||||
/** Returns the given rect, clamped to the boundaries of a tile. */
|
||||
public FloatRect clampRect(FloatRect rect) {
|
||||
float x = clamp(0, rect.x, mPageSize.width - LayerController.TILE_WIDTH);
|
||||
float y = clamp(0, rect.y, mPageSize.height - LayerController.TILE_HEIGHT);
|
||||
return new FloatRect(x, y, rect.width, rect.height);
|
||||
public RectF clampRect(RectF rect) {
|
||||
float x = clamp(0, rect.left, mPageSize.width - LayerController.TILE_WIDTH);
|
||||
float y = clamp(0, rect.top, mPageSize.height - LayerController.TILE_HEIGHT);
|
||||
return new RectF(x, y, x + rect.width(), x + rect.height());
|
||||
}
|
||||
|
||||
/** Returns the coordinates of a tile centered on the given rect. */
|
||||
public static FloatRect widenRect(FloatRect rect) {
|
||||
PointF center = rect.getCenter();
|
||||
return new FloatRect(center.x - LayerController.TILE_WIDTH / 2,
|
||||
center.y - LayerController.TILE_HEIGHT / 2,
|
||||
LayerController.TILE_WIDTH,
|
||||
LayerController.TILE_HEIGHT);
|
||||
public static RectF widenRect(RectF rect) {
|
||||
return new RectF(rect.centerX() - LayerController.TILE_WIDTH / 2,
|
||||
rect.centerY() - LayerController.TILE_HEIGHT / 2,
|
||||
rect.centerX() + LayerController.TILE_WIDTH / 2,
|
||||
rect.centerY() + LayerController.TILE_HEIGHT / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the layer controller's visible rect, page size, and screen size, returns the zoom
|
||||
* factor.
|
||||
*/
|
||||
public float getZoomFactor(FloatRect layerVisibleRect, IntSize layerPageSize,
|
||||
public float getZoomFactor(RectF layerVisibleRect, IntSize layerPageSize,
|
||||
IntSize screenSize) {
|
||||
FloatRect transformed = transformVisibleRect(layerVisibleRect, layerPageSize);
|
||||
return (float)screenSize.width / transformed.width;
|
||||
RectF transformed = transformVisibleRect(layerVisibleRect, layerPageSize);
|
||||
return (float)screenSize.width / transformed.width();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the visible rectangle that the user is viewing and the layer controller's page size,
|
||||
* returns the dimensions of the box that this corresponds to on the page.
|
||||
*/
|
||||
public FloatRect transformVisibleRect(FloatRect layerVisibleRect, IntSize layerPageSize) {
|
||||
public RectF transformVisibleRect(RectF layerVisibleRect, IntSize layerPageSize) {
|
||||
float zoomFactor = (float)layerPageSize.width / (float)mPageSize.width;
|
||||
return layerVisibleRect.scaleAll(1.0f / zoomFactor);
|
||||
return RectUtils.scale(layerVisibleRect, 1.0f / zoomFactor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the visible rectangle that the user is viewing and the layer controller's page size,
|
||||
* returns the dimensions in layer coordinates that this corresponds to.
|
||||
*/
|
||||
public FloatRect untransformVisibleRect(FloatRect viewportVisibleRect, IntSize layerPageSize) {
|
||||
public RectF untransformVisibleRect(RectF viewportVisibleRect, IntSize layerPageSize) {
|
||||
float zoomFactor = (float)layerPageSize.width / (float)mPageSize.width;
|
||||
return viewportVisibleRect.scaleAll(zoomFactor);
|
||||
return RectUtils.scale(viewportVisibleRect, zoomFactor);
|
||||
}
|
||||
|
||||
public IntSize getPageSize() { return mPageSize; }
|
||||
public void setPageSize(IntSize pageSize) { mPageSize = pageSize; }
|
||||
public FloatRect getVisibleRect() { return mVisibleRect; }
|
||||
public void setVisibleRect(FloatRect visibleRect) { mVisibleRect = visibleRect; }
|
||||
public RectF getVisibleRect() { return mVisibleRect; }
|
||||
public void setVisibleRect(RectF visibleRect) { mVisibleRect = visibleRect; }
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче