2018-05-24 07:56:02 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2018-09-28 02:47:09 +00:00
|
|
|
#include "atom/browser/api/views/atom_api_button.h"
|
2018-05-24 07:56:02 +00:00
|
|
|
|
|
|
|
#include "atom/common/api/constructor.h"
|
|
|
|
#include "atom/common/node_includes.h"
|
2019-03-12 00:13:43 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
2018-05-24 07:56:02 +00:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2018-10-23 14:57:13 +00:00
|
|
|
Button::Button(views::Button* impl) : View(impl) {
|
2018-05-24 07:56:02 +00:00
|
|
|
view()->set_owned_by_client();
|
2018-10-23 14:57:13 +00:00
|
|
|
// Make the button focusable as per the platform.
|
|
|
|
button()->SetFocusForPlatform();
|
2018-05-24 07:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Button::~Button() {}
|
|
|
|
|
2018-05-24 08:11:08 +00:00
|
|
|
void Button::ButtonPressed(views::Button* sender, const ui::Event& event) {
|
|
|
|
Emit("click");
|
|
|
|
}
|
|
|
|
|
2018-05-24 07:56:02 +00:00
|
|
|
// static
|
|
|
|
mate::WrappableBase* Button::New(mate::Arguments* args) {
|
|
|
|
args->ThrowError("Button can not be created directly");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void Button::BuildPrototype(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
|
|
|
prototype->SetClassName(mate::StringToV8(isolate, "Button"));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using atom::api::Button;
|
|
|
|
|
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
mate::Dictionary dict(isolate, exports);
|
2019-04-30 00:40:39 +00:00
|
|
|
dict.Set("Button", mate::CreateConstructor<Button>(
|
|
|
|
isolate, base::BindRepeating(&Button::New)));
|
2018-05-24 07:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-03-08 18:29:52 +00:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_button, Initialize)
|