| 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 "app/gfx/gtk_util.h" | 9 #include "app/gfx/gtk_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "skia/ext/skia_utils_gtk.h" | 11 #include "skia/ext/skia_utils_gtk.h" |
| 12 #include "views/controls/textfield/textfield.h" | 12 #include "views/controls/textfield/textfield.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 // A character used to hide a text in password mode. |
| 16 const char kPasswordChar = '*'; |
| 15 | 17 |
| 16 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 17 // NativeTextfieldGtk, public: | 19 // NativeTextfieldGtk, public: |
| 18 | 20 |
| 19 NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield) | 21 NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield) |
| 20 : textfield_(textfield) { | 22 : textfield_(textfield) { |
| 21 if (textfield_->style() & Textfield::STYLE_MULTILINE) | 23 if (textfield_->style() & Textfield::STYLE_MULTILINE) |
| 22 NOTIMPLEMENTED(); // We don't support multiline yet. | 24 NOTIMPLEMENTED(); // We don't support multiline yet. |
| 23 // Make |textfield| the focused view, so that when we get focused the focus | 25 // Make |textfield| the focused view, so that when we get focused the focus |
| 24 // manager sees |textfield| as the focused view (since we are just a wrapper | 26 // manager sees |textfield| as the focused view (since we are just a wrapper |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 if (controller) | 224 if (controller) |
| 223 controller->ContentsChanged(textfield_, GetText()); | 225 controller->ContentsChanged(textfield_, GetText()); |
| 224 return false; | 226 return false; |
| 225 } | 227 } |
| 226 | 228 |
| 227 //////////////////////////////////////////////////////////////////////////////// | 229 //////////////////////////////////////////////////////////////////////////////// |
| 228 // NativeTextfieldGtk, NativeControlGtk overrides: | 230 // NativeTextfieldGtk, NativeControlGtk overrides: |
| 229 | 231 |
| 230 void NativeTextfieldGtk::CreateNativeControl() { | 232 void NativeTextfieldGtk::CreateNativeControl() { |
| 231 NativeControlCreated(gtk_entry_new()); | 233 NativeControlCreated(gtk_entry_new()); |
| 234 if (textfield_->IsPassword()) { |
| 235 gtk_entry_set_invisible_char(GTK_ENTRY(native_view()), |
| 236 static_cast<gunichar>(kPasswordChar)); |
| 237 gtk_entry_set_visibility(GTK_ENTRY(native_view()), false); |
| 238 } |
| 232 } | 239 } |
| 233 | 240 |
| 234 void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) { | 241 void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) { |
| 235 NativeControlGtk::NativeControlCreated(widget); | 242 NativeControlGtk::NativeControlCreated(widget); |
| 236 g_signal_connect(widget, "changed", | 243 g_signal_connect(widget, "changed", |
| 237 G_CALLBACK(OnChangedHandler), this); | 244 G_CALLBACK(OnChangedHandler), this); |
| 238 g_signal_connect(widget, "key-press-event", | 245 g_signal_connect(widget, "key-press-event", |
| 239 G_CALLBACK(OnKeyPressEventHandler), this); | 246 G_CALLBACK(OnKeyPressEventHandler), this); |
| 240 } | 247 } |
| 241 | 248 |
| 242 //////////////////////////////////////////////////////////////////////////////// | 249 //////////////////////////////////////////////////////////////////////////////// |
| 243 // NativeTextfieldWrapper, public: | 250 // NativeTextfieldWrapper, public: |
| 244 | 251 |
| 245 // static | 252 // static |
| 246 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 253 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 247 Textfield* field) { | 254 Textfield* field) { |
| 248 return new NativeTextfieldGtk(field); | 255 return new NativeTextfieldGtk(field); |
| 249 } | 256 } |
| 250 | 257 |
| 251 } // namespace views | 258 } // namespace views |
| OLD | NEW |