Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(661)

Side by Side Diff: chrome/browser/resources/print_preview.js

Issue 6979024: Print Preview: Fading in/out printing options. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing <hr> before copies option. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 */ 150 */
151 function updateControlsWithSelectedPrinterCapabilities() { 151 function updateControlsWithSelectedPrinterCapabilities() {
152 var printerList = $('printer-list'); 152 var printerList = $('printer-list');
153 var selectedIndex = printerList.selectedIndex; 153 var selectedIndex = printerList.selectedIndex;
154 if (selectedIndex < 0) 154 if (selectedIndex < 0)
155 return; 155 return;
156 156
157 var selectedValue = printerList.options[selectedIndex].value; 157 var selectedValue = printerList.options[selectedIndex].value;
158 if (selectedValue == PRINT_TO_PDF) { 158 if (selectedValue == PRINT_TO_PDF) {
159 updateWithPrinterCapabilities({'disableColorOption': true, 159 updateWithPrinterCapabilities({'disableColorOption': true,
160 'setColorAsDefault': true}); 160 'setColorAsDefault': true,
161 'disableCopiesOption': true});
161 } else if (selectedValue == MANAGE_PRINTERS) { 162 } else if (selectedValue == MANAGE_PRINTERS) {
162 printerList.selectedIndex = lastSelectedPrinterIndex; 163 printerList.selectedIndex = lastSelectedPrinterIndex;
163 chrome.send('managePrinters'); 164 chrome.send('managePrinters');
164 return; 165 return;
165 } else { 166 } else {
166 // This message will call back to 'updateWithPrinterCapabilities' 167 // This message will call back to 'updateWithPrinterCapabilities'
167 // function. 168 // function.
168 chrome.send('getPrinterCapabilities', [selectedValue]); 169 chrome.send('getPrinterCapabilities', [selectedValue]);
169 } 170 }
170 171
171 lastSelectedPrinterIndex = selectedIndex; 172 lastSelectedPrinterIndex = selectedIndex;
172 173
173 // Regenerate the preview data based on selected printer settings. 174 // Regenerate the preview data based on selected printer settings.
174 setDefaultValuesAndRegeneratePreview(); 175 setDefaultValuesAndRegeneratePreview();
175 } 176 }
176 177
177 /** 178 /**
178 * Updates the controls with printer capabilities information. 179 * Updates the controls with printer capabilities information.
179 * @param {Object} settingInfo printer setting information. 180 * @param {Object} settingInfo printer setting information.
180 */ 181 */
181 function updateWithPrinterCapabilities(settingInfo) { 182 function updateWithPrinterCapabilities(settingInfo) {
182 var disableColorOption = settingInfo.disableColorOption; 183 var disableColorOption = settingInfo.disableColorOption;
184 var disableCopiesOption = settingInfo.disableCopiesOption;
183 var setColorAsDefault = settingInfo.setColorAsDefault; 185 var setColorAsDefault = settingInfo.setColorAsDefault;
184 var colorOption = $('color'); 186 var colorOption = $('color');
185 var bwOption = $('bw'); 187 var bwOption = $('bw');
186 188
187 if (disableColorOption) 189 if (disableCopiesOption) {
188 $('color-options').classList.add("hidden"); 190 fadeOutElement($('copies-option'));
189 else 191 $('hr-before-copies').classList.remove('invisible');
190 $('color-options').classList.remove("hidden"); 192 } else {
193 fadeInElement($('copies-option'));
194 $('hr-before-copies').classList.add('invisible');
195 }
196
197 disableColorOption ? fadeOutElement($('color-options')) :
198 fadeInElement($('color-options'));
191 199
192 if (colorOption.checked != setColorAsDefault) { 200 if (colorOption.checked != setColorAsDefault) {
193 colorOption.checked = setColorAsDefault; 201 colorOption.checked = setColorAsDefault;
194 bwOption.checked = !setColorAsDefault; 202 bwOption.checked = !setColorAsDefault;
195 setColor(colorOption.checked); 203 setColor(colorOption.checked);
196 } 204 }
197 } 205 }
198 206
199 /** 207 /**
200 * Disables or enables all controls in the options pane except for the cancel 208 * Disables or enables all controls in the options pane except for the cancel
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 * Called when the PDF plugin loads its document. 456 * Called when the PDF plugin loads its document.
449 */ 457 */
450 function onPDFLoad() { 458 function onPDFLoad() {
451 if (isLandscape()) 459 if (isLandscape())
452 $('pdf-viewer').fitToWidth(); 460 $('pdf-viewer').fitToWidth();
453 else 461 else
454 $('pdf-viewer').fitToHeight(); 462 $('pdf-viewer').fitToHeight();
455 463
456 $('dancing-dots').classList.add('invisible'); 464 $('dancing-dots').classList.add('invisible');
457 465
458 if (!previewModifiable) { 466 if (!previewModifiable)
459 $('landscape').disabled = true; 467 fadeOutElement($('landscape-option'));
460 $('portrait').disabled = true;
461 }
462 468
463 updateCopiesButtonsState(); 469 updateCopiesButtonsState();
464 } 470 }
465 471
466 /** 472 /**
467 * Update the print preview when new preview data is available. 473 * Update the print preview when new preview data is available.
468 * Create the PDF plugin as needed. 474 * Create the PDF plugin as needed.
469 * Called from PrintPreviewUI::PreviewDataIsAvailable(). 475 * Called from PrintPreviewUI::PreviewDataIsAvailable().
470 * @param {number} pageCount The expected total pages count. 476 * @param {number} pageCount The expected total pages count.
471 * @param {string} jobTitle The print job title. 477 * @param {string} jobTitle The print job title.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 */ 563 */
558 function checkCompatiblePluginExists() { 564 function checkCompatiblePluginExists() {
559 var dummyPlugin = $('dummy-viewer') 565 var dummyPlugin = $('dummy-viewer')
560 return !!dummyPlugin.onload; 566 return !!dummyPlugin.onload;
561 } 567 }
562 568
563 /** 569 /**
564 * Updates the state of print button depending on the user selection. 570 * Updates the state of print button depending on the user selection.
565 * The button is enabled only when the following conditions are true. 571 * The button is enabled only when the following conditions are true.
566 * 1) The selected page ranges are valid. 572 * 1) The selected page ranges are valid.
567 * 2) The number of copies is valid. 573 * 2) The number of copies is valid (if applicable).
568 */ 574 */
569 function updatePrintButtonState() { 575 function updatePrintButtonState() {
570 $('print-button').disabled = (!isNumberOfCopiesValid() || 576 if (getSelectedPrinterName() == PRINT_TO_PDF)
571 getSelectedPagesValidityLevel() != 1); 577 $('print-button').disabled = (getSelectedPagesValidityLevel() != 1);
578 else
579 $('print-button').disabled = (!isNumberOfCopiesValid() ||
Lei Zhang 2011/05/27 22:58:01 nit: add parenthesis.
dpapad 2011/05/27 23:16:17 Done. BTW I thought we prefer to use parenthesis o
Lei Zhang 2011/05/27 23:27:30 Multi-line else statement = required.
Lei Zhang 2011/05/27 23:28:55 Err, I meant to say braces. that is: if () { ...
580 getSelectedPagesValidityLevel() != 1);
572 } 581 }
573 582
574 window.addEventListener('DOMContentLoaded', onLoad); 583 window.addEventListener('DOMContentLoaded', onLoad);
575 584
576 /** 585 /**
577 * Listener function that executes whenever a change occurs in the 'copies' 586 * Listener function that executes whenever a change occurs in the 'copies'
578 * field. 587 * field.
579 */ 588 */
580 function copiesFieldChanged() { 589 function copiesFieldChanged() {
581 updateCopiesButtonsState(); 590 updateCopiesButtonsState();
582 $('collate-option').hidden = getCopies() <= 1; 591 $('collate-option').hidden = getCopies() <= 1;
583 } 592 }
584 593
585 /** 594 /**
586 * Executes whenever a blur event occurs on the 'individual-pages' 595 * Executes whenever a blur event occurs on the 'individual-pages'
587 * field or when the timer expires. It takes care of 596 * field or when the timer expires. It takes care of
588 * 1) showing/hiding warnings/suggestions 597 * 1) showing/hiding warnings/suggestions
589 * 2) updating print button/summary 598 * 2) updating print button/summary
590 */ 599 */
591 function pageRangesFieldChanged() { 600 function pageRangesFieldChanged() {
592 var currentlySelectedPages = getSelectedPagesSet(); 601 var currentlySelectedPages = getSelectedPagesSet();
593 var individualPagesField = $('individual-pages'); 602 var individualPagesField = $('individual-pages');
594 var individualPagesHint = $('individual-pages-hint'); 603 var individualPagesHint = $('individual-pages-hint');
595 var validityLevel = getSelectedPagesValidityLevel(); 604 var validityLevel = getSelectedPagesValidityLevel();
596 605
597 if (validityLevel == 1) { 606 if (validityLevel == 1) {
598 individualPagesField.classList.remove('invalid'); 607 individualPagesField.classList.remove('invalid');
599 hideInvalidHint(individualPagesHint); 608 fadeOutElement(individualPagesHint);
600 } else { 609 } else {
601 individualPagesField.classList.add('invalid'); 610 individualPagesField.classList.add('invalid');
602 individualPagesHint.classList.remove('suggestion'); 611 individualPagesHint.classList.remove('suggestion');
603 individualPagesHint.innerHTML = 612 individualPagesHint.innerHTML =
604 localStrings.getStringF('pageRangeInstruction', 613 localStrings.getStringF('pageRangeInstruction',
605 localStrings.getString( 614 localStrings.getString(
606 'examplePageRangeText')); 615 'examplePageRangeText'));
607 showInvalidHint(individualPagesHint); 616 fadeInElement(individualPagesHint);
608 } 617 }
609 618
610 resetPageRangeFieldTimer(); 619 resetPageRangeFieldTimer();
611 updatePrintButtonState(); 620 updatePrintButtonState();
612 updatePrintSummary(); 621 updatePrintSummary();
613 } 622 }
614 623
615 /** 624 /**
616 * Updates the state of the increment/decrement buttons based on the current 625 * Updates the state of the increment/decrement buttons based on the current
617 * 'copies' value. 626 * 'copies' value.
618 */ 627 */
619 function updateCopiesButtonsState() { 628 function updateCopiesButtonsState() {
620 var copiesField = $('copies'); 629 var copiesField = $('copies');
621 if (!isNumberOfCopiesValid()) { 630 if (!isNumberOfCopiesValid()) {
622 copiesField.classList.add('invalid'); 631 copiesField.classList.add('invalid');
623 $('increment').disabled = false; 632 $('increment').disabled = false;
624 $('decrement').disabled = false; 633 $('decrement').disabled = false;
625 showInvalidHint($('copies-hint')); 634 fadeInElement($('copies-hint'));
626 } 635 }
627 else { 636 else {
628 copiesField.classList.remove('invalid'); 637 copiesField.classList.remove('invalid');
629 $('increment').disabled = (getCopies() == copiesField.max) ? true : false; 638 $('increment').disabled = (getCopies() == copiesField.max) ? true : false;
630 $('decrement').disabled = (getCopies() == copiesField.min) ? true : false; 639 $('decrement').disabled = (getCopies() == copiesField.min) ? true : false;
631 hideInvalidHint($('copies-hint')); 640 fadeOutElement($('copies-hint'));
632 } 641 }
633 } 642 }
634 643
635 /** 644 /**
636 * Updates the print summary based on the currently selected user options. 645 * Updates the print summary based on the currently selected user options.
637 * 646 *
638 */ 647 */
639 function updatePrintSummary() { 648 function updatePrintSummary() {
640 var copies = getCopies(); 649 var copies = getCopies();
641 var printSummary = $('print-summary'); 650 var printSummary = $('print-summary');
651 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF;
Lei Zhang 2011/05/27 22:58:01 move this to the top and set copies based on print
dpapad 2011/05/27 23:16:17 Done.
642 652
643 if (!isNumberOfCopiesValid()) { 653 if (printToPDF)
654 copies = 1;
655
656 if (!printToPDF && !isNumberOfCopiesValid()) {
644 printSummary.innerHTML = localStrings.getString('invalidNumberOfCopies'); 657 printSummary.innerHTML = localStrings.getString('invalidNumberOfCopies');
645 return; 658 return;
646 } 659 }
647 660
648 if (getSelectedPagesValidityLevel() != 1) { 661 if (getSelectedPagesValidityLevel() != 1) {
649 printSummary.innerHTML = ''; 662 printSummary.innerHTML = '';
650 return; 663 return;
651 } 664 }
652 665
653 var pageList = getSelectedPagesSet(); 666 var pageList = getSelectedPagesSet();
654 var numOfSheets = pageList.length; 667 var numOfSheets = pageList.length;
655 var sheetsLabel = localStrings.getString('printPreviewSheetsLabelSingular'); 668 var sheetsLabel = localStrings.getString('printPreviewSheetsLabelSingular');
656 var numOfPagesText = ''; 669 var numOfPagesText = '';
657 var pagesLabel = ''; 670 var pagesLabel = '';
658 671
659 if (isTwoSided()) 672 if (!printToPDF && isTwoSided())
660 numOfSheets = Math.ceil(numOfSheets / 2); 673 numOfSheets = Math.ceil(numOfSheets / 2);
661 numOfSheets *= copies; 674 numOfSheets *= copies;
662 675
663 if (numOfSheets > 1) 676 if (numOfSheets > 1)
664 sheetsLabel = localStrings.getString('printPreviewSheetsLabelPlural'); 677 sheetsLabel = localStrings.getString('printPreviewSheetsLabelPlural');
665 678
666 var html = ''; 679 var html = '';
667 if (pageList.length * copies != numOfSheets) { 680 if (pageList.length * copies != numOfSheets) {
668 numOfPagesText = pageList.length * copies; 681 numOfPagesText = pageList.length * copies;
669 pagesLabel = localStrings.getString('printPreviewPageLabelPlural'); 682 pagesLabel = localStrings.getString('printPreviewPageLabelPlural');
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 return; 721 return;
709 722
710 $('individual-pages').classList.remove('invalid'); 723 $('individual-pages').classList.remove('invalid');
711 setDefaultValuesAndRegeneratePreview(); 724 setDefaultValuesAndRegeneratePreview();
712 } 725 }
713 726
714 /** 727 /**
715 * Sets the default values and sends a request to regenerate preview data. 728 * Sets the default values and sends a request to regenerate preview data.
716 */ 729 */
717 function setDefaultValuesAndRegeneratePreview() { 730 function setDefaultValuesAndRegeneratePreview() {
718 hideInvalidHint($('individual-pages-hint')); 731 fadeOutElement($('individual-pages-hint'));
719 totalPageCount = -1; 732 totalPageCount = -1;
720 previouslySelectedPages.length = 0; 733 previouslySelectedPages.length = 0;
721 requestPrintPreview(); 734 requestPrintPreview();
722 } 735 }
723 736
724 /** 737 /**
725 * Returns a list of all pages in the specified ranges. The pages are listed in 738 * Returns a list of all pages in the specified ranges. The pages are listed in
726 * the order they appear in the 'individual-pages' textbox and duplicates are 739 * the order they appear in the 'individual-pages' textbox and duplicates are
727 * not eliminated. If the page ranges can't be parsed an empty list is 740 * not eliminated. If the page ranges can't be parsed an empty list is
728 * returned. 741 * returned.
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 this.isLandscape = ''; 952 this.isLandscape = '';
940 } 953 }
941 954
942 /** 955 /**
943 * Takes a snapshot of the print settings. 956 * Takes a snapshot of the print settings.
944 */ 957 */
945 PrintSettings.prototype.save = function() { 958 PrintSettings.prototype.save = function() {
946 this.deviceName = getSelectedPrinterName(); 959 this.deviceName = getSelectedPrinterName();
947 this.isLandscape = isLandscape(); 960 this.isLandscape = isLandscape();
948 } 961 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698