2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-14 15:36:48 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 08:30:26 +08:00
|
|
|
#include "atom/browser/api/atom_api_window.h"
|
2015-11-11 00:26:46 +08:00
|
|
|
#include "atom/common/native_mate_converters/value_converter.h"
|
2013-04-14 15:36:48 +08:00
|
|
|
|
2015-06-04 15:32:33 +08:00
|
|
|
#include "atom/browser/api/atom_api_menu.h"
|
2014-04-24 16:45:25 +08:00
|
|
|
#include "atom/browser/api/atom_api_web_contents.h"
|
2014-10-30 21:32:35 +08:00
|
|
|
#include "atom/browser/browser.h"
|
2014-04-22 23:07:21 +08:00
|
|
|
#include "atom/browser/native_window.h"
|
2015-08-07 18:10:19 +08:00
|
|
|
#include "atom/common/native_mate_converters/callback.h"
|
2016-11-12 17:21:31 +01:00
|
|
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
2014-10-24 12:48:52 +08:00
|
|
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
2015-01-14 17:51:54 -08:00
|
|
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
2015-02-06 17:00:26 -08:00
|
|
|
#include "atom/common/native_mate_converters/image_converter.h"
|
2015-02-10 17:14:26 -08:00
|
|
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
2015-09-05 01:51:14 +09:00
|
|
|
#include "atom/common/options_switches.h"
|
2016-07-27 18:24:58 +02:00
|
|
|
#include "base/command_line.h"
|
2016-11-30 16:30:03 +09:00
|
|
|
#include "base/threading/thread_task_runner_handle.h"
|
2013-04-23 17:21:34 +08:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2016-07-27 18:24:58 +02:00
|
|
|
#include "content/public/common/content_switches.h"
|
2014-04-22 23:07:21 +08:00
|
|
|
#include "native_mate/constructor.h"
|
|
|
|
#include "native_mate/dictionary.h"
|
2015-05-01 16:20:53 +05:30
|
|
|
#include "ui/gfx/geometry/rect.h"
|
2013-04-16 00:25:08 +08:00
|
|
|
|
2016-05-20 22:22:15 +09:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2015-08-06 11:10:34 +08:00
|
|
|
#include "atom/browser/native_window_views.h"
|
2016-05-20 22:22:15 +09:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2015-08-06 11:10:34 +08:00
|
|
|
#include "atom/browser/ui/win/taskbar_host.h"
|
2016-11-12 17:59:57 +01:00
|
|
|
#include "ui/base/win/shell.h"
|
2015-08-06 11:10:34 +08:00
|
|
|
#endif
|
|
|
|
|
2016-09-06 17:24:37 +09:00
|
|
|
#include "atom/common/node_includes.h"
|
|
|
|
|
2015-08-06 11:10:34 +08:00
|
|
|
#if defined(OS_WIN)
|
2015-08-02 11:11:29 +08:00
|
|
|
namespace mate {
|
|
|
|
|
|
|
|
template<>
|
2015-08-06 11:10:34 +08:00
|
|
|
struct Converter<atom::TaskbarHost::ThumbarButton> {
|
2015-08-02 11:11:29 +08:00
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
2015-08-06 11:10:34 +08:00
|
|
|
atom::TaskbarHost::ThumbarButton* out) {
|
2015-08-02 11:11:29 +08:00
|
|
|
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 11:10:34 +08:00
|
|
|
#endif
|
2015-08-02 11:11:29 +08:00
|
|
|
|
2013-04-14 15:36:48 +08:00
|
|
|
namespace atom {
|
|
|
|
|
2013-04-16 00:25:08 +08:00
|
|
|
namespace api {
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
namespace {
|
|
|
|
|
2015-11-11 00:26:46 +08:00
|
|
|
// Converts binary data to Buffer.
|
2015-10-29 10:53:48 +08:00
|
|
|
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
2016-02-07 10:20:38 +01:00
|
|
|
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
|
2015-10-29 10:53:48 +08:00
|
|
|
if (buffer.IsEmpty())
|
|
|
|
return v8::Null(isolate);
|
|
|
|
else
|
|
|
|
return buffer.ToLocalChecked();
|
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2016-08-02 15:15:40 +09:00
|
|
|
Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
|
|
|
const mate::Dictionary& options) {
|
2016-08-15 21:13:18 -03:00
|
|
|
mate::Handle<class WebContents> web_contents;
|
|
|
|
// If no WebContents was passed to the constructor, create it from options.
|
|
|
|
if (!options.Get("webContents", &web_contents)) {
|
|
|
|
// Use options.webPreferences to create WebContents.
|
|
|
|
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
|
|
|
options.Get(options::kWebPreferences, &web_preferences);
|
|
|
|
|
|
|
|
// Copy the backgroundColor to webContents.
|
|
|
|
v8::Local<v8::Value> value;
|
|
|
|
if (options.Get(options::kBackgroundColor, &value))
|
|
|
|
web_preferences.Set(options::kBackgroundColor, value);
|
|
|
|
|
|
|
|
v8::Local<v8::Value> transparent;
|
|
|
|
if (options.Get("transparent", &transparent))
|
|
|
|
web_preferences.Set("transparent", transparent);
|
|
|
|
|
2016-12-20 23:43:52 +01:00
|
|
|
// Offscreen windows are always created frameless.
|
|
|
|
bool offscreen;
|
2016-12-21 23:15:05 +01:00
|
|
|
if (web_preferences.Get("offscreen", &offscreen) && offscreen) {
|
|
|
|
auto window_options = const_cast<mate::Dictionary&>(options);
|
|
|
|
window_options.Set(options::kFrame, false);
|
2016-12-20 23:43:52 +01:00
|
|
|
}
|
|
|
|
|
2016-08-15 21:13:18 -03:00
|
|
|
// Creates the WebContents used by BrowserWindow.
|
|
|
|
web_contents = WebContents::Create(isolate, web_preferences);
|
|
|
|
}
|
2016-08-15 20:58:07 -03:00
|
|
|
|
|
|
|
Init(isolate, wrapper, options, web_contents);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::Init(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> wrapper,
|
|
|
|
const mate::Dictionary& options,
|
|
|
|
mate::Handle<class WebContents> web_contents) {
|
2015-06-25 09:47:57 +08:00
|
|
|
web_contents_.Reset(isolate, web_contents.ToV8());
|
2015-06-25 11:07:23 +08:00
|
|
|
api_web_contents_ = web_contents.get();
|
2015-06-25 09:47:57 +08:00
|
|
|
|
2015-09-22 21:56:56 +08:00
|
|
|
// Keep a copy of the options for later use.
|
2016-04-25 10:19:25 +09:00
|
|
|
mate::Dictionary(isolate, web_contents->GetWrapper()).Set(
|
2015-09-22 21:56:56 +08:00
|
|
|
"browserWindowOptions", options);
|
|
|
|
|
2016-06-19 12:06:08 +09:00
|
|
|
// The parent window.
|
|
|
|
mate::Handle<Window> parent;
|
|
|
|
if (options.Get("parent", &parent))
|
|
|
|
parent_window_.Reset(isolate, parent.ToV8());
|
|
|
|
|
2015-06-25 09:47:57 +08:00
|
|
|
// Creates BrowserWindow.
|
2016-06-19 12:06:08 +09:00
|
|
|
window_.reset(NativeWindow::Create(
|
|
|
|
web_contents->managed_web_contents(),
|
|
|
|
options,
|
|
|
|
parent.IsEmpty() ? nullptr : parent->window_.get()));
|
2015-06-25 09:47:57 +08:00
|
|
|
web_contents->SetOwnerWindow(window_.get());
|
2016-05-20 19:46:05 +09:00
|
|
|
|
2016-05-20 22:22:15 +09:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2016-05-20 19:46:05 +09:00
|
|
|
// Sets the window icon.
|
|
|
|
mate::Handle<NativeImage> icon;
|
2016-05-20 22:22:15 +09:00
|
|
|
if (options.Get(options::kIcon, &icon))
|
|
|
|
SetIcon(icon);
|
2016-05-20 19:46:05 +09:00
|
|
|
#endif
|
2016-07-02 16:16:47 +09:00
|
|
|
|
|
|
|
window_->InitFromOptions(options);
|
|
|
|
window_->AddObserver(this);
|
2016-08-02 15:15:40 +09:00
|
|
|
|
|
|
|
InitWith(isolate, wrapper);
|
2016-07-02 16:16:47 +09:00
|
|
|
AttachAsUserData(window_.get());
|
2016-08-02 15:15:40 +09:00
|
|
|
|
|
|
|
// We can only append this window to parent window's child windows after this
|
|
|
|
// window's JS wrapper gets initialized.
|
|
|
|
if (!parent.IsEmpty())
|
|
|
|
parent->child_windows_.Set(isolate, ID(), wrapper);
|
2013-04-16 00:25:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window() {
|
2015-12-03 15:38:43 +08:00
|
|
|
if (!window_->IsClosed())
|
|
|
|
window_->CloseContents(nullptr);
|
2015-12-04 11:35:04 +08:00
|
|
|
|
|
|
|
// Destroy the native window in next tick because the native code might be
|
|
|
|
// iterating all windows.
|
2016-11-30 16:30:03 +09:00
|
|
|
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window_.release());
|
2013-04-16 00:25:08 +08:00
|
|
|
}
|
|
|
|
|
2013-05-01 23:28:01 +08:00
|
|
|
void Window::WillCloseWindow(bool* prevent_default) {
|
2013-05-02 18:19:07 +08:00
|
|
|
*prevent_default = Emit("close");
|
2013-05-01 23:28:01 +08:00
|
|
|
}
|
|
|
|
|
2016-08-25 11:24:16 -07:00
|
|
|
void Window::WillDestroyNativeObject() {
|
2016-06-19 15:47:27 +09:00
|
|
|
// Close all child windows before closing current window.
|
|
|
|
v8::Locker locker(isolate());
|
|
|
|
v8::HandleScope handle_scope(isolate());
|
|
|
|
for (v8::Local<v8::Value> value : child_windows_.Values(isolate())) {
|
|
|
|
mate::Handle<Window> child;
|
|
|
|
if (mate::ConvertFromV8(isolate(), value, &child))
|
|
|
|
child->window_->CloseImmediately();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-01 23:28:01 +08:00
|
|
|
void Window::OnWindowClosed() {
|
2015-12-03 15:38:43 +08:00
|
|
|
api_web_contents_->DestroyWebContents();
|
2015-06-25 11:07:23 +08:00
|
|
|
|
2015-06-24 17:58:12 +08:00
|
|
|
RemoveFromWeakMap();
|
2014-04-23 09:53:38 +08:00
|
|
|
window_->RemoveObserver(this);
|
2015-06-27 17:01:20 +08:00
|
|
|
|
2015-12-03 15:38:43 +08:00
|
|
|
// 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();
|
|
|
|
|
2015-06-27 17:01:20 +08:00
|
|
|
Emit("closed");
|
2015-09-17 11:30:17 +08:00
|
|
|
|
2016-06-17 16:57:03 +09:00
|
|
|
RemoveFromParentChildWindows();
|
|
|
|
|
2015-12-03 15:38:43 +08:00
|
|
|
// Destroy the native class when window is closed.
|
2016-11-30 16:30:03 +09:00
|
|
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
|
|
|
FROM_HERE, GetDestroyClosure());
|
2013-04-18 23:50:47 +08:00
|
|
|
}
|
|
|
|
|
2013-05-24 17:58:39 +08:00
|
|
|
void Window::OnWindowBlur() {
|
|
|
|
Emit("blur");
|
|
|
|
}
|
|
|
|
|
2014-05-21 13:46:13 -04:00
|
|
|
void Window::OnWindowFocus() {
|
|
|
|
Emit("focus");
|
|
|
|
}
|
|
|
|
|
2016-03-08 09:36:41 -08:00
|
|
|
void Window::OnWindowShow() {
|
|
|
|
Emit("show");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowHide() {
|
|
|
|
Emit("hide");
|
|
|
|
}
|
|
|
|
|
2016-06-13 21:19:56 +09:00
|
|
|
void Window::OnReadyToShow() {
|
|
|
|
Emit("ready-to-show");
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:43:25 +08:00
|
|
|
void Window::OnWindowMaximize() {
|
|
|
|
Emit("maximize");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowUnmaximize() {
|
|
|
|
Emit("unmaximize");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowMinimize() {
|
|
|
|
Emit("minimize");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowRestore() {
|
|
|
|
Emit("restore");
|
|
|
|
}
|
|
|
|
|
2015-05-09 21:25:10 +05:30
|
|
|
void Window::OnWindowResize() {
|
2015-05-09 23:33:16 +05:30
|
|
|
Emit("resize");
|
2015-05-09 21:25:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowMove() {
|
2015-05-09 23:33:16 +05:30
|
|
|
Emit("move");
|
2015-05-09 21:25:10 +05:30
|
|
|
}
|
|
|
|
|
2015-05-20 14:07:13 +05:30
|
|
|
void Window::OnWindowMoved() {
|
|
|
|
Emit("moved");
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:43:25 +08:00
|
|
|
void Window::OnWindowEnterFullScreen() {
|
|
|
|
Emit("enter-full-screen");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowLeaveFullScreen() {
|
|
|
|
Emit("leave-full-screen");
|
|
|
|
}
|
|
|
|
|
2016-01-21 16:31:09 -08:00
|
|
|
void Window::OnWindowScrollTouchBegin() {
|
|
|
|
Emit("scroll-touch-begin");
|
2016-01-21 09:40:21 -08:00
|
|
|
}
|
|
|
|
|
2016-01-21 16:31:09 -08:00
|
|
|
void Window::OnWindowScrollTouchEnd() {
|
|
|
|
Emit("scroll-touch-end");
|
2016-01-21 09:40:21 -08:00
|
|
|
}
|
|
|
|
|
2016-09-17 22:29:32 +08:00
|
|
|
void Window::OnWindowScrollTouchEdge() {
|
|
|
|
Emit("scroll-touch-edge");
|
|
|
|
}
|
|
|
|
|
2016-03-23 15:20:11 +00:00
|
|
|
void Window::OnWindowSwipe(const std::string& direction) {
|
|
|
|
Emit("swipe", direction);
|
2016-03-18 15:20:04 +00:00
|
|
|
}
|
|
|
|
|
2015-05-17 02:31:30 +05:30
|
|
|
void Window::OnWindowEnterHtmlFullScreen() {
|
|
|
|
Emit("enter-html-full-screen");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowLeaveHtmlFullScreen() {
|
|
|
|
Emit("leave-html-full-screen");
|
|
|
|
}
|
|
|
|
|
2013-06-06 19:45:48 +08:00
|
|
|
void Window::OnRendererUnresponsive() {
|
|
|
|
Emit("unresponsive");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnRendererResponsive() {
|
|
|
|
Emit("responsive");
|
|
|
|
}
|
|
|
|
|
2015-06-25 15:09:25 -06:00
|
|
|
void Window::OnExecuteWindowsCommand(const std::string& command_name) {
|
2015-06-25 11:25:55 -05:00
|
|
|
Emit("app-command", command_name);
|
2015-06-17 17:31:50 -07:00
|
|
|
}
|
|
|
|
|
2015-10-27 03:12:01 +02:00
|
|
|
#if defined(OS_WIN)
|
2015-10-29 03:00:44 +02:00
|
|
|
void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
|
2015-10-27 14:00:08 +02:00
|
|
|
if (IsWindowMessageHooked(message)) {
|
2015-10-29 03:00:44 +02:00
|
|
|
messages_callback_map_[message].Run(
|
2015-10-29 10:53:48 +08:00
|
|
|
ToBuffer(isolate(), static_cast<void*>(&w_param), sizeof(WPARAM)),
|
|
|
|
ToBuffer(isolate(), static_cast<void*>(&l_param), sizeof(LPARAM)));
|
2015-10-27 14:00:08 +02:00
|
|
|
}
|
2015-10-27 03:12:01 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-16 00:25:08 +08:00
|
|
|
// static
|
2016-08-02 15:15:40 +09:00
|
|
|
mate::WrappableBase* Window::New(mate::Arguments* args) {
|
2015-03-26 11:34:41 +08:00
|
|
|
if (!Browser::Get()->is_ready()) {
|
2016-08-02 15:15:40 +09:00
|
|
|
args->ThrowError("Cannot create BrowserWindow before app is ready");
|
2014-10-30 21:32:35 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-11-21 06:22:19 +02:00
|
|
|
|
|
|
|
if (args->Length() > 1) {
|
|
|
|
args->ThrowError();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mate::Dictionary options;
|
|
|
|
if (!(args->Length() == 1 && args->GetNext(&options))) {
|
2016-08-02 15:15:40 +09:00
|
|
|
options = mate::Dictionary::CreateEmpty(args->isolate());
|
2015-11-21 06:22:19 +02:00
|
|
|
}
|
|
|
|
|
2016-08-02 15:15:40 +09:00
|
|
|
return new Window(args->isolate(), args->GetThis(), options);
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::Close() {
|
|
|
|
window_->Close();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::Focus() {
|
|
|
|
window_->Focus(true);
|
2013-05-16 22:56:52 +08:00
|
|
|
}
|
|
|
|
|
2016-03-10 21:45:51 -08:00
|
|
|
void Window::Blur() {
|
|
|
|
window_->Focus(false);
|
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
bool Window::IsFocused() {
|
|
|
|
return window_->IsFocused();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::Show() {
|
|
|
|
window_->Show();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-10-17 22:51:20 +08:00
|
|
|
void Window::ShowInactive() {
|
2016-06-20 14:49:24 +09:00
|
|
|
// This method doesn't make sense for modal window..
|
|
|
|
if (IsModal())
|
|
|
|
return;
|
|
|
|
|
2014-10-17 22:51:20 +08:00
|
|
|
window_->ShowInactive();
|
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::Hide() {
|
|
|
|
window_->Hide();
|
2013-10-03 08:27:59 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
bool Window::IsVisible() {
|
|
|
|
return window_->IsVisible();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2016-06-17 17:38:44 +09:00
|
|
|
bool Window::IsEnabled() {
|
|
|
|
return window_->IsEnabled();
|
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::Maximize() {
|
|
|
|
window_->Maximize();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::Unmaximize() {
|
|
|
|
window_->Unmaximize();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-06-28 10:17:37 +09:00
|
|
|
bool Window::IsMaximized() {
|
2014-05-14 23:58:49 +02:00
|
|
|
return window_->IsMaximized();
|
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::Minimize() {
|
|
|
|
window_->Minimize();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::Restore() {
|
|
|
|
window_->Restore();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-07-26 13:58:26 +08:00
|
|
|
bool Window::IsMinimized() {
|
|
|
|
return window_->IsMinimized();
|
|
|
|
}
|
|
|
|
|
2014-11-25 14:34:14 +08:00
|
|
|
void Window::SetFullScreen(bool fullscreen) {
|
|
|
|
window_->SetFullScreen(fullscreen);
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
bool Window::IsFullscreen() {
|
|
|
|
return window_->IsFullscreen();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2016-01-15 17:31:31 +01:00
|
|
|
void Window::SetBounds(const gfx::Rect& bounds, mate::Arguments* args) {
|
2016-01-15 05:54:12 +01:00
|
|
|
bool animate = false;
|
2016-01-15 17:31:31 +01:00
|
|
|
args->GetNext(&animate);
|
|
|
|
window_->SetBounds(bounds, animate);
|
2015-05-01 16:20:53 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect Window::GetBounds() {
|
|
|
|
return window_->GetBounds();
|
|
|
|
}
|
|
|
|
|
2016-08-04 12:02:24 -07:00
|
|
|
void Window::SetContentBounds(const gfx::Rect& bounds, mate::Arguments* args) {
|
|
|
|
bool animate = false;
|
|
|
|
args->GetNext(&animate);
|
|
|
|
window_->SetContentBounds(bounds, animate);
|
|
|
|
}
|
|
|
|
|
2016-07-28 18:19:17 -07:00
|
|
|
gfx::Rect Window::GetContentBounds() {
|
|
|
|
return window_->GetContentBounds();
|
|
|
|
}
|
|
|
|
|
2016-01-15 17:31:31 +01:00
|
|
|
void Window::SetSize(int width, int height, mate::Arguments* args) {
|
2016-01-15 05:54:12 +01:00
|
|
|
bool animate = false;
|
2016-01-15 17:31:31 +01:00
|
|
|
args->GetNext(&animate);
|
2016-01-15 05:54:12 +01:00
|
|
|
window_->SetSize(gfx::Size(width, height), animate);
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08: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 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2016-01-15 17:31:31 +01:00
|
|
|
void Window::SetContentSize(int width, int height, mate::Arguments* args) {
|
2016-01-15 05:54:12 +01:00
|
|
|
bool animate = false;
|
2016-01-15 17:31:31 +01:00
|
|
|
args->GetNext(&animate);
|
2016-01-15 05:54:12 +01:00
|
|
|
window_->SetContentSize(gfx::Size(width, height), animate);
|
2014-05-15 16:05:35 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 15:30:04 +08: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 23:07:21 +08:00
|
|
|
void Window::SetMinimumSize(int width, int height) {
|
|
|
|
window_->SetMinimumSize(gfx::Size(width, height));
|
2013-04-18 15:38:04 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08: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 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::SetMaximumSize(int width, int height) {
|
|
|
|
window_->SetMaximumSize(gfx::Size(width, height));
|
2013-04-18 15:38:04 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08: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 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 20:19:08 -07:00
|
|
|
void Window::SetSheetOffset(double offsetY, mate::Arguments* args) {
|
|
|
|
double offsetX = 0.0;
|
|
|
|
args->GetNext(&offsetX);
|
|
|
|
window_->SetSheetOffset(offsetX, offsetY);
|
2016-04-18 22:45:38 -07:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::SetResizable(bool resizable) {
|
|
|
|
window_->SetResizable(resizable);
|
2013-04-18 15:38:04 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
bool Window::IsResizable() {
|
|
|
|
return window_->IsResizable();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2016-01-18 23:46:35 +01:00
|
|
|
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 22:24:33 +01:00
|
|
|
void Window::SetMaximizable(bool maximizable) {
|
|
|
|
window_->SetMaximizable(maximizable);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::IsMaximizable() {
|
|
|
|
return window_->IsMaximizable();
|
|
|
|
}
|
|
|
|
|
2016-01-22 23:47:37 -08:00
|
|
|
void Window::SetFullScreenable(bool fullscreenable) {
|
|
|
|
window_->SetFullScreenable(fullscreenable);
|
2016-01-22 22:24:33 +01:00
|
|
|
}
|
|
|
|
|
2016-01-22 23:47:37 -08:00
|
|
|
bool Window::IsFullScreenable() {
|
|
|
|
return window_->IsFullScreenable();
|
2016-01-22 22:24:33 +01:00
|
|
|
}
|
|
|
|
|
2016-01-18 23:46:35 +01:00
|
|
|
void Window::SetClosable(bool closable) {
|
|
|
|
window_->SetClosable(closable);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::IsClosable() {
|
|
|
|
return window_->IsClosable();
|
|
|
|
}
|
|
|
|
|
2016-09-21 13:35:59 -04:00
|
|
|
void Window::SetAlwaysOnTop(bool top, mate::Arguments* args) {
|
2016-09-21 22:49:06 -04:00
|
|
|
std::string level = "floating";
|
2017-01-23 20:36:09 -08:00
|
|
|
int relativeLevel = 0;
|
2017-01-24 20:08:08 -08:00
|
|
|
std::string error;
|
|
|
|
|
2016-09-21 13:35:59 -04:00
|
|
|
args->GetNext(&level);
|
2017-01-23 20:36:09 -08:00
|
|
|
args->GetNext(&relativeLevel);
|
2017-01-24 20:08:08 -08:00
|
|
|
|
|
|
|
window_->SetAlwaysOnTop(top, level, relativeLevel, &error);
|
|
|
|
|
|
|
|
if (!error.empty()) {
|
|
|
|
args->ThrowError(error);
|
|
|
|
}
|
2013-04-18 15:38:04 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
bool Window::IsAlwaysOnTop() {
|
|
|
|
return window_->IsAlwaysOnTop();
|
2013-05-10 20:34:05 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::Center() {
|
|
|
|
window_->Center();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2016-01-15 17:31:31 +01:00
|
|
|
void Window::SetPosition(int x, int y, mate::Arguments* args) {
|
2016-01-15 05:54:12 +01:00
|
|
|
bool animate = false;
|
2016-01-15 17:31:31 +01:00
|
|
|
args->GetNext(&animate);
|
2016-01-15 05:54:12 +01:00
|
|
|
window_->SetPosition(gfx::Point(x, y), animate);
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08: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 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::SetTitle(const std::string& title) {
|
|
|
|
window_->SetTitle(title);
|
2013-04-18 14:30:05 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
std::string Window::GetTitle() {
|
|
|
|
return window_->GetTitle();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::FlashFrame(bool flash) {
|
|
|
|
window_->FlashFrame(flash);
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-06-16 10:29:51 +08:00
|
|
|
void Window::SetSkipTaskbar(bool skip) {
|
|
|
|
window_->SetSkipTaskbar(skip);
|
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::SetKiosk(bool kiosk) {
|
|
|
|
window_->SetKiosk(kiosk);
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
bool Window::IsKiosk() {
|
|
|
|
return window_->IsKiosk();
|
2013-04-17 22:49:49 +08:00
|
|
|
}
|
|
|
|
|
2015-10-23 11:35:33 +08:00
|
|
|
void Window::SetBackgroundColor(const std::string& color_name) {
|
|
|
|
window_->SetBackgroundColor(color_name);
|
|
|
|
}
|
|
|
|
|
2016-01-23 01:15:49 +01:00
|
|
|
void Window::SetHasShadow(bool has_shadow) {
|
|
|
|
window_->SetHasShadow(has_shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::HasShadow() {
|
|
|
|
return window_->HasShadow();
|
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::FocusOnWebView() {
|
|
|
|
window_->FocusOnWebView();
|
2013-05-24 17:51:15 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
void Window::BlurWebView() {
|
|
|
|
window_->BlurWebView();
|
2013-08-16 12:56:25 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
bool Window::IsWebViewFocused() {
|
|
|
|
return window_->IsWebViewFocused();
|
|
|
|
}
|
2013-11-22 14:23:19 +08:00
|
|
|
|
2014-08-21 21:00:49 +08: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();
|
|
|
|
}
|
|
|
|
|
2015-12-06 10:14:54 +08:00
|
|
|
void Window::SetIgnoreMouseEvents(bool ignore) {
|
|
|
|
return window_->SetIgnoreMouseEvents(ignore);
|
|
|
|
}
|
|
|
|
|
2016-06-22 10:40:01 +02:00
|
|
|
void Window::SetContentProtection(bool enable) {
|
|
|
|
return window_->SetContentProtection(enable);
|
|
|
|
}
|
|
|
|
|
2016-06-13 17:10:28 +09:00
|
|
|
void Window::SetFocusable(bool focusable) {
|
|
|
|
return window_->SetFocusable(focusable);
|
2016-06-12 20:20:25 +02:00
|
|
|
}
|
|
|
|
|
2016-08-08 15:44:48 -07:00
|
|
|
void Window::SetProgressBar(double progress, mate::Arguments* args) {
|
|
|
|
mate::Dictionary options;
|
|
|
|
std::string mode;
|
2016-08-09 16:05:44 -07:00
|
|
|
NativeWindow::ProgressState state = NativeWindow::PROGRESS_NORMAL;
|
|
|
|
|
2016-08-08 15:44:48 -07:00
|
|
|
args->GetNext(&options) && options.Get("mode", &mode);
|
|
|
|
|
2016-08-09 16:05:44 -07:00
|
|
|
if (mode == "error") {
|
|
|
|
state = NativeWindow::PROGRESS_ERROR;
|
|
|
|
} else if (mode == "paused") {
|
|
|
|
state = NativeWindow::PROGRESS_PAUSED;
|
|
|
|
} else if (mode == "indeterminate") {
|
|
|
|
state = NativeWindow::PROGRESS_INDETERMINATE;
|
|
|
|
} else if (mode == "none") {
|
|
|
|
state = NativeWindow::PROGRESS_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_->SetProgressBar(progress, state);
|
2014-09-17 09:42:47 +08:00
|
|
|
}
|
|
|
|
|
2015-02-06 17:07:29 -08:00
|
|
|
void Window::SetOverlayIcon(const gfx::Image& overlay,
|
2015-02-10 17:14:26 -08:00
|
|
|
const std::string& description) {
|
2015-02-06 17:07:29 -08:00
|
|
|
window_->SetOverlayIcon(overlay, description);
|
|
|
|
}
|
|
|
|
|
2015-08-06 12:44:07 +08:00
|
|
|
bool Window::SetThumbarButtons(mate::Arguments* args) {
|
2015-08-06 11:10:34 +08:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
std::vector<TaskbarHost::ThumbarButton> buttons;
|
|
|
|
if (!args->GetNext(&buttons)) {
|
|
|
|
args->ThrowError();
|
2015-08-06 12:44:07 +08:00
|
|
|
return false;
|
2015-08-06 11:10:34 +08:00
|
|
|
}
|
|
|
|
auto window = static_cast<NativeWindowViews*>(window_.get());
|
2015-08-06 12:44:07 +08:00
|
|
|
return window->taskbar_host().SetThumbarButtons(
|
2016-08-13 01:55:42 +10:00
|
|
|
window_->GetAcceleratedWidget(), buttons);
|
2015-08-06 12:44:07 +08:00
|
|
|
#else
|
|
|
|
return false;
|
2015-08-06 11:10:34 +08:00
|
|
|
#endif
|
2015-08-02 11:11:29 +08:00
|
|
|
}
|
|
|
|
|
2015-06-24 19:51:11 +08: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")));
|
|
|
|
}
|
2015-06-04 15:32:33 +08:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:31:55 +08: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();
|
|
|
|
}
|
|
|
|
|
2015-10-27 14:00:08 +02:00
|
|
|
#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();
|
|
|
|
}
|
2016-07-14 13:27:16 -07:00
|
|
|
|
|
|
|
bool Window::SetThumbnailClip(const gfx::Rect& region) {
|
|
|
|
auto window = static_cast<NativeWindowViews*>(window_.get());
|
|
|
|
return window->taskbar_host().SetThumbnailClip(
|
|
|
|
window_->GetAcceleratedWidget(), region);
|
|
|
|
}
|
2016-08-07 19:23:42 +02:00
|
|
|
|
|
|
|
bool Window::SetThumbnailToolTip(const std::string& tooltip) {
|
|
|
|
auto window = static_cast<NativeWindowViews*>(window_.get());
|
|
|
|
return window->taskbar_host().SetThumbnailToolTip(
|
|
|
|
window_->GetAcceleratedWidget(), tooltip);
|
|
|
|
}
|
2016-11-12 17:21:31 +01:00
|
|
|
|
|
|
|
void Window::SetAppDetails(const mate::Dictionary& options) {
|
|
|
|
base::string16 app_id;
|
|
|
|
base::FilePath app_icon_path;
|
2016-11-28 14:26:30 -08:00
|
|
|
int app_icon_index = 0;
|
2016-11-12 17:21:31 +01:00
|
|
|
base::string16 relaunch_command;
|
|
|
|
base::string16 relaunch_display_name;
|
|
|
|
|
|
|
|
options.Get("appId", &app_id);
|
|
|
|
options.Get("appIconPath", &app_icon_path);
|
|
|
|
options.Get("appIconIndex", &app_icon_index);
|
|
|
|
options.Get("relaunchCommand", &relaunch_command);
|
|
|
|
options.Get("relaunchDisplayName", &relaunch_display_name);
|
|
|
|
|
|
|
|
ui::win::SetAppDetailsForWindow(
|
|
|
|
app_id, app_icon_path, app_icon_index,
|
|
|
|
relaunch_command, relaunch_display_name,
|
|
|
|
window_->GetAcceleratedWidget());
|
|
|
|
}
|
2015-10-27 14:00:08 +02:00
|
|
|
#endif
|
|
|
|
|
2016-05-20 22:22:15 +09:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
|
|
|
void Window::SetIcon(mate::Handle<NativeImage> icon) {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
static_cast<NativeWindowViews*>(window_.get())->SetIcon(
|
2016-05-30 09:46:42 +09:00
|
|
|
icon->GetHICON(GetSystemMetrics(SM_CXSMICON)),
|
|
|
|
icon->GetHICON(GetSystemMetrics(SM_CXICON)));
|
2016-05-20 22:22:15 +09:00
|
|
|
#elif defined(USE_X11)
|
|
|
|
static_cast<NativeWindowViews*>(window_.get())->SetIcon(
|
|
|
|
icon->image().AsImageSkia());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-23 10:14:02 +08:00
|
|
|
void Window::SetAspectRatio(double aspect_ratio, mate::Arguments* args) {
|
|
|
|
gfx::Size extra_size;
|
|
|
|
args->GetNext(&extra_size);
|
|
|
|
window_->SetAspectRatio(aspect_ratio, extra_size);
|
|
|
|
}
|
|
|
|
|
2016-10-14 09:42:50 -07:00
|
|
|
void Window::PreviewFile(const std::string& path, mate::Arguments* args) {
|
2016-10-26 09:47:22 +09:00
|
|
|
std::string display_name;
|
2016-10-26 09:55:34 +09:00
|
|
|
if (!args->GetNext(&display_name))
|
2016-10-26 09:47:22 +09:00
|
|
|
display_name = path;
|
|
|
|
window_->PreviewFile(path, display_name);
|
2016-10-11 18:08:01 -07:00
|
|
|
}
|
|
|
|
|
2016-11-21 13:30:13 -05:00
|
|
|
void Window::CloseFilePreview() {
|
|
|
|
window_->CloseFilePreview();
|
|
|
|
}
|
|
|
|
|
2016-06-17 16:57:03 +09:00
|
|
|
void Window::SetParentWindow(v8::Local<v8::Value> value,
|
|
|
|
mate::Arguments* args) {
|
2016-06-20 14:49:24 +09:00
|
|
|
if (IsModal()) {
|
|
|
|
args->ThrowError("Can not be called for modal window");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-17 16:57:03 +09:00
|
|
|
mate::Handle<Window> parent;
|
|
|
|
if (value->IsNull()) {
|
|
|
|
RemoveFromParentChildWindows();
|
|
|
|
parent_window_.Reset();
|
|
|
|
window_->SetParentWindow(nullptr);
|
|
|
|
} else if (mate::ConvertFromV8(isolate(), value, &parent)) {
|
2016-06-17 16:09:43 +09:00
|
|
|
parent_window_.Reset(isolate(), value);
|
2016-06-17 16:57:03 +09:00
|
|
|
window_->SetParentWindow(parent->window_.get());
|
|
|
|
parent->child_windows_.Set(isolate(), ID(), GetWrapper());
|
2016-06-17 16:09:43 +09:00
|
|
|
} else {
|
|
|
|
args->ThrowError("Must pass BrowserWindow instance or null");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-18 09:42:18 +09:00
|
|
|
v8::Local<v8::Value> Window::GetParentWindow() const {
|
2016-06-17 16:09:43 +09:00
|
|
|
if (parent_window_.IsEmpty())
|
|
|
|
return v8::Null(isolate());
|
|
|
|
else
|
|
|
|
return v8::Local<v8::Value>::New(isolate(), parent_window_);
|
2016-06-17 15:28:43 +09:00
|
|
|
}
|
|
|
|
|
2016-06-18 09:42:18 +09:00
|
|
|
std::vector<v8::Local<v8::Object>> Window::GetChildWindows() const {
|
2016-06-17 16:57:03 +09:00
|
|
|
return child_windows_.Values(isolate());
|
|
|
|
}
|
|
|
|
|
2016-06-18 09:42:18 +09:00
|
|
|
bool Window::IsModal() const {
|
2016-06-20 14:49:24 +09:00
|
|
|
return window_->is_modal();
|
2016-06-18 22:53:41 +09:00
|
|
|
}
|
|
|
|
|
2016-01-07 22:38:35 +02:00
|
|
|
v8::Local<v8::Value> Window::GetNativeWindowHandle() {
|
|
|
|
gfx::AcceleratedWidget handle = window_->GetAcceleratedWidget();
|
2016-01-11 13:43:24 +08:00
|
|
|
return ToBuffer(
|
|
|
|
isolate(), static_cast<void*>(&handle), sizeof(gfx::AcceleratedWidget));
|
2016-01-07 22:38:35 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 14:18:37 +08:00
|
|
|
void Window::SetVisibleOnAllWorkspaces(bool visible) {
|
|
|
|
return window_->SetVisibleOnAllWorkspaces(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::IsVisibleOnAllWorkspaces() {
|
|
|
|
return window_->IsVisibleOnAllWorkspaces();
|
|
|
|
}
|
|
|
|
|
2016-11-28 11:38:40 -08:00
|
|
|
void Window::SetAutoHideCursor(bool auto_hide) {
|
|
|
|
window_->SetAutoHideCursor(auto_hide);
|
|
|
|
}
|
|
|
|
|
2016-11-10 20:36:21 +01:00
|
|
|
void Window::SetVibrancy(mate::Arguments* args) {
|
2016-11-10 11:59:25 +01:00
|
|
|
std::string type;
|
2016-11-07 21:22:41 +01:00
|
|
|
|
2016-11-10 20:36:21 +01:00
|
|
|
args->GetNext(&type);
|
|
|
|
window_->SetVibrancy(type);
|
2016-11-07 21:22:41 +01:00
|
|
|
}
|
|
|
|
|
2015-06-24 16:37:48 +08:00
|
|
|
int32_t Window::ID() const {
|
|
|
|
return weak_map_id();
|
|
|
|
}
|
|
|
|
|
2015-06-05 17:01:17 +08:00
|
|
|
v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
|
2015-06-24 19:04:08 +08:00
|
|
|
if (web_contents_.IsEmpty())
|
|
|
|
return v8::Null(isolate);
|
|
|
|
else
|
|
|
|
return v8::Local<v8::Value>::New(isolate, web_contents_);
|
2014-04-24 16:45:25 +08:00
|
|
|
}
|
|
|
|
|
2016-06-17 16:57:03 +09:00
|
|
|
void Window::RemoveFromParentChildWindows() {
|
|
|
|
if (parent_window_.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
mate::Handle<Window> parent;
|
2016-06-18 09:42:18 +09:00
|
|
|
if (!mate::ConvertFromV8(isolate(), GetParentWindow(), &parent))
|
|
|
|
return;
|
|
|
|
|
|
|
|
parent->child_windows_.Remove(ID());
|
2016-06-17 16:57:03 +09:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
// static
|
|
|
|
void Window::BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 18:08:12 +09:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
2016-08-02 19:28:12 +09:00
|
|
|
prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow"));
|
2016-08-02 18:08:12 +09:00
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2015-12-03 15:38:43 +08:00
|
|
|
.MakeDestroyable()
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("close", &Window::Close)
|
|
|
|
.SetMethod("focus", &Window::Focus)
|
2016-03-10 21:45:51 -08:00
|
|
|
.SetMethod("blur", &Window::Blur)
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("isFocused", &Window::IsFocused)
|
|
|
|
.SetMethod("show", &Window::Show)
|
2014-10-17 22:51:20 +08:00
|
|
|
.SetMethod("showInactive", &Window::ShowInactive)
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("hide", &Window::Hide)
|
|
|
|
.SetMethod("isVisible", &Window::IsVisible)
|
2016-06-17 17:38:44 +09:00
|
|
|
.SetMethod("isEnabled", &Window::IsEnabled)
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("maximize", &Window::Maximize)
|
|
|
|
.SetMethod("unmaximize", &Window::Unmaximize)
|
2014-05-14 23:58:49 +02:00
|
|
|
.SetMethod("isMaximized", &Window::IsMaximized)
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("minimize", &Window::Minimize)
|
|
|
|
.SetMethod("restore", &Window::Restore)
|
2014-07-26 13:58:26 +08:00
|
|
|
.SetMethod("isMinimized", &Window::IsMinimized)
|
2014-11-25 14:34:14 +08:00
|
|
|
.SetMethod("setFullScreen", &Window::SetFullScreen)
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("isFullScreen", &Window::IsFullscreen)
|
2015-07-22 10:23:31 -04:00
|
|
|
.SetMethod("setAspectRatio", &Window::SetAspectRatio)
|
2016-10-11 18:08:01 -07:00
|
|
|
.SetMethod("previewFile", &Window::PreviewFile)
|
2016-11-21 13:30:13 -05:00
|
|
|
.SetMethod("closeFilePreview", &Window::CloseFilePreview)
|
2016-06-20 15:44:50 +09:00
|
|
|
#if !defined(OS_WIN)
|
2016-06-17 15:28:43 +09:00
|
|
|
.SetMethod("setParentWindow", &Window::SetParentWindow)
|
2016-06-20 15:44:50 +09:00
|
|
|
#endif
|
2016-06-17 16:09:43 +09:00
|
|
|
.SetMethod("getParentWindow", &Window::GetParentWindow)
|
2016-06-17 16:57:03 +09:00
|
|
|
.SetMethod("getChildWindows", &Window::GetChildWindows)
|
2016-06-18 09:42:18 +09:00
|
|
|
.SetMethod("isModal", &Window::IsModal)
|
2016-01-07 22:38:35 +02:00
|
|
|
.SetMethod("getNativeWindowHandle", &Window::GetNativeWindowHandle)
|
2015-05-01 16:20:53 +05:30
|
|
|
.SetMethod("getBounds", &Window::GetBounds)
|
|
|
|
.SetMethod("setBounds", &Window::SetBounds)
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("getSize", &Window::GetSize)
|
|
|
|
.SetMethod("setSize", &Window::SetSize)
|
2016-07-28 18:19:17 -07:00
|
|
|
.SetMethod("getContentBounds", &Window::GetContentBounds)
|
2016-08-04 12:02:24 -07:00
|
|
|
.SetMethod("setContentBounds", &Window::SetContentBounds)
|
2014-05-15 16:05:35 +08:00
|
|
|
.SetMethod("getContentSize", &Window::GetContentSize)
|
|
|
|
.SetMethod("setContentSize", &Window::SetContentSize)
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("setMinimumSize", &Window::SetMinimumSize)
|
|
|
|
.SetMethod("getMinimumSize", &Window::GetMinimumSize)
|
|
|
|
.SetMethod("setMaximumSize", &Window::SetMaximumSize)
|
|
|
|
.SetMethod("getMaximumSize", &Window::GetMaximumSize)
|
2016-04-18 22:45:38 -07:00
|
|
|
.SetMethod("setSheetOffset", &Window::SetSheetOffset)
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("setResizable", &Window::SetResizable)
|
|
|
|
.SetMethod("isResizable", &Window::IsResizable)
|
2016-01-18 23:46:35 +01:00
|
|
|
.SetMethod("setMovable", &Window::SetMovable)
|
|
|
|
.SetMethod("isMovable", &Window::IsMovable)
|
|
|
|
.SetMethod("setMinimizable", &Window::SetMinimizable)
|
|
|
|
.SetMethod("isMinimizable", &Window::IsMinimizable)
|
2016-01-22 22:24:33 +01:00
|
|
|
.SetMethod("setMaximizable", &Window::SetMaximizable)
|
|
|
|
.SetMethod("isMaximizable", &Window::IsMaximizable)
|
2016-01-22 23:47:37 -08:00
|
|
|
.SetMethod("setFullScreenable", &Window::SetFullScreenable)
|
|
|
|
.SetMethod("isFullScreenable", &Window::IsFullScreenable)
|
2016-01-18 23:46:35 +01:00
|
|
|
.SetMethod("setClosable", &Window::SetClosable)
|
|
|
|
.SetMethod("isClosable", &Window::IsClosable)
|
2014-04-22 23:07:21 +08:00
|
|
|
.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 10:29:51 +08:00
|
|
|
.SetMethod("setSkipTaskbar", &Window::SetSkipTaskbar)
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("setKiosk", &Window::SetKiosk)
|
|
|
|
.SetMethod("isKiosk", &Window::IsKiosk)
|
2015-10-23 11:35:33 +08:00
|
|
|
.SetMethod("setBackgroundColor", &Window::SetBackgroundColor)
|
2016-01-23 01:15:49 +01:00
|
|
|
.SetMethod("setHasShadow", &Window::SetHasShadow)
|
|
|
|
.SetMethod("hasShadow", &Window::HasShadow)
|
2014-05-27 14:15:34 +08:00
|
|
|
.SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
|
2014-07-18 21:42:26 +08:00
|
|
|
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
2014-05-27 14:15:34 +08:00
|
|
|
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
2014-08-21 21:00:49 +08:00
|
|
|
.SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
|
2015-12-06 10:14:54 +08:00
|
|
|
.SetMethod("setIgnoreMouseEvents", &Window::SetIgnoreMouseEvents)
|
2016-06-22 10:40:01 +02:00
|
|
|
.SetMethod("setContentProtection", &Window::SetContentProtection)
|
2016-06-13 17:10:28 +09:00
|
|
|
.SetMethod("setFocusable", &Window::SetFocusable)
|
2014-04-22 23:07:21 +08:00
|
|
|
.SetMethod("focusOnWebView", &Window::FocusOnWebView)
|
|
|
|
.SetMethod("blurWebView", &Window::BlurWebView)
|
|
|
|
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
|
2014-09-17 09:42:47 +08:00
|
|
|
.SetMethod("setProgressBar", &Window::SetProgressBar)
|
2015-02-06 16:12:32 -08:00
|
|
|
.SetMethod("setOverlayIcon", &Window::SetOverlayIcon)
|
2015-08-02 11:11:29 +08:00
|
|
|
.SetMethod("setThumbarButtons", &Window::SetThumbarButtons)
|
2015-06-24 19:51:11 +08:00
|
|
|
.SetMethod("setMenu", &Window::SetMenu)
|
2014-11-12 20:31:55 +08:00
|
|
|
.SetMethod("setAutoHideMenuBar", &Window::SetAutoHideMenuBar)
|
|
|
|
.SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide)
|
|
|
|
.SetMethod("setMenuBarVisibility", &Window::SetMenuBarVisibility)
|
|
|
|
.SetMethod("isMenuBarVisible", &Window::IsMenuBarVisible)
|
2015-03-26 14:18:37 +08:00
|
|
|
.SetMethod("setVisibleOnAllWorkspaces",
|
|
|
|
&Window::SetVisibleOnAllWorkspaces)
|
|
|
|
.SetMethod("isVisibleOnAllWorkspaces",
|
|
|
|
&Window::IsVisibleOnAllWorkspaces)
|
2016-11-28 11:38:40 -08:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
.SetMethod("setAutoHideCursor", &Window::SetAutoHideCursor)
|
|
|
|
#endif
|
2016-11-07 21:22:41 +01:00
|
|
|
.SetMethod("setVibrancy", &Window::SetVibrancy)
|
2015-10-27 14:00:08 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
.SetMethod("hookWindowMessage", &Window::HookWindowMessage)
|
|
|
|
.SetMethod("isWindowMessageHooked", &Window::IsWindowMessageHooked)
|
|
|
|
.SetMethod("unhookWindowMessage", &Window::UnhookWindowMessage)
|
|
|
|
.SetMethod("unhookAllWindowMessages", &Window::UnhookAllWindowMessages)
|
2016-07-14 13:27:16 -07:00
|
|
|
.SetMethod("setThumbnailClip", &Window::SetThumbnailClip)
|
2016-08-07 19:23:42 +02:00
|
|
|
.SetMethod("setThumbnailToolTip", &Window::SetThumbnailToolTip)
|
2016-11-12 17:21:31 +01:00
|
|
|
.SetMethod("setAppDetails", &Window::SetAppDetails)
|
2015-10-27 14:00:08 +02:00
|
|
|
#endif
|
2016-05-20 22:22:15 +09:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
|
|
|
.SetMethod("setIcon", &Window::SetIcon)
|
2014-12-18 15:40:35 -08:00
|
|
|
#endif
|
2015-12-03 15:38:43 +08:00
|
|
|
.SetProperty("id", &Window::ID)
|
|
|
|
.SetProperty("webContents", &Window::WebContents);
|
2013-04-19 00:06:10 +08:00
|
|
|
}
|
|
|
|
|
2015-10-01 13:45:59 +08:00
|
|
|
// static
|
|
|
|
v8::Local<v8::Value> Window::From(v8::Isolate* isolate,
|
|
|
|
NativeWindow* native_window) {
|
|
|
|
auto existing = TrackableObject::FromWrappedClass(isolate, native_window);
|
|
|
|
if (existing)
|
2016-04-25 10:19:25 +09:00
|
|
|
return existing->GetWrapper();
|
2015-10-01 13:45:59 +08:00
|
|
|
else
|
|
|
|
return v8::Null(isolate);
|
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
} // namespace api
|
2013-04-18 15:09:53 +08:00
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
} // namespace atom
|
2013-04-18 15:09:53 +08:00
|
|
|
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
namespace {
|
2013-04-18 15:09:53 +08:00
|
|
|
|
2015-06-24 16:37:48 +08:00
|
|
|
using atom::api::Window;
|
|
|
|
|
2015-05-22 19:11:22 +08:00
|
|
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context, void* priv) {
|
2014-06-29 20:48:44 +08:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2016-08-02 19:28:12 +09:00
|
|
|
Window::SetConstructor(isolate, base::Bind(&Window::New));
|
2016-08-02 17:02:04 +09:00
|
|
|
|
2016-08-02 17:20:58 +09:00
|
|
|
mate::Dictionary browser_window(
|
|
|
|
isolate, Window::GetConstructor(isolate)->GetFunction());
|
2015-06-24 17:58:12 +08:00
|
|
|
browser_window.SetMethod("fromId",
|
|
|
|
&mate::TrackableObject<Window>::FromWeakMapID);
|
|
|
|
browser_window.SetMethod("getAllWindows",
|
|
|
|
&mate::TrackableObject<Window>::GetAll);
|
2015-06-24 16:37:48 +08:00
|
|
|
|
2014-06-28 19:49:55 +08:00
|
|
|
mate::Dictionary dict(isolate, exports);
|
2015-06-24 16:37:48 +08:00
|
|
|
dict.Set("BrowserWindow", browser_window);
|
2013-04-16 00:25:08 +08:00
|
|
|
}
|
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
} // namespace
|
2013-04-14 15:36:48 +08:00
|
|
|
|
2014-06-29 20:48:44 +08:00
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_window, Initialize)
|