deleted file mode 100644
--- a/mobile/android/chrome/content/ZoomHelper.js
+++ /dev/null
@@ -1,101 +0,0 @@
-/* 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/. */
-"use strict";
-
-var ZoomHelper = {
- zoomOut: function() {
- Messaging.sendRequest({ type: "Browser:ZoomToPageWidth" });
- },
-
- isRectZoomedIn: function(aRect, aViewport) {
- // This function checks to see if the area of the rect visible in the
- // viewport (i.e. the "overlapArea" variable below) is approximately
- // the max area of the rect we can show. It also checks that the rect
- // is actually on-screen by testing the left and right edges of the rect.
- // In effect, this tells us whether or not zooming in to this rect
- // will significantly change what the user is seeing.
- const minDifference = -20;
- const maxDifference = 20;
- const maxZoomAllowed = 4; // keep this in sync with mobile/android/base/ui/PanZoomController.MAX_ZOOM
-
- let vRect = new Rect(aViewport.cssX, aViewport.cssY, aViewport.cssWidth, aViewport.cssHeight);
- let overlap = vRect.intersect(aRect);
- let overlapArea = overlap.width * overlap.height;
- let availHeight = Math.min(aRect.width * vRect.height / vRect.width, aRect.height);
- let showing = overlapArea / (aRect.width * availHeight);
- let dw = (aRect.width - vRect.width);
- let dx = (aRect.x - vRect.x);
-
- if (fuzzyEquals(aViewport.zoom, maxZoomAllowed) && overlap.width / aRect.width > 0.9) {
- // we're already at the max zoom and the block is not spilling off the side of the screen so that even
- // if the block isn't taking up most of the viewport we can't pan/zoom in any more. return true so that we zoom out
- return true;
- }
-
- return (showing > 0.9 &&
- dx > minDifference && dx < maxDifference &&
- dw > minDifference && dw < maxDifference);
- },
-
- /* Zoom to an element, optionally keeping a particular part of it
- * in view if it is really tall.
- */
- zoomToElement: function(aElement, aClickY = -1, aCanZoomOut = true, aCanScrollHorizontally = true) {
- let rect = ElementTouchHelper.getBoundingContentRect(aElement);
-
- const margin = 15;
-
-
- let viewport = BrowserApp.selectedTab.getViewport();
- rect = new Rect(aCanScrollHorizontally ? Math.max(viewport.cssPageLeft, rect.x - margin) : viewport.cssX,
- rect.y,
- aCanScrollHorizontally ? rect.w + 2 * margin : viewport.cssWidth,
- rect.h);
- // constrict the rect to the screen's right edge
- rect.width = Math.min(rect.width, viewport.cssPageRight - rect.x);
-
- // if the rect is already taking up most of the visible area and is stretching the
- // width of the page, then we want to zoom out instead.
- if (aElement) {
- if (ZoomHelper.isRectZoomedIn(rect, viewport)) {
- if (aCanZoomOut) {
- ZoomHelper.zoomOut();
- }
- return;
- }
-
- ZoomHelper.zoomToRect(rect, aClickY);
- }
- },
-
- /* Zoom to a specific part of the screen defined by a rect,
- * optionally keeping a particular part of it in view
- * if it is really tall.
- */
- zoomToRect: function(aRect, aClickY = -1) {
- let viewport = BrowserApp.selectedTab.getViewport();
-
- let rect = {
- x: aRect.x,
- y: aRect.y,
- w: aRect.width,
- h: Math.min(aRect.width * viewport.cssHeight / viewport.cssWidth, aRect.height)
- };
-
- rect.type = "Browser:ZoomToRect";
-
- if (aClickY >= 0) {
- // if the block we're zooming to is really tall, and we want to keep a particular
- // part of it in view, then adjust the y-coordinate of the target rect accordingly.
- // the 1.2 multiplier is just a little fuzz to compensate for aRect including horizontal
- // margins but not vertical ones.
- let cssTapY = viewport.cssY + aClickY;
- if ((aRect.height > rect.h) && (cssTapY > rect.y + (rect.h * 1.2))) {
- rect.y = cssTapY - (rect.h / 2);
- }
- }
-
- Messaging.sendRequest(rect);
- },
-};
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -124,17 +124,16 @@ XPCOMUtils.defineLazyServiceGetter(this,
var lazilyLoadedBrowserScripts = [
["SelectHelper", "chrome://browser/content/SelectHelper.js"],
["InputWidgetHelper", "chrome://browser/content/InputWidgetHelper.js"],
["MasterPassword", "chrome://browser/content/MasterPassword.js"],
["PluginHelper", "chrome://browser/content/PluginHelper.js"],
["OfflineApps", "chrome://browser/content/OfflineApps.js"],
["Linkifier", "chrome://browser/content/Linkify.js"],
- ["ZoomHelper", "chrome://browser/content/ZoomHelper.js"],
["CastingApps", "chrome://browser/content/CastingApps.js"],
["RemoteDebugger", "chrome://browser/content/RemoteDebugger.js"],
];
if (!AppConstants.RELEASE_OR_BETA) {
lazilyLoadedBrowserScripts.push(
["WebcompatReporter", "chrome://browser/content/WebcompatReporter.js"]);
}
@@ -4476,42 +4475,16 @@ var BrowserEventHandler = {
uri: mediaSrc,
uuid: aEvent.target.moz_video_uuid
});
break;
}
}
},
- _handleTouchStart: function(aEvent) {
- if (!BrowserApp.isBrowserContentDocumentDisplayed() || aEvent.touches.length > 1 || aEvent.defaultPrevented)
- return;
-
- let target = aEvent.target;
- if (!target) {
- return;
- }
-
- // If we've pressed a scrollable element, let Java know that we may
- // want to override the scroll behaviour (for document sub-frames)
- this._scrollableElement = this._findScrollableElement(target, true);
- this._firstScrollEvent = true;
-
- if (this._scrollableElement != null) {
- // Discard if it's the top-level scrollable, we let Java handle this
- // The top-level scrollable is the body in quirks mode and the html element
- // in standards mode
- let doc = BrowserApp.selectedBrowser.contentDocument;
- let rootScrollable = (doc.compatMode === "BackCompat" ? doc.body : doc.documentElement);
- if (this._scrollableElement != rootScrollable) {
- Messaging.sendRequest({ type: "Panning:Override" });
- }
- }
- },
-
_handleRetargetedTouchStart: function(aEvent) {
// we should only get this called just after a new touchstart with a single
// touch point.
if (!BrowserApp.isBrowserContentDocumentDisplayed() || aEvent.defaultPrevented) {
return;
}
let target = aEvent.target;
@@ -4605,197 +4578,31 @@ var BrowserEventHandler = {
type: "Gesture:clusteredLinksClicked",
clickPosition: {
x: aX,
y: aY
}
});
},
- onDoubleTap: function(aData) {
- let metadata = ViewportHandler.getMetadataForDocument(BrowserApp.selectedBrowser.contentDocument);
- if (metadata && !metadata.allowDoubleTapZoom) {
- return;
- }
-
- let data = JSON.parse(aData);
- let element = ElementTouchHelper.anyElementFromPoint(data.x, data.y);
-
- if (!element) {
- ZoomHelper.zoomOut();
- return;
- }
-
- while (element && !this._shouldZoomToElement(element))
- element = element.parentNode;
-
- if (!element) {
- ZoomHelper.zoomOut();
- } else {
- ZoomHelper.zoomToElement(element, data.y);
- }
- },
-
- _shouldZoomToElement: function(aElement) {
- let win = aElement.ownerDocument.defaultView;
- if (win.getComputedStyle(aElement, null).display == "inline")
- return false;
- if (aElement instanceof Ci.nsIDOMHTMLLIElement)
- return false;
- if (aElement instanceof Ci.nsIDOMHTMLQuoteElement)
- return false;
- return true;
- },
-
- _firstScrollEvent: false,
-
- _scrollableElement: null,
-
_highlightElement: null,
_doTapHighlight: function _doTapHighlight(aElement) {
this._highlightElement = aElement;
},
_cancelTapHighlight: function _cancelTapHighlight() {
if (!this._highlightElement)
return;
this._highlightElement = null;
- },
-
- _updateLastPosition: function(x, y, dx, dy) {
- this.lastX = x;
- this.lastY = y;
- this.lastTime = Date.now();
-
- this.motionBuffer.push({ dx: dx, dy: dy, time: this.lastTime });
- },
-
- _sendMouseEvent: function _sendMouseEvent(aName, aX, aY) {
- let win = BrowserApp.selectedBrowser.contentWindow;
- try {
- let cwu = win.top.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
- cwu.sendMouseEventToWindow(aName, aX, aY, 0, 1, 0, true, 0, Ci.nsIDOMMouseEvent.MOZ_SOURCE_TOUCH, false);
- } catch(e) {
- Cu.reportError(e);
- }
- },
-
- _hasScrollableOverflow: function(elem) {
- var win = elem.ownerDocument.defaultView;
- if (!win)
- return false;
- var computedStyle = win.getComputedStyle(elem);
- if (!computedStyle)
- return false;
- // We check for overflow:hidden only because all the other cases are scrollable
- // under various conditions. See https://bugzilla.mozilla.org/show_bug.cgi?id=911574#c24
- // for some more details.
- return !(computedStyle.overflowX == 'hidden' && computedStyle.overflowY == 'hidden');
- },
-
- _findScrollableElement: function(elem, checkElem) {
- // Walk the DOM tree until we find a scrollable element
- let scrollable = false;
- while (elem) {
- /* Element is scrollable if its scroll-size exceeds its client size, and:
- * - It has overflow other than 'hidden', or
- * - It's a textarea node, or
- * - It's a text input, or
- * - It's a select element showing multiple rows
- */
- if (checkElem) {
- if ((elem.scrollTopMin != elem.scrollTopMax ||
- elem.scrollLeftMin != elem.scrollLeftMax) &&
- (this._hasScrollableOverflow(elem) ||
- elem.matches("textarea")) ||
- (elem instanceof HTMLInputElement && elem.mozIsTextField(false)) ||
- (elem instanceof HTMLSelectElement && (elem.size > 1 || elem.multiple))) {
- scrollable = true;
- break;
- }
- } else {
- checkElem = true;
- }
-
- // Propagate up iFrames
- if (!elem.parentNode && elem.documentElement && elem.documentElement.ownerDocument)
- elem = elem.documentElement.ownerDocument.defaultView.frameElement;
- else
- elem = elem.parentNode;
- }
-
- if (!scrollable)
- return null;
-
- return elem;
- },
-
- _scrollElementBy: function(elem, x, y) {
- elem.scrollTop = elem.scrollTop + y;
- elem.scrollLeft = elem.scrollLeft + x;
- },
-
- _elementCanScroll: function(elem, x, y) {
- let scrollX = (x < 0 && elem.scrollLeft > 0)
- || (x > 0 && elem.scrollLeft < elem.scrollLeftMax);
-
- let scrollY = (y < 0 && elem.scrollTop > 0)
- || (y > 0 && elem.scrollTop < elem.scrollTopMax);
-
- return scrollX || scrollY;
}
};
const ElementTouchHelper = {
- /* Return the element at the given coordinates, starting from the given window and
- drilling down through frames. If no window is provided, the top-level window of
- the currently selected tab is used. The coordinates provided should be CSS pixels
- relative to the window's scroll position. */
- anyElementFromPoint: function(aX, aY, aWindow) {
- let win = (aWindow ? aWindow : BrowserApp.selectedBrowser.contentWindow);
- let cwu = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
- let elem = cwu.elementFromPoint(aX, aY, true, true);
-
- while (elem && (elem instanceof HTMLIFrameElement || elem instanceof HTMLFrameElement)) {
- let rect = elem.getBoundingClientRect();
- aX -= rect.left;
- aY -= rect.top;
- cwu = elem.contentDocument.defaultView.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
- elem = cwu.elementFromPoint(aX, aY, true, true);
- }
-
- return elem;
- },
-
- /* Returns the touch radius with zoom factored in. */
- getTouchRadius: function getTouchRadius() {
- let zoom = BrowserApp.selectedTab._zoom;
- return {
- top: this.radius.top / zoom,
- right: this.radius.right / zoom,
- bottom: this.radius.bottom / zoom,
- left: this.radius.left / zoom
- };
- },
-
- /* Returns the touch radius in device pixels. */
- get radius() {
- let mmToIn = 1 / 25.4;
- let mmToPx = mmToIn * ViewportHandler.displayDPI;
- let prefs = Services.prefs;
- delete this.radius;
- return this.radius = { "top": prefs.getIntPref("ui.touch.radius.topmm") * mmToPx,
- "right": prefs.getIntPref("ui.touch.radius.rightmm") * mmToPx,
- "bottom": prefs.getIntPref("ui.touch.radius.bottommm") * mmToPx,
- "left": prefs.getIntPref("ui.touch.radius.leftmm") * mmToPx
- };
- },
-
getBoundingContentRect: function(aElement) {
if (!aElement)
return {x: 0, y: 0, w: 0, h: 0};
let document = aElement.ownerDocument;
while (document.defaultView.frameElement)
document = document.defaultView.frameElement.ownerDocument;
@@ -5540,76 +5347,26 @@ var XPInstallObserver = {
},
hideRestartPrompt: function() {
NativeWindow.doorhanger.hide("addon-app-restart", BrowserApp.selectedTab.id);
}
};
var ViewportHandler = {
- // The cached viewport metadata for each document. We tie viewport metadata to each document
- // instead of to each tab so that we don't have to update it when the document changes. Using an
- // ES6 weak map lets us avoid leaks.
- _metadata: new WeakMap(),
-
init: function init() {
Services.obs.addObserver(this, "Window:Resize", false);
},
observe: function(aSubject, aTopic, aData) {
if (aTopic == "Window:Resize" && aData) {
let scrollChange = JSON.parse(aData);
let windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
windowUtils.setNextPaintSyncId(scrollChange.id);
}
- },
-
- /**
- * Returns true if a viewport tag was specified
- */
- isViewportSpecified: function isViewportSpecified(aWindow) {
- let tab = BrowserApp.getTabForWindow(aWindow);
- let readerMode = false;
- try {
- readerMode = tab.browser.contentDocument.documentURI.startsWith("about:reader");
- } catch (e) {
- }
- if (tab.desktopMode && !readerMode) {
- return false;
- }
-
- let windowUtils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
- return !isNaN(parseFloat(windowUtils.getDocumentMetadata("viewport-initial-scale")))
- || !isNaN(parseFloat(windowUtils.getDocumentMetadata("viewport-minimum-scale")))
- || !isNaN(parseFloat(windowUtils.getDocumentMetadata("viewport-maximum-scale")))
- || ("" != windowUtils.getDocumentMetadata("viewport-user-scalable"))
- || ("" != windowUtils.getDocumentMetadata("viewport-width"))
- || ("" != windowUtils.getDocumentMetadata("viewport-height"));
- },
-
- get displayDPI() {
- let utils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
- delete this.displayDPI;
- return this.displayDPI = utils.displayDPI;
- },
-
- /**
- * Returns the viewport metadata for the given document, or undefined if there
- * isn't one.
- */
- getMetadataForDocument: function getMetadataForDocument(aDocument) {
- return this._metadata.get(aDocument);
- },
-
- /** Updates the saved viewport metadata for the given content document. */
- setMetadataForDocument: function setMetadataForDocument(aDocument, aMetadata) {
- if (!aMetadata)
- this._metadata.delete(aDocument);
- else
- this._metadata.set(aDocument, aMetadata);
}
};
/**
* Handler for blocked popups, triggered by DOMUpdatePageReport events in browser.xml
*/
var PopupBlockerObserver = {
onUpdatePageReport: function onUpdatePageReport(aEvent) {