Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: chrome/browser/gtk/location_bar_view_gtk.cc

Issue 2078021: First pass at experimental omnibox API. There are plenty of rough edges and (Closed)
Patch Set: no prefer_keyword Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/gtk/location_bar_view_gtk.h" 5 #include "chrome/browser/gtk/location_bar_view_gtk.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/gtk_dnd_util.h" 9 #include "app/gtk_dnd_util.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // Colors used to draw the Tab to Search rounded bubble. 87 // Colors used to draw the Tab to Search rounded bubble.
88 const GdkColor kKeywordBackgroundColor = GDK_COLOR_RGB(0xf0, 0xf4, 0xfa); 88 const GdkColor kKeywordBackgroundColor = GDK_COLOR_RGB(0xf0, 0xf4, 0xfa);
89 const GdkColor kKeywordBorderColor = GDK_COLOR_RGB(0xcb, 0xde, 0xf7); 89 const GdkColor kKeywordBorderColor = GDK_COLOR_RGB(0xcb, 0xde, 0xf7);
90 90
91 // Use weak gray for showing search and keyword hint text. 91 // Use weak gray for showing search and keyword hint text.
92 const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75); 92 const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75);
93 93
94 // Size of the rounding of the "Search site for:" box. 94 // Size of the rounding of the "Search site for:" box.
95 const int kCornerSize = 3; 95 const int kCornerSize = 3;
96 96
97 // Returns the short name for a keyword.
98 std::wstring GetKeywordName(Profile* profile,
99 const std::wstring& keyword) {
100 // Make sure the TemplateURL still exists.
101 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel
102 // to track changes to the model, this should become a DCHECK.
103 const TemplateURL* template_url =
104 profile->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword);
105 if (template_url)
106 return template_url->AdjustedShortNameForLocaleDirection();
107 return std::wstring();
108 }
109
110 // If widget is visible, increment the int pointed to by count. 97 // If widget is visible, increment the int pointed to by count.
111 // Suitible for use with gtk_container_foreach. 98 // Suitible for use with gtk_container_foreach.
112 void CountVisibleWidgets(GtkWidget* widget, gpointer count) { 99 void CountVisibleWidgets(GtkWidget* widget, gpointer count) {
113 if (GTK_WIDGET_VISIBLE(widget)) 100 if (GTK_WIDGET_VISIBLE(widget))
114 *static_cast<int*>(count) += 1; 101 *static_cast<int*>(count) += 1;
115 } 102 }
116 103
117 // Build a short string to use in keyword-search when the field isn't 104 // Build a short string to use in keyword-search when the field isn't
118 // very big. 105 // very big.
119 // TODO(suzhe): Copied from views/location_bar_view.cc. Try to share. 106 // TODO(suzhe): Copied from views/location_bar_view.cc. Try to share.
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 } 885 }
899 886
900 void LocationBarViewGtk::SetKeywordLabel(const std::wstring& keyword) { 887 void LocationBarViewGtk::SetKeywordLabel(const std::wstring& keyword) {
901 if (keyword.empty()) 888 if (keyword.empty())
902 return; 889 return;
903 890
904 DCHECK(profile_); 891 DCHECK(profile_);
905 if (!profile_->GetTemplateURLModel()) 892 if (!profile_->GetTemplateURLModel())
906 return; 893 return;
907 894
908 const std::wstring short_name = GetKeywordName(profile_, keyword); 895 bool is_extension_keyword;
909 std::wstring full_name(l10n_util::GetStringF( 896 const std::wstring short_name = profile_->GetTemplateURLModel()->
910 IDS_OMNIBOX_KEYWORD_TEXT, short_name)); 897 GetKeywordShortName(keyword, &is_extension_keyword);
898 int message_id = is_extension_keyword ?
899 IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT;
900 std::wstring full_name(l10n_util::GetStringF(message_id, short_name));
911 std::wstring partial_name(l10n_util::GetStringF( 901 std::wstring partial_name(l10n_util::GetStringF(
912 IDS_OMNIBOX_KEYWORD_TEXT, CalculateMinString(short_name))); 902 message_id, CalculateMinString(short_name)));
913 gtk_label_set_text(GTK_LABEL(tab_to_search_full_label_), 903 gtk_label_set_text(GTK_LABEL(tab_to_search_full_label_),
914 WideToUTF8(full_name).c_str()); 904 WideToUTF8(full_name).c_str());
915 gtk_label_set_text(GTK_LABEL(tab_to_search_partial_label_), 905 gtk_label_set_text(GTK_LABEL(tab_to_search_partial_label_),
916 WideToUTF8(partial_name).c_str()); 906 WideToUTF8(partial_name).c_str());
917 } 907 }
918 908
919 void LocationBarViewGtk::SetKeywordHintLabel(const std::wstring& keyword) { 909 void LocationBarViewGtk::SetKeywordHintLabel(const std::wstring& keyword) {
920 if (keyword.empty()) 910 if (keyword.empty())
921 return; 911 return;
922 912
923 DCHECK(profile_); 913 DCHECK(profile_);
924 if (!profile_->GetTemplateURLModel()) 914 if (!profile_->GetTemplateURLModel())
925 return; 915 return;
926 916
917 bool is_extension_keyword;
918 const std::wstring short_name = profile_->GetTemplateURLModel()->
919 GetKeywordShortName(keyword, &is_extension_keyword);
920 int message_id = is_extension_keyword ?
921 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT;
927 std::vector<size_t> content_param_offsets; 922 std::vector<size_t> content_param_offsets;
928 const std::wstring keyword_hint(l10n_util::GetStringF( 923 const std::wstring keyword_hint(l10n_util::GetStringF(
929 IDS_OMNIBOX_KEYWORD_HINT, std::wstring(), 924 message_id, std::wstring(), short_name, &content_param_offsets));
930 GetKeywordName(profile_, keyword), &content_param_offsets));
931 925
932 if (content_param_offsets.size() != 2) { 926 if (content_param_offsets.size() != 2) {
933 // See comments on an identical NOTREACHED() in search_provider.cc. 927 // See comments on an identical NOTREACHED() in search_provider.cc.
934 NOTREACHED(); 928 NOTREACHED();
935 return; 929 return;
936 } 930 }
937 931
938 std::string leading(WideToUTF8( 932 std::string leading(WideToUTF8(
939 keyword_hint.substr(0, content_param_offsets.front()))); 933 keyword_hint.substr(0, content_param_offsets.front())));
940 std::string trailing(WideToUTF8( 934 std::string trailing(WideToUTF8(
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 1431
1438 std::string badge_text = page_action_->GetBadgeText(tab_id); 1432 std::string badge_text = page_action_->GetBadgeText(tab_id);
1439 if (badge_text.empty()) 1433 if (badge_text.empty())
1440 return FALSE; 1434 return FALSE;
1441 1435
1442 gfx::CanvasPaint canvas(event, false); 1436 gfx::CanvasPaint canvas(event, false);
1443 gfx::Rect bounding_rect(widget->allocation); 1437 gfx::Rect bounding_rect(widget->allocation);
1444 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); 1438 page_action_->PaintBadge(&canvas, bounding_rect, tab_id);
1445 return FALSE; 1439 return FALSE;
1446 } 1440 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/browser/search_engines/template_url.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698