Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Oobe network screen implementation. | 6 * @fileoverview Oobe network screen implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 cr.define('oobe', function() { | 9 cr.define('oobe', function() { |
| 10 /** | 10 /** |
| 11 * Creates a new DropDown div. | |
| 12 * @constructor | |
| 13 * @extends {HTMLDivElement} | |
| 14 */ | |
| 15 var DropDown = cr.ui.define('div'); | |
| 16 | |
| 17 DropDown.ITEM_DIVIDER_ID = -2; | |
| 18 | |
| 19 DropDown.prototype = { | |
| 20 __proto__: HTMLDivElement.prototype, | |
| 21 | |
| 22 /** @inheritDoc */ | |
| 23 decorate: function() { | |
| 24 this.appendChild(this.createTitle_()); | |
| 25 | |
| 26 // Create menu items container. | |
| 27 var container = this.ownerDocument.createElement('div') | |
| 28 container.classList.add('dropdown-container'); | |
| 29 this.appendChild(container); | |
| 30 this.isShown = false; | |
| 31 }, | |
| 32 | |
| 33 /** | |
| 34 * Returns true if dropdown menu is shown. | |
| 35 * @type {bool} Whether menu element is shown. | |
| 36 */ | |
| 37 get isShown() { | |
| 38 return !this.lastElementChild.hidden; | |
| 39 }, | |
| 40 | |
| 41 /** | |
| 42 * Sets dropdown menu visibility. | |
| 43 * @param {bool} show New visibility state for dropdown menu. | |
| 44 */ | |
| 45 set isShown(show) { | |
| 46 this.lastElementChild.hidden = !show; | |
| 47 }, | |
| 48 | |
| 49 /** | |
| 50 * Sets title and icon. | |
| 51 * @param {string} title Text on dropdown. | |
| 52 * @param {string} icon Icon in dataURL format. | |
| 53 */ | |
| 54 setTitle: function(title, icon) { | |
| 55 // TODO(nkostylev): Icon support for dropdown title. | |
| 56 $('dropdownTitle').textContent = title; | |
|
xiyuan
2011/08/06 17:12:17
nit: this.firstElementChild?
Nikita (slow)
2011/08/06 19:27:53
Done, I've thought that Chrome doesn't support thi
| |
| 57 }, | |
| 58 | |
| 59 /** | |
| 60 * Sets dropdown items. | |
| 61 * @param {Array} items Dropdown items array. | |
| 62 */ | |
| 63 setItems: function(items) { | |
| 64 var container = this.lastElementChild; | |
| 65 container.innerHTML = ''; | |
| 66 for (var i = 0; i < items.length; ++i) { | |
| 67 var item = items[i]; | |
| 68 if ('sub' in item) { | |
| 69 // Workaround for submenus, add items on top level. | |
| 70 // TODO(altimofeev): support submenus. | |
| 71 for (var j = 0; j < item.sub.length; ++j) | |
| 72 this.createItem_(container, item.sub[j]); | |
| 73 continue; | |
| 74 } | |
| 75 this.createItem_(container, item); | |
| 76 } | |
| 77 }, | |
| 78 | |
| 79 /** | |
| 80 * Creates dropdown item element and adds into container. | |
| 81 * @param {HTMLElement} container Container where item is added. | |
| 82 * @param {!Object} item Item to be added. | |
| 83 * @private | |
| 84 */ | |
| 85 createItem_ : function(container, item) { | |
| 86 var itemContentElement; | |
| 87 var className = 'dropdown-item'; | |
| 88 if (item.id == DropDown.ITEM_DIVIDER_ID) { | |
| 89 className = 'dropdown-divider'; | |
| 90 itemContentElement = this.ownerDocument.createElement('hr'); | |
| 91 } else { | |
| 92 var span = this.ownerDocument.createElement('span'); | |
| 93 itemContentElement = span; | |
| 94 span.textContent = item.label; | |
| 95 if ('bold' in item && item.bold) | |
| 96 span.classList.add('bold'); | |
| 97 var image = this.ownerDocument.createElement('img'); | |
| 98 if (item.icon) | |
| 99 image.src = item.icon; | |
| 100 } | |
| 101 | |
| 102 var itemElement = this.ownerDocument.createElement('div'); | |
| 103 itemElement.classList.add(className); | |
| 104 itemElement.appendChild(itemContentElement); | |
| 105 itemElement.iid = item.id; | |
| 106 itemElement.controller = this; | |
| 107 var enabled = 'enabled' in item && item.enabled; | |
| 108 if (!enabled) | |
| 109 itemElement.classList.add('disabled-item'); | |
| 110 | |
| 111 if (item.id > 0) { | |
| 112 var wrapperDiv = this.ownerDocument.createElement('div'); | |
| 113 wrapperDiv.classList.add('dropdown-item-container'); | |
| 114 var imageDiv = this.ownerDocument.createElement('div'); | |
| 115 imageDiv.classList.add('dropdown-image'); | |
| 116 imageDiv.appendChild(image); | |
| 117 wrapperDiv.appendChild(imageDiv); | |
| 118 wrapperDiv.appendChild(itemElement); | |
| 119 wrapperDiv.addEventListener('click', function f(e) { | |
| 120 var item = this.lastElementChild; | |
| 121 if (item.iid < -1 || item.classList.contains('disabled-item')) | |
| 122 return; | |
| 123 item.controller.isShown = !item.controller.isShown; | |
| 124 if (item.iid >= 0) | |
| 125 chrome.send('networkItemChosen', [item.iid]); | |
| 126 }); | |
| 127 itemElement = wrapperDiv; | |
| 128 } | |
| 129 container.appendChild(itemElement); | |
| 130 }, | |
| 131 | |
| 132 /** | |
| 133 * Creates dropdown title element. | |
| 134 * @type {HTMLElement} | |
| 135 * @private | |
| 136 */ | |
| 137 createTitle_: function() { | |
| 138 var el = this.ownerDocument.createElement('button'); | |
| 139 el.id = 'dropdownTitle'; | |
| 140 el.classList.add('dropdown-title'); | |
| 141 el.iid = -1; | |
| 142 el.controller = this; | |
| 143 el.addEventListener('click', function f(e) { | |
| 144 this.controller.isShown = !this.controller.isShown; | |
| 145 }); | |
| 146 return el; | |
| 147 } | |
| 148 }; | |
| 149 | |
| 150 /** | |
| 11 * Creates a new oobe screen div. | 151 * Creates a new oobe screen div. |
| 12 * @constructor | 152 * @constructor |
| 13 * @extends {HTMLDivElement} | 153 * @extends {HTMLDivElement} |
| 14 */ | 154 */ |
| 15 var NetworkScreen = cr.ui.define('div'); | 155 var NetworkScreen = cr.ui.define('div'); |
| 16 | 156 |
| 17 /** | 157 /** |
| 18 * Registers with Oobe. | 158 * Registers with Oobe. |
| 19 */ | 159 */ |
| 20 NetworkScreen.register = function() { | 160 NetworkScreen.register = function() { |
| 21 var screen = $('connect'); | 161 var screen = $('connect'); |
| 22 NetworkScreen.decorate(screen); | 162 NetworkScreen.decorate(screen); |
| 23 Oobe.getInstance().registerScreen(screen); | 163 Oobe.getInstance().registerScreen(screen); |
| 24 }; | 164 }; |
| 25 | 165 |
| 26 NetworkScreen.prototype = { | 166 NetworkScreen.prototype = { |
| 27 __proto__: HTMLDivElement.prototype, | 167 __proto__: HTMLDivElement.prototype, |
| 28 | 168 |
| 169 /** | |
| 170 * Dropdown element for networks selection. | |
| 171 */ | |
| 172 dropdown_: null, | |
| 173 | |
| 29 /** @inheritDoc */ | 174 /** @inheritDoc */ |
| 30 decorate: function() { | 175 decorate: function() { |
| 31 Oobe.setupSelect($('language-select'), | 176 Oobe.setupSelect($('language-select'), |
| 32 templateData.languageList, | 177 templateData.languageList, |
| 33 'networkOnLanguageChanged'); | 178 'networkOnLanguageChanged'); |
| 34 | 179 |
| 35 Oobe.setupSelect($('keyboard-select'), | 180 Oobe.setupSelect($('keyboard-select'), |
| 36 templateData.inputMethodsList, | 181 templateData.inputMethodsList, |
| 37 'networkOnInputMethodChanged'); | 182 'networkOnInputMethodChanged'); |
| 38 }, | 183 |
| 184 this.dropdown_ = $('networks-list'); | |
| 185 DropDown.decorate(this.dropdown_); | |
| 186 }, | |
| 187 | |
| 188 /** | |
| 189 * Updates network list in dropdown. | |
| 190 * @param {Array} items Dropdown items array. | |
| 191 */ | |
| 192 updateNetworks: function(data) { | |
| 193 this.dropdown_.setItems(data); | |
| 194 }, | |
| 195 | |
| 196 /** | |
| 197 * Updates dropdown title and icon. | |
| 198 * @param {string} title Text on dropdown. | |
| 199 * @param {string} icon Icon in dataURL format. | |
| 200 */ | |
| 201 updateNetworkTitle: function(title, icon) { | |
| 202 this.dropdown_.setTitle(title, icon); | |
| 203 }, | |
| 39 | 204 |
| 40 /** | 205 /** |
| 41 * Header text of the screen. | 206 * Header text of the screen. |
| 42 * @type {string} | 207 * @type {string} |
| 43 */ | 208 */ |
| 44 get header() { | 209 get header() { |
| 45 return localStrings.getString('networkScreenTitle'); | 210 return localStrings.getString('networkScreenTitle'); |
| 46 }, | 211 }, |
| 47 | 212 |
| 48 /** | 213 /** |
| 49 * Buttons in oobe wizard's button strip. | 214 * Buttons in oobe wizard's button strip. |
| 50 * @type {array} Array of Buttons. | 215 * @type {array} Array of Buttons. |
| 51 */ | 216 */ |
| 52 get buttons() { | 217 get buttons() { |
| 53 var buttons = []; | 218 var buttons = []; |
| 54 | 219 |
| 55 var continueButton = this.ownerDocument.createElement('button'); | 220 var continueButton = this.ownerDocument.createElement('button'); |
| 56 continueButton.id = 'continue-button'; | 221 continueButton.id = 'continue-button'; |
| 57 continueButton.textContent = localStrings.getString('continueButton'); | 222 continueButton.textContent = localStrings.getString('continueButton'); |
| 58 continueButton.addEventListener('click', function(e) { | 223 continueButton.addEventListener('click', function(e) { |
| 59 chrome.send('networkOnExit', []); | 224 chrome.send('networkOnExit', []); |
| 60 }); | 225 }); |
| 61 buttons.push(continueButton); | 226 buttons.push(continueButton); |
| 62 | 227 |
| 63 return buttons; | 228 return buttons; |
| 64 } | 229 } |
| 65 }; | 230 }; |
| 66 | 231 |
| 232 NetworkScreen.updateNetworks = function(data) { | |
| 233 $('connect').updateNetworks(data); | |
| 234 }; | |
| 235 | |
| 236 NetworkScreen.updateNetworkTitle = function(title, icon) { | |
| 237 $('connect').updateNetworkTitle(title, icon); | |
| 238 }; | |
| 239 | |
| 67 return { | 240 return { |
| 68 NetworkScreen: NetworkScreen | 241 NetworkScreen: NetworkScreen |
| 69 }; | 242 }; |
| 70 }); | 243 }); |
| OLD | NEW |