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 135257e40e8d690d10a94ea80bf0ca080371ff51..9c8b9fe28ce7e13a7b4ca3f24196616385b6087e 100644 |
--- a/chrome/browser/resources/print_preview/print_preview.js |
+++ b/chrome/browser/resources/print_preview/print_preview.js |
@@ -103,6 +103,26 @@ const maxCloudPrinters = 10; |
const MIN_REQUEST_ID = 0; |
const MAX_REQUEST_ID = 32000; |
+// Names of all the custom events used. |
+var customEvents = { |
+ // Fired when the mouse moves while a margin line is being dragged. |
+ MARGINS_LINE_DRAG: 'marginsLineDrag', |
Evan Stade
2011/10/26 23:16:28
no S
|
+ // Fired when a mousedown event occurs on a margin line. |
+ MARGINS_LINE_MOUSE_DOWN: 'marginsLineMouseDown', |
+ // Fired when a new preview might be needed because of margin changes. |
+ MARGINS_MAY_HAVE_CHANGED: 'marginsMayHaveChanged', |
+ // Fired when a pdf generation related error occurs. |
+ PDF_GENERATION_ERROR: 'PDFGenerationError', |
+ // Fired once the first page of the pdf document is loaded in the plugin. |
+ PDF_LOADED: 'PDFLoaded', |
+ // Fired when the selected printer capabilities change. |
+ PRINTER_CAPABILITIES_UPDATED: 'printerCapabilitiesUpdated', |
+ // Fired when the print button needs to be updated. |
+ UPDATE_PRINT_BUTTON: 'updatePrintButton', |
+ // Fired when the print summary needs to be updated. |
+ UPDATE_SUMMARY: 'updateSummary', |
+} |
+ |
/** |
* Window onload handler, sets up the page and starts print preview by getting |
* the printer list. |
@@ -114,7 +134,8 @@ function onLoad() { |
previewArea = print_preview.PreviewArea.getInstance(); |
printHeader = print_preview.PrintHeader.getInstance(); |
- document.addEventListener('PDFGenerationError', cancelPendingPrintRequest); |
+ document.addEventListener(customEvents.PDF_GENERATION_ERROR, |
+ cancelPendingPrintRequest); |
if (!checkCompatiblePluginExists()) { |
disableInputElementsInSidebar(); |
@@ -282,11 +303,12 @@ function doUpdateCloudPrinterCapabilities(printer) { |
} |
/** |
- * Updates the controls with printer capabilities information. |
+ * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the |
+ * capabilities of the currently selected printer. It is called from C++ too. |
* @param {Object} settingInfo printer setting information. |
*/ |
function updateWithPrinterCapabilities(settingInfo) { |
- var customEvent = new cr.Event("printerCapabilitiesUpdated"); |
+ var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); |
customEvent.printerCapabilities = settingInfo; |
document.dispatchEvent(customEvent); |
} |
@@ -488,7 +510,7 @@ function loadSelectedPages() { |
if (pageCount == 0 || currentPreviewUid == '') |
return; |
- cr.dispatchSimpleEvent(document, 'updateSummary'); |
+ cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
for (var i = 0; i < pageCount; i++) |
onDidPreviewPage(pageSet[i] - 1, currentPreviewUid, lastPreviewRequestID); |
} |
@@ -733,7 +755,7 @@ function onPDFLoad() { |
if (previewModifiable) { |
setPluginPreviewPageCount(); |
} |
- cr.dispatchSimpleEvent(document, 'PDFLoaded'); |
+ cr.dispatchSimpleEvent(document, customEvents.PDF_LOADED); |
isFirstPageLoaded = true; |
checkAndHideOverlayLayerIfValid(); |
sendPrintDocumentRequestIfNeeded(); |
@@ -761,7 +783,7 @@ function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { |
if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) |
return; |
- cr.dispatchSimpleEvent(document, 'updateSummary'); |
+ cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
} |
/** |
@@ -804,7 +826,7 @@ function reloadPreviewPages(previewUid, previewResponseId) { |
if (!isExpectedPreviewResponse(previewResponseId)) |
return; |
- cr.dispatchSimpleEvent(document, 'updatePrintButton'); |
+ cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); |
checkAndHideOverlayLayerIfValid(); |
var pageSet = pageSettings.previouslySelectedPages; |
for (var i = 0; i < pageSet.length; i++) |
@@ -875,7 +897,7 @@ function updatePrintPreview(previewUid, previewResponseId) { |
createPDFPlugin(PRINT_READY_DATA_INDEX); |
} |
- cr.dispatchSimpleEvent(document, 'updatePrintButton'); |
+ cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); |
if (previewModifiable) |
sendPrintDocumentRequestIfNeeded(); |
} |