Bug 592469 - Web Console cleanup: part 6 - HUDService - remove displaysIndex() and more; r=dcamp,gavin.sharp

This commit is contained in:
Mihai Sucan 2011-07-01 23:20:09 +03:00
Родитель 15280d025b
Коммит 8248f63ec8
1 изменённых файлов: 22 добавлений и 62 удалений

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

@ -1197,15 +1197,14 @@ NetworkPanel.prototype =
* Ensures that the number of message nodes of type aCategory don't exceed that
* category's line limit by removing old messages as needed.
*
* @param nsIDOMNode aConsoleNode
* The DOM node (richlistbox aka outputNode) that holds the output of the
* console.
* @param aHUDId aHUDId
* The HeadsUpDisplay ID.
* @param integer aCategory
* The category of message nodes to limit.
* @return number
* The current user-selected log limit.
*/
function pruneConsoleOutputIfNecessary(aConsoleNode, aCategory)
function pruneConsoleOutputIfNecessary(aHUDId, aCategory)
{
// Get the log limit, either from the pref or from the constant.
let logLimit;
@ -1216,13 +1215,15 @@ function pruneConsoleOutputIfNecessary(aConsoleNode, aCategory)
logLimit = DEFAULT_LOG_LIMIT;
}
let scrollBox = aConsoleNode.scrollBoxObject.element;
let hudRef = HUDService.getHudReferenceById(aHUDId);
let outputNode = hudRef.outputNode;
let scrollBox = outputNode.scrollBoxObject.element;
let oldScrollHeight = scrollBox.scrollHeight;
let scrolledToBottom = ConsoleUtils.isOutputScrolledToBottom(aConsoleNode);
let hudRef = HUDService.getHudReferenceForOutputNode(aConsoleNode);
let scrolledToBottom = ConsoleUtils.isOutputScrolledToBottom(outputNode);
// Prune the nodes.
let messageNodes = aConsoleNode.querySelectorAll(".webconsole-msg-" +
let messageNodes = outputNode.querySelectorAll(".webconsole-msg-" +
CATEGORY_CLASS_FRAGMENTS[aCategory]);
let removeNodes = messageNodes.length - logLimit;
for (let i = 0; i < removeNodes; i++) {
@ -1837,6 +1838,18 @@ HUD_SERVICE.prototype =
}
},
/**
* Returns the HeadsUpDisplay object associated to a content window.
*
* @param nsIDOMWindow aContentWindow
* @returns object
*/
getHudByWindow: function HS_getHudByWindow(aContentWindow)
{
let hudId = this.getHudIdByWindow(aContentWindow);
return hudId ? this.hudReferences[hudId] : null;
},
/**
* Returns the hudId that is corresponding to the hud activated for the
* passed aContentWindow. If there is no matching hudId null is returned.
@ -1850,27 +1863,6 @@ HUD_SERVICE.prototype =
return this.getHudIdByWindowId(windowId);
},
/**
* Returns the hudReference for a given output node.
*
* @param nsIDOMNode aNode currently either a xul:vbox, the HUDBox, or a
* richlistbox, the outputNode.
* @returns a HUD | null
*/
getHudReferenceForOutputNode: function HS_getHudReferenceForOutputNode(aNode)
{
let node = aNode;
// starting from richlistbox, need to find hudbox
while (!node.id && !node.classList.contains("hud-box")) {
if (node.parentNode) {
node = node.parentNode;
} else {
return null;
}
}
return this.getHudReferenceById(node.id);
},
/**
* Returns the hudReference for a given id.
*
@ -1882,15 +1874,6 @@ HUD_SERVICE.prototype =
return aId in this.hudReferences ? this.hudReferences[aId] : null;
},
/**
* Gets an array that contains all the HUD IDs.
* @returns array
*/
displaysIndex: function HS_displaysIndex()
{
return Object.keys(this.hudReferences);
},
/**
* Returns the hudId that is corresponding to the given outer window ID.
*
@ -2589,29 +2572,6 @@ HUD_SERVICE.prototype =
// see bug 559748
},
/**
* Passed a HUDId, the corresponding window is returned
*
* @param string aHUDId
* @returns nsIDOMWindow
*/
getContentWindowFromHUDId: function HS_getContentWindowFromHUDId(aHUDId)
{
var hud = this.getHudReferenceById(aHUDId).HUDBox;
var nodes = hud.parentNode.childNodes;
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
if (node.localName == "stack" &&
node.firstChild &&
node.firstChild.contentWindow) {
return node.firstChild.contentWindow;
}
}
throw new Error("HS_getContentWindowFromHUD: Cannot get contentWindow");
},
/**
* Creates a generator that always returns a unique number for use in the
* indexes
@ -5744,7 +5704,7 @@ ConsoleUtils = {
HUDService.regroupOutput(outputNode);
if (pruneConsoleOutputIfNecessary(outputNode, aNode.category) == 0) {
if (pruneConsoleOutputIfNecessary(aHUDId, aNode.category) == 0) {
// We can't very well scroll to make the message node visible if the log
// limit is zero and the node was destroyed in the first place.
return;