0

PrintPreview:[MAC] Added "Open PDF In Preview" option to open the pdf in native preview app.

BUG=101724
TEST=Preview a webpage. Click "Open PDF In Preview" option Observe that the pdf is displayed in native preview app. Complete the printing workflow by clicking "Print" or
"Cancel" button at the bottom of the preview app.

Review URL: http://codereview.chromium.org/8425008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110398 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
kmadhusu@chromium.org
2011-11-17 00:44:37 +00:00
parent 1bf1b92d64
commit 97c29575ab
11 changed files with 134 additions and 13 deletions

@ -6325,6 +6325,11 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_PRINT_PREVIEW_PRINTING_TO_PDF_IN_PROGRESS" desc="Text shown after the user clicks on the print button while Print To PDF is selected, but the PDF file is not ready yet.">
Printing to PDF in progress
</message>
<if expr="is_macosx">
<message name="IDS_PRINT_PREVIEW_OPENING_PDF_IN_PREVIEW" desc="Text shown after the user clicks on the open pdf in preview button while the pdf file is not ready yet.">
Opening PDF in Preview
</message>
</if>
<message name="IDS_PRINT_PREVIEW_CANCEL_BUTTON" desc="Cancel button.">
Cancel
</message>
@ -6410,8 +6415,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
page
</message>
<message name="IDS_PRINT_PREVIEW_PAGE_LABEL_PLURAL" desc="Label shown in the print preview summary.">
pages
</message>
<if expr="is_macosx">
<message name="IDS_PRINT_PREVIEW_OPEN_PDF_IN_PREVIEW_APP" desc="Option allowing the user to open the pdf in native preview app">
Open PDF in Preview
</message>
</if>
<message name="IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION" desc="Option allowing the user to access advanced printer settings using the native print system dialog instead of printing through the print preview mechanism. Shortcut key is not translated">
Print using system dialog... <ph name="SHORTCUT_KEY">$1<ex>(Shift+Ctrl+P)</ex></ph>
</message>

