From 89f42732b707dde92354026ba8eac5c7a182c34a Mon Sep 17 00:00:00 2001 From: Mihai Sucan Date: Fri, 1 Jul 2011 23:20:09 +0300 Subject: [PATCH] Bug 592469 - Web Console cleanup: part 6 - HUDService - remove displaysIndex() and more; r=dcamp,gavin.sharp --- .../console/hudservice/HUDService.jsm | 84 +++++-------------- 1 file changed, 22 insertions(+), 62 deletions(-) diff --git a/toolkit/components/console/hudservice/HUDService.jsm b/toolkit/components/console/hudservice/HUDService.jsm index e232c9f1a0d..d47b55917c3 100644 --- a/toolkit/components/console/hudservice/HUDService.jsm +++ b/toolkit/components/console/hudservice/HUDService.jsm @@ -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;