bug 570788 - Incorporate improvements from SeaMonkey places review into Firefox code, round 3 (PUIU, PC, sbUtils), r=mak a=gavin

This commit is contained in:
Robert Kaiser 2010-08-11 18:05:08 +02:00
Родитель 7274f7f20b
Коммит 612c60785d
3 изменённых файлов: 97 добавлений и 96 удалений

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

@ -50,7 +50,7 @@ const RELOAD_ACTION_NOTHING = 0;
const RELOAD_ACTION_INSERT = 1;
// Removing items from the view, select the first item after the last selected
const RELOAD_ACTION_REMOVE = 2;
// Moving items within a view, don't treat the dropped items as additional
// Moving items within a view, don't treat the dropped items as additional
// rows.
const RELOAD_ACTION_MOVE = 3;
@ -67,7 +67,7 @@ const REMOVE_PAGES_MAX_SINGLEREMOVES = 10;
/**
* Represents an insertion point within a container where we can insert
* items.
* items.
* @param aItemId
* The identifier of the parent container
* @param aIndex
@ -139,7 +139,7 @@ PlacesController.prototype = {
return true;
}
// All other Places Commands are prefixed with "placesCmd_" ... this
// All other Places Commands are prefixed with "placesCmd_" ... this
// filters out other commands that we do _not_ support (see 329587).
const CMD_PREFIX = "placesCmd_";
return (aCommand.substr(0, CMD_PREFIX.length) == CMD_PREFIX);
@ -178,7 +178,7 @@ PlacesController.prototype = {
if (this._view.selType != "single") {
let rootNode = this._view.result.root;
if (rootNode.containerOpen && rootNode.childCount > 0)
return true;
return true;
}
return false;
case "placesCmd_open":
@ -308,9 +308,9 @@ PlacesController.prototype = {
onEvent: function PC_onEvent(eventName) { },
/**
* Determine whether or not the selection can be removed, either by the
* Determine whether or not the selection can be removed, either by the
* delete or cut operations based on whether or not any of its contents
* are non-removable. We don't need to worry about recursion here since it
* is a policy decision that a removable item not be placed inside a non-
@ -373,14 +373,14 @@ PlacesController.prototype = {
var root = this._view.result.root;
for (var i = 0; i < nodes.length; ++i) {
if (nodes[i] == root)
return true;
return true;
}
return false;
},
/**
* Looks at the data on the clipboard to see if it is paste-able.
* Looks at the data on the clipboard to see if it is paste-able.
* Paste-able data is:
* - in a format that the view can receive
* @returns true if: - clipboard data is of a TYPE_X_MOZ_PLACE_* flavor,
@ -427,7 +427,7 @@ PlacesController.prototype = {
}
},
/**
/**
* Gathers information about the selected nodes according to the following
* rules:
* "link" node is a URI
@ -442,7 +442,7 @@ PlacesController.prototype = {
*
* @returns an array of objects corresponding the selected nodes. Each
* object has each of the properties above set if its corresponding
* node matches the rule. In addition, the annotations names for each
* node matches the rule. In addition, the annotations names for each
* node are set on its corresponding object as properties.
* Notes:
* 1) This can be slow, so don't call it anywhere performance critical!
@ -456,7 +456,7 @@ PlacesController.prototype = {
if (nodes.length == 0)
nodes.push(root); // See the second note above
for (var i=0; i < nodes.length; i++) {
for (var i = 0; i < nodes.length; i++) {
var nodeData = {};
var node = nodes[i];
var nodeType = node.type;
@ -514,16 +514,16 @@ PlacesController.prototype = {
// annotations
if (uri) {
var names = PlacesUtils.annotations.getPageAnnotationNames(uri);
for (var j = 0; j < names.length; ++j)
let names = PlacesUtils.annotations.getPageAnnotationNames(uri);
for (let j = 0; j < names.length; ++j)
nodeData[names[j]] = true;
}
// For items also include the item-specific annotations
if (node.itemId != -1) {
names = PlacesUtils.annotations
.getItemAnnotationNames(node.itemId);
for (j = 0; j < names.length; ++j)
let names = PlacesUtils.annotations
.getItemAnnotationNames(node.itemId);
for (let j = 0; j < names.length; ++j)
nodeData[names[j]] = true;
}
metadata.push(nodeData);
@ -532,14 +532,14 @@ PlacesController.prototype = {
return metadata;
},
/**
/**
* Determines if a context-menu item should be shown
* @param aMenuItem
* the context menu item
* the context menu item
* @param aMetaData
* meta data about the selection
* @returns true if the conditions (see buildContextMenu) are satisfied
* and the item can be displayed, false otherwise.
* and the item can be displayed, false otherwise.
*/
_shouldShowMenuItem: function PC__shouldShowMenuItem(aMenuItem, aMetaData) {
var selectiontype = aMenuItem.getAttribute("selectiontype");
@ -551,8 +551,8 @@ PlacesController.prototype = {
var forceHideAttr = aMenuItem.getAttribute("forcehideselection");
if (forceHideAttr) {
var forceHideRules = forceHideAttr.split("|");
for (var i = 0; i < aMetaData.length; ++i) {
for (var j=0; j < forceHideRules.length; ++j) {
for (let i = 0; i < aMetaData.length; ++i) {
for (let j = 0; j < forceHideRules.length; ++j) {
if (forceHideRules[j] in aMetaData[i])
return false;
}
@ -682,7 +682,7 @@ PlacesController.prototype = {
},
/**
* Select all links in the current view.
* Select all links in the current view.
*/
selectAll: function PC_selectAll() {
this._view.selectAll();
@ -691,7 +691,7 @@ PlacesController.prototype = {
/**
* Opens the bookmark properties for the selected URI Node.
*/
showBookmarkPropertiesForSelection:
showBookmarkPropertiesForSelection:
function PC_showBookmarkPropertiesForSelection() {
var node = this._view.selectedNode;
if (!node)
@ -717,7 +717,7 @@ PlacesController.prototype = {
* receive a string instead of an nsIURI object.
*/
_assertURINotString: function PC__assertURINotString(value) {
NS_ASSERT((typeof(value) == "object") && !(value instanceof String),
NS_ASSERT((typeof(value) == "object") && !(value instanceof String),
"This method should be passed a URI as a nsIURI object, not as a string.");
},
@ -759,16 +759,15 @@ PlacesController.prototype = {
var messageKey = "tabs.openWarningMultipleBranded";
var openKey = "tabs.openButtonMultiple";
var strings = document.getElementById("placeBundle");
const BRANDING_BUNDLE_URI = "chrome://branding/locale/brand.properties";
var brandShortName = Cc["@mozilla.org/intl/stringbundle;1"].
getService(Ci.nsIStringBundleService).
createBundle(BRANDING_BUNDLE_URI).
GetStringFromName("brandShortName");
var buttonPressed = promptService.confirmEx(window,
PlacesUIUtils.getString("tabs.openWarningTitle"),
PlacesUIUtils.getFormattedString(messageKey,
PlacesUIUtils.getFormattedString(messageKey,
[numTabsToOpen, brandShortName]),
(promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0)
+ (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
@ -788,7 +787,7 @@ PlacesController.prototype = {
},
/**
* Opens the links in the selected folder, or the selected links in new tabs.
* Opens the links in the selected folder, or the selected links in new tabs.
*/
openSelectionInTabs: function PC_openLinksInTabs(aEvent) {
var node = this._view.selectedNode;
@ -828,7 +827,7 @@ PlacesController.prototype = {
/**
* Create a new Bookmark folder somewhere. Prompts the user for the name
* of the folder.
* of the folder.
*/
newFolder: function PC_newFolder() {
var ip = this._view.insertionPoint;
@ -880,17 +879,17 @@ PlacesController.prototype = {
/**
* Walk the list of folders we're removing in this delete operation, and
* see if the selected node specified is already implicitly being removed
* because it is a child of that folder.
* see if the selected node specified is already implicitly being removed
* because it is a child of that folder.
* @param node
* Node to check for containment.
* Node to check for containment.
* @param pastFolders
* List of folders the calling function has already traversed
* @returns true if the node should be skipped, false otherwise.
* @returns true if the node should be skipped, false otherwise.
*/
_shouldSkipNode: function PC_shouldSkipNode(node, pastFolders) {
/**
* Determines if a node is contained by another node within a resultset.
* Determines if a node is contained by another node within a resultset.
* @param node
* The node to check for containment for
* @param parent
@ -906,7 +905,7 @@ PlacesController.prototype = {
}
return false;
}
for (var j = 0; j < pastFolders.length; ++j) {
if (isContainedBy(node, pastFolders[j]))
return true;
@ -915,10 +914,10 @@ PlacesController.prototype = {
},
/**
* Creates a set of transactions for the removal of a range of items.
* Creates a set of transactions for the removal of a range of items.
* A range is an array of adjacent nodes in a view.
* @param [in] range
* An array of nodes to remove. Should all be adjacent.
* An array of nodes to remove. Should all be adjacent.
* @param [out] transactions
* An array of transactions.
* @param [optional] removedFolders
@ -1090,7 +1089,7 @@ PlacesController.prototype = {
var root = this._view.result.root;
if (PlacesUtils.nodeIsFolder(root))
if (PlacesUtils.nodeIsFolder(root))
this._removeRowsFromBookmarks(aTxnName);
else if (PlacesUtils.nodeIsQuery(root)) {
var queryType = PlacesUtils.asQuery(root).queryOptions.queryType;
@ -1136,7 +1135,7 @@ PlacesController.prototype = {
addData(PlacesUtils.TYPE_HTML, index, overrideURI);
}
// This order is _important_! It controls how this and other
// This order is _important_! It controls how this and other
// applications select data to be inserted based on type.
addData(PlacesUtils.TYPE_X_MOZ_PLACE, i);
@ -1166,8 +1165,8 @@ PlacesController.prototype = {
try {
let nodes = this._view.selectedNodes;
let xferable = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);
let xferable = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);
let foundFolder = false, foundLink = false;
let copiedFolders = [];
let placeString, mozURLString, htmlString, unicodeString;
@ -1179,11 +1178,11 @@ PlacesController.prototype = {
continue;
if (PlacesUtils.nodeIsFolder(node))
copiedFolders.push(node);
function generateChunk(type, overrideURI) {
let suffix = i < (nodes.length - 1) ? PlacesUtils.endl : "";
let uri = overrideURI;
if (PlacesUtils.nodeIsLivemarkContainer(node))
uri = PlacesUtils.livemarks.getFeedURI(node.itemId).spec
@ -1194,8 +1193,8 @@ PlacesController.prototype = {
htmlString += (PlacesUtils.wrapNode(node, PlacesUtils.TYPE_HTML,
uri) + suffix);
var placeSuffix = i < (nodes.length - 1) ? "," : "";
var resolveShortcuts = !PlacesControllerDragHelper.canMoveNode(node);
let placeSuffix = i < (nodes.length - 1) ? "," : "";
let resolveShortcuts = !PlacesControllerDragHelper.canMoveNode(node);
return PlacesUtils.wrapNode(node, type, overrideURI, resolveShortcuts) + placeSuffix;
}
@ -1207,7 +1206,7 @@ PlacesController.prototype = {
xferable.addDataFlavor(type);
xferable.setTransferData(type, PlacesUIUtils._wrapString(data), data.length * 2);
}
// This order is _important_! It controls how this and other applications
// This order is _important_! It controls how this and other applications
// select data to be inserted based on type.
if (placeString)
addData(PlacesUtils.TYPE_X_MOZ_PLACE, placeString);
@ -1241,11 +1240,11 @@ PlacesController.prototype = {
*/
paste: function PC_paste() {
// Strategy:
//
// There can be data of various types (folder, separator, link) on the
//
// There can be data of various types (folder, separator, link) on the
// clipboard. We need to get all of that data and build edit transactions
// for them. This means asking the clipboard once for each type and
// aggregating the results.
// for them. This means asking the clipboard once for each type and
// aggregating the results.
/**
* Constructs a transferable that can receive data of specific types.
@ -1255,10 +1254,9 @@ PlacesController.prototype = {
* @returns The transferable.
*/
function makeXferable(types) {
var xferable =
Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);
for (var i = 0; i < types.length; ++i)
var xferable = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);
for (var i = 0; i < types.length; ++i)
xferable.addDataFlavor(types[i]);
return xferable;
}
@ -1291,10 +1289,10 @@ PlacesController.prototype = {
if (ip.isTag) {
var uri = PlacesUtils._uri(items[i].uri);
txn = PlacesUIUtils.ptm.tagURI(uri, [ip.itemId]);
}
}
else {
// adjusted to make sure that items are given the correct index
// transactions insert differently if index == -1
// transactions insert differently if index == -1
// transaction will enqueue the item.
if (ip.index > -1)
index = ip.index + i;
@ -1307,18 +1305,18 @@ PlacesController.prototype = {
}
catch (e) {
// getAnyTransferData will throw if there is no data of the specified
// type on the clipboard.
// type on the clipboard.
// unwrapNodes will throw if the data that is present is malformed in
// some way.
// some way.
// In either case, don't fail horribly, just return no data.
}
return [];
}
// Get transactions to paste any folders, separators or links that might
// be on the clipboard, aggregate them and execute them.
// be on the clipboard, aggregate them and execute them.
var transactions = getTransactions([PlacesUtils.TYPE_X_MOZ_PLACE,
PlacesUtils.TYPE_X_MOZ_URL,
PlacesUtils.TYPE_X_MOZ_URL,
PlacesUtils.TYPE_UNICODE]);
var txn = PlacesUIUtils.ptm.aggregateTransactions("Paste", transactions);
PlacesUIUtils.ptm.doTransaction(txn);
@ -1336,8 +1334,8 @@ PlacesController.prototype = {
/**
* Handles drag and drop operations for views. Note that this is view agnostic!
* You should not use PlacesController._view within these methods, since
* the view that the item(s) have been dropped on was not necessarily active.
* Drop functions are passed the view that is being dropped on.
* the view that the item(s) have been dropped on was not necessarily active.
* Drop functions are passed the view that is being dropped on.
*/
let PlacesControllerDragHelper = {
/**
@ -1416,7 +1414,8 @@ let PlacesControllerDragHelper = {
let dragged;
try {
dragged = PlacesUtils.unwrapNodes(data, flavor)[0];
} catch (e) {
}
catch (e) {
return false;
}
@ -1442,10 +1441,10 @@ let PlacesControllerDragHelper = {
return true;
},
/**
* Determines if a node can be moved.
*
*
* @param aNode
* A nsINavHistoryResultNode node.
* @returns True if the node can be moved, false otherwise.
@ -1477,7 +1476,7 @@ let PlacesControllerDragHelper = {
/**
* Determines if a container node can be moved.
*
*
* @param aId
* A bookmark folder id.
* @param [optional] aParentId

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

@ -132,6 +132,6 @@ var SidebarUtils = {
},
clearURLFromStatusBar: function SU_clearURLFromStatusBar() {
window.top.XULBrowserWindow.setOverLink("", null);
window.top.XULBrowserWindow.setOverLink("", null);
}
};

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

@ -72,7 +72,7 @@ var PlacesUIUtils = {
* @returns A URI object for the spec.
*/
createFixedURI: function PUIU_createFixedURI(aSpec) {
return URIFixup.createFixupURI(aSpec, 0);
return URIFixup.createFixupURI(aSpec, Ci.nsIURIFixup.FIXUP_FLAG_NONE);
},
/**
@ -128,7 +128,7 @@ var PlacesUIUtils = {
*/
_getBookmarkItemCopyTransaction:
function PUIU__getBookmarkItemCopyTransaction(aData, aContainer, aIndex,
aExcludeAnnotations) {
aExcludeAnnotations) {
var itemURL = PlacesUtils._uri(aData.uri);
var itemTitle = aData.title;
var keyword = aData.keyword || null;
@ -278,7 +278,7 @@ var PlacesUIUtils = {
* the move/insert.
*/
makeTransaction: function PUIU_makeTransaction(data, type, container,
index, copy) {
index, copy) {
switch (data.type) {
case PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER:
if (copy)
@ -289,7 +289,7 @@ var PlacesUIUtils = {
case PlacesUtils.TYPE_X_MOZ_PLACE:
if (data.id == -1) // Not bookmarked.
return this._getURIItemCopyTransaction(data, container, index);
if (copy)
return this._getBookmarkItemCopyTransaction(data, container, index);
// Otherwise move the item.
@ -361,14 +361,14 @@ var PlacesUIUtils = {
* bookmarks root folder.
*/
showAddBookmarkUI: function PUIU_showAddBookmarkUI(aURI,
aTitle,
aDescription,
aDefaultInsertionPoint,
aShowPicker,
aLoadInSidebar,
aKeyword,
aPostData,
aCharSet) {
aTitle,
aDescription,
aDefaultInsertionPoint,
aShowPicker,
aLoadInSidebar,
aKeyword,
aPostData,
aCharSet) {
var info = {
action: "add",
type: "bookmark"
@ -417,9 +417,9 @@ var PlacesUIUtils = {
*/
showMinimalAddBookmarkUI:
function PUIU_showMinimalAddBookmarkUI(aURI, aTitle, aDescription,
aDefaultInsertionPoint, aShowPicker,
aLoadInSidebar, aKeyword, aPostData,
aCharSet) {
aDefaultInsertionPoint, aShowPicker,
aLoadInSidebar, aKeyword, aPostData,
aCharSet) {
var info = {
action: "add",
type: "bookmark",
@ -485,11 +485,11 @@ var PlacesUIUtils = {
* bookmarks root folder.
*/
showAddLivemarkUI: function PUIU_showAddLivemarkURI(aFeedURI,
aSiteURI,
aTitle,
aDescription,
aDefaultInsertionPoint,
aShowPicker) {
aSiteURI,
aTitle,
aDescription,
aDefaultInsertionPoint,
aShowPicker) {
var info = {
action: "add",
type: "livemark"
@ -525,8 +525,8 @@ var PlacesUIUtils = {
*/
showMinimalAddLivemarkUI:
function PUIU_showMinimalAddLivemarkURI(aFeedURI, aSiteURI, aTitle,
aDescription, aDefaultInsertionPoint,
aShowPicker) {
aDescription, aDefaultInsertionPoint,
aShowPicker) {
var info = {
action: "add",
type: "livemark",
@ -706,7 +706,7 @@ var PlacesUIUtils = {
/**
* By calling this before visiting an URL, the visit will be associated to a
* TRANSITION_BOOKMARK transition.
* This is used when visiting pages from the bookmarks menu,
* This is used when visiting pages from the bookmarks menu,
* personal toolbar, and bookmarks from within the places organizer.
* If this is not called visits will be marked as TRANSITION_LINK.
*/
@ -730,6 +730,8 @@ var PlacesUIUtils = {
* bookmarked (see bug 224521).
* @param aURINode
* a URI node
* @param aWindow
* a window on which a potential error alert is shown on.
* @return true if it's safe to open the node in the browser, false otherwise.
*
*/
@ -890,7 +892,7 @@ var PlacesUIUtils = {
openNodeWithEvent: function PUIU_openNodeWithEvent(aNode, aEvent) {
this.openNodeIn(aNode, this._getCurrentActiveWin().whereToOpenLink(aEvent));
},
/**
* Loads the node's URL in the appropriate tab or window or as a
* web panel.
@ -927,12 +929,12 @@ var PlacesUIUtils = {
* Used to avoid nsIURI overhead in frequently called UI functions.
*
* @param aUrlString the url to guess the scheme from.
*
*
* @return guessed scheme for this url string.
*
* @note this is not supposed be perfect, so use it only for UI purposes.
*/
guessUrlSchemeForUI: function PUU_guessUrlSchemeForUI(aUrlString) {
guessUrlSchemeForUI: function PUIU_guessUrlSchemeForUI(aUrlString) {
return aUrlString.substr(0, aUrlString.indexOf(":"));
},
@ -961,7 +963,7 @@ var PlacesUIUtils = {
return title || this.getString("noTitle");
},
get leftPaneQueries() {
get leftPaneQueries() {
// build the map
this.leftPaneFolderId;
return this.leftPaneQueries;
@ -1239,7 +1241,7 @@ var PlacesUIUtils = {
queryName = name;
}
}
return queryName;
return queryName;
}
};
@ -1380,7 +1382,7 @@ XPCOMUtils.defineLazyGetter(PlacesUIUtils, "ptm", function() {
/**
* Transaction for editing a the description of a bookmark or a folder.
*
*
* @param aItemId
* id of the item to edit.
* @param aDescription