| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/textfield/native_textfield_gtk.h" | 8 #include "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/gfx/gtk_util.h" | 12 #include "ui/gfx/gtk_util.h" |
| 13 #include "ui/gfx/insets.h" | 13 #include "ui/gfx/insets.h" |
| 14 #include "ui/gfx/skia_utils_gtk.h" | 14 #include "ui/gfx/skia_utils_gtk.h" |
| 15 #include "views/controls/textfield/gtk_views_entry.h" | 15 #include "views/controls/textfield/gtk_views_entry.h" |
| 16 #include "views/controls/textfield/gtk_views_textview.h" | 16 #include "views/controls/textfield/gtk_views_textview.h" |
| 17 #include "views/controls/textfield/native_textfield_views.h" | 17 #include "views/controls/textfield/native_textfield_views.h" |
| 18 #include "views/controls/textfield/text_range.h" |
| 18 #include "views/controls/textfield/textfield.h" | 19 #include "views/controls/textfield/textfield.h" |
| 20 #include "views/controls/textfield/textfield_controller.h" |
| 19 #include "views/widget/widget_gtk.h" | 21 #include "views/widget/widget_gtk.h" |
| 20 | 22 |
| 21 namespace views { | 23 namespace views { |
| 22 | 24 |
| 23 // A character used to hide a text in password mode. | 25 // A character used to hide a text in password mode. |
| 24 static const char kPasswordChar = '*'; | 26 static const char kPasswordChar = '*'; |
| 25 | 27 |
| 26 // Border width for GtkTextView. | 28 // Border width for GtkTextView. |
| 27 const int kTextViewBorderWidth = 4; | 29 const int kTextViewBorderWidth = 4; |
| 28 | 30 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 378 |
| 377 // static | 379 // static |
| 378 gboolean NativeTextfieldGtk::OnKeyPressEventHandler( | 380 gboolean NativeTextfieldGtk::OnKeyPressEventHandler( |
| 379 GtkWidget* widget, | 381 GtkWidget* widget, |
| 380 GdkEventKey* event, | 382 GdkEventKey* event, |
| 381 NativeTextfieldGtk* textfield) { | 383 NativeTextfieldGtk* textfield) { |
| 382 return textfield->OnKeyPressEvent(event); | 384 return textfield->OnKeyPressEvent(event); |
| 383 } | 385 } |
| 384 | 386 |
| 385 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { | 387 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { |
| 386 Textfield::Controller* controller = textfield_->GetController(); | 388 TextfieldController* controller = textfield_->GetController(); |
| 387 if (controller) { | 389 if (controller) { |
| 388 KeyEvent key_event(reinterpret_cast<GdkEvent*>(event)); | 390 KeyEvent key_event(reinterpret_cast<GdkEvent*>(event)); |
| 389 return controller->HandleKeyEvent(textfield_, key_event); | 391 return controller->HandleKeyEvent(textfield_, key_event); |
| 390 } | 392 } |
| 391 return false; | 393 return false; |
| 392 } | 394 } |
| 393 | 395 |
| 394 // static | 396 // static |
| 395 gboolean NativeTextfieldGtk::OnActivateHandler( | 397 gboolean NativeTextfieldGtk::OnActivateHandler( |
| 396 GtkWidget* widget, | 398 GtkWidget* widget, |
| 397 NativeTextfieldGtk* textfield) { | 399 NativeTextfieldGtk* textfield) { |
| 398 return textfield->OnActivate(); | 400 return textfield->OnActivate(); |
| 399 } | 401 } |
| 400 | 402 |
| 401 gboolean NativeTextfieldGtk::OnActivate() { | 403 gboolean NativeTextfieldGtk::OnActivate() { |
| 402 GdkEvent* event = gtk_get_current_event(); | 404 GdkEvent* event = gtk_get_current_event(); |
| 403 if (!event || event->type != GDK_KEY_PRESS) | 405 if (!event || event->type != GDK_KEY_PRESS) |
| 404 return false; | 406 return false; |
| 405 | 407 |
| 406 GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event); | 408 GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event); |
| 407 gboolean handled = false; | 409 gboolean handled = false; |
| 408 | 410 |
| 409 Textfield::Controller* controller = textfield_->GetController(); | 411 TextfieldController* controller = textfield_->GetController(); |
| 410 if (controller) { | 412 if (controller) { |
| 411 KeyEvent views_key_event(event); | 413 KeyEvent views_key_event(event); |
| 412 handled = controller->HandleKeyEvent(textfield_, views_key_event); | 414 handled = controller->HandleKeyEvent(textfield_, views_key_event); |
| 413 } | 415 } |
| 414 | 416 |
| 415 WidgetGtk* widget = static_cast<WidgetGtk*>(GetWidget()); | 417 WidgetGtk* widget = static_cast<WidgetGtk*>(GetWidget()); |
| 416 if (!handled && widget) | 418 if (!handled && widget) |
| 417 handled = widget->HandleKeyboardEvent(key_event); | 419 handled = widget->HandleKeyboardEvent(key_event); |
| 418 | 420 |
| 419 return handled; | 421 return handled; |
| 420 } | 422 } |
| 421 | 423 |
| 422 // static | 424 // static |
| 423 gboolean NativeTextfieldGtk::OnChangedHandler( | 425 gboolean NativeTextfieldGtk::OnChangedHandler( |
| 424 GtkWidget* widget, | 426 GtkWidget* widget, |
| 425 NativeTextfieldGtk* textfield) { | 427 NativeTextfieldGtk* textfield) { |
| 426 return textfield->OnChanged(); | 428 return textfield->OnChanged(); |
| 427 } | 429 } |
| 428 | 430 |
| 429 gboolean NativeTextfieldGtk::OnChanged() { | 431 gboolean NativeTextfieldGtk::OnChanged() { |
| 430 textfield_->SyncText(); | 432 textfield_->SyncText(); |
| 431 Textfield::Controller* controller = textfield_->GetController(); | 433 TextfieldController* controller = textfield_->GetController(); |
| 432 if (controller) | 434 if (controller) |
| 433 controller->ContentsChanged(textfield_, GetText()); | 435 controller->ContentsChanged(textfield_, GetText()); |
| 434 textfield_->NotifyAccessibilityEvent(AccessibilityTypes::EVENT_TEXT_CHANGED); | 436 textfield_->NotifyAccessibilityEvent(AccessibilityTypes::EVENT_TEXT_CHANGED); |
| 435 return false; | 437 return false; |
| 436 } | 438 } |
| 437 | 439 |
| 438 // static | 440 // static |
| 439 gboolean NativeTextfieldGtk::OnMoveCursorHandler( | 441 gboolean NativeTextfieldGtk::OnMoveCursorHandler( |
| 440 GtkWidget* widget, | 442 GtkWidget* widget, |
| 441 GtkMovementStep step, | 443 GtkMovementStep step, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // static | 518 // static |
| 517 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 519 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 518 Textfield* field) { | 520 Textfield* field) { |
| 519 if (NativeTextfieldViews::IsTextfieldViewsEnabled()) { | 521 if (NativeTextfieldViews::IsTextfieldViewsEnabled()) { |
| 520 return new NativeTextfieldViews(field); | 522 return new NativeTextfieldViews(field); |
| 521 } | 523 } |
| 522 return new NativeTextfieldGtk(field); | 524 return new NativeTextfieldGtk(field); |
| 523 } | 525 } |
| 524 | 526 |
| 525 } // namespace views | 527 } // namespace views |
| OLD | NEW |