| 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 * UI component that renders checkboxes for various print options. | 9 * UI component that renders checkboxes for various print options. |
| 10 * @param {!print_preview.ticket_items.Duplex} duplex Duplex ticket item. | 10 * @param {!print_preview.ticket_items.Duplex} duplex Duplex ticket item. |
| 11 * @param {!print_preview.ticket_items.FitToPage} fitToPage Fit-to-page ticket | 11 * @param {!print_preview.ticket_items.FitToPage} fitToPage Fit-to-page ticket |
| 12 * item. | 12 * item. |
| 13 * @param {!print_preview.ticket_items.CssBackground} cssBackground CSS | 13 * @param {!print_preview.ticket_items.CssBackground} cssBackground CSS |
| 14 * background ticket item. | 14 * background ticket item. |
| 15 * @param {!print_preview.ticket_items.SelectionOnly} selectionOnly Selection | 15 * @param {!print_preview.ticket_items.SelectionOnly} selectionOnly Selection |
| 16 * only ticket item. | 16 * only ticket item. |
| 17 * @param {!print_preview.ticket_items.HeaderFooter} headerFooter Header | 17 * @param {!print_preview.ticket_items.HeaderFooter} headerFooter Header |
| 18 * footer ticket item. | 18 * footer ticket item. |
| 19 * @param {!print_preview.ticket_items.PrintFriendly} printFriendly Print |
| 20 * friendly ticket item. |
| 19 * @constructor | 21 * @constructor |
| 20 * @extends {print_preview.SettingsSection} | 22 * @extends {print_preview.SettingsSection} |
| 21 */ | 23 */ |
| 22 function OtherOptionsSettings( | 24 function OtherOptionsSettings( |
| 23 duplex, fitToPage, cssBackground, selectionOnly, headerFooter) { | 25 duplex, fitToPage, cssBackground, selectionOnly, |
| 26 headerFooter, printFriendly) { |
| 24 print_preview.SettingsSection.call(this); | 27 print_preview.SettingsSection.call(this); |
| 25 | 28 |
| 26 /** | 29 /** |
| 27 * Duplex ticket item, used to read/write the duplex selection. | 30 * Duplex ticket item, used to read/write the duplex selection. |
| 28 * @type {!print_preview.ticket_items.Duplex} | 31 * @type {!print_preview.ticket_items.Duplex} |
| 29 * @private | 32 * @private |
| 30 */ | 33 */ |
| 31 this.duplexTicketItem_ = duplex; | 34 this.duplexTicketItem_ = duplex; |
| 32 | 35 |
| 33 /** | 36 /** |
| (...skipping 18 matching lines...) Expand all Loading... |
| 52 this.selectionOnlyTicketItem_ = selectionOnly; | 55 this.selectionOnlyTicketItem_ = selectionOnly; |
| 53 | 56 |
| 54 /** | 57 /** |
| 55 * Header-footer ticket item, used to read/write. | 58 * Header-footer ticket item, used to read/write. |
| 56 * @type {!print_preview.ticket_items.HeaderFooter} | 59 * @type {!print_preview.ticket_items.HeaderFooter} |
| 57 * @private | 60 * @private |
| 58 */ | 61 */ |
| 59 this.headerFooterTicketItem_ = headerFooter; | 62 this.headerFooterTicketItem_ = headerFooter; |
| 60 | 63 |
| 61 /** | 64 /** |
| 65 * Print friendly ticket item, used to read/write. |
| 66 * @type {!print_preview.ticket_items.PrintFriendly} |
| 67 * @private |
| 68 */ |
| 69 this.printFriendlyTicketItem_ = printFriendly; |
| 70 |
| 71 /** |
| 72 * Print friendly container element. |
| 73 * @type {HTMLElement} |
| 74 * @private |
| 75 */ |
| 76 this.printFriendlyContainer_ = null; |
| 77 |
| 78 /** |
| 79 * Print friendly checkbox. |
| 80 * @type {HTMLInputElement} |
| 81 * @private |
| 82 */ |
| 83 this.printFriendlyCheckbox_ = null; |
| 84 |
| 85 /** |
| 62 * Header footer container element. | 86 * Header footer container element. |
| 63 * @type {HTMLElement} | 87 * @type {HTMLElement} |
| 64 * @private | 88 * @private |
| 65 */ | 89 */ |
| 66 this.headerFooterContainer_ = null; | 90 this.headerFooterContainer_ = null; |
| 67 | 91 |
| 68 /** | 92 /** |
| 69 * Header footer checkbox. | 93 * Header footer checkbox. |
| 70 * @type {HTMLInputElement} | 94 * @type {HTMLInputElement} |
| 71 * @private | 95 * @private |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 * @private | 151 * @private |
| 128 */ | 152 */ |
| 129 this.selectionOnlyCheckbox_ = null; | 153 this.selectionOnlyCheckbox_ = null; |
| 130 }; | 154 }; |
| 131 | 155 |
| 132 OtherOptionsSettings.prototype = { | 156 OtherOptionsSettings.prototype = { |
| 133 __proto__: print_preview.SettingsSection.prototype, | 157 __proto__: print_preview.SettingsSection.prototype, |
| 134 | 158 |
| 135 /** @override */ | 159 /** @override */ |
| 136 isAvailable: function() { | 160 isAvailable: function() { |
| 137 return this.headerFooterTicketItem_.isCapabilityAvailable() || | 161 return this.printFriendlyTicketItem_.isCapabilityAvailable() || |
| 162 this.headerFooterTicketItem_.isCapabilityAvailable() || |
| 138 this.fitToPageTicketItem_.isCapabilityAvailable() || | 163 this.fitToPageTicketItem_.isCapabilityAvailable() || |
| 139 this.duplexTicketItem_.isCapabilityAvailable() || | 164 this.duplexTicketItem_.isCapabilityAvailable() || |
| 140 this.cssBackgroundTicketItem_.isCapabilityAvailable() || | 165 this.cssBackgroundTicketItem_.isCapabilityAvailable() || |
| 141 this.selectionOnlyTicketItem_.isCapabilityAvailable(); | 166 this.selectionOnlyTicketItem_.isCapabilityAvailable(); |
| 142 }, | 167 }, |
| 143 | 168 |
| 144 /** @override */ | 169 /** @override */ |
| 145 hasCollapsibleContent: function() { | 170 hasCollapsibleContent: function() { |
| 146 return this.headerFooterTicketItem_.isCapabilityAvailable() || | 171 return this.headerFooterTicketItem_.isCapabilityAvailable() || |
| 147 this.fitToPageTicketItem_.isCapabilityAvailable() || | 172 this.fitToPageTicketItem_.isCapabilityAvailable() || |
| 148 this.cssBackgroundTicketItem_.isCapabilityAvailable() || | 173 this.cssBackgroundTicketItem_.isCapabilityAvailable() || |
| 149 this.selectionOnlyTicketItem_.isCapabilityAvailable(); | 174 this.selectionOnlyTicketItem_.isCapabilityAvailable(); |
| 150 }, | 175 }, |
| 151 | 176 |
| 152 /** @override */ | 177 /** @override */ |
| 153 set isEnabled(isEnabled) { | 178 set isEnabled(isEnabled) { |
| 154 this.headerFooterCheckbox_.disabled = !isEnabled; | 179 this.headerFooterCheckbox_.disabled = !isEnabled; |
| 155 this.fitToPageCheckbox_.disabled = !isEnabled; | 180 this.fitToPageCheckbox_.disabled = !isEnabled; |
| 156 this.duplexCheckbox_.disabled = !isEnabled; | 181 this.duplexCheckbox_.disabled = !isEnabled; |
| 182 this.printFriendlyCheckbox_.disabled = !isEnabled; |
| 157 this.cssBackgroundCheckbox_.disabled = !isEnabled; | 183 this.cssBackgroundCheckbox_.disabled = !isEnabled; |
| 158 }, | 184 }, |
| 159 | 185 |
| 160 /** @override */ | 186 /** @override */ |
| 161 enterDocument: function() { | 187 enterDocument: function() { |
| 162 print_preview.SettingsSection.prototype.enterDocument.call(this); | 188 print_preview.SettingsSection.prototype.enterDocument.call(this); |
| 163 this.tracker.add( | 189 this.tracker.add( |
| 190 this.printFriendlyCheckbox_, |
| 191 'click', |
| 192 this.onPrintFriendlyCheckboxClick_.bind(this)); |
| 193 this.tracker.add( |
| 164 this.headerFooterCheckbox_, | 194 this.headerFooterCheckbox_, |
| 165 'click', | 195 'click', |
| 166 this.onHeaderFooterCheckboxClick_.bind(this)); | 196 this.onHeaderFooterCheckboxClick_.bind(this)); |
| 167 this.tracker.add( | 197 this.tracker.add( |
| 168 this.fitToPageCheckbox_, | 198 this.fitToPageCheckbox_, |
| 169 'click', | 199 'click', |
| 170 this.onFitToPageCheckboxClick_.bind(this)); | 200 this.onFitToPageCheckboxClick_.bind(this)); |
| 171 this.tracker.add( | 201 this.tracker.add( |
| 172 this.duplexCheckbox_, | 202 this.duplexCheckbox_, |
| 173 'click', | 203 'click', |
| (...skipping 19 matching lines...) Expand all Loading... |
| 193 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 223 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 194 this.onCssBackgroundChange_.bind(this)); | 224 this.onCssBackgroundChange_.bind(this)); |
| 195 this.tracker.add( | 225 this.tracker.add( |
| 196 this.selectionOnlyTicketItem_, | 226 this.selectionOnlyTicketItem_, |
| 197 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 227 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 198 this.onSelectionOnlyChange_.bind(this)); | 228 this.onSelectionOnlyChange_.bind(this)); |
| 199 this.tracker.add( | 229 this.tracker.add( |
| 200 this.headerFooterTicketItem_, | 230 this.headerFooterTicketItem_, |
| 201 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 231 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 202 this.onHeaderFooterChange_.bind(this)); | 232 this.onHeaderFooterChange_.bind(this)); |
| 233 this.tracker.add( |
| 234 this.printFriendlyTicketItem_, |
| 235 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 236 this.onPrintFriendlyChange_.bind(this)); |
| 203 }, | 237 }, |
| 204 | 238 |
| 205 /** @override */ | 239 /** @override */ |
| 206 exitDocument: function() { | 240 exitDocument: function() { |
| 207 print_preview.SettingsSection.prototype.exitDocument.call(this); | 241 print_preview.SettingsSection.prototype.exitDocument.call(this); |
| 242 this.printFriendlyContainer_ = null; |
| 243 this.printFriendlyCheckbox_ = null; |
| 208 this.headerFooterContainer_ = null; | 244 this.headerFooterContainer_ = null; |
| 209 this.headerFooterCheckbox_ = null; | 245 this.headerFooterCheckbox_ = null; |
| 210 this.fitToPageContainer_ = null; | 246 this.fitToPageContainer_ = null; |
| 211 this.fitToPageCheckbox_ = null; | 247 this.fitToPageCheckbox_ = null; |
| 212 this.duplexContainer_ = null; | 248 this.duplexContainer_ = null; |
| 213 this.duplexCheckbox_ = null; | 249 this.duplexCheckbox_ = null; |
| 214 this.cssBackgroundContainer_ = null; | 250 this.cssBackgroundContainer_ = null; |
| 215 this.cssBackgroundCheckbox_ = null; | 251 this.cssBackgroundCheckbox_ = null; |
| 216 this.selectionOnlyContainer_ = null; | 252 this.selectionOnlyContainer_ = null; |
| 217 this.selectionOnlyCheckbox_ = null; | 253 this.selectionOnlyCheckbox_ = null; |
| 218 }, | 254 }, |
| 219 | 255 |
| 220 /** @override */ | 256 /** @override */ |
| 221 decorateInternal: function() { | 257 decorateInternal: function() { |
| 258 this.printFriendlyContainer_ = this.getElement().querySelector( |
| 259 '.print-friendly-container'); |
| 260 this.printFriendlyCheckbox_ = this.printFriendlyContainer_.querySelector( |
| 261 '.print-friendly-checkbox'); |
| 222 this.headerFooterContainer_ = this.getElement().querySelector( | 262 this.headerFooterContainer_ = this.getElement().querySelector( |
| 223 '.header-footer-container'); | 263 '.header-footer-container'); |
| 224 this.headerFooterCheckbox_ = this.headerFooterContainer_.querySelector( | 264 this.headerFooterCheckbox_ = this.headerFooterContainer_.querySelector( |
| 225 '.header-footer-checkbox'); | 265 '.header-footer-checkbox'); |
| 226 this.fitToPageContainer_ = this.getElement().querySelector( | 266 this.fitToPageContainer_ = this.getElement().querySelector( |
| 227 '.fit-to-page-container'); | 267 '.fit-to-page-container'); |
| 228 this.fitToPageCheckbox_ = this.fitToPageContainer_.querySelector( | 268 this.fitToPageCheckbox_ = this.fitToPageContainer_.querySelector( |
| 229 '.fit-to-page-checkbox'); | 269 '.fit-to-page-checkbox'); |
| 230 this.duplexContainer_ = this.getElement().querySelector( | 270 this.duplexContainer_ = this.getElement().querySelector( |
| 231 '.duplex-container'); | 271 '.duplex-container'); |
| 232 this.duplexCheckbox_ = this.duplexContainer_.querySelector( | 272 this.duplexCheckbox_ = this.duplexContainer_.querySelector( |
| 233 '.duplex-checkbox'); | 273 '.duplex-checkbox'); |
| 234 this.cssBackgroundContainer_ = this.getElement().querySelector( | 274 this.cssBackgroundContainer_ = this.getElement().querySelector( |
| 235 '.css-background-container'); | 275 '.css-background-container'); |
| 236 this.cssBackgroundCheckbox_ = this.cssBackgroundContainer_.querySelector( | 276 this.cssBackgroundCheckbox_ = this.cssBackgroundContainer_.querySelector( |
| 237 '.css-background-checkbox'); | 277 '.css-background-checkbox'); |
| 238 this.selectionOnlyContainer_ = this.getElement().querySelector( | 278 this.selectionOnlyContainer_ = this.getElement().querySelector( |
| 239 '.selection-only-container'); | 279 '.selection-only-container'); |
| 240 this.selectionOnlyCheckbox_ = this.selectionOnlyContainer_.querySelector( | 280 this.selectionOnlyCheckbox_ = this.selectionOnlyContainer_.querySelector( |
| 241 '.selection-only-checkbox'); | 281 '.selection-only-checkbox'); |
| 242 }, | 282 }, |
| 243 | 283 |
| 244 /** @override */ | 284 /** @override */ |
| 245 updateUiStateInternal: function() { | 285 updateUiStateInternal: function() { |
| 246 if (this.isAvailable()) { | 286 if (this.isAvailable()) { |
| 287 setIsVisible(this.printFriendlyContainer_, |
| 288 this.printFriendlyTicketItem_.isCapabilityAvailable()); |
| 247 setIsVisible(this.headerFooterContainer_, | 289 setIsVisible(this.headerFooterContainer_, |
| 248 this.headerFooterTicketItem_.isCapabilityAvailable() && | 290 this.headerFooterTicketItem_.isCapabilityAvailable() && |
| 249 !this.collapseContent); | 291 !this.collapseContent); |
| 250 setIsVisible(this.fitToPageContainer_, | 292 setIsVisible(this.fitToPageContainer_, |
| 251 this.fitToPageTicketItem_.isCapabilityAvailable() && | 293 this.fitToPageTicketItem_.isCapabilityAvailable() && |
| 252 !this.collapseContent); | 294 !this.collapseContent); |
| 253 setIsVisible(this.duplexContainer_, | 295 setIsVisible(this.duplexContainer_, |
| 254 this.duplexTicketItem_.isCapabilityAvailable()); | 296 this.duplexTicketItem_.isCapabilityAvailable()); |
| 255 setIsVisible(this.cssBackgroundContainer_, | 297 setIsVisible(this.cssBackgroundContainer_, |
| 256 this.cssBackgroundTicketItem_.isCapabilityAvailable() && | 298 this.cssBackgroundTicketItem_.isCapabilityAvailable() && |
| 257 !this.collapseContent); | 299 !this.collapseContent); |
| 258 setIsVisible(this.selectionOnlyContainer_, | 300 setIsVisible(this.selectionOnlyContainer_, |
| 259 this.selectionOnlyTicketItem_.isCapabilityAvailable() && | 301 this.selectionOnlyTicketItem_.isCapabilityAvailable() && |
| 260 !this.collapseContent); | 302 !this.collapseContent); |
| 261 } | 303 } |
| 262 print_preview.SettingsSection.prototype.updateUiStateInternal.call(this); | 304 print_preview.SettingsSection.prototype.updateUiStateInternal.call(this); |
| 263 }, | 305 }, |
| 264 | 306 |
| 265 /** @override */ | 307 /** @override */ |
| 266 isSectionVisibleInternal: function() { | 308 isSectionVisibleInternal: function() { |
| 267 return this.collapseContent ? | 309 return this.collapseContent ? |
| 310 this.printFriendlyTicketItem_.isCapabilityAvailable() || |
| 268 this.duplexTicketItem_.isCapabilityAvailable() : this.isAvailable(); | 311 this.duplexTicketItem_.isCapabilityAvailable() : this.isAvailable(); |
| 269 }, | 312 }, |
| 270 | 313 |
| 271 /** | 314 /** |
| 315 * Called when the print-friendly checkbox is clicked. Updates the print |
| 316 * ticket. |
| 317 * @private |
| 318 */ |
| 319 onPrintFriendlyCheckboxClick_: function() { |
| 320 this.printFriendlyTicketItem_.updateValue( |
| 321 this.printFriendlyCheckbox_.checked); |
| 322 }, |
| 323 |
| 324 /** |
| 272 * Called when the header-footer checkbox is clicked. Updates the print | 325 * Called when the header-footer checkbox is clicked. Updates the print |
| 273 * ticket. | 326 * ticket. |
| 274 * @private | 327 * @private |
| 275 */ | 328 */ |
| 276 onHeaderFooterCheckboxClick_: function() { | 329 onHeaderFooterCheckboxClick_: function() { |
| 277 this.headerFooterTicketItem_.updateValue( | 330 this.headerFooterTicketItem_.updateValue( |
| 278 this.headerFooterCheckbox_.checked); | 331 this.headerFooterCheckbox_.checked); |
| 279 }, | 332 }, |
| 280 | 333 |
| 281 /** | 334 /** |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 412 |
| 360 /** | 413 /** |
| 361 * Called when the header-footer ticket item has changed. Updates the | 414 * Called when the header-footer ticket item has changed. Updates the |
| 362 * header-footer checkbox. | 415 * header-footer checkbox. |
| 363 * @private | 416 * @private |
| 364 */ | 417 */ |
| 365 onHeaderFooterChange_: function() { | 418 onHeaderFooterChange_: function() { |
| 366 this.headerFooterCheckbox_.checked = | 419 this.headerFooterCheckbox_.checked = |
| 367 this.headerFooterTicketItem_.getValue(); | 420 this.headerFooterTicketItem_.getValue(); |
| 368 this.updateUiStateInternal(); | 421 this.updateUiStateInternal(); |
| 422 }, |
| 423 |
| 424 /** |
| 425 * Called when the print-friendly ticket item has changed. Updates the |
| 426 * print-friendly checkbox. |
| 427 * @private |
| 428 */ |
| 429 onPrintFriendlyChange_: function() { |
| 430 this.printFriendlyCheckbox_.checked = |
| 431 this.printFriendlyTicketItem_.getValue(); |
| 432 this.updateUiStateInternal(); |
| 369 } | 433 } |
| 370 }; | 434 }; |
| 371 | 435 |
| 372 // Export | 436 // Export |
| 373 return { | 437 return { |
| 374 OtherOptionsSettings: OtherOptionsSettings | 438 OtherOptionsSettings: OtherOptionsSettings |
| 375 }; | 439 }; |
| 376 }); | 440 }); |
| OLD | NEW |