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> |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "gfx/color_utils.h" | 31 #include "gfx/color_utils.h" |
32 #include "gfx/font.h" | 32 #include "gfx/font.h" |
33 #include "gfx/gtk_util.h" | 33 #include "gfx/gtk_util.h" |
34 #include "gfx/skia_utils_gtk.h" | 34 #include "gfx/skia_utils_gtk.h" |
35 #include "googleurl/src/gurl.h" | 35 #include "googleurl/src/gurl.h" |
36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
37 #include "net/base/escape.h" | 37 #include "net/base/escape.h" |
38 #include "third_party/undoview/undo_view.h" | 38 #include "third_party/undoview/undo_view.h" |
39 | 39 |
40 #if defined(TOOLKIT_VIEWS) | 40 #if defined(TOOLKIT_VIEWS) |
41 #include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" | 41 #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" |
42 #include "chrome/browser/views/location_bar/location_bar_view.h" | 42 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h" |
43 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | |
43 #else | 44 #else |
44 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" | 45 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
45 #include "chrome/browser/gtk/gtk_theme_provider.h" | 46 #include "chrome/browser/gtk/gtk_theme_provider.h" |
46 #include "chrome/browser/gtk/location_bar_view_gtk.h" | 47 #include "chrome/browser/gtk/location_bar_view_gtk.h" |
48 #include "views/controls/native/native_view_host.h" | |
47 #endif | 49 #endif |
48 | 50 |
49 namespace { | 51 namespace { |
50 | 52 |
51 const gchar* kAutocompleteEditViewGtkKey = "__ACE_VIEW_GTK__"; | 53 const gchar* kAutocompleteEditViewGtkKey = "__ACE_VIEW_GTK__"; |
52 | 54 |
53 const char kTextBaseColor[] = "#808080"; | 55 const char kTextBaseColor[] = "#808080"; |
54 const char kSecureSchemeColor[] = "#079500"; | 56 const char kSecureSchemeColor[] = "#079500"; |
55 const char kSecurityErrorSchemeColor[] = "#a20000"; | 57 const char kSecurityErrorSchemeColor[] = "#a20000"; |
56 | 58 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 | 413 |
412 // Use |signals_| to make sure we don't get called back after destruction. | 414 // Use |signals_| to make sure we don't get called back after destruction. |
413 signals_.Connect(new_toplevel, "set-focus", | 415 signals_.Connect(new_toplevel, "set-focus", |
414 G_CALLBACK(&HandleWindowSetFocusThunk), this); | 416 G_CALLBACK(&HandleWindowSetFocusThunk), this); |
415 } | 417 } |
416 | 418 |
417 void AutocompleteEditViewGtk::SetFocus() { | 419 void AutocompleteEditViewGtk::SetFocus() { |
418 gtk_widget_grab_focus(text_view_); | 420 gtk_widget_grab_focus(text_view_); |
419 } | 421 } |
420 | 422 |
421 int AutocompleteEditViewGtk::TextWidth() { | |
422 int horizontal_border_size = | |
423 gtk_text_view_get_border_window_size(GTK_TEXT_VIEW(text_view_), | |
424 GTK_TEXT_WINDOW_LEFT) + | |
425 gtk_text_view_get_border_window_size(GTK_TEXT_VIEW(text_view_), | |
426 GTK_TEXT_WINDOW_RIGHT) + | |
427 gtk_text_view_get_left_margin(GTK_TEXT_VIEW(text_view_)) + | |
428 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(text_view_)); | |
429 | |
430 GtkTextIter start, end; | |
431 GdkRectangle first_char_bounds, last_char_bounds; | |
432 gtk_text_buffer_get_start_iter(text_buffer_, &start); | |
433 | |
434 // Use the real end iterator here to take the width of instant suggestion | |
435 // text into account, so that location bar can layout its children correctly. | |
436 gtk_text_buffer_get_end_iter(text_buffer_, &end); | |
437 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(text_view_), | |
438 &start, &first_char_bounds); | |
439 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(text_view_), | |
440 &end, &last_char_bounds); | |
441 | |
442 gint first_char_start = first_char_bounds.x; | |
443 gint first_char_end = first_char_start + first_char_bounds.width; | |
444 gint last_char_start = last_char_bounds.x; | |
445 gint last_char_end = last_char_start + last_char_bounds.width; | |
446 | |
447 // bounds width could be negative for RTL text. | |
448 if (first_char_start > first_char_end) | |
449 std::swap(first_char_start, first_char_end); | |
450 if (last_char_start > last_char_end) | |
451 std::swap(last_char_start, last_char_end); | |
452 | |
453 gint text_width = first_char_start < last_char_start ? | |
454 last_char_end - first_char_start : first_char_end - last_char_start; | |
455 | |
456 return text_width + horizontal_border_size; | |
457 } | |
458 | |
459 int AutocompleteEditViewGtk::WidthOfTextAfterCursor() { | 423 int AutocompleteEditViewGtk::WidthOfTextAfterCursor() { |
460 // Not used. | 424 // Not used. |
461 return -1; | 425 return -1; |
462 } | 426 } |
463 | 427 |
464 gfx::Font AutocompleteEditViewGtk::GetFont() { | 428 gfx::Font AutocompleteEditViewGtk::GetFont() { |
465 GtkRcStyle* rc_style = gtk_widget_get_modifier_style(text_view_); | 429 GtkRcStyle* rc_style = gtk_widget_get_modifier_style(text_view_); |
466 return gfx::Font((rc_style && rc_style->font_desc) ? | 430 return gfx::Font((rc_style && rc_style->font_desc) ? |
467 rc_style->font_desc : text_view_->style->font_desc); | 431 rc_style->font_desc : text_view_->style->font_desc); |
468 } | 432 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
783 } | 747 } |
784 | 748 |
785 gfx::NativeView AutocompleteEditViewGtk::GetNativeView() const { | 749 gfx::NativeView AutocompleteEditViewGtk::GetNativeView() const { |
786 return alignment_.get(); | 750 return alignment_.get(); |
787 } | 751 } |
788 | 752 |
789 CommandUpdater* AutocompleteEditViewGtk::GetCommandUpdater() { | 753 CommandUpdater* AutocompleteEditViewGtk::GetCommandUpdater() { |
790 return command_updater_; | 754 return command_updater_; |
791 } | 755 } |
792 | 756 |
757 int AutocompleteEditViewGtk::TextWidth() const { | |
758 int horizontal_border_size = | |
759 gtk_text_view_get_border_window_size(GTK_TEXT_VIEW(text_view_), | |
760 GTK_TEXT_WINDOW_LEFT) + | |
761 gtk_text_view_get_border_window_size(GTK_TEXT_VIEW(text_view_), | |
762 GTK_TEXT_WINDOW_RIGHT) + | |
763 gtk_text_view_get_left_margin(GTK_TEXT_VIEW(text_view_)) + | |
764 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(text_view_)); | |
765 | |
766 GtkTextIter start, end; | |
767 GdkRectangle first_char_bounds, last_char_bounds; | |
768 gtk_text_buffer_get_start_iter(text_buffer_, &start); | |
769 | |
770 // Use the real end iterator here to take the width of instant suggestion | |
771 // text into account, so that location bar can layout its children correctly. | |
772 gtk_text_buffer_get_end_iter(text_buffer_, &end); | |
773 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(text_view_), | |
774 &start, &first_char_bounds); | |
775 gtk_text_view_get_iter_location(GTK_TEXT_VIEW(text_view_), | |
776 &end, &last_char_bounds); | |
777 | |
778 gint first_char_start = first_char_bounds.x; | |
779 gint first_char_end = first_char_start + first_char_bounds.width; | |
780 gint last_char_start = last_char_bounds.x; | |
781 gint last_char_end = last_char_start + last_char_bounds.width; | |
782 | |
783 // bounds width could be negative for RTL text. | |
784 if (first_char_start > first_char_end) | |
785 std::swap(first_char_start, first_char_end); | |
786 if (last_char_start > last_char_end) | |
787 std::swap(last_char_start, last_char_end); | |
788 | |
789 gint text_width = first_char_start < last_char_start ? | |
790 last_char_end - first_char_start : first_char_end - last_char_start; | |
791 | |
792 return text_width + horizontal_border_size; | |
793 } | |
794 | |
795 #if defined(TOOLKIT_VIEWS) | |
796 views::View* AutocompleteEditViewGtk::AddToView(views::View* parent) { | |
Peter Kasting
2011/01/06 02:06:48
Nit: This function is the same in Windows and Gtk.
oshima
2011/01/06 19:43:35
Views implementation will be different (there will
Peter Kasting
2011/01/06 20:51:38
I'm fine with whatever route you want to do as lon
| |
797 views::NativeViewHost* host = new views::NativeViewHost; | |
798 parent->AddChildView(host); | |
799 host->set_focus_view(parent); | |
800 host->Attach(GetNativeView()); | |
801 return host; | |
802 } | |
803 | |
804 bool AutocompleteEditViewGtk::CommitInstantSuggestion( | |
805 const std::wstring& typed_text, | |
806 const std::wstring& suggestion) { | |
807 return CommitInstantSuggestion(); | |
Peter Kasting
2011/01/06 02:06:48
Nit: Can't the body of that function be rolled int
oshima
2011/01/06 19:43:35
CommitInstantSuggestoni() is used by gtk version.
Peter Kasting
2011/01/06 20:51:38
OK, but since this ignores its args anyway, couldn
oshima
2011/01/06 21:39:26
Let me refactor further before making this change.
| |
808 } | |
809 | |
810 void AutocompleteEditViewGtk::CreateAccessibleWidgetHelper(int res) { | |
811 accessible_widget_helper_.reset( | |
812 new AccessibleWidgetHelper(text_view(), model_->profile())); | |
813 accessible_widget_helper_->SetWidgetName( | |
814 text_view(), l10n_util::GetStringUTF8(res)); | |
815 } | |
816 | |
817 void AutocompleteEditViewGtk::SetInstantSuggestion(const string16& suggestion) { | |
818 SetInstantSuggestion(UTF16ToUTF8(suggestion)); | |
819 } | |
820 | |
821 // static | |
822 AutocompleteEditView* AutocompleteEditViewGtk::Create( | |
823 AutocompleteEditController* controller, | |
824 ToolbarModel* toolbar_model, | |
825 Profile* profile, | |
826 CommandUpdater* command_updater, | |
827 bool popup_window_mode, | |
828 const views::View* location_bar) { | |
829 AutocompleteEditViewGtk* autocomplete = | |
830 new AutocompleteEditViewGtk(controller, | |
831 toolbar_model, | |
832 profile, | |
833 command_updater, | |
834 popup_window_mode, | |
835 location_bar); | |
836 autocomplete->Init(); | |
837 | |
838 // Make all the children of the widget visible. NOTE: this won't display | |
839 // anything, it just toggles the visible flag. | |
840 gtk_widget_show_all(autocomplete->GetNativeView()); | |
841 // Hide the widget. NativeViewHostGtk will make it visible again as | |
842 // necessary. | |
843 gtk_widget_hide(autocomplete->GetNativeView()); | |
844 | |
845 autocomplete->CreateAccessibleWidgetHelper(IDS_ACCNAME_LOCATION); | |
dmazzoni
2011/01/06 15:03:03
Why should this be a separate step? Could it be do
oshima
2011/01/06 19:43:35
Above functions are not called in gtk impl. I can
| |
846 | |
847 return autocomplete; | |
848 } | |
849 #endif | |
850 | |
851 | |
793 void AutocompleteEditViewGtk::Observe(NotificationType type, | 852 void AutocompleteEditViewGtk::Observe(NotificationType type, |
794 const NotificationSource& source, | 853 const NotificationSource& source, |
795 const NotificationDetails& details) { | 854 const NotificationDetails& details) { |
796 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED); | 855 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED); |
797 | 856 |
798 SetBaseColor(); | 857 SetBaseColor(); |
799 } | 858 } |
800 | 859 |
801 void AutocompleteEditViewGtk::AnimationEnded(const Animation* animation) { | 860 void AutocompleteEditViewGtk::AnimationEnded(const Animation* animation) { |
802 controller_->OnCommitSuggestedText(GetText()); | 861 controller_->OnCommitSuggestedText(GetText()); |
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2149 // baseline, so we need to move the |instant_view_| down to make sure it | 2208 // baseline, so we need to move the |instant_view_| down to make sure it |
2150 // has the same baseline as the |text_view_|. | 2209 // has the same baseline as the |text_view_|. |
2151 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); | 2210 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); |
2152 int height; | 2211 int height; |
2153 pango_layout_get_size(layout, NULL, &height); | 2212 pango_layout_get_size(layout, NULL, &height); |
2154 PangoLayoutIter* iter = pango_layout_get_iter(layout); | 2213 PangoLayoutIter* iter = pango_layout_get_iter(layout); |
2155 int baseline = pango_layout_iter_get_baseline(iter); | 2214 int baseline = pango_layout_iter_get_baseline(iter); |
2156 pango_layout_iter_free(iter); | 2215 pango_layout_iter_free(iter); |
2157 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); | 2216 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); |
2158 } | 2217 } |
OLD | NEW |