| 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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Component that renders a destination item in a destination list. | 9 * Component that renders a destination item in a destination list. |
| 10 * @param {!cr.EventTarget} eventTarget Event target to dispatch selection | 10 * @param {!cr.EventTarget} eventTarget Event target to dispatch selection |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 * @private | 31 * @private |
| 32 */ | 32 */ |
| 33 this.destination_ = destination; | 33 this.destination_ = destination; |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * Active filter query text. | 36 * Active filter query text. |
| 37 * @type {RegExp} | 37 * @type {RegExp} |
| 38 * @private | 38 * @private |
| 39 */ | 39 */ |
| 40 this.query_ = query; | 40 this.query_ = query; |
| 41 }; | 41 } |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Event types dispatched by the destination list item. | 44 * Event types dispatched by the destination list item. |
| 45 * @enum {string} | 45 * @enum {string} |
| 46 */ | 46 */ |
| 47 DestinationListItem.EventType = { | 47 DestinationListItem.EventType = { |
| 48 // Dispatched to check the printer needs to be configured before activation. | 48 // Dispatched to check the printer needs to be configured before activation. |
| 49 CONFIGURE_REQUEST: 'print_preview.DestinationListItem.CONFIGURE_REQUEST', | 49 CONFIGURE_REQUEST: 'print_preview.DestinationListItem.CONFIGURE_REQUEST', |
| 50 // Dispatched when the list item is activated. | 50 // Dispatched when the list item is activated. |
| 51 SELECT: 'print_preview.DestinationListItem.SELECT', | 51 SELECT: 'print_preview.DestinationListItem.SELECT', |
| (...skipping 16 matching lines...) Expand all Loading... |
| 68 print_preview.Component.prototype.enterDocument.call(this); | 68 print_preview.Component.prototype.enterDocument.call(this); |
| 69 this.tracker.add(this.getElement(), 'click', this.onActivate_.bind(this)); | 69 this.tracker.add(this.getElement(), 'click', this.onActivate_.bind(this)); |
| 70 this.tracker.add( | 70 this.tracker.add( |
| 71 this.getElement(), 'keydown', this.onKeyDown_.bind(this)); | 71 this.getElement(), 'keydown', this.onKeyDown_.bind(this)); |
| 72 this.tracker.add( | 72 this.tracker.add( |
| 73 this.getChildElement('.register-promo-button'), | 73 this.getChildElement('.register-promo-button'), |
| 74 'click', | 74 'click', |
| 75 this.onRegisterPromoClicked_.bind(this)); | 75 this.onRegisterPromoClicked_.bind(this)); |
| 76 }, | 76 }, |
| 77 | 77 |
| 78 /** @return {!print_preiew.Destination} */ | 78 /** @return {!print_preview.Destination} */ |
| 79 get destination() { | 79 get destination() { |
| 80 return this.destination_; | 80 return this.destination_; |
| 81 }, | 81 }, |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Updates the list item UI state. | 84 * Updates the list item UI state. |
| 85 * @param {!print_preview.Destination} destination Destination data object | 85 * @param {!print_preview.Destination} destination Destination data object |
| 86 * to render. | 86 * to render. |
| 87 * @param {RegExp} query Active filter query. | 87 * @param {RegExp} query Active filter query. |
| 88 */ | 88 */ |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 span.className = 'destination-list-item-query-highlight'; | 234 span.className = 'destination-list-item-query-highlight'; |
| 235 span.textContent = sections[i]; | 235 span.textContent = sections[i]; |
| 236 parent.appendChild(span); | 236 parent.appendChild(span); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 }, | 239 }, |
| 240 | 240 |
| 241 /** | 241 /** |
| 242 * Shows/Hides the configuring in progress message and starts/stops its | 242 * Shows/Hides the configuring in progress message and starts/stops its |
| 243 * animation accordingly. | 243 * animation accordingly. |
| 244 * @param {bool} show If the message and animation should be shown. | 244 * @param {boolean} show If the message and animation should be shown. |
| 245 * @private | 245 * @private |
| 246 */ | 246 */ |
| 247 updateConfiguringMessage_: function(show) { | 247 updateConfiguringMessage_: function(show) { |
| 248 setIsVisible( | 248 setIsVisible( |
| 249 this.getChildElement('.configuring-in-progress-text'), show); | 249 this.getChildElement('.configuring-in-progress-text'), show); |
| 250 this.getChildElement('.configuring-text-jumping-dots') | 250 this.getChildElement('.configuring-text-jumping-dots') |
| 251 .classList.toggle('jumping-dots', show); | 251 .classList.toggle('jumping-dots', show); |
| 252 }, | 252 }, |
| 253 | 253 |
| 254 /** | 254 /** |
| (...skipping 29 matching lines...) Expand all Loading... |
| 284 } | 284 } |
| 285 }, | 285 }, |
| 286 | 286 |
| 287 /** | 287 /** |
| 288 * Called when the key is pressed on the destination item. Dispatches a | 288 * Called when the key is pressed on the destination item. Dispatches a |
| 289 * SELECT event when Enter is pressed. | 289 * SELECT event when Enter is pressed. |
| 290 * @param {KeyboardEvent} e Keyboard event to process. | 290 * @param {KeyboardEvent} e Keyboard event to process. |
| 291 * @private | 291 * @private |
| 292 */ | 292 */ |
| 293 onKeyDown_: function(e) { | 293 onKeyDown_: function(e) { |
| 294 if (!hasKeyModifiers(e)) { | 294 if (e && !hasKeyModifiers(e)) { |
| 295 if (e.keyCode == 13) { | 295 if (e.keyCode == 13) { |
| 296 var activeElementTag = document.activeElement ? | 296 var activeElementTag = document.activeElement ? |
| 297 document.activeElement.tagName.toUpperCase() : ''; | 297 document.activeElement.tagName.toUpperCase() : ''; |
| 298 if (activeElementTag == 'LI') { | 298 if (activeElementTag == 'LI') { |
| 299 e.stopPropagation(); | 299 e.stopPropagation(); |
| 300 e.preventDefault(); | 300 e.preventDefault(); |
| 301 this.onActivate_(); | 301 this.onActivate_(); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 }, | 305 }, |
| 306 | 306 |
| 307 /** | 307 /** |
| 308 * Called when the registration promo is clicked. | 308 * Called when the registration promo is clicked. |
| 309 * @private | 309 * @private |
| 310 */ | 310 */ |
| 311 onRegisterPromoClicked_: function() { | 311 onRegisterPromoClicked_: function() { |
| 312 var promoClickedEvent = new Event( | 312 var promoClickedEvent = new Event( |
| 313 DestinationListItem.EventType.REGISTER_PROMO_CLICKED); | 313 DestinationListItem.EventType.REGISTER_PROMO_CLICKED); |
| 314 promoClickedEvent.destination = this.destination_; | 314 promoClickedEvent.destination = this.destination_; |
| 315 this.eventTarget_.dispatchEvent(promoClickedEvent); | 315 this.eventTarget_.dispatchEvent(promoClickedEvent); |
| 316 }, | 316 }, |
| 317 | 317 |
| 318 /** | 318 /** |
| 319 * Handles click and 'Enter' key down events for the extension icon element. | 319 * Handles click and 'Enter' key down events for the extension icon element. |
| 320 * It opens extensions page with the extension associated with the | 320 * It opens extensions page with the extension associated with the |
| 321 * destination highlighted. | 321 * destination highlighted. |
| 322 * @param {MouseEvent|KeyboardEvent} e The event to handle. | 322 * @param {Event} e The event to handle. |
| 323 * @private | 323 * @private |
| 324 */ | 324 */ |
| 325 onExtensionIconClicked_: function(e) { | 325 onExtensionIconClicked_: function(e) { |
| 326 e.stopPropagation(); | 326 e.stopPropagation(); |
| 327 window.open('chrome://extensions?id=' + this.destination_.extensionId); | 327 window.open('chrome://extensions?id=' + this.destination_.extensionId); |
| 328 }, | 328 }, |
| 329 | 329 |
| 330 /** | 330 /** |
| 331 * Handles key down event for the extensin icon element. Keys different than | 331 * Handles key down event for the extensin icon element. Keys different than |
| 332 * 'Enter' are ignored. | 332 * 'Enter' are ignored. |
| 333 * @param {KeyboardEvent} e The event to handle. | 333 * @param {Event} e The event to handle. |
| 334 * @private | 334 * @private |
| 335 */ | 335 */ |
| 336 onExtensionIconKeyDown_: function(e) { | 336 onExtensionIconKeyDown_: function(e) { |
| 337 if (hasKeyModifiers(e)) | 337 if (e && hasKeyModifiers(e)) |
| 338 return; | 338 return; |
| 339 if (e.keyCode != 13 /* Enter */) | 339 if (e.keyCode != 13 /* Enter */) |
| 340 return; | 340 return; |
| 341 this.onExtensionIconClicked_(event); | 341 this.onExtensionIconClicked_(e); |
| 342 } | 342 } |
| 343 }; | 343 }; |
| 344 | 344 |
| 345 // Export | 345 // Export |
| 346 return { | 346 return { |
| 347 DestinationListItem: DestinationListItem | 347 DestinationListItem: DestinationListItem |
| 348 }; | 348 }; |
| 349 }); | 349 }); |
| OLD | NEW |