[Pale-Moon] Issue #1737 - Part 2: Clean up base/content p.2

This commit is contained in:
Pale Moon 2020-03-08 13:58:47 +01:00 • committed by Roy Tam
commit b017678cf0
9 changed files with 662 additions and 442 deletions

View file

@ -134,19 +134,22 @@ var FullZoom = {
}
let browser = gBrowser.selectedBrowser;
if (!browser.currentURI)
if (!browser.currentURI) {
return;
}
let ctxt = this._loadContextFromBrowser(browser);
let domain = this._cps2.extractDomain(browser.currentURI.spec);
if (aGroup) {
if (aGroup == domain && ctxt.usePrivateBrowsing == aIsPrivate)
if (aGroup == domain && ctxt.usePrivateBrowsing == aIsPrivate) {
this._applyPrefToZoom(aValue, browser);
}
return;
}
this._globalValue = aValue === undefined ? aValue :
this._ensureValid(aValue);
this._globalValue = aValue === undefined ?
aValue :
this._ensureValid(aValue);
// If the current page doesn't have a site-specific preference, then its
// zoom should be set to the new global preference now that the global
@ -156,8 +159,9 @@ var FullZoom = {
this._cps2.getByDomainAndName(browser.currentURI.spec, this.name, ctxt, {
handleResult: function() { hasPref = true; },
handleCompletion: function() {
if (!hasPref && token.isCurrent)
if (!hasPref && token.isCurrent) {
this._applyPrefToZoom(undefined, browser);
}
}.bind(this)
});
},
@ -358,8 +362,9 @@ var FullZoom = {
Services.obs.notifyObservers(browser, "browser-fullZoom:zoomChange", "");
if (!this.siteSpecific ||
gInPrintPreviewMode ||
browser.isSyntheticDocument)
browser.isSyntheticDocument) {
return;
}
this._cps2.set(browser.currentURI.spec, this.name,
ZoomManager.getZoomForBrowser(browser),
@ -377,8 +382,9 @@ var FullZoom = {
*/
_removePref: function(browser) {
Services.obs.notifyObservers(browser, "browser-fullZoom:zoomReset", "");
if (browser.isSyntheticDocument)
if (browser.isSyntheticDocument) {
return;
}
let ctxt = this._loadContextFromBrowser(browser);
this._cps2.removeByDomainAndName(browser.currentURI.spec, this.name, ctxt, {
handleCompletion: function() {
@ -403,8 +409,9 @@ var FullZoom = {
*/
_getBrowserToken: function(browser) {
let map = this._browserTokenMap;
if (!map.has(browser))
if (!map.has(browser)) {
map.set(browser, 0);
}
return {
token: map.get(browser),
get isCurrent() {
@ -431,13 +438,15 @@ var FullZoom = {
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
if (target instanceof window.XULElement &&
target.localName == "browser" &&
target.namespaceURI == XUL_NS)
target.namespaceURI == XUL_NS) {
return target;
}
// With in-process content browsers, the event's target is the content
// document.
if (target.nodeType == Node.DOCUMENT_NODE)
if (target.nodeType == Node.DOCUMENT_NODE) {
return gBrowser.getBrowserForDocument(target);
}
throw new Error("Unexpected ZoomChangeUsingMouseWheel event source");
},
@ -457,14 +466,17 @@ var FullZoom = {
_ensureValid: function(aValue) {
// Note that undefined is a valid value for aValue that indicates a known-
// not-to-exist value.
if (isNaN(aValue))
if (isNaN(aValue)) {
return 1;
}
if (aValue < ZoomManager.MIN)
if (aValue < ZoomManager.MIN) {
return ZoomManager.MIN;
}
if (aValue > ZoomManager.MAX)
if (aValue > ZoomManager.MAX) {
return ZoomManager.MAX;
}
return aValue;
},
@ -519,8 +531,9 @@ var FullZoom = {
},
_executeSoon: function(callback) {
if (!callback)
if (!callback) {
return;
}
Services.tm.mainThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL);
},
};

View file

@ -31,8 +31,9 @@ var gGestureSupport = {
"RotateGestureStart", "RotateGestureUpdate", "RotateGesture",
"TapGesture", "PressTapGesture"];
let addRemove = aAddListener ? window.addEventListener :
window.removeEventListener;
let addRemove = aAddListener ?
window.addEventListener :
window.removeEventListener;
for (let event of gestureEvents) {
addRemove("Moz" + event, this, true);
@ -54,8 +55,9 @@ var gGestureSupport = {
}
// Create a preference object with some defaults
let def = (aThreshold, aLatched) =>
({ threshold: aThreshold, latched: !!aLatched });
let def = function(aThreshold, aLatched) {
return { threshold: aThreshold, latched: !!aLatched };
}
switch (aEvent.type) {
case "MozSwipeGestureMayStart":
@ -126,8 +128,9 @@ var gGestureSupport = {
*/
_setupGesture: function(aEvent, aGesture, aPref, aInc, aDec) {
// Try to load user-set values from preferences
for (let [pref, def] in Iterator(aPref))
for (let [pref, def] in Iterator(aPref)) {
aPref[pref] = this._getPref(aGesture + "." + pref, def);
}
// Keep track of the total deltas and latching behavior
let offset = 0;
@ -170,10 +173,8 @@ var gGestureSupport = {
* @return true if the swipe event may navigate the history, false othwerwise.
*/
_swipeNavigatesHistory: function(aEvent) {
return this._getCommand(aEvent, ["swipe", "left"])
== "Browser:BackOrBackDuplicate" &&
this._getCommand(aEvent, ["swipe", "right"])
== "Browser:ForwardOrForwardDuplicate";
return this._getCommand(aEvent, ["swipe", "left"]) == "Browser:BackOrBackDuplicate" &&
this._getCommand(aEvent, ["swipe", "right"]) == "Browser:ForwardOrForwardDuplicate";
},
/**
@ -186,19 +187,24 @@ var gGestureSupport = {
* otherwise.
*/
_shouldDoSwipeGesture: function(aEvent) {
if (!this._swipeNavigatesHistory(aEvent))
if (!this._swipeNavigatesHistory(aEvent)) {
return false;
}
let canGoBack = gHistorySwipeAnimation.canGoBack();
let canGoForward = gHistorySwipeAnimation.canGoForward();
let isLTR = gHistorySwipeAnimation.isLTR;
if (canGoBack)
aEvent.allowedDirections |= isLTR ? aEvent.DIRECTION_LEFT :
aEvent.DIRECTION_RIGHT;
if (canGoForward)
aEvent.allowedDirections |= isLTR ? aEvent.DIRECTION_RIGHT :
aEvent.DIRECTION_LEFT;
if (canGoBack) {
aEvent.allowedDirections |= isLTR ?
aEvent.DIRECTION_LEFT :
aEvent.DIRECTION_RIGHT;
}
if (canGoForward) {
aEvent.allowedDirections |= isLTR ?
aEvent.DIRECTION_RIGHT :
aEvent.DIRECTION_LEFT;
}
return true;
},
@ -222,8 +228,8 @@ var gGestureSupport = {
this._doEnd = function(aEvent) {
gHistorySwipeAnimation.swipeEndEventReceived();
this._doUpdate = function(aEvent) {};
this._doEnd = function(aEvent) {};
this._doUpdate = function(aEvent) { };
this._doEnd = function(aEvent) { };
}
},
@ -241,8 +247,9 @@ var gGestureSupport = {
while (--num >= 0) {
// Only select array elements where the current bit is set
yield aArray.reduce(function(aPrev, aCurr, aIndex) {
if (num & 1 << aIndex)
if (num & 1 << aIndex) {
aPrev.push(aCurr);
}
return aPrev;
}, []);
}
@ -279,8 +286,9 @@ var gGestureSupport = {
// command for both don't exist)
let keyCombos = [];
["shift", "alt", "ctrl", "meta"].forEach(function(key) {
if (aEvent[key + "Key"])
if (aEvent[key + "Key"]) {
keyCombos.push(key);
}
});
// Try each combination of key presses in decreasing order for commands
@ -291,10 +299,12 @@ var gGestureSupport = {
let command;
try {
command = this._getPref(aGesture.concat(subCombo).join("."));
} catch (e) {}
} catch(e) {
}
if (command)
if (command) {
return command;
}
}
return null;
},
@ -318,8 +328,7 @@ var gGestureSupport = {
node.dispatchEvent(cmdEvent);
}
}
else {
} else {
goDoCommand(aCommand);
}
},
@ -331,7 +340,7 @@ var gGestureSupport = {
* @param aEvent
* The continual motion update event to handle
*/
_doUpdate: function(aEvent) {},
_doUpdate: function(aEvent) { },
/**
* Handle gesture end events. This function will be set by _setupSwipe.
@ -339,7 +348,7 @@ var gGestureSupport = {
* @param aEvent
* The gesture end event to handle
*/
_doEnd: function(aEvent) {},
_doEnd: function(aEvent) { },
/**
* Convert the swipe gesture into a browser action based on the direction.
@ -380,13 +389,11 @@ var gGestureSupport = {
* @param aDir
* The direction for the swipe event
*/
_coordinateSwipeEventWithAnimation:
function(aEvent, aDir) {
_coordinateSwipeEventWithAnimation: function(aEvent, aDir) {
if ((gHistorySwipeAnimation.isAnimationRunning()) &&
(aDir == "RIGHT" || aDir == "LEFT")) {
gHistorySwipeAnimation.processSwipeEvent(aEvent, aDir);
}
else {
} else {
this.processSwipeEvent(aEvent, aDir);
}
},
@ -406,11 +413,13 @@ var gGestureSupport = {
try {
// Determine what type of data to load based on default value's type
let type = typeof aDef;
let getFunc = "get" + (type == "boolean" ? "Bool" :
type == "number" ? "Int" : "Char") + "Pref";
let getFunc = "get" + (type == "boolean" ?
"Bool" :
type == "number" ?
"Int" :
"Char") + "Pref";
return gPrefService[getFunc](branch + aPref);
}
catch (e) {
} catch(e) {
return aDef;
}
},
@ -422,15 +431,18 @@ var gGestureSupport = {
* The MozRotateGestureUpdate event triggering this call
*/
rotate: function(aEvent) {
if (!(content.document instanceof ImageDocument))
if (!(content.document instanceof ImageDocument)) {
return;
}
let contentElement = content.document.body.firstElementChild;
if (!contentElement)
if (!contentElement) {
return;
}
// If we're currently snapping, cancel that snap
if (contentElement.classList.contains("completeRotation"))
if (contentElement.classList.contains("completeRotation")) {
this._clearCompleteRotation();
}
this.rotation = Math.round(this.rotation + aEvent.delta);
contentElement.style.transform = "rotate(" + this.rotation + "deg)";
@ -441,37 +453,41 @@ var gGestureSupport = {
* Perform a rotation end for ImageDocuments
*/
rotateEnd: function() {
if (!(content.document instanceof ImageDocument))
if (!(content.document instanceof ImageDocument)) {
return;
}
let contentElement = content.document.body.firstElementChild;
if (!contentElement)
if (!contentElement) {
return;
}
let transitionRotation = 0;
// The reason that 360 is allowed here is because when rotating between
// 315 and 360, setting rotate(0deg) will cause it to rotate the wrong
// direction around--spinning wildly.
if (this.rotation <= 45)
if (this.rotation <= 45) {
transitionRotation = 0;
else if (this.rotation > 45 && this.rotation <= 135)
} else if (this.rotation > 45 && this.rotation <= 135) {
transitionRotation = 90;
else if (this.rotation > 135 && this.rotation <= 225)
} else if (this.rotation > 135 && this.rotation <= 225) {
transitionRotation = 180;
else if (this.rotation > 225 && this.rotation <= 315)
} else if (this.rotation > 225 && this.rotation <= 315) {
transitionRotation = 270;
else
} else {
transitionRotation = 360;
}
// If we're going fast enough, and we didn't already snap ahead of rotation,
// then snap ahead of rotation to simulate momentum
if (this._lastRotateDelta > this._rotateMomentumThreshold &&
this.rotation > transitionRotation)
this.rotation > transitionRotation) {
transitionRotation += 90;
else if (this._lastRotateDelta < -1 * this._rotateMomentumThreshold &&
this.rotation < transitionRotation)
} else if (this._lastRotateDelta < -1 * this._rotateMomentumThreshold &&
this.rotation < transitionRotation) {
transitionRotation -= 90;
}
// Only add the completeRotation class if it is is necessary
if (transitionRotation != this.rotation) {
@ -499,8 +515,9 @@ var gGestureSupport = {
*/
set rotation(aVal) {
this._currentRotation = aVal % 360;
if (this._currentRotation < 0)
if (this._currentRotation < 0) {
this._currentRotation += 360;
}
return this._currentRotation;
},
@ -509,8 +526,9 @@ var gGestureSupport = {
* image
*/
restoreRotationState: function() {
if (!(content.document instanceof ImageDocument))
if (!(content.document instanceof ImageDocument)) {
return;
}
let contentElement = content.document.body.firstElementChild;
let transformValue = content.window.getComputedStyle(contentElement, null)
@ -538,8 +556,9 @@ var gGestureSupport = {
content.document instanceof ImageDocument &&
content.document.body &&
content.document.body.firstElementChild;
if (!contentElement)
if (!contentElement) {
return;
}
contentElement.classList.remove("completeRotation");
contentElement.removeEventListener("transitionend", this._clearCompleteRotation);
},
@ -556,11 +575,12 @@ var gHistorySwipeAnimation = {
* by the platform/configuration.
*/
init: function() {
if (!this._isSupported())
if (!this._isSupported()) {
return;
}
this.active = false;
this.isLTR = document.documentElement.matches(":-moz-locale-dir(ltr)");
this.isLTR = document.documentElement.mozMatchesSelector(":-moz-locale-dir(ltr)");
this._trackedSnapshots = [];
this._historyIndex = -1;
this._boxWidth = -1;
@ -604,8 +624,7 @@ var gHistorySwipeAnimation = {
this._canGoBack = this.canGoBack();
this._canGoForward = this.canGoForward();
this._handleFastSwiping();
}
else {
} else {
this._historyIndex = gBrowser.webNavigation.sessionHistory.index;
this._canGoBack = this.canGoBack();
this._canGoForward = this.canGoForward();
@ -635,18 +654,22 @@ var gHistorySwipeAnimation = {
* swipe gesture.
*/
updateAnimation: function(aVal) {
if (!this.isAnimationRunning())
if (!this.isAnimationRunning()) {
return;
}
if ((aVal >= 0 && this.isLTR) ||
(aVal <= 0 && !this.isLTR)) {
if (aVal > 1)
aVal = 1; // Cap value to avoid sliding the page further than allowed.
if (aVal > 1) {
// Cap value to avoid sliding the page further than allowed.
aVal = 1;
}
if (this._canGoBack)
if (this._canGoBack) {
this._prevBox.collapsed = false;
else
} else {
this._prevBox.collapsed = true;
}
// The current page is pushed to the right (LTR) or left (RTL),
// the intention is to go back.
@ -655,10 +678,12 @@ var gHistorySwipeAnimation = {
// The forward page should be pushed offscreen all the way to the right.
this._positionBox(this._nextBox, 1);
}
else {
if (aVal < -1)
aVal = -1; // Cap value to avoid sliding the page further than allowed.
} else {
if (aVal < -1) {
// Cap value to avoid sliding the page further than allowed.
aVal = -1;
}
// The intention is to go forward. If there is a page to go forward to,
// it should slide in from the right (LTR) or left (RTL).
// Otherwise, the current page should slide to the left (LTR) or
@ -670,8 +695,7 @@ var gHistorySwipeAnimation = {
let offset = this.isLTR ? 1 : -1;
this._positionBox(this._curBox, 0);
this._positionBox(this._nextBox, offset + aVal); // aval is negative
}
else {
} else {
this._prevBox.collapsed = true;
this._positionBox(this._curBox, aVal);
}
@ -736,12 +760,13 @@ var gHistorySwipeAnimation = {
* The direction for the swipe event
*/
processSwipeEvent: function(aEvent, aDir) {
if (aDir == "RIGHT")
if (aDir == "RIGHT") {
this._historyIndex += this.isLTR ? 1 : -1;
else if (aDir == "LEFT")
} else if (aDir == "LEFT") {
this._historyIndex += this.isLTR ? -1 : 1;
else
} else {
return;
}
this._lastSwipeDir = aDir;
},
@ -751,8 +776,9 @@ var gHistorySwipeAnimation = {
* @return true if there is a previous page in history, false otherwise.
*/
canGoBack: function() {
if (this.isAnimationRunning())
if (this.isAnimationRunning()) {
return this._doesIndexExistInHistory(this._historyIndex - 1);
}
return gBrowser.webNavigation.canGoBack;
},
@ -762,8 +788,9 @@ var gHistorySwipeAnimation = {
* @return true if there is a next page in history, false otherwise.
*/
canGoForward: function() {
if (this.isAnimationRunning())
if (this.isAnimationRunning()) {
return this._doesIndexExistInHistory(this._historyIndex + 1);
}
return gBrowser.webNavigation.canGoForward;
},
@ -773,10 +800,11 @@ var gHistorySwipeAnimation = {
* any. This will also result in the animation overlay to be torn down.
*/
swipeEndEventReceived: function() {
if (this._lastSwipeDir != "")
if (this._lastSwipeDir != "") {
this._navigateToHistoryIndex();
else
} else {
this.stopAnimation();
}
},
/**
@ -789,8 +817,7 @@ var gHistorySwipeAnimation = {
_doesIndexExistInHistory: function(aIndex) {
try {
gBrowser.webNavigation.sessionHistory.getEntryAtIndex(aIndex, false);
}
catch(ex) {
} catch(ex) {
return false;
}
return true;
@ -860,8 +887,9 @@ var gHistorySwipeAnimation = {
this._curBox = null;
this._prevBox = null;
this._nextBox = null;
if (this._container)
if (this._container) {
this._container.parentNode.removeChild(this._container);
}
this._container = null;
this._boxWidth = -1;
},
@ -958,16 +986,16 @@ var gHistorySwipeAnimation = {
* @param aCanvas
* The snapshot to add to the list and compress.
*/
_assignSnapshotToCurrentBrowser:
function(aCanvas) {
_assignSnapshotToCurrentBrowser: function(aCanvas) {
let browser = gBrowser.selectedBrowser;
let currIndex = browser.webNavigation.sessionHistory.index;
this._removeTrackedSnapshot(currIndex, browser);
this._addSnapshotRefToArray(currIndex, browser);
if (!("snapshots" in browser))
if (!("snapshots" in browser)) {
browser.snapshots = [];
}
let snapshots = browser.snapshots;
// Temporarily store the canvas as the compressed snapshot.
// This avoids a blank page if the user swipes quickly
@ -1024,10 +1052,13 @@ var gHistorySwipeAnimation = {
(aIndex < 0 || aIndex == arr[i].index)) {
delete aBrowser.snapshots[arr[i].index];
arr.splice(i, 1);
if (requiresExactIndexMatch)
return; // Found and removed the only element.
i--; // Make sure to revisit the index that we just removed an
// element at.
if (requiresExactIndexMatch) {
// Found and removed the only element.
return;
}
// Make sure to revisit the index that we just removed an
// element at.
i--;
}
}
},
@ -1041,8 +1072,7 @@ var gHistorySwipeAnimation = {
* @param aBrowser
* The browser the new snapshot was taken in.
*/
_addSnapshotRefToArray:
function(aIndex, aBrowser) {
_addSnapshotRefToArray: function(aIndex, aBrowser) {
let id = { index: aIndex,
browser: aBrowser };
let arr = this._trackedSnapshots;
@ -1067,12 +1097,14 @@ var gHistorySwipeAnimation = {
* @return A new Image object representing the converted blob.
*/
_convertToImg: function(aBlob) {
if (!aBlob)
if (!aBlob) {
return null;
}
// Return aBlob if it's still a canvas and not a compressed blob yet.
if (aBlob instanceof HTMLCanvasElement)
if (aBlob instanceof HTMLCanvasElement) {
return aBlob;
}
let img = new Image();
let url = "";
@ -1122,12 +1154,11 @@ var gHistorySwipeAnimation = {
* The snapshot to set the current page to. If this parameter is null,
* the previously stored snapshot for this index (if any) will be used.
*/
_installCurrentPageSnapshot:
function(aCanvas) {
_installCurrentPageSnapshot: function(aCanvas) {
let currSnapshot = aCanvas;
let scale = window.devicePixelRatio;
if (!currSnapshot) {
let snapshots = gBrowser.selectedBrowser.snapshots || {};
let snapshots = gBrowser.selectedBrowser.snapshots || { };
let currIndex = this._historyIndex;
if (currIndex in snapshots) {
currSnapshot = this._convertToImg(snapshots[currIndex].image);
@ -1144,8 +1175,7 @@ var gHistorySwipeAnimation = {
* Sets the snapshots of the previous and next pages to the snapshots
* previously stored for their respective indeces.
*/
_installPrevAndNextSnapshots:
function() {
_installPrevAndNextSnapshots: function() {
let snapshots = gBrowser.selectedBrowser.snapshots || [];
let currIndex = this._historyIndex;
let prevIndex = currIndex - 1;

View file

@ -23,7 +23,7 @@ var browserMenuDragging = {
count:[],
init: function(){
init: function() {
window.removeEventListener('load', this, false);
window.addEventListener('unload', this, false);
this.addPrefListener(this.PrefListener);
@ -34,7 +34,7 @@ var browserMenuDragging = {
this.delayedStartup();
},
uninit: function(){
uninit: function() {
window.removeEventListener('unload', this, false);
this.removePrefListener(this.PrefListener);
@ -50,7 +50,7 @@ var browserMenuDragging = {
},
initPref: function(){
initPref: function() {
this.STAY_OPEN_ONDRAGEXIT =
Services.prefs.getBoolPref('browser.menu.dragging.stayOpen', false);
this.DEBUG =
@ -58,12 +58,12 @@ var browserMenuDragging = {
},
//delayed startup
delayedStartup: function(){
delayedStartup: function() {
//wait until construction of bookmarksBarContent is completed.
for (var i = 0; i < this.menupopup.length; i++){
for (var i = 0; i < this.menupopup.length; i++) {
this.count[i] = 0;
this.timer[i] = setInterval(function(self, i){
if(++self.count[i] > 50 || document.getElementById(self.menupopup[i])){
this.timer[i] = setInterval(function(self, i) {
if(++self.count[i] > 50 || document.getElementById(self.menupopup[i])) {
clearInterval(self.timer[i]);
var menupopup = document.getElementById(self.menupopup[i]);
if (menupopup) {
@ -75,7 +75,7 @@ var browserMenuDragging = {
}
},
handleEvent: function(event){
handleEvent: function(event) {
switch (event.type) {
case 'popupshowing':
this.popupshowing(event);
@ -105,12 +105,14 @@ var browserMenuDragging = {
// leaves button depressed/sunken when hovered
menupopup.parentNode.parentNode._openedMenuButton = null;
if (!PlacesControllerDragHelper.getSession())
// Clear the dragover attribute if present, if we are dragging into a
// folder in the hierachy of current opened popup we don't clear
// this attribute on clearOverFolder. See Notify for closeTimer.
if (menupopup.parentNode.hasAttribute('dragover'))
menupopup.parentNode.removeAttribute('dragover');
if (!PlacesControllerDragHelper.getSession()) {
// Clear the dragover attribute if present, if we are dragging into a
// folder in the hierachy of current opened popup we don't clear
// this attribute on clearOverFolder. See Notify for closeTimer.
if (menupopup.parentNode.hasAttribute('dragover')) {
menupopup.parentNode.removeAttribute('dragover');
}
}
}
},
@ -120,10 +122,11 @@ var browserMenuDragging = {
var parentPopup = menupopup.parentNode.parentNode;
if (!!parentPopup.openNode){
if (!!parentPopup.openNode) {
try {
parentPopup.openNode.hidePopup();
} catch(e){}
} catch(e) {
}
}
parentPopup.openNode = menupopup;
@ -138,12 +141,16 @@ var browserMenuDragging = {
var target = event.originalTarget;
while (target) {
if (/menupopup/.test(target.localName))
if (/menupopup/.test(target.localName)) {
break;
}
target = target.parentNode;
}
if (this != target)
if (this != target) {
return;
}
event.stopPropagation();
browserMenuDragging.debug("onDragOver " + "\n" + this.parentNode.getAttribute('label'));
@ -201,13 +208,13 @@ var browserMenuDragging = {
if (scrollDir == 0) {
let elt = this.firstChild;
while (elt && event.screenY > elt.boxObject.screenY +
elt.boxObject.height / 2)
elt.boxObject.height / 2) {
elt = elt.nextSibling;
newMarginTop = elt ? elt.boxObject.screenY - sbo.screenY :
sbo.height;
}
else if (scrollDir == 1)
}
newMarginTop = elt ? elt.boxObject.screenY - sbo.screenY : sbo.height;
} else if (scrollDir == 1) {
newMarginTop = sbo.height;
}
// Set the new marginTop based on arrowscrollbox.
newMarginTop += sbo.y - this._scrollBox.boxObject.y;
@ -221,12 +228,16 @@ var browserMenuDragging = {
menupopup.onDragExit = function (event) {
var target = event.originalTarget;
while (target) {
if (/menupopup/.test(target.localName))
if (/menupopup/.test(target.localName)) {
break;
}
target = target.parentNode;
}
if (this != target)
if (this != target) {
return;
}
event.stopPropagation();
browserMenuDragging.debug("onDragExit " + browserMenuDragging.STAY_OPEN_ONDRAGEXIT);
@ -236,13 +247,13 @@ var browserMenuDragging = {
// If we have not moved to a valid new target clear the drop indicator
// this happens when moving out of the popup.
target = event.relatedTarget;
if (!target)
if (!target) {
this._indicatorBar.hidden = true;
}
// Close any folder being hovered over
if (this._overFolder.elt) {
this._overFolder.closeTimer = this._overFolder
.setTimer(this._overFolder.hoverTime);
this._overFolder.closeTimer = this._overFolder.setTimer(this._overFolder.hoverTime);
}
// The auto-opened attribute is set when this folder was automatically
@ -268,12 +279,13 @@ var browserMenuDragging = {
hideTooltip: function() {
['bhTooltip', 'btTooltip2'].forEach(function(id) {
var tooltip = document.getElementById(id);
if (tooltip)
if (tooltip) {
tooltip.hidePopup();
}
});
},
get getVer(){
get getVer() {
const Cc = Components.classes;
const Ci = Components.interfaces;
var info = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
@ -281,17 +293,18 @@ var browserMenuDragging = {
return ver;
},
debug: function(aMsg){
if (!browserMenuDragging.DEBUG)
debug: function(aMsg) {
if (!browserMenuDragging.DEBUG) {
return;
}
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(aMsg);
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(aMsg);
},
setPref: function(aPrefString, aPrefType, aValue){
setPref: function(aPrefString, aPrefType, aValue) {
var xpPref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
.getService(Components.interfaces.nsIPrefService);
try{
switch (aPrefType){
case 'complex':
@ -305,7 +318,7 @@ var browserMenuDragging = {
default:
return xpPref.setBoolPref(aPrefString, aValue); break;
}
}catch(e){
} catch(e) {
}
return null;
},
@ -315,7 +328,8 @@ var browserMenuDragging = {
var pbi = Components.classes["@mozilla.org/preferences;1"].
getService(Components.interfaces.nsIPrefBranch2);
pbi.addObserver(aObserver.domain, aObserver, false);
} catch(e) {}
} catch(e) {
}
},
removePrefListener: function(aObserver) {
@ -323,7 +337,8 @@ var browserMenuDragging = {
var pbi = Components.classes["@mozilla.org/preferences;1"].
getService(Components.interfaces.nsIPrefBranch2);
pbi.removeObserver(aObserver.domain, aObserver);
} catch(e) {}
} catch(e) {
}
},
PrefListener:{

View file

@ -40,8 +40,9 @@ var StarUI = {
_blockCommands: function() {
this._blockedCommands.forEach(function(elt) {
// make sure not to permanently disable this item (see bug 409155)
if (elt.hasAttribute("wasDisabled"))
if (elt.hasAttribute("wasDisabled")) {
return;
}
if (elt.getAttribute("disabled") == "true") {
elt.setAttribute("wasDisabled", "true");
} else {
@ -53,8 +54,9 @@ var StarUI = {
_restoreCommandsState: function() {
this._blockedCommands.forEach(function(elt) {
if (elt.getAttribute("wasDisabled") != "true")
if (elt.getAttribute("wasDisabled") != "true") {
elt.removeAttribute("disabled");
}
elt.removeAttribute("wasDisabled");
});
},
@ -64,8 +66,9 @@ var StarUI = {
switch (aEvent.type) {
case "popuphidden":
if (aEvent.originalTarget == this.panel) {
if (!this._element("editBookmarkPanelContent").hidden)
if (!this._element("editBookmarkPanelContent").hidden) {
this.quitEditMode();
}
this._restoreCommandsState();
this._itemId = -1;
@ -102,8 +105,9 @@ var StarUI = {
}
switch (aEvent.keyCode) {
case KeyEvent.DOM_VK_ESCAPE:
if (!this._element("editBookmarkPanelContent").hidden)
if (!this._element("editBookmarkPanelContent").hidden) {
this.cancelButtonOnCommand();
}
break;
case KeyEvent.DOM_VK_RETURN:
if (aEvent.target.className == "expander-up" ||
@ -126,8 +130,9 @@ var StarUI = {
function(aItemId, aAnchorElement, aPosition) {
// Performance: load the overlay the first time the panel is opened
// (see bug 392443).
if (this._overlayLoading)
if (this._overlayLoading) {
return;
}
if (this._overlayLoaded) {
this._doShowEditBookmarkPanel(aItemId, aAnchorElement, aPosition);
@ -157,8 +162,9 @@ var StarUI = {
_doShowEditBookmarkPanel:
function(aItemId, aAnchorElement, aPosition) {
if (this.panel.state != "closed")
if (this.panel.state != "closed") {
return;
}
this._blockCommands(); // un-done in the popuphiding handler
@ -168,8 +174,8 @@ var StarUI = {
// we are about editing it, then use Edit This Bookmark.
this._element("editBookmarkPanelTitle").value =
this._batching ?
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle");
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle");
// No description; show the Done, Cancel;
this._element("editBookmarkPanelDescription").textContent = "";
@ -222,8 +228,7 @@ var StarUI = {
var elt = this._element(fieldToFocus);
elt.focus();
elt.select();
}
else {
} else {
// Note this isn't actually used anymore, we should remove this
// once we decide not to bring back the page bookmarked notification
this.panel.focus();
@ -294,8 +299,8 @@ var PlacesCommandHook = {
title = title || url.spec;
description = PlacesUIUtils.getDescriptionFromDocument(webNav.document);
charset = webNav.document.characterSet;
} catch(e) {
}
catch (e) { }
if (aShowEditUI) {
// If we bookmark the page here (i.e. page was not "starred" already)
@ -305,7 +310,8 @@ var PlacesCommandHook = {
}
var parent = aParent != undefined ?
aParent : PlacesUtils.unfiledBookmarksFolderId;
aParent :
PlacesUtils.unfiledBookmarksFolderId;
var descAnno = { name: PlacesUIUtils.DESCRIPTION_ANNO, value: description };
var txn = new PlacesCreateBookmarkTransaction(uri, parent,
PlacesUtils.bookmarks.DEFAULT_INDEX,
@ -313,17 +319,20 @@ var PlacesCommandHook = {
PlacesUtils.transactionManager.doTransaction(txn);
itemId = txn.item.id;
// Set the character-set
if (charset && !PrivateBrowsingUtils.isWindowPrivate(aBrowser.contentWindow))
if (charset && !PrivateBrowsingUtils.isWindowPrivate(aBrowser.contentWindow)) {
PlacesUtils.setCharsetForURI(uri, charset);
}
}
// Revert the contents of the location bar
if (gURLBar)
if (gURLBar) {
gURLBar.handleRevert();
}
// If it was not requested to open directly in "edit" mode, we are done.
if (!aShowEditUI)
if (!aShowEditUI) {
return;
}
// Try to dock the panel to:
// 1. the bookmarks menu button
@ -365,20 +374,19 @@ var PlacesCommandHook = {
var linkURI = makeURI(aURL);
var itemId = PlacesUtils.getMostRecentBookmarkForURI(linkURI);
if (itemId == -1) {
PlacesUIUtils.showBookmarkDialog({ action: "add"
, type: "bookmark"
, uri: linkURI
, title: aTitle
, hiddenRows: [ "description"
, "location"
, "loadInSidebar"
, "keyword" ]
PlacesUIUtils.showBookmarkDialog({ action: "add",
type: "bookmark",
uri: linkURI,
title: aTitle,
hiddenRows: [ "description",
"location",
"loadInSidebar",
"keyword" ]
}, window);
}
else {
PlacesUIUtils.showBookmarkDialog({ action: "edit"
, type: "bookmark"
, itemId: itemId
} else {
PlacesUIUtils.showBookmarkDialog({ action: "edit",
type: "bookmark",
itemId: itemId
}, window);
}
},
@ -408,10 +416,10 @@ var PlacesCommandHook = {
bookmarkCurrentPages: function() {
let pages = this.uniqueCurrentPages;
if (pages.length > 1) {
PlacesUIUtils.showBookmarkDialog({ action: "add"
, type: "folder"
, URIList: pages
, hiddenRows: [ "description" ]
PlacesUIUtils.showBookmarkDialog({ action: "add",
type: "folder",
URIList: pages,
hiddenRows: [ "description" ]
}, window);
}
},
@ -419,11 +427,11 @@ var PlacesCommandHook = {
/**
* Updates disabled state for the "Bookmark All Tabs" command.
*/
updateBookmarkAllTabsCommand:
function() {
updateBookmarkAllTabsCommand: function() {
// There's nothing to do in non-browser windows.
if (window.location.href != getBrowserURL())
if (window.location.href != getBrowserURL()) {
return;
}
// Disable "Bookmark All Tabs" if there are less than two
// "unique current pages".
@ -450,16 +458,16 @@ var PlacesCommandHook = {
description = PlacesUIUtils.getDescriptionFromDocument(gBrowser.contentDocument);
}
PlacesUIUtils.showBookmarkDialog({ action: "add"
, type: "livemark"
, feedURI: feedURI
, siteURI: gBrowser.currentURI
, title: title
, description: description
, defaultInsertionPoint: toolbarIP
, hiddenRows: [ "feedLocation"
, "siteLocation"
, "description" ]
PlacesUIUtils.showBookmarkDialog({ action: "add",
type: "livemark",
feedURI: feedURI,
siteURI: gBrowser.currentURI,
title: title,
description: description,
defaultInsertionPoint: toolbarIP,
hiddenRows: [ "feedLocation",
"siteLocation",
"description" ]
}, window);
},
@ -477,8 +485,7 @@ var PlacesCommandHook = {
// No currently open places window, so open one with the specified mode.
openDialog("chrome://browser/content/places/places.xul",
"", "chrome,toolbar=yes,dialog=no,resizable", aLeftPaneRoot);
}
else {
} else {
organizer.PlacesOrganizer.selectLeftPaneQuery(aLeftPaneRoot);
organizer.focus();
}
@ -507,10 +514,11 @@ HistoryMenu.prototype = {
let restoreItem = this._rootElt.ownerDocument.getElementById("Browser:RestoreLastSession");
if (this._ss.canRestoreLastSession &&
!PrivateBrowsingUtils.isWindowPrivate(window))
!PrivateBrowsingUtils.isWindowPrivate(window)) {
restoreItem.removeAttribute("disabled");
else
} else {
restoreItem.setAttribute("disabled", true);
}
},
toggleRecentlyClosedTabs: function() {
@ -518,10 +526,11 @@ HistoryMenu.prototype = {
var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedTabsMenu")[0];
// no restorable tabs, so disable menu
if (this._ss.getClosedTabCount(window) == 0)
if (this._ss.getClosedTabCount(window) == 0) {
undoMenu.setAttribute("disabled", true);
else
} else {
undoMenu.removeAttribute("disabled");
}
},
/**
@ -531,8 +540,9 @@ HistoryMenu.prototype = {
* The event when the user clicks the menu item
*/
_undoCloseMiddleClick: function(aEvent) {
if (aEvent.button != 1)
if (aEvent.button != 1) {
return;
}
undoCloseTab(aEvent.originalTarget.value);
gBrowser.moveTabToEnd();
@ -546,8 +556,9 @@ HistoryMenu.prototype = {
var undoPopup = undoMenu.firstChild;
// remove existing menu items
while (undoPopup.hasChildNodes())
while (undoPopup.hasChildNodes()) {
undoPopup.removeChild(undoPopup.firstChild);
}
// no restorable tabs, so make sure menu is disabled, and return
if (this._ss.getClosedTabCount(window) == 0) {
@ -566,8 +577,9 @@ HistoryMenu.prototype = {
if (undoItems[i].image) {
let iconURL = undoItems[i].image;
// don't initiate a connection just to fetch a favicon (see bug 467828)
if (/^https?:/.test(iconURL))
if (/^https?:/.test(iconURL)) {
iconURL = "moz-anno:favicon:" + iconURL;
}
m.setAttribute("image", iconURL);
}
m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon");
@ -579,12 +591,14 @@ HistoryMenu.prototype = {
// normalize them.
let tabData = undoItems[i].state;
let activeIndex = (tabData.index || tabData.entries.length) - 1;
if (activeIndex >= 0 && tabData.entries[activeIndex])
if (activeIndex >= 0 && tabData.entries[activeIndex]) {
m.setAttribute("targetURI", tabData.entries[activeIndex].url);
}
m.addEventListener("click", this._undoCloseMiddleClick, false);
if (i == 0)
if (i == 0) {
m.setAttribute("key", "key_undoCloseTab");
}
undoPopup.appendChild(m);
}
@ -595,8 +609,9 @@ HistoryMenu.prototype = {
m.id = "menu_restoreAllTabs";
m.setAttribute("label", strings.getString("menuRestoreAllTabs.label"));
m.addEventListener("command", function() {
for (var i = 0; i < undoItems.length; i++)
for (var i = 0; i < undoItems.length; i++) {
undoCloseTab();
}
}, false);
},
@ -605,10 +620,11 @@ HistoryMenu.prototype = {
var undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0];
// no restorable windows, so disable menu
if (this._ss.getClosedWindowCount() == 0)
if (this._ss.getClosedWindowCount() == 0) {
undoMenu.setAttribute("disabled", true);
else
} else {
undoMenu.removeAttribute("disabled");
}
},
/**
@ -618,12 +634,12 @@ HistoryMenu.prototype = {
let undoMenu = this._rootElt.getElementsByClassName("recentlyClosedWindowsMenu")[0];
let undoPopup = undoMenu.firstChild;
let menuLabelString = gNavigatorBundle.getString("menuUndoCloseWindowLabel");
let menuLabelStringSingleTab =
gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");
let menuLabelStringSingleTab = gNavigatorBundle.getString("menuUndoCloseWindowSingleTabLabel");
// remove existing menu items
while (undoPopup.hasChildNodes())
while (undoPopup.hasChildNodes()) {
undoPopup.removeChild(undoPopup.firstChild);
}
// no restorable windows, so make sure menu is disabled, and return
if (this._ss.getClosedWindowCount() == 0) {
@ -649,8 +665,9 @@ HistoryMenu.prototype = {
if (selectedTab.image) {
let iconURL = selectedTab.image;
// don't initiate a connection just to fetch a favicon (see bug 467828)
if (/^https?:/.test(iconURL))
if (/^https?:/.test(iconURL)) {
iconURL = "moz-anno:favicon:" + iconURL;
}
m.setAttribute("image", iconURL);
}
m.setAttribute("class", "menuitem-iconic bookmark-item menuitem-with-favicon");
@ -659,11 +676,13 @@ HistoryMenu.prototype = {
// Set the targetURI attribute so it will be shown in tooltip.
// SessionStore uses one-based indexes, so we need to normalize them.
let activeIndex = (selectedTab.index || selectedTab.entries.length) - 1;
if (activeIndex >= 0 && selectedTab.entries[activeIndex])
if (activeIndex >= 0 && selectedTab.entries[activeIndex]) {
m.setAttribute("targetURI", selectedTab.entries[activeIndex].url);
}
if (i == 0)
if (i == 0) {
m.setAttribute("key", "key_undoCloseWindow");
}
undoPopup.appendChild(m);
}
@ -682,8 +701,9 @@ HistoryMenu.prototype = {
// Enable/disable the Tabs From Other Computers menu. Some of the menus handled
// by HistoryMenu do not have this menuitem.
let menuitem = this._rootElt.getElementsByClassName("syncTabsMenuItem")[0];
if (!menuitem)
if (!menuitem) {
return;
}
// If Sync isn't configured yet, then don't show the menuitem.
if (Weave.Status.checkSetup() == Weave.CLIENT_NOT_CONFIGURED ||
@ -706,8 +726,9 @@ HistoryMenu.prototype = {
PlacesMenu.prototype._onPopupShowing.apply(this, arguments);
// Don't handle events for submenus.
if (aEvent.target != aEvent.currentTarget)
if (aEvent.target != aEvent.currentTarget) {
return;
}
this.toggleRestoreLastSession();
this.toggleRecentlyClosedTabs();
@ -718,8 +739,9 @@ HistoryMenu.prototype = {
_onCommand: function(aEvent) {
let placesNode = aEvent.target._placesNode;
if (placesNode) {
if (!PrivateBrowsingUtils.isWindowPrivate(window))
if (!PrivateBrowsingUtils.isWindowPrivate(window)) {
PlacesUIUtils.markPageAsTyped(placesNode.uri);
}
openUILink(placesNode.uri, aEvent, { ignoreAlt: true });
}
}
@ -750,21 +772,23 @@ var BookmarksEventHandler = {
#else
var modifKey = aEvent.ctrlKey || aEvent.shiftKey;
#endif
if (aEvent.button == 2 || (aEvent.button == 0 && !modifKey))
if (aEvent.button == 2 || (aEvent.button == 0 && !modifKey)) {
return;
}
var target = aEvent.originalTarget;
// If this event bubbled up from a menu or menuitem, close the menus.
// Do this before opening tabs, to avoid hiding the open tabs confirm-dialog.
if (target.localName == "menu" || target.localName == "menuitem") {
for (node = target.parentNode; node; node = node.parentNode) {
if (node.localName == "menupopup")
if (node.localName == "menupopup") {
node.hidePopup();
else if (node.localName != "menu" &&
node.localName != "splitmenu" &&
node.localName != "hbox" &&
node.localName != "vbox" )
} else if (node.localName != "menu" &&
node.localName != "splitmenu" &&
node.localName != "hbox" &&
node.localName != "vbox" ) {
break;
}
}
}
@ -772,10 +796,10 @@ var BookmarksEventHandler = {
// Don't open the root folder in tabs when the empty area on the toolbar
// is middle-clicked or when a non-bookmark item except for Open in Tabs)
// in a bookmarks menupopup is middle-clicked.
if (target.localName == "menu" || target.localName == "toolbarbutton")
if (target.localName == "menu" || target.localName == "toolbarbutton") {
PlacesUIUtils.openContainerNodeInTabs(target._placesNode, aEvent, aView);
}
else if (aEvent.button == 1) {
}
} else if (aEvent.button == 1) {
// left-clicks with modifier are already served by onCommand
this.onCommand(aEvent, aView);
}
@ -792,8 +816,9 @@ var BookmarksEventHandler = {
*/
onCommand: function(aEvent, aView) {
var target = aEvent.originalTarget;
if (target._placesNode)
if (target._placesNode) {
PlacesUIUtils.openNodeWithEvent(target._placesNode, aEvent, aView);
}
},
fillInBHTooltip: function(aDocument, aEvent) {
@ -805,47 +830,52 @@ var BookmarksEventHandler = {
var tree = aDocument.tooltipNode.parentNode;
var tbo = tree.treeBoxObject;
var cell = tbo.getCellAt(aEvent.clientX, aEvent.clientY);
if (cell.row == -1)
if (cell.row == -1) {
return false;
}
node = tree.view.nodeForTreeIndex(cell.row);
cropped = tbo.isCellCropped(cell.row, cell.col);
}
else {
} else {
// Check whether the tooltipNode is a Places node.
// In such a case use it, otherwise check for targetURI attribute.
var tooltipNode = aDocument.tooltipNode;
if (tooltipNode._placesNode)
if (tooltipNode._placesNode) {
node = tooltipNode._placesNode;
else {
} else {
// This is a static non-Places node.
targetURI = tooltipNode.getAttribute("targetURI");
}
}
if (!node && !targetURI)
if (!node && !targetURI) {
return false;
}
// Show node.label as tooltip's title for non-Places nodes.
var title = node ? node.title : tooltipNode.label;
// Show URL only for Places URI-nodes or nodes with a targetURI attribute.
var url;
if (targetURI || PlacesUtils.nodeIsURI(node))
if (targetURI || PlacesUtils.nodeIsURI(node)) {
url = targetURI || node.uri;
}
// Show tooltip for containers only if their title is cropped.
if (!cropped && !url)
if (!cropped && !url) {
return false;
}
var tooltipTitle = aDocument.getElementById("bhtTitleText");
tooltipTitle.hidden = (!title || (title == url));
if (!tooltipTitle.hidden)
if (!tooltipTitle.hidden) {
tooltipTitle.textContent = title;
}
var tooltipUrl = aDocument.getElementById("bhtUrlText");
tooltipUrl.hidden = !url;
if (!tooltipUrl.hidden)
if (!tooltipUrl.hidden) {
tooltipUrl.value = url;
}
// Show tooltip.
return true;
@ -869,12 +899,14 @@ var PlacesMenuDNDHandler = {
*/
onDragEnter: function(event) {
// Opening menus in a Places popup is handled by the view itself.
if (!this._isStaticContainer(event.target))
if (!this._isStaticContainer(event.target)) {
return;
}
let popup = event.target.lastChild;
if (this._loadTimer || popup.state === "showing" || popup.state === "open")
if (this._loadTimer || popup.state === "showing" || popup.state === "open") {
return;
}
this._loadTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
this._loadTimer.initWithCallback(() => {
@ -894,12 +926,14 @@ var PlacesMenuDNDHandler = {
onDragLeave: function(event) {
// Handle menu-button separate targets.
if (event.relatedTarget === event.currentTarget ||
event.relatedTarget.parentNode === event.currentTarget)
event.relatedTarget.parentNode === event.currentTarget) {
return;
}
// Closing menus in a Places popup is handled by the view itself.
if (!this._isStaticContainer(event.target))
if (!this._isStaticContainer(event.target)) {
return;
}
let popup = event.target.lastChild;
@ -933,7 +967,8 @@ var PlacesMenuDNDHandler = {
(node.localName == "toolbarbutton" &&
(node.getAttribute("type") == "menu" ||
node.getAttribute("type") == "menu-button"));
let isStatic = !("_placesNode" in node) && node.lastChild &&
let isStatic = !("_placesNode" in node) &&
node.lastChild &&
node.lastChild.hasAttribute("placespopup") &&
!node.parentNode.hasAttribute("placespopup");
return isMenu && isStatic;
@ -948,8 +983,9 @@ var PlacesMenuDNDHandler = {
let ip = new InsertionPoint(PlacesUtils.bookmarksMenuFolderId,
PlacesUtils.bookmarks.DEFAULT_INDEX,
Ci.nsITreeView.DROP_ON);
if (ip && PlacesControllerDragHelper.canDrop(ip, event.dataTransfer))
if (ip && PlacesControllerDragHelper.canDrop(ip, event.dataTransfer)) {
event.preventDefault();
}
event.stopPropagation();
},
@ -985,8 +1021,9 @@ var PlacesToolbarHelper = {
init: function() {
let viewElt = this._viewElt;
if (!viewElt || viewElt._placesView)
if (!viewElt || viewElt._placesView) {
return;
}
// If the bookmarks toolbar item is hidden because the parent toolbar is
// collapsed or hidden (i.e. in a popup), spare the initialization. Also,
@ -995,16 +1032,18 @@ var PlacesToolbarHelper = {
let toolbar = viewElt.parentNode.parentNode;
if (toolbar.collapsed ||
getComputedStyle(toolbar, "").display == "none" ||
this._isCustomizing)
this._isCustomizing) {
return;
}
new PlacesToolbar(this._place);
},
customizeStart: function() {
let viewElt = this._viewElt;
if (viewElt && viewElt._placesView)
if (viewElt && viewElt._placesView) {
viewElt._placesView.uninit();
}
this._isCustomizing = true;
},
@ -1050,25 +1089,23 @@ var BookmarkingUI = {
STATUS_UNSTARRED: 0,
STATUS_STARRED: 1,
get status() {
if (this._pendingStmt)
if (this._pendingStmt) {
return this.STATUS_UPDATING;
}
return this.star &&
this.star.hasAttribute("starred") ? this.STATUS_STARRED
: this.STATUS_UNSTARRED;
this.star.hasAttribute("starred") ? this.STATUS_STARRED : this.STATUS_UNSTARRED;
},
get _starredTooltip()
{
delete this._starredTooltip;
return this._starredTooltip =
gNavigatorBundle.getString("starButtonOn.tooltip");
return this._starredTooltip = gNavigatorBundle.getString("starButtonOn.tooltip");
},
get _unstarredTooltip()
{
delete this._unstarredTooltip;
return this._unstarredTooltip =
gNavigatorBundle.getString("starButtonOff.tooltip");
return this._unstarredTooltip = gNavigatorBundle.getString("starButtonOff.tooltip");
},
/**
@ -1084,11 +1121,14 @@ var BookmarkingUI = {
onPopupShowing: function(event) {
// Don't handle events for submenus.
if (event.target != event.currentTarget)
if (event.target != event.currentTarget) {
return;
}
if (!this._popupNeedsUpdate)
if (!this._popupNeedsUpdate) {
return;
}
this._popupNeedsUpdate = false;
let popup = event.target;
@ -1124,8 +1164,7 @@ var BookmarkingUI = {
if (aState == "invalid") {
this.star.setAttribute("disabled", "true");
this.star.removeAttribute("starred");
}
else {
} else {
this.star.removeAttribute("disabled");
}
},
@ -1142,8 +1181,7 @@ var BookmarkingUI = {
if (onPersonalToolbar) {
this.button.classList.add("bookmark-item");
this.button.classList.remove("toolbarbutton-1");
}
else {
} else {
this.button.classList.remove("bookmark-item");
this.button.classList.add("toolbarbutton-1");
}
@ -1252,8 +1290,7 @@ var BookmarkingUI = {
if (this._itemIds.length > 0) {
this.star.setAttribute("starred", "true");
this.star.setAttribute("tooltiptext", this._starredTooltip);
}
else {
} else {
this.star.removeAttribute("starred");
this.star.setAttribute("tooltiptext", this._unstarredTooltip);
}
@ -1300,9 +1337,8 @@ var BookmarkingUI = {
if (index != -1 && aNewValue != this._uri.spec) {
this._itemIds.splice(index, 1);
this._updateStar();
}
// If another bookmark is now pointing to the tracked uri, register it.
else if (index == -1 && aNewValue == this._uri.spec) {
} else if (index == -1 && aNewValue == this._uri.spec) {
// If another bookmark is now pointing to the tracked uri, register it.
this._itemIds.push(aItemId);
this._updateStar();
}

View file

@ -64,8 +64,9 @@ var gPluginHandler = {
// Map the plugin's name to a filtered version more suitable for user UI.
makeNicePluginName : function(aName) {
if (aName == "Shockwave Flash")
if (aName == "Shockwave Flash") {
return "Adobe Flash";
}
// Clean up the plugin name by stripping off any trailing version numbers
// or "plugin". EG, "Foo Bar Plugin 1.23_02" --> "Foo Bar"
@ -94,34 +95,37 @@ var gPluginHandler = {
let callbackArgs = Array.prototype.slice.call(arguments).slice(2);
linkNode.addEventListener("click",
function(evt) {
if (!evt.isTrusted)
if (!evt.isTrusted) {
return;
}
evt.preventDefault();
if (callbackArgs.length == 0)
if (callbackArgs.length == 0) {
callbackArgs = [ evt ];
}
(self[callbackName]).apply(self, callbackArgs);
},
true);
}, true);
linkNode.addEventListener("keydown",
function(evt) {
if (!evt.isTrusted)
if (!evt.isTrusted) {
return;
}
if (evt.keyCode == evt.DOM_VK_RETURN) {
evt.preventDefault();
if (callbackArgs.length == 0)
if (callbackArgs.length == 0) {
callbackArgs = [ evt ];
}
evt.preventDefault();
(self[callbackName]).apply(self, callbackArgs);
}
},
true);
}, true);
},
// Helper to get the binding handler type from a plugin object
_getBindingType : function(plugin) {
if (!(plugin instanceof Ci.nsIObjectLoadingContent))
if (!(plugin instanceof Ci.nsIObjectLoadingContent)) {
return null;
}
switch (plugin.pluginFallbackType) {
case Ci.nsIObjectLoadingContent.PLUGIN_UNSUPPORTED:
@ -153,13 +157,13 @@ var gPluginHandler = {
let eventType = event.type;
if (eventType === "PluginRemoved") {
doc = event.target;
}
else {
} else {
plugin = event.target;
doc = plugin.ownerDocument;
if (!(plugin instanceof Ci.nsIObjectLoadingContent))
if (!(plugin instanceof Ci.nsIObjectLoadingContent)) {
return;
}
}
if (eventType == "PluginBindingAttached") {
@ -182,8 +186,9 @@ var gPluginHandler = {
let shouldShowNotification = false;
let browser = gBrowser.getBrowserForDocument(doc.defaultView.top.document);
if (!browser)
if (!browser) {
return;
}
switch (eventType) {
case "PluginCrashed":
@ -278,8 +283,9 @@ var gPluginHandler = {
// if this isn't a known plugin, we can't activate it
// (this also guards pluginHost.getPermissionStringForType against
// unexpected input)
if (!gPluginHandler.isKnownPlugin(objLoadingContent))
if (!gPluginHandler.isKnownPlugin(objLoadingContent)) {
return false;
}
let pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
let permissionString = pluginHost.getPermissionStringForType(objLoadingContent.actualType);
@ -303,19 +309,22 @@ var gPluginHandler = {
hideClickToPlayOverlay: function(aPlugin) {
let overlay = this.getPluginUI(aPlugin, "main");
if (overlay)
if (overlay) {
overlay.style.visibility = "hidden";
}
},
stopPlayPreview: function(aPlugin, aPlayPlugin) {
let objLoadingContent = aPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
if (objLoadingContent.activated)
if (objLoadingContent.activated) {
return;
}
if (aPlayPlugin)
if (aPlayPlugin) {
objLoadingContent.playPlugin();
else
} else {
objLoadingContent.cancelPlayPreview();
}
},
// Callback for user clicking on a disabled plugin
@ -347,8 +356,9 @@ var gPluginHandler = {
let objLoadingContent = aPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
// guard against giving pluginHost.getPermissionStringForType a type
// not associated with any known plugin
if (!gPluginHandler.isKnownPlugin(objLoadingContent))
if (!gPluginHandler.isKnownPlugin(objLoadingContent)) {
return;
}
let permissionString = pluginHost.getPermissionStringForType(objLoadingContent.actualType);
let principal = doc.defaultView.top.document.nodePrincipal;
let pluginPermission = Services.perms.testPermissionFromPrincipal(principal, permissionString);
@ -356,8 +366,9 @@ var gPluginHandler = {
let overlay = this.getPluginUI(aPlugin, "main");
if (pluginPermission == Ci.nsIPermissionManager.DENY_ACTION) {
if (overlay)
if (overlay) {
overlay.style.visibility = "hidden";
}
return;
}
@ -365,8 +376,9 @@ var gPluginHandler = {
overlay.addEventListener("click", gPluginHandler._overlayClickListener, true);
let closeIcon = gPluginHandler.getPluginUI(aPlugin, "closeIcon");
closeIcon.addEventListener("click", function(aEvent) {
if (aEvent.button == 0 && aEvent.isTrusted)
if (aEvent.button == 0 && aEvent.isTrusted) {
gPluginHandler.hideClickToPlayOverlay(aPlugin);
}
}, true);
}
},
@ -379,8 +391,8 @@ var gPluginHandler = {
// drag-and-dropped a tab from a window containing only that tab. In
// that case, the window gets destroyed.
let browser = gBrowser.getBrowserForDocument ?
gBrowser.getBrowserForDocument(contentWindow.document) :
null;
gBrowser.getBrowserForDocument(contentWindow.document) :
null;
// If browser is null here, we've been drag-and-dropped from another
// window, and this is the wrong click handler.
if (!browser) {
@ -422,8 +434,9 @@ var gPluginHandler = {
// MozPlayPlugin event can be dispatched from the extension chrome
// code to replace the preview content with the native plugin
previewContent.addEventListener("MozPlayPlugin", function playPluginHandler(aEvent) {
if (!aEvent.isTrusted)
if (!aEvent.isTrusted) {
return;
}
previewContent.removeEventListener("MozPlayPlugin", playPluginHandler, true);
@ -432,8 +445,9 @@ var gPluginHandler = {
// cleaning up: removes overlay iframe from the DOM
let iframe = previewContent.getElementsByClassName("previewPluginContentFrame")[0];
if (iframe)
if (iframe) {
previewContent.removeChild(iframe);
}
}, true);
if (!playPreviewInfo.ignoreCTP) {
@ -450,11 +464,13 @@ var gPluginHandler = {
let plugins = cwu.plugins;
for (let plugin of plugins) {
let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
if (overlay)
if (overlay) {
overlay.removeEventListener("click", gPluginHandler._overlayClickListener, true);
}
let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
if (gPluginHandler.canActivatePlugin(objLoadingContent))
if (gPluginHandler.canActivatePlugin(objLoadingContent)) {
gPluginHandler._handleClickToPlayEvent(plugin);
}
}
gPluginHandler._showClickToPlayNotification(browser);
},
@ -462,8 +478,7 @@ var gPluginHandler = {
_clickToPlayNotificationEventCallback: function(event) {
if (event == "showing") {
gPluginHandler._makeCenterActions(this);
}
else if (event == "dismissed") {
} else if (event == "dismissed") {
// Once the popup is dismissed, clicking the icon should show the full
// list again
this.options.primaryPlugin = null;
@ -503,8 +518,7 @@ var gPluginHandler = {
if (permissionObj) {
pluginInfo.pluginPermissionPrePath = permissionObj.principal.originNoSuffix;
pluginInfo.pluginPermissionType = permissionObj.expireType;
}
else {
} else {
pluginInfo.pluginPermissionPrePath = principal.originNoSuffix;
pluginInfo.pluginPermissionType = undefined;
}
@ -513,8 +527,7 @@ var gPluginHandler = {
// TODO: allow the blocklist to specify a better link, bug 873093
if (pluginInfo.blocklistState == Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE) {
url = Services.urlFormatter.formatURLPref("plugins.update.url");
}
else if (pluginInfo.blocklistState != Ci.nsIBlocklistService.STATE_NOT_BLOCKED) {
} else if (pluginInfo.blocklistState != Ci.nsIBlocklistService.STATE_NOT_BLOCKED) {
url = Services.blocklist.getPluginBlocklistURL(pluginInfo.pluginTag);
}
pluginInfo.detailsLink = url;
@ -635,8 +648,9 @@ var gPluginHandler = {
}
let dismissed = notification ? notification.dismissed : true;
if (aPrimaryPlugin)
if (aPrimaryPlugin) {
dismissed = false;
}
let primaryPluginPermission = null;
if (aPrimaryPlugin) {
@ -649,8 +663,7 @@ var gPluginHandler = {
primaryPlugin: primaryPluginPermission
};
PopupNotifications.show(aBrowser, "click-to-play-plugins",
"", icon,
null, null, options);
"", icon, null, null, options);
},
// Crashed-plugin observer. Notified once per plugin crash, before events
@ -658,16 +671,18 @@ var gPluginHandler = {
pluginCrashed : function(subject, topic, data) {
let propertyBag = subject;
if (!(propertyBag instanceof Ci.nsIPropertyBag2) ||
!(propertyBag instanceof Ci.nsIWritablePropertyBag2))
return;
!(propertyBag instanceof Ci.nsIWritablePropertyBag2)) {
return;
}
},
// Crashed-plugin event listener. Called for every instance of a
// plugin in content.
pluginInstanceCrashed: function(plugin, aEvent) {
// Ensure the plugin and event are of the right type.
if (!(aEvent instanceof Ci.nsIDOMDataContainerEvent))
if (!(aEvent instanceof Ci.nsIDOMDataContainerEvent)) {
return;
}
let submittedReport = aEvent.getData("submittedCrashReport");
let doPrompt = true; // XXX followup for .getData("doPrompt");
@ -731,15 +746,17 @@ var gPluginHandler = {
function hideNotificationBar() {
let notification = notificationBox.getNotificationWithValue("plugin-crashed");
if (notification)
if (notification) {
notificationBox.removeNotification(notification, true);
}
}
function showNotificationBar(pluginDumpID, browserDumpID) {
// If there's already an existing notification bar, don't do anything.
let notification = notificationBox.getNotificationWithValue("plugin-crashed");
if (notification)
if (notification) {
return;
}
// Configure the notification bar
let priority = notificationBox.PRIORITY_WARNING_MEDIUM;
@ -757,7 +774,7 @@ var gPluginHandler = {
}];
notification = notificationBox.appendNotification(messageString, "plugin-crashed",
iconURL, priority, buttons);
iconURL, priority, buttons);
// Add the "learn more" link.
let XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";

View file

@ -109,12 +109,14 @@ var gSyncUI = {
// Functions called by observers
onActivityStart: function() {
if (!gBrowser)
if (!gBrowser) {
return;
}
let button = document.getElementById("sync-button");
if (!button)
if (!button) {
return;
}
button.setAttribute("status", "active");
},
@ -173,7 +175,10 @@ var gSyncUI = {
buttons.push(new Weave.NotificationButton(
this._stringBundle.GetStringFromName("error.login.prefs.label"),
this._stringBundle.GetStringFromName("error.login.prefs.accesskey"),
function() { gSyncUI.openPrefs(); return true; }
function() {
gSyncUI.openPrefs();
return true;
}
));
let notification = new Weave.Notification(title, description, null,
@ -197,7 +202,10 @@ var gSyncUI = {
buttons.push(new Weave.NotificationButton(
this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.label"),
this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.accesskey"),
function() { gSyncUI.openQuotaDialog(); return true; }
function() {
gSyncUI.openQuotaDialog();
return true;
}
));
let notification = new Weave.Notification(
@ -216,10 +224,11 @@ var gSyncUI = {
},
handleToolbarButton: function() {
if (this._needsSetup())
if (this._needsSetup()) {
this.openSetup();
else
} else {
this.doSync();
}
},
//XXXzpao should be part of syncCommon.js - which we might want to make a module...
@ -237,9 +246,9 @@ var gSyncUI = {
openSetup: function(wizardType) {
let win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
if (win)
if (win) {
win.focus();
else {
} else {
window.openDialog("chrome://browser/content/sync/setup.xul",
"weaveSetup", "centerscreen,chrome,resizable=no",
wizardType);
@ -247,25 +256,28 @@ var gSyncUI = {
},
openAddDevice: function() {
if (!Weave.Utils.ensureMPUnlocked())
if (!Weave.Utils.ensureMPUnlocked()) {
return;
}
let win = Services.wm.getMostRecentWindow("Sync:AddDevice");
if (win)
if (win) {
win.focus();
else
} else {
window.openDialog("chrome://browser/content/sync/addDevice.xul",
"syncAddDevice", "centerscreen,chrome,resizable=no");
}
},
openQuotaDialog: function() {
let win = Services.wm.getMostRecentWindow("Sync:ViewQuota");
if (win)
if (win) {
win.focus();
else
} else {
Services.ww.activeWindow.openDialog(
"chrome://browser/content/sync/quota.xul", "",
"centerscreen,chrome,dialog,modal");
}
},
openPrefs: function() {
@ -275,12 +287,14 @@ var gSyncUI = {
// Helpers
_updateLastSyncTime: function() {
if (!gBrowser)
if (!gBrowser) {
return;
}
let syncButton = document.getElementById("sync-button");
if (!syncButton)
if (!syncButton) {
return;
}
let lastSync = Services.prefs.getCharPref("services.sync.lastSync");
if (!lastSync || this._needsSetup()) {
@ -339,8 +353,9 @@ var gSyncUI = {
// Check if the client is outdated in some way
let outdated = Weave.Status.sync == Weave.VERSION_OUT_OF_DATE;
for (let [engine, reason] in Iterator(Weave.Status.engines))
for (let [engine, reason] in Iterator(Weave.Status.engines)) {
outdated = outdated || reason == Weave.VERSION_OUT_OF_DATE;
}
if (outdated) {
description = this._stringBundle.GetStringFromName(
@ -353,8 +368,7 @@ var gSyncUI = {
return true;
}
));
}
else if (Weave.Status.sync == Weave.OVER_QUOTA) {
} else if (Weave.Status.sync == Weave.OVER_QUOTA) {
description = this._stringBundle.GetStringFromName(
"error.sync.quota.description");
buttons.push(new Weave.NotificationButton(
@ -362,23 +376,30 @@ var gSyncUI = {
"error.sync.viewQuotaButton.label"),
this._stringBundle.GetStringFromName(
"error.sync.viewQuotaButton.accesskey"),
function() { gSyncUI.openQuotaDialog(); return true; } )
);
}
else if (Weave.Status.enforceBackoff) {
function() {
gSyncUI.openQuotaDialog();
return true;
}
));
} else if (Weave.Status.enforceBackoff) {
priority = Weave.Notifications.PRIORITY_INFO;
buttons.push(new Weave.NotificationButton(
this._stringBundle.GetStringFromName("error.sync.serverStatusButton.label"),
this._stringBundle.GetStringFromName("error.sync.serverStatusButton.accesskey"),
function() { gSyncUI.openServerStatus(); return true; }
function() {
gSyncUI.openServerStatus();
return true;
}
));
}
else {
} else {
priority = Weave.Notifications.PRIORITY_INFO;
buttons.push(new Weave.NotificationButton(
this._stringBundle.GetStringFromName("error.sync.tryAgainButton.label"),
this._stringBundle.GetStringFromName("error.sync.tryAgainButton.accesskey"),
function() { gSyncUI.doSync(); return true; }
function() {
gSyncUI.doSync();
return true;
}
));
}

View file

@ -23,8 +23,9 @@ var tabPreviews = {
},
init: function() {
if (this._selectedTab)
if (this._selectedTab) {
return;
}
this._selectedTab = gBrowser.selectedTab;
gBrowser.tabContainer.addEventListener("TabSelect", this, false);
@ -40,8 +41,9 @@ var tabPreviews = {
aTab.__thumbnail_lastURI = null;
}
if (aTab.__thumbnail)
if (aTab.__thumbnail) {
return aTab.__thumbnail;
}
if (aTab.getAttribute("pending") == "true") {
let img = new Image;
@ -90,8 +92,9 @@ var tabPreviews = {
self._pendingUpdate = false;
if (aTab.parentNode &&
!aTab.hasAttribute("busy") &&
!aTab.hasAttribute("pending"))
!aTab.hasAttribute("pending")) {
self.capture(aTab, true);
}
}, 2000, this, this._selectedTab);
}
this._selectedTab = event.target;
@ -123,20 +126,23 @@ var tabPreviewPanelHelper = {
};
},
_popupshown: function(host) {
if ("setupGUI" in host)
if ("setupGUI" in host) {
host.setupGUI();
}
},
_popuphiding: function(host) {
if ("suspendGUI" in host)
if ("suspendGUI" in host) {
host.suspendGUI();
}
if (host._prevFocus) {
Cc["@mozilla.org/focus-manager;1"]
.getService(Ci.nsIFocusManager)
.setFocus(host._prevFocus, Ci.nsIFocusManager.FLAG_NOSCROLL);
host._prevFocus = null;
} else
} else {
gBrowser.selectedBrowser.focus();
}
if (host.tabToSelect) {
gBrowser.selectedTab = host.tabToSelect;
@ -149,23 +155,23 @@ var tabPreviewPanelHelper = {
* Ctrl-Tab panel
*/
var ctrlTab = {
get panel () {
get panel() {
delete this.panel;
return this.panel = document.getElementById("ctrlTab-panel");
},
get showAllButton () {
get showAllButton() {
delete this.showAllButton;
return this.showAllButton = document.getElementById("ctrlTab-showAll");
},
get previews () {
get previews() {
delete this.previews;
return this.previews = this.panel.getElementsByClassName("ctrlTab-preview");
},
get recentlyUsedLimit () {
get recentlyUsedLimit() {
delete this.recentlyUsedLimit;
return this.recentlyUsedLimit = gPrefService.getIntPref("browser.ctrlTab.recentlyUsedLimit");
},
get keys () {
get keys() {
var keys = {};
["close", "find", "selectAll"].forEach(function(key) {
keys[key] = document.getElementById("key_" + key)
@ -176,17 +182,26 @@ var ctrlTab = {
return this.keys = keys;
},
_selectedIndex: 0,
get selected () this._selectedIndex < 0 ?
document.activeElement :
this.previews.item(this._selectedIndex),
get isOpen () this.panel.state == "open" || this.panel.state == "showing" || this._timer,
get tabCount () this.tabList.length,
get tabPreviewCount () Math.min(this.previews.length - 1, this.tabCount),
get canvasWidth () Math.min(tabPreviews.width,
Math.ceil(screen.availWidth * .85 / this.tabPreviewCount)),
get canvasHeight () Math.round(this.canvasWidth * tabPreviews.aspectRatio),
get selected() {
return this._selectedIndex < 0 ? document.activeElement : this.previews.item(this._selectedIndex);
},
get isOpen() {
return this.panel.state == "open" || this.panel.state == "showing" || this._timer;
},
get tabCount() {
return this.tabList.length;
},
get tabPreviewCount() {
return Math.min(this.previews.length - 1, this.tabCount);
},
get canvasWidth() {
return Math.min(tabPreviews.width, Math.ceil(screen.availWidth * .85 / this.tabPreviewCount));
},
get canvasHeight() {
return Math.round(this.canvasWidth * tabPreviews.aspectRatio);
},
get tabList () {
get tabList() {
if (this._tabList)
return this._tabList;
@ -196,8 +211,9 @@ var ctrlTab = {
let list = Array.filter(gBrowser.tabs, function(tab) !tab.hidden);
// Rotate the list until the selected tab is first
while (!list[0].selected)
while (!list[0].selected) {
list.push(list.shift());
}
list = list.filter(function(tab) !tab.closing);
@ -206,8 +222,9 @@ var ctrlTab = {
for (let tab of this._recentlyUsedTabs) {
if (!tab.hidden && !tab.closing) {
recentlyUsedTabs.push(tab);
if (this.recentlyUsedLimit > 0 && recentlyUsedTabs.length >= this.recentlyUsedLimit)
if (this.recentlyUsedLimit > 0 && recentlyUsedTabs.length >= this.recentlyUsedLimit) {
break;
}
}
}
for (let i = recentlyUsedTabs.length - 1; i >= 0; i--) {
@ -249,18 +266,20 @@ var ctrlTab = {
(!gPrefService.prefHasUserValue("browser.ctrlTab.disallowForScreenReaders") ||
!gPrefService.getBoolPref("browser.ctrlTab.disallowForScreenReaders"));
if (enable)
if (enable) {
this.init();
else
} else {
this.uninit();
}
},
observe: function(aSubject, aTopic, aPrefName) {
this.readPref();
},
updatePreviews: function() {
for (let i = 0; i < this.previews.length; i++)
for (let i = 0; i < this.previews.length; i++) {
this.updatePreview(this.previews[i], this.tabList[i]);
}
var showAllLabel = gNavigatorBundle.getString("ctrlTab.showAll.label");
this.showAllButton.label =
@ -268,13 +287,15 @@ var ctrlTab = {
},
updatePreview: function(aPreview, aTab) {
if (aPreview == this.showAllButton)
if (aPreview == this.showAllButton) {
return;
}
aPreview._tab = aTab;
if (aPreview.firstChild)
if (aPreview.firstChild) {
aPreview.removeChild(aPreview.firstChild);
}
if (aTab) {
let canvasWidth = this.canvasWidth;
let canvasHeight = this.canvasHeight;
@ -305,10 +326,11 @@ var ctrlTab = {
let selectedIndex = Array.indexOf(this.previews, this.selected);
do {
selectedIndex += aForward ? 1 : -1;
if (selectedIndex < 0)
if (selectedIndex < 0) {
selectedIndex = this.previews.length - 1;
else if (selectedIndex >= this.previews.length)
} else if (selectedIndex >= this.previews.length)
selectedIndex = 0;
}
} while (this.previews[selectedIndex].hidden);
if (this._selectedIndex == -1) {
@ -331,15 +353,17 @@ var ctrlTab = {
},
pick: function(aPreview) {
if (!this.tabCount)
if (!this.tabCount) {
return;
}
var select = (aPreview || this.selected);
if (select == this.showAllButton)
if (select == this.showAllButton) {
this.showAllTabs();
else
} else {
this.close(select._tab);
}
},
showAllTabs: function(aPreview) {
@ -348,27 +372,31 @@ var ctrlTab = {
},
remove: function(aPreview) {
if (aPreview._tab)
if (aPreview._tab) {
gBrowser.removeTab(aPreview._tab);
}
},
attachTab: function(aTab, aPos) {
if (aPos == 0)
if (aPos == 0) {
this._recentlyUsedTabs.unshift(aTab);
else if (aPos)
} else if (aPos) {
this._recentlyUsedTabs.splice(aPos, 0, aTab);
else
} else {
this._recentlyUsedTabs.push(aTab);
}
},
detachTab: function(aTab) {
var i = this._recentlyUsedTabs.indexOf(aTab);
if (i >= 0)
if (i >= 0) {
this._recentlyUsedTabs.splice(i, 1);
}
},
open: function() {
if (this.isOpen)
if (this.isOpen) {
return;
}
allTabs.close();
@ -397,15 +425,17 @@ var ctrlTab = {
},
close: function(aTabToSelect) {
if (!this.isOpen)
if (!this.isOpen) {
return;
}
if (this._timer) {
clearTimeout(this._timer);
this._timer = null;
this.suspendGUI();
if (aTabToSelect)
if (aTabToSelect) {
gBrowser.selectedTab = aTabToSelect;
}
return;
}
@ -421,8 +451,9 @@ var ctrlTab = {
// to be under the mouse pointer initially won't be selected unintentionally.
this._trackMouseOver = false;
setTimeout(function(self) {
if (self.isOpen)
if (self.isOpen) {
self._trackMouseOver = true;
}
}, 0, this);
},
@ -490,10 +521,12 @@ var ctrlTab = {
this._tabList = null;
this.updatePreviews();
if (this.selected.hidden)
if (this.selected.hidden) {
this.advanceFocus(false);
if (this.selected == this.showAllButton)
}
if (this.selected == this.showAllButton) {
this.advanceFocus(false);
}
// If the current tab is removed, another tab can steal our focus.
if (aTab.selected && this.panel.state == "open") {
@ -523,15 +556,17 @@ var ctrlTab = {
break;
case "TabClose":
this.detachTab(event.target);
if (this.isOpen)
if (this.isOpen) {
this.removeClosingTabFromUI(event.target);
}
break;
case "keypress":
this.onKeyPress(event);
break;
case "keyup":
if (event.keyCode == event.DOM_VK_CONTROL)
if (event.keyCode == event.DOM_VK_CONTROL) {
this.pick();
}
break;
}
},
@ -555,10 +590,11 @@ var ctrlTab = {
// Also disable the <key> to ensure Shift+Ctrl+Tab never triggers
// Show All Tabs.
var key_showAllTabs = document.getElementById("key_showAllTabs");
if (enable)
if (enable) {
key_showAllTabs.removeAttribute("disabled");
else
} else {
key_showAllTabs.setAttribute("disabled", "true");
}
}
};
@ -567,29 +603,36 @@ var ctrlTab = {
* All Tabs panel
*/
var allTabs = {
get panel () {
get panel() {
delete this.panel;
return this.panel = document.getElementById("allTabs-panel");
},
get filterField () {
get filterField() {
delete this.filterField;
return this.filterField = document.getElementById("allTabs-filter");
},
get container () {
get container() {
delete this.container;
return this.container = document.getElementById("allTabs-container");
},
get tabCloseButton () {
get tabCloseButton() {
delete this.tabCloseButton;
return this.tabCloseButton = document.getElementById("allTabs-tab-close-button");
},
get toolbarButton() document.getElementById("alltabs-button"),
get previews () this.container.getElementsByClassName("allTabs-preview"),
get isOpen () this.panel.state == "open" || this.panel.state == "showing",
get toolbarButton() {
return document.getElementById("alltabs-button");
},
get previews() {
return this.container.getElementsByClassName("allTabs-preview");
},
get isOpen() {
return this.panel.state == "open" || this.panel.state == "showing";
},
init: function() {
if (this._initiated)
if (this._initiated) {
return;
}
this._initiated = true;
tabPreviews.init();
@ -605,16 +648,18 @@ var allTabs = {
},
uninit: function() {
if (!this._initiated)
if (!this._initiated) {
return;
}
gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
gBrowser.tabContainer.removeEventListener("TabAttrModified", this, false);
gBrowser.tabContainer.removeEventListener("TabMove", this, false);
gBrowser.tabContainer.removeEventListener("TabClose", this, false);
while (this.container.hasChildNodes())
while (this.container.hasChildNodes()) {
this.container.removeChild(this.container.firstChild);
}
this._initiated = false;
},
@ -622,8 +667,9 @@ var allTabs = {
prefName: "browser.allTabs.previews",
readPref: function() {
var allTabsButton = this.toolbarButton;
if (!allTabsButton)
if (!allTabsButton) {
return;
}
if (gPrefService.getBoolPref(this.prefName)) {
allTabsButton.removeAttribute("type");
@ -639,10 +685,12 @@ var allTabs = {
},
pick: function(aPreview) {
if (!aPreview)
if (!aPreview) {
aPreview = this._firstVisiblePreview;
if (aPreview)
}
if (aPreview) {
this.tabToSelect = aPreview._tab;
}
this.close();
},
@ -653,8 +701,9 @@ var allTabs = {
},
filter: function() {
if (this._currentFilter == this.filterField.value)
if (this._currentFilter == this.filterField.value) {
return;
}
this._currentFilter = this.filterField.value;
@ -676,15 +725,16 @@ var allTabs = {
let tabstring = tab.linkedBrowser.currentURI.spec;
try {
tabstring = decodeURI(tabstring);
} catch (e) {}
} catch (e) {
}
tabstring = tab.label + " " + tab.label.toLocaleLowerCase() + " " + tabstring;
for (let i = 0; i < filter.length; i++)
for (let i = 0; i < filter.length; i++) {
matches += tabstring.includes(filter[i]);
}
}
if (matches < filter.length || tab.hidden || (hidePinnedTabs && tab.pinned)) {
preview.hidden = true;
}
else {
} else {
this._visible++;
this._updatePreview(preview);
preview.hidden = false;
@ -708,8 +758,9 @@ var allTabs = {
this.init();
if (this.isOpen)
if (this.isOpen) {
return;
}
this._maxPanelHeight = Math.max(gBrowser.clientHeight, screen.availHeight / 2);
this._maxPanelWidth = Math.max(gBrowser.clientWidth, screen.availWidth / 2);
@ -758,27 +809,31 @@ var allTabs = {
handleEvent: function(event) {
if (event.type.startsWith("Tab")) {
var tab = event.target;
if (event.type != "TabOpen")
if (event.type != "TabOpen") {
var preview = this._getPreview(tab);
}
}
switch (event.type) {
case "TabAttrModified":
// tab attribute modified (e.g. label, crop, busy, image)
if (!preview.hidden)
if (!preview.hidden) {
this._updatePreview(preview);
}
break;
case "TabOpen":
if (this.isOpen)
if (this.isOpen) {
this.close();
}
this._addPreview(tab);
break;
case "TabMove":
let siblingPreview = tab.nextSibling &&
this._getPreview(tab.nextSibling);
if (siblingPreview)
if (siblingPreview) {
siblingPreview.parentNode.insertBefore(preview, siblingPreview);
else
} else {
this.container.lastChild.appendChild(preview);
}
if (this.isOpen && !preview.hidden) {
this._reflow();
preview.focus();
@ -801,23 +856,23 @@ var allTabs = {
_visible: 0,
_currentFilter: null,
get _stack () {
get _stack() {
delete this._stack;
return this._stack = document.getElementById("allTabs-stack");
},
get _browserCommandSet () {
get _browserCommandSet() {
delete this._browserCommandSet;
return this._browserCommandSet = document.getElementById("mainCommandSet");
},
get _previewLabelHeight () {
get _previewLabelHeight() {
delete this._previewLabelHeight;
return this._previewLabelHeight = parseInt(getComputedStyle(this.previews[0], "").lineHeight);
},
get _visiblePreviews ()
get _visiblePreviews()
Array.filter(this.previews, function(preview) !preview.hidden),
get _firstVisiblePreview () {
get _firstVisiblePreview() {
if (this._visible == 0)
return null;
var previews = this.previews;
@ -860,10 +915,12 @@ var allTabs = {
var previews = Array.slice(this.previews);
while (this.container.hasChildNodes())
while (this.container.hasChildNodes()) {
this.container.removeChild(this.container.firstChild);
for (let i = rows || 1; i > 0; i--)
}
for (let i = rows || 1; i > 0; i--) {
this.container.appendChild(document.createElement("hbox"));
}
var row = this.container.firstChild;
var colCount = 0;
@ -907,19 +964,23 @@ var allTabs = {
_getPreview: function(aTab) {
var previews = this.previews;
for (let i = 0; i < previews.length; i++)
if (previews[i]._tab == aTab)
for (let i = 0; i < previews.length; i++) {
if (previews[i]._tab == aTab) {
return previews[i];
}
}
return null;
},
_updateTabCloseButton: function(event) {
if (event && event.target == this.tabCloseButton)
if (event && event.target == this.tabCloseButton) {
return;
}
if (this.tabCloseButton._targetPreview) {
if (event && event.target == this.tabCloseButton._targetPreview)
if (event && event.target == this.tabCloseButton._targetPreview) {
return;
}
this.tabCloseButton._targetPreview.removeAttribute("closebuttonhover");
}
@ -954,22 +1015,25 @@ var allTabs = {
aPreview.setAttribute("label", aPreview._tab.label);
aPreview.setAttribute("tooltiptext", aPreview._tab.label);
aPreview.setAttribute("crop", aPreview._tab.crop);
if (aPreview._tab.image)
if (aPreview._tab.image) {
aPreview.setAttribute("image", aPreview._tab.image);
else
} else {
aPreview.removeAttribute("image");
}
aPreview.removeAttribute("soundplaying");
aPreview.removeAttribute("muted");
if (aPreview._tab.hasAttribute("muted"))
if (aPreview._tab.hasAttribute("muted")) {
aPreview.setAttribute("muted", "true");
else if (aPreview._tab.hasAttribute("soundplaying"))
} else if (aPreview._tab.hasAttribute("soundplaying")) {
aPreview.setAttribute("soundplaying", "true");
}
var thumbnail = tabPreviews.get(aPreview._tab);
if (aPreview.firstChild) {
if (aPreview.firstChild == thumbnail)
if (aPreview.firstChild == thumbnail) {
return;
}
aPreview.removeChild(aPreview.firstChild);
}
aPreview.appendChild(thumbnail);
@ -1014,8 +1078,9 @@ var allTabs = {
switch (event.keyCode) {
case event.DOM_VK_UP:
case event.DOM_VK_DOWN:
if (event.target != this.filterField)
if (event.target != this.filterField) {
this._advanceFocusVertically(event);
}
break;
case event.DOM_VK_RETURN:
if (event.target == this.filterField) {
@ -1030,8 +1095,9 @@ var allTabs = {
_advanceFocusVertically: function(event) {
var preview = document.activeElement;
if (!preview || preview.parentNode.parentNode != this.container)
if (!preview || preview.parentNode.parentNode != this.container) {
return;
}
event.stopPropagation();
@ -1057,8 +1123,9 @@ var allTabs = {
let rows = Math.ceil(previews.length / columns);
row = rows - 1;
column--;
if (outOfBounds())
if (outOfBounds()) {
row--;
}
}
} else {
row++;

View file

@ -32,13 +32,15 @@ var gBrowserThumbnails = {
init: function() {
// Bug 863512 - Make page thumbnails work in electrolysis
if (gMultiProcessBrowser)
if (gMultiProcessBrowser) {
return;
}
try {
if (Services.prefs.getBoolPref("browser.pagethumbnails.capturing_disabled"))
return;
} catch (e) {}
} catch (e) {
}
PageThumbs.addExpirationFilter(this);
gBrowser.addTabsProgressListener(this);
@ -56,8 +58,9 @@ var gBrowserThumbnails = {
uninit: function() {
// Bug 863512 - Make page thumbnails work in electrolysis
if (gMultiProcessBrowser)
if (gMultiProcessBrowser) {
return;
}
PageThumbs.removeExpirationFilter(this);
gBrowser.removeTabsProgressListener(this);
@ -72,8 +75,9 @@ var gBrowserThumbnails = {
switch (aEvent.type) {
case "scroll":
let browser = aEvent.currentTarget;
if (this._timeouts.has(browser))
if (this._timeouts.has(browser)) {
this._delayedCapture(browser);
}
break;
case "TabSelect":
this._delayedCapture(aEvent.target.linkedBrowser);
@ -106,20 +110,23 @@ var gBrowserThumbnails = {
onStateChange: function(aBrowser, aWebProgress,
aRequest, aStateFlags, aStatus) {
if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK)
aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
this._delayedCapture(aBrowser);
}
},
_capture: function(aBrowser) {
if (this._shouldCapture(aBrowser))
if (this._shouldCapture(aBrowser)) {
PageThumbs.captureAndStore(aBrowser);
}
},
_delayedCapture: function(aBrowser) {
if (this._timeouts.has(aBrowser))
if (this._timeouts.has(aBrowser)) {
clearTimeout(this._timeouts.get(aBrowser));
else
} else {
aBrowser.addEventListener("scroll", this, true);
}
let timeout = setTimeout(function() {
this._clearTimeout(aBrowser);
@ -131,50 +138,60 @@ var gBrowserThumbnails = {
_shouldCapture: function(aBrowser) {
// Capture only if it's the currently selected tab.
if (aBrowser != gBrowser.selectedBrowser)
if (aBrowser != gBrowser.selectedBrowser) {
return false;
}
// Don't capture in per-window private browsing mode.
if (PrivateBrowsingUtils.isWindowPrivate(window))
if (PrivateBrowsingUtils.isWindowPrivate(window)) {
return false;
}
let doc = aBrowser.contentDocument;
// FIXME Bug 720575 - Don't capture thumbnails for SVG or XML documents as
// that currently regresses Talos SVG tests.
if (doc instanceof XMLDocument)
if (doc instanceof XMLDocument) {
return false;
}
// There's no point in taking screenshot of loading pages.
if (aBrowser.docShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE)
if (aBrowser.docShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE) {
return false;
}
// Don't take screenshots of about: pages.
if (aBrowser.currentURI.schemeIs("about"))
if (aBrowser.currentURI.schemeIs("about")) {
return false;
}
let channel = aBrowser.docShell.currentDocumentChannel;
// No valid document channel. We shouldn't take a screenshot.
if (!channel)
if (!channel) {
return false;
}
// Don't take screenshots of internally redirecting about: pages.
// This includes error pages.
let uri = channel.originalURI;
if (uri.schemeIs("about"))
if (uri.schemeIs("about")) {
return false;
}
let httpChannel;
try {
httpChannel = channel.QueryInterface(Ci.nsIHttpChannel);
} catch (e) { /* Not an HTTP channel. */ }
} catch (e) {
// Not an HTTP channel.
}
if (httpChannel) {
// Continue only if we have a 2xx status code.
try {
if (Math.floor(httpChannel.responseStatus / 100) != 2)
if (Math.floor(httpChannel.responseStatus / 100) != 2) {
return false;
}
} catch (e) {
// Can't get response information from the httpChannel
// because mResponseHead is not available.
@ -182,12 +199,14 @@ var gBrowserThumbnails = {
}
// Cache-Control: no-store.
if (httpChannel.isNoStoreResponse())
if (httpChannel.isNoStoreResponse()) {
return false;
}
// Don't capture HTTPS pages unless the user explicitly enabled it.
if (uri.schemeIs("https") && !this._sslDiskCacheEnabled)
if (uri.schemeIs("https") && !this._sslDiskCacheEnabled) {
return false;
}
}
return true;

View file

@ -5,7 +5,7 @@
var WebrtcIndicator = {
init: function () {
let temp = {};
let temp = { };
Cu.import("resource:///modules/webrtcUI.jsm", temp);
this.UIModule = temp.webrtcUI;
@ -35,14 +35,16 @@ var WebrtcIndicator = {
},
clearPopup: function (aPopup) {
while (aPopup.lastChild)
while (aPopup.lastChild) {
aPopup.removeChild(aPopup.lastChild);
}
},
menuCommand: function (aMenuitem) {
let streamData = this._menuitemData.get(aMenuitem);
if (!streamData)
if (!streamData) {
return;
}
let browserWindow = streamData.browser.ownerDocument.defaultView;
if (streamData.tab) {