Bug 809199 - Switch mGeckoViewport to be an ImmutableViewportMetrics instead of a ViewportMetrics. r=Cwiiis

This commit is contained in:
Kartikaya Gupta 2012-11-07 11:47:08 -05:00
parent 15548d7f45
commit baa905f00d

View File

@ -58,7 +58,7 @@ public class GeckoLayerClient
* to the Gecko viewport position. Note that if Gecko updates its viewport independently,
* we get notified synchronously and also update this on the UI thread.
*/
private ViewportMetrics mGeckoViewport;
private ImmutableViewportMetrics mGeckoViewport;
/*
* The viewport metrics being used to draw the current frame. This is only
@ -275,7 +275,7 @@ public class GeckoLayerClient
}
mDisplayPort = displayPort;
mGeckoViewport = new ViewportMetrics(clampedMetrics);
mGeckoViewport = clampedMetrics;
if (mRecordDrawTimes) {
mDrawTimingQueue.add(displayPort);
@ -308,15 +308,15 @@ public class GeckoLayerClient
/** Viewport message handler. */
private DisplayPortMetrics handleViewportMessage(ViewportMetrics messageMetrics, ViewportMessageType type) {
synchronized (this) {
final ViewportMetrics newMetrics;
ViewportMetrics metrics;
ImmutableViewportMetrics oldMetrics = getViewportMetrics();
switch (type) {
default:
case UPDATE:
newMetrics = messageMetrics;
metrics = messageMetrics;
// Keep the old viewport size
newMetrics.setSize(oldMetrics.getSize());
metrics.setSize(oldMetrics.getSize());
abortPanZoomAnimation();
break;
case PAGE_SIZE:
@ -324,17 +324,18 @@ public class GeckoLayerClient
// between the rendered content (which is what Gecko tells us)
// and our zoom level (which may have diverged).
float scaleFactor = oldMetrics.zoomFactor / messageMetrics.getZoomFactor();
newMetrics = new ViewportMetrics(oldMetrics);
newMetrics.setPageRect(RectUtils.scale(messageMetrics.getPageRect(), scaleFactor), messageMetrics.getCssPageRect());
metrics = new ViewportMetrics(oldMetrics);
metrics.setPageRect(RectUtils.scale(messageMetrics.getPageRect(), scaleFactor), messageMetrics.getCssPageRect());
break;
}
final ImmutableViewportMetrics newMetrics = new ImmutableViewportMetrics(metrics);
post(new Runnable() {
public void run() {
mGeckoViewport = newMetrics;
}
});
setViewportMetrics(new ImmutableViewportMetrics(newMetrics), type == ViewportMessageType.UPDATE);
setViewportMetrics(newMetrics, type == ViewportMessageType.UPDATE);
mDisplayPort = DisplayPortCalculator.calculate(getViewportMetrics(), null);
}
return mDisplayPort;
@ -467,21 +468,22 @@ public class GeckoLayerClient
float pageLeft, float pageTop, float pageRight, float pageBottom,
float cssPageLeft, float cssPageTop, float cssPageRight, float cssPageBottom) {
synchronized (this) {
final ViewportMetrics currentMetrics = new ViewportMetrics(getViewportMetrics());
ViewportMetrics currentMetrics = new ViewportMetrics(getViewportMetrics());
currentMetrics.setOrigin(new PointF(offsetX, offsetY));
currentMetrics.setZoomFactor(zoom);
currentMetrics.setPageRect(new RectF(pageLeft, pageTop, pageRight, pageBottom),
new RectF(cssPageLeft, cssPageTop, cssPageRight, cssPageBottom));
final ImmutableViewportMetrics newMetrics = new ImmutableViewportMetrics(currentMetrics);
// Since we have switched to displaying a different document, we need to update any
// viewport-related state we have lying around. This includes mGeckoViewport and
// mViewportMetrics. Usually this information is updated via handleViewportMessage
// while we remain on the same document.
post(new Runnable() {
public void run() {
mGeckoViewport = currentMetrics;
mGeckoViewport = newMetrics;
}
});
setViewportMetrics(new ImmutableViewportMetrics(currentMetrics));
setViewportMetrics(newMetrics);
Tab tab = Tabs.getInstance().getSelectedTab();
mView.setCheckerboardColor(tab.getCheckerboardColor());
@ -719,9 +721,9 @@ public class GeckoLayerClient
ImmutableViewportMetrics viewportMetrics = mViewportMetrics;
PointF origin = viewportMetrics.getOrigin();
float zoom = viewportMetrics.zoomFactor;
ViewportMetrics geckoViewport = mGeckoViewport;
ImmutableViewportMetrics geckoViewport = mGeckoViewport;
PointF geckoOrigin = geckoViewport.getOrigin();
float geckoZoom = geckoViewport.getZoomFactor();
float geckoZoom = geckoViewport.zoomFactor;
// viewPoint + origin gives the coordinate in device pixels from the top-left corner of the page.
// Divided by zoom, this gives us the coordinate in CSS pixels from the top-left corner of the page.