Bug 941995 - Disable double-tapping and click delay on pages that are device-width or narrower. r=mbrubeck,wesj

This commit is contained in:
Kartikaya Gupta 2014-02-24 19:21:02 -05:00
Родитель 599e862904
Коммит 47dd9a9818
3 изменённых файлов: 40 добавлений и 7 удалений

Просмотреть файл

@ -10,12 +10,14 @@ import org.json.JSONObject;
public final class ZoomConstraints { public final class ZoomConstraints {
private final boolean mAllowZoom; private final boolean mAllowZoom;
private final boolean mAllowDoubleTapZoom;
private final float mDefaultZoom; private final float mDefaultZoom;
private final float mMinZoom; private final float mMinZoom;
private final float mMaxZoom; private final float mMaxZoom;
public ZoomConstraints(boolean allowZoom) { public ZoomConstraints(boolean allowZoom) {
mAllowZoom = allowZoom; mAllowZoom = allowZoom;
mAllowDoubleTapZoom = allowZoom;
mDefaultZoom = 0.0f; mDefaultZoom = 0.0f;
mMinZoom = 0.0f; mMinZoom = 0.0f;
mMaxZoom = 0.0f; mMaxZoom = 0.0f;
@ -23,6 +25,7 @@ public final class ZoomConstraints {
ZoomConstraints(JSONObject message) throws JSONException { ZoomConstraints(JSONObject message) throws JSONException {
mAllowZoom = message.getBoolean("allowZoom"); mAllowZoom = message.getBoolean("allowZoom");
mAllowDoubleTapZoom = message.getBoolean("allowDoubleTapZoom");
mDefaultZoom = (float)message.getDouble("defaultZoom"); mDefaultZoom = (float)message.getDouble("defaultZoom");
mMinZoom = (float)message.getDouble("minZoom"); mMinZoom = (float)message.getDouble("minZoom");
mMaxZoom = (float)message.getDouble("maxZoom"); mMaxZoom = (float)message.getDouble("maxZoom");
@ -32,6 +35,10 @@ public final class ZoomConstraints {
return mAllowZoom; return mAllowZoom;
} }
public final boolean getAllowDoubleTapZoom() {
return mAllowDoubleTapZoom;
}
public final float getDefaultZoom() { public final float getDefaultZoom() {
return mDefaultZoom; return mDefaultZoom;
} }

Просмотреть файл

@ -1354,10 +1354,11 @@ class JavaPanZoomController
@Override @Override
public boolean onSingleTapUp(MotionEvent motionEvent) { public boolean onSingleTapUp(MotionEvent motionEvent) {
// When zooming is enabled, we wait to see if there's a double-tap. // When double-tapping is allowed, we have to wait to see if this is
// going to be a double-tap.
// However, if mMediumPress is true then we know there will be no // However, if mMediumPress is true then we know there will be no
// double-tap so we treat this as a click. // double-tap so we treat this as a click.
if (mMediumPress || !mTarget.getZoomConstraints().getAllowZoom()) { if (mMediumPress || !mTarget.getZoomConstraints().getAllowDoubleTapZoom()) {
sendPointToGecko("Gesture:SingleTap", motionEvent); sendPointToGecko("Gesture:SingleTap", motionEvent);
} }
// return false because we still want to get the ACTION_UP event that triggers this // return false because we still want to get the ACTION_UP event that triggers this
@ -1367,7 +1368,7 @@ class JavaPanZoomController
@Override @Override
public boolean onSingleTapConfirmed(MotionEvent motionEvent) { public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
// When zooming is disabled, we handle this in onSingleTapUp. // When zooming is disabled, we handle this in onSingleTapUp.
if (mTarget.getZoomConstraints().getAllowZoom()) { if (mTarget.getZoomConstraints().getAllowDoubleTapZoom()) {
sendPointToGecko("Gesture:SingleTap", motionEvent); sendPointToGecko("Gesture:SingleTap", motionEvent);
} }
return true; return true;
@ -1375,7 +1376,7 @@ class JavaPanZoomController
@Override @Override
public boolean onDoubleTap(MotionEvent motionEvent) { public boolean onDoubleTap(MotionEvent motionEvent) {
if (mTarget.getZoomConstraints().getAllowZoom()) { if (mTarget.getZoomConstraints().getAllowDoubleTapZoom()) {
sendPointToGecko("Gesture:DoubleTap", motionEvent); sendPointToGecko("Gesture:DoubleTap", motionEvent);
} }
return true; return true;

Просмотреть файл

@ -4041,6 +4041,7 @@ Tab.prototype = {
updateViewportMetadata: function updateViewportMetadata(aMetadata, aInitialLoad) { updateViewportMetadata: function updateViewportMetadata(aMetadata, aInitialLoad) {
if (Services.prefs.getBoolPref("browser.ui.zoom.force-user-scalable")) { if (Services.prefs.getBoolPref("browser.ui.zoom.force-user-scalable")) {
aMetadata.allowZoom = true; aMetadata.allowZoom = true;
aMetadata.allowDoubleTapZoom = true;
aMetadata.minZoom = aMetadata.maxZoom = NaN; aMetadata.minZoom = aMetadata.maxZoom = NaN;
} }
@ -4056,8 +4057,9 @@ Tab.prototype = {
aMetadata.isRTL = this.browser.contentDocument.documentElement.dir == "rtl"; aMetadata.isRTL = this.browser.contentDocument.documentElement.dir == "rtl";
ViewportHandler.setMetadataForDocument(this.browser.contentDocument, aMetadata); ViewportHandler.setMetadataForDocument(this.browser.contentDocument, aMetadata);
this.updateViewportSize(gScreenWidth, aInitialLoad);
this.sendViewportMetadata(); this.sendViewportMetadata();
this.updateViewportSize(gScreenWidth, aInitialLoad);
}, },
/** Update viewport when the metadata or the window size changes. */ /** Update viewport when the metadata or the window size changes. */
@ -4182,6 +4184,17 @@ Tab.prototype = {
this.sendViewportUpdate(); this.sendViewportUpdate();
if (metadata.allowZoom && !Services.prefs.getBoolPref("browser.ui.zoom.force-user-scalable")) {
// If the CSS viewport is narrower than the screen (i.e. width <= device-width)
// then we disable double-tap-to-zoom behaviour.
var oldAllowDoubleTapZoom = metadata.allowDoubleTapZoom;
var newAllowDoubleTapZoom = (viewportW > screenW / window.devicePixelRatio);
if (oldAllowDoubleTapZoom !== newAllowDoubleTapZoom) {
metadata.allowDoubleTapZoom = newAllowDoubleTapZoom;
this.sendViewportMetadata();
}
}
// Store the page size that was used to calculate the viewport so that we // Store the page size that was used to calculate the viewport so that we
// can verify it's changed when we consider remeasuring in updateViewportForPageSize // can verify it's changed when we consider remeasuring in updateViewportForPageSize
let viewport = this.getViewport(); let viewport = this.getViewport();
@ -4196,6 +4209,7 @@ Tab.prototype = {
sendMessageToJava({ sendMessageToJava({
type: "Tab:ViewportMetadata", type: "Tab:ViewportMetadata",
allowZoom: metadata.allowZoom, allowZoom: metadata.allowZoom,
allowDoubleTapZoom: metadata.allowDoubleTapZoom,
defaultZoom: metadata.defaultZoom || window.devicePixelRatio, defaultZoom: metadata.defaultZoom || window.devicePixelRatio,
minZoom: metadata.minZoom || 0, minZoom: metadata.minZoom || 0,
maxZoom: metadata.maxZoom || 0, maxZoom: metadata.maxZoom || 0,
@ -5878,6 +5892,11 @@ var ViewportHandler = {
let allowZoomStr = windowUtils.getDocumentMetadata("viewport-user-scalable"); let allowZoomStr = windowUtils.getDocumentMetadata("viewport-user-scalable");
let allowZoom = !/^(0|no|false)$/.test(allowZoomStr) && (minScale != maxScale); let allowZoom = !/^(0|no|false)$/.test(allowZoomStr) && (minScale != maxScale);
// Double-tap should always be disabled if allowZoom is disabled. So we initialize
// allowDoubleTapZoom to the same value as allowZoom and have additional conditions to
// disable it in updateViewportSize.
let allowDoubleTapZoom = allowZoom;
let autoSize = true; let autoSize = true;
if (isNaN(scale) && isNaN(minScale) && isNaN(maxScale) && allowZoomStr == "" && widthStr == "" && heightStr == "") { if (isNaN(scale) && isNaN(minScale) && isNaN(maxScale) && allowZoomStr == "" && widthStr == "" && heightStr == "") {
@ -5887,7 +5906,8 @@ var ViewportHandler = {
return new ViewportMetadata({ return new ViewportMetadata({
defaultZoom: 1, defaultZoom: 1,
autoSize: true, autoSize: true,
allowZoom: true allowZoom: true,
allowDoubleTapZoom: false
}); });
} }
@ -5896,7 +5916,8 @@ var ViewportHandler = {
return new ViewportMetadata({ return new ViewportMetadata({
defaultZoom: 1, defaultZoom: 1,
autoSize: true, autoSize: true,
allowZoom: true allowZoom: true,
allowDoubleTapZoom: false
}); });
} }
@ -5928,6 +5949,7 @@ var ViewportHandler = {
height: height, height: height,
autoSize: autoSize, autoSize: autoSize,
allowZoom: allowZoom, allowZoom: allowZoom,
allowDoubleTapZoom: allowDoubleTapZoom,
isSpecified: hasMetaViewport, isSpecified: hasMetaViewport,
isRTL: isRTL isRTL: isRTL
}); });
@ -5971,6 +5993,7 @@ var ViewportHandler = {
* maxZoom (float): The maximum zoom level. * maxZoom (float): The maximum zoom level.
* autoSize (boolean): Resize the CSS viewport when the window resizes. * autoSize (boolean): Resize the CSS viewport when the window resizes.
* allowZoom (boolean): Let the user zoom in or out. * allowZoom (boolean): Let the user zoom in or out.
* allowDoubleTapZoom (boolean): Allow double-tap to zoom in.
* isSpecified (boolean): Whether the page viewport is specified or not. * isSpecified (boolean): Whether the page viewport is specified or not.
*/ */
function ViewportMetadata(aMetadata = {}) { function ViewportMetadata(aMetadata = {}) {
@ -5981,6 +6004,7 @@ function ViewportMetadata(aMetadata = {}) {
this.maxZoom = ("maxZoom" in aMetadata) ? aMetadata.maxZoom : 0; this.maxZoom = ("maxZoom" in aMetadata) ? aMetadata.maxZoom : 0;
this.autoSize = ("autoSize" in aMetadata) ? aMetadata.autoSize : false; this.autoSize = ("autoSize" in aMetadata) ? aMetadata.autoSize : false;
this.allowZoom = ("allowZoom" in aMetadata) ? aMetadata.allowZoom : true; this.allowZoom = ("allowZoom" in aMetadata) ? aMetadata.allowZoom : true;
this.allowDoubleTapZoom = ("allowDoubleTapZoom" in aMetadata) ? aMetadata.allowDoubleTapZoom : true;
this.isSpecified = ("isSpecified" in aMetadata) ? aMetadata.isSpecified : false; this.isSpecified = ("isSpecified" in aMetadata) ? aMetadata.isSpecified : false;
this.isRTL = ("isRTL" in aMetadata) ? aMetadata.isRTL : false; this.isRTL = ("isRTL" in aMetadata) ? aMetadata.isRTL : false;
Object.seal(this); Object.seal(this);
@ -5994,6 +6018,7 @@ ViewportMetadata.prototype = {
maxZoom: null, maxZoom: null,
autoSize: null, autoSize: null,
allowZoom: null, allowZoom: null,
allowDoubleTapZoom: null,
isSpecified: null, isSpecified: null,
isRTL: null, isRTL: null,
}; };