Browse Source

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

pull/24/head
Pale Moon 2 years ago committed by Roy Tam
parent
commit
b017678cf0
  1. 41
      application/palemoon/base/content/browser-fullZoom.js
  2. 212
      application/palemoon/base/content/browser-gestureSupport.js
  3. 93
      application/palemoon/base/content/browser-menudragging.js
  4. 266
      application/palemoon/base/content/browser-places.js
  5. 103
      application/palemoon/base/content/browser-plugins.js
  6. 73
      application/palemoon/base/content/browser-syncui.js
  7. 251
      application/palemoon/base/content/browser-tabPreviews.js
  8. 57
      application/palemoon/base/content/browser-thumbnails.js
  9. 8
      application/palemoon/base/content/browser-webrtcUI.js

41
application/palemoon/base/content/browser-fullZoom.js

@ -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);
},
};

212
application/palemoon/base/content/browser-gestureSupport.js

@ -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;

93
application/palemoon/base/content/browser-menudragging.js

@ -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:{

266
application/palemoon/base/content/browser-places.js

@ -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];