Commit 6c5746e7 authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

WebUI Task Manager: Prevent redundant scroll.

Fixed a problem that a list is scrolled intentionally while refresh when some rows is selected. Prevented a select event from scrolling if selected rows is not changed. And prevented a scroll event from re-selecting rows if scroll position is not changed.

BUG=104136
TEST=manual on TaskManager, FileManager and Cookie Manager.


Review URL: http://codereview.chromium.org/8589023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110661 0039d316-1c4b-4281-b951-d872f2087c98
parent c5036995
......@@ -354,7 +354,7 @@ cr.define('cr.ui', function() {
this.addEventListener('keydown', this.handleKeyDown);
this.addEventListener('focus', this.handleElementFocus_, true);
this.addEventListener('blur', this.handleElementBlur_, true);
this.addEventListener('scroll', this.redraw.bind(this));
this.addEventListener('scroll', this.handleScroll.bind(this));
this.setAttribute('role', 'listbox');
// Make list focusable
......@@ -502,6 +502,20 @@ cr.define('cr.ui', function() {
return this.selectionController_.handleKeyDown(e);
},
scrollTopBefore_: 0,
/**
* Handle a scroll event.
* @param {Event} e The scroll event.
*/
handleScroll: function(e) {
var scrollTop = this.scrollTop;
if (scrollTop != this.scrollTopBefore_) {
this.scrollTopBefore_ = scrollTop;
this.redraw();
}
},
/**
* Callback from the selection model. We dispatch {@code change} events
* when the selection changes.
......@@ -533,21 +547,23 @@ cr.define('cr.ui', function() {
if (pe.newValue != -1) {
if ((element = this.getListItemByIndex(pe.newValue)))
element.lead = true;
this.scrollIndexIntoView(pe.newValue);
// If the lead item has a different height than other items, then we
// may run into a problem that requires a second attempt to scroll
// it into view. The first scroll attempt will trigger a redraw,
// which will clear out the list and repopulate it with new items.
// During the redraw, the list may shrink temporarily, which if the
// lead item is the last item, will move the scrollTop up since it
// cannot extend beyond the end of the list. (Sadly, being scrolled to
// the bottom of the list is not "sticky.") So, we set a timeout to
// rescroll the list after this all gets sorted out. This is perhaps
// not the most elegant solution, but no others seem obvious.
var self = this;
window.setTimeout(function() {
self.scrollIndexIntoView(pe.newValue);
});
if (pe.oldValue != pe.newValue) {
this.scrollIndexIntoView(pe.newValue);
// If the lead item has a different height than other items, then we
// may run into a problem that requires a second attempt to scroll
// it into view. The first scroll attempt will trigger a redraw,
// which will clear out the list and repopulate it with new items.
// During the redraw, the list may shrink temporarily, which if the
// lead item is the last item, will move the scrollTop up since it
// cannot extend beyond the end of the list. (Sadly, being scrolled to
// the bottom of the list is not "sticky.") So, we set a timeout to
// rescroll the list after this all gets sorted out. This is perhaps
// not the most elegant solution, but no others seem obvious.
var self = this;
window.setTimeout(function() {
self.scrollIndexIntoView(pe.newValue);
});
}
}
},
......@@ -906,6 +922,8 @@ cr.define('cr.ui', function() {
listItem = newCachedItems[y];
}
this.scrollTop = scrollTop;
this.firstIndex_ = firstIndex;
this.lastIndex_ = lastIndex;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment