Bug 1446913 - document and fix event object usage, r?kmag
MozReview-Commit-ID: 8EjhiXfBmTX
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -6092,16 +6092,21 @@ function handleLinkClick(event, href, li
params.userContextId = doc.nodePrincipal.originAttributes.userContextId;
}
openLinkIn(href, where, params);
event.preventDefault();
return true;
}
+/**
+ * Handles paste on middle mouse clicks.
+ *
+ * @param event {Event | Object} Event or JSON object.
+ */
function middleMousePaste(event) {
let clipboard = readFromClipboard();
if (!clipboard)
return;
// Strip embedded newlines and surrounding whitespace, to match the URL
// bar's behavior (stripsurroundingwhitespace)
clipboard = clipboard.replace(/\s*\n\s*/g, "");
@@ -6135,17 +6140,19 @@ function middleMousePaste(event) {
if (where != "current" ||
lastLocationChange == gBrowser.selectedBrowser.lastLocationChange) {
openUILink(data.url, event,
{ ignoreButton: true,
disallowInheritPrincipal: !data.mayInheritPrincipal });
}
});
- event.stopPropagation();
+ if (event instanceof Event) {
+ event.stopPropagation();
+ }
}
function stripUnsafeProtocolOnPaste(pasteData) {
// Don't allow pasting javascript URIs since we don't support
// LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL for those.
while (true) {
let scheme = "";
try {
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -76,20 +76,30 @@ function getBoolPref(prefname, def) {
function doGetProtocolFlags(aURI) {
let handler = Services.io.getProtocolHandler(aURI.scheme);
// see DoGetProtocolFlags in nsIProtocolHandler.idl
return handler instanceof Ci.nsIProtocolHandlerWithDynamicFlags ?
handler.QueryInterface(Ci.nsIProtocolHandlerWithDynamicFlags).getFlagsForURI(aURI) :
handler.protocolFlags;
}
-/* openUILink handles clicks on UI elements that cause URLs to load.
+/**
+ * openUILink handles clicks on UI elements that cause URLs to load.
*
* As the third argument, you may pass an object with the same properties as
* accepted by openUILinkIn, plus "ignoreButton" and "ignoreAlt".
+ *
+ * @param url {string}
+ * @param event {Event | Object} Event or JSON object representing an Event
+ * @param {Boolean | Object} aIgnoreButton
+ * @param {Boolean} aIgnoreButton
+ * @param {Boolean} aIgnoreAlt
+ * @param {Boolean} aAllowThirdPartyFixup
+ * @param {Object} aPostData
+ * @param {nsIURI} aReferrerURI
*/
function openUILink(url, event, aIgnoreButton, aIgnoreAlt, aAllowThirdPartyFixup,
aPostData, aReferrerURI) {
let params;
if (aIgnoreButton && typeof aIgnoreButton == "object") {
params = aIgnoreButton;
@@ -108,17 +118,18 @@ function openUILink(url, event, aIgnoreB
};
}
let where = whereToOpenLink(event, aIgnoreButton, aIgnoreAlt);
openUILinkIn(url, where, params);
}
-/* whereToOpenLink() looks at an event to decide where to open a link.
+/**
+ * whereToOpenLink() looks at an event to decide where to open a link.
*
* The event may be a mouse event (click, double-click, middle-click) or keypress event (enter).
*
* On Windows, the modifiers are:
* Ctrl new tab, selected
* Shift new window
* Ctrl+Shift new tab, in background
* Alt save
@@ -126,16 +137,21 @@ function openUILink(url, event, aIgnoreB
* Middle-clicking is the same as Ctrl+clicking (it opens a new tab).
*
* Exceptions:
* - Alt is ignored for menu items selected using the keyboard so you don't accidentally save stuff.
* (Currently, the Alt isn't sent here at all for menu items, but that will change in bug 126189.)
* - Alt is hard to use in context menus, because pressing Alt closes the menu.
* - Alt can't be used on the bookmarks toolbar because Alt is used for "treat this as something draggable".
* - The button is ignored for the middle-click-paste-URL feature, since it's always a middle-click.
+ *
+ * @param e {Event|Object} Event or JSON Object
+ * @param ignoreButton {Boolean}
+ * @param ignoreAlt {Boolean}
+ * @returns {"current" | "tabshifted" | "tab" | "save" | "window"}
*/
function whereToOpenLink(e, ignoreButton, ignoreAlt) {
// This method must treat a null event like a left click without modifier keys (i.e.
// e = { shiftKey:false, ctrlKey:false, metaKey:false, altKey:false, button:0 })
// for compatibility purposes.
if (!e)
return "current";
--- a/browser/modules/ContentClick.jsm
+++ b/browser/modules/ContentClick.jsm
@@ -20,16 +20,22 @@ var ContentClick = {
receiveMessage(message) {
switch (message.name) {
case "Content:Click":
this.contentAreaClick(message.json, message.target);
break;
}
},
+ /**
+ * Handles clicks in the content area.
+ *
+ * @param json {Object} JSON object that looks like an Event
+ * @param browser {Element<browser>}
+ */
contentAreaClick(json, browser) {
// This is heavily based on contentAreaClick from browser.js (Bug 903016)
// The json is set up in a way to look like an Event.
let window = browser.ownerGlobal;
if (!json.href) {
// Might be middle mouse navigation.
if (Services.prefs.getBoolPref("middlemouse.contentLoadURL") &&