Bug 800857 - Simplify the ensureElementIsVisible method in the SideMenuWidget, r=rcampbell
--- a/browser/devtools/shared/widgets/SideMenuWidget.jsm
+++ b/browser/devtools/shared/widgets/SideMenuWidget.jsm
@@ -3,18 +3,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const Ci = Components.interfaces;
const Cu = Components.utils;
-const ENSURE_SELECTION_VISIBLE_DELAY = 50; // ms
-
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource:///modules/devtools/ViewHelpers.jsm");
Cu.import("resource:///modules/devtools/shared/event-emitter.js");
XPCOMUtils.defineLazyModuleGetter(this, "devtools",
"resource://gre/modules/devtools/Loader.jsm");
Object.defineProperty(this, "NetworkHelper", {
@@ -132,17 +130,17 @@ SideMenuWidget.prototype = {
// 4. The list should already be scrolled at the bottom.
(this._list.scrollTop + this._list.clientHeight >= this._list.scrollHeight);
let group = this._getMenuGroupForName(aGroup);
let item = this._getMenuItemForGroup(group, aContents, aTooltip, aAttachment);
let element = item.insertSelfAt(aIndex);
if (this.maintainSelectionVisible) {
- this.ensureSelectionIsVisible({ withGroup: true, delayed: true });
+ this.ensureElementIsVisible(this.selectedItem);
}
if (maintainScrollAtBottom) {
this._list.scrollTop = this._list.scrollHeight;
}
return element;
},
@@ -223,60 +221,33 @@ SideMenuWidget.prototype = {
node.parentNode.classList.add("selected");
this._selectedItem = node;
} else {
node.classList.remove("selected");
node.parentNode.classList.remove("selected");
}
}
- // Repeated calls to ensureElementIsVisible would interfere with each other
- // and may sometimes result in incorrect scroll positions.
- this.ensureSelectionIsVisible({ delayed: true });
- },
-
- /**
- * Ensures the selected element is visible.
- * @see SideMenuWidget.prototype.ensureElementIsVisible.
- */
- ensureSelectionIsVisible: function(aFlags) {
- this.ensureElementIsVisible(this.selectedItem, aFlags);
+ this.ensureElementIsVisible(this.selectedItem);
},
/**
* Ensures the specified element is visible.
*
* @param nsIDOMNode aElement
* The element to make visible.
- * @param object aFlags [optional]
- * An object containing some of the following flags:
- * - withGroup: true if the group header should also be made visible, if possible
- * - delayed: wait a few cycles before ensuring the selection is visible
*/
- ensureElementIsVisible: function(aElement, aFlags = {}) {
+ ensureElementIsVisible: function(aElement) {
if (!aElement) {
return;
}
- if (aFlags.delayed) {
- delete aFlags.delayed;
- this.window.clearTimeout(this._ensureVisibleTimeout);
- this._ensureVisibleTimeout = this.window.setTimeout(() => {
- this.ensureElementIsVisible(aElement, aFlags);
- }, ENSURE_SELECTION_VISIBLE_DELAY);
- return;
- }
-
- if (aFlags.withGroup) {
- let groupList = aElement.parentNode;
- let groupContainer = groupList.parentNode;
- groupContainer.scrollIntoView(true); // Align with the top.
- }
-
+ // Ensure the element is visible but not scrolled horizontally.
this._boxObject.ensureElementIsVisible(aElement);
+ this._boxObject.scrollBy(-aElement.clientWidth, 0);
},
/**
* Shows all the groups, even the ones with no visible children.
*/
showEmptyGroups: function() {
for (let group of this._orderedGroupElementsArray) {
group.hidden = false;