Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / print_preview / print_preview.js
index f17e871..673b8d8 100644 (file)
@@ -151,6 +151,15 @@ cr.define('print_preview', function() {
     this.addChild(this.marginSettings_);
 
     /**
+     * Component that renders the DPI settings.
+     * @type {!print_preview.DpiSettings}
+     * @private
+     */
+    this.dpiSettings_ =
+        new print_preview.DpiSettings(this.printTicketStore_.dpi);
+    this.addChild(this.dpiSettings_);
+
+    /**
      * Component that renders miscellaneous print options.
      * @type {!print_preview.OtherOptionsSettings}
      * @private
@@ -181,11 +190,6 @@ cr.define('print_preview', function() {
         this.printTicketStore_);
     this.addChild(this.advancedSettings_);
 
-    /**
-     * Component representing more/less settings button.
-     * @type {!print_preview.MoreSettings}
-     * @private
-     */
     var settingsSections = [
         this.destinationSettings_,
         this.pageSettings_,
@@ -194,8 +198,14 @@ cr.define('print_preview', function() {
         this.layoutSettings_,
         this.marginSettings_,
         this.colorSettings_,
+        this.dpiSettings_,
         this.otherOptionsSettings_,
         this.advancedOptionsSettings_];
+    /**
+     * Component representing more/less settings button.
+     * @type {!print_preview.MoreSettings}
+     * @private
+     */
     this.moreSettings_ = new print_preview.MoreSettings(
         this.destinationStore_, settingsSections);
     this.addChild(this.moreSettings_);
@@ -238,11 +248,12 @@ cr.define('print_preview', function() {
     this.isInAppKioskMode_ = false;
 
     /**
-     * Whether Print with System Dialog option is available.
+     * Whether Print with System Dialog link should be hidden. Overrides the
+     * default rules for System dialog link visibility.
      * @type {boolean}
      * @private
      */
-    this.isSystemDialogAvailable_ = false;
+    this.hideSystemDialogLink_ = true;
 
     /**
      * State of the print preview UI.
@@ -275,7 +286,6 @@ cr.define('print_preview', function() {
     INITIALIZING: 'initializing',
     READY: 'ready',
     OPENING_PDF_PREVIEW: 'opening-pdf-preview',
-    OPENING_CLOUD_PRINT_DIALOG: 'opening-cloud-print-dialog',
     OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog',
     PRINTING: 'printing',
     FILE_SELECTION: 'file-selection',
@@ -348,14 +358,12 @@ cr.define('print_preview', function() {
           print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST,
           this.onManipulateSettingsForTest_.bind(this));
 
-      this.tracker.add(
-          $('system-dialog-link'),
-          'click',
-          this.openSystemPrintDialog_.bind(this));
-      this.tracker.add(
-          $('cloud-print-dialog-link'),
-          'click',
-          this.onCloudPrintDialogLinkClick_.bind(this));
+      if ($('system-dialog-link')) {
+        this.tracker.add(
+            $('system-dialog-link'),
+            'click',
+            this.openSystemPrintDialog_.bind(this));
+      }
       if ($('open-pdf-in-preview-link')) {
         this.tracker.add(
             $('open-pdf-in-preview-link'),
@@ -463,6 +471,7 @@ cr.define('print_preview', function() {
       this.layoutSettings_.decorate($('layout-settings'));
       this.colorSettings_.decorate($('color-settings'));
       this.marginSettings_.decorate($('margin-settings'));
+      this.dpiSettings_.decorate($('dpi-settings'));
       this.otherOptionsSettings_.decorate($('other-options-settings'));
       this.advancedOptionsSettings_.decorate($('advanced-options-settings'));
       this.advancedSettings_.decorate($('advanced-settings'));
@@ -477,11 +486,10 @@ cr.define('print_preview', function() {
      * @private
      */
     setIsEnabled_: function(isEnabled) {
-      $('system-dialog-link').disabled = !isEnabled;
-      $('cloud-print-dialog-link').disabled = !isEnabled;
-      if ($('open-pdf-in-preview-link')) {
-        $('open-pdf-in-preview-link').disabled = !isEnabled;
-      }
+      if ($('system-dialog-link'))
+        $('system-dialog-link').classList.toggle('disabled', !isEnabled);
+      if ($('open-pdf-in-preview-link'))
+        $('open-pdf-in-preview-link').classList.toggle('disabled', !isEnabled);
       this.printHeader_.isEnabled = isEnabled;
       this.destinationSettings_.isEnabled = isEnabled;
       this.pageSettings_.isEnabled = isEnabled;
@@ -490,6 +498,7 @@ cr.define('print_preview', function() {
       this.layoutSettings_.isEnabled = isEnabled;
       this.colorSettings_.isEnabled = isEnabled;
       this.marginSettings_.isEnabled = isEnabled;
+      this.dpiSettings_.isEnabled = isEnabled;
       this.otherOptionsSettings_.isEnabled = isEnabled;
       this.advancedOptionsSettings_.isEnabled = isEnabled;
     },
@@ -539,7 +548,6 @@ cr.define('print_preview', function() {
           (this.uiState_ == PrintPreview.UiState_.PRINTING ||
            this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW ||
            this.uiState_ == PrintPreview.UiState_.FILE_SELECTION ||
-           this.uiState_ == PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG ||
            this.isInKioskAutoPrintMode_) &&
           this.destinationStore_.selectedDestination &&
           this.destinationStore_.selectedDestination.capabilities;
@@ -551,27 +559,22 @@ cr.define('print_preview', function() {
       }
       assert(this.printTicketStore_.isTicketValid(),
           'Trying to print with invalid ticket');
-      if (this.uiState_ == PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG) {
-        this.nativeLayer_.startShowCloudPrintDialog(
-            this.printTicketStore_.pageRange.getPageNumberSet().size);
-      } else {
-        if (getIsVisible(this.moreSettings_.getElement())) {
-          new print_preview.PrintSettingsUiMetricsContext().record(
-              this.moreSettings_.isExpanded ?
-                  print_preview.Metrics.PrintSettingsUiBucket.
-                      PRINT_WITH_SETTINGS_EXPANDED :
-                  print_preview.Metrics.PrintSettingsUiBucket.
-                      PRINT_WITH_SETTINGS_COLLAPSED);
-        }
-        this.nativeLayer_.startPrint(
-            this.destinationStore_.selectedDestination,
-            this.printTicketStore_,
-            this.cloudPrintInterface_,
-            this.documentInfo_,
-            this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW,
-            this.showSystemDialogBeforeNextPrint_);
-        this.showSystemDialogBeforeNextPrint_ = false;
+      if (getIsVisible(this.moreSettings_.getElement())) {
+        new print_preview.PrintSettingsUiMetricsContext().record(
+            this.moreSettings_.isExpanded ?
+                print_preview.Metrics.PrintSettingsUiBucket.
+                    PRINT_WITH_SETTINGS_EXPANDED :
+                print_preview.Metrics.PrintSettingsUiBucket.
+                    PRINT_WITH_SETTINGS_COLLAPSED);
       }
+      this.nativeLayer_.startPrint(
+          this.destinationStore_.selectedDestination,
+          this.printTicketStore_,
+          this.cloudPrintInterface_,
+          this.documentInfo_,
+          this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW,
+          this.showSystemDialogBeforeNextPrint_);
+      this.showSystemDialogBeforeNextPrint_ = false;
       return PrintPreview.PrintAttemptResult_.PRINTED;
     },
 
@@ -592,12 +595,14 @@ cr.define('print_preview', function() {
     openSystemPrintDialog_: function() {
       if (!this.shouldShowSystemDialogLink_())
         return;
+      if ($('system-dialog-link').classList.contains('disabled'))
+        return;
       if (cr.isWindows) {
         this.showSystemDialogBeforeNextPrint_ = true;
         this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/);
         return;
       }
-      setIsVisible($('system-dialog-throbber'), true);
+      setIsVisible(getRequiredElement('system-dialog-throbber'), true);
       this.setIsEnabled_(false);
       this.uiState_ = PrintPreview.UiState_.OPENING_NATIVE_PRINT_DIALOG;
       this.nativeLayer_.startShowSystemDialog();
@@ -638,9 +643,12 @@ cr.define('print_preview', function() {
       this.appState_.setInitialized();
 
       $('document-title').innerText = settings.documentTitle;
-      this.isSystemDialogAvailable_ = !settings.hidePrintWithSystemDialogLink &&
-                                      !settings.isInAppKioskMode;
-      setIsVisible($('system-dialog-link'), this.shouldShowSystemDialogLink_());
+      this.hideSystemDialogLink_ = settings.hidePrintWithSystemDialogLink ||
+                                   settings.isInAppKioskMode;
+      if ($('system-dialog-link')) {
+        setIsVisible($('system-dialog-link'),
+                     this.shouldShowSystemDialogLink_());
+      }
     },
 
     /**
@@ -798,12 +806,8 @@ cr.define('print_preview', function() {
     onPreviewGenerationFail_: function() {
       this.isPreviewGenerationInProgress_ = false;
       this.printHeader_.isPrintButtonEnabled = false;
-      if (this.uiState_ == PrintPreview.UiState_.PRINTING) {
+      if (this.uiState_ == PrintPreview.UiState_.PRINTING)
         this.nativeLayer_.startCancelPendingPrint();
-      } else if (this.uiState_ ==
-            PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG) {
-        this.uiState_ = PrintPreview.UiState_.READY;
-      }
     },
 
     /**
@@ -812,10 +816,12 @@ cr.define('print_preview', function() {
      * @private
      */
     onOpenPdfInPreviewLinkClick_: function() {
+      if ($('open-pdf-in-preview-link').classList.contains('disabled'))
+        return;
       assert(this.uiState_ == PrintPreview.UiState_.READY,
              'Trying to open pdf in preview when not in ready state: ' +
                  this.uiState_);
-      setIsVisible($('open-preview-app-throbber'), true);
+      setIsVisible(getRequiredElement('open-preview-app-throbber'), true);
       this.previewArea_.showCustomMessage(
           loadTimeData.getString('openingPDFInPreview'));
       this.printDocumentOrOpenPdfPreview_(true /*isPdfPreview*/);
@@ -856,19 +862,22 @@ cr.define('print_preview', function() {
      * to the preview area.
      * @param {KeyboardEvent} e The keyboard event.
      * @private
+     * @suppress {uselessCode}
+     * Current compiler preprocessor leaves all the code inside all the <if>s,
+     * so the compiler claims that code after first return is unreachable.
      */
     onKeyDown_: function(e) {
       // Escape key closes the dialog.
       if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey &&
           !e.metaKey) {
-        <if expr="toolkit_views">
+<if expr="toolkit_views">
         // On the toolkit_views environment, ESC key is handled by C++-side
         // instead of JS-side.
         return;
-        </if>
-        <if expr="not toolkit_views">
+</if>
+<if expr="not toolkit_views">
         this.close_();
-        </if>
+</if>
         e.preventDefault();
         return;
       }
@@ -893,12 +902,13 @@ cr.define('print_preview', function() {
       if (e.keyCode == 13 /*enter*/ &&
           !document.querySelector('.overlay:not([hidden])') &&
           this.destinationStore_.selectedDestination &&
-          this.printTicketStore_.isTicketValid()) {
+          this.printTicketStore_.isTicketValid() &&
+          this.printHeader_.isPrintButtonEnabled) {
         assert(this.uiState_ == PrintPreview.UiState_.READY,
             'Trying to print when not in ready state: ' + this.uiState_);
-        var activeElementTag = document.activeElement ?
-            document.activeElement.tagName.toUpperCase() : '';
-        if (activeElementTag != 'BUTTON' && activeElementTag != 'SELECT') {
+        var activeElementTag = document.activeElement.tagName.toUpperCase();
+        if (activeElementTag != 'BUTTON' && activeElementTag != 'SELECT' &&
+            activeElementTag != 'A') {
           this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/);
           e.preventDefault();
         }
@@ -936,7 +946,7 @@ cr.define('print_preview', function() {
      */
     onAdvancedOptionsButtonActivated_: function() {
       this.advancedSettings_.showForDestination(
-          this.destinationStore_.selectedDestination);
+          assert(this.destinationStore_.selectedDestination));
     },
 
     /**
@@ -997,19 +1007,21 @@ cr.define('print_preview', function() {
      * @private
      */
     onManipulateSettingsForTest_: function(event) {
-      if ('selectSaveAsPdfDestination' in event.settings) {
+      var settings =
+          /** @type {print_preview.PreviewSettings} */(event.settings);
+      if ('selectSaveAsPdfDestination' in settings) {
         this.saveAsPdfForTest_();  // No parameters.
-      } else if ('layoutSettings' in event.settings) {
-        this.setLayoutSettingsForTest_(event.settings.layoutSettings.portrait);
-      } else if ('pageRange' in event.settings) {
-        this.setPageRangeForTest_(event.settings.pageRange);
-      } else if ('headersAndFooters' in event.settings) {
-        this.setHeadersAndFootersForTest_(event.settings.headersAndFooters);
-      } else if ('backgroundColorsAndImages' in event.settings) {
+      } else if ('layoutSettings' in settings) {
+        this.setLayoutSettingsForTest_(settings.layoutSettings.portrait);
+      } else if ('pageRange' in settings) {
+        this.setPageRangeForTest_(settings.pageRange);
+      } else if ('headersAndFooters' in settings) {
+        this.setHeadersAndFootersForTest_(settings.headersAndFooters);
+      } else if ('backgroundColorsAndImages' in settings) {
         this.setBackgroundColorsAndImagesForTest_(
-            event.settings.backgroundColorsAndImages);
-      } else if ('margins' in event.settings) {
-        this.setMarginsForTest_(event.settings.margins);
+            settings.backgroundColorsAndImages);
+      } else if ('margins' in settings) {
+        this.setMarginsForTest_(settings.margins);
       }
     },
 
@@ -1131,46 +1143,29 @@ cr.define('print_preview', function() {
      * @return {boolean} Returns true if link should be shown.
      */
     shouldShowSystemDialogLink_: function() {
-      if (!this.isSystemDialogAvailable_)
+      if (cr.isChromeOS || this.hideSystemDialogLink_)
         return false;
       if (!cr.isWindows)
         return true;
       var selectedDest = this.destinationStore_.selectedDestination;
-      return selectedDest &&
+      return !!selectedDest &&
              selectedDest.origin == print_preview.Destination.Origin.LOCAL &&
              selectedDest.id !=
                  print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
     },
 
     /**
-     * Called when the open-cloud-print-dialog link is clicked. Opens the Google
-     * Cloud Print web dialog.
-     * @private
-     */
-    onCloudPrintDialogLinkClick_: function() {
-      assert(this.uiState_ == PrintPreview.UiState_.READY,
-             'Opening Google Cloud Print dialog when not in ready state: ' +
-                 this.uiState_);
-      setIsVisible($('cloud-print-dialog-throbber'), true);
-      this.setIsEnabled_(false);
-      this.uiState_ = PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG;
-      this.printIfReady_();
-    },
-
-    /**
      * Called when a print destination is selected. Shows/hides the "Print with
      * Cloud Print" link in the navbar.
      * @private
      */
     onDestinationSelect_: function() {
-      var selectedDest = this.destinationStore_.selectedDestination;
-      setIsVisible(
-          $('cloud-print-dialog-link'),
-          selectedDest && !cr.isChromeOS && !selectedDest.isLocal);
-      setIsVisible(
-          $('system-dialog-link'),
-          this.shouldShowSystemDialogLink_());
-      if (selectedDest && this.isInKioskAutoPrintMode_) {
+      if ($('system-dialog-link')) {
+        setIsVisible($('system-dialog-link'),
+                     this.shouldShowSystemDialogLink_());
+      }
+      if (this.destinationStore_.selectedDestination &&
+          this.isInKioskAutoPrintMode_) {
         this.onPrintButtonClick_();
       }
     },
@@ -1186,8 +1181,8 @@ cr.define('print_preview', function() {
           this.cloudPrintInterface_ &&
           this.userInfo_.activeUser &&
           !this.appState_.isGcpPromoDismissed &&
-          !this.destinationStore_.isLocalDestinationsSearchInProgress &&
-          !this.destinationStore_.isCloudDestinationsSearchInProgress &&
+          !this.destinationStore_.isLocalDestinationSearchInProgress &&
+          !this.destinationStore_.isCloudDestinationSearchInProgress &&
           this.destinationStore_.hasOnlyDefaultCloudDestinations();
       setIsVisible(this.getChildElement('#no-destinations-promo'),
                    isPromoVisible);
@@ -1259,6 +1254,7 @@ cr.define('print_preview', function() {
 <include src="data/ticket_items/collate.js">
 <include src="data/ticket_items/color.js">
 <include src="data/ticket_items/copies.js">
+<include src="data/ticket_items/dpi.js">
 <include src="data/ticket_items/duplex.js">
 <include src="data/ticket_items/header_footer.js">
 <include src="data/ticket_items/media_size.js">
@@ -1278,8 +1274,10 @@ cr.define('print_preview', function() {
 <include src="metrics.js">
 
 <include src="settings/settings_section.js">
+<include src="settings/settings_section_select.js">
 <include src="settings/page_settings.js">
 <include src="settings/copies_settings.js">
+<include src="settings/dpi_settings.js">
 <include src="settings/media_size_settings.js">
 <include src="settings/layout_settings.js">
 <include src="settings/color_settings.js">