OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
6 | 6 |
7 #include "views/controls/textfield/native_textfield_gtk.h" | 7 #include "views/controls/textfield/native_textfield_gtk.h" |
8 | 8 |
9 #include "base/gfx/gtk_util.h" | 9 #include "base/gfx/gtk_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 127 } |
128 | 128 |
129 View* NativeTextfieldGtk::GetView() { | 129 View* NativeTextfieldGtk::GetView() { |
130 return this; | 130 return this; |
131 } | 131 } |
132 | 132 |
133 gfx::NativeView NativeTextfieldGtk::GetTestingHandle() const { | 133 gfx::NativeView NativeTextfieldGtk::GetTestingHandle() const { |
134 return native_view(); | 134 return native_view(); |
135 } | 135 } |
136 | 136 |
| 137 // static |
| 138 gboolean NativeTextfieldGtk::OnKeyPressEventHandler( |
| 139 GtkWidget* entry, |
| 140 GdkEventKey* event, |
| 141 NativeTextfieldGtk* textfield) { |
| 142 return textfield->OnKeyPressEvent(event); |
| 143 } |
| 144 |
| 145 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { |
| 146 Textfield::Controller* controller = textfield_->GetController(); |
| 147 if (controller) |
| 148 return controller->HandleKeystroke(textfield_, Textfield::Keystroke(event)); |
| 149 return false; |
| 150 } |
| 151 |
| 152 // static |
| 153 gboolean NativeTextfieldGtk::OnChangedHandler( |
| 154 GtkWidget* entry, |
| 155 NativeTextfieldGtk* textfield) { |
| 156 return textfield->OnChanged(); |
| 157 } |
| 158 |
| 159 gboolean NativeTextfieldGtk::OnChanged() { |
| 160 Textfield::Controller* controller = textfield_->GetController(); |
| 161 if (controller) |
| 162 controller->ContentsChanged(textfield_, GetText()); |
| 163 return false; |
| 164 } |
| 165 |
137 //////////////////////////////////////////////////////////////////////////////// | 166 //////////////////////////////////////////////////////////////////////////////// |
138 // NativeTextfieldGtk, NativeControlGtk overrides: | 167 // NativeTextfieldGtk, NativeControlGtk overrides: |
139 | 168 |
140 void NativeTextfieldGtk::CreateNativeControl() { | 169 void NativeTextfieldGtk::CreateNativeControl() { |
141 // TODO(brettw) hook in an observer to get text change events so we can call | |
142 // the controller. | |
143 NativeControlCreated(gtk_entry_new()); | 170 NativeControlCreated(gtk_entry_new()); |
144 } | 171 } |
145 | 172 |
146 void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) { | 173 void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) { |
147 NativeControlGtk::NativeControlCreated(widget); | 174 NativeControlGtk::NativeControlCreated(widget); |
148 // TODO(port): post-creation init | 175 g_signal_connect(widget, "changed", |
| 176 G_CALLBACK(OnChangedHandler), this); |
| 177 g_signal_connect(widget, "key-press-event", |
| 178 G_CALLBACK(OnKeyPressEventHandler), this); |
149 } | 179 } |
150 | 180 |
151 //////////////////////////////////////////////////////////////////////////////// | 181 //////////////////////////////////////////////////////////////////////////////// |
152 // NativeTextfieldWrapper, public: | 182 // NativeTextfieldWrapper, public: |
153 | 183 |
154 // static | 184 // static |
155 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 185 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
156 Textfield* field) { | 186 Textfield* field) { |
157 return new NativeTextfieldGtk(field); | 187 return new NativeTextfieldGtk(field); |
158 } | 188 } |
159 | 189 |
160 } // namespace views | 190 } // namespace views |
OLD | NEW |