| Index: chrome/browser/resources/print_preview/print_preview.js
|
| diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js
|
| index 3d4be808bf5eb5eaf0a99f29f282710a141bd2d0..8f302f99ac4f81ac05fd0259e6b315b502dbe0cb 100644
|
| --- a/chrome/browser/resources/print_preview/print_preview.js
|
| +++ b/chrome/browser/resources/print_preview/print_preview.js
|
| @@ -71,6 +71,8 @@ var headerFooterSettings;
|
| // Object holding all the color related settings.
|
| var colorSettings;
|
|
|
| +var previewArea;
|
| +
|
| // True if the user has click 'Advanced...' in order to open the system print
|
| // dialog.
|
| var showingSystemDialog = false;
|
| @@ -125,6 +127,7 @@ function onLoad() {
|
| marginSettings = print_preview.MarginSettings.getInstance();
|
| headerFooterSettings = print_preview.HeaderFooterSettings.getInstance();
|
| colorSettings = print_preview.ColorSettings.getInstance();
|
| + previewArea = print_preview.PreviewArea.getInstance();
|
| printHeader.addEventListeners();
|
| pageSettings.addEventListeners();
|
| copiesSettings.addEventListeners();
|
| @@ -132,6 +135,7 @@ function onLoad() {
|
| layoutSettings.addEventListeners();
|
| marginSettings.addEventListeners();
|
| colorSettings.addEventListeners();
|
| + previewArea.addEventListeners();
|
| $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities;
|
|
|
| showLoadingAnimation();
|
| @@ -312,9 +316,9 @@ function finishedCloudPrinting() {
|
| */
|
| function areSettingsValid() {
|
| var selectedPrinter = getSelectedPrinterName();
|
| - return pageSettings.isPageSelectionValid() &&
|
| - (copiesSettings.isValid() ||
|
| - selectedPrinter == PRINT_TO_PDF ||
|
| + return pageSettings.isPageSelectionValid()
|
| + && marginSettings.areMarginSettingsValid() &&
|
| + (copiesSettings.isValid() || selectedPrinter == PRINT_TO_PDF ||
|
| selectedPrinter == PRINT_WITH_CLOUD_PRINT);
|
| }
|
|
|
| @@ -496,6 +500,7 @@ function requestPrintPreview() {
|
|
|
| printSettings.save();
|
| layoutSettings.updateState();
|
| + previewArea.resetState();
|
| isPrintReadyMetafileReady = false;
|
| isFirstPageLoaded = false;
|
|
|
| @@ -673,6 +678,7 @@ function addDestinationListOptionAtPosition(position,
|
| printerList.add(option, before);
|
| return option;
|
| }
|
| +
|
| /**
|
| * Sets the color mode for the PDF plugin.
|
| * Called from PrintPreviewHandler::ProcessColorSetting().
|
| @@ -754,7 +760,6 @@ function onPDFLoad() {
|
| if (previewModifiable) {
|
| setPluginPreviewPageCount();
|
| }
|
| - $('pdf-viewer').fitToHeight();
|
| cr.dispatchSimpleEvent(document, 'PDFLoaded');
|
| isFirstPageLoaded = true;
|
| checkAndHideOverlayLayerIfValid();
|
| @@ -786,8 +791,18 @@ function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) {
|
| cr.dispatchSimpleEvent(document, 'updateSummary');
|
| }
|
|
|
| +/**
|
| + * @param {printing::PageSizeMargins} pageLayout The default layout of the page
|
| + * in points.
|
| + */
|
| function onDidGetDefaultPageLayout(pageLayout) {
|
| - // TODO(aayushkumar): Do something here!
|
| + marginSettings.currentDefaultPageLayout = new print_preview.PageLayout(
|
| + pageLayout.contentWidth,
|
| + pageLayout.contentHeight,
|
| + pageLayout.marginLeft,
|
| + pageLayout.marginTop,
|
| + pageLayout.marginRight,
|
| + pageLayout.marginBottom);
|
| }
|
|
|
| /**
|
| @@ -963,21 +978,48 @@ function createPDFPlugin(srcDataIndex) {
|
| pdfViewer.setAttribute('aria-atomic', 'true');
|
| $('mainview').appendChild(pdfViewer);
|
| pdfViewer.onload('onPDFLoad()');
|
| + pdfViewer.onScroll('onPreviewPositionChanged()');
|
| + pdfViewer.onPluginSizeChanged('onPreviewPositionChanged()');
|
| pdfViewer.removePrintButton();
|
| pdfViewer.grayscale(true);
|
| }
|
|
|
| /**
|
| + * Called either when there is a scroll event or when the plugin size changes.
|
| + */
|
| +function onPreviewPositionChanged() {
|
| + marginSettings.onPreviewPositionChanged();
|
| +}
|
| +
|
| +/**
|
| * @return {boolean} true if a compatible pdf plugin exists.
|
| */
|
| function checkCompatiblePluginExists() {
|
| - var dummyPlugin = $('dummy-viewer')
|
| - return !!(dummyPlugin.onload &&
|
| - dummyPlugin.goToPage &&
|
| - dummyPlugin.removePrintButton &&
|
| - dummyPlugin.loadPreviewPage &&
|
| - dummyPlugin.printPreviewPageCount &&
|
| - dummyPlugin.resetPrintPreviewUrl);
|
| + var dummyPlugin = $('dummy-viewer');
|
| + var pluginInterface = [ dummyPlugin.onload,
|
| + dummyPlugin.goToPage,
|
| + dummyPlugin.removePrintButton,
|
| + dummyPlugin.loadPreviewPage,
|
| + dummyPlugin.printPreviewPageCount,
|
| + dummyPlugin.resetPrintPreviewUrl,
|
| + dummyPlugin.onPluginSizeChanged,
|
| + dummyPlugin.onScroll,
|
| + dummyPlugin.pageXOffset,
|
| + dummyPlugin.pageYOffset,
|
| + dummyPlugin.setZoomLevel,
|
| + dummyPlugin.setPageXOffset,
|
| + dummyPlugin.setPageYOffset,
|
| + dummyPlugin.getHorizontalScrollbarThickness,
|
| + dummyPlugin.getVerticalScrollbarThickness,
|
| + dummyPlugin.getPageLocationNormalized,
|
| + dummyPlugin.getHeight,
|
| + dummyPlugin.getWidth ];
|
| +
|
| + for (var i = 0; i < pluginInterface.length; i++) {
|
| + if (!pluginInterface[i])
|
| + return false;
|
| + }
|
| + return true;
|
| }
|
|
|
| window.addEventListener('DOMContentLoaded', onLoad);
|
| @@ -1035,3 +1077,8 @@ function setInitiatorTabTitle(initiatorTabTitle) {
|
| <include src="layout_settings.js"/>
|
| <include src="color_settings.js"/>
|
| <include src="margin_settings.js"/>
|
| +<include src="margin_textbox.js"/>
|
| +<include src="margin_line.js"/>
|
| +<include src="margin_utils.js"/>
|
| +<include src="margins_ui.js"/>
|
| +<include src="preview_area.js"/>
|
|
|