Bug 777075 - Extract a ZoomConstraints class to carry around the pieces of data that are otherwise floating around Tab and LayerController. r=mbrubeck

This commit is contained in:
Kartikaya Gupta 2012-08-07 10:39:03 -04:00
parent 2908c132a4
commit 148fa116dc
7 changed files with 83 additions and 94 deletions

View File

@ -685,10 +685,7 @@ abstract public class GeckoApp
tab.updateTitle(null);
tab.updateIdentityData(null);
tab.setReaderEnabled(false);
tab.setAllowZoom(true);
tab.setDefaultZoom(0);
tab.setMinZoom(0);
tab.setMaxZoom(0);
tab.setZoomConstraints(new ZoomConstraints(true));
tab.setHasTouchListeners(false);
tab.setCheckerboardColor(Color.WHITE);
@ -1004,17 +1001,11 @@ abstract public class GeckoApp
Tab tab = Tabs.getInstance().getTab(tabId);
if (tab == null)
return;
tab.setAllowZoom(message.getBoolean("allowZoom"));
tab.setDefaultZoom((float) message.getDouble("defaultZoom"));
tab.setMinZoom((float) message.getDouble("minZoom"));
tab.setMaxZoom((float) message.getDouble("maxZoom"));
tab.setZoomConstraints(new ZoomConstraints(message));
// Sync up the LayerController and the tab if the tab's currently displayed.
LayerController controller = getLayerController();
if (controller != null && Tabs.getInstance().isSelectedTab(tab)) {
controller.setAllowZoom(tab.getAllowZoom());
controller.setDefaultZoom(tab.getDefaultZoom());
controller.setMinZoom(tab.getMinZoom());
controller.setMaxZoom(tab.getMaxZoom());
controller.setZoomConstraints(tab.getZoomConstraints());
}
} else if (event.equals("Tab:HasTouchListener")) {
int tabId = message.getInt("tabID");

View File

@ -113,6 +113,7 @@ FENNEC_JAVA_FILES = \
TextSelection.java \
TextSelectionHandle.java \
WebAppAllocator.java \
ZoomConstraints.java \
gfx/BitmapUtils.java \
gfx/BufferedCairoImage.java \
gfx/CairoGLInfo.java \

View File

@ -54,10 +54,7 @@ public final class Tab {
private String mDocumentURI;
private String mContentType;
private boolean mHasTouchListeners;
private boolean mAllowZoom;
private float mDefaultZoom;
private float mMinZoom;
private float mMaxZoom;
private ZoomConstraints mZoomConstraints;
private ArrayList<View> mPluginViews;
private HashMap<Object, Layer> mPluginLayers;
private ContentResolver mContentResolver;
@ -92,6 +89,7 @@ public final class Tab {
mFaviconLoadId = 0;
mDocumentURI = "";
mContentType = "";
mZoomConstraints = new ZoomConstraints(false);
mPluginViews = new ArrayList<View>();
mPluginLayers = new HashMap<Object, Layer>();
mState = "about:home".equals(url) ? STATE_SUCCESS : STATE_LOADING;
@ -282,36 +280,12 @@ public final class Tab {
return mState;
}
public void setAllowZoom(boolean aValue) {
mAllowZoom = aValue;
public void setZoomConstraints(ZoomConstraints constraints) {
mZoomConstraints = constraints;
}
public boolean getAllowZoom() {
return mAllowZoom;
}
public void setDefaultZoom(float aValue) {
mDefaultZoom = aValue;
}
public float getDefaultZoom() {
return mDefaultZoom;
}
public void setMinZoom(float aValue) {
mMinZoom = aValue;
}
public float getMinZoom() {
return mMinZoom;
}
public void setMaxZoom(float aValue) {
mMaxZoom = aValue;
}
public float getMaxZoom() {
return mMaxZoom;
public ZoomConstraints getZoomConstraints() {
return mZoomConstraints;
}
public void setHasTouchListeners(boolean aValue) {

View File

@ -0,0 +1,46 @@
/* -*- 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;
import org.json.JSONException;
import org.json.JSONObject;
public final class ZoomConstraints {
private final boolean mAllowZoom;
private final float mDefaultZoom;
private final float mMinZoom;
private final float mMaxZoom;
public ZoomConstraints(boolean allowZoom) {
mAllowZoom = allowZoom;
mDefaultZoom = 0.0f;
mMinZoom = 0.0f;
mMaxZoom = 0.0f;
}
ZoomConstraints(JSONObject message) throws JSONException {
mAllowZoom = message.getBoolean("allowZoom");
mDefaultZoom = (float)message.getDouble("defaultZoom");
mMinZoom = (float)message.getDouble("minZoom");
mMaxZoom = (float)message.getDouble("maxZoom");
}
public final boolean getAllowZoom() {
return mAllowZoom;
}
public final float getDefaultZoom() {
return mDefaultZoom;
}
public final float getMinZoom() {
return mMinZoom;
}
public final float getMaxZoom() {
return mMaxZoom;
}
}

View File

@ -336,10 +336,7 @@ public class GeckoLayerClient implements GeckoEventResponder, LayerView.Listener
Tab tab = Tabs.getInstance().getSelectedTab();
mLayerController.setCheckerboardColor(tab.getCheckerboardColor());
mLayerController.setAllowZoom(tab.getAllowZoom());
mLayerController.setDefaultZoom(tab.getDefaultZoom());
mLayerController.setMinZoom(tab.getMinZoom());
mLayerController.setMaxZoom(tab.getMaxZoom());
mLayerController.setZoomConstraints(tab.getZoomConstraints());
// At this point, we have just switched to displaying a different document than we
// we previously displaying. This means we need to abort any panning/zooming animations

View File

@ -5,6 +5,7 @@
package org.mozilla.gecko.gfx;
import org.mozilla.gecko.ZoomConstraints;
import org.mozilla.gecko.ui.PanZoomController;
import org.mozilla.gecko.ui.SimpleScaleGestureDetector;
@ -57,10 +58,7 @@ public class LayerController {
private int mCheckerboardColor = Color.WHITE;
private boolean mCheckerboardShouldShowChecks;
private boolean mAllowZoom;
private float mDefaultZoom;
private float mMinZoom;
private float mMaxZoom;
private ZoomConstraints mZoomConstraints;
private boolean mForceRedraw;
@ -71,6 +69,7 @@ public class LayerController {
mViewportMetrics = new ImmutableViewportMetrics(new ViewportMetrics(displayMetrics));
mPanZoomController = new PanZoomController(this);
mCheckerboardShouldShowChecks = true;
mZoomConstraints = new ZoomConstraints(false);
}
public void setView(LayerView v) {
@ -312,35 +311,11 @@ public class LayerController {
mView.requestRender();
}
public void setAllowZoom(final boolean aValue) {
mAllowZoom = aValue;
public void setZoomConstraints(ZoomConstraints constraints) {
mZoomConstraints = constraints;
}
public boolean getAllowZoom() {
return mAllowZoom;
}
public void setDefaultZoom(float aValue) {
mDefaultZoom = aValue;
}
public float getDefaultZoom() {
return mDefaultZoom;
}
public void setMinZoom(float aValue) {
mMinZoom = aValue;
}
public float getMinZoom() {
return mMinZoom;
}
public void setMaxZoom(float aValue) {
mMaxZoom = aValue;
}
public float getMaxZoom() {
return mMaxZoom;
public ZoomConstraints getZoomConstraints() {
return mZoomConstraints;
}
}

View File

@ -9,6 +9,7 @@ import org.mozilla.gecko.GeckoApp;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoEventListener;
import org.mozilla.gecko.ZoomConstraints;
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
import org.mozilla.gecko.gfx.LayerController;
import org.mozilla.gecko.gfx.PointUtils;
@ -795,14 +796,16 @@ public class PanZoomController
float minZoomFactor = 0.0f;
float maxZoomFactor = MAX_ZOOM;
if (mController.getMinZoom() > 0)
minZoomFactor = mController.getMinZoom();
if (mController.getMaxZoom() > 0)
maxZoomFactor = mController.getMaxZoom();
ZoomConstraints constraints = mController.getZoomConstraints();
if (!mController.getAllowZoom()) {
if (constraints.getMinZoom() > 0)
minZoomFactor = constraints.getMinZoom();
if (constraints.getMaxZoom() > 0)
maxZoomFactor = constraints.getMaxZoom();
if (!constraints.getAllowZoom()) {
// If allowZoom is false, clamp to the default zoom level.
maxZoomFactor = minZoomFactor = mController.getDefaultZoom();
maxZoomFactor = minZoomFactor = constraints.getDefaultZoom();
}
// Ensure minZoomFactor keeps the page at least as big as the viewport.
@ -872,7 +875,7 @@ public class PanZoomController
if (mState == PanZoomState.ANIMATED_ZOOM)
return false;
if (!mController.getAllowZoom())
if (!mController.getZoomConstraints().getAllowZoom())
return false;
setState(PanZoomState.PINCHING);
@ -913,10 +916,12 @@ public class PanZoomController
float minZoomFactor = 0.0f;
float maxZoomFactor = MAX_ZOOM;
if (mController.getMinZoom() > 0)
minZoomFactor = mController.getMinZoom();
if (mController.getMaxZoom() > 0)
maxZoomFactor = mController.getMaxZoom();
ZoomConstraints constraints = mController.getZoomConstraints();
if (constraints.getMinZoom() > 0)
minZoomFactor = constraints.getMinZoom();
if (constraints.getMaxZoom() > 0)
maxZoomFactor = constraints.getMaxZoom();
if (newZoomFactor < minZoomFactor) {
// apply resistance when zooming past minZoomFactor,
@ -1001,7 +1006,7 @@ public class PanZoomController
@Override
public boolean onSingleTapUp(MotionEvent motionEvent) {
// When zooming is enabled, wait to see if there's a double-tap.
if (!mController.getAllowZoom()) {
if (!mController.getZoomConstraints().getAllowZoom()) {
sendPointToGecko("Gesture:SingleTap", motionEvent);
}
// return false because we still want to get the ACTION_UP event that triggers this
@ -1011,7 +1016,7 @@ public class PanZoomController
@Override
public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
// When zooming is disabled, we handle this in onSingleTapUp.
if (mController.getAllowZoom()) {
if (mController.getZoomConstraints().getAllowZoom()) {
sendPointToGecko("Gesture:SingleTap", motionEvent);
}
return true;
@ -1019,7 +1024,7 @@ public class PanZoomController
@Override
public boolean onDoubleTap(MotionEvent motionEvent) {
if (mController.getAllowZoom()) {
if (mController.getZoomConstraints().getAllowZoom()) {
sendPointToGecko("Gesture:DoubleTap", motionEvent);
}
return true;