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 <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" |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { | 354 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { |
| 355 Textfield::Controller* controller = textfield_->GetController(); | 355 Textfield::Controller* controller = textfield_->GetController(); |
| 356 if (controller) { | 356 if (controller) { |
| 357 Textfield::Keystroke ks(event); | 357 Textfield::Keystroke ks(event); |
| 358 return controller->HandleKeystroke(textfield_, ks); | 358 return controller->HandleKeystroke(textfield_, ks); |
| 359 } | 359 } |
| 360 return false; | 360 return false; |
| 361 } | 361 } |
| 362 | 362 |
| 363 // static | 363 // static |
| 364 gboolean NativeTextfieldGtk::OnActivateHandler( | |
| 365 GtkWidget* widget, | |
| 366 NativeTextfieldGtk* textfield) { | |
| 367 return textfield->OnActivate(); | |
| 368 } | |
| 369 | |
| 370 gboolean NativeTextfieldGtk::OnActivate() { | |
| 371 return textfield_->GetParent()->AcceleratorPressed( | |
| 372 Accelerator(app::VKEY_RETURN, false, false, false)); | |
|
James Su
2010/12/01 18:35:56
It's probably better to call the widget's HandleKe
| |
| 373 } | |
| 374 | |
| 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() { |
| 371 textfield_->SyncText(); | 383 textfield_->SyncText(); |
| 372 Textfield::Controller* controller = textfield_->GetController(); | 384 Textfield::Controller* controller = textfield_->GetController(); |
| 373 if (controller) | 385 if (controller) |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 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); |
| 424 // In order to properly trigger Accelerators bound to VKEY_RETURN, we need to | |
| 425 // send an event when the widget gets the activate signal. | |
| 426 g_signal_connect(widget, "activate", G_CALLBACK(&OnActivateHandler), this); | |
|
James Su
2010/12/01 18:35:56
Only GtkEntry has "activate" signal.
| |
| 412 } | 427 } |
| 413 | 428 |
| 414 //////////////////////////////////////////////////////////////////////////////// | 429 //////////////////////////////////////////////////////////////////////////////// |
| 415 // NativeTextfieldWrapper, public: | 430 // NativeTextfieldWrapper, public: |
| 416 | 431 |
| 417 // static | 432 // static |
| 418 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 433 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 419 Textfield* field) { | 434 Textfield* field) { |
| 420 return new NativeTextfieldGtk(field); | 435 return new NativeTextfieldGtk(field); |
| 421 } | 436 } |
| 422 | 437 |
| 423 } // namespace views | 438 } // namespace views |
| OLD | NEW |