OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** |
(...skipping 27 matching lines...) Expand all Loading... |
38 /** | 38 /** |
39 * Gets scroll action to be done for the item. | 39 * Gets scroll action to be done for the item. |
40 * @param {!Object} item Menu item. | 40 * @param {!Object} item Menu item. |
41 * @return {integer} -1 for scroll up; 0 for no action; 1 for scroll down. | 41 * @return {integer} -1 for scroll up; 0 for no action; 1 for scroll down. |
42 */ | 42 */ |
43 scrollAction: function(item) { | 43 scrollAction: function(item) { |
44 var thisTop = this.scrollTop; | 44 var thisTop = this.scrollTop; |
45 var thisBottom = thisTop + this.offsetHeight; | 45 var thisBottom = thisTop + this.offsetHeight; |
46 var itemTop = item.offsetTop; | 46 var itemTop = item.offsetTop; |
47 var itemBottom = itemTop + item.offsetHeight; | 47 var itemBottom = itemTop + item.offsetHeight; |
48 if (itemTop <= thisTop) return -1; | 48 if (itemTop <= thisTop) |
49 if (itemBottom >= thisBottom) return 1; | 49 return -1; |
| 50 if (itemBottom >= thisBottom) |
| 51 return 1; |
50 return 0; | 52 return 0; |
51 }, | 53 }, |
52 | 54 |
53 /** | 55 /** |
54 * Selects new item. | 56 * Selects new item. |
55 * @param {!Object} selectedItem Item to be selected. | 57 * @param {!Object} selectedItem Item to be selected. |
56 * @param {boolean} mouseOver Is mouseover event triggered? | 58 * @param {boolean} mouseOver Is mouseover event triggered? |
57 */ | 59 */ |
58 selectItem: function(selectedItem, mouseOver) { | 60 selectItem: function(selectedItem, mouseOver) { |
59 if (mouseOver && this.scrollJustHappened) { | 61 if (mouseOver && this.scrollJustHappened) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // Workaround for submenus, add items on top level. | 165 // Workaround for submenus, add items on top level. |
164 // TODO(altimofeev): support submenus. | 166 // TODO(altimofeev): support submenus. |
165 for (var j = 0; j < item.sub.length; ++j) | 167 for (var j = 0; j < item.sub.length; ++j) |
166 this.createItem_(this.container, item.sub[j]); | 168 this.createItem_(this.container, item.sub[j]); |
167 continue; | 169 continue; |
168 } | 170 } |
169 this.createItem_(this.container, item); | 171 this.createItem_(this.container, item); |
170 } | 172 } |
171 this.container.selectItem(this.container.firstItem, false); | 173 this.container.selectItem(this.container.firstItem, false); |
172 | 174 |
173 var maxHeight = cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping( | 175 var maxHeight = |
174 this.container); | 176 cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping(this.container); |
175 if (maxHeight < this.container.offsetHeight) | 177 if (maxHeight < this.container.offsetHeight) |
176 this.container.style.maxHeight = maxHeight + 'px'; | 178 this.container.style.maxHeight = maxHeight + 'px'; |
177 }, | 179 }, |
178 | 180 |
179 /** | 181 /** |
180 * Id of the active drop-down element. | 182 * Id of the active drop-down element. |
181 * @private | 183 * @private |
182 */ | 184 */ |
183 activeElementId_: '', | 185 activeElementId_: '', |
184 | 186 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 }); | 295 }); |
294 | 296 |
295 el.addEventListener('blur', function(e) { | 297 el.addEventListener('blur', function(e) { |
296 this.inFocus = false; | 298 this.inFocus = false; |
297 }); | 299 }); |
298 | 300 |
299 el.addEventListener('keydown', function f(e) { | 301 el.addEventListener('keydown', function f(e) { |
300 if (this.inFocus && !this.controller.isShown && | 302 if (this.inFocus && !this.controller.isShown && |
301 (e.keyCode == DropDown.KEYCODE_ENTER || | 303 (e.keyCode == DropDown.KEYCODE_ENTER || |
302 e.keyCode == DropDown.KEYCODE_SPACE || | 304 e.keyCode == DropDown.KEYCODE_SPACE || |
303 (!useKeyboardFlow && (e.keyCode == DropDown.KEYCODE_UP || | 305 (!useKeyboardFlow && |
304 e.keyCode == DropDown.KEYCODE_DOWN)))) { | 306 (e.keyCode == DropDown.KEYCODE_UP || |
| 307 e.keyCode == DropDown.KEYCODE_DOWN)))) { |
305 this.opening = true; | 308 this.opening = true; |
306 this.controller.isShown = true; | 309 this.controller.isShown = true; |
307 e.stopPropagation(); | 310 e.stopPropagation(); |
308 e.preventDefault(); | 311 e.preventDefault(); |
309 } | 312 } |
310 }); | 313 }); |
311 return el; | 314 return el; |
312 }, | 315 }, |
313 | 316 |
314 /** | 317 /** |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 chrome.send('networkDropdownRefresh'); | 429 chrome.send('networkDropdownRefresh'); |
427 }; | 430 }; |
428 | 431 |
429 /** | 432 /** |
430 * Sets the keyboard flow flag. | 433 * Sets the keyboard flow flag. |
431 */ | 434 */ |
432 DropDown.enableKeyboardFlow = function() { | 435 DropDown.enableKeyboardFlow = function() { |
433 useKeyboardFlow = true; | 436 useKeyboardFlow = true; |
434 }; | 437 }; |
435 | 438 |
436 return { | 439 return {DropDown: DropDown}; |
437 DropDown: DropDown | |
438 }; | |
439 }); | 440 }); |
OLD | NEW |