diff --git a/atom/browser/api/atom_api_text_field.cc b/atom/browser/api/atom_api_text_field.cc index 2eb927591e..c1ceea3b54 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 c7dfa0c9ce..fd7d592325 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); };