Chromium Code Reviews| 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 |
| 11 * events to. | 11 * events to. |
| 12 * @param {!print_preview.DestinationStore} destinationStore Data store | |
| 13 * containing the destinations to search through. Used as a proxy to | |
| 14 * native layer for resolving the destination. | |
| 12 * @param {!print_preview.Destination} destination Destination data object to | 15 * @param {!print_preview.Destination} destination Destination data object to |
| 13 * render. | 16 * render. |
| 14 * @param {RegExp} query Active filter query. | 17 * @param {RegExp} query Active filter query. |
| 15 * @constructor | 18 * @constructor |
| 16 * @extends {print_preview.Component} | 19 * @extends {print_preview.Component} |
| 17 */ | 20 */ |
| 18 function DestinationListItem(eventTarget, destination, query) { | 21 function DestinationListItem( |
| 22 eventTarget, destinationStore, destination, query) { | |
| 19 print_preview.Component.call(this); | 23 print_preview.Component.call(this); |
| 20 | 24 |
| 21 /** | 25 /** |
| 22 * Event target to dispatch selection events to. | 26 * Event target to dispatch selection events to. |
| 23 * @type {!cr.EventTarget} | 27 * @type {!cr.EventTarget} |
| 24 * @private | 28 * @private |
| 25 */ | 29 */ |
| 26 this.eventTarget_ = eventTarget; | 30 this.eventTarget_ = eventTarget; |
| 27 | 31 |
| 28 /** | 32 /** |
| 33 * Data store containing all the destinations. | |
| 34 * @type {!print_preview.DestinationStore} | |
| 35 * @private | |
| 36 */ | |
| 37 this.destinationStore_ = destinationStore; | |
| 38 | |
| 39 /** | |
| 29 * Destination that the list item renders. | 40 * Destination that the list item renders. |
| 30 * @type {!print_preview.Destination} | 41 * @type {!print_preview.Destination} |
| 31 * @private | 42 * @private |
| 32 */ | 43 */ |
| 33 this.destination_ = destination; | 44 this.destination_ = destination; |
| 34 | 45 |
| 35 /** | 46 /** |
| 36 * Active filter query text. | 47 * Active filter query text. |
| 37 * @type {RegExp} | 48 * @type {RegExp} |
| 38 * @private | 49 * @private |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 this.getElement().classList.toggle('stale', this.destination_.isOffline); | 175 this.getElement().classList.toggle('stale', this.destination_.isOffline); |
| 165 var offlineStatusEl = this.getChildElement('.offline-status'); | 176 var offlineStatusEl = this.getChildElement('.offline-status'); |
| 166 offlineStatusEl.textContent = this.destination_.offlineStatusText; | 177 offlineStatusEl.textContent = this.destination_.offlineStatusText; |
| 167 setIsVisible(offlineStatusEl, this.destination_.isOffline); | 178 setIsVisible(offlineStatusEl, this.destination_.isOffline); |
| 168 | 179 |
| 169 // Initialize registration promo element for Privet unregistered printers. | 180 // Initialize registration promo element for Privet unregistered printers. |
| 170 setIsVisible( | 181 setIsVisible( |
| 171 this.getChildElement('.register-promo'), | 182 this.getChildElement('.register-promo'), |
| 172 this.destination_.connectionStatus == | 183 this.destination_.connectionStatus == |
| 173 print_preview.Destination.ConnectionStatus.UNREGISTERED); | 184 print_preview.Destination.ConnectionStatus.UNREGISTERED); |
| 185 | |
| 186 // Reset the configuring messages for CUPS printers. | |
| 187 setIsVisible( | |
| 188 this.getChildElement('.configuring-in-progress-text'), false); | |
| 189 setIsVisible( | |
| 190 this.getChildElement('.configuring-failed-text'), false); | |
| 174 }, | 191 }, |
| 175 | 192 |
| 176 /** | 193 /** |
| 177 * Adds text to parent element wrapping search query matches in highlighted | 194 * Adds text to parent element wrapping search query matches in highlighted |
| 178 * spans. | 195 * spans. |
| 179 * @param {!Element} parent Element to build the text in. | 196 * @param {!Element} parent Element to build the text in. |
| 180 * @param {string} text The text string to highlight segments in. | 197 * @param {string} text The text string to highlight segments in. |
| 181 * @private | 198 * @private |
| 182 */ | 199 */ |
| 183 addTextWithHighlight_: function(parent, text) { | 200 addTextWithHighlight_: function(parent, text) { |
| 184 var sections = text.split(this.query_); | 201 var sections = text.split(this.query_); |
| 185 for (var i = 0; i < sections.length; ++i) { | 202 for (var i = 0; i < sections.length; ++i) { |
| 186 if (i % 2 == 0) { | 203 if (i % 2 == 0) { |
| 187 parent.appendChild(document.createTextNode(sections[i])); | 204 parent.appendChild(document.createTextNode(sections[i])); |
| 188 } else { | 205 } else { |
| 189 var span = document.createElement('span'); | 206 var span = document.createElement('span'); |
| 190 span.className = 'destination-list-item-query-highlight'; | 207 span.className = 'destination-list-item-query-highlight'; |
| 191 span.textContent = sections[i]; | 208 span.textContent = sections[i]; |
| 192 parent.appendChild(span); | 209 parent.appendChild(span); |
| 193 } | 210 } |
| 194 } | 211 } |
| 195 }, | 212 }, |
| 196 | 213 |
| 197 /** | 214 /** |
| 198 * Called when the destination item is activated. Dispatches a SELECT event | 215 * Called when the destination item is activated. Resolve the destination |
| 199 * on the given event target. | 216 * first if necessary (i.e., the printer needs to be setup on Chrome OS). |
| 200 * @private | 217 * @private |
| 201 */ | 218 */ |
| 202 onActivate_: function() { | 219 onActivate_: function() { |
| 220 if (this.destination_.origin == print_preview.Destination.Origin.CROS && | |
| 221 !this.destination_.capabilities) { | |
| 222 setIsVisible( | |
| 223 this.getChildElement('.configuring-in-progress-text'), true); | |
| 224 setIsVisible( | |
| 225 this.getChildElement('.configuring-failed-text'), false); | |
| 226 | |
| 227 this.destinationStore_.resolveCrosDestination(this.destination_).then( | |
| 228 /** | |
| 229 * Called when the Promise is fulfilled. | |
| 230 * @param {!print_preview.PrinterSetupResponse} response. | |
| 231 */ | |
| 232 function(response) { | |
| 233 if (response.success) { | |
| 234 setIsVisible( | |
| 235 this.getChildElement('.configuring-in-progress-text'), false); | |
| 236 this.destination_.capabilities = response.capabilities; | |
| 237 this.onDestinationResolved_(); | |
|
skau
2017/03/20 22:16:01
This component is not designed to have this called
| |
| 238 } else { | |
| 239 this.onResolveDestinationFailed_(); | |
| 240 } | |
| 241 }.bind(this), | |
| 242 /** | |
| 243 * Called when the Promise is rejected. | |
| 244 */ | |
| 245 this.onResolveDestinationFailed_.bind(this)); | |
| 246 } else { | |
| 247 this.onDestinationResolved_(); | |
| 248 } | |
| 249 }, | |
| 250 | |
| 251 /** | |
| 252 * Called when the destination has been resolved successfully. Dispatches a | |
| 253 * SELECT event on the given event target. | |
| 254 * @private | |
| 255 */ | |
| 256 onDestinationResolved_: function() { | |
| 203 if (this.destination_.id == | 257 if (this.destination_.id == |
| 204 print_preview.Destination.GooglePromotedId.FEDEX && | 258 print_preview.Destination.GooglePromotedId.FEDEX && |
| 205 !this.destination_.isTosAccepted) { | 259 !this.destination_.isTosAccepted) { |
| 206 if (!this.fedexTos_) { | 260 if (!this.fedexTos_) { |
| 207 this.fedexTos_ = new print_preview.FedexTos(); | 261 this.fedexTos_ = new print_preview.FedexTos(); |
| 208 this.fedexTos_.render(this.getElement()); | 262 this.fedexTos_.render(this.getElement()); |
| 209 this.tracker.add( | 263 this.tracker.add( |
| 210 this.fedexTos_, | 264 this.fedexTos_, |
| 211 print_preview.FedexTos.EventType.AGREE, | 265 print_preview.FedexTos.EventType.AGREE, |
| 212 this.onTosAgree_.bind(this)); | 266 this.onTosAgree_.bind(this)); |
| 213 } | 267 } |
| 214 this.fedexTos_.setIsVisible(true); | 268 this.fedexTos_.setIsVisible(true); |
| 215 } else if (this.destination_.connectionStatus != | 269 } else if (this.destination_.connectionStatus != |
| 216 print_preview.Destination.ConnectionStatus.UNREGISTERED) { | 270 print_preview.Destination.ConnectionStatus.UNREGISTERED) { |
| 217 var selectEvt = new Event(DestinationListItem.EventType.SELECT); | 271 var selectEvt = new Event(DestinationListItem.EventType.SELECT); |
| 218 selectEvt.destination = this.destination_; | 272 selectEvt.destination = this.destination_; |
| 219 this.eventTarget_.dispatchEvent(selectEvt); | 273 this.eventTarget_.dispatchEvent(selectEvt); |
| 220 } | 274 } |
| 221 }, | 275 }, |
| 222 | 276 |
| 223 /** | 277 /** |
| 278 * Called when the destination resolve was failed. | |
| 279 * @private | |
| 280 */ | |
| 281 onResolveDestinationFailed_: function() { | |
| 282 setIsVisible( | |
| 283 this.getChildElement('.configuring-in-progress-text'), false); | |
| 284 setIsVisible( | |
| 285 this.getChildElement('.configuring-failed-text'), true); | |
| 286 }, | |
| 287 | |
| 288 /** | |
| 224 * Called when the key is pressed on the destination item. Dispatches a | 289 * Called when the key is pressed on the destination item. Dispatches a |
| 225 * SELECT event when Enter is pressed. | 290 * SELECT event when Enter is pressed. |
| 226 * @param {KeyboardEvent} e Keyboard event to process. | 291 * @param {KeyboardEvent} e Keyboard event to process. |
| 227 * @private | 292 * @private |
| 228 */ | 293 */ |
| 229 onKeyDown_: function(e) { | 294 onKeyDown_: function(e) { |
| 230 if (!hasKeyModifiers(e)) { | 295 if (!hasKeyModifiers(e)) { |
| 231 if (e.keyCode == 13) { | 296 if (e.keyCode == 13) { |
| 232 var activeElementTag = document.activeElement ? | 297 var activeElementTag = document.activeElement ? |
| 233 document.activeElement.tagName.toUpperCase() : ''; | 298 document.activeElement.tagName.toUpperCase() : ''; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 return; | 352 return; |
| 288 this.onExtensionIconClicked_(event); | 353 this.onExtensionIconClicked_(event); |
| 289 } | 354 } |
| 290 }; | 355 }; |
| 291 | 356 |
| 292 // Export | 357 // Export |
| 293 return { | 358 return { |
| 294 DestinationListItem: DestinationListItem | 359 DestinationListItem: DestinationListItem |
| 295 }; | 360 }; |
| 296 }); | 361 }); |
| OLD | NEW |