@ -194,6 +194,14 @@ cr.define('print_preview', function() {
this.overlayLayer.classList.remove('invisible');
},
/**
* Clears the custom message with dots animation.
*/
clearCustomMessageWithDots: function() {
this.customMessageWithDots_.innerHTML = '';
this.customMessageWithDots_.hidden = true;
},
/**
* Display an error message in the center of the preview area.
* @param {string} errorMessage The error message to be displayed.
@ -227,6 +235,8 @@ cr.define('print_preview', function() {
this.errorButton.hidden = false;
$('system-dialog-throbber').hidden = true;
$('native-print-dialog-throbber').hidden = true;
if (cr.isMac)
$('open-preview-app-throbber').hidden = true;
this.displayErrorMessageAndNotify(errorMessage);
}
};

@ -102,7 +102,7 @@ h1 {
font-weight: 300;
}
#system-dialog-link {
.preview-link-button {
-webkit-padding-start: 16px;
outline: 0;
padding-top: 10px;
@ -110,11 +110,11 @@ h1 {
text-align: start;
}
#system-dialog-link:hover:not(:disabled) {
.preview-link-button:hover:not(:disabled) {
text-decoration: underline;
}
#system-dialog-link:disabled {
.preview-link-button:disabled {
color: rgba(0, 0, 0, .5);
cursor: default;
text-shadow: none;

@ -49,15 +49,25 @@
<include src="header_footer_settings.html"></include>
<div>
<if expr="pp_ifdef('chromeos')">
<button id="system-dialog-link" class="link-button"
<button id="system-dialog-link"
class="link-button preview-link-button"
i18n-content="cloudPrintDialogOption"></button>
</if>
<if expr="not pp_ifdef('chromeos')">
<button id="system-dialog-link" class="link-button"
<button id="system-dialog-link"
class="link-button preview-link-button"
i18n-content="systemDialogOption"></button>
</if>
<div id="system-dialog-throbber" class="throbber" hidden></div>
</div>
<if expr="os == 'darwin'">
<div>
<button id="open-pdf-in-preview-link"
class="link-button preview-link-button"
i18n-content="openPdfInPreviewOption"></button>
<div id="open-preview-app-throbber" class="throbber" hidden></div>
</div>
</if>
</div>
</div>
<div id="mainview">

@ -83,6 +83,9 @@ var previewArea;
// dialog.
var showingSystemDialog = false;
// True if the user has clicked 'Open PDF in Preview' option.
var previewAppRequested = false;
// The range of options in the printer dropdown controlled by cloud print.
var firstCloudPrintOptionPos = 0;
var lastCloudPrintOptionPos = firstCloudPrintOptionPos;
@ -151,6 +154,10 @@ function onLoad() {
}
$('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked);
if (cr.isMac) {
$('open-pdf-in-preview-link').addEventListener(
'click', onOpenPdfInPreviewLinkClicked);
}
$('mainview').parentElement.removeChild($('dummy-viewer'));
$('printer-list').disabled = true;
@ -197,6 +204,15 @@ function disableInputElementsInSidebar() {
}
}
/**
* Enables the input elements in the sidebar.
*/
function enableInputElementsInSidebar() {
var els = $('navbar-container').querySelectorAll('input, button, select');
for (var i = 0; i < els.length; i++)
els[i].disabled = false;
}
/**
* Disables the controls in the sidebar, shows the throbber and instructs the
* backend to open the native print dialog.
@ -211,6 +227,20 @@ function onSystemDialogLinkClicked() {
chrome.send('showSystemDialog');
}
/**
* Disables the controls in the sidebar, shows the throbber and instructs the
* backend to open the pdf in native preview app. This is only for Mac.
*/
function onOpenPdfInPreviewLinkClicked() {
if (previewAppRequested)
return;
previewAppRequested = true;
disableInputElementsInSidebar();
$('open-preview-app-throbber').hidden = false;
printHeader.disableCancelButton();
requestToPrintDocument();
}
/**
* Similar to onSystemDialogLinkClicked(), but specific to the
* 'Launch native print dialog' UI.
@ -233,6 +263,9 @@ function updateControlsWithSelectedPrinterCapabilities() {
var selectedIndex = printerList.selectedIndex;
if (selectedIndex < 0)
return;
if (cr.isMac)
$('open-pdf-in-preview-link').disabled = false;
var skip_refresh = false;
var selectedValue = printerList.options[selectedIndex].value;
if (cloudprint.isCloudPrint(printerList.options[selectedIndex])) {
@ -461,7 +494,10 @@ function requestToPrintDocument() {
var printToPDF = selectedPrinterName == PRINT_TO_PDF;
var printWithCloudPrint = selectedPrinterName == PRINT_WITH_CLOUD_PRINT;
if (hasPendingPrintDocumentRequest) {
if (printToPDF) {
if (previewAppRequested) {
previewArea.showCustomMessage(
localStrings.getString('openingPDFInPreview'));
} else if (printToPDF) {
sendPrintDocumentRequest();
} else if (printWithCloudPrint) {
previewArea.showCustomMessage(
@ -474,7 +510,7 @@ function requestToPrintDocument() {
return;
}
if (printToPDF) {
if (printToPDF || previewAppRequested) {
sendPrintDocumentRequest();
} else {
window.setTimeout(function() { sendPrintDocumentRequest(); }, 1000);
@ -496,7 +532,12 @@ function sendPrintDocumentRequest() {
var printerList = $('printer-list');
var printer = printerList[printerList.selectedIndex];
chrome.send('saveLastPrinter', [printer.value, cloudprint.getData(printer)]);
chrome.send('print', [JSON.stringify(getSettings()),
var settings = getSettings();
if (cr.isMac && previewAppRequested)
settings.OpenPDFInPreview = true;
chrome.send('print', [JSON.stringify(settings),
cloudprint.getPrintTicketJSON(printer)]);
}
@ -744,6 +785,16 @@ function printPreviewFailed() {
* Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings().
*/
function invalidPrinterSettings() {
if (cr.isMac) {
if (previewAppRequested) {
$('open-preview-app-throbber').hidden = true;
previewArea.clearCustomMessageWithDots();
previewAppRequested = false;
hasPendingPrintDocumentRequest = false;
enableInputElementsInSidebar();
}
$('open-pdf-in-preview-link').disabled = true;
}
previewArea.displayErrorMessageAndNotify(
localStrings.getString('invalidPrinterSettings'));
}

@ -56,7 +56,10 @@ PrintPreviewDataSource::PrintPreviewDataSource()
AddLocalizedString("printing", IDS_PRINT_PREVIEW_PRINTING);
AddLocalizedString("printingToPDFInProgress",
IDS_PRINT_PREVIEW_PRINTING_TO_PDF_IN_PROGRESS);
#if defined(OS_MACOSX)
AddLocalizedString("openingPDFInPreview",
IDS_PRINT_PREVIEW_OPENING_PDF_IN_PREVIEW);
#endif
AddLocalizedString("destinationLabel", IDS_PRINT_PREVIEW_DESTINATION_LABEL);
AddLocalizedString("copiesLabel", IDS_PRINT_PREVIEW_COPIES_LABEL);
AddLocalizedString("examplePageRangeText",
@ -99,6 +102,10 @@ PrintPreviewDataSource::PrintPreviewDataSource()
shortcut_text));
AddLocalizedString("printWithCloudPrint",
IDS_PRINT_PREVIEW_PRINT_WITH_CLOUD_PRINT);
#endif
#if defined(OS_MACOSX)
AddLocalizedString("openPdfInPreviewOption",
IDS_PRINT_PREVIEW_OPEN_PDF_IN_PREVIEW_APP);
#endif
AddLocalizedString("pageRangeInstruction",
IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION);

