2018-05-24 07:26:17 +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.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/views/electron_api_text_field.h"
|
2018-05-24 07:26:17 +00:00
|
|
|
|
2019-12-05 09:46:34 +00:00
|
|
|
#include "shell/common/gin_helper/constructor.h"
|
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/node_includes.h"
|
2018-05-24 07:26:17 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2018-05-24 07:26:17 +00:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
TextField::TextField() : View(new views::Textfield()) {
|
|
|
|
view()->set_owned_by_client();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextField::~TextField() {}
|
|
|
|
|
2018-05-30 06:47:24 +00:00
|
|
|
void TextField::SetText(const base::string16& new_text) {
|
|
|
|
text_field()->SetText(new_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
base::string16 TextField::GetText() const {
|
|
|
|
return text_field()->text();
|
|
|
|
}
|
|
|
|
|
2018-05-24 07:26:17 +00:00
|
|
|
// static
|
2019-12-05 09:46:34 +00:00
|
|
|
gin_helper::WrappableBase* TextField::New(gin_helper::Arguments* args) {
|
2018-05-24 07:26:17 +00:00
|
|
|
// Constructor call.
|
|
|
|
auto* view = new TextField();
|
|
|
|
view->InitWith(args->isolate(), args->GetThis());
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void TextField::BuildPrototype(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
2019-12-05 09:46:34 +00:00
|
|
|
prototype->SetClassName(gin_helper::StringTov8(isolate, "TextField"));
|
|
|
|
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2018-05-30 06:47:24 +00:00
|
|
|
.SetMethod("setText", &TextField::SetText)
|
|
|
|
.SetMethod("getText", &TextField::GetText);
|
2018-05-24 07:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2018-05-24 07:26:17 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
using electron::api::TextField;
|
2018-05-24 07:26:17 +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();
|
2019-12-05 09:46:34 +00:00
|
|
|
gin_helper::Dictionary dict(isolate, exports);
|
|
|
|
dict.Set("TextField", gin_helper::CreateConstructor<TextField>(
|
2019-04-30 00:40:39 +00:00
|
|
|
isolate, base::BindRepeating(&TextField::New)));
|
2018-05-24 07:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-03-08 18:29:52 +00:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_text_field, Initialize)
|