Bug 873749 - SideMenuWidget shouldn't automatically scroll to bottom when there's a selected item, r=rcampbell

This commit is contained in:
Victor Porof 2013-05-24 20:10:07 +03:00
Родитель 468c05c4bc
Коммит 02d2012286
3 изменённых файлов: 25 добавлений и 4 удалений

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

@ -21,7 +21,8 @@ function test() {
// when the requests overflow the vertical size of the container.
.then(() => {
return waitForRequestsToOverflowContainer(monitor, requestsContainer);
}).then(() => {
})
.then(() => {
ok(scrolledToBottom(requestsContainer), "Scrolled to bottom on overflow.");
})
@ -34,7 +35,8 @@ function test() {
ok(!scrolledToBottom(requestsContainer), "Not scrolled to bottom.");
scrollTop = requestsContainer.scrollTop; // save for comparison later
return waitForNetworkEvents(monitor, 8);
}).then(() => {
})
.then(() => {
is(requestsContainer.scrollTop, scrollTop, "Did not scroll.");
})
@ -44,10 +46,21 @@ function test() {
requestsContainer.scrollTop = requestsContainer.scrollHeight;
ok(scrolledToBottom(requestsContainer), "Set scroll position to bottom.");
return waitForNetworkEvents(monitor, 8);
}).then(() => {
})
.then(() => {
ok(scrolledToBottom(requestsContainer), "Still scrolled to bottom.");
})
// (4) Now select an item in the list and check that additional requests
// do not change the scroll position.
.then(() => {
monitor.panelWin.NetMonitorView.RequestsMenu.selectedIndex = 0;
return waitForNetworkEvents(monitor, 8);
})
.then(() => {
is(requestsContainer.scrollTop, 0, "Did not scroll.");
})
// Done; clean up.
.then(() => {
return teardown(monitor).then(finish);

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

@ -27,7 +27,7 @@
(function performRequests() {
get("request_" + (count++), function() {
setTimeout(performRequests, 0);
setTimeout(performRequests, 50);
});
})();
</script>

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

@ -100,9 +100,17 @@ SideMenuWidget.prototype = {
// Invalidate any notices set on this widget.
this.removeAttribute("notice");
// Maintaining scroll position at the bottom when a new item is inserted
// depends on several factors (the order of testing is important to avoid
// needlessly expensive operations that may cause reflows):
let maintainScrollAtBottom =
// 1. The behavior should be enabled,
this.autoscrollWithAppendedItems &&
// 2. There shouldn't currently be any selected item in the list.
!this._selectedItem &&
// 3. The new item should be appended at the end of the list.
(aIndex < 0 || aIndex >= this._orderedMenuElementsArray.length) &&
// 4. The list should already be scrolled at the bottom.
(this._list.scrollTop + this._list.clientHeight >= this._list.scrollHeight);
let group = this._getMenuGroupForName(aGroup);