Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: chrome/browser/resources/chromeos/login/network_dropdown.js

Issue 7982002: [cros,webui] Adds scrollbar for the network drop-down controller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added ellipsis for title, fixed width problems Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Network drop-down implementation. 6 * @fileoverview Network drop-down implementation.
7 */ 7 */
8 8
9 cr.define('cr.ui', function() { 9 cr.define('cr.ui', function() {
10 /** 10 /**
11 * Creates a new container for the drop down menu items. 11 * Creates a new container for the drop down menu items.
12 * @constructor 12 * @constructor
13 * @extends {HTMLDivElement} 13 * @extends {HTMLDivElement}
14 */ 14 */
15 var DropDownContainer = cr.ui.define('div'); 15 var DropDownContainer = cr.ui.define('div');
16 16
17 DropDownContainer.prototype = { 17 DropDownContainer.prototype = {
18 __proto__: HTMLDivElement.prototype, 18 __proto__: HTMLDivElement.prototype,
19 19
20 /** @inheritDoc */ 20 /** @inheritDoc */
21 decorate: function() { 21 decorate: function() {
22 this.classList.add('dropdown-container'); 22 this.classList.add('dropdown-container');
23 // Selected item in the menu list. 23 // Selected item in the menu list.
24 this.selectedItem = null; 24 this.selectedItem = null;
25 // First item which could be selected. 25 // First item which could be selected.
26 this.firstItem = null; 26 this.firstItem = null;
27 // Whether scroll has just happened.
28 this.scrollJustHappened = false;
29 },
30
31 scrollAction: function(item) {
Nikita (slow) 2011/09/21 10:44:25 nit: Function comment.
altimofeev 2011/09/21 11:49:53 Done.
32 var thisTop = this.scrollTop;
33 var thisBottom = thisTop + this.offsetHeight;
34 var itemTop = item.offsetTop;
35 var itemBottom = itemTop + item.offsetHeight;
36 if (itemTop <= thisTop) return -1;
37 if (itemBottom >= thisBottom) return 1;
38 return 0;
27 }, 39 },
28 40
29 /** 41 /**
30 * Selects new item. 42 * Selects new item.
31 * @param {!Object} selectedItem Item to be selected. 43 * @param {!Object} selectedItem Item to be selected.
44 * @param {boolean} mouseOver Is mouseover event triggered?
32 */ 45 */
33 selectItem: function(selectedItem) { 46 selectItem: function(selectedItem, mouseOver) {
47 if (mouseOver && this.scrollJustHappened) {
48 this.scrollJustHappened = false;
49 return;
50 }
34 if (this.selectedItem) 51 if (this.selectedItem)
35 this.selectedItem.classList.remove('hover'); 52 this.selectedItem.classList.remove('hover');
36 selectedItem.classList.add('hover'); 53 selectedItem.classList.add('hover');
37 this.selectedItem = selectedItem; 54 this.selectedItem = selectedItem;
55 var action = this.scrollAction(selectedItem);
56 if (action != 0) {
57 selectedItem.scrollIntoView(action < 0);
58 this.scrollJustHappened = true;
59 }
38 } 60 }
39 }; 61 };
40 62
41 /** 63 /**
42 * Creates a new DropDown div. 64 * Creates a new DropDown div.
43 * @constructor 65 * @constructor
44 * @extends {HTMLDivElement} 66 * @extends {HTMLDivElement}
45 */ 67 */
46 var DropDown = cr.ui.define('div'); 68 var DropDown = cr.ui.define('div');
47 69
(...skipping 21 matching lines...) Expand all
69 }, 91 },
70 92
71 /** 93 /**
72 * Sets dropdown menu visibility. 94 * Sets dropdown menu visibility.
73 * @param {bool} show New visibility state for dropdown menu. 95 * @param {bool} show New visibility state for dropdown menu.
74 */ 96 */
75 set isShown(show) { 97 set isShown(show) {
76 this.firstElementChild.hidden = !show; 98 this.firstElementChild.hidden = !show;
77 this.container.hidden = !show; 99 this.container.hidden = !show;
78 if (show) 100 if (show)
79 this.container.selectItem(this.container.firstItem); 101 this.container.selectItem(this.container.firstItem, false);
80 }, 102 },
81 103
82 /** 104 /**
83 * Returns title button. 105 * Returns title button.
84 */ 106 */
85 get titleButton() { 107 get titleButton() {
86 return this.children[1]; 108 return this.children[1];
87 }, 109 },
88 110
89 /** 111 /**
(...skipping 25 matching lines...) Expand all
115 var item = items[i]; 137 var item = items[i];
116 if ('sub' in item) { 138 if ('sub' in item) {
117 // Workaround for submenus, add items on top level. 139 // Workaround for submenus, add items on top level.
118 // TODO(altimofeev): support submenus. 140 // TODO(altimofeev): support submenus.
119 for (var j = 0; j < item.sub.length; ++j) 141 for (var j = 0; j < item.sub.length; ++j)
120 this.createItem_(this.container, item.sub[j]); 142 this.createItem_(this.container, item.sub[j]);
121 continue; 143 continue;
122 } 144 }
123 this.createItem_(this.container, item); 145 this.createItem_(this.container, item);
124 } 146 }
125 this.container.selectItem(this.container.firstItem); 147 this.container.selectItem(this.container.firstItem, false);
126 }, 148 },
127 149
128 /** 150 /**
129 * Id of the active drop-down element. 151 * Id of the active drop-down element.
130 * @private 152 * @private
131 */ 153 */
132 activeElementId_: '', 154 activeElementId_: '',
133 155
134 /** 156 /**
135 * Creates dropdown item element and adds into container. 157 * Creates dropdown item element and adds into container.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 wrapperDiv.addEventListener('click', function f(e) { 196 wrapperDiv.addEventListener('click', function f(e) {
175 var item = this.lastElementChild; 197 var item = this.lastElementChild;
176 if (item.iid < -1 || item.classList.contains('disabled-item')) 198 if (item.iid < -1 || item.classList.contains('disabled-item'))
177 return; 199 return;
178 item.controller.isShown = false; 200 item.controller.isShown = false;
179 if (item.iid >= 0) 201 if (item.iid >= 0)
180 chrome.send('networkItemChosen', [item.iid]); 202 chrome.send('networkItemChosen', [item.iid]);
181 this.parentNode.parentNode.titleButton.focus(); 203 this.parentNode.parentNode.titleButton.focus();
182 }); 204 });
183 wrapperDiv.addEventListener('mouseover', function f(e) { 205 wrapperDiv.addEventListener('mouseover', function f(e) {
184 this.parentNode.selectItem(this); 206 this.parentNode.selectItem(this, true);
185 }); 207 });
186 itemElement = wrapperDiv; 208 itemElement = wrapperDiv;
187 } 209 }
188 container.appendChild(itemElement); 210 container.appendChild(itemElement);
189 if (!container.firstItem && item.id >= 0) { 211 if (!container.firstItem && item.id >= 0) {
190 container.firstItem = itemElement; 212 container.firstItem = itemElement;
191 } 213 }
192 }, 214 },
193 215
194 /** 216 /**
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (!this.isShown) 279 if (!this.isShown)
258 return; 280 return;
259 var selected = this.container.selectedItem; 281 var selected = this.container.selectedItem;
260 switch (e.keyCode) { 282 switch (e.keyCode) {
261 case 38: { // Key up. 283 case 38: { // Key up.
262 do { 284 do {
263 selected = selected.previousSibling; 285 selected = selected.previousSibling;
264 if (!selected) 286 if (!selected)
265 selected = this.container.lastElementChild; 287 selected = this.container.lastElementChild;
266 } while (selected.iid < 0); 288 } while (selected.iid < 0);
267 this.container.selectItem(selected); 289 this.container.selectItem(selected, false);
268 break; 290 break;
269 } 291 }
270 case 40: { // Key down. 292 case 40: { // Key down.
271 do { 293 do {
272 selected = selected.nextSibling; 294 selected = selected.nextSibling;
273 if (!selected) 295 if (!selected)
274 selected = this.container.firstItem; 296 selected = this.container.firstItem;
275 } while (selected.iid < 0); 297 } while (selected.iid < 0);
276 this.container.selectItem(selected); 298 this.container.selectItem(selected, false);
277 break; 299 break;
278 } 300 }
279 case 27: { // Esc. 301 case 27: { // Esc.
280 this.isShown = false; 302 this.isShown = false;
281 break; 303 break;
282 } 304 }
283 case 9: { // Tab. 305 case 9: { // Tab.
284 this.isShown = false; 306 this.isShown = false;
285 break; 307 break;
286 } 308 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 DropDown.activeElementId_ = ''; 359 DropDown.activeElementId_ = '';
338 chrome.send('networkDropdownHide', []); 360 chrome.send('networkDropdownHide', []);
339 } 361 }
340 } 362 }
341 }; 363 };
342 364
343 return { 365 return {
344 DropDown: DropDown 366 DropDown: DropDown
345 }; 367 };
346 }); 368 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698