electron/shell/browser/api/views/electron_api_button.cc

60 lines
1.6 KiB
C++
Raw Normal View History

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.
#include "shell/browser/api/views/electron_api_button.h"
2018-05-24 07:56:02 +00:00
#include "shell/common/gin_helper/constructor.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
2018-05-24 07:56:02 +00:00
namespace electron {
2018-05-24 07:56:02 +00:00
namespace api {
Button::Button(views::Button* impl) : View(impl) {
2018-05-24 07:56:02 +00:00
view()->set_owned_by_client();
// 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
gin_helper::WrappableBase* Button::New(gin_helper::Arguments* args) {
2018-05-24 07:56:02 +00:00
args->ThrowError("Button can not be created directly");
return nullptr;
}
// static
void Button::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(gin_helper::StringTov8(isolate, "Button"));
2018-05-24 07:56:02 +00:00
}
} // namespace api
} // namespace electron
2018-05-24 07:56:02 +00:00
namespace {
using electron::api::Button;
2018-05-24 07:56:02 +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();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("Button", gin_helper::CreateConstructor<Button>(
isolate, base::BindRepeating(&Button::New)));
2018-05-24 07:56:02 +00:00
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_button, Initialize)