Chromium Code Reviews| 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 <gdk/gdkkeysyms.h> | |
| 5 #include <gtk/gtk.h> | 6 #include <gtk/gtk.h> |
| 6 | 7 |
| 7 #include "views/controls/textfield/native_textfield_gtk.h" | 8 #include "views/controls/textfield/native_textfield_gtk.h" |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "gfx/gtk_util.h" | 12 #include "gfx/gtk_util.h" |
| 12 #include "gfx/insets.h" | 13 #include "gfx/insets.h" |
| 13 #include "gfx/skia_utils_gtk.h" | 14 #include "gfx/skia_utils_gtk.h" |
| 14 #include "views/controls/textfield/gtk_views_entry.h" | 15 #include "views/controls/textfield/gtk_views_entry.h" |
| 15 #include "views/controls/textfield/gtk_views_textview.h" | 16 #include "views/controls/textfield/gtk_views_textview.h" |
| 16 #include "views/controls/textfield/textfield.h" | 17 #include "views/controls/textfield/textfield.h" |
| 18 #include "views/widget/widget_gtk.h" | |
| 17 | 19 |
| 18 namespace views { | 20 namespace views { |
| 19 | 21 |
| 20 // A character used to hide a text in password mode. | 22 // A character used to hide a text in password mode. |
| 21 static const char kPasswordChar = '*'; | 23 static const char kPasswordChar = '*'; |
| 22 | 24 |
| 23 // Border width for GtkTextView. | 25 // Border width for GtkTextView. |
| 24 const int kTextViewBorderWidth = 4; | 26 const int kTextViewBorderWidth = 4; |
| 25 | 27 |
| 26 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { | 356 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { |
| 355 Textfield::Controller* controller = textfield_->GetController(); | 357 Textfield::Controller* controller = textfield_->GetController(); |
| 356 if (controller) { | 358 if (controller) { |
| 357 Textfield::Keystroke ks(event); | 359 Textfield::Keystroke ks(event); |
| 358 return controller->HandleKeystroke(textfield_, ks); | 360 return controller->HandleKeystroke(textfield_, ks); |
| 359 } | 361 } |
| 360 return false; | 362 return false; |
| 361 } | 363 } |
| 362 | 364 |
| 363 // static | 365 // static |
| 366 gboolean NativeTextfieldGtk::OnActivateHandler( | |
| 367 GtkWidget* widget, | |
| 368 NativeTextfieldGtk* textfield) { | |
| 369 return textfield->OnActivate(); | |
| 370 } | |
| 371 | |
| 372 gboolean NativeTextfieldGtk::OnActivate() { | |
| 373 GdkEvent* event = gtk_get_current_event(); | |
| 374 if (!event || event->type != GDK_KEY_PRESS) { | |
| 375 return false; | |
| 376 } | |
|
James Su
2010/12/15 06:06:43
No braces.
Zachary Kuznia
2010/12/15 08:23:25
Done.
| |
| 377 | |
| 378 GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event); | |
| 379 gboolean handled = false; | |
| 380 | |
| 381 Textfield::Controller* controller = textfield_->GetController(); | |
| 382 if (controller) { | |
| 383 Textfield::Keystroke ks(key_event); | |
| 384 handled = controller->HandleKeystroke(textfield_, ks); | |
| 385 } | |
| 386 | |
| 387 WidgetGtk* widget = static_cast<WidgetGtk*>(GetWidget()); | |
| 388 if (!handled && widget) { | |
| 389 handled = widget->HandleKeyboardEvent(key_event); | |
| 390 } | |
|
James Su
2010/12/15 06:06:43
No braces.
Zachary Kuznia
2010/12/15 08:23:25
Done.
| |
| 391 return handled; | |
| 392 } | |
| 393 | |
| 394 // static | |
| 364 gboolean NativeTextfieldGtk::OnChangedHandler( | 395 gboolean NativeTextfieldGtk::OnChangedHandler( |
| 365 GtkWidget* widget, | 396 GtkWidget* widget, |
| 366 NativeTextfieldGtk* textfield) { | 397 NativeTextfieldGtk* textfield) { |
| 367 return textfield->OnChanged(); | 398 return textfield->OnChanged(); |
| 368 } | 399 } |
| 369 | 400 |
| 370 gboolean NativeTextfieldGtk::OnChanged() { | 401 gboolean NativeTextfieldGtk::OnChanged() { |
| 371 textfield_->SyncText(); | 402 textfield_->SyncText(); |
| 372 Textfield::Controller* controller = textfield_->GetController(); | 403 Textfield::Controller* controller = textfield_->GetController(); |
| 373 if (controller) | 404 if (controller) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 400 | 431 |
| 401 if (GTK_IS_TEXT_VIEW(widget)) { | 432 if (GTK_IS_TEXT_VIEW(widget)) { |
| 402 GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( | 433 GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( |
| 403 GTK_TEXT_VIEW(widget)); | 434 GTK_TEXT_VIEW(widget)); |
| 404 g_signal_connect(text_buffer, "changed", | 435 g_signal_connect(text_buffer, "changed", |
| 405 G_CALLBACK(OnChangedHandler), this); | 436 G_CALLBACK(OnChangedHandler), this); |
| 406 } else { | 437 } else { |
| 407 g_signal_connect(widget, "changed", | 438 g_signal_connect(widget, "changed", |
| 408 G_CALLBACK(OnChangedHandler), this); | 439 G_CALLBACK(OnChangedHandler), this); |
| 409 } | 440 } |
| 410 g_signal_connect(widget, "key-press-event", | 441 g_signal_connect_after(widget, "key-press-event", |
| 411 G_CALLBACK(OnKeyPressEventHandler), this); | 442 G_CALLBACK(OnKeyPressEventHandler), this); |
|
James Su
2010/12/15 06:06:43
Alignment.
Zachary Kuznia
2010/12/15 08:23:25
Done.
| |
| 443 // In order to properly trigger Accelerators bound to VKEY_RETURN, we need to | |
| 444 // send an event when the widget gets the activate signal. | |
| 445 g_signal_connect(widget, "activate", G_CALLBACK(&OnActivateHandler), this); | |
|
James Su
2010/12/15 06:06:43
& is not necessary.
Zachary Kuznia
2010/12/15 08:23:25
Done.
| |
| 412 } | 446 } |
| 413 | 447 |
| 414 //////////////////////////////////////////////////////////////////////////////// | 448 //////////////////////////////////////////////////////////////////////////////// |
| 415 // NativeTextfieldWrapper, public: | 449 // NativeTextfieldWrapper, public: |
| 416 | 450 |
| 417 // static | 451 // static |
| 418 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 452 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 419 Textfield* field) { | 453 Textfield* field) { |
| 420 return new NativeTextfieldGtk(field); | 454 return new NativeTextfieldGtk(field); |
| 421 } | 455 } |
| 422 | 456 |
| 423 } // namespace views | 457 } // namespace views |
| OLD | NEW |