mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 702416 - Replace IntRect with android.graphics.Rect [r=pcwalton]
This commit is contained in:
parent
419a047fb6
commit
309c4ec3c6
@ -42,11 +42,11 @@ package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.gfx.GeckoSoftwareLayerClient;
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.LayerController;
|
||||
import org.mozilla.gecko.gfx.LayerView;
|
||||
import org.mozilla.gecko.gfx.PlaceholderLayerClient;
|
||||
import org.mozilla.gecko.gfx.RectUtils;
|
||||
import org.mozilla.gecko.Tab.HistoryEntry;
|
||||
|
||||
import java.io.*;
|
||||
@ -751,7 +751,7 @@ abstract public class GeckoApp
|
||||
});
|
||||
connectGeckoLayerClient();
|
||||
} else if (event.equals("PanZoom:Ack")) {
|
||||
final IntRect rect = new IntRect(message.getJSONObject("rect"));
|
||||
Rect rect = RectUtils.create(message.getJSONObject("rect"));
|
||||
mSoftwareLayerClient.jsPanZoomCompleted(rect);
|
||||
} else if (event.equals("PanZoom:Resize")) {
|
||||
IntSize size = new IntSize(message.getJSONObject("size"));
|
||||
|
@ -76,7 +76,6 @@ JAVAFILES = \
|
||||
gfx/FloatRect.java \
|
||||
gfx/GeckoSoftwareLayerClient.java \
|
||||
gfx/InputConnectionHandler.java \
|
||||
gfx/IntRect.java \
|
||||
gfx/IntSize.java \
|
||||
gfx/Layer.java \
|
||||
gfx/LayerClient.java \
|
||||
@ -86,6 +85,7 @@ JAVAFILES = \
|
||||
gfx/NinePatchTileLayer.java \
|
||||
gfx/PlaceholderLayerClient.java \
|
||||
gfx/PointUtils.java \
|
||||
gfx/RectUtils.java \
|
||||
gfx/SingleTileLayer.java \
|
||||
gfx/TextureReaper.java \
|
||||
gfx/TextLayer.java \
|
||||
|
@ -38,7 +38,7 @@
|
||||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import org.mozilla.gecko.gfx.IntRect;
|
||||
import android.graphics.Rect;
|
||||
|
||||
public class FloatRect {
|
||||
public final float x, y, width, height;
|
||||
@ -47,8 +47,8 @@ public class FloatRect {
|
||||
x = inX; y = inY; width = inWidth; height = inHeight;
|
||||
}
|
||||
|
||||
public FloatRect(IntRect intRect) {
|
||||
x = intRect.x; y = intRect.y; width = intRect.width; height = intRect.height;
|
||||
public FloatRect(Rect intRect) {
|
||||
x = intRect.left; y = intRect.top; width = intRect.width(); height = intRect.height();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +39,6 @@ package org.mozilla.gecko.gfx;
|
||||
|
||||
import org.mozilla.gecko.gfx.CairoImage;
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.LayerClient;
|
||||
import org.mozilla.gecko.gfx.LayerController;
|
||||
@ -51,6 +50,7 @@ import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.GeckoEvent;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.util.Log;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.Semaphore;
|
||||
@ -74,7 +74,7 @@ public class GeckoSoftwareLayerClient extends LayerClient {
|
||||
private FloatRect mGeckoVisibleRect;
|
||||
/* The viewport rect that Gecko is currently displaying. */
|
||||
|
||||
private IntRect mJSPanningToRect;
|
||||
private Rect mJSPanningToRect;
|
||||
/* The rect that we just told chrome JavaScript to pan to. */
|
||||
|
||||
private boolean mWaitingForJSPanZoom;
|
||||
@ -155,15 +155,15 @@ public class GeckoSoftwareLayerClient extends LayerClient {
|
||||
mTileLayer.origin = layerRect.getOrigin();
|
||||
}
|
||||
|
||||
repaint(new IntRect(x, y, width, height));
|
||||
repaint(new Rect(x, y, x + width, y + height));
|
||||
}
|
||||
|
||||
private void repaint(IntRect rect) {
|
||||
private void repaint(Rect rect) {
|
||||
mTileLayer.paintSubimage(mCairoImage, rect);
|
||||
}
|
||||
|
||||
/** Called whenever the chrome JS finishes panning or zooming to some location. */
|
||||
public void jsPanZoomCompleted(IntRect rect) {
|
||||
public void jsPanZoomCompleted(Rect rect) {
|
||||
mGeckoVisibleRect = new FloatRect(rect);
|
||||
if (mWaitingForJSPanZoom)
|
||||
render();
|
||||
@ -234,10 +234,11 @@ 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. */
|
||||
IntRect panToRect = new IntRect((int)Math.round(viewportRect.x),
|
||||
(int)Math.round(viewportRect.y),
|
||||
LayerController.TILE_WIDTH,
|
||||
LayerController.TILE_HEIGHT);
|
||||
int viewportRectX = (int)Math.round(viewportRect.x);
|
||||
int viewportRectY = (int)Math.round(viewportRect.y);
|
||||
Rect panToRect = new Rect(viewportRectX, viewportRectY,
|
||||
viewportRectX + LayerController.TILE_WIDTH,
|
||||
viewportRectY + LayerController.TILE_HEIGHT);
|
||||
|
||||
if (mWaitingForJSPanZoom && mJSPanningToRect != null &&
|
||||
mJSPanningToRect.equals(panToRect)) {
|
||||
@ -248,8 +249,8 @@ public class GeckoSoftwareLayerClient extends LayerClient {
|
||||
* set a flag to remind us to try the redraw again. */
|
||||
|
||||
GeckoAppShell.sendEventToGecko(new GeckoEvent("PanZoom:PanZoom",
|
||||
"{\"x\": " + panToRect.x + ", \"y\": " + panToRect.y +
|
||||
", \"width\": " + panToRect.width + ", \"height\": " + panToRect.height +
|
||||
"{\"x\": " + panToRect.left + ", \"y\": " + panToRect.top +
|
||||
", \"width\": " + panToRect.width() + ", \"height\": " + panToRect.height() +
|
||||
", \"zoomFactor\": " + getZoomFactor() + "}"));
|
||||
|
||||
mJSPanningToRect = panToRect;
|
||||
|
@ -37,7 +37,6 @@
|
||||
|
||||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import org.mozilla.gecko.gfx.IntRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.LayerController;
|
||||
|
||||
|
@ -38,7 +38,6 @@
|
||||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.Layer;
|
||||
import org.mozilla.gecko.gfx.LayerClient;
|
||||
@ -50,6 +49,7 @@ import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.GestureDetector;
|
||||
@ -222,8 +222,8 @@ public class LayerController {
|
||||
|
||||
// Returns true if a checkerboard is about to be visible.
|
||||
private boolean aboutToCheckerboard() {
|
||||
IntRect pageRect = new IntRect(0, 0, mPageSize.width, mPageSize.height);
|
||||
IntRect adjustedPageRect = pageRect.contract(DANGER_ZONE_X, DANGER_ZONE_Y);
|
||||
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);
|
||||
return !adjustedTileRect.contains(visiblePageRect);
|
||||
|
@ -39,7 +39,6 @@ package org.mozilla.gecko.gfx;
|
||||
|
||||
import org.mozilla.gecko.gfx.BufferedCairoImage;
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntRect;
|
||||
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.TextureReaper;
|
||||
import org.mozilla.gecko.gfx.TextLayer;
|
||||
import org.mozilla.gecko.gfx.TileLayer;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
@ -114,11 +114,11 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
|
||||
mShadowLayer.draw(gl);
|
||||
|
||||
/* Draw the checkerboard. */
|
||||
IntRect pageRect = clampToScreen(getPageRect());
|
||||
Rect pageRect = clampToScreen(getPageRect());
|
||||
IntSize screenSize = controller.getScreenSize();
|
||||
gl.glEnable(GL10.GL_SCISSOR_TEST);
|
||||
gl.glScissor(pageRect.x, screenSize.height - (pageRect.y + pageRect.height),
|
||||
pageRect.width, pageRect.height);
|
||||
gl.glScissor(pageRect.left, screenSize.height - pageRect.bottom,
|
||||
pageRect.width(), pageRect.height());
|
||||
|
||||
gl.glLoadIdentity();
|
||||
mCheckerboardLayer.draw(gl);
|
||||
@ -153,27 +153,28 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
|
||||
gl.glTranslatef(-visibleRect.x, -visibleRect.y, 0.0f);
|
||||
}
|
||||
|
||||
private IntRect getPageRect() {
|
||||
private Rect getPageRect() {
|
||||
LayerController controller = mView.getController();
|
||||
float zoomFactor = controller.getZoomFactor();
|
||||
FloatRect visibleRect = controller.getVisibleRect();
|
||||
IntSize pageSize = controller.getPageSize();
|
||||
|
||||
return new IntRect((int)Math.round(-zoomFactor * visibleRect.x),
|
||||
(int)Math.round(-zoomFactor * visibleRect.y),
|
||||
(int)Math.round(zoomFactor * pageSize.width),
|
||||
(int)Math.round(zoomFactor * pageSize.height));
|
||||
int x = (int)Math.round(-zoomFactor * visibleRect.x);
|
||||
int y = (int)Math.round(-zoomFactor * visibleRect.y);
|
||||
return new Rect(x, y,
|
||||
x + (int)Math.round(zoomFactor * pageSize.width),
|
||||
y + (int)Math.round(zoomFactor * pageSize.height));
|
||||
}
|
||||
|
||||
private IntRect clampToScreen(IntRect rect) {
|
||||
private Rect clampToScreen(Rect rect) {
|
||||
LayerController controller = mView.getController();
|
||||
IntSize screenSize = controller.getScreenSize();
|
||||
|
||||
int left = Math.max(0, rect.x);
|
||||
int top = Math.max(0, rect.y);
|
||||
int right = Math.min(screenSize.width, rect.getRight());
|
||||
int bottom = Math.min(screenSize.height, rect.getBottom());
|
||||
return new IntRect(left, top, right - left, bottom - top);
|
||||
int left = Math.max(0, rect.left);
|
||||
int top = Math.max(0, rect.top);
|
||||
int right = Math.min(screenSize.width, rect.right);
|
||||
int bottom = Math.min(screenSize.height, rect.bottom);
|
||||
return new Rect(left, top, right, bottom);
|
||||
}
|
||||
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||
|
@ -15,11 +15,11 @@
|
||||
* 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
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick Walton <pcwalton@mozilla.com>
|
||||
* Kartikaya Gupta <kgupta@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
|
||||
@ -37,58 +37,29 @@
|
||||
|
||||
package org.mozilla.gecko.gfx;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class IntRect implements Cloneable {
|
||||
public final int x, y, width, height;
|
||||
|
||||
public IntRect(int inX, int inY, int inWidth, int inHeight) {
|
||||
x = inX; y = inY; width = inWidth; height = inHeight;
|
||||
}
|
||||
|
||||
public IntRect(JSONObject json) {
|
||||
public final class RectUtils {
|
||||
public static Rect create(JSONObject json) {
|
||||
try {
|
||||
x = json.getInt("x");
|
||||
y = json.getInt("y");
|
||||
width = json.getInt("width");
|
||||
height = json.getInt("height");
|
||||
int x = json.getInt("x");
|
||||
int y = json.getInt("y");
|
||||
int width = json.getInt("width");
|
||||
int height = json.getInt("height");
|
||||
return new Rect(x, y, x + width, y + height);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() { return new IntRect(x, y, width, height); }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof IntRect))
|
||||
return false;
|
||||
IntRect otherRect = (IntRect)other;
|
||||
return x == otherRect.x && y == otherRect.y && width == otherRect.width &&
|
||||
height == otherRect.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() { return "(" + x + "," + y + "," + width + "," + height + ")"; }
|
||||
|
||||
public Point getOrigin() { return new Point(x, y); }
|
||||
public Point getCenter() { return new Point(x + width / 2, y + height / 2); }
|
||||
|
||||
public int getRight() { return x + width; }
|
||||
public int getBottom() { return y + height; }
|
||||
|
||||
/** Contracts a rectangle by the given number of units in each direction, from the center. */
|
||||
public IntRect contract(int lessWidth, int lessHeight) {
|
||||
float halfWidth = width / 2.0f - lessWidth, halfHeight = height / 2.0f - lessHeight;
|
||||
Point center = getCenter();
|
||||
return new IntRect((int)Math.round((float)center.x - halfWidth),
|
||||
(int)Math.round((float)center.y - halfHeight),
|
||||
(int)Math.round(halfWidth * 2.0f),
|
||||
(int)Math.round(halfHeight * 2.0f));
|
||||
public static Rect contract(Rect rect, int lessWidth, int lessHeight) {
|
||||
float halfLessWidth = (float)lessWidth / 2.0f;
|
||||
float halfLessHeight = (float)lessHeight / 2.0f;
|
||||
return new Rect((int)Math.round((float)rect.left + halfLessWidth),
|
||||
(int)Math.round((float)rect.top + halfLessHeight),
|
||||
(int)Math.round((float)rect.right - halfLessWidth),
|
||||
(int)Math.round((float)rect.bottom - halfLessHeight));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ import org.mozilla.gecko.gfx.CairoImage;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.Layer;
|
||||
import org.mozilla.gecko.gfx.TextureReaper;
|
||||
import android.graphics.Rect;
|
||||
import android.util.Log;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
import java.nio.Buffer;
|
||||
@ -58,8 +59,12 @@ public abstract class TileLayer extends Layer {
|
||||
private IntSize mSize;
|
||||
private int[] mTextureIDs;
|
||||
|
||||
private IntRect mTextureUploadRect;
|
||||
/* The rect that needs to be uploaded to the texture. */
|
||||
/* The rect that needs to be uploaded to the texture.
|
||||
* This field should not be exposed to other classes, since it is
|
||||
* mutated by calls to union(), and this may lead to odd behavior
|
||||
* if other classes assume it is immutable.
|
||||
*/
|
||||
private Rect mTextureUploadRect;
|
||||
|
||||
public TileLayer(boolean repeat) {
|
||||
super();
|
||||
@ -102,7 +107,7 @@ public abstract class TileLayer extends Layer {
|
||||
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
public void paintSubimage(CairoImage image, IntRect rect) {
|
||||
public void paintSubimage(CairoImage image, Rect rect) {
|
||||
mImage = image;
|
||||
mTextureUploadRect = rect;
|
||||
|
||||
@ -116,7 +121,7 @@ public abstract class TileLayer extends Layer {
|
||||
}
|
||||
|
||||
public void paintImage(CairoImage image) {
|
||||
paintSubimage(image, new IntRect(0, 0, image.getWidth(), image.getHeight()));
|
||||
paintSubimage(image, new Rect(0, 0, image.getWidth(), image.getHeight()));
|
||||
}
|
||||
|
||||
private void uploadTexture(GL10 gl) {
|
||||
@ -156,10 +161,10 @@ public abstract class TileLayer extends Layer {
|
||||
*/
|
||||
Buffer viewBuffer = buffer.slice();
|
||||
int bpp = CairoUtils.bitsPerPixelForCairoFormat(cairoFormat) / 8;
|
||||
viewBuffer.position(mTextureUploadRect.y * width * bpp);
|
||||
viewBuffer.position(mTextureUploadRect.top * width * bpp);
|
||||
|
||||
gl.glTexSubImage2D(gl.GL_TEXTURE_2D,
|
||||
0, 0, mTextureUploadRect.y, width, mTextureUploadRect.height,
|
||||
0, 0, mTextureUploadRect.top, width, mTextureUploadRect.height(),
|
||||
format, type, viewBuffer);
|
||||
}
|
||||
} finally {
|
||||
|
@ -39,7 +39,6 @@ package org.mozilla.gecko.ui;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.LayerController;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
|
@ -39,7 +39,6 @@ package org.mozilla.gecko.ui;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import org.mozilla.gecko.gfx.FloatRect;
|
||||
import org.mozilla.gecko.gfx.IntRect;
|
||||
import org.mozilla.gecko.gfx.IntSize;
|
||||
import org.mozilla.gecko.gfx.LayerController;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user