summaryrefslogtreecommitdiffstats
path: root/views/controls/textfield
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 22:35:40 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 22:35:40 +0000
commit6bc080954611da13cfba38879e96792c079d1a95 (patch)
tree9cd29e2c9faa988cf6dbcf9024b832776509759d /views/controls/textfield
parent005afbdc6836ecd6b3a09ab76b00221201830210 (diff)
downloadchromium_src-6bc080954611da13cfba38879e96792c079d1a95.zip
chromium_src-6bc080954611da13cfba38879e96792c079d1a95.tar.gz
chromium_src-6bc080954611da13cfba38879e96792c079d1a95.tar.bz2
Make the views bookmark bubble work on GTK.
The combobox still isn't implemented, but this makes TextBox work, and also does some changes around the info_bubble to make sure it get created properly. TEST=none BUG=none. Review URL: http://codereview.chromium.org/177026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/textfield')
-rw-r--r--views/controls/textfield/native_textfield_gtk.cc73
-rw-r--r--views/controls/textfield/native_textfield_gtk.h2
2 files changed, 71 insertions, 4 deletions
diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc
index 87ef0db..82cda2b 100644
--- a/views/controls/textfield/native_textfield_gtk.cc
+++ b/views/controls/textfield/native_textfield_gtk.cc
@@ -4,13 +4,19 @@
#include "views/controls/textfield/native_textfield_gtk.h"
+#include "base/string_util.h"
+#include "views/controls/textfield/textfield.h"
+
namespace views {
////////////////////////////////////////////////////////////////////////////////
// NativeTextfieldGtk, public:
NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield)
- : NativeControlGtk() {
+ : NativeControlGtk(),
+ textfield_(textfield) {
+ if (textfield_->style() & Textfield::STYLE_MULTILINE)
+ NOTIMPLEMENTED(); // We don't support multiline yet.
}
NativeTextfieldGtk::~NativeTextfieldGtk() {
@@ -20,44 +26,91 @@ NativeTextfieldGtk::~NativeTextfieldGtk() {
// NativeTextfieldGtk, NativeTextfieldWrapper implementation:
std::wstring NativeTextfieldGtk::GetText() const {
- return std::wstring();
+ if (!native_view())
+ return std::wstring();
+ return UTF8ToWide(gtk_entry_get_text(GTK_ENTRY(native_view())));
}
void NativeTextfieldGtk::UpdateText() {
+ if (!native_view())
+ return;
+ gtk_entry_set_text(GTK_ENTRY(native_view()),
+ WideToUTF8(textfield_->text()).c_str());
}
void NativeTextfieldGtk::AppendText(const std::wstring& text) {
+ if (!native_view())
+ return;
+ gtk_entry_append_text(GTK_ENTRY(native_view()), WideToUTF8(text).c_str());
}
std::wstring NativeTextfieldGtk::GetSelectedText() const {
- return std::wstring();
+ if (!native_view())
+ return std::wstring();
+
+ int begin, end;
+ if (!gtk_editable_get_selection_bounds(GTK_EDITABLE(native_view()),
+ &begin, &end))
+ return std::wstring(); // Nothing selected.
+
+ return UTF8ToWide(std::string(
+ &gtk_entry_get_text(GTK_ENTRY(native_view()))[begin],
+ end - begin));
}
void NativeTextfieldGtk::SelectAll() {
+ if (!native_view())
+ return;
+ // -1 as the end position selects to the end of the text.
+ gtk_editable_select_region(GTK_EDITABLE(native_view()),
+ 0, -1);
}
void NativeTextfieldGtk::ClearSelection() {
+ if (!native_view())
+ return;
+ gtk_editable_select_region(GTK_EDITABLE(native_view()), 0, 0);
}
void NativeTextfieldGtk::UpdateBorder() {
+ if (!native_view())
+ return;
+ NOTIMPLEMENTED();
}
void NativeTextfieldGtk::UpdateBackgroundColor() {
+ if (!native_view())
+ return;
+ NOTIMPLEMENTED();
}
void NativeTextfieldGtk::UpdateReadOnly() {
+ if (!native_view())
+ return;
+ gtk_editable_set_editable(GTK_EDITABLE(native_view()),
+ textfield_->IsEnabled());
}
void NativeTextfieldGtk::UpdateFont() {
+ if (!native_view())
+ return;
+ NOTIMPLEMENTED();
}
void NativeTextfieldGtk::UpdateEnabled() {
+ if (!native_view())
+ return;
+ NOTIMPLEMENTED();
}
void NativeTextfieldGtk::SetHorizontalMargins(int left, int right) {
+ if (!native_view())
+ return;
+ NOTIMPLEMENTED();
}
void NativeTextfieldGtk::SetFocus() {
+ Focus();
}
View* NativeTextfieldGtk::GetView() {
@@ -72,7 +125,10 @@ gfx::NativeView NativeTextfieldGtk::GetTestingHandle() const {
// NativeTextfieldGtk, NativeControlGtk overrides:
void NativeTextfieldGtk::CreateNativeControl() {
- // TODO(port): create gtk text field
+ GtkWidget* widget = gtk_entry_new();
+ // TODO(brettw) hook in an observer to get text change events so we can call
+ // the controller.
+ NativeControlCreated(widget);
}
void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) {
@@ -80,4 +136,13 @@ void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) {
// TODO(port): post-creation init
}
+////////////////////////////////////////////////////////////////////////////////
+// NativeTextfieldWrapper, public:
+
+// static
+NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
+ Textfield* field) {
+ return new NativeTextfieldGtk(field);
+}
+
} // namespace views
diff --git a/views/controls/textfield/native_textfield_gtk.h b/views/controls/textfield/native_textfield_gtk.h
index ce89e55..83013f3 100644
--- a/views/controls/textfield/native_textfield_gtk.h
+++ b/views/controls/textfield/native_textfield_gtk.h
@@ -38,6 +38,8 @@ class NativeTextfieldGtk : public NativeControlGtk,
virtual void NativeControlCreated(GtkWidget* widget);
private:
+ Textfield* textfield_;
+
DISALLOW_COPY_AND_ASSIGN(NativeTextfieldGtk);
};