2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-14 07:36:48 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/api/atom_api_window.h"
|
2013-04-14 07:36:48 +00:00
|
|
|
|
2015-06-04 07:32:33 +00:00
|
|
|
#include "atom/browser/api/atom_api_menu.h"
|
2014-04-24 08:45:25 +00:00
|
|
|
#include "atom/browser/api/atom_api_web_contents.h"
|
2014-10-30 13:32:35 +00:00
|
|
|
#include "atom/browser/browser.h"
|
2014-04-22 15:07:21 +00:00
|
|
|
#include "atom/browser/native_window.h"
|
2014-10-24 04:48:52 +00:00
|
|
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
2015-01-15 01:51:54 +00:00
|
|
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
2015-02-07 01:00:26 +00:00
|
|
|
#include "atom/common/native_mate_converters/image_converter.h"
|
2015-02-11 01:14:26 +00:00
|
|
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
2013-04-23 09:21:34 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2014-08-10 11:14:20 +00:00
|
|
|
#include "native_mate/callback.h"
|
2014-04-22 15:07:21 +00:00
|
|
|
#include "native_mate/constructor.h"
|
|
|
|
#include "native_mate/dictionary.h"
|
2015-05-01 10:50:53 +00:00
|
|
|
#include "ui/gfx/geometry/rect.h"
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
2013-12-11 07:48:19 +00:00
|
|
|
|
2014-08-22 07:01:07 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct PrintSettings {
|
|
|
|
bool silent;
|
2014-11-25 19:57:55 +00:00
|
|
|
bool print_background;
|
2014-08-22 07:01:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
namespace mate {
|
|
|
|
|
2014-08-22 07:01:07 +00:00
|
|
|
template<>
|
|
|
|
struct Converter<PrintSettings> {
|
2015-05-22 11:11:22 +00:00
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
|
2014-08-22 07:01:07 +00:00
|
|
|
PrintSettings* out) {
|
|
|
|
mate::Dictionary dict;
|
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
2014-08-22 07:05:30 +00:00
|
|
|
dict.Get("silent", &(out->silent));
|
2014-11-25 19:57:55 +00:00
|
|
|
dict.Get("printBackground", &(out->print_background));
|
2014-08-22 07:01:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace mate
|
2013-04-29 11:38:18 +00:00
|
|
|
|
2013-04-14 07:36:48 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
namespace api {
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void OnCapturePageDone(
|
2014-06-28 11:49:55 +00:00
|
|
|
v8::Isolate* isolate,
|
2015-02-12 04:58:11 +00:00
|
|
|
const base::Callback<void(const gfx::Image&)>& callback,
|
2015-03-20 02:26:22 +00:00
|
|
|
const SkBitmap& bitmap) {
|
2014-06-28 11:49:55 +00:00
|
|
|
v8::Locker locker(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-03-20 02:26:22 +00:00
|
|
|
callback.Run(gfx::Image::CreateFrom1xBitmap(bitmap));
|
2014-04-22 15:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2014-06-23 13:51:42 +00:00
|
|
|
Window::Window(const mate::Dictionary& options)
|
2014-04-22 15:07:21 +00:00
|
|
|
: window_(NativeWindow::Create(options)) {
|
2013-04-17 12:05:43 +00:00
|
|
|
window_->InitFromOptions(options);
|
2013-04-18 15:50:47 +00:00
|
|
|
window_->AddObserver(this);
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window() {
|
2014-04-23 02:53:07 +00:00
|
|
|
if (window_)
|
|
|
|
Destroy();
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 15:50:47 +00:00
|
|
|
void Window::OnPageTitleUpdated(bool* prevent_default,
|
|
|
|
const std::string& title) {
|
2015-01-15 01:51:54 +00:00
|
|
|
*prevent_default = Emit("page-title-updated", title);
|
2013-05-01 15:28:01 +00:00
|
|
|
}
|
|
|
|
|
2014-10-27 10:52:55 +00:00
|
|
|
void Window::WillCreatePopupWindow(const base::string16& frame_name,
|
|
|
|
const GURL& target_url,
|
2014-11-04 09:59:15 +00:00
|
|
|
const std::string& partition_id,
|
|
|
|
WindowOpenDisposition disposition) {
|
2015-01-15 01:51:54 +00:00
|
|
|
Emit("-new-window", target_url, frame_name, static_cast<int>(disposition));
|
2014-10-27 10:52:55 +00:00
|
|
|
}
|
|
|
|
|
2014-12-17 22:40:19 +00:00
|
|
|
void Window::WillNavigate(bool* prevent_default, const GURL& url) {
|
2015-01-15 01:51:54 +00:00
|
|
|
*prevent_default = Emit("-will-navigate", url);
|
2014-12-17 22:40:19 +00:00
|
|
|
}
|
|
|
|
|
2013-05-01 15:28:01 +00:00
|
|
|
void Window::WillCloseWindow(bool* prevent_default) {
|
2013-05-02 10:19:07 +00:00
|
|
|
*prevent_default = Emit("close");
|
2013-05-01 15:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowClosed() {
|
2013-05-02 10:19:07 +00:00
|
|
|
Emit("closed");
|
2014-04-23 00:50:26 +00:00
|
|
|
|
2014-04-23 01:53:38 +00:00
|
|
|
window_->RemoveObserver(this);
|
2013-04-18 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 09:58:39 +00:00
|
|
|
void Window::OnWindowBlur() {
|
|
|
|
Emit("blur");
|
|
|
|
}
|
|
|
|
|
2014-05-21 17:46:13 +00:00
|
|
|
void Window::OnWindowFocus() {
|
|
|
|
Emit("focus");
|
|
|
|
}
|
|
|
|
|
2014-11-25 04:43:25 +00:00
|
|
|
void Window::OnWindowMaximize() {
|
|
|
|
Emit("maximize");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowUnmaximize() {
|
|
|
|
Emit("unmaximize");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowMinimize() {
|
|
|
|
Emit("minimize");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowRestore() {
|
|
|
|
Emit("restore");
|
|
|
|
}
|
|
|
|
|
2015-05-09 15:55:10 +00:00
|
|
|
void Window::OnWindowResize() {
|
2015-05-09 18:03:16 +00:00
|
|
|
Emit("resize");
|
2015-05-09 15:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowMove() {
|
2015-05-09 18:03:16 +00:00
|
|
|
Emit("move");
|
2015-05-09 15:55:10 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 08:37:13 +00:00
|
|
|
void Window::OnWindowMoved() {
|
|
|
|
Emit("moved");
|
|
|
|
}
|
|
|
|
|
2014-11-25 04:43:25 +00:00
|
|
|
void Window::OnWindowEnterFullScreen() {
|
|
|
|
Emit("enter-full-screen");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowLeaveFullScreen() {
|
|
|
|
Emit("leave-full-screen");
|
|
|
|
}
|
|
|
|
|
2015-05-16 21:01:30 +00:00
|
|
|
void Window::OnWindowEnterHtmlFullScreen() {
|
|
|
|
Emit("enter-html-full-screen");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowLeaveHtmlFullScreen() {
|
|
|
|
Emit("leave-html-full-screen");
|
|
|
|
}
|
|
|
|
|
2013-06-06 11:45:48 +00:00
|
|
|
void Window::OnRendererUnresponsive() {
|
|
|
|
Emit("unresponsive");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnRendererResponsive() {
|
|
|
|
Emit("responsive");
|
|
|
|
}
|
|
|
|
|
2015-03-31 15:45:06 +00:00
|
|
|
void Window::OnDevToolsFocus() {
|
|
|
|
Emit("devtools-focused");
|
|
|
|
}
|
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
// static
|
2014-10-30 13:32:35 +00:00
|
|
|
mate::Wrappable* Window::New(v8::Isolate* isolate,
|
|
|
|
const mate::Dictionary& options) {
|
2015-03-26 03:34:41 +00:00
|
|
|
if (!Browser::Get()->is_ready()) {
|
|
|
|
node::ThrowError("Cannot create BrowserWindow before app is ready");
|
2014-10-30 13:32:35 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-03-26 03:34:41 +00:00
|
|
|
return new Window(options);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Destroy() {
|
2014-04-23 02:53:07 +00:00
|
|
|
window_->DestroyWebContents();
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->CloseImmediately();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Close() {
|
|
|
|
window_->Close();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-10-28 10:51:28 +00:00
|
|
|
bool Window::IsClosed() {
|
|
|
|
return window_->IsClosed();
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Focus() {
|
|
|
|
window_->Focus(true);
|
2013-05-16 14:56:52 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsFocused() {
|
|
|
|
return window_->IsFocused();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Show() {
|
|
|
|
window_->Show();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-10-17 14:51:20 +00:00
|
|
|
void Window::ShowInactive() {
|
|
|
|
window_->ShowInactive();
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Hide() {
|
|
|
|
window_->Hide();
|
2013-10-03 00:27:59 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsVisible() {
|
|
|
|
return window_->IsVisible();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Maximize() {
|
|
|
|
window_->Maximize();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Unmaximize() {
|
|
|
|
window_->Unmaximize();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-06-28 01:17:37 +00:00
|
|
|
bool Window::IsMaximized() {
|
2014-05-14 21:58:49 +00:00
|
|
|
return window_->IsMaximized();
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Minimize() {
|
|
|
|
window_->Minimize();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Restore() {
|
|
|
|
window_->Restore();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 05:58:26 +00:00
|
|
|
bool Window::IsMinimized() {
|
|
|
|
return window_->IsMinimized();
|
|
|
|
}
|
|
|
|
|
2014-11-25 06:34:14 +00:00
|
|
|
void Window::SetFullScreen(bool fullscreen) {
|
|
|
|
window_->SetFullScreen(fullscreen);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsFullscreen() {
|
|
|
|
return window_->IsFullscreen();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2015-05-01 10:50:53 +00:00
|
|
|
void Window::SetBounds(const gfx::Rect& bounds) {
|
|
|
|
window_->SetBounds(bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect Window::GetBounds() {
|
|
|
|
return window_->GetBounds();
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetSize(int width, int height) {
|
|
|
|
window_->SetSize(gfx::Size(width, height));
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> Window::GetSize() {
|
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-05-15 08:05:35 +00:00
|
|
|
void Window::SetContentSize(int width, int height) {
|
|
|
|
window_->SetContentSize(gfx::Size(width, height));
|
|
|
|
}
|
|
|
|
|
2014-05-15 07:30:04 +00:00
|
|
|
std::vector<int> Window::GetContentSize() {
|
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetContentSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetMinimumSize(int width, int height) {
|
|
|
|
window_->SetMinimumSize(gfx::Size(width, height));
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> Window::GetMinimumSize() {
|
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetMinimumSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetMaximumSize(int width, int height) {
|
|
|
|
window_->SetMaximumSize(gfx::Size(width, height));
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> Window::GetMaximumSize() {
|
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetMaximumSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetResizable(bool resizable) {
|
|
|
|
window_->SetResizable(resizable);
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsResizable() {
|
|
|
|
return window_->IsResizable();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetAlwaysOnTop(bool top) {
|
|
|
|
window_->SetAlwaysOnTop(top);
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsAlwaysOnTop() {
|
|
|
|
return window_->IsAlwaysOnTop();
|
2013-05-10 12:34:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Center() {
|
|
|
|
window_->Center();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetPosition(int x, int y) {
|
|
|
|
window_->SetPosition(gfx::Point(x, y));
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> Window::GetPosition() {
|
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Point pos = window_->GetPosition();
|
|
|
|
result[0] = pos.x();
|
|
|
|
result[1] = pos.y();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetTitle(const std::string& title) {
|
|
|
|
window_->SetTitle(title);
|
2013-04-18 06:30:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
std::string Window::GetTitle() {
|
|
|
|
return window_->GetTitle();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::FlashFrame(bool flash) {
|
|
|
|
window_->FlashFrame(flash);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-06-16 02:29:51 +00:00
|
|
|
void Window::SetSkipTaskbar(bool skip) {
|
|
|
|
window_->SetSkipTaskbar(skip);
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetKiosk(bool kiosk) {
|
|
|
|
window_->SetKiosk(kiosk);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsKiosk() {
|
|
|
|
return window_->IsKiosk();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 08:24:33 +00:00
|
|
|
void Window::OpenDevTools(bool can_dock) {
|
|
|
|
window_->OpenDevTools(can_dock);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::CloseDevTools() {
|
|
|
|
window_->CloseDevTools();
|
2013-11-05 02:32:45 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsDevToolsOpened() {
|
|
|
|
return window_->IsDevToolsOpened();
|
2013-07-18 11:21:25 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::InspectElement(int x, int y) {
|
|
|
|
window_->InspectElement(x, y);
|
2014-02-24 04:08:33 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 14:38:08 +00:00
|
|
|
void Window::InspectServiceWorker() {
|
|
|
|
window_->InspectServiceWorker();
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::FocusOnWebView() {
|
|
|
|
window_->FocusOnWebView();
|
2013-05-24 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::BlurWebView() {
|
|
|
|
window_->BlurWebView();
|
2013-08-16 04:56:25 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsWebViewFocused() {
|
|
|
|
return window_->IsWebViewFocused();
|
|
|
|
}
|
2013-11-22 06:23:19 +00:00
|
|
|
|
2014-08-21 13:00:49 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::CapturePage(mate::Arguments* args) {
|
2013-11-22 06:23:19 +00:00
|
|
|
gfx::Rect rect;
|
2015-02-12 04:58:11 +00:00
|
|
|
base::Callback<void(const gfx::Image&)> callback;
|
2013-11-22 06:23:19 +00:00
|
|
|
|
2014-04-23 03:39:40 +00:00
|
|
|
if (!(args->Length() == 1 && args->GetNext(&callback)) &&
|
2014-04-23 01:09:28 +00:00
|
|
|
!(args->Length() == 2 && args->GetNext(&rect)
|
|
|
|
&& args->GetNext(&callback))) {
|
2014-04-22 15:07:21 +00:00
|
|
|
args->ThrowError();
|
|
|
|
return;
|
|
|
|
}
|
2013-11-22 06:23:19 +00:00
|
|
|
|
2014-06-28 11:49:55 +00:00
|
|
|
window_->CapturePage(
|
|
|
|
rect, base::Bind(&OnCapturePageDone, args->isolate(), callback));
|
2013-04-18 07:09:53 +00:00
|
|
|
}
|
|
|
|
|
2014-08-22 07:01:07 +00:00
|
|
|
void Window::Print(mate::Arguments* args) {
|
|
|
|
PrintSettings settings = { false, false };;
|
|
|
|
if (args->Length() == 1 && !args->GetNext(&settings)) {
|
|
|
|
args->ThrowError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-25 19:57:55 +00:00
|
|
|
window_->Print(settings.silent, settings.print_background);
|
2014-07-24 07:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-09-17 01:42:47 +00:00
|
|
|
void Window::SetProgressBar(double progress) {
|
|
|
|
window_->SetProgressBar(progress);
|
|
|
|
}
|
|
|
|
|
2015-02-07 01:07:29 +00:00
|
|
|
void Window::SetOverlayIcon(const gfx::Image& overlay,
|
2015-02-11 01:14:26 +00:00
|
|
|
const std::string& description) {
|
2015-02-07 01:07:29 +00:00
|
|
|
window_->SetOverlayIcon(overlay, description);
|
|
|
|
}
|
|
|
|
|
2015-06-04 07:32:33 +00:00
|
|
|
void Window::SetMenu(ui::SimpleMenuModel* menu) {
|
|
|
|
window_->SetMenu(menu);
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:31:55 +00:00
|
|
|
void Window::SetAutoHideMenuBar(bool auto_hide) {
|
|
|
|
window_->SetAutoHideMenuBar(auto_hide);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::IsMenuBarAutoHide() {
|
|
|
|
return window_->IsMenuBarAutoHide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::SetMenuBarVisibility(bool visible) {
|
|
|
|
window_->SetMenuBarVisibility(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::IsMenuBarVisible() {
|
|
|
|
return window_->IsMenuBarVisible();
|
|
|
|
}
|
|
|
|
|
2014-12-18 23:40:35 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
void Window::ShowDefinitionForSelection() {
|
|
|
|
window_->ShowDefinitionForSelection();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-26 06:18:37 +00:00
|
|
|
void Window::SetVisibleOnAllWorkspaces(bool visible) {
|
|
|
|
return window_->SetVisibleOnAllWorkspaces(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::IsVisibleOnAllWorkspaces() {
|
|
|
|
return window_->IsVisibleOnAllWorkspaces();
|
|
|
|
}
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
|
2015-06-05 07:41:03 +00:00
|
|
|
return WebContents::CreateFrom(isolate, window_->managed_web_contents());
|
2014-04-24 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mate::Handle<WebContents> Window::GetDevToolsWebContents(
|
|
|
|
v8::Isolate* isolate) const {
|
2014-10-23 06:04:13 +00:00
|
|
|
return WebContents::CreateFrom(isolate, window_->GetDevToolsWebContents());
|
2014-04-24 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
// static
|
|
|
|
void Window::BuildPrototype(v8::Isolate* isolate,
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> prototype) {
|
2014-04-22 15:07:21 +00:00
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype)
|
|
|
|
.SetMethod("destroy", &Window::Destroy)
|
|
|
|
.SetMethod("close", &Window::Close)
|
2014-10-28 10:51:28 +00:00
|
|
|
.SetMethod("isClosed", &Window::IsClosed)
|
2014-04-22 15:07:21 +00:00
|
|
|
.SetMethod("focus", &Window::Focus)
|
|
|
|
.SetMethod("isFocused", &Window::IsFocused)
|
|
|
|
.SetMethod("show", &Window::Show)
|
2014-10-17 14:51:20 +00:00
|
|
|
.SetMethod("showInactive", &Window::ShowInactive)
|
2014-04-22 15:07:21 +00:00
|
|
|
.SetMethod("hide", &Window::Hide)
|
|
|
|
.SetMethod("isVisible", &Window::IsVisible)
|
|
|
|
.SetMethod("maximize", &Window::Maximize)
|
|
|
|
.SetMethod("unmaximize", &Window::Unmaximize)
|
2014-05-14 21:58:49 +00:00
|
|
|
.SetMethod("isMaximized", &Window::IsMaximized)
|
2014-04-22 15:07:21 +00:00
|
|
|
.SetMethod("minimize", &Window::Minimize)
|
|
|
|
.SetMethod("restore", &Window::Restore)
|
2014-07-26 05:58:26 +00:00
|
|
|
.SetMethod("isMinimized", &Window::IsMinimized)
|
2014-11-25 06:34:14 +00:00
|
|
|
.SetMethod("setFullScreen", &Window::SetFullScreen)
|
2014-04-22 15:07:21 +00:00
|
|
|
.SetMethod("isFullScreen", &Window::IsFullscreen)
|
2015-05-01 10:50:53 +00:00
|
|
|
.SetMethod("getBounds", &Window::GetBounds)
|
|
|
|
.SetMethod("setBounds", &Window::SetBounds)
|
2014-04-22 15:07:21 +00:00
|
|
|
.SetMethod("getSize", &Window::GetSize)
|
|
|
|
.SetMethod("setSize", &Window::SetSize)
|
2014-05-15 08:05:35 +00:00
|
|
|
.SetMethod("getContentSize", &Window::GetContentSize)
|
|
|
|
.SetMethod("setContentSize", &Window::SetContentSize)
|
2014-04-22 15:07:21 +00:00
|
|
|
.SetMethod("setMinimumSize", &Window::SetMinimumSize)
|
|
|
|
.SetMethod("getMinimumSize", &Window::GetMinimumSize)
|
|
|
|
.SetMethod("setMaximumSize", &Window::SetMaximumSize)
|
|
|
|
.SetMethod("getMaximumSize", &Window::GetMaximumSize)
|
|
|
|
.SetMethod("setResizable", &Window::SetResizable)
|
|
|
|
.SetMethod("isResizable", &Window::IsResizable)
|
|
|
|
.SetMethod("setAlwaysOnTop", &Window::SetAlwaysOnTop)
|
|
|
|
.SetMethod("isAlwaysOnTop", &Window::IsAlwaysOnTop)
|
|
|
|
.SetMethod("center", &Window::Center)
|
|
|
|
.SetMethod("setPosition", &Window::SetPosition)
|
|
|
|
.SetMethod("getPosition", &Window::GetPosition)
|
|
|
|
.SetMethod("setTitle", &Window::SetTitle)
|
|
|
|
.SetMethod("getTitle", &Window::GetTitle)
|
|
|
|
.SetMethod("flashFrame", &Window::FlashFrame)
|
2014-06-16 02:29:51 +00:00
|
|
|
.SetMethod("setSkipTaskbar", &Window::SetSkipTaskbar)
|
2014-04-22 15:07:21 +00:00
|
|
|
.SetMethod("setKiosk", &Window::SetKiosk)
|
|
|
|
.SetMethod("isKiosk", &Window::IsKiosk)
|
2014-05-27 06:15:34 +00:00
|
|
|
.SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
|
2014-07-18 13:42:26 +00:00
|
|
|
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
2014-05-27 06:15:34 +00:00
|
|
|
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
2014-08-21 13:00:49 +00:00
|
|
|
.SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
|
2014-05-20 12:58:11 +00:00
|
|
|
.SetMethod("_openDevTools", &Window::OpenDevTools)
|
2014-04-22 15:07:21 +00:00
|
|
|
.SetMethod("closeDevTools", &Window::CloseDevTools)
|
|
|
|
.SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened)
|
2015-06-01 11:53:44 +00:00
|
|
|
.SetMethod("_inspectElement", &Window::InspectElement)
|
2014-04-22 15:07:21 +00:00
|
|
|
.SetMethod("focusOnWebView", &Window::FocusOnWebView)
|
|
|
|
.SetMethod("blurWebView", &Window::BlurWebView)
|
|
|
|
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
|
|
|
|
.SetMethod("capturePage", &Window::CapturePage)
|
2014-08-21 13:00:49 +00:00
|
|
|
.SetMethod("print", &Window::Print)
|
2014-09-17 01:42:47 +00:00
|
|
|
.SetMethod("setProgressBar", &Window::SetProgressBar)
|
2015-02-07 00:12:32 +00:00
|
|
|
.SetMethod("setOverlayIcon", &Window::SetOverlayIcon)
|
2015-06-04 07:32:33 +00:00
|
|
|
.SetMethod("_setMenu", &Window::SetMenu)
|
2014-11-12 12:31:55 +00:00
|
|
|
.SetMethod("setAutoHideMenuBar", &Window::SetAutoHideMenuBar)
|
|
|
|
.SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide)
|
|
|
|
.SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility)
|
|
|
|
.SetMethod("isMenuBarVisible", &Window::IsMenuBarVisible)
|
2015-03-26 06:18:37 +00:00
|
|
|
.SetMethod("setVisibleOnAllWorkspaces",
|
|
|
|
&Window::SetVisibleOnAllWorkspaces)
|
|
|
|
.SetMethod("isVisibleOnAllWorkspaces",
|
|
|
|
&Window::IsVisibleOnAllWorkspaces)
|
2014-12-18 23:40:35 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2014-12-19 20:48:53 +00:00
|
|
|
.SetMethod("showDefinitionForSelection",
|
|
|
|
&Window::ShowDefinitionForSelection)
|
2014-12-18 23:40:35 +00:00
|
|
|
#endif
|
2014-04-25 03:51:05 +00:00
|
|
|
.SetMethod("_getWebContents", &Window::GetWebContents)
|
2015-05-18 14:38:08 +00:00
|
|
|
.SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents)
|
2015-06-01 11:53:44 +00:00
|
|
|
.SetMethod("_inspectServiceWorker", &Window::InspectServiceWorker);
|
2013-04-18 16:06:10 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace api
|
2013-04-18 07:09:53 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace atom
|
2013-04-18 07:09:53 +00:00
|
|
|
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
namespace {
|
2013-04-18 07:09:53 +00:00
|
|
|
|
2015-05-22 11:11:22 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context, void* priv) {
|
2014-04-22 15:07:21 +00:00
|
|
|
using atom::api::Window;
|
2014-06-29 12:48:44 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2014-04-22 15:07:21 +00:00
|
|
|
v8::Local<v8::Function> constructor = mate::CreateConstructor<Window>(
|
2014-06-28 11:49:55 +00:00
|
|
|
isolate, "BrowserWindow", base::Bind(&Window::New));
|
|
|
|
mate::Dictionary dict(isolate, exports);
|
2015-05-22 11:11:22 +00:00
|
|
|
dict.Set("BrowserWindow", static_cast<v8::Local<v8::Value>>(constructor));
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace
|
2013-04-14 07:36:48 +00:00
|
|
|
|
2014-06-29 12:48:44 +00:00
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_window, Initialize)
|