Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1860)

Unified Diff: chrome/browser/resources/print_preview/print_preview.js

Issue 7544018: Print preview page selection should not require a rerendering of draft pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix style Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/print_preview/page_settings.js ('k') | chrome/common/print_messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 47c455d1bbe3752074401d25d87bb44b1681269b..27f6257a5f9d883ff60dbc41dc06029cf75396d9 100644
--- a/chrome/browser/resources/print_preview/print_preview.js
+++ b/chrome/browser/resources/print_preview/print_preview.js
@@ -24,6 +24,9 @@ const MORE_PRINTERS = 'morePrinters';
const SIGN_IN = 'signIn';
const PRINT_TO_PDF = 'Print to PDF';
+// Print ready data index.
+const PRINT_READY_DATA_INDEX = -1;
+
// State of the print preview settings.
var printSettings = new PrintSettings();
@@ -62,6 +65,11 @@ var showingSystemDialog = false;
var firstCloudPrintOptionPos = 0;
var lastCloudPrintOptionPos = firstCloudPrintOptionPos;
+// Store the current previewUid.
+var currentPreviewUid = '';
+
+// True if we need to generate draft preview data.
+var generateDraftData = true;
// TODO(abodenha@chromium.org) A lot of cloud print specific logic has
// made its way into this file. Refactor to create a cleaner boundary
@@ -311,7 +319,8 @@ function getSettings() {
'landscape': layoutSettings.isLandscape(),
'color': colorSettings.isColor(),
'printToPDF': printToPDF,
- 'requestID': 0};
+ 'requestID': 0,
+ 'generateDraftData': generateDraftData};
var printerList = $('printer-list');
var selectedPrinter = printerList.selectedIndex;
@@ -421,15 +430,42 @@ function sendPrintDocumentRequest() {
}
/**
+ * Loads the selected preview pages.
+ */
+function loadSelectedPages() {
+ hasPendingPreviewRequest = false;
+ pageSettings.updatePageSelection();
+ var pageSet = pageSettings.previouslySelectedPages;
+ var pageCount = pageSet.length;
+ if (pageCount == 0 || currentPreviewUid == '')
+ return;
+
+ for (var i = 0; i < pageCount; i++)
+ onDidPreviewPage(pageSet[i] - 1, currentPreviewUid);
+ addEventListeners();
+}
+
+/**
* Asks the browser to generate a preview PDF based on current print settings.
*/
function requestPrintPreview() {
hasPendingPreviewRequest = true;
removeEventListeners();
printSettings.save();
+ generateDraftData = true;
if (!isTabHidden)
showLoadingAnimation();
+ if (previewModifiable && hasOnlyPageSettingsChanged()) {
+ loadSelectedPages();
+ generateDraftData = false;
+ } else {
+ pageSettings.updatePageSelection();
+ }
+
+ if (!previewModifiable && pageSettings.totalPageCount > 0)
+ generateDraftData = false;
+
var settings = getSettings();
settings.requestID = generatePreviewRequestID();
chrome.send('getPreview', [JSON.stringify(settings)]);
@@ -829,12 +865,16 @@ function onDidPreviewPage(pageNumber, previewUid) {
if (!previewModifiable)
return;
- var pageIndex = pageSettings.previouslySelectedPages.indexOf(pageNumber + 1);
-
if (checkIfSettingsChangedAndRegeneratePreview())
return;
+
+ var pageIndex = pageSettings.previouslySelectedPages.indexOf(pageNumber + 1);
+ if (pageIndex == -1)
+ return;
+
+ currentPreviewUid = previewUid;
if (pageIndex == 0)
- createPDFPlugin(previewUid);
+ createPDFPlugin(pageNumber);
$('pdf-viewer').loadPreviewPage(
getPageSrcURL(previewUid, pageNumber), pageIndex);
@@ -864,7 +904,8 @@ function updatePrintPreview(jobTitle,
if (!previewModifiable) {
// If the preview is not modifiable the plugin has not been created yet.
- createPDFPlugin(previewUid);
+ currentPreviewUid = previewUid;
+ createPDFPlugin(PRINT_READY_DATA_INDEX);
}
cr.dispatchSimpleEvent(document, 'updateSummary');
@@ -898,28 +939,41 @@ function checkIfSettingsChangedAndRegeneratePreview() {
}
/**
+ * Check if only page selection has been changed since the last preview request
+ * and is valid.
+ * @return {boolean} true if the new page selection is valid.
+ */
+function hasOnlyPageSettingsChanged() {
+ var tempPrintSettings = new PrintSettings();
+ tempPrintSettings.save();
+
+ return !!(printSettings.deviceName == tempPrintSettings.deviceName &&
+ printSettings.isLandscape == tempPrintSettings.isLandscape &&
+ pageSettings.hasPageSelectionChangedAndIsValid());
+}
+
+/**
* Create the PDF plugin or reload the existing one.
- * @param {string} previewUid Preview unique identifier.
+ * @param {number} srcDataIndex Preview data source index.
*/
-function createPDFPlugin(previewUid) {
+function createPDFPlugin(srcDataIndex) {
var pdfViewer = $('pdf-viewer');
+ var srcURL = getPageSrcURL(currentPreviewUid, srcDataIndex);
if (pdfViewer) {
// Need to call this before the reload(), where the plugin resets its
// internal page count.
pdfViewer.goToPage('0');
+ pdfViewer.resetPrintPreviewUrl(srcURL);
pdfViewer.reload();
pdfViewer.grayscale(!colorSettings.isColor());
return;
}
- // Get the complete preview document.
- var dataIndex = previewModifiable ? '0' : '-1';
-
pdfViewer = document.createElement('embed');
pdfViewer.setAttribute('id', 'pdf-viewer');
pdfViewer.setAttribute('type',
'application/x-google-chrome-print-preview-pdf');
- pdfViewer.setAttribute('src', getPageSrcURL(previewUid, dataIndex));
+ pdfViewer.setAttribute('src', srcURL);
pdfViewer.setAttribute('aria-live', 'polite');
pdfViewer.setAttribute('aria-atomic', 'true');
$('mainview').appendChild(pdfViewer);
@@ -937,7 +991,8 @@ function checkCompatiblePluginExists() {
dummyPlugin.goToPage &&
dummyPlugin.removePrintButton &&
dummyPlugin.loadPreviewPage &&
- dummyPlugin.printPreviewPageCount);
+ dummyPlugin.printPreviewPageCount &&
+ dummyPlugin.resetPrintPreviewUrl);
}
window.addEventListener('DOMContentLoaded', onLoad);
« no previous file with comments | « chrome/browser/resources/print_preview/page_settings.js ('k') | chrome/common/print_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698