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 // require: cr/ui/print_preview_cloud.js | 5 // require: cr/ui/print_preview_cloud.js |
6 | 6 |
7 var localStrings = new LocalStrings(); | 7 var localStrings = new LocalStrings(); |
8 | 8 |
9 // If useCloudPrint is true we attempt to connect to cloud print | 9 // If useCloudPrint is true we attempt to connect to cloud print |
10 // and populate the list of printers with cloud print printers. | 10 // and populate the list of printers with cloud print printers. |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 } | 529 } |
530 | 530 |
531 /** | 531 /** |
532 * Set the default printer. If there is one, generate a print preview. | 532 * Set the default printer. If there is one, generate a print preview. |
533 * @param {string} printer Name of the default printer. Empty if none. | 533 * @param {string} printer Name of the default printer. Empty if none. |
534 * @param {string} cloudPrintData Cloud print related data to restore if | 534 * @param {string} cloudPrintData Cloud print related data to restore if |
535 * the default printer is a cloud printer. | 535 * the default printer is a cloud printer. |
536 */ | 536 */ |
537 function setDefaultPrinter(printer_name, cloudPrintData) { | 537 function setDefaultPrinter(printer_name, cloudPrintData) { |
538 // Add a placeholder value so the printer list looks valid. | 538 // Add a placeholder value so the printer list looks valid. |
539 addDestinationListOption('', '', true, true, true); | 539 addDestinationListOption('', '', true, true); |
540 if (printer_name) { | 540 if (printer_name) { |
541 defaultOrLastUsedPrinterName = printer_name; | 541 defaultOrLastUsedPrinterName = printer_name; |
542 if (cloudPrintData) { | 542 if (cloudPrintData) { |
543 cloudprint.setDefaultPrinter(printer_name, | 543 cloudprint.setDefaultPrinter(printer_name, |
544 cloudPrintData, | 544 cloudPrintData, |
545 addDestinationListOptionAtPosition, | 545 addDestinationListOptionAtPosition, |
546 doUpdateCloudPrinterCapabilities); | 546 doUpdateCloudPrinterCapabilities); |
547 } else { | 547 } else { |
548 $('printer-list')[0].value = defaultOrLastUsedPrinterName; | 548 $('printer-list')[0].value = defaultOrLastUsedPrinterName; |
549 updateControlsWithSelectedPrinterCapabilities(); | 549 updateControlsWithSelectedPrinterCapabilities(); |
550 } | 550 } |
551 } | 551 } |
552 chrome.send('getPrinters'); | 552 chrome.send('getPrinters'); |
553 } | 553 } |
554 | 554 |
555 /** | 555 /** |
556 * Fill the printer list drop down. | 556 * Fill the printer list drop down. |
557 * Called from PrintPreviewHandler::SendPrinterList(). | 557 * Called from PrintPreviewHandler::SendPrinterList(). |
558 * @param {Array} printers Array of printer info objects. | 558 * @param {Array} printers Array of printer info objects. |
559 */ | 559 */ |
560 function setPrinters(printers) { | 560 function setPrinters(printers) { |
561 var printerList = $('printer-list'); | 561 var printerList = $('printer-list'); |
562 // Remove empty entry added by setDefaultPrinter. | 562 // Remove empty entry added by setDefaultPrinter. |
563 if (printerList[0] && printerList[0].textContent == '') | 563 if (printerList[0] && printerList[0].textContent == '') |
564 printerList.remove(0); | 564 printerList.remove(0); |
565 for (var i = 0; i < printers.length; ++i) { | 565 for (var i = 0; i < printers.length; ++i) { |
566 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName); | 566 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName); |
567 addDestinationListOption(printers[i].printerName, printers[i].deviceName, | 567 addDestinationListOption(printers[i].printerName, printers[i].deviceName, |
568 isDefault, false, false); | 568 isDefault, false); |
569 } | 569 } |
570 | 570 |
571 if (printers.length != 0) | 571 if (printers.length != 0) |
572 addDestinationListOption('', '', false, true, true); | 572 addDestinationListSeparator(); |
573 | 573 |
574 // Adding option for saving PDF to disk. | 574 // Adding option for saving PDF to disk. |
575 addDestinationListOption(localStrings.getString('printToPDF'), | 575 addDestinationListOption(localStrings.getString('printToPDF'), |
576 PRINT_TO_PDF, | 576 PRINT_TO_PDF, |
577 defaultOrLastUsedPrinterName == PRINT_TO_PDF, | 577 defaultOrLastUsedPrinterName == PRINT_TO_PDF, |
578 false, | |
579 false); | 578 false); |
580 addDestinationListOption('', '', false, true, true); | 579 addDestinationListSeparator(); |
581 if (useCloudPrint) { | 580 if (useCloudPrint) { |
582 addDestinationListOption(localStrings.getString('printWithCloudPrint'), | 581 addDestinationListOption(localStrings.getString('printWithCloudPrint'), |
583 PRINT_WITH_CLOUD_PRINT, | 582 PRINT_WITH_CLOUD_PRINT, |
584 false, | 583 false, |
585 false, | |
586 false); | 584 false); |
587 addDestinationListOption('', '', false, true, true); | 585 addDestinationListSeparator(); |
588 } | 586 } |
589 // Add options to manage printers. | 587 // Add options to manage printers. |
590 if (!cr.isChromeOS) { | 588 if (!cr.isChromeOS) { |
591 addDestinationListOption(localStrings.getString('managePrinters'), | 589 addDestinationListOption(localStrings.getString('managePrinters'), |
592 MANAGE_LOCAL_PRINTERS, false, false, false); | 590 MANAGE_LOCAL_PRINTERS, false, false); |
593 } else if (useCloudPrint) { | 591 } else if (useCloudPrint) { |
594 // Fetch recent printers. | 592 // Fetch recent printers. |
595 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, false); | 593 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, false); |
596 // Fetch the full printer list. | 594 // Fetch the full printer list. |
597 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, true); | 595 cloudprint.fetchPrinters(addDestinationListOptionAtPosition, true); |
598 addDestinationListOption(localStrings.getString('managePrinters'), | 596 addDestinationListOption(localStrings.getString('managePrinters'), |
599 MANAGE_CLOUD_PRINTERS, false, false, false); | 597 MANAGE_CLOUD_PRINTERS, false, false); |
600 } | 598 } |
601 | 599 |
602 printerList.disabled = false; | 600 printerList.disabled = false; |
603 | 601 |
604 if (!hasRequestedPreview()) | 602 if (!hasRequestedPreview()) |
605 updateControlsWithSelectedPrinterCapabilities(); | 603 updateControlsWithSelectedPrinterCapabilities(); |
606 } | 604 } |
607 | 605 |
608 /** | 606 /** |
609 * Creates an option that can be added to the printer destination list. | 607 * Creates an option that can be added to the printer destination list. |
610 * @param {string} optionText specifies the option text content. | 608 * @param {string} optionText specifies the option text content. |
611 * @param {string} optionValue specifies the option value. | 609 * @param {string} optionValue specifies the option value. |
612 * @param {boolean} isDefault is true if the option needs to be selected. | 610 * @param {boolean} isDefault is true if the option needs to be selected. |
613 * @param {boolean} isDisabled is true if the option needs to be disabled. | 611 * @param {boolean} isDisabled is true if the option needs to be disabled. |
614 * @param {boolean} isSeparator is true if the option is a visual separator and | |
615 * needs to be disabled. | |
616 * @return {Object} The created option. | 612 * @return {Object} The created option. |
617 */ | 613 */ |
618 function createDestinationListOption(optionText, optionValue, isDefault, | 614 function createDestinationListOption(optionText, optionValue, isDefault, |
619 isDisabled, isSeparator) { | 615 isDisabled) { |
620 var option = document.createElement('option'); | 616 var option = document.createElement('option'); |
621 option.textContent = optionText; | 617 option.textContent = optionText; |
622 option.value = optionValue; | 618 option.value = optionValue; |
623 option.selected = isDefault; | 619 option.selected = isDefault; |
624 option.disabled = isSeparator || isDisabled; | 620 option.disabled = isDisabled; |
625 // Adding attribute for improved accessibility. | |
626 if (isSeparator) | |
627 option.setAttribute("role", "separator"); | |
628 return option; | 621 return option; |
629 } | 622 } |
630 | 623 |
631 /** | 624 /** |
632 * Adds an option to the printer destination list. | 625 * Adds an option to the printer destination list. |
633 * @param {string} optionText specifies the option text content. | 626 * @param {string} optionText specifies the option text content. |
634 * @param {string} optionValue specifies the option value. | 627 * @param {string} optionValue specifies the option value. |
635 * @param {boolean} isDefault is true if the option needs to be selected. | 628 * @param {boolean} isDefault is true if the option needs to be selected. |
636 * @param {boolean} isDisabled is true if the option needs to be disabled. | 629 * @param {boolean} isDisabled is true if the option needs to be disabled. |
637 * @return {Object} The created option. | 630 * @return {Object} The created option. |
638 */ | 631 */ |
639 function addDestinationListOption(optionText, optionValue, isDefault, | 632 function addDestinationListOption(optionText, optionValue, isDefault, |
640 isDisabled, isSeparator) { | 633 isDisabled) { |
641 var option = createDestinationListOption(optionText, | 634 var option = createDestinationListOption(optionText, |
642 optionValue, | 635 optionValue, |
643 isDefault, | 636 isDefault, |
644 isDisabled, | 637 isDisabled); |
645 isSeparator); | |
646 $('printer-list').add(option); | 638 $('printer-list').add(option); |
647 return option; | 639 return option; |
648 } | 640 } |
649 | 641 |
650 /** | 642 /** |
651 * Adds an option to the printer destination list at a specified position. | 643 * Adds an option to the printer destination list at a specified position. |
652 * @param {number} position The index in the printer-list wher the option | 644 * @param {number} position The index in the printer-list wher the option |
653 should be created. | 645 should be created. |
654 * @param {string} optionText specifies the option text content. | 646 * @param {string} optionText specifies the option text content. |
655 * @param {string} optionValue specifies the option value. | 647 * @param {string} optionValue specifies the option value. |
656 * @param {boolean} isDefault is true if the option needs to be selected. | 648 * @param {boolean} isDefault is true if the option needs to be selected. |
657 * @param {boolean} isDisabled is true if the option needs to be disabled. | 649 * @param {boolean} isDisabled is true if the option needs to be disabled. |
658 * @return {Object} The created option. | 650 * @return {Object} The created option. |
659 */ | 651 */ |
660 function addDestinationListOptionAtPosition(position, | 652 function addDestinationListOptionAtPosition(position, |
661 optionText, | 653 optionText, |
662 optionValue, | 654 optionValue, |
663 isDefault, | 655 isDefault, |
664 isDisabled, | 656 isDisabled) { |
665 isSeparator) { | |
666 var option = createDestinationListOption(optionText, | 657 var option = createDestinationListOption(optionText, |
667 optionValue, | 658 optionValue, |
668 isDefault, | 659 isDefault, |
669 isDisabled, | 660 isDisabled); |
670 isSeparator); | |
671 var printerList = $('printer-list'); | 661 var printerList = $('printer-list'); |
672 var before = printerList[position]; | 662 var before = printerList[position]; |
673 printerList.add(option, before); | 663 printerList.add(option, before); |
674 return option; | 664 return option; |
675 } | 665 } |
| 666 |
| 667 /** |
| 668 * Adds a separator to the printer destination list. |
| 669 */ |
| 670 function addDestinationListSeparator() { |
| 671 $('printer-list').add(document.createElement('hr')); |
| 672 } |
| 673 |
676 /** | 674 /** |
677 * Sets the color mode for the PDF plugin. | 675 * Sets the color mode for the PDF plugin. |
678 * Called from PrintPreviewHandler::ProcessColorSetting(). | 676 * Called from PrintPreviewHandler::ProcessColorSetting(). |
679 * @param {boolean} color is true if the PDF plugin should display in color. | 677 * @param {boolean} color is true if the PDF plugin should display in color. |
680 */ | 678 */ |
681 function setColor(color) { | 679 function setColor(color) { |
682 var pdfViewer = $('pdf-viewer'); | 680 var pdfViewer = $('pdf-viewer'); |
683 if (!pdfViewer) { | 681 if (!pdfViewer) { |
684 return; | 682 return; |
685 } | 683 } |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 <include src="print_preview_animations.js"/> | 1026 <include src="print_preview_animations.js"/> |
1029 <include src="print_preview_cloud.js"/> | 1027 <include src="print_preview_cloud.js"/> |
1030 <include src="print_preview_utils.js"/> | 1028 <include src="print_preview_utils.js"/> |
1031 <include src="print_header.js"/> | 1029 <include src="print_header.js"/> |
1032 <include src="page_settings.js"/> | 1030 <include src="page_settings.js"/> |
1033 <include src="copies_settings.js"/> | 1031 <include src="copies_settings.js"/> |
1034 <include src="header_footer_settings.js"/> | 1032 <include src="header_footer_settings.js"/> |
1035 <include src="layout_settings.js"/> | 1033 <include src="layout_settings.js"/> |
1036 <include src="color_settings.js"/> | 1034 <include src="color_settings.js"/> |
1037 <include src="margin_settings.js"/> | 1035 <include src="margin_settings.js"/> |
OLD | NEW |