@ -401,18 +401,23 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) {
bool print_to_pdf = false;
settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf);
bool open_pdf_in_preview = false;
#if defined(OS_MACOSX)
open_pdf_in_preview = settings->HasKey(printing::kSettingOpenPDFInPreview);
#endif
settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false);
bool is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId);
bool is_cloud_dialog = false;
settings->GetBoolean(printing::kSettingCloudPrintDialog, &is_cloud_dialog);
if (is_cloud_printer) {
if (is_cloud_printer && !open_pdf_in_preview) {
std::string print_ticket;
args->GetString(1, &print_ticket);
SendCloudPrintJob(*settings, print_ticket);
} else if (print_to_pdf) {
} else if (print_to_pdf && !open_pdf_in_preview) {
HandlePrintToPdf(*settings);
} else if (is_cloud_dialog) {
} else if (is_cloud_dialog && !open_pdf_in_preview) {
HandlePrintWithCloudPrint();
} else {
ReportPrintSettingsStats(*settings);

@ -123,6 +123,10 @@ const char kSettingPrintToPDF[] = "printToPDF";
const int FIRST_PAGE_INDEX = 0;
const int COMPLETE_PREVIEW_DOCUMENT_INDEX = -1;
#if defined(OS_MACOSX)
const char kSettingOpenPDFInPreview[] = "OpenPDFInPreview";
#endif
#if defined (USE_CUPS)
const char kBlack[] = "Black";
const char kCMYK[] = "CMYK";

@ -5,6 +5,7 @@
#ifndef PRINTING_PRINT_JOB_CONSTANTS_H_
#define PRINTING_PRINT_JOB_CONSTANTS_H_
#include "build/build_config.h"
#include "printing/printing_export.h"
namespace printing {
@ -49,6 +50,10 @@ PRINTING_EXPORT extern const char kSettingPrintToPDF[];
PRINTING_EXPORT extern const int FIRST_PAGE_INDEX;
PRINTING_EXPORT extern const int COMPLETE_PREVIEW_DOCUMENT_INDEX;
#if defined(OS_MACOSX)
PRINTING_EXPORT extern const char kSettingOpenPDFInPreview[];
#endif // defined(OS_MACOSX)
#if defined (USE_CUPS)
// Printer color models
PRINTING_EXPORT extern const char kBlack[];

@ -61,6 +61,10 @@ class PRINTING_EXPORT PrintingContextMac : public PrintingContext {
// Returns true if the paper was set else returns false.
bool UpdatePageFormatWithPaperInfo();
// Sets the print job destination type as preview job.
// Returns true if the print job destination type is set.
bool SetPrintPreviewJob();
// Sets |copies| in PMPrintSettings.
// Returns true if the number of copies is set.
bool SetCopiesInPrintSettings(int copies);

@ -124,6 +124,7 @@ PrintingContext::Result PrintingContextMac::UpdatePrinterSettings(
}
bool print_to_cloud = job_settings.HasKey(kSettingCloudPrintId);
bool open_pdf_in_preview = job_settings.HasKey(kSettingOpenPDFInPreview);
if (!print_to_pdf && !print_to_cloud && !is_cloud_dialog) {
if (!SetPrinter(device_name))
@ -143,6 +144,11 @@ PrintingContext::Result PrintingContextMac::UpdatePrinterSettings(
if (!SetOutputColor(color))
return OnError();
}
if (open_pdf_in_preview) {
if (!SetPrintPreviewJob())
return OnError();
}
if (!UpdatePageFormatWithPaperInfo())
return OnError();
@ -155,6 +161,16 @@ PrintingContext::Result PrintingContextMac::UpdatePrinterSettings(
return OK;
}
bool PrintingContextMac::SetPrintPreviewJob() {
PMPrintSession print_session =
static_cast<PMPrintSession>([print_info_.get() PMPrintSession]);
PMPrintSettings print_settings =
static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]);
return PMSessionSetDestination(
print_session, print_settings, kPMDestinationPreview,
NULL, NULL) == noErr;
}
void PrintingContextMac::InitPrintSettingsFromPrintInfo(
const PageRanges& ranges) {
PMPrintSession print_session =