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 "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 | 11 |
12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
13 #include "app/multi_animation.h" | |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
16 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
17 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 18 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
18 #include "chrome/browser/autocomplete/autocomplete_match.h" | 19 #include "chrome/browser/autocomplete/autocomplete_match.h" |
19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 20 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
20 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 21 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/command_updater.h" | 23 #include "chrome/browser/command_updater.h" |
23 #include "chrome/browser/defaults.h" | 24 #include "chrome/browser/defaults.h" |
24 #include "chrome/browser/gtk/gtk_util.h" | 25 #include "chrome/browser/gtk/gtk_util.h" |
25 #include "chrome/browser/gtk/view_id_util.h" | 26 #include "chrome/browser/gtk/view_id_util.h" |
27 #include "chrome/browser/instant/instant_controller.h" | |
26 #include "chrome/browser/platform_util.h" | 28 #include "chrome/browser/platform_util.h" |
27 #include "chrome/browser/tab_contents/tab_contents.h" | 29 #include "chrome/browser/tab_contents/tab_contents.h" |
28 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 30 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
29 #include "chrome/common/notification_service.h" | 31 #include "chrome/common/notification_service.h" |
32 #include "gfx/color_utils.h" | |
30 #include "gfx/font.h" | 33 #include "gfx/font.h" |
31 #include "gfx/gtk_util.h" | 34 #include "gfx/gtk_util.h" |
32 #include "gfx/skia_utils_gtk.h" | 35 #include "gfx/skia_utils_gtk.h" |
33 #include "googleurl/src/gurl.h" | 36 #include "googleurl/src/gurl.h" |
34 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
35 #include "net/base/escape.h" | 38 #include "net/base/escape.h" |
36 #include "third_party/undoview/undo_view.h" | 39 #include "third_party/undoview/undo_view.h" |
37 | 40 |
38 #if defined(TOOLKIT_VIEWS) | 41 #if defined(TOOLKIT_VIEWS) |
39 #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" | 42 #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" |
40 #include "chrome/browser/views/location_bar/location_bar_view.h" | 43 #include "chrome/browser/views/location_bar/location_bar_view.h" |
41 #else | 44 #else |
42 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" | 45 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
43 #include "chrome/browser/gtk/gtk_theme_provider.h" | 46 #include "chrome/browser/gtk/gtk_theme_provider.h" |
44 #include "chrome/browser/gtk/location_bar_view_gtk.h" | 47 #include "chrome/browser/gtk/location_bar_view_gtk.h" |
45 #endif | 48 #endif |
46 | 49 |
47 namespace { | 50 namespace { |
48 | 51 |
49 const gchar* kAutocompleteEditViewGtkKey = "__ACE_VIEW_GTK__"; | 52 const gchar* kAutocompleteEditViewGtkKey = "__ACE_VIEW_GTK__"; |
50 | 53 |
51 const char kTextBaseColor[] = "#808080"; | 54 const char kTextBaseColor[] = "#808080"; |
52 const char kSecureSchemeColor[] = "#079500"; | 55 const char kSecureSchemeColor[] = "#079500"; |
53 const char kSecurityErrorSchemeColor[] = "#a20000"; | 56 const char kSecurityErrorSchemeColor[] = "#a20000"; |
54 | 57 |
55 const double kStrikethroughStrokeRed = 162.0 / 256.0; | 58 const double kStrikethroughStrokeRed = 162.0 / 256.0; |
56 const double kStrikethroughStrokeWidth = 2.0; | 59 const double kStrikethroughStrokeWidth = 2.0; |
57 | 60 |
61 // Amount of time to wait before starting the instant animation. | |
62 const int kPauseTimeMS = 1000; | |
63 // Duration of the instant animation in which the colors change. | |
64 const int kFadeInTimeMS = 300; | |
James Su
2010/12/04 03:43:38
Is it possible or necessary to share these constan
sky
2010/12/06 17:38:12
Maybe move them to browser/defaults?
Evan Stade
2010/12/06 22:15:48
moved to instant_controller. defaults.h doesn't se
| |
65 | |
58 size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) { | 66 size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) { |
59 return WideToUTF8(wide_text.substr(0, wide_text_offset)).size(); | 67 return WideToUTF8(wide_text.substr(0, wide_text_offset)).size(); |
60 } | 68 } |
61 | 69 |
62 // Stores GTK+-specific state so it can be restored after switching tabs. | 70 // Stores GTK+-specific state so it can be restored after switching tabs. |
63 struct ViewState { | 71 struct ViewState { |
64 explicit ViewState(const AutocompleteEditViewGtk::CharRange& selection_range) | 72 explicit ViewState(const AutocompleteEditViewGtk::CharRange& selection_range) |
65 : selection_range(selection_range) { | 73 : selection_range(selection_range) { |
66 } | 74 } |
67 | 75 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 g_signal_connect(text_view_, "redo", G_CALLBACK(&HandleUndoRedoThunk), this); | 338 g_signal_connect(text_view_, "redo", G_CALLBACK(&HandleUndoRedoThunk), this); |
331 g_signal_connect_after(text_view_, "undo", | 339 g_signal_connect_after(text_view_, "undo", |
332 G_CALLBACK(&HandleUndoRedoAfterThunk), this); | 340 G_CALLBACK(&HandleUndoRedoAfterThunk), this); |
333 g_signal_connect_after(text_view_, "redo", | 341 g_signal_connect_after(text_view_, "redo", |
334 G_CALLBACK(&HandleUndoRedoAfterThunk), this); | 342 G_CALLBACK(&HandleUndoRedoAfterThunk), this); |
335 | 343 |
336 // Setup for the Instant suggestion text view. | 344 // Setup for the Instant suggestion text view. |
337 // GtkLabel is used instead of GtkTextView to get transparent background. | 345 // GtkLabel is used instead of GtkTextView to get transparent background. |
338 instant_view_ = gtk_label_new(NULL); | 346 instant_view_ = gtk_label_new(NULL); |
339 gtk_widget_set_no_show_all(instant_view_, TRUE); | 347 gtk_widget_set_no_show_all(instant_view_, TRUE); |
348 gtk_label_set_selectable(GTK_LABEL(instant_view_), TRUE); | |
340 | 349 |
341 GtkTextIter end_iter; | 350 GtkTextIter end_iter; |
342 gtk_text_buffer_get_end_iter(text_buffer_, &end_iter); | 351 gtk_text_buffer_get_end_iter(text_buffer_, &end_iter); |
343 | 352 |
344 // Insert a Zero Width Space character just before the instant anchor. | 353 // Insert a Zero Width Space character just before the instant anchor. |
345 // It's a hack to workaround a bug of GtkTextView which can not align the | 354 // It's a hack to workaround a bug of GtkTextView which can not align the |
346 // preedit string and a child anchor correctly when there is no other content | 355 // preedit string and a child anchor correctly when there is no other content |
347 // around the preedit string. | 356 // around the preedit string. |
348 gtk_text_buffer_insert(text_buffer_, &end_iter, "\342\200\213", -1); | 357 gtk_text_buffer_insert(text_buffer_, &end_iter, "\342\200\213", -1); |
349 GtkTextChildAnchor* instant_anchor = | 358 GtkTextChildAnchor* instant_anchor = |
(...skipping 16 matching lines...) Expand all Loading... | |
366 instant_mark_ = | 375 instant_mark_ = |
367 gtk_text_buffer_create_mark(text_buffer_, NULL, &start_iter, FALSE); | 376 gtk_text_buffer_create_mark(text_buffer_, NULL, &start_iter, FALSE); |
368 | 377 |
369 // Hooking up this handler after setting up above hacks for Instant view, so | 378 // Hooking up this handler after setting up above hacks for Instant view, so |
370 // that we won't filter out the special ZWP mark itself. | 379 // that we won't filter out the special ZWP mark itself. |
371 g_signal_connect(text_buffer_, "insert-text", | 380 g_signal_connect(text_buffer_, "insert-text", |
372 G_CALLBACK(&HandleInsertTextThunk), this); | 381 G_CALLBACK(&HandleInsertTextThunk), this); |
373 | 382 |
374 AdjustVerticalAlignmentOfInstantView(); | 383 AdjustVerticalAlignmentOfInstantView(); |
375 | 384 |
385 MultiAnimation::Parts parts; | |
386 parts.push_back(MultiAnimation::Part(kPauseTimeMS, Tween::ZERO)); | |
387 parts.push_back(MultiAnimation::Part(kFadeInTimeMS, Tween::EASE_IN)); | |
388 instant_animation_.reset(new MultiAnimation(parts)); | |
389 instant_animation_->set_continuous(false); | |
390 | |
376 #if !defined(TOOLKIT_VIEWS) | 391 #if !defined(TOOLKIT_VIEWS) |
377 registrar_.Add(this, | 392 registrar_.Add(this, |
378 NotificationType::BROWSER_THEME_CHANGED, | 393 NotificationType::BROWSER_THEME_CHANGED, |
379 NotificationService::AllSources()); | 394 NotificationService::AllSources()); |
380 theme_provider_->InitThemesFor(this); | 395 theme_provider_->InitThemesFor(this); |
381 #else | 396 #else |
382 // Manually invoke SetBaseColor() because TOOLKIT_VIEWS doesn't observe | 397 // Manually invoke SetBaseColor() because TOOLKIT_VIEWS doesn't observe |
383 // themes. | 398 // themes. |
384 SetBaseColor(); | 399 SetBaseColor(); |
385 #endif | 400 #endif |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 } | 749 } |
735 | 750 |
736 void AutocompleteEditViewGtk::Observe(NotificationType type, | 751 void AutocompleteEditViewGtk::Observe(NotificationType type, |
737 const NotificationSource& source, | 752 const NotificationSource& source, |
738 const NotificationDetails& details) { | 753 const NotificationDetails& details) { |
739 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED); | 754 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED); |
740 | 755 |
741 SetBaseColor(); | 756 SetBaseColor(); |
742 } | 757 } |
743 | 758 |
759 void AutocompleteEditViewGtk::AnimationEnded(const Animation* animation) { | |
760 controller_->OnCommitSuggestedText(GetText()); | |
761 } | |
762 | |
763 void AutocompleteEditViewGtk::AnimationProgressed(const Animation* animation) { | |
764 UpdateInstantViewColors(); | |
765 } | |
766 | |
767 void AutocompleteEditViewGtk::AnimationCanceled(const Animation* animation) { | |
768 UpdateInstantViewColors(); | |
769 } | |
770 | |
744 void AutocompleteEditViewGtk::SetBaseColor() { | 771 void AutocompleteEditViewGtk::SetBaseColor() { |
745 #if defined(TOOLKIT_VIEWS) | 772 #if defined(TOOLKIT_VIEWS) |
746 bool use_gtk = false; | 773 bool use_gtk = false; |
747 #else | 774 #else |
748 bool use_gtk = theme_provider_->UseGtkTheme(); | 775 bool use_gtk = theme_provider_->UseGtkTheme(); |
749 #endif | 776 #endif |
750 | 777 |
751 if (use_gtk) { | 778 if (use_gtk) { |
752 gtk_widget_modify_cursor(text_view_, NULL, NULL); | 779 gtk_widget_modify_cursor(text_view_, NULL, NULL); |
753 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, NULL); | 780 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, NULL); |
754 gtk_widget_modify_base(text_view_, GTK_STATE_SELECTED, NULL); | 781 gtk_widget_modify_base(text_view_, GTK_STATE_SELECTED, NULL); |
755 gtk_widget_modify_text(text_view_, GTK_STATE_SELECTED, NULL); | 782 gtk_widget_modify_text(text_view_, GTK_STATE_SELECTED, NULL); |
756 gtk_widget_modify_base(text_view_, GTK_STATE_ACTIVE, NULL); | 783 gtk_widget_modify_base(text_view_, GTK_STATE_ACTIVE, NULL); |
757 gtk_widget_modify_text(text_view_, GTK_STATE_ACTIVE, NULL); | 784 gtk_widget_modify_text(text_view_, GTK_STATE_ACTIVE, NULL); |
758 | 785 |
759 gtk_util::UndoForceFontSize(text_view_); | 786 gtk_util::UndoForceFontSize(text_view_); |
760 gtk_util::UndoForceFontSize(instant_view_); | 787 gtk_util::UndoForceFontSize(instant_view_); |
761 | 788 |
762 // Grab the text colors out of the style and set our tags to use them. | 789 // Grab the text colors out of the style and set our tags to use them. |
763 GtkStyle* style = gtk_rc_get_style(text_view_); | 790 GtkStyle* style = gtk_rc_get_style(text_view_); |
764 | 791 |
765 // style may be unrealized at this point, so calculate the halfway point | 792 // style may be unrealized at this point, so calculate the halfway point |
766 // between text[] and base[] manually instead of just using text_aa[]. | 793 // between text[] and base[] manually instead of just using text_aa[]. |
767 GdkColor average_color = gtk_util::AverageColors( | 794 GdkColor average_color = gtk_util::AverageColors( |
768 style->text[GTK_STATE_NORMAL], style->base[GTK_STATE_NORMAL]); | 795 style->text[GTK_STATE_NORMAL], style->base[GTK_STATE_NORMAL]); |
769 | 796 |
770 g_object_set(faded_text_tag_, "foreground-gdk", &average_color, NULL); | 797 g_object_set(faded_text_tag_, "foreground-gdk", &average_color, NULL); |
771 g_object_set(normal_text_tag_, "foreground-gdk", | 798 g_object_set(normal_text_tag_, "foreground-gdk", |
772 &style->text[GTK_STATE_NORMAL], NULL); | 799 &style->text[GTK_STATE_NORMAL], NULL); |
773 | |
774 // GtkLabel uses fg color instead of text color. | |
775 gtk_widget_modify_fg(instant_view_, GTK_STATE_NORMAL, &average_color); | |
776 } else { | 800 } else { |
777 const GdkColor* background_color_ptr; | 801 const GdkColor* background_color_ptr; |
778 #if defined(TOOLKIT_VIEWS) | 802 #if defined(TOOLKIT_VIEWS) |
779 const GdkColor background_color = gfx::SkColorToGdkColor( | 803 const GdkColor background_color = gfx::SkColorToGdkColor( |
780 LocationBarView::GetColor(ToolbarModel::NONE, | 804 LocationBarView::GetColor(ToolbarModel::NONE, |
781 LocationBarView::BACKGROUND)); | 805 LocationBarView::BACKGROUND)); |
782 background_color_ptr = &background_color; | 806 background_color_ptr = &background_color; |
783 #else | 807 #else |
784 background_color_ptr = &LocationBarViewGtk::kBackgroundColor; | 808 background_color_ptr = &LocationBarViewGtk::kBackgroundColor; |
785 #endif | 809 #endif |
786 gtk_widget_modify_cursor( | 810 gtk_widget_modify_cursor( |
787 text_view_, >k_util::kGdkBlack, >k_util::kGdkGray); | 811 text_view_, >k_util::kGdkBlack, >k_util::kGdkGray); |
788 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, background_color_ptr); | 812 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, background_color_ptr); |
789 | 813 |
790 GdkColor c; | 814 GdkColor c; |
James Su
2010/12/04 03:43:38
It's not used in views port.
Evan Stade
2010/12/06 22:15:48
Done.
| |
791 #if !defined(TOOLKIT_VIEWS) | 815 #if !defined(TOOLKIT_VIEWS) |
792 // Override the selected colors so we don't leak colors from the current | 816 // Override the selected colors so we don't leak colors from the current |
793 // gtk theme into the chrome-theme. | 817 // gtk theme into the chrome-theme. |
794 c = gfx::SkColorToGdkColor( | 818 c = gfx::SkColorToGdkColor( |
795 theme_provider_->get_active_selection_bg_color()); | 819 theme_provider_->get_active_selection_bg_color()); |
796 gtk_widget_modify_base(text_view_, GTK_STATE_SELECTED, &c); | 820 gtk_widget_modify_base(text_view_, GTK_STATE_SELECTED, &c); |
797 | 821 |
798 c = gfx::SkColorToGdkColor( | 822 c = gfx::SkColorToGdkColor( |
799 theme_provider_->get_active_selection_fg_color()); | 823 theme_provider_->get_active_selection_fg_color()); |
800 gtk_widget_modify_text(text_view_, GTK_STATE_SELECTED, &c); | 824 gtk_widget_modify_text(text_view_, GTK_STATE_SELECTED, &c); |
801 | 825 |
802 c = gfx::SkColorToGdkColor( | 826 c = gfx::SkColorToGdkColor( |
803 theme_provider_->get_inactive_selection_bg_color()); | 827 theme_provider_->get_inactive_selection_bg_color()); |
804 gtk_widget_modify_base(text_view_, GTK_STATE_ACTIVE, &c); | 828 gtk_widget_modify_base(text_view_, GTK_STATE_ACTIVE, &c); |
805 | 829 |
806 c = gfx::SkColorToGdkColor( | 830 c = gfx::SkColorToGdkColor( |
807 theme_provider_->get_inactive_selection_fg_color()); | 831 theme_provider_->get_inactive_selection_fg_color()); |
808 gtk_widget_modify_text(text_view_, GTK_STATE_ACTIVE, &c); | 832 gtk_widget_modify_text(text_view_, GTK_STATE_ACTIVE, &c); |
809 #endif | 833 #endif |
810 | 834 |
811 gdk_color_parse(kTextBaseColor, &c); | |
812 gtk_widget_modify_fg(instant_view_, GTK_STATE_NORMAL, &c); | |
813 | |
814 // Until we switch to vector graphics, force the font size. | 835 // Until we switch to vector graphics, force the font size. |
815 gtk_util::ForceFontSizePixels(text_view_, | 836 gtk_util::ForceFontSizePixels(text_view_, |
816 popup_window_mode_ ? | 837 popup_window_mode_ ? |
817 browser_defaults::kAutocompleteEditFontPixelSizeInPopup : | 838 browser_defaults::kAutocompleteEditFontPixelSizeInPopup : |
818 browser_defaults::kAutocompleteEditFontPixelSize); | 839 browser_defaults::kAutocompleteEditFontPixelSize); |
819 | 840 |
820 gtk_util::ForceFontSizePixels(instant_view_, | 841 gtk_util::ForceFontSizePixels(instant_view_, |
821 popup_window_mode_ ? | 842 popup_window_mode_ ? |
822 browser_defaults::kAutocompleteEditFontPixelSizeInPopup : | 843 browser_defaults::kAutocompleteEditFontPixelSizeInPopup : |
823 browser_defaults::kAutocompleteEditFontPixelSize); | 844 browser_defaults::kAutocompleteEditFontPixelSize); |
824 | 845 |
825 g_object_set(faded_text_tag_, "foreground", kTextBaseColor, NULL); | 846 g_object_set(faded_text_tag_, "foreground", kTextBaseColor, NULL); |
826 g_object_set(normal_text_tag_, "foreground", "#000000", NULL); | 847 g_object_set(normal_text_tag_, "foreground", "#000000", NULL); |
827 } | 848 } |
828 | 849 |
829 AdjustVerticalAlignmentOfInstantView(); | 850 AdjustVerticalAlignmentOfInstantView(); |
851 UpdateInstantViewColors(); | |
852 } | |
853 | |
854 void AutocompleteEditViewGtk::UpdateInstantViewColors() { | |
James Su
2010/12/04 03:43:38
Please fix compilation failure for views port.
Evan Stade
2010/12/06 22:15:48
Done.
| |
855 SkColor selection_text, selection_bg; | |
856 GdkColor faded_text, normal_bg; | |
857 | |
858 // We don't worry about views because it doesn't use the instant view. | |
859 if (theme_provider_->UseGtkTheme()) { | |
860 GtkStyle* style = gtk_rc_get_style(text_view_); | |
861 | |
862 faded_text = gtk_util::AverageColors( | |
863 style->text[GTK_STATE_NORMAL], style->base[GTK_STATE_NORMAL]); | |
864 normal_bg = style->base[GTK_STATE_NORMAL]; | |
865 | |
866 selection_text = gfx::GdkColorToSkColor(style->text[GTK_STATE_SELECTED]); | |
867 selection_bg = gfx::GdkColorToSkColor(style->base[GTK_STATE_SELECTED]); | |
868 } else { | |
869 gdk_color_parse(kTextBaseColor, &faded_text); | |
870 normal_bg = LocationBarViewGtk::kBackgroundColor; | |
871 | |
872 selection_text = | |
873 theme_provider_->get_active_selection_fg_color(); | |
874 selection_bg = | |
875 theme_provider_->get_active_selection_bg_color(); | |
876 } | |
877 | |
878 double alpha = instant_animation_->GetCurrentValue(); | |
879 GdkColor text = gfx::SkColorToGdkColor(color_utils::AlphaBlend( | |
880 selection_text, | |
881 gfx::GdkColorToSkColor(faded_text), | |
882 alpha * 0xff)); | |
883 GdkColor bg = gfx::SkColorToGdkColor(color_utils::AlphaBlend( | |
884 selection_bg, | |
885 gfx::GdkColorToSkColor(normal_bg), | |
886 alpha * 0xff)); | |
887 | |
888 // ACTIVE is the state for text that is selected, but not focused (the | |
889 // instant view is always fully selected and never has focus). | |
890 gtk_widget_modify_text(instant_view_, GTK_STATE_ACTIVE, &text); | |
891 gtk_widget_modify_base(instant_view_, GTK_STATE_ACTIVE, &bg); | |
830 } | 892 } |
831 | 893 |
832 void AutocompleteEditViewGtk::HandleBeginUserAction(GtkTextBuffer* sender) { | 894 void AutocompleteEditViewGtk::HandleBeginUserAction(GtkTextBuffer* sender) { |
833 OnBeforePossibleChange(); | 895 OnBeforePossibleChange(); |
834 } | 896 } |
835 | 897 |
836 void AutocompleteEditViewGtk::HandleEndUserAction(GtkTextBuffer* sender) { | 898 void AutocompleteEditViewGtk::HandleEndUserAction(GtkTextBuffer* sender) { |
837 OnAfterPossibleChange(); | 899 OnAfterPossibleChange(); |
838 } | 900 } |
839 | 901 |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1691 gtk_text_buffer_apply_tag(text_buffer_, faded_text_tag_, &start, &end); | 1753 gtk_text_buffer_apply_tag(text_buffer_, faded_text_tag_, &start, &end); |
1692 } else { | 1754 } else { |
1693 gtk_text_buffer_apply_tag(text_buffer_, secure_scheme_tag_, &start, &end); | 1755 gtk_text_buffer_apply_tag(text_buffer_, secure_scheme_tag_, &start, &end); |
1694 } | 1756 } |
1695 } | 1757 } |
1696 } | 1758 } |
1697 | 1759 |
1698 void AutocompleteEditViewGtk::SetInstantSuggestion( | 1760 void AutocompleteEditViewGtk::SetInstantSuggestion( |
1699 const std::string& suggestion) { | 1761 const std::string& suggestion) { |
1700 gtk_label_set_text(GTK_LABEL(instant_view_), suggestion.c_str()); | 1762 gtk_label_set_text(GTK_LABEL(instant_view_), suggestion.c_str()); |
1763 // Select the whole thing. | |
1764 gtk_label_select_region(GTK_LABEL(instant_view_), 0, -1); | |
1765 | |
1766 // Clear the animation delegate so we don't get an AnimationEnded() callback. | |
1767 instant_animation_->set_delegate(NULL); | |
1768 instant_animation_->Reset(); | |
1769 | |
1701 if (suggestion.empty()) { | 1770 if (suggestion.empty()) { |
1702 gtk_widget_hide(instant_view_); | 1771 gtk_widget_hide(instant_view_); |
1703 } else { | 1772 } else { |
1773 if (InstantController::IsEnabled(model_->profile(), | |
1774 InstantController::PREDICTIVE_TYPE)) { | |
1775 instant_animation_->set_delegate(this); | |
1776 instant_animation_->Start(); | |
1777 } | |
1778 | |
1704 gtk_widget_show(instant_view_); | 1779 gtk_widget_show(instant_view_); |
1705 AdjustVerticalAlignmentOfInstantView(); | 1780 AdjustVerticalAlignmentOfInstantView(); |
1781 UpdateInstantViewColors(); | |
1706 } | 1782 } |
1707 } | 1783 } |
1708 | 1784 |
1709 bool AutocompleteEditViewGtk::CommitInstantSuggestion() { | 1785 bool AutocompleteEditViewGtk::CommitInstantSuggestion() { |
1710 const gchar* suggestion = gtk_label_get_text(GTK_LABEL(instant_view_)); | 1786 const gchar* suggestion = gtk_label_get_text(GTK_LABEL(instant_view_)); |
1711 if (!suggestion || !*suggestion) | 1787 if (!suggestion || !*suggestion) |
1712 return false; | 1788 return false; |
1713 | 1789 |
1714 model()->FinalizeInstantQuery(GetText() + UTF8ToWide(suggestion)); | 1790 model()->FinalizeInstantQuery(GetText() + UTF8ToWide(suggestion)); |
1715 return true; | 1791 return true; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1976 // baseline, so we need to move the |instant_view_| down to make sure it | 2052 // baseline, so we need to move the |instant_view_| down to make sure it |
1977 // has the same baseline as the |text_view_|. | 2053 // has the same baseline as the |text_view_|. |
1978 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); | 2054 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); |
1979 int height; | 2055 int height; |
1980 pango_layout_get_size(layout, NULL, &height); | 2056 pango_layout_get_size(layout, NULL, &height); |
1981 PangoLayoutIter* iter = pango_layout_get_iter(layout); | 2057 PangoLayoutIter* iter = pango_layout_get_iter(layout); |
1982 int baseline = pango_layout_iter_get_baseline(iter); | 2058 int baseline = pango_layout_iter_get_baseline(iter); |
1983 pango_layout_iter_free(iter); | 2059 pango_layout_iter_free(iter); |
1984 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); | 2060 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); |
1985 } | 2061 } |
OLD | NEW |