From a11182ca84254fd4be9a0b0240925f099a5e3f61 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 30 May 2018 15:47:24 +0900 Subject: [PATCH] feat: add SetText for TextField --- atom/browser/api/atom_api_text_field.cc | 12 +++++++++++- atom/browser/api/atom_api_text_field.h | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_text_field.cc b/atom/browser/api/atom_api_text_field.cc index 2eb927591eca..c1ceea3b54a5 100644 --- a/atom/browser/api/atom_api_text_field.cc +++ b/atom/browser/api/atom_api_text_field.cc @@ -6,7 +6,6 @@ #include "atom/common/api/constructor.h" #include "native_mate/dictionary.h" -#include "ui/views/controls/textfield/textfield.h" #include "atom/common/node_includes.h" @@ -20,6 +19,14 @@ TextField::TextField() : View(new views::Textfield()) { TextField::~TextField() {} +void TextField::SetText(const base::string16& new_text) { + text_field()->SetText(new_text); +} + +base::string16 TextField::GetText() const { + return text_field()->text(); +} + // static mate::WrappableBase* TextField::New(mate::Arguments* args) { // Constructor call. @@ -32,6 +39,9 @@ mate::WrappableBase* TextField::New(mate::Arguments* args) { void TextField::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { prototype->SetClassName(mate::StringToV8(isolate, "TextField")); + mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + .SetMethod("setText", &TextField::SetText) + .SetMethod("getText", &TextField::GetText); } } // namespace api diff --git a/atom/browser/api/atom_api_text_field.h b/atom/browser/api/atom_api_text_field.h index c7dfa0c9cea0..fd7d592325c8 100644 --- a/atom/browser/api/atom_api_text_field.h +++ b/atom/browser/api/atom_api_text_field.h @@ -7,6 +7,7 @@ #include "atom/browser/api/atom_api_view.h" #include "native_mate/handle.h" +#include "ui/views/controls/textfield/textfield.h" namespace atom { @@ -19,10 +20,17 @@ class TextField : public View { static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); + void SetText(const base::string16& new_text); + base::string16 GetText() const; + private: TextField(); ~TextField() override; + views::Textfield* text_field() const { + return static_cast(view()); + } + private: DISALLOW_COPY_AND_ASSIGN(TextField); };