From 11b9a06639c45896f6969bcfe5922ebf14d2032f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 21 Aug 2014 21:00:49 +0800 Subject: [PATCH] Add BrowserWindow.print() method. --- atom/browser/api/atom_api_window.cc | 35 ++++++++++++++++------------- atom/browser/api/atom_api_window.h | 3 ++- atom/browser/native_window.cc | 9 ++++++-- atom/browser/native_window.h | 5 ++++- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index cc7f9319ab8d..da6a113aa5c3 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -303,6 +303,22 @@ bool Window::IsWebViewFocused() { return window_->IsWebViewFocused(); } +void Window::SetRepresentedFilename(const std::string& filename) { + window_->SetRepresentedFilename(filename); +} + +std::string Window::GetRepresentedFilename() { + return window_->GetRepresentedFilename(); +} + +void Window::SetDocumentEdited(bool edited) { + window_->SetDocumentEdited(edited); +} + +bool Window::IsDocumentEdited() { + return window_->IsDocumentEdited(); +} + void Window::CapturePage(mate::Arguments* args) { gfx::Rect rect; base::Callback)> callback; @@ -318,20 +334,8 @@ void Window::CapturePage(mate::Arguments* args) { rect, base::Bind(&OnCapturePageDone, args->isolate(), callback)); } -void Window::SetRepresentedFilename(const std::string& filename) { - window_->SetRepresentedFilename(filename); -} - -std::string Window::GetRepresentedFilename() { - return window_->GetRepresentedFilename(); -} - -void Window::SetDocumentEdited(bool edited) { - window_->SetDocumentEdited(edited); -} - -bool Window::IsDocumentEdited() { - return window_->IsDocumentEdited(); +void Window::Print() { + window_->Print(); } mate::Handle Window::GetWebContents(v8::Isolate* isolate) const { @@ -386,7 +390,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename) .SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename) .SetMethod("setDocumentEdited", &Window::SetDocumentEdited) - .SetMethod("IsDocumentEdited", &Window::IsDocumentEdited) + .SetMethod("isDocumentEdited", &Window::IsDocumentEdited) .SetMethod("_openDevTools", &Window::OpenDevTools) .SetMethod("closeDevTools", &Window::CloseDevTools) .SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened) @@ -395,6 +399,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("blurWebView", &Window::BlurWebView) .SetMethod("isWebViewFocused", &Window::IsWebViewFocused) .SetMethod("capturePage", &Window::CapturePage) + .SetMethod("print", &Window::Print) .SetMethod("_getWebContents", &Window::GetWebContents) .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents); } diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 9dda160e2b62..1a8bdb1dec65 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -97,11 +97,12 @@ class Window : public mate::EventEmitter, void FocusOnWebView(); void BlurWebView(); bool IsWebViewFocused(); - void CapturePage(mate::Arguments* args); void SetRepresentedFilename(const std::string& filename); std::string GetRepresentedFilename(); void SetDocumentEdited(bool edited); bool IsDocumentEdited(); + void CapturePage(mate::Arguments* args); + void Print(); // APIs for WebContents. mate::Handle GetWebContents(v8::Isolate* isolate) const; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 19bba99470bb..de1d2a18a9f1 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -195,11 +195,16 @@ std::string NativeWindow::GetRepresentedFilename() { void NativeWindow::SetDocumentEdited(bool edited) { } +bool NativeWindow::IsDocumentEdited() { + return false; +} + void NativeWindow::SetMenu(ui::MenuModel* menu) { } -bool NativeWindow::IsDocumentEdited() { - return false; +void NativeWindow::Print() { + printing::PrintViewManagerBasic::FromWebContents(GetWebContents())-> + PrintNow(); } bool NativeWindow::HasModalDialog() { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 8a207cdc5d2a..cafccc17a5bf 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -136,8 +136,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual void SetRepresentedFilename(const std::string& filename); virtual std::string GetRepresentedFilename(); virtual void SetDocumentEdited(bool edited); - virtual void SetMenu(ui::MenuModel* menu); virtual bool IsDocumentEdited(); + virtual void SetMenu(ui::MenuModel* menu); virtual bool HasModalDialog(); virtual gfx::NativeWindow GetNativeWindow() = 0; @@ -156,6 +156,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual void CapturePage(const gfx::Rect& rect, const CapturePageCallback& callback); + // Print current page. + virtual void Print(); + // The same with closing a tab in a real browser. // // Should be called by platform code when user want to close the window.