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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 374 |
373 // static | 375 // static |
374 gboolean NativeTextfieldGtk::OnKeyPressEventHandler( | 376 gboolean NativeTextfieldGtk::OnKeyPressEventHandler( |
375 GtkWidget* widget, | 377 GtkWidget* widget, |
376 GdkEventKey* event, | 378 GdkEventKey* event, |
377 NativeTextfieldGtk* textfield) { | 379 NativeTextfieldGtk* textfield) { |
378 return textfield->OnKeyPressEvent(event); | 380 return textfield->OnKeyPressEvent(event); |
379 } | 381 } |
380 | 382 |
381 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { | 383 gboolean NativeTextfieldGtk::OnKeyPressEvent(GdkEventKey* event) { |
382 Textfield::Controller* controller = textfield_->GetController(); | 384 TextfieldController* controller = textfield_->GetController(); |
383 if (controller) { | 385 if (controller) { |
384 KeyEvent key_event(reinterpret_cast<GdkEvent*>(event)); | 386 KeyEvent key_event(reinterpret_cast<GdkEvent*>(event)); |
385 return controller->HandleKeyEvent(textfield_, key_event); | 387 return controller->HandleKeyEvent(textfield_, key_event); |
386 } | 388 } |
387 return false; | 389 return false; |
388 } | 390 } |
389 | 391 |
390 // static | 392 // static |
391 gboolean NativeTextfieldGtk::OnActivateHandler( | 393 gboolean NativeTextfieldGtk::OnActivateHandler( |
392 GtkWidget* widget, | 394 GtkWidget* widget, |
393 NativeTextfieldGtk* textfield) { | 395 NativeTextfieldGtk* textfield) { |
394 return textfield->OnActivate(); | 396 return textfield->OnActivate(); |
395 } | 397 } |
396 | 398 |
397 gboolean NativeTextfieldGtk::OnActivate() { | 399 gboolean NativeTextfieldGtk::OnActivate() { |
398 GdkEvent* event = gtk_get_current_event(); | 400 GdkEvent* event = gtk_get_current_event(); |
399 if (!event || event->type != GDK_KEY_PRESS) | 401 if (!event || event->type != GDK_KEY_PRESS) |
400 return false; | 402 return false; |
401 | 403 |
402 GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event); | 404 GdkEventKey* key_event = reinterpret_cast<GdkEventKey*>(event); |
403 gboolean handled = false; | 405 gboolean handled = false; |
404 | 406 |
405 Textfield::Controller* controller = textfield_->GetController(); | 407 TextfieldController* controller = textfield_->GetController(); |
406 if (controller) { | 408 if (controller) { |
407 KeyEvent views_key_event(event); | 409 KeyEvent views_key_event(event); |
408 handled = controller->HandleKeyEvent(textfield_, views_key_event); | 410 handled = controller->HandleKeyEvent(textfield_, views_key_event); |
409 } | 411 } |
410 | 412 |
411 WidgetGtk* widget = static_cast<WidgetGtk*>(GetWidget()); | 413 WidgetGtk* widget = static_cast<WidgetGtk*>(GetWidget()); |
412 if (!handled && widget) | 414 if (!handled && widget) |
413 handled = widget->HandleKeyboardEvent(key_event); | 415 handled = widget->HandleKeyboardEvent(key_event); |
414 | 416 |
415 return handled; | 417 return handled; |
416 } | 418 } |
417 | 419 |
418 // static | 420 // static |
419 gboolean NativeTextfieldGtk::OnChangedHandler( | 421 gboolean NativeTextfieldGtk::OnChangedHandler( |
420 GtkWidget* widget, | 422 GtkWidget* widget, |
421 NativeTextfieldGtk* textfield) { | 423 NativeTextfieldGtk* textfield) { |
422 return textfield->OnChanged(); | 424 return textfield->OnChanged(); |
423 } | 425 } |
424 | 426 |
425 gboolean NativeTextfieldGtk::OnChanged() { | 427 gboolean NativeTextfieldGtk::OnChanged() { |
426 textfield_->SyncText(); | 428 textfield_->SyncText(); |
427 Textfield::Controller* controller = textfield_->GetController(); | 429 TextfieldController* controller = textfield_->GetController(); |
428 if (controller) | 430 if (controller) |
429 controller->ContentsChanged(textfield_, GetText()); | 431 controller->ContentsChanged(textfield_, GetText()); |
430 return false; | 432 return false; |
431 } | 433 } |
432 | 434 |
433 //////////////////////////////////////////////////////////////////////////////// | 435 //////////////////////////////////////////////////////////////////////////////// |
434 // NativeTextfieldGtk, NativeControlGtk overrides: | 436 // NativeTextfieldGtk, NativeControlGtk overrides: |
435 | 437 |
436 void NativeTextfieldGtk::CreateNativeControl() { | 438 void NativeTextfieldGtk::CreateNativeControl() { |
437 if (textfield_->IsMultiLine()) { | 439 if (textfield_->IsMultiLine()) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 // static | 481 // static |
480 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 482 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
481 Textfield* field) { | 483 Textfield* field) { |
482 if (NativeTextfieldViews::IsTextfieldViewsEnabled()) { | 484 if (NativeTextfieldViews::IsTextfieldViewsEnabled()) { |
483 return new NativeTextfieldViews(field); | 485 return new NativeTextfieldViews(field); |
484 } | 486 } |
485 return new NativeTextfieldGtk(field); | 487 return new NativeTextfieldGtk(field); |
486 } | 488 } |
487 | 489 |
488 } // namespace views | 490 } // namespace views |
OLD | NEW |