OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "gfx/gtk_util.h" | 11 #include "gfx/gtk_util.h" |
12 #include "gfx/insets.h" | 12 #include "gfx/insets.h" |
13 #include "gfx/skia_utils_gtk.h" | 13 #include "gfx/skia_utils_gtk.h" |
14 #include "views/controls/textfield/gtk_views_entry.h" | 14 #include "views/controls/textfield/gtk_views_entry.h" |
15 #include "views/controls/textfield/gtk_views_textview.h" | 15 #include "views/controls/textfield/gtk_views_textview.h" |
16 #include "views/controls/textfield/textfield.h" | 16 #include "views/controls/textfield/textfield.h" |
17 #include "views/widget/widget_gtk.h" | |
17 | 18 |
18 namespace views { | 19 namespace views { |
19 | 20 |
20 // A character used to hide a text in password mode. | 21 // A character used to hide a text in password mode. |
21 static const char kPasswordChar = '*'; | 22 static const char kPasswordChar = '*'; |
22 | 23 |
23 // Border width for GtkTextView. | 24 // Border width for GtkTextView. |
24 const int kTextViewBorderWidth = 4; | 25 const int kTextViewBorderWidth = 4; |
25 | 26 |
26 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 | 346 |
346 // static | 347 // static |
347 gboolean NativeTextfieldGtk::OnKeyPressEventHandler( | 348 gboolean NativeTextfieldGtk::OnKeyPressEventHandler( |
348 GtkWidget* widget, | 349 GtkWidget* widget, |
349 GdkEventKey* event, | 350 GdkEventKey* event, |
350 NativeTextfieldGtk* textfield) { | 351 NativeTextfieldGtk* textfield) { |
351 return textfield->OnKeyPressEvent(event); | 352 return textfield->OnKeyPressEvent(event); |
352 } | 353 } |
353 | 354 |
354 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { | 355 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { |
356 bool handled = false; | |
357 | |
355 Textfield::Controller* controller = textfield_->GetController(); | 358 Textfield::Controller* controller = textfield_->GetController(); |
356 if (controller) { | 359 if (controller) { |
357 Textfield::Keystroke ks(event); | 360 Textfield::Keystroke ks(event); |
358 return controller->HandleKeystroke(textfield_, ks); | 361 handled = controller->HandleKeystroke(textfield_, ks); |
359 } | 362 } |
360 return false; | 363 |
364 // If the controller doesn't handle the event, invite the widget's | |
365 // keyboard event handler. This picks up accelerators that would otherwise be | |
366 // lost to the widget. | |
367 if (!handled) { | |
368 WidgetGtk* widget = static_cast<WidgetGtk*>(GetWidget()); | |
369 if (widget) | |
370 handled = widget->HandleKeyboardEvent(event); | |
371 } | |
372 return handled; | |
James Su
2010/12/02 08:37:24
This approach can cause problem as it handles a ke
| |
361 } | 373 } |
362 | 374 |
363 // static | 375 // static |
364 gboolean NativeTextfieldGtk::OnChangedHandler( | 376 gboolean NativeTextfieldGtk::OnChangedHandler( |
365 GtkWidget* widget, | 377 GtkWidget* widget, |
366 NativeTextfieldGtk* textfield) { | 378 NativeTextfieldGtk* textfield) { |
367 return textfield->OnChanged(); | 379 return textfield->OnChanged(); |
368 } | 380 } |
369 | 381 |
370 gboolean NativeTextfieldGtk::OnChanged() { | 382 gboolean NativeTextfieldGtk::OnChanged() { |
(...skipping 30 matching lines...) Expand all Loading... | |
401 if (GTK_IS_TEXT_VIEW(widget)) { | 413 if (GTK_IS_TEXT_VIEW(widget)) { |
402 GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( | 414 GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( |
403 GTK_TEXT_VIEW(widget)); | 415 GTK_TEXT_VIEW(widget)); |
404 g_signal_connect(text_buffer, "changed", | 416 g_signal_connect(text_buffer, "changed", |
405 G_CALLBACK(OnChangedHandler), this); | 417 G_CALLBACK(OnChangedHandler), this); |
406 } else { | 418 } else { |
407 g_signal_connect(widget, "changed", | 419 g_signal_connect(widget, "changed", |
408 G_CALLBACK(OnChangedHandler), this); | 420 G_CALLBACK(OnChangedHandler), this); |
409 } | 421 } |
410 g_signal_connect(widget, "key-press-event", | 422 g_signal_connect(widget, "key-press-event", |
411 G_CALLBACK(OnKeyPressEventHandler), this); | 423 G_CALLBACK(OnKeyPressEventHandler), this); |
James Su
2010/12/02 08:37:24
We need to use g_signal_connect_after() here to ma
| |
412 } | 424 } |
413 | 425 |
414 //////////////////////////////////////////////////////////////////////////////// | 426 //////////////////////////////////////////////////////////////////////////////// |
415 // NativeTextfieldWrapper, public: | 427 // NativeTextfieldWrapper, public: |
416 | 428 |
417 // static | 429 // static |
418 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 430 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
419 Textfield* field) { | 431 Textfield* field) { |
420 return new NativeTextfieldGtk(field); | 432 return new NativeTextfieldGtk(field); |
421 } | 433 } |
422 | 434 |
423 } // namespace views | 435 } // namespace views |
OLD | NEW |