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..66caf7a6cc7ead7cb14f522c5d57bd3ec74f7a13 100644 |
--- a/chrome/browser/resources/print_preview/print_preview.js |
+++ b/chrome/browser/resources/print_preview/print_preview.js |
@@ -53,24 +53,29 @@ var isPrintReadyMetafileReady = false; |
// True when preview tab is hidden. |
var isTabHidden = false; |
-// Object holding all the pages related settings. |
+// @type {print_preview.PageSettings} Holds all the pages related settings. |
var pageSettings; |
-// Object holding all the copies related settings. |
+// @type {print_preview.CopiesSettings} Holds all the copies related settings. |
var copiesSettings; |
-// Object holding all the layout related settings. |
+// @type {print_preview.LayoutSettings} Holds all the layout related settings. |
var layoutSettings; |
-// Object holding all the margin related settings. |
+// @type {print_preview.MarginSettings} Holds all the margin related settings. |
var marginSettings; |
-// Object holding all the header footer related settings. |
+// @type {print_preview.HeaderFooterSettings} Holds all the header footer |
+// related settings. |
var headerFooterSettings; |
-// Object holding all the color related settings. |
+// @type {print_preview.ColorSettings} Holds all the color related settings. |
var colorSettings; |
+// @type {print_preview.PreviewArea} Holds information related to the preview |
+// area (on the right). |
+var previewArea; |
+ |
// True if the user has click 'Advanced...' in order to open the system print |
// dialog. |
var showingSystemDialog = false; |
@@ -125,6 +130,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 +138,7 @@ function onLoad() { |
layoutSettings.addEventListeners(); |
marginSettings.addEventListeners(); |
colorSettings.addEventListeners(); |
+ previewArea.addEventListeners(); |
$('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
showLoadingAnimation(); |
@@ -313,8 +320,8 @@ function finishedCloudPrinting() { |
function areSettingsValid() { |
var selectedPrinter = getSelectedPrinterName(); |
return pageSettings.isPageSelectionValid() && |
- (copiesSettings.isValid() || |
- selectedPrinter == PRINT_TO_PDF || |
+ marginSettings.areMarginSettingsValid() && |
+ (copiesSettings.isValid() || selectedPrinter == PRINT_TO_PDF || |
selectedPrinter == PRINT_WITH_CLOUD_PRINT); |
} |
@@ -496,6 +503,7 @@ function requestPrintPreview() { |
printSettings.save(); |
layoutSettings.updateState(); |
+ previewArea.resetState(); |
isPrintReadyMetafileReady = false; |
isFirstPageLoaded = false; |
@@ -673,6 +681,7 @@ function addDestinationListOptionAtPosition(position, |
printerList.add(option, before); |
return option; |
} |
+ |
/** |
* Sets the color mode for the PDF plugin. |
* Called from PrintPreviewHandler::ProcessColorSetting(). |
@@ -754,7 +763,6 @@ function onPDFLoad() { |
if (previewModifiable) { |
setPluginPreviewPageCount(); |
} |
- $('pdf-viewer').fitToHeight(); |
cr.dispatchSimpleEvent(document, 'PDFLoaded'); |
isFirstPageLoaded = true; |
checkAndHideOverlayLayerIfValid(); |
@@ -786,8 +794,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 +981,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, |
Evan Stade
2011/10/05 22:42:14
I don't see anything wrong with the old format, wh
dpapad
2011/10/06 00:05:39
Because this way is much easier to find which func
Evan Stade
2011/10/07 03:29:58
I suggest you leave the console.log there.
|
+ 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 +1080,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"/> |