| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 SELECT: 'print_preview.DestinationListItem.SELECT', | 57 SELECT: 'print_preview.DestinationListItem.SELECT', |
| 58 REGISTER_PROMO_CLICKED: | 58 REGISTER_PROMO_CLICKED: |
| 59 'print_preview.DestinationListItem.REGISTER_PROMO_CLICKED' | 59 'print_preview.DestinationListItem.REGISTER_PROMO_CLICKED' |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 DestinationListItem.prototype = { | 62 DestinationListItem.prototype = { |
| 63 __proto__: print_preview.Component.prototype, | 63 __proto__: print_preview.Component.prototype, |
| 64 | 64 |
| 65 /** @override */ | 65 /** @override */ |
| 66 createDom: function() { | 66 createDom: function() { |
| 67 this.setElementInternal(this.cloneTemplateInternal( | 67 this.setElementInternal( |
| 68 'destination-list-item-template')); | 68 this.cloneTemplateInternal('destination-list-item-template')); |
| 69 this.updateUi_(); | 69 this.updateUi_(); |
| 70 }, | 70 }, |
| 71 | 71 |
| 72 /** @override */ | 72 /** @override */ |
| 73 enterDocument: function() { | 73 enterDocument: function() { |
| 74 print_preview.Component.prototype.enterDocument.call(this); | 74 print_preview.Component.prototype.enterDocument.call(this); |
| 75 this.tracker.add(this.getElement(), 'click', this.onActivate_.bind(this)); | 75 this.tracker.add(this.getElement(), 'click', this.onActivate_.bind(this)); |
| 76 this.tracker.add( | 76 this.tracker.add( |
| 77 this.getElement(), 'keydown', this.onKeyDown_.bind(this)); | 77 this.getElement(), 'keydown', this.onKeyDown_.bind(this)); |
| 78 this.tracker.add( | 78 this.tracker.add( |
| 79 this.getChildElement('.register-promo-button'), | 79 this.getChildElement('.register-promo-button'), 'click', |
| 80 'click', | |
| 81 this.onRegisterPromoClicked_.bind(this)); | 80 this.onRegisterPromoClicked_.bind(this)); |
| 82 }, | 81 }, |
| 83 | 82 |
| 84 /** @return {!print_preiew.Destination} */ | 83 /** @return {!print_preiew.Destination} */ |
| 85 get destination() { | 84 get destination() { |
| 86 return this.destination_; | 85 return this.destination_; |
| 87 }, | 86 }, |
| 88 | 87 |
| 89 /** | 88 /** |
| 90 * Updates the list item UI state. | 89 * Updates the list item UI state. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 extensionNameEl.title = this.destination_.extensionName; | 137 extensionNameEl.title = this.destination_.extensionName; |
| 139 if (this.query_) { | 138 if (this.query_) { |
| 140 extensionNameEl.textContent = ''; | 139 extensionNameEl.textContent = ''; |
| 141 this.addTextWithHighlight_(extensionNameEl, extensionName); | 140 this.addTextWithHighlight_(extensionNameEl, extensionName); |
| 142 } else { | 141 } else { |
| 143 extensionNameEl.textContent = this.destination_.extensionName; | 142 extensionNameEl.textContent = this.destination_.extensionName; |
| 144 } | 143 } |
| 145 | 144 |
| 146 var extensionIconEl = this.getChildElement('.extension-icon'); | 145 var extensionIconEl = this.getChildElement('.extension-icon'); |
| 147 extensionIconEl.style.backgroundImage = '-webkit-image-set(' + | 146 extensionIconEl.style.backgroundImage = '-webkit-image-set(' + |
| 148 'url(chrome://extension-icon/' + | 147 'url(chrome://extension-icon/' + this.destination_.extensionId + |
| 149 this.destination_.extensionId + '/24/1) 1x,' + | 148 '/24/1) 1x,' + |
| 150 'url(chrome://extension-icon/' + | 149 'url(chrome://extension-icon/' + this.destination_.extensionId + |
| 151 this.destination_.extensionId + '/48/1) 2x)'; | 150 '/48/1) 2x)'; |
| 152 extensionIconEl.title = loadTimeData.getStringF( | 151 extensionIconEl.title = loadTimeData.getStringF( |
| 153 'extensionDestinationIconTooltip', | 152 'extensionDestinationIconTooltip', this.destination_.extensionName); |
| 154 this.destination_.extensionName); | |
| 155 extensionIconEl.onclick = this.onExtensionIconClicked_.bind(this); | 153 extensionIconEl.onclick = this.onExtensionIconClicked_.bind(this); |
| 156 extensionIconEl.onkeydown = this.onExtensionIconKeyDown_.bind(this); | 154 extensionIconEl.onkeydown = this.onExtensionIconKeyDown_.bind(this); |
| 157 } | 155 } |
| 158 | 156 |
| 159 var extensionIndicatorEl = | 157 var extensionIndicatorEl = |
| 160 this.getChildElement('.extension-controlled-indicator'); | 158 this.getChildElement('.extension-controlled-indicator'); |
| 161 setIsVisible(extensionIndicatorEl, this.destination_.isExtension); | 159 setIsVisible(extensionIndicatorEl, this.destination_.isExtension); |
| 162 | 160 |
| 163 // Initialize the element which renders the destination's offline status. | 161 // Initialize the element which renders the destination's offline status. |
| 164 this.getElement().classList.toggle('stale', this.destination_.isOffline); | 162 this.getElement().classList.toggle('stale', this.destination_.isOffline); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 * @private | 198 * @private |
| 201 */ | 199 */ |
| 202 onActivate_: function() { | 200 onActivate_: function() { |
| 203 if (this.destination_.id == | 201 if (this.destination_.id == |
| 204 print_preview.Destination.GooglePromotedId.FEDEX && | 202 print_preview.Destination.GooglePromotedId.FEDEX && |
| 205 !this.destination_.isTosAccepted) { | 203 !this.destination_.isTosAccepted) { |
| 206 if (!this.fedexTos_) { | 204 if (!this.fedexTos_) { |
| 207 this.fedexTos_ = new print_preview.FedexTos(); | 205 this.fedexTos_ = new print_preview.FedexTos(); |
| 208 this.fedexTos_.render(this.getElement()); | 206 this.fedexTos_.render(this.getElement()); |
| 209 this.tracker.add( | 207 this.tracker.add( |
| 210 this.fedexTos_, | 208 this.fedexTos_, print_preview.FedexTos.EventType.AGREE, |
| 211 print_preview.FedexTos.EventType.AGREE, | |
| 212 this.onTosAgree_.bind(this)); | 209 this.onTosAgree_.bind(this)); |
| 213 } | 210 } |
| 214 this.fedexTos_.setIsVisible(true); | 211 this.fedexTos_.setIsVisible(true); |
| 215 } else if (this.destination_.connectionStatus != | 212 } else if ( |
| 216 print_preview.Destination.ConnectionStatus.UNREGISTERED) { | 213 this.destination_.connectionStatus != |
| 214 print_preview.Destination.ConnectionStatus.UNREGISTERED) { |
| 217 var selectEvt = new Event(DestinationListItem.EventType.SELECT); | 215 var selectEvt = new Event(DestinationListItem.EventType.SELECT); |
| 218 selectEvt.destination = this.destination_; | 216 selectEvt.destination = this.destination_; |
| 219 this.eventTarget_.dispatchEvent(selectEvt); | 217 this.eventTarget_.dispatchEvent(selectEvt); |
| 220 } | 218 } |
| 221 }, | 219 }, |
| 222 | 220 |
| 223 /** | 221 /** |
| 224 * Called when the key is pressed on the destination item. Dispatches a | 222 * Called when the key is pressed on the destination item. Dispatches a |
| 225 * SELECT event when Enter is pressed. | 223 * SELECT event when Enter is pressed. |
| 226 * @param {KeyboardEvent} e Keyboard event to process. | 224 * @param {KeyboardEvent} e Keyboard event to process. |
| 227 * @private | 225 * @private |
| 228 */ | 226 */ |
| 229 onKeyDown_: function(e) { | 227 onKeyDown_: function(e) { |
| 230 if (!hasKeyModifiers(e)) { | 228 if (!hasKeyModifiers(e)) { |
| 231 if (e.keyCode == 13) { | 229 if (e.keyCode == 13) { |
| 232 var activeElementTag = document.activeElement ? | 230 var activeElementTag = document.activeElement ? |
| 233 document.activeElement.tagName.toUpperCase() : ''; | 231 document.activeElement.tagName.toUpperCase() : |
| 232 ''; |
| 234 if (activeElementTag == 'LI') { | 233 if (activeElementTag == 'LI') { |
| 235 e.stopPropagation(); | 234 e.stopPropagation(); |
| 236 e.preventDefault(); | 235 e.preventDefault(); |
| 237 this.onActivate_(); | 236 this.onActivate_(); |
| 238 } | 237 } |
| 239 } | 238 } |
| 240 } | 239 } |
| 241 }, | 240 }, |
| 242 | 241 |
| 243 /** | 242 /** |
| 244 * Called when the user agrees to the print destination's terms-of-service. | 243 * Called when the user agrees to the print destination's terms-of-service. |
| 245 * Selects the print destination that was agreed to. | 244 * Selects the print destination that was agreed to. |
| 246 * @private | 245 * @private |
| 247 */ | 246 */ |
| 248 onTosAgree_: function() { | 247 onTosAgree_: function() { |
| 249 var selectEvt = new Event(DestinationListItem.EventType.SELECT); | 248 var selectEvt = new Event(DestinationListItem.EventType.SELECT); |
| 250 selectEvt.destination = this.destination_; | 249 selectEvt.destination = this.destination_; |
| 251 this.eventTarget_.dispatchEvent(selectEvt); | 250 this.eventTarget_.dispatchEvent(selectEvt); |
| 252 }, | 251 }, |
| 253 | 252 |
| 254 /** | 253 /** |
| 255 * Called when the registration promo is clicked. | 254 * Called when the registration promo is clicked. |
| 256 * @private | 255 * @private |
| 257 */ | 256 */ |
| 258 onRegisterPromoClicked_: function() { | 257 onRegisterPromoClicked_: function() { |
| 259 var promoClickedEvent = new Event( | 258 var promoClickedEvent = |
| 260 DestinationListItem.EventType.REGISTER_PROMO_CLICKED); | 259 new Event(DestinationListItem.EventType.REGISTER_PROMO_CLICKED); |
| 261 promoClickedEvent.destination = this.destination_; | 260 promoClickedEvent.destination = this.destination_; |
| 262 this.eventTarget_.dispatchEvent(promoClickedEvent); | 261 this.eventTarget_.dispatchEvent(promoClickedEvent); |
| 263 }, | 262 }, |
| 264 | 263 |
| 265 /** | 264 /** |
| 266 * Handles click and 'Enter' key down events for the extension icon element. | 265 * Handles click and 'Enter' key down events for the extension icon element. |
| 267 * It opens extensions page with the extension associated with the | 266 * It opens extensions page with the extension associated with the |
| 268 * destination highlighted. | 267 * destination highlighted. |
| 269 * @param {MouseEvent|KeyboardEvent} e The event to handle. | 268 * @param {MouseEvent|KeyboardEvent} e The event to handle. |
| 270 * @private | 269 * @private |
| (...skipping 12 matching lines...) Expand all Loading... |
| 283 onExtensionIconKeyDown_: function(e) { | 282 onExtensionIconKeyDown_: function(e) { |
| 284 if (hasKeyModifiers(e)) | 283 if (hasKeyModifiers(e)) |
| 285 return; | 284 return; |
| 286 if (e.keyCode != 13 /* Enter */) | 285 if (e.keyCode != 13 /* Enter */) |
| 287 return; | 286 return; |
| 288 this.onExtensionIconClicked_(event); | 287 this.onExtensionIconClicked_(event); |
| 289 } | 288 } |
| 290 }; | 289 }; |
| 291 | 290 |
| 292 // Export | 291 // Export |
| 293 return { | 292 return {DestinationListItem: DestinationListItem}; |
| 294 DestinationListItem: DestinationListItem | |
| 295 }; | |
| 296 }); | 293 }); |
| OLD | NEW |