Move PDF printing setting in JS part.
This commit is contained in:
parent
c0a6cb69bf
commit
6e099af5fe
6 changed files with 64 additions and 83 deletions
|
@ -582,6 +582,7 @@ void WebContents::UnregisterServiceWorker(
|
|||
callback);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
void WebContents::SetAudioMuted(bool muted) {
|
||||
web_contents()->SetAudioMuted(muted);
|
||||
|
@ -591,18 +592,10 @@ bool WebContents::IsAudioMuted() {
|
|||
return web_contents()->IsAudioMuted();
|
||||
}
|
||||
|
||||
void WebContents::PrintToPDF(mate::Arguments* args) {
|
||||
mate::Dictionary options;
|
||||
base::Callback<void(int)> callback;
|
||||
if (!(args->Length() == 1 && args->GetNext(&callback)) &&
|
||||
!(args->Length() == 2 && args->GetNext(&options)
|
||||
&& args->GetNext(&callback))) {
|
||||
args->ThrowError();
|
||||
return;
|
||||
}
|
||||
|
||||
void WebContents::PrintToPDF(const base::DictionaryValue& setting,
|
||||
const PrintToPDFCallback& callback) {
|
||||
printing::PrintPreviewMessageHandler::FromWebContents(web_contents())->
|
||||
PrintToPDF(options, callback);
|
||||
PrintToPDF(setting, callback);
|
||||
}
|
||||
|
||||
void WebContents::Undo() {
|
||||
|
@ -777,7 +770,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
|||
.SetMethod("unregisterServiceWorker",
|
||||
&WebContents::UnregisterServiceWorker)
|
||||
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
|
||||
.SetMethod("printToPDF", &WebContents::PrintToPDF)
|
||||
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
||||
.Build());
|
||||
|
||||
return mate::ObjectTemplateBuilder(
|
||||
|
|
|
@ -52,6 +52,8 @@ class WebContents : public mate::EventEmitter,
|
|||
public content::WebContentsObserver,
|
||||
public content::GpuDataManagerObserver {
|
||||
public:
|
||||
typedef base::Callback<void(int)> PrintToPDFCallback;
|
||||
|
||||
// Create from an existing WebContents.
|
||||
static mate::Handle<WebContents> CreateFrom(
|
||||
v8::Isolate* isolate, brightray::InspectableWebContents* web_contents);
|
||||
|
@ -91,7 +93,8 @@ class WebContents : public mate::EventEmitter,
|
|||
bool IsAudioMuted();
|
||||
|
||||
// Print current page as PDF.
|
||||
void PrintToPDF(mate::Arguments* args);
|
||||
void PrintToPDF(const base::DictionaryValue& setting,
|
||||
const PrintToPDFCallback& callback);
|
||||
|
||||
// Editing commands.
|
||||
void Undo();
|
||||
|
|
|
@ -3,6 +3,9 @@ NavigationController = require './navigation-controller'
|
|||
binding = process.atomBinding 'web_contents'
|
||||
ipc = require 'ipc'
|
||||
|
||||
nextId = 0
|
||||
getNextId = -> ++nextId
|
||||
|
||||
wrapWebContents = (webContents) ->
|
||||
# webContents is an EventEmitter.
|
||||
webContents.__proto__ = EventEmitter.prototype
|
||||
|
@ -58,6 +61,46 @@ wrapWebContents = (webContents) ->
|
|||
Object.defineProperty event, 'sender', value: webContents
|
||||
ipc.emit channel, event, args...
|
||||
|
||||
webContents.printToPDF = (options, callback) ->
|
||||
printingSetting =
|
||||
pageRage:[],
|
||||
mediaSize:
|
||||
height_microns:297000,
|
||||
is_default:true,
|
||||
name:"ISO_A4",
|
||||
width_microns:210000,
|
||||
custom_display_name:"A4",
|
||||
landscape:false,
|
||||
color:2,
|
||||
headerFooterEnabled:false,
|
||||
marginsType:0,
|
||||
isFirstRequest:false,
|
||||
requestID: getNextId(),
|
||||
previewModifiable:true,
|
||||
printToPDF:true,
|
||||
printWithCloudPrint:false,
|
||||
printWithPrivet:false,
|
||||
printWithExtension:false,
|
||||
deviceName:"Save as PDF",
|
||||
generateDraftData:true,
|
||||
fitToPageEnabled:false,
|
||||
duplex:0,
|
||||
copies:1,
|
||||
collate:true,
|
||||
shouldPrintBackgrounds:false,
|
||||
shouldPrintSelectionOnly:false
|
||||
|
||||
if options.landscape
|
||||
printingSetting.landscape = options.landscape
|
||||
if options.marginsType
|
||||
printingSetting.marginsType = options.marginsType
|
||||
if options.printSelectionOnly
|
||||
printingSetting.shouldPrintSelectionOnly = options.printSelectionOnly
|
||||
if options.printCSSBackgrounds
|
||||
printingSetting.shouldPrintBackgrounds = options.printBackgrounds
|
||||
|
||||
webContents._printToPDF printingSetting, callback
|
||||
|
||||
webContents
|
||||
|
||||
binding._setWrapWebContents wrapWebContents
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue