Chromium Code Reviews| Index: chrome/browser/resources/chromeos/login/network_dropdown.js |
| diff --git a/chrome/browser/resources/chromeos/login/network_dropdown.js b/chrome/browser/resources/chromeos/login/network_dropdown.js |
| index c1c513c72e679e30bae9d87639b6eadaaa87a1b0..6f009af78316201b17391b1342b226c23a35e769 100644 |
| --- a/chrome/browser/resources/chromeos/login/network_dropdown.js |
| +++ b/chrome/browser/resources/chromeos/login/network_dropdown.js |
| @@ -24,17 +24,39 @@ cr.define('cr.ui', function() { |
| this.selectedItem = null; |
| // First item which could be selected. |
| this.firstItem = null; |
| + // Whether scroll has just happened. |
| + this.scrollJustHappened = false; |
| + }, |
| + |
| + scrollAction: function(item) { |
|
Nikita (slow)
2011/09/21 10:44:25
nit: Function comment.
altimofeev
2011/09/21 11:49:53
Done.
|
| + var thisTop = this.scrollTop; |
| + var thisBottom = thisTop + this.offsetHeight; |
| + var itemTop = item.offsetTop; |
| + var itemBottom = itemTop + item.offsetHeight; |
| + if (itemTop <= thisTop) return -1; |
| + if (itemBottom >= thisBottom) return 1; |
| + return 0; |
| }, |
| /** |
| * Selects new item. |
| * @param {!Object} selectedItem Item to be selected. |
| + * @param {boolean} mouseOver Is mouseover event triggered? |
| */ |
| - selectItem: function(selectedItem) { |
| + selectItem: function(selectedItem, mouseOver) { |
| + if (mouseOver && this.scrollJustHappened) { |
| + this.scrollJustHappened = false; |
| + return; |
| + } |
| if (this.selectedItem) |
| this.selectedItem.classList.remove('hover'); |
| selectedItem.classList.add('hover'); |
| this.selectedItem = selectedItem; |
| + var action = this.scrollAction(selectedItem); |
| + if (action != 0) { |
| + selectedItem.scrollIntoView(action < 0); |
| + this.scrollJustHappened = true; |
| + } |
| } |
| }; |
| @@ -76,7 +98,7 @@ cr.define('cr.ui', function() { |
| this.firstElementChild.hidden = !show; |
| this.container.hidden = !show; |
| if (show) |
| - this.container.selectItem(this.container.firstItem); |
| + this.container.selectItem(this.container.firstItem, false); |
| }, |
| /** |
| @@ -122,7 +144,7 @@ cr.define('cr.ui', function() { |
| } |
| this.createItem_(this.container, item); |
| } |
| - this.container.selectItem(this.container.firstItem); |
| + this.container.selectItem(this.container.firstItem, false); |
| }, |
| /** |
| @@ -181,7 +203,7 @@ cr.define('cr.ui', function() { |
| this.parentNode.parentNode.titleButton.focus(); |
| }); |
| wrapperDiv.addEventListener('mouseover', function f(e) { |
| - this.parentNode.selectItem(this); |
| + this.parentNode.selectItem(this, true); |
| }); |
| itemElement = wrapperDiv; |
| } |
| @@ -264,7 +286,7 @@ cr.define('cr.ui', function() { |
| if (!selected) |
| selected = this.container.lastElementChild; |
| } while (selected.iid < 0); |
| - this.container.selectItem(selected); |
| + this.container.selectItem(selected, false); |
| break; |
| } |
| case 40: { // Key down. |
| @@ -273,7 +295,7 @@ cr.define('cr.ui', function() { |
| if (!selected) |
| selected = this.container.firstItem; |
| } while (selected.iid < 0); |
| - this.container.selectItem(selected); |
| + this.container.selectItem(selected, false); |
| break; |
| } |
| case 27: { // Esc. |