var localStrings = new LocalStrings(templateData);
<include src="component.js"/>
+<include src="print_preview_focus_manager.js"/>
cr.define('print_preview', function() {
'use strict';
this.userInfo_ = new print_preview.UserInfo();
/**
- * Metrics object used to report usage statistics.
- * @type {!print_preview.Metrics}
- * @private
- */
- this.metrics_ = new print_preview.Metrics();
-
- /**
* Application state.
* @type {!print_preview.AppState}
* @private
* @private
*/
this.destinationStore_ = new print_preview.DestinationStore(
- this.nativeLayer_, this.userInfo_, this.appState_, this.metrics_);
+ this.nativeLayer_, this.userInfo_, this.appState_);
/**
* Storage of the print ticket used to create the print job.
* @private
*/
this.destinationSearch_ = new print_preview.DestinationSearch(
- this.destinationStore_, this.userInfo_, this.metrics_);
+ this.destinationStore_, this.userInfo_);
this.addChild(this.destinationSearch_);
/**
this.addChild(this.otherOptionsSettings_);
/**
+ * Component that renders the advanced options button.
+ * @type {!print_preview.AdvancedOptionsSettings}
+ * @private
+ */
+ this.advancedOptionsSettings_ = new print_preview.AdvancedOptionsSettings(
+ this.destinationStore_);
+ this.addChild(this.advancedOptionsSettings_);
+
+ /**
+ * Component used to search for print destinations.
+ * @type {!print_preview.AdvancedSettings}
+ * @private
+ */
+ this.advancedSettings_ = new print_preview.AdvancedSettings(
+ this.printTicketStore_);
+ this.addChild(this.advancedSettings_);
+
+ /**
* Area of the UI that holds the print preview.
* @type {!print_preview.PreviewArea}
* @private
this.isInKioskAutoPrintMode_ = false;
/**
+ * Whether Print Preview is in App Kiosk mode, basically, use only printers
+ * available for the device.
+ * @type {boolean}
+ * @private
+ */
+ this.isInAppKioskMode_ = false;
+
+ /**
* State of the print preview UI.
* @type {print_preview.PrintPreview.UiState_}
* @private
this.setIsEnabled_(false);
}
this.nativeLayer_.startGetInitialSettings();
+ print_preview.PrintPreviewFocusManager.getInstance().initialize();
cr.ui.FocusOutlineManager.forDocument(document);
},
this.nativeLayer_,
print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED,
this.onPrivetPrintFailed_.bind(this));
-
+ this.tracker.add(
+ this.nativeLayer_,
+ print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST,
+ this.onManipulateSettingsForTest_.bind(this));
this.tracker.add(
$('system-dialog-link'),
print_preview.DestinationListItem.EventType.REGISTER_PROMO_CLICKED,
this.onCloudPrintRegisterPromoClick_.bind(this));
+ this.tracker.add(
+ this.advancedOptionsSettings_,
+ print_preview.AdvancedOptionsSettings.EventType.BUTTON_ACTIVATED,
+ this.onAdvancedOptionsButtonActivated_.bind(this));
+
// TODO(rltoscano): Move no-destinations-promo into its own component
// instead being part of PrintPreview.
this.tracker.add(
this.colorSettings_.decorate($('color-settings'));
this.marginSettings_.decorate($('margin-settings'));
this.otherOptionsSettings_.decorate($('other-options-settings'));
+ this.advancedOptionsSettings_.decorate($('advanced-options-settings'));
+ this.advancedSettings_.decorate($('advanced-settings'));
this.previewArea_.decorate($('preview-area'));
setIsVisible($('open-pdf-in-preview-link'), cr.isMac);
this.colorSettings_.isEnabled = isEnabled;
this.marginSettings_.isEnabled = isEnabled;
this.otherOptionsSettings_.isEnabled = isEnabled;
+ this.advancedOptionsSettings_.isEnabled = isEnabled;
},
/**
var settings = event.initialSettings;
this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode;
+ this.isInAppKioskMode_ = settings.isInAppKioskMode;
// The following components must be initialized in this order.
this.appState_.init(
settings.decimalDelimeter,
settings.unitType,
settings.selectionOnly);
- this.destinationStore_.init();
+ this.destinationStore_.init(settings.isInAppKioskMode);
this.appState_.setInitialized();
$('document-title').innerText = settings.documentTitle;
setIsVisible($('system-dialog-link'),
- !settings.hidePrintWithSystemDialogLink);
+ !settings.hidePrintWithSystemDialogLink &&
+ !settings.isInAppKioskMode);
},
/**
this.cloudPrintInterface_ = new cloudprint.CloudPrintInterface(
event.baseCloudPrintUrl,
this.nativeLayer_,
- this.userInfo_);
+ this.userInfo_,
+ event.appKioskMode);
this.tracker.add(
this.cloudPrintInterface_,
cloudprint.CloudPrintInterface.EventType.SUBMIT_DONE,
*/
onCloudPrintError_: function(event) {
if (event.status == 403) {
- this.destinationSearch_.showCloudPrintPromo();
+ if (!this.isInAppKioskMode_) {
+ this.destinationSearch_.showCloudPrintPromo();
+ }
} else if (event.status == 0) {
return; // Ignore, the system does not have internet connectivity.
} else {
onPreviewGenerationDone_: function() {
this.isPreviewGenerationInProgress_ = false;
this.printHeader_.isPrintButtonEnabled = true;
+ this.nativeLayer_.previewReadyForTest();
this.printIfReady_();
},
* @private
*/
onCloudPrintRegisterPromoClick_: function(e) {
- this.metrics_.incrementDestinationSearchBucket(
- print_preview.Metrics.DestinationSearchBucket.REGISTER_PROMO_SELECTED);
var devicesUrl = 'chrome://devices/register?id=' + e.destination.id;
this.nativeLayer_.startForceOpenNewTab(devicesUrl);
this.destinationStore_.waitForRegister(e.destination.id);
// Escape key closes the dialog.
if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey &&
!e.metaKey) {
- if (this.destinationSearch_.getIsVisible()) {
- this.destinationSearch_.setIsVisible(false);
- this.metrics_.incrementDestinationSearchBucket(
- print_preview.Metrics.DestinationSearchBucket.CANCELED);
- } else {
- <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">
- this.close_();
- </if>
- }
+ <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">
+ this.close_();
+ </if>
e.preventDefault();
return;
}
}
if (e.keyCode == 13 /*enter*/ &&
- !this.destinationSearch_.getIsVisible() &&
+ !document.querySelector('.overlay:not([hidden])') &&
this.destinationStore_.selectedDestination &&
this.printTicketStore_.isTicketValid()) {
assert(this.uiState_ == PrintPreview.UiState_.READY,
this.destinationStore_.startLoadCloudDestinations();
this.destinationStore_.startLoadLocalDestinations();
this.destinationStore_.startLoadPrivetDestinations();
- this.metrics_.incrementDestinationSearchBucket(
- print_preview.Metrics.DestinationSearchBucket.SHOWN);
+ },
+
+ /**
+ * Called when the destination settings' change button is activated.
+ * Displays the destination search component.
+ * @private
+ */
+ onAdvancedOptionsButtonActivated_: function() {
+ this.advancedSettings_.showForDestination(
+ this.destinationStore_.selectedDestination);
},
/**
},
/**
+ * Called when the print preview settings need to be changed for testing.
+ * @param {Event} event Event object that contains the option that is to
+ * be changed and what to set that option.
+ * @private
+ */
+ onManipulateSettingsForTest_: function(event) {
+ if ('selectSaveAsPdfDestination' in event.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) {
+ this.setBackgroundColorsAndImagesForTest_(
+ event.settings.backgroundColorsAndImages);
+ } else if ('margins' in event.settings) {
+ this.setMarginsForTest_(event.settings.margins);
+ }
+ },
+
+ /**
+ * Called by onManipulateSettingsForTest_(). Sets the print destination
+ * as a pdf.
+ * @private
+ */
+ saveAsPdfForTest_: function() {
+ if (this.destinationStore_.selectedDestination &&
+ print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ==
+ this.destinationStore_.selectedDestination.id) {
+ this.nativeLayer_.previewReadyForTest();
+ return;
+ }
+
+ var destinations = this.destinationStore_.destinations();
+ var pdfDestination = null;
+ for (var i = 0; i < destinations.length; i++) {
+ if (destinations[i].id ==
+ print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) {
+ pdfDestination = destinations[i];
+ break;
+ }
+ }
+
+ if (pdfDestination)
+ this.destinationStore_.selectDestination(pdfDestination);
+ else
+ this.nativeLayer_.previewFailedForTest();
+ },
+
+ /**
+ * Called by onManipulateSettingsForTest_(). Sets the layout settings to
+ * either portrait or landscape.
+ * @param {boolean} portrait Whether to use portrait page layout;
+ * if false: landscape.
+ * @private
+ */
+ setLayoutSettingsForTest_: function(portrait) {
+ var element = document.querySelector(portrait ?
+ '.layout-settings-portrait-radio' :
+ '.layout-settings-landscape-radio');
+ if (element.checked)
+ this.nativeLayer_.previewReadyForTest();
+ else
+ element.click();
+ },
+
+ /**
+ * Called by onManipulateSettingsForTest_(). Sets the page range for
+ * for the print preview settings.
+ * @param {string} pageRange Sets the page range to the desired value(s).
+ * Ex: "1-5,9" means pages 1 through 5 and page 9 will be printed.
+ * @private
+ */
+ setPageRangeForTest_: function(pageRange) {
+ var textbox = document.querySelector('.page-settings-custom-input');
+ if (textbox.value == pageRange) {
+ this.nativeLayer_.previewReadyForTest();
+ } else {
+ textbox.value = pageRange;
+ document.querySelector('.page-settings-custom-radio').click();
+ }
+ },
+
+ /**
+ * Called by onManipulateSettings_(). Checks or unchecks the headers and
+ * footers option on print preview.
+ * @param {boolean} headersAndFooters Whether the "Headers and Footers"
+ * checkbox should be checked.
+ * @private
+ */
+ setHeadersAndFootersForTest_: function(headersAndFooters) {
+ var checkbox = document.querySelector('.header-footer-checkbox');
+ if (headersAndFooters == checkbox.checked)
+ this.nativeLayer_.previewReadyForTest();
+ else
+ checkbox.click();
+ },
+
+ /**
+ * Called by onManipulateSettings_(). Checks or unchecks the background
+ * colors and images option on print preview.
+ * @param {boolean} backgroundColorsAndImages If true, the checkbox should
+ * be checked. Otherwise it should be unchecked.
+ * @private
+ */
+ setBackgroundColorsAndImagesForTest_: function(backgroundColorsAndImages) {
+ var checkbox = document.querySelector('.css-background-checkbox');
+ if (backgroundColorsAndImages == checkbox.checked)
+ this.nativeLayer_.previewReadyForTest();
+ else
+ checkbox.click();
+ },
+
+ /**
+ * Called by onManipulateSettings_(). Sets the margin settings
+ * that are desired. Custom margin settings aren't currently supported.
+ * @param {number} margins The desired margins combobox index. Must be
+ * a valid index or else the test fails.
+ * @private
+ */
+ setMarginsForTest_: function(margins) {
+ var combobox = document.querySelector('.margin-settings-select');
+ if (margins == combobox.selectedIndex) {
+ this.nativeLayer_.previewReadyForTest();
+ } else if (margins >= 0 && margins < combobox.length) {
+ combobox.selectedIndex = margins;
+ this.marginSettings_.onSelectChange_();
+ } else {
+ this.nativeLayer_.previewFailedForTest();
+ }
+ },
+
+ /**
* Called when the open-cloud-print-dialog link is clicked. Opens the Google
* Cloud Print web dialog.
* @private
setIsVisible(this.getChildElement('#no-destinations-promo'),
isPromoVisible);
if (isPromoVisible) {
- this.metrics_.incrementGcpPromoBucket(
- print_preview.Metrics.GcpPromoBucket.SHOWN);
+ new print_preview.GcpPromoMetricsContext().record(
+ print_preview.Metrics.GcpPromoBucket.PROMO_SHOWN);
}
},
* @private
*/
onNoDestinationsPromoClose_: function() {
- this.metrics_.incrementGcpPromoBucket(
- print_preview.Metrics.GcpPromoBucket.DISMISSED);
+ new print_preview.GcpPromoMetricsContext().record(
+ print_preview.Metrics.GcpPromoBucket.PROMO_CLOSED);
setIsVisible(this.getChildElement('#no-destinations-promo'), false);
this.appState_.persistIsGcpPromoDismissed(true);
},
* @private
*/
onNoDestinationsPromoClick_: function() {
- this.metrics_.incrementGcpPromoBucket(
- print_preview.Metrics.GcpPromoBucket.CLICKED);
+ new print_preview.GcpPromoMetricsContext().record(
+ print_preview.Metrics.GcpPromoBucket.PROMO_CLICKED);
this.appState_.persistIsGcpPromoDismissed(true);
window.open(this.cloudPrintInterface_.baseUrl + '?user=' +
this.userInfo_.activeUser + '#printers');
});
// Pull in all other scripts in a single shot.
+<include src="common/overlay.js"/>
+<include src="common/search_box.js"/>
+
<include src="data/page_number_set.js"/>
<include src="data/destination.js"/>
<include src="data/local_parsers.js"/>
<include src="settings/margin_settings.js"/>
<include src="settings/destination_settings.js"/>
<include src="settings/other_options_settings.js"/>
+<include src="settings/advanced_options_settings.js"/>
+<include src="settings/advanced_settings/advanced_settings.js"/>
+<include src="settings/advanced_settings/advanced_settings_item.js"/>
<include src="previewarea/margin_control.js"/>
<include src="previewarea/margin_control_container.js"/>
<include src="search/recent_destination_list.js"/>
<include src="search/destination_list_item.js"/>
<include src="search/destination_search.js"/>
-<include src="search/search_box.js"/>
<include src="search/fedex_tos.js"/>
window.addEventListener('DOMContentLoaded', function() {