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 | |
377 GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event); | |
378 gboolean handled = false; | |
379 | |
380 Textfield::Controller* controller = textfield_->GetController(); | |
381 if (controller) { | |
382 Textfield::Keystroke ks(key_event); | |
383 handled = controller->HandleKeystroke(textfield_, ks); | |
384 } | |
385 | |
386 WidgetGtk* widget = static_cast<WidgetGtk*>(GetWidget()); | |
387 if (!handled && widget) | |
388 handled = widget->HandleKeyboardEvent(key_event); | |
389 | |
390 return handled; | |
391 } | |
392 | |
393 // static | |
364 gboolean NativeTextfieldGtk::OnChangedHandler( | 394 gboolean NativeTextfieldGtk::OnChangedHandler( |
365 GtkWidget* widget, | 395 GtkWidget* widget, |
366 NativeTextfieldGtk* textfield) { | 396 NativeTextfieldGtk* textfield) { |
367 return textfield->OnChanged(); | 397 return textfield->OnChanged(); |
368 } | 398 } |
369 | 399 |
370 gboolean NativeTextfieldGtk::OnChanged() { | 400 gboolean NativeTextfieldGtk::OnChanged() { |
371 textfield_->SyncText(); | 401 textfield_->SyncText(); |
372 Textfield::Controller* controller = textfield_->GetController(); | 402 Textfield::Controller* controller = textfield_->GetController(); |
373 if (controller) | 403 if (controller) |
(...skipping 26 matching lines...) Expand all Loading... | |
400 | 430 |
401 if (GTK_IS_TEXT_VIEW(widget)) { | 431 if (GTK_IS_TEXT_VIEW(widget)) { |
402 GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( | 432 GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( |
403 GTK_TEXT_VIEW(widget)); | 433 GTK_TEXT_VIEW(widget)); |
404 g_signal_connect(text_buffer, "changed", | 434 g_signal_connect(text_buffer, "changed", |
405 G_CALLBACK(OnChangedHandler), this); | 435 G_CALLBACK(OnChangedHandler), this); |
406 } else { | 436 } else { |
407 g_signal_connect(widget, "changed", | 437 g_signal_connect(widget, "changed", |
408 G_CALLBACK(OnChangedHandler), this); | 438 G_CALLBACK(OnChangedHandler), this); |
409 } | 439 } |
410 g_signal_connect(widget, "key-press-event", | 440 g_signal_connect_after(widget, "key-press-event", |
Dmitry Polukhin
2011/01/17 10:50:19
Changing g_signal_connect_after to g_signal_connec
James Su
2011/01/17 18:35:16
We should never intercept key events before being
Dmitry Polukhin
2011/01/17 20:10:21
What will happen on Windows? Is it possible to wri
James Su
2011/01/17 21:25:39
Windows has different event flow, which will alway
| |
411 G_CALLBACK(OnKeyPressEventHandler), this); | 441 G_CALLBACK(OnKeyPressEventHandler), this); |
442 // In order to properly trigger Accelerators bound to VKEY_RETURN, we need to | |
443 // send an event when the widget gets the activate signal. | |
444 g_signal_connect(widget, "activate", G_CALLBACK(OnActivateHandler), this); | |
412 } | 445 } |
413 | 446 |
414 //////////////////////////////////////////////////////////////////////////////// | 447 //////////////////////////////////////////////////////////////////////////////// |
415 // NativeTextfieldWrapper, public: | 448 // NativeTextfieldWrapper, public: |
416 | 449 |
417 // static | 450 // static |
418 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 451 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
419 Textfield* field) { | 452 Textfield* field) { |
420 return new NativeTextfieldGtk(field); | 453 return new NativeTextfieldGtk(field); |
421 } | 454 } |
422 | 455 |
423 } // namespace views | 456 } // namespace views |
OLD | NEW |