Chromium Code Reviews| 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 var localStrings = new LocalStrings(); | 5 var localStrings = new LocalStrings(); |
| 6 | 6 |
| 7 // The total page count of the previewed document regardless of which pages the | 7 // The total page count of the previewed document regardless of which pages the |
| 8 // user has selected. | 8 // user has selected. |
| 9 var totalPageCount = -1; | 9 var totalPageCount = -1; |
| 10 | 10 |
| 11 // The previously selected pages by the user. It is used in | 11 // The previously selected pages by the user. It is used in |
| 12 // onPageSelectionMayHaveChanged() to make sure that a new preview is not | 12 // onPageSelectionMayHaveChanged() to make sure that a new preview is not |
| 13 // requested more often than necessary. | 13 // requested more often than necessary. |
| 14 var previouslySelectedPages = []; | 14 var previouslySelectedPages = []; |
| 15 | 15 |
| 16 // The previously selected layout mode. It is used in order to prevent the | |
| 17 // preview from updating when the user clicks on the already selected layout | |
| 18 // mode. | |
| 19 var previouslySelectedLayout = null; | |
| 20 | |
| 21 // Timer id of the page range textfield. It is used to reset the timer whenever | 16 // Timer id of the page range textfield. It is used to reset the timer whenever |
| 22 // needed. | 17 // needed. |
| 23 var timerId; | 18 var timerId; |
| 24 | 19 |
| 25 // Store the last selected printer index. | 20 // Store the last selected printer index. |
| 26 var lastSelectedPrinterIndex = 0; | 21 var lastSelectedPrinterIndex = 0; |
| 27 | 22 |
| 28 // Indicates whether a preview has been requested but not received yet. | |
| 29 var isPreviewStillLoading = true; | |
| 30 | |
| 31 // Currently selected printer capabilities. | |
| 32 var printerCapabilities; | |
| 33 | |
| 34 // Used to disable some printing options when the preview is not modifiable. | 23 // Used to disable some printing options when the preview is not modifiable. |
| 35 var previewModifiable = false; | 24 var previewModifiable = false; |
| 36 | 25 |
| 37 // Destination list special value constants. | 26 // Destination list special value constants. |
| 38 const PRINT_TO_PDF = 'Print To PDF'; | 27 const PRINT_TO_PDF = 'Print To PDF'; |
| 39 const MANAGE_PRINTERS = 'Manage Printers'; | 28 const MANAGE_PRINTERS = 'Manage Printers'; |
| 40 | 29 |
| 30 // State of the print preview settings. | |
| 31 var printSettings = new PrintSettings(); | |
| 32 | |
| 41 /** | 33 /** |
| 42 * Window onload handler, sets up the page and starts print preview by getting | 34 * Window onload handler, sets up the page and starts print preview by getting |
| 43 * the printer list. | 35 * the printer list. |
| 44 */ | 36 */ |
| 45 function onLoad() { | 37 function onLoad() { |
| 46 $('system-dialog-link').addEventListener('click', showSystemDialog); | 38 $('system-dialog-link').addEventListener('click', showSystemDialog); |
| 47 $('cancel-button').addEventListener('click', handleCancelButtonClick); | 39 $('cancel-button').addEventListener('click', handleCancelButtonClick); |
| 48 | 40 |
| 49 if (!checkCompatiblePluginExists()) { | 41 if (!checkCompatiblePluginExists()) { |
| 50 displayErrorMessage(localStrings.getString('noPlugin'), false); | 42 displayErrorMessage(localStrings.getString('noPlugin'), false); |
| 51 $('mainview').parentElement.removeChild($('dummy-viewer')); | 43 $('mainview').parentElement.removeChild($('dummy-viewer')); |
| 52 return; | 44 return; |
| 53 } | 45 } |
| 54 $('mainview').parentElement.removeChild($('dummy-viewer')); | 46 $('mainview').parentElement.removeChild($('dummy-viewer')); |
| 55 | 47 |
| 56 $('printer-list').disabled = true; | 48 $('printer-list').disabled = true; |
| 57 $('print-button').disabled = true; | 49 $('print-button').disabled = true; |
| 58 $('print-button').addEventListener('click', printFile); | |
| 59 $('all-pages').addEventListener('click', onPageSelectionMayHaveChanged); | |
| 60 $('copies').addEventListener('input', copiesFieldChanged); | |
| 61 $('print-pages').addEventListener('click', handleIndividualPagesCheckbox); | |
| 62 $('individual-pages').addEventListener('blur', function() { | |
| 63 clearTimeout(timerId); | |
| 64 onPageSelectionMayHaveChanged(); | |
| 65 }); | |
| 66 $('individual-pages').addEventListener('focus', addTimerToPageRangeField); | |
| 67 $('individual-pages').addEventListener('input', resetPageRangeFieldTimer); | |
| 68 $('two-sided').addEventListener('click', handleTwoSidedClick) | |
| 69 $('landscape').addEventListener('click', onLayoutModeToggle); | |
| 70 $('portrait').addEventListener('click', onLayoutModeToggle); | |
| 71 $('color').addEventListener('click', function() { setColor(true); }); | |
| 72 $('bw').addEventListener('click', function() { setColor(false); }); | |
| 73 $('printer-list').addEventListener( | |
| 74 'change', updateControlsWithSelectedPrinterCapabilities); | |
| 75 $('increment').addEventListener('click', | |
| 76 function() { onCopiesButtonsClicked(1); }); | |
| 77 $('decrement').addEventListener('click', | |
| 78 function() { onCopiesButtonsClicked(-1); }); | |
| 79 $('controls').onsubmit = function() { return false; }; | 50 $('controls').onsubmit = function() { return false; }; |
| 80 $('dancing-dots').classList.remove('invisible'); | 51 $('dancing-dots').classList.remove('invisible'); |
| 81 chrome.send('getPrinters'); | 52 chrome.send('getPrinters'); |
| 82 } | 53 } |
| 83 | 54 |
| 84 /** | 55 /** |
| 56 * Adds event listeners to the settings controls. | |
| 57 */ | |
| 58 function addEventListeners() { | |
| 59 $('print-button').onclick = printFile; | |
| 60 | |
| 61 // Controls that require preview rendering. | |
| 62 $('all-pages').onclick = onPageSelectionMayHaveChanged; | |
| 63 $('print-pages').onclick = handleIndividualPagesCheckbox; | |
| 64 var individualPages = $('individual-pages'); | |
| 65 individualPages.onblur = function() { | |
| 66 clearTimeout(timerId); | |
| 67 onPageSelectionMayHaveChanged(); | |
| 68 }; | |
| 69 individualPages.onfocus = addTimerToPageRangeField; | |
| 70 individualPages.oninput = resetPageRangeFieldTimer; | |
| 71 $('landscape').onclick = onLayoutModeToggle; | |
| 72 $('portrait').onclick = onLayoutModeToggle; | |
| 73 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | |
| 74 | |
| 75 // Controls that dont require preview rendering. | |
| 76 $('copies').oninput = function() { | |
| 77 copiesFieldChanged(); | |
| 78 updatePrintButtonState(); | |
| 79 updatePrintSummary(); | |
| 80 }; | |
| 81 $('two-sided').onclick = handleTwoSidedClick; | |
| 82 $('color').onclick = function() { setColor(true); }; | |
| 83 $('bw').onclick = function() { setColor(false); }; | |
| 84 $('increment').onclick = function() { | |
| 85 onCopiesButtonsClicked(1); | |
| 86 updatePrintButtonState(); | |
| 87 updatePrintSummary(); | |
| 88 }; | |
| 89 $('decrement').onclick = function() { | |
| 90 onCopiesButtonsClicked(-1); | |
| 91 updatePrintButtonState(); | |
| 92 updatePrintSummary(); | |
| 93 }; | |
| 94 } | |
| 95 | |
| 96 /** | |
| 97 * Removes event listeners from the settings controls. | |
| 98 */ | |
| 99 function removeEventListeners() { | |
| 100 // Controls that require preview rendering. | |
| 101 $('print-button').disabled = true; | |
| 102 $('all-pages').onclick = null; | |
| 103 $('print-pages').onclick = null; | |
| 104 var individualPages = $('individual-pages'); | |
| 105 individualPages.onblur = null; | |
| 106 individualPages.onfocus = null; | |
| 107 individualPages.oninput = null; | |
| 108 clearTimeout(timerId); | |
| 109 $('landscape').onclick = null; | |
| 110 $('portrait').onclick = null; | |
| 111 $('printer-list').onchange = null; | |
| 112 | |
| 113 // Controls that dont require preview rendering. | |
| 114 $('copies').oninput = copiesFieldChanged; | |
| 115 $('two-sided').onclick = null; | |
| 116 $('color').onclick = null; | |
| 117 $('bw').onclick = null; | |
| 118 $('increment').onclick = function() { onCopiesButtonsClicked(1); }; | |
| 119 $('decrement').onclick = function() { onCopiesButtonsClicked(-1); }; | |
| 120 } | |
| 121 | |
| 122 /** | |
| 85 * Asks the browser to close the preview tab. | 123 * Asks the browser to close the preview tab. |
| 86 */ | 124 */ |
| 87 function handleCancelButtonClick() { | 125 function handleCancelButtonClick() { |
| 88 chrome.send('closePrintPreviewTab'); | 126 chrome.send('closePrintPreviewTab'); |
| 89 } | 127 } |
| 90 | 128 |
| 91 /** | 129 /** |
| 92 * Asks the browser to show the native print dialog for printing. | 130 * Asks the browser to show the native print dialog for printing. |
| 93 */ | 131 */ |
| 94 function showSystemDialog() { | 132 function showSystemDialog() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 | 172 |
| 135 // Regenerate the preview data based on selected printer settings. | 173 // Regenerate the preview data based on selected printer settings. |
| 136 setDefaultValuesAndRegeneratePreview(); | 174 setDefaultValuesAndRegeneratePreview(); |
| 137 } | 175 } |
| 138 | 176 |
| 139 /** | 177 /** |
| 140 * Updates the controls with printer capabilities information. | 178 * Updates the controls with printer capabilities information. |
| 141 * @param {Object} settingInfo printer setting information. | 179 * @param {Object} settingInfo printer setting information. |
| 142 */ | 180 */ |
| 143 function updateWithPrinterCapabilities(settingInfo) { | 181 function updateWithPrinterCapabilities(settingInfo) { |
| 144 printerCapabilities = settingInfo; | |
| 145 | |
| 146 if (isPreviewStillLoading) | |
| 147 return; | |
| 148 | |
| 149 var disableColorOption = settingInfo.disableColorOption; | 182 var disableColorOption = settingInfo.disableColorOption; |
| 150 var setColorAsDefault = settingInfo.setColorAsDefault; | 183 var setColorAsDefault = settingInfo.setColorAsDefault; |
| 151 var colorOption = $('color'); | 184 var colorOption = $('color'); |
| 152 var bwOption = $('bw'); | 185 var bwOption = $('bw'); |
| 153 | 186 |
| 154 if (disableColorOption) | 187 if (disableColorOption) |
| 155 $('color-options').classList.add("hidden"); | 188 $('color-options').classList.add("hidden"); |
| 156 else | 189 else |
| 157 $('color-options').classList.remove("hidden"); | 190 $('color-options').classList.remove("hidden"); |
| 158 | 191 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 function isColor() { | 272 function isColor() { |
| 240 return $('color').checked; | 273 return $('color').checked; |
| 241 } | 274 } |
| 242 | 275 |
| 243 /** | 276 /** |
| 244 * Checks whether the preview collate setting value is set or not. | 277 * Checks whether the preview collate setting value is set or not. |
| 245 * | 278 * |
| 246 * @return {boolean} true if collate setting is enabled and checked. | 279 * @return {boolean} true if collate setting is enabled and checked. |
| 247 */ | 280 */ |
| 248 function isCollated() { | 281 function isCollated() { |
| 249 var collateField = $('collate'); | 282 return !$('collate-option').classList.contains('hidden') && |
| 250 return !collateField.disabled && collateField.checked; | 283 $('collate').checked; |
| 251 } | 284 } |
| 252 | 285 |
| 253 /** | 286 /** |
| 254 * Returns the number of copies currently indicated in the copies textfield. If | 287 * Returns the number of copies currently indicated in the copies textfield. If |
| 255 * the contents of the textfield can not be converted to a number or if <1 it | 288 * the contents of the textfield can not be converted to a number or if <1 it |
| 256 * returns 1. | 289 * returns 1. |
| 257 * | 290 * |
| 258 * @return {number} number of copies. | 291 * @return {number} number of copies. |
| 259 */ | 292 */ |
| 260 function getCopies() { | 293 function getCopies() { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 return deviceName; | 351 return deviceName; |
| 319 } | 352 } |
| 320 | 353 |
| 321 /** | 354 /** |
| 322 * Asks the browser to print the preview PDF based on current print settings. | 355 * Asks the browser to print the preview PDF based on current print settings. |
| 323 */ | 356 */ |
| 324 function printFile() { | 357 function printFile() { |
| 325 $('print-button').classList.add('loading'); | 358 $('print-button').classList.add('loading'); |
| 326 $('cancel-button').classList.add('loading'); | 359 $('cancel-button').classList.add('loading'); |
| 327 $('print-summary').innerHTML = localStrings.getString('printing'); | 360 $('print-summary').innerHTML = localStrings.getString('printing'); |
| 361 removeEventListeners(); | |
| 328 | 362 |
| 329 if (getSelectedPrinterName() != PRINT_TO_PDF) { | 363 if (getSelectedPrinterName() != PRINT_TO_PDF) { |
| 330 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); }, | 364 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); }, |
| 331 1000); | 365 1000); |
| 332 } else | 366 } else |
| 333 chrome.send('print', [getSettingsJSON()]); | 367 chrome.send('print', [getSettingsJSON()]); |
| 334 } | 368 } |
| 335 | 369 |
| 336 /** | 370 /** |
| 337 * Asks the browser to generate a preview PDF based on current print settings. | 371 * Asks the browser to generate a preview PDF based on current print settings. |
| 338 */ | 372 */ |
| 339 function requestPrintPreview() { | 373 function requestPrintPreview() { |
| 340 isPreviewStillLoading = true; | 374 removeEventListeners(); |
| 341 setControlsDisabled(true); | 375 printSettings.save(); |
| 342 $('dancing-dots').classList.remove('invisible'); | 376 $('dancing-dots').classList.remove('invisible'); |
| 343 chrome.send('getPreview', [getSettingsJSON()]); | 377 chrome.send('getPreview', [getSettingsJSON()]); |
| 344 } | 378 } |
| 345 | 379 |
| 346 /** | 380 /** |
| 347 * Fill the printer list drop down. | 381 * Fill the printer list drop down. |
| 348 * Called from PrintPreviewHandler::SendPrinterList(). | 382 * Called from PrintPreviewHandler::SendPrinterList(). |
| 349 * @param {Array} printers Array of printer info objects. | 383 * @param {Array} printers Array of printer info objects. |
| 350 * @param {number} defaultPrinterIndex The index of the default printer. | 384 * @param {number} defaultPrinterIndex The index of the default printer. |
| 351 */ | 385 */ |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 pdfViewer.grayscale(!color); | 436 pdfViewer.grayscale(!color); |
| 403 } | 437 } |
| 404 | 438 |
| 405 /** | 439 /** |
| 406 * Display an error message in the center of the preview area. | 440 * Display an error message in the center of the preview area. |
| 407 * @param {string} errorMessage The error message to be displayed. | 441 * @param {string} errorMessage The error message to be displayed. |
| 408 * @param {boolean} showButton Indivates whether the "Reopen the page" button | 442 * @param {boolean} showButton Indivates whether the "Reopen the page" button |
| 409 * should be displayed. | 443 * should be displayed. |
| 410 */ | 444 */ |
| 411 function displayErrorMessage(errorMessage, showButton) { | 445 function displayErrorMessage(errorMessage, showButton) { |
| 412 isPreviewStillLoading = false; | |
| 413 $('dancing-dots').classList.remove('invisible'); | 446 $('dancing-dots').classList.remove('invisible'); |
| 414 $('dancing-dots-text').classList.add('hidden'); | 447 $('dancing-dots-text').classList.add('hidden'); |
| 415 $('error-text').innerHTML = errorMessage; | 448 $('error-text').innerHTML = errorMessage; |
| 416 $('error-text').classList.remove('hidden'); | 449 $('error-text').classList.remove('hidden'); |
| 417 if (showButton) | 450 if (showButton) |
| 418 $('reopen-page').classList.remove('hidden'); | 451 $('reopen-page').classList.remove('hidden'); |
| 419 else | 452 else |
| 420 $('reopen-page').classList.add('hidden'); | 453 $('reopen-page').classList.add('hidden'); |
| 421 | 454 |
| 422 setControlsDisabled(true); | 455 setControlsDisabled(true); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 437 /** | 470 /** |
| 438 * Called when the PDF plugin loads its document. | 471 * Called when the PDF plugin loads its document. |
| 439 */ | 472 */ |
| 440 function onPDFLoad() { | 473 function onPDFLoad() { |
| 441 if (isLandscape()) | 474 if (isLandscape()) |
| 442 $('pdf-viewer').fitToWidth(); | 475 $('pdf-viewer').fitToWidth(); |
| 443 else | 476 else |
| 444 $('pdf-viewer').fitToHeight(); | 477 $('pdf-viewer').fitToHeight(); |
| 445 | 478 |
| 446 $('dancing-dots').classList.add('invisible'); | 479 $('dancing-dots').classList.add('invisible'); |
| 447 setControlsDisabled(false); | |
| 448 | 480 |
| 449 if (!previewModifiable) { | 481 if (!previewModifiable) { |
| 450 $('landscape').disabled = true; | 482 $('landscape').disabled = true; |
| 451 $('portrait').disabled = true; | 483 $('portrait').disabled = true; |
| 452 } | 484 } |
| 453 | 485 |
| 454 updateCopiesButtonsState(); | 486 updateCopiesButtonsState(); |
| 455 updateWithPrinterCapabilities(printerCapabilities); | |
| 456 } | 487 } |
| 457 | 488 |
| 458 /** | 489 /** |
| 459 * Update the print preview when new preview data is available. | 490 * Update the print preview when new preview data is available. |
| 460 * Create the PDF plugin as needed. | 491 * Create the PDF plugin as needed. |
| 461 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | 492 * Called from PrintPreviewUI::PreviewDataIsAvailable(). |
| 462 * @param {number} pageCount The expected total pages count. | 493 * @param {number} pageCount The expected total pages count. |
| 463 * @param {string} jobTitle The print job title. | 494 * @param {string} jobTitle The print job title. |
| 464 * @param {boolean} modifiable If the preview is modifiable. | 495 * @param {boolean} modifiable If the preview is modifiable. |
| 465 * | 496 * |
| 466 */ | 497 */ |
| 467 function updatePrintPreview(pageCount, jobTitle, modifiable) { | 498 function updatePrintPreview(pageCount, jobTitle, modifiable) { |
| 499 var tempPrintSettings = new PrintSettings(); | |
| 500 tempPrintSettings.save(); | |
| 501 | |
| 468 previewModifiable = modifiable; | 502 previewModifiable = modifiable; |
| 469 | 503 |
| 470 if (totalPageCount == -1) | 504 if (totalPageCount == -1) |
| 471 totalPageCount = pageCount; | 505 totalPageCount = pageCount; |
| 472 | 506 |
| 473 if (previouslySelectedPages.length == 0) | 507 if (previouslySelectedPages.length == 0) |
| 474 for (var i = 0; i < totalPageCount; i++) | 508 for (var i = 0; i < totalPageCount; i++) |
| 475 previouslySelectedPages.push(i+1); | 509 previouslySelectedPages.push(i+1); |
| 476 | 510 |
| 477 if (previouslySelectedLayout == null) | 511 if (printSettings.deviceName != tempPrintSettings.deviceName) { |
| 478 previouslySelectedLayout = $('portrait'); | 512 updateControlsWithSelectedPrinterCapabilities(); |
| 513 return; | |
| 514 } else if (printSettings.isLandscape != tempPrintSettings.isLandscape) { | |
| 515 setDefaultValuesAndRegeneratePreview(); | |
| 516 return; | |
| 517 } else if (getSelectedPagesValidityLevel() == 1) { | |
| 518 var currentlySelectedPages = getSelectedPagesSet(); | |
| 519 if (!areArraysEqual(previouslySelectedPages, currentlySelectedPages)) { | |
| 520 previouslySelectedPages = currentlySelectedPages; | |
| 521 requestPrintPreview(); | |
| 522 return; | |
| 523 } | |
| 524 } | |
| 525 | |
| 526 if (getSelectedPagesValidityLevel() != 1) | |
| 527 pageRangesFieldChanged(); | |
| 479 | 528 |
| 480 // Update the current tab title. | 529 // Update the current tab title. |
| 481 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); | 530 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); |
| 482 | 531 |
| 483 createPDFPlugin(); | 532 createPDFPlugin(); |
| 484 isPreviewStillLoading = false; | |
| 485 updatePrintSummary(); | 533 updatePrintSummary(); |
| 534 updatePrintButtonState(); | |
| 535 addEventListeners(); | |
| 486 } | 536 } |
| 487 | 537 |
| 488 /** | 538 /** |
| 489 * Create the PDF plugin or reload the existing one. | 539 * Create the PDF plugin or reload the existing one. |
| 490 */ | 540 */ |
| 491 function createPDFPlugin() { | 541 function createPDFPlugin() { |
| 492 // Enable the print button. | 542 // Enable the print button. |
| 493 if (!$('printer-list').disabled) { | 543 if (!$('printer-list').disabled) { |
| 494 $('print-button').disabled = false; | 544 $('print-button').disabled = false; |
| 495 } | 545 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 } | 595 } |
| 546 | 596 |
| 547 window.addEventListener('DOMContentLoaded', onLoad); | 597 window.addEventListener('DOMContentLoaded', onLoad); |
| 548 | 598 |
| 549 /** | 599 /** |
| 550 * Listener function that executes whenever a change occurs in the 'copies' | 600 * Listener function that executes whenever a change occurs in the 'copies' |
| 551 * field. | 601 * field. |
| 552 */ | 602 */ |
| 553 function copiesFieldChanged() { | 603 function copiesFieldChanged() { |
| 554 updateCopiesButtonsState(); | 604 updateCopiesButtonsState(); |
| 555 updatePrintButtonState(); | 605 // TODO: change the following if else to |
| 556 $('collate-option').hidden = getCopies() <= 1; | 606 // $('collate-option').hidden = getCopies() <= 1; |
| 557 updatePrintSummary(); | 607 // once the span[hidden] {display: none;} rule is applied correctly and also |
| 608 // update isCollated() function. Currently it is not reducing the size of the | |
| 609 // span to 0x0. | |
|
dpapad
2011/05/24 18:04:57
I left it as a span. Changing it into a div makes
| |
| 610 if (getCopies() <= 1) | |
| 611 $('collate-option').classList.add('hidden'); | |
| 612 else | |
| 613 $('collate-option').classList.remove('hidden'); | |
| 558 } | 614 } |
| 559 | 615 |
| 560 /** | 616 /** |
| 561 * Executes whenever a blur event occurs on the 'individual-pages' | 617 * Executes whenever a blur event occurs on the 'individual-pages' |
| 562 * field or when the timer expires. It takes care of | 618 * field or when the timer expires. It takes care of |
| 563 * 1) showing/hiding warnings/suggestions | 619 * 1) showing/hiding warnings/suggestions |
| 564 * 2) updating print button/summary | 620 * 2) updating print button/summary |
| 565 */ | 621 */ |
| 566 function pageRangesFieldChanged() { | 622 function pageRangesFieldChanged() { |
| 567 var currentlySelectedPages = getSelectedPagesSet(); | 623 var currentlySelectedPages = getSelectedPagesSet(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 $('individual-pages').focus(); | 741 $('individual-pages').focus(); |
| 686 } | 742 } |
| 687 | 743 |
| 688 /** | 744 /** |
| 689 * When the user switches printing orientation mode the page field selection is | 745 * When the user switches printing orientation mode the page field selection is |
| 690 * reset to "all pages selected". After the change the number of pages will be | 746 * reset to "all pages selected". After the change the number of pages will be |
| 691 * different and currently selected page numbers might no longer be valid. | 747 * different and currently selected page numbers might no longer be valid. |
| 692 * Even if they are still valid the content of these pages will be different. | 748 * Even if they are still valid the content of these pages will be different. |
| 693 */ | 749 */ |
| 694 function onLayoutModeToggle() { | 750 function onLayoutModeToggle() { |
| 695 var currentlySelectedLayout = $('portrait').checked ? $('portrait') : | |
| 696 $('landscape'); | |
| 697 | |
| 698 // If the chosen layout is same as before, nothing needs to be done. | 751 // If the chosen layout is same as before, nothing needs to be done. |
| 699 if (previouslySelectedLayout == currentlySelectedLayout) | 752 if (printSettings.isLandscape == isLandscape()) |
| 700 return; | 753 return; |
| 701 | 754 |
| 702 previouslySelectedLayout = currentlySelectedLayout; | |
| 703 $('individual-pages').classList.remove('invalid'); | 755 $('individual-pages').classList.remove('invalid'); |
| 704 setDefaultValuesAndRegeneratePreview(); | 756 setDefaultValuesAndRegeneratePreview(); |
| 705 } | 757 } |
| 706 | 758 |
| 707 /** | 759 /** |
| 708 * Sets the default values and sends a request to regenerate preview data. | 760 * Sets the default values and sends a request to regenerate preview data. |
| 709 */ | 761 */ |
| 710 function setDefaultValuesAndRegeneratePreview() { | 762 function setDefaultValuesAndRegeneratePreview() { |
| 711 $('individual-pages').value = ''; | |
| 712 hideInvalidHint($('individual-pages-hint')); | 763 hideInvalidHint($('individual-pages-hint')); |
| 713 $('all-pages').checked = true; | |
| 714 totalPageCount = -1; | 764 totalPageCount = -1; |
| 715 previouslySelectedPages.length = 0; | 765 previouslySelectedPages.length = 0; |
| 716 requestPrintPreview(); | 766 requestPrintPreview(); |
| 717 } | 767 } |
| 718 | 768 |
| 719 /** | 769 /** |
| 720 * Returns a list of all pages in the specified ranges. The pages are listed in | 770 * Returns a list of all pages in the specified ranges. The pages are listed in |
| 721 * the order they appear in the 'individual-pages' textbox and duplicates are | 771 * the order they appear in the 'individual-pages' textbox and duplicates are |
| 722 * not eliminated. If the page ranges can't be parsed an empty list is | 772 * not eliminated. If the page ranges can't be parsed an empty list is |
| 723 * returned. | 773 * returned. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 920 copiesField.value = 1; | 970 copiesField.value = 1; |
| 921 else { | 971 else { |
| 922 var newValue = getCopies() + sign * 1; | 972 var newValue = getCopies() + sign * 1; |
| 923 if (newValue < copiesField.min || newValue > copiesField.max) | 973 if (newValue < copiesField.min || newValue > copiesField.max) |
| 924 return; | 974 return; |
| 925 copiesField.value = newValue; | 975 copiesField.value = newValue; |
| 926 } | 976 } |
| 927 copiesFieldChanged(); | 977 copiesFieldChanged(); |
| 928 } | 978 } |
| 929 | 979 |
| 980 /** | |
| 981 * Class that represents the state of the print settings. | |
| 982 */ | |
| 983 function PrintSettings() { | |
| 984 this.deviceName = ''; | |
| 985 this.isLandscape = ''; | |
| 986 } | |
| 987 | |
| 988 /** | |
| 989 * Takes a snapshot of the print settings. | |
| 990 */ | |
| 991 PrintSettings.prototype.save = function() { | |
| 992 this.deviceName = getSelectedPrinterName(); | |
| 993 this.isLandscape = isLandscape(); | |
| 994 } | |
| OLD | NEW |