| 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 /** |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 get container() { | 92 get container() { |
| 93 return this.lastElementChild; | 93 return this.lastElementChild; |
| 94 }, | 94 }, |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * Sets title and icon. | 97 * Sets title and icon. |
| 98 * @param {string} title Text on dropdown. | 98 * @param {string} title Text on dropdown. |
| 99 * @param {string} icon Icon in dataURL format. | 99 * @param {string} icon Icon in dataURL format. |
| 100 */ | 100 */ |
| 101 setTitle: function(title, icon) { | 101 setTitle: function(title, icon) { |
| 102 // TODO(nkostylev): Icon support for dropdown title. | 102 this.titleButton.firstElementChild.src = icon; |
| 103 this.titleButton.textContent = title; | 103 this.titleButton.lastElementChild.textContent = title; |
| 104 }, | 104 }, |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * Sets dropdown items. | 107 * Sets dropdown items. |
| 108 * @param {Array} items Dropdown items array. | 108 * @param {Array} items Dropdown items array. |
| 109 */ | 109 */ |
| 110 setItems: function(items) { | 110 setItems: function(items) { |
| 111 this.container.innerHTML = ''; | 111 this.container.innerHTML = ''; |
| 112 this.container.firstItem = null; | 112 this.container.firstItem = null; |
| 113 this.container.selectedItem = null; | 113 this.container.selectedItem = null; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 imageDiv.appendChild(image); | 165 imageDiv.appendChild(image); |
| 166 wrapperDiv.appendChild(imageDiv); | 166 wrapperDiv.appendChild(imageDiv); |
| 167 wrapperDiv.appendChild(itemElement); | 167 wrapperDiv.appendChild(itemElement); |
| 168 wrapperDiv.addEventListener('click', function f(e) { | 168 wrapperDiv.addEventListener('click', function f(e) { |
| 169 var item = this.lastElementChild; | 169 var item = this.lastElementChild; |
| 170 if (item.iid < -1 || item.classList.contains('disabled-item')) | 170 if (item.iid < -1 || item.classList.contains('disabled-item')) |
| 171 return; | 171 return; |
| 172 item.controller.isShown = false; | 172 item.controller.isShown = false; |
| 173 if (item.iid >= 0) | 173 if (item.iid >= 0) |
| 174 chrome.send('networkItemChosen', [item.iid]); | 174 chrome.send('networkItemChosen', [item.iid]); |
| 175 this.parentNode.parentNode.titleButton.focus(); |
| 175 }); | 176 }); |
| 176 wrapperDiv.addEventListener('mouseover', function f(e) { | 177 wrapperDiv.addEventListener('mouseover', function f(e) { |
| 177 this.parentNode.selectItem(this); | 178 this.parentNode.selectItem(this); |
| 178 }); | 179 }); |
| 179 itemElement = wrapperDiv; | 180 itemElement = wrapperDiv; |
| 180 } | 181 } |
| 181 container.appendChild(itemElement); | 182 container.appendChild(itemElement); |
| 182 if (!container.firstItem && item.id >= 0) { | 183 if (!container.firstItem && item.id >= 0) { |
| 183 container.firstItem = itemElement; | 184 container.firstItem = itemElement; |
| 184 } | 185 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 198 }); | 199 }); |
| 199 return overlay; | 200 return overlay; |
| 200 }, | 201 }, |
| 201 | 202 |
| 202 /** | 203 /** |
| 203 * Creates dropdown title element. | 204 * Creates dropdown title element. |
| 204 * @type {HTMLElement} | 205 * @type {HTMLElement} |
| 205 * @private | 206 * @private |
| 206 */ | 207 */ |
| 207 createTitle_: function() { | 208 createTitle_: function() { |
| 208 var el = this.ownerDocument.createElement('button'); | 209 var image = this.ownerDocument.createElement('img'); |
| 210 var text = this.ownerDocument.createElement('div'); |
| 211 |
| 212 var el = this.ownerDocument.createElement('div'); |
| 213 el.appendChild(image); |
| 214 el.appendChild(text); |
| 215 |
| 216 el.tabIndex = 0; |
| 209 el.classList.add('dropdown-title'); | 217 el.classList.add('dropdown-title'); |
| 210 el.iid = -1; | 218 el.iid = -1; |
| 211 el.controller = this; | 219 el.controller = this; |
| 212 el.enterPressed = false; | 220 el.inFocus = false; |
| 221 el.opening = false; |
| 213 | 222 |
| 214 el.addEventListener('click', function f(e) { | 223 el.addEventListener('click', function f(e) { |
| 215 this.focus(); | |
| 216 this.controller.isShown = !this.controller.isShown; | 224 this.controller.isShown = !this.controller.isShown; |
| 225 }); |
| 217 | 226 |
| 218 if (this.enterPressed) { | 227 el.addEventListener('focus', function(e) { |
| 219 this.enterPressed = false; | 228 this.inFocus = true; |
| 220 if (!this.controller.isShown) { | 229 }); |
| 221 var item = this.controller.container.selectedItem.lastElementChild; | 230 |
| 222 if (item.iid >= 0 && !item.classList.contains('disabled-item')) | 231 el.addEventListener('blur', function(e) { |
| 223 chrome.send('networkItemChosen', [item.iid]); | 232 this.inFocus = false; |
| 224 } | 233 }); |
| 234 |
| 235 el.addEventListener('keydown', function f(e) { |
| 236 if (this.inFocus && !this.controller.isShown && e.keyCode == 13) { |
| 237 // Enter has been pressed. |
| 238 this.opening = true; |
| 239 this.controller.isShown = true; |
| 225 } | 240 } |
| 226 }); | 241 }); |
| 227 return el; | 242 return el; |
| 228 }, | 243 }, |
| 229 | 244 |
| 230 /** | 245 /** |
| 231 * Handles keydown event from the keyboard. | 246 * Handles keydown event from the keyboard. |
| 232 * @private | 247 * @private |
| 233 * @param {!Event} e Keydown event. | 248 * @param {!Event} e Keydown event. |
| 234 */ | 249 */ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 257 } | 272 } |
| 258 case 27: { // Esc. | 273 case 27: { // Esc. |
| 259 this.isShown = false; | 274 this.isShown = false; |
| 260 break; | 275 break; |
| 261 } | 276 } |
| 262 case 9: { // Tab. | 277 case 9: { // Tab. |
| 263 this.isShown = false; | 278 this.isShown = false; |
| 264 break; | 279 break; |
| 265 } | 280 } |
| 266 case 13: { // Enter. | 281 case 13: { // Enter. |
| 267 this.titleButton.enterPressed = true; | 282 var button = this.titleButton; |
| 283 if (!button.opening) { |
| 284 button.focus(); |
| 285 this.isShown = false; |
| 286 var item = |
| 287 button.controller.container.selectedItem.lastElementChild; |
| 288 if (item.iid >= 0 && !item.classList.contains('disabled-item')) |
| 289 chrome.send('networkItemChosen', [item.iid]); |
| 290 } else { |
| 291 button.opening = false; |
| 292 } |
| 268 break; | 293 break; |
| 269 } | 294 } |
| 270 }; | 295 }; |
| 271 } | 296 } |
| 272 }; | 297 }; |
| 273 | 298 |
| 274 /** | 299 /** |
| 275 * Creates a new oobe screen div. | 300 * Creates a new oobe screen div. |
| 276 * @constructor | 301 * @constructor |
| 277 * @extends {HTMLDivElement} | 302 * @extends {HTMLDivElement} |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 }; | 383 }; |
| 359 | 384 |
| 360 NetworkScreen.updateNetworkTitle = function(title, icon) { | 385 NetworkScreen.updateNetworkTitle = function(title, icon) { |
| 361 $('connect').updateNetworkTitle(title, icon); | 386 $('connect').updateNetworkTitle(title, icon); |
| 362 }; | 387 }; |
| 363 | 388 |
| 364 return { | 389 return { |
| 365 NetworkScreen: NetworkScreen | 390 NetworkScreen: NetworkScreen |
| 366 }; | 391 }; |
| 367 }); | 392 }); |
| OLD | NEW |