Add options to custom print settings in printToPDF API.
This commit is contained in:
parent
9cf9229308
commit
ce8bbb689c
6 changed files with 40 additions and 11 deletions
|
@ -16,6 +16,7 @@
|
||||||
#include "native_mate/callback.h"
|
#include "native_mate/callback.h"
|
||||||
#include "native_mate/constructor.h"
|
#include "native_mate/constructor.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
#include "printing/print_job_constants.h"
|
||||||
#include "ui/gfx/geometry/rect.h"
|
#include "ui/gfx/geometry/rect.h"
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
@ -430,8 +431,13 @@ void Window::Print(mate::Arguments* args) {
|
||||||
window_->Print(settings.silent, settings.print_background);
|
window_->Print(settings.silent, settings.print_background);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::PrintToPDF() {
|
void Window::PrintToPDF(mate::Arguments* args) {
|
||||||
window_->PrintToPDF();
|
mate::Dictionary options;
|
||||||
|
if (args->Length() == 1 && !args->GetNext(&options)) {
|
||||||
|
args->ThrowError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window_->PrintToPDF(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::SetProgressBar(double progress) {
|
void Window::SetProgressBar(double progress) {
|
||||||
|
|
|
@ -132,7 +132,7 @@ class Window : public mate::EventEmitter,
|
||||||
bool IsDocumentEdited();
|
bool IsDocumentEdited();
|
||||||
void CapturePage(mate::Arguments* args);
|
void CapturePage(mate::Arguments* args);
|
||||||
void Print(mate::Arguments* args);
|
void Print(mate::Arguments* args);
|
||||||
void PrintToPDF();
|
void PrintToPDF(mate::Arguments* args);
|
||||||
void SetProgressBar(double progress);
|
void SetProgressBar(double progress);
|
||||||
void SetOverlayIcon(const gfx::Image& overlay,
|
void SetOverlayIcon(const gfx::Image& overlay,
|
||||||
const std::string& description);
|
const std::string& description);
|
||||||
|
|
|
@ -265,9 +265,9 @@ void NativeWindow::Print(bool silent, bool print_background) {
|
||||||
PrintNow(silent, print_background);
|
PrintNow(silent, print_background);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::PrintToPDF() {
|
void NativeWindow::PrintToPDF(const mate::Dictionary& options) {
|
||||||
printing::PrintPreviewMessageHandler::FromWebContents(GetWebContents())->
|
printing::PrintPreviewMessageHandler::FromWebContents(GetWebContents())->
|
||||||
HandleGetPreview(NULL);
|
HandleGetPreview(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::ShowDefinitionForSelection() {
|
void NativeWindow::ShowDefinitionForSelection() {
|
||||||
|
|
|
@ -158,7 +158,7 @@ class NativeWindow : public CommonWebContentsDelegate,
|
||||||
virtual void Print(bool silent, bool print_background);
|
virtual void Print(bool silent, bool print_background);
|
||||||
|
|
||||||
// Print current page as PDF.
|
// Print current page as PDF.
|
||||||
virtual void PrintToPDF();
|
virtual void PrintToPDF(const mate::Dictionary& options);
|
||||||
|
|
||||||
// Show popup dictionary.
|
// Show popup dictionary.
|
||||||
virtual void ShowDefinitionForSelection();
|
virtual void ShowDefinitionForSelection();
|
||||||
|
|
|
@ -199,7 +199,8 @@ bool PrintPreviewMessageHandler::OnMessageReceived(
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintPreviewMessageHandler::HandleGetPreview(const base::ListValue* args) {
|
void PrintPreviewMessageHandler::HandleGetPreview(
|
||||||
|
const mate::Dictionary& options) {
|
||||||
static int request_id = 0;
|
static int request_id = 0;
|
||||||
request_id++;
|
request_id++;
|
||||||
// A simulated Chromium print preivew setting.
|
// A simulated Chromium print preivew setting.
|
||||||
|
@ -212,7 +213,7 @@ void PrintPreviewMessageHandler::HandleGetPreview(const base::ListValue* args) {
|
||||||
\"width_microns\":210000, \
|
\"width_microns\":210000, \
|
||||||
\"custom_display_name\":\"A4\" \
|
\"custom_display_name\":\"A4\" \
|
||||||
}, \
|
}, \
|
||||||
\"landscape\":true, \
|
\"landscape\":false, \
|
||||||
\"color\":2, \
|
\"color\":2, \
|
||||||
\"headerFooterEnabled\":false, \
|
\"headerFooterEnabled\":false, \
|
||||||
\"marginsType\":0, \
|
\"marginsType\":0, \
|
||||||
|
@ -229,7 +230,7 @@ void PrintPreviewMessageHandler::HandleGetPreview(const base::ListValue* args) {
|
||||||
\"duplex\":0, \
|
\"duplex\":0, \
|
||||||
\"copies\":1, \
|
\"copies\":1, \
|
||||||
\"collate\":true, \
|
\"collate\":true, \
|
||||||
\"shouldPrintBackgrounds\":true, \
|
\"shouldPrintBackgrounds\":false, \
|
||||||
\"shouldPrintSelectionOnly\":false \
|
\"shouldPrintSelectionOnly\":false \
|
||||||
}";
|
}";
|
||||||
|
|
||||||
|
@ -237,7 +238,26 @@ void PrintPreviewMessageHandler::HandleGetPreview(const base::ListValue* args) {
|
||||||
static_cast<base::DictionaryValue*>(
|
static_cast<base::DictionaryValue*>(
|
||||||
base::JSONReader::Read(setting_json_str)));
|
base::JSONReader::Read(setting_json_str)));
|
||||||
settings->SetInteger(printing::kPreviewRequestID, request_id);
|
settings->SetInteger(printing::kPreviewRequestID, request_id);
|
||||||
|
// Default Print PDF settings:
|
||||||
|
int margins_type = 0; // DEFAULT_MARGINS
|
||||||
|
bool print_background = false;
|
||||||
|
bool print_selection_only = false;
|
||||||
|
bool is_landscape = false; // layout: true for portrait, false for landscape
|
||||||
|
|
||||||
|
if (!options.IsEmpty()) {
|
||||||
|
options.Get(printing::kSettingMarginsType, &margins_type);
|
||||||
|
options.Get(printing::kSettingShouldPrintBackgrounds, &print_background);
|
||||||
|
options.Get(printing::kSettingShouldPrintSelectionOnly,
|
||||||
|
&print_selection_only);
|
||||||
|
std::string layout;
|
||||||
|
options.Get("layout", &is_landscape);
|
||||||
|
}
|
||||||
|
settings->SetInteger(printing::kSettingMarginsType, margins_type);
|
||||||
|
settings->SetBoolean(printing::kSettingShouldPrintBackgrounds,
|
||||||
|
print_background);
|
||||||
|
settings->SetBoolean(printing::kSettingShouldPrintSelectionOnly,
|
||||||
|
print_selection_only);
|
||||||
|
settings->SetBoolean(printing::kSettingLandscape, is_landscape);
|
||||||
LOG(ERROR) << "Print preview request start";
|
LOG(ERROR) << "Print preview request start";
|
||||||
content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
|
content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
|
||||||
rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings));
|
rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings));
|
||||||
|
|
|
@ -17,6 +17,10 @@ namespace content {
|
||||||
class WebContents;
|
class WebContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace mate {
|
||||||
|
class Dictionary;
|
||||||
|
}
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
class Rect;
|
class Rect;
|
||||||
}
|
}
|
||||||
|
@ -37,8 +41,7 @@ class PrintPreviewMessageHandler
|
||||||
|
|
||||||
// Asks the initiator renderer to generate a preview. First element of |args|
|
// Asks the initiator renderer to generate a preview. First element of |args|
|
||||||
// is a job settings JSON string.
|
// is a job settings JSON string.
|
||||||
void HandleGetPreview(const base::ListValue* args);
|
void HandleGetPreview(const mate::Dictionary& options);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit PrintPreviewMessageHandler(content::WebContents* web_contents);
|
explicit PrintPreviewMessageHandler(content::WebContents* web_contents);
|
||||||
friend class content::WebContentsUserData<PrintPreviewMessageHandler>;
|
friend class content::WebContentsUserData<PrintPreviewMessageHandler>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue