OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <gdk/gdkkeysyms.h> | 5 #include <gdk/gdkkeysyms.h> |
6 #include <gtk/gtk.h> | 6 #include <gtk/gtk.h> |
7 | 7 |
8 #include "ui/views/controls/textfield/native_textfield_gtk.h" | 8 #include "ui/views/controls/textfield/native_textfield_gtk.h" |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "ui/base/range/range.h" | 12 #include "ui/base/range/range.h" |
13 #include "ui/gfx/gtk_util.h" | 13 #include "ui/gfx/gtk_util.h" |
14 #include "ui/gfx/insets.h" | 14 #include "ui/gfx/insets.h" |
15 #include "ui/gfx/selection_model.h" | 15 #include "ui/gfx/selection_model.h" |
16 #include "ui/gfx/skia_utils_gtk.h" | 16 #include "ui/gfx/skia_utils_gtk.h" |
17 #include "ui/views/controls/textfield/gtk_views_entry.h" | 17 #include "ui/views/controls/textfield/gtk_views_entry.h" |
18 #include "ui/views/controls/textfield/gtk_views_textview.h" | 18 #include "ui/views/controls/textfield/gtk_views_textview.h" |
19 #include "ui/views/controls/textfield/native_textfield_views.h" | 19 #include "ui/views/controls/textfield/native_textfield_views.h" |
20 #include "ui/views/controls/textfield/textfield.h" | 20 #include "ui/views/controls/textfield/textfield.h" |
21 #include "ui/views/controls/textfield/textfield_controller.h" | 21 #include "ui/views/controls/textfield/textfield_controller.h" |
22 #include "ui/views/widget/native_widget_gtk.h" | 22 #include "ui/views/widget/native_widget_gtk.h" |
23 | 23 |
24 namespace views { | 24 namespace views { |
25 | 25 |
26 // A character used to hide a text in password mode. | 26 // A character used to hide a text in obscured mode. |
27 static const char kPasswordChar = '*'; | 27 static const char kObscuredChar = '*'; |
28 | 28 |
29 // Border width for GtkTextView. | 29 // Border width for GtkTextView. |
30 const int kTextViewBorderWidth = 4; | 30 const int kTextViewBorderWidth = 4; |
31 | 31 |
32 //////////////////////////////////////////////////////////////////////////////// | 32 //////////////////////////////////////////////////////////////////////////////// |
33 // NativeTextfieldGtk, public: | 33 // NativeTextfieldGtk, public: |
34 | 34 |
35 NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield) | 35 NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield) |
36 : textfield_(textfield), | 36 : textfield_(textfield), |
37 paste_clipboard_requested_(false) { | 37 paste_clipboard_requested_(false) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 159 } |
160 | 160 |
161 void NativeTextfieldGtk::UpdateFont() { | 161 void NativeTextfieldGtk::UpdateFont() { |
162 if (!native_view()) | 162 if (!native_view()) |
163 return; | 163 return; |
164 PangoFontDescription* pfd = textfield_->font().GetNativeFont(); | 164 PangoFontDescription* pfd = textfield_->font().GetNativeFont(); |
165 gtk_widget_modify_font(native_view(), pfd); | 165 gtk_widget_modify_font(native_view(), pfd); |
166 pango_font_description_free(pfd); | 166 pango_font_description_free(pfd); |
167 } | 167 } |
168 | 168 |
169 void NativeTextfieldGtk::UpdateIsPassword() { | 169 void NativeTextfieldGtk::UpdateIsObscured() { |
170 if (!native_view()) | 170 if (!native_view()) |
171 return; | 171 return; |
172 gtk_entry_set_visibility(GTK_ENTRY(native_view()), !textfield_->IsPassword()); | 172 gtk_entry_set_visibility(GTK_ENTRY(native_view()), !textfield_->IsObscured()); |
173 } | 173 } |
174 | 174 |
175 void NativeTextfieldGtk::UpdateEnabled() { | 175 void NativeTextfieldGtk::UpdateEnabled() { |
176 if (!native_view()) | 176 if (!native_view()) |
177 return; | 177 return; |
178 SetEnabled(textfield_->enabled()); | 178 SetEnabled(textfield_->enabled()); |
179 } | 179 } |
180 | 180 |
181 gfx::Insets NativeTextfieldGtk::CalculateInsets() { | 181 gfx::Insets NativeTextfieldGtk::CalculateInsets() { |
182 if (!native_view()) | 182 if (!native_view()) |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 if (!textfield_->read_only()) | 392 if (!textfield_->read_only()) |
393 paste_clipboard_requested_ = true; | 393 paste_clipboard_requested_ = true; |
394 } | 394 } |
395 | 395 |
396 //////////////////////////////////////////////////////////////////////////////// | 396 //////////////////////////////////////////////////////////////////////////////// |
397 // NativeTextfieldGtk, NativeControlGtk overrides: | 397 // NativeTextfieldGtk, NativeControlGtk overrides: |
398 | 398 |
399 void NativeTextfieldGtk::CreateNativeControl() { | 399 void NativeTextfieldGtk::CreateNativeControl() { |
400 NativeControlCreated(gtk_views_entry_new(this)); | 400 NativeControlCreated(gtk_views_entry_new(this)); |
401 gtk_entry_set_invisible_char(GTK_ENTRY(native_view()), | 401 gtk_entry_set_invisible_char(GTK_ENTRY(native_view()), |
402 static_cast<gunichar>(kPasswordChar)); | 402 static_cast<gunichar>(kObscuredChar)); |
403 textfield_->UpdateAllProperties(); | 403 textfield_->UpdateAllProperties(); |
404 } | 404 } |
405 | 405 |
406 void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) { | 406 void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) { |
407 NativeControlGtk::NativeControlCreated(widget); | 407 NativeControlGtk::NativeControlCreated(widget); |
408 | 408 |
409 g_signal_connect(widget, "changed", G_CALLBACK(OnChangedThunk), this); | 409 g_signal_connect(widget, "changed", G_CALLBACK(OnChangedThunk), this); |
410 // In order to properly trigger Accelerators bound to VKEY_RETURN, we need | 410 // In order to properly trigger Accelerators bound to VKEY_RETURN, we need |
411 // to send an event when the widget gets the activate signal. | 411 // to send an event when the widget gets the activate signal. |
412 g_signal_connect(widget, "activate", G_CALLBACK(OnActivateThunk), this); | 412 g_signal_connect(widget, "activate", G_CALLBACK(OnActivateThunk), this); |
413 g_signal_connect(widget, "move-cursor", G_CALLBACK(OnMoveCursorThunk), this); | 413 g_signal_connect(widget, "move-cursor", G_CALLBACK(OnMoveCursorThunk), this); |
414 g_signal_connect(widget, "button-press-event", | 414 g_signal_connect(widget, "button-press-event", |
415 G_CALLBACK(OnButtonPressEventThunk), this); | 415 G_CALLBACK(OnButtonPressEventThunk), this); |
416 g_signal_connect(widget, "key-press-event", | 416 g_signal_connect(widget, "key-press-event", |
417 G_CALLBACK(OnKeyPressEventThunk), this); | 417 G_CALLBACK(OnKeyPressEventThunk), this); |
418 g_signal_connect(widget, "paste-clipboard", | 418 g_signal_connect(widget, "paste-clipboard", |
419 G_CALLBACK(OnPasteClipboardThunk), this); | 419 G_CALLBACK(OnPasteClipboardThunk), this); |
420 | 420 |
421 g_signal_connect_after(widget, "button-release-event", | 421 g_signal_connect_after(widget, "button-release-event", |
422 G_CALLBACK(OnButtonReleaseEventAfterThunk), this); | 422 G_CALLBACK(OnButtonReleaseEventAfterThunk), this); |
423 g_signal_connect_after(widget, "key-press-event", | 423 g_signal_connect_after(widget, "key-press-event", |
424 G_CALLBACK(OnKeyPressEventAfterThunk), this); | 424 G_CALLBACK(OnKeyPressEventAfterThunk), this); |
425 } | 425 } |
426 | 426 |
427 bool NativeTextfieldGtk::IsPassword() { | 427 bool NativeTextfieldGtk::IsObscured() { |
428 return textfield_->IsPassword(); | 428 return textfield_->IsObscured(); |
429 } | 429 } |
430 | 430 |
431 /////////////////////////////////////////////////////////////////////////////// | 431 /////////////////////////////////////////////////////////////////////////////// |
432 // NativeTextfieldWrapper: | 432 // NativeTextfieldWrapper: |
433 | 433 |
434 // static | 434 // static |
435 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 435 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
436 Textfield* field) { | 436 Textfield* field) { |
437 if (Widget::IsPureViews()) | 437 if (Widget::IsPureViews()) |
438 return new NativeTextfieldViews(field); | 438 return new NativeTextfieldViews(field); |
439 return new NativeTextfieldGtk(field); | 439 return new NativeTextfieldGtk(field); |
440 } | 440 } |
441 | 441 |
442 } // namespace views | 442 } // namespace views |
OLD | NEW |