electron/atom/browser/api/atom_api_window.cc

814 lines
22 KiB
C++
Raw Normal View History

// 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
// found in the LICENSE file.
2014-03-16 00:30:26 +00:00
#include "atom/browser/api/atom_api_window.h"
#include "atom/common/native_mate_converters/value_converter.h"
#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"
#include "atom/browser/browser.h"
#include "atom/browser/native_window.h"
#include "atom/common/native_mate_converters/callback.h"
2014-10-24 04:48:52 +00:00
#include "atom/common/native_mate_converters/gfx_converter.h"
#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"
#include "atom/common/node_includes.h"
#include "atom/common/options_switches.h"
#include "content/public/browser/render_process_host.h"
#include "native_mate/constructor.h"
#include "native_mate/dictionary.h"
#include "ui/gfx/geometry/rect.h"
2015-08-06 03:10:34 +00:00
#if defined(OS_WIN)
#include "atom/browser/native_window_views.h"
#include "atom/browser/ui/win/taskbar_host.h"
#endif
#if defined(OS_WIN)
namespace mate {
template<>
2015-08-06 03:10:34 +00:00
struct Converter<atom::TaskbarHost::ThumbarButton> {
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
2015-08-06 03:10:34 +00:00
atom::TaskbarHost::ThumbarButton* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
dict.Get("click", &(out->clicked_callback));
dict.Get("tooltip", &(out->tooltip));
dict.Get("flags", &out->flags);
return dict.Get("icon", &(out->icon));
}
};
} // namespace mate
2015-08-06 03:10:34 +00:00
#endif
namespace atom {
namespace api {
namespace {
void OnCapturePageDone(
2014-06-28 11:49:55 +00:00
v8::Isolate* isolate,
const base::Callback<void(const gfx::Image&)>& callback,
const SkBitmap& bitmap) {
2014-06-28 11:49:55 +00:00
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
callback.Run(gfx::Image::CreateFrom1xBitmap(bitmap));
}
// Converts min-width to minWidth, returns false if no conversion is needed.
bool TranslateOldKey(const std::string& key, std::string* new_key) {
if (key.find('-') == std::string::npos)
return false;
new_key->reserve(key.size());
bool next_upper_case = false;
for (char c : key) {
if (c == '-') {
next_upper_case = true;
} else if (next_upper_case) {
new_key->push_back(base::ToUpperASCII(c));
next_upper_case = false;
} else {
new_key->push_back(c);
}
}
return true;
}
// Converts min-width to minWidth recursively in the dictionary.
void TranslateOldOptions(v8::Isolate* isolate, v8::Local<v8::Object> options) {
auto context = isolate->GetCurrentContext();
auto maybe_keys = options->GetOwnPropertyNames(context);
if (maybe_keys.IsEmpty())
return;
std::vector<std::string> keys;
if (!mate::ConvertFromV8(isolate, maybe_keys.ToLocalChecked(), &keys))
return;
mate::Dictionary dict(isolate, options);
for (const auto& key : keys) {
v8::Local<v8::Value> value;
if (!dict.Get(key, &value)) // Shouldn't happen, but guard it anyway.
continue;
// Go recursively.
v8::Local<v8::Object> sub_options;
if (mate::ConvertFromV8(isolate, value, &sub_options))
TranslateOldOptions(isolate, sub_options);
// Translate key.
std::string new_key;
if (TranslateOldKey(key, &new_key)) {
dict.Set(new_key, value);
dict.Delete(key);
}
}
}
2015-11-10 14:17:27 +00:00
// Converts binary data to Buffer.
2015-10-29 02:53:48 +00:00
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
2015-10-29 02:53:48 +00:00
if (buffer.IsEmpty())
return v8::Null(isolate);
else
return buffer.ToLocalChecked();
}
} // namespace
Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
// Be compatible with old style field names like min-width.
TranslateOldOptions(isolate, options.GetHandle());
// Use options.webPreferences to create WebContents.
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences);
// Be compatible with old options which are now in web_preferences.
v8::Local<v8::Value> value;
if (options.Get(options::kNodeIntegration, &value))
web_preferences.Set(options::kNodeIntegration, value);
if (options.Get(options::kPreloadScript, &value))
web_preferences.Set(options::kPreloadScript, value);
if (options.Get(options::kZoomFactor, &value))
web_preferences.Set(options::kZoomFactor, value);
// Creates the WebContents used by BrowserWindow.
auto web_contents = WebContents::Create(isolate, web_preferences);
web_contents_.Reset(isolate, web_contents.ToV8());
api_web_contents_ = web_contents.get();
// Keep a copy of the options for later use.
mate::Dictionary(isolate, web_contents->GetWrapper(isolate)).Set(
"browserWindowOptions", options);
// Creates BrowserWindow.
window_.reset(NativeWindow::Create(web_contents->managed_web_contents(),
options));
web_contents->SetOwnerWindow(window_.get());
window_->InitFromOptions(options);
window_->AddObserver(this);
2015-10-01 05:45:59 +00:00
AttachAsUserData(window_.get());
}
Window::~Window() {
if (!window_->IsClosed())
window_->CloseContents(nullptr);
// Destroy the native window in next tick because the native code might be
// iterating all windows.
base::MessageLoop::current()->DeleteSoon(FROM_HERE, window_.release());
}
void Window::WillCloseWindow(bool* prevent_default) {
*prevent_default = Emit("close");
}
void Window::OnWindowClosed() {
api_web_contents_->DestroyWebContents();
2015-06-24 09:58:12 +00:00
RemoveFromWeakMap();
window_->RemoveObserver(this);
// We can not call Destroy here because we need to call Emit first, but we
// also do not want any method to be used, so just mark as destroyed here.
MarkDestroyed();
Emit("closed");
// Destroy the native class when window is closed.
base::MessageLoop::current()->PostTask(FROM_HERE, GetDestroyClosure());
}
2013-05-24 09:58:39 +00:00
void Window::OnWindowBlur() {
Emit("blur");
}
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");
}
2016-01-22 00:31:09 +00:00
void Window::OnWindowScrollTouchBegin() {
Emit("scroll-touch-begin");
}
2016-01-22 00:31:09 +00:00
void Window::OnWindowScrollTouchEnd() {
Emit("scroll-touch-end");
}
void Window::OnWindowEnterHtmlFullScreen() {
Emit("enter-html-full-screen");
}
void Window::OnWindowLeaveHtmlFullScreen() {
Emit("leave-html-full-screen");
}
void Window::OnRendererUnresponsive() {
Emit("unresponsive");
}
void Window::OnRendererResponsive() {
Emit("responsive");
}
2015-06-25 21:09:25 +00:00
void Window::OnExecuteWindowsCommand(const std::string& command_name) {
2015-06-25 16:25:55 +00:00
Emit("app-command", command_name);
2015-06-18 00:31:50 +00:00
}
2015-10-27 01:12:01 +00:00
#if defined(OS_WIN)
void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
if (IsWindowMessageHooked(message)) {
messages_callback_map_[message].Run(
2015-10-29 02:53:48 +00:00
ToBuffer(isolate(), static_cast<void*>(&w_param), sizeof(WPARAM)),
ToBuffer(isolate(), static_cast<void*>(&l_param), sizeof(LPARAM)));
}
2015-10-27 01:12:01 +00:00
}
#endif
// static
mate::Wrappable* Window::New(v8::Isolate* isolate, mate::Arguments* args) {
2015-03-26 03:34:41 +00:00
if (!Browser::Get()->is_ready()) {
2015-09-07 08:12:31 +00:00
isolate->ThrowException(v8::Exception::Error(mate::StringToV8(
isolate, "Cannot create BrowserWindow before app is ready")));
return nullptr;
}
if (args->Length() > 1) {
args->ThrowError();
return nullptr;
}
mate::Dictionary options;
if (!(args->Length() == 1 && args->GetNext(&options))) {
options = mate::Dictionary::CreateEmpty(isolate);
}
return new Window(isolate, options);
}
void Window::Close() {
window_->Close();
}
void Window::Focus() {
window_->Focus(true);
2013-05-16 14:56:52 +00:00
}
bool Window::IsFocused() {
return window_->IsFocused();
}
void Window::Show() {
window_->Show();
}
2014-10-17 14:51:20 +00:00
void Window::ShowInactive() {
window_->ShowInactive();
}
void Window::Hide() {
window_->Hide();
2013-10-03 00:27:59 +00:00
}
bool Window::IsVisible() {
return window_->IsVisible();
}
void Window::Maximize() {
window_->Maximize();
}
void Window::Unmaximize() {
window_->Unmaximize();
}
2014-06-28 01:17:37 +00:00
bool Window::IsMaximized() {
2014-05-14 21:58:49 +00:00
return window_->IsMaximized();
}
void Window::Minimize() {
window_->Minimize();
}
void Window::Restore() {
window_->Restore();
}
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);
}
bool Window::IsFullscreen() {
return window_->IsFullscreen();
}
void Window::SetBounds(const gfx::Rect& bounds, mate::Arguments* args) {
2016-01-15 04:54:12 +00:00
bool animate = false;
args->GetNext(&animate);
window_->SetBounds(bounds, animate);
}
gfx::Rect Window::GetBounds() {
return window_->GetBounds();
}
void Window::SetSize(int width, int height, mate::Arguments* args) {
2016-01-15 04:54:12 +00:00
bool animate = false;
args->GetNext(&animate);
2016-01-15 04:54:12 +00:00
window_->SetSize(gfx::Size(width, height), animate);
}
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;
}
void Window::SetContentSize(int width, int height, mate::Arguments* args) {
2016-01-15 04:54:12 +00:00
bool animate = false;
args->GetNext(&animate);
2016-01-15 04:54:12 +00:00
window_->SetContentSize(gfx::Size(width, height), animate);
2014-05-15 08:05:35 +00:00
}
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;
}
void Window::SetMinimumSize(int width, int height) {
window_->SetMinimumSize(gfx::Size(width, height));
2013-04-18 07:38:04 +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;
}
void Window::SetMaximumSize(int width, int height) {
window_->SetMaximumSize(gfx::Size(width, height));
2013-04-18 07:38:04 +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;
}
void Window::SetResizable(bool resizable) {
window_->SetResizable(resizable);
2013-04-18 07:38:04 +00:00
}
bool Window::IsResizable() {
return window_->IsResizable();
}
void Window::SetMovable(bool movable) {
window_->SetMovable(movable);
}
bool Window::IsMovable() {
return window_->IsMovable();
}
void Window::SetMinimizable(bool minimizable) {
window_->SetMinimizable(minimizable);
}
bool Window::IsMinimizable() {
return window_->IsMinimizable();
}
2016-01-22 21:24:33 +00:00
void Window::SetMaximizable(bool maximizable) {
window_->SetMaximizable(maximizable);
}
bool Window::IsMaximizable() {
return window_->IsMaximizable();
}
2016-01-23 07:47:37 +00:00
void Window::SetFullScreenable(bool fullscreenable) {
window_->SetFullScreenable(fullscreenable);
2016-01-22 21:24:33 +00:00
}
2016-01-23 07:47:37 +00:00
bool Window::IsFullScreenable() {
return window_->IsFullScreenable();
2016-01-22 21:24:33 +00:00
}
void Window::SetClosable(bool closable) {
window_->SetClosable(closable);
}
bool Window::IsClosable() {
return window_->IsClosable();
}
void Window::SetAlwaysOnTop(bool top) {
window_->SetAlwaysOnTop(top);
2013-04-18 07:38:04 +00:00
}
bool Window::IsAlwaysOnTop() {
return window_->IsAlwaysOnTop();
}
void Window::Center() {
window_->Center();
}
void Window::SetPosition(int x, int y, mate::Arguments* args) {
2016-01-15 04:54:12 +00:00
bool animate = false;
args->GetNext(&animate);
2016-01-15 04:54:12 +00:00
window_->SetPosition(gfx::Point(x, y), animate);
}
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;
}
void Window::SetTitle(const std::string& title) {
window_->SetTitle(title);
2013-04-18 06:30:05 +00:00
}
std::string Window::GetTitle() {
return window_->GetTitle();
}
void Window::FlashFrame(bool flash) {
window_->FlashFrame(flash);
}
void Window::SetSkipTaskbar(bool skip) {
window_->SetSkipTaskbar(skip);
}
void Window::SetKiosk(bool kiosk) {
window_->SetKiosk(kiosk);
}
bool Window::IsKiosk() {
return window_->IsKiosk();
}
2015-10-23 03:35:33 +00:00
void Window::SetBackgroundColor(const std::string& color_name) {
window_->SetBackgroundColor(color_name);
}
void Window::SetHasShadow(bool has_shadow) {
window_->SetHasShadow(has_shadow);
}
bool Window::HasShadow() {
return window_->HasShadow();
}
void Window::FocusOnWebView() {
window_->FocusOnWebView();
}
void Window::BlurWebView() {
window_->BlurWebView();
}
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();
}
void Window::SetIgnoreMouseEvents(bool ignore) {
return window_->SetIgnoreMouseEvents(ignore);
}
void Window::CapturePage(mate::Arguments* args) {
2013-11-22 06:23:19 +00:00
gfx::Rect rect;
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)) &&
!(args->Length() == 2 && args->GetNext(&rect)
&& args->GetNext(&callback))) {
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));
}
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-08-06 04:44:07 +00:00
bool Window::SetThumbarButtons(mate::Arguments* args) {
2015-08-06 03:10:34 +00:00
#if defined(OS_WIN)
std::vector<TaskbarHost::ThumbarButton> buttons;
if (!args->GetNext(&buttons)) {
args->ThrowError();
2015-08-06 04:44:07 +00:00
return false;
2015-08-06 03:10:34 +00:00
}
auto window = static_cast<NativeWindowViews*>(window_.get());
2015-08-06 04:44:07 +00:00
return window->taskbar_host().SetThumbarButtons(
window->GetAcceleratedWidget(), buttons);
#else
return false;
2015-08-06 03:10:34 +00:00
#endif
}
2015-06-24 11:51:11 +00:00
void Window::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
mate::Handle<Menu> menu;
if (value->IsObject() &&
mate::V8ToString(value->ToObject()->GetConstructorName()) == "Menu" &&
mate::ConvertFromV8(isolate, value, &menu)) {
menu_.Reset(isolate, menu.ToV8());
window_->SetMenu(menu->model());
} else if (value->IsNull()) {
menu_.Reset();
window_->SetMenu(nullptr);
} else {
isolate->ThrowException(v8::Exception::TypeError(
mate::StringToV8(isolate, "Invalid 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();
}
#if defined(OS_WIN)
bool Window::HookWindowMessage(UINT message,
const MessageCallback& callback) {
messages_callback_map_[message] = callback;
return true;
}
void Window::UnhookWindowMessage(UINT message) {
if (!ContainsKey(messages_callback_map_, message))
return;
messages_callback_map_.erase(message);
}
bool Window::IsWindowMessageHooked(UINT message) {
return ContainsKey(messages_callback_map_, message);
}
void Window::UnhookAllWindowMessages() {
messages_callback_map_.clear();
}
#endif
#if defined(OS_MACOSX)
void Window::ShowDefinitionForSelection() {
window_->ShowDefinitionForSelection();
}
#endif
void Window::SetAspectRatio(double aspect_ratio, mate::Arguments* args) {
gfx::Size extra_size;
args->GetNext(&extra_size);
window_->SetAspectRatio(aspect_ratio, extra_size);
}
2016-01-07 20:38:35 +00:00
v8::Local<v8::Value> Window::GetNativeWindowHandle() {
gfx::AcceleratedWidget handle = window_->GetAcceleratedWidget();
return ToBuffer(
isolate(), static_cast<void*>(&handle), sizeof(gfx::AcceleratedWidget));
2016-01-07 20:38:35 +00:00
}
void Window::SetVisibleOnAllWorkspaces(bool visible) {
return window_->SetVisibleOnAllWorkspaces(visible);
}
bool Window::IsVisibleOnAllWorkspaces() {
return window_->IsVisibleOnAllWorkspaces();
}
2015-06-24 08:37:48 +00:00
int32_t Window::ID() const {
return weak_map_id();
}
2015-06-05 09:01:17 +00:00
v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
if (web_contents_.IsEmpty())
return v8::Null(isolate);
else
return v8::Local<v8::Value>::New(isolate, web_contents_);
2014-04-24 08:45:25 +00:00
}
// static
void Window::BuildPrototype(v8::Isolate* isolate,
2015-05-22 11:11:22 +00:00
v8::Local<v8::ObjectTemplate> prototype) {
mate::ObjectTemplateBuilder(isolate, prototype)
.MakeDestroyable()
.SetMethod("close", &Window::Close)
.SetMethod("focus", &Window::Focus)
.SetMethod("isFocused", &Window::IsFocused)
.SetMethod("show", &Window::Show)
2014-10-17 14:51:20 +00:00
.SetMethod("showInactive", &Window::ShowInactive)
.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)
.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)
.SetMethod("isFullScreen", &Window::IsFullscreen)
.SetMethod("setAspectRatio", &Window::SetAspectRatio)
2016-01-07 20:38:35 +00:00
.SetMethod("getNativeWindowHandle", &Window::GetNativeWindowHandle)
.SetMethod("getBounds", &Window::GetBounds)
.SetMethod("setBounds", &Window::SetBounds)
.SetMethod("getSize", &Window::GetSize)
.SetMethod("setSize", &Window::SetSize)
2014-05-15 08:05:35 +00:00
.SetMethod("getContentSize", &Window::GetContentSize)
.SetMethod("setContentSize", &Window::SetContentSize)
.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("setMovable", &Window::SetMovable)
.SetMethod("isMovable", &Window::IsMovable)
.SetMethod("setMinimizable", &Window::SetMinimizable)
.SetMethod("isMinimizable", &Window::IsMinimizable)
2016-01-22 21:24:33 +00:00
.SetMethod("setMaximizable", &Window::SetMaximizable)
.SetMethod("isMaximizable", &Window::IsMaximizable)
2016-01-23 07:47:37 +00:00
.SetMethod("setFullScreenable", &Window::SetFullScreenable)
.SetMethod("isFullScreenable", &Window::IsFullScreenable)
.SetMethod("setClosable", &Window::SetClosable)
.SetMethod("isClosable", &Window::IsClosable)
.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)
.SetMethod("setSkipTaskbar", &Window::SetSkipTaskbar)
.SetMethod("setKiosk", &Window::SetKiosk)
.SetMethod("isKiosk", &Window::IsKiosk)
2015-10-23 03:35:33 +00:00
.SetMethod("setBackgroundColor", &Window::SetBackgroundColor)
.SetMethod("setHasShadow", &Window::SetHasShadow)
.SetMethod("hasShadow", &Window::HasShadow)
.SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
2014-08-21 13:00:49 +00:00
.SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
.SetMethod("setIgnoreMouseEvents", &Window::SetIgnoreMouseEvents)
.SetMethod("focusOnWebView", &Window::FocusOnWebView)
.SetMethod("blurWebView", &Window::BlurWebView)
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
.SetMethod("capturePage", &Window::CapturePage)
2014-09-17 01:42:47 +00:00
.SetMethod("setProgressBar", &Window::SetProgressBar)
2015-02-07 00:12:32 +00:00
.SetMethod("setOverlayIcon", &Window::SetOverlayIcon)
.SetMethod("setThumbarButtons", &Window::SetThumbarButtons)
2015-06-24 11:51:11 +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)
.SetMethod("setVisibleOnAllWorkspaces",
&Window::SetVisibleOnAllWorkspaces)
.SetMethod("isVisibleOnAllWorkspaces",
&Window::IsVisibleOnAllWorkspaces)
#if defined(OS_WIN)
.SetMethod("hookWindowMessage", &Window::HookWindowMessage)
.SetMethod("isWindowMessageHooked", &Window::IsWindowMessageHooked)
.SetMethod("unhookWindowMessage", &Window::UnhookWindowMessage)
.SetMethod("unhookAllWindowMessages", &Window::UnhookAllWindowMessages)
#endif
#if defined(OS_MACOSX)
2014-12-19 20:48:53 +00:00
.SetMethod("showDefinitionForSelection",
&Window::ShowDefinitionForSelection)
#endif
.SetProperty("id", &Window::ID)
.SetProperty("webContents", &Window::WebContents);
2013-04-18 16:06:10 +00:00
}
2015-10-01 05:45:59 +00:00
// static
v8::Local<v8::Value> Window::From(v8::Isolate* isolate,
NativeWindow* native_window) {
auto existing = TrackableObject::FromWrappedClass(isolate, native_window);
if (existing)
return existing->GetWrapper(isolate);
else
return v8::Null(isolate);
}
} // namespace api
} // namespace atom
namespace {
2015-06-24 08:37:48 +00:00
using atom::api::Window;
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) {
v8::Isolate* isolate = context->GetIsolate();
v8::Local<v8::Function> constructor = mate::CreateConstructor<Window>(
2014-06-28 11:49:55 +00:00
isolate, "BrowserWindow", base::Bind(&Window::New));
2015-06-24 08:37:48 +00:00
mate::Dictionary browser_window(isolate, constructor);
2015-06-24 09:58:12 +00:00
browser_window.SetMethod("fromId",
&mate::TrackableObject<Window>::FromWeakMapID);
browser_window.SetMethod("getAllWindows",
&mate::TrackableObject<Window>::GetAll);
2015-06-24 08:37:48 +00:00
2014-06-28 11:49:55 +00:00
mate::Dictionary dict(isolate, exports);
2015-06-24 08:37:48 +00:00
dict.Set("BrowserWindow", browser_window);
}
} // namespace
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_window, Initialize)