summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-30 02:20:07 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-30 02:20:07 +0000
commit87609f15399bd5c26b4a0aa07b1cba0287f597e4 (patch)
tree50137fddddf2d47b8a6bc1c274f2c7315083c4dc /chrome
parent1a0a19a59b7b57c166a49aa93dfda3568660d14d (diff)
downloadchromium_src-87609f15399bd5c26b4a0aa07b1cba0287f597e4.zip
chromium_src-87609f15399bd5c26b4a0aa07b1cba0287f597e4.tar.gz
chromium_src-87609f15399bd5c26b4a0aa07b1cba0287f597e4.tar.bz2
Share common location bar functions across the 3 platforms that uses them.
BUG=None TEST=compiles, and everything should works as before. Review URL: http://codereview.chromium.org/2125020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48568 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.mm37
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc23
-rw-r--r--chrome/browser/location_bar_util.cc42
-rw-r--r--chrome/browser/location_bar_util.h23
-rw-r--r--chrome/browser/views/location_bar/selected_keyword_view.cc21
-rw-r--r--chrome/browser/views/location_bar/selected_keyword_view.h3
-rw-r--r--chrome/chrome_browser.gypi2
7 files changed, 75 insertions, 76 deletions
diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm
index f339d146..ea02141 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.mm
+++ b/chrome/browser/cocoa/location_bar_view_mac.mm
@@ -28,6 +28,7 @@
#include "chrome/browser/extensions/extension_browser_event_router.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/extensions/extension_tabs_module.h"
+#include "chrome/browser/location_bar_util.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
@@ -50,20 +51,6 @@
namespace {
-// Returns the short name for a keyword.
-// TODO(shess): Copied from views/location_bar_view.cc. Try to share
-// it.
-std::wstring GetKeywordName(Profile* profile, const std::wstring& keyword) {
-// Make sure the TemplateURL still exists.
-// TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel
-// to track changes to the model, this should become a DCHECK.
- const TemplateURL* template_url =
- profile->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword);
- if (template_url)
- return template_url->AdjustedShortNameForLocaleDirection();
- return std::wstring();
-}
-
// Values for the label colors for different security states.
static const CGFloat kEVSecureTextColorRedComponent = 0.03;
static const CGFloat kEVSecureTextColorGreenComponent = 0.58;
@@ -72,25 +59,6 @@ static const CGFloat kSecurityErrorTextColorRedComponent = 0.63;
static const CGFloat kSecurityErrorTextColorGreenComponent = 0.0;
static const CGFloat kSecurityErrorTextColorBlueComponent = 0.0;
-// Build a short string to use in keyword-search when the field isn't
-// very big.
-// TODO(shess): Copied from views/location_bar_view.cc. Try to share.
-std::wstring CalculateMinString(const std::wstring& description) {
- // Chop at the first '.' or whitespace.
- const size_t dot_index = description.find(L'.');
- const size_t ws_index = description.find_first_of(kWhitespaceWide);
- size_t chop_index = std::min(dot_index, ws_index);
- std::wstring min_string;
- if (chop_index == std::wstring::npos) {
- // No dot or whitespace, truncate to at most 3 chars.
- min_string = l10n_util::TruncateString(description, 3);
- } else {
- min_string = description.substr(0, chop_index);
- }
- base::i18n::AdjustStringForLocaleDirection(min_string, &min_string);
- return min_string;
-}
-
} // namespace
LocationBarViewMac::LocationBarViewMac(
@@ -265,7 +233,8 @@ void LocationBarViewMac::OnChangedImpl(AutocompleteTextField* field,
// "Engine" is a parameter to be replaced by text based on the
// keyword.
- const std::wstring min_name(CalculateMinString(short_name));
+ const std::wstring min_name(
+ location_bar_util::CalculateMinString(short_name));
NSString* partial_string = nil;
int message_id = is_extension_keyword ?
IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT;
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 9eb2257..eb1ca61 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -37,6 +37,7 @@
#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/browser/gtk/rounded_window.h"
#include "chrome/browser/gtk/view_id_util.h"
+#include "chrome/browser/location_bar_util.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
@@ -101,25 +102,6 @@ void CountVisibleWidgets(GtkWidget* widget, gpointer count) {
*static_cast<int*>(count) += 1;
}
-// Build a short string to use in keyword-search when the field isn't
-// very big.
-// TODO(suzhe): Copied from views/location_bar_view.cc. Try to share.
-std::wstring CalculateMinString(const std::wstring& description) {
- // Chop at the first '.' or whitespace.
- const size_t dot_index = description.find(L'.');
- const size_t ws_index = description.find_first_of(kWhitespaceWide);
- size_t chop_index = std::min(dot_index, ws_index);
- std::wstring min_string;
- if (chop_index == std::wstring::npos) {
- // No dot or whitespace, truncate to at most 3 chars.
- min_string = l10n_util::TruncateString(description, 3);
- } else {
- min_string = description.substr(0, chop_index);
- }
- base::i18n::AdjustStringForLocaleDirection(min_string, &min_string);
- return min_string;
-}
-
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -899,7 +881,7 @@ void LocationBarViewGtk::SetKeywordLabel(const std::wstring& keyword) {
IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT;
std::wstring full_name(l10n_util::GetStringF(message_id, short_name));
std::wstring partial_name(l10n_util::GetStringF(
- message_id, CalculateMinString(short_name)));
+ message_id, location_bar_util::CalculateMinString(short_name)));
gtk_label_set_text(GTK_LABEL(tab_to_search_full_label_),
WideToUTF8(full_name).c_str());
gtk_label_set_text(GTK_LABEL(tab_to_search_partial_label_),
@@ -922,7 +904,6 @@ void LocationBarViewGtk::SetKeywordHintLabel(const std::wstring& keyword) {
std::vector<size_t> content_param_offsets;
const std::wstring keyword_hint(l10n_util::GetStringF(
message_id, std::wstring(), short_name, &content_param_offsets));
-
if (content_param_offsets.size() != 2) {
// See comments on an identical NOTREACHED() in search_provider.cc.
NOTREACHED();
diff --git a/chrome/browser/location_bar_util.cc b/chrome/browser/location_bar_util.cc
new file mode 100644
index 0000000..3542070d
--- /dev/null
+++ b/chrome/browser/location_bar_util.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/location_bar_util.h"
+
+#include "app/l10n_util.h"
+#include "base/i18n/rtl.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_model.h"
+
+namespace location_bar_util {
+
+std::wstring GetKeywordName(Profile* profile, const std::wstring& keyword) {
+// Make sure the TemplateURL still exists.
+// TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel
+// to track changes to the model, this should become a DCHECK.
+ const TemplateURL* template_url =
+ profile->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword);
+ if (template_url)
+ return template_url->AdjustedShortNameForLocaleDirection();
+ return std::wstring();
+}
+
+std::wstring CalculateMinString(const std::wstring& description) {
+ // Chop at the first '.' or whitespace.
+ const size_t dot_index = description.find(L'.');
+ const size_t ws_index = description.find_first_of(kWhitespaceWide);
+ size_t chop_index = std::min(dot_index, ws_index);
+ std::wstring min_string;
+ if (chop_index == std::wstring::npos) {
+ // No dot or whitespace, truncate to at most 3 chars.
+ min_string = l10n_util::TruncateString(description, 3);
+ } else {
+ min_string = description.substr(0, chop_index);
+ }
+ base::i18n::AdjustStringForLocaleDirection(min_string, &min_string);
+ return min_string;
+}
+
+} // namespace location_bar_util
diff --git a/chrome/browser/location_bar_util.h b/chrome/browser/location_bar_util.h
new file mode 100644
index 0000000..2264f53
--- /dev/null
+++ b/chrome/browser/location_bar_util.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_LOCATION_BAR_UTIL_H_
+#define CHROME_BROWSER_LOCATION_BAR_UTIL_H_
+
+#include <string>
+
+class Profile;
+
+namespace location_bar_util {
+
+// Returns the short name for a keyword.
+std::wstring GetKeywordName(Profile* profile, const std::wstring& keyword);
+
+// Build a short string to use in keyword-search when the field isn't
+// very big.
+std::wstring CalculateMinString(const std::wstring& description);
+
+} // namespace location_bar_util
+
+#endif // CHROME_BROWSER_LOCATION_BAR_UTIL_H_
diff --git a/chrome/browser/views/location_bar/selected_keyword_view.cc b/chrome/browser/views/location_bar/selected_keyword_view.cc
index 4bcb827..aeead05 100644
--- a/chrome/browser/views/location_bar/selected_keyword_view.cc
+++ b/chrome/browser/views/location_bar/selected_keyword_view.cc
@@ -8,6 +8,7 @@
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/location_bar_util.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/views/location_bar/keyword_hint_view.h"
#include "grit/generated_resources.h"
@@ -63,25 +64,9 @@ void SelectedKeywordView::SetKeyword(const std::wstring& keyword) {
int message_id = is_extension_keyword ?
IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT;
full_label_.SetText(l10n_util::GetStringF(message_id, short_name));
- const std::wstring min_string = CalculateMinString(short_name);
+ const std::wstring min_string(
+ location_bar_util::CalculateMinString(short_name));
partial_label_.SetText(min_string.empty() ?
full_label_.GetText() :
l10n_util::GetStringF(message_id, min_string));
}
-
-std::wstring SelectedKeywordView::CalculateMinString(
- const std::wstring& description) {
- // Chop at the first '.' or whitespace.
- const size_t dot_index = description.find(L'.');
- const size_t ws_index = description.find_first_of(kWhitespaceWide);
- size_t chop_index = std::min(dot_index, ws_index);
- std::wstring min_string;
- if (chop_index == std::wstring::npos) {
- // No dot or whitespace, truncate to at most 3 chars.
- min_string = l10n_util::TruncateString(description, 3);
- } else {
- min_string = description.substr(0, chop_index);
- }
- base::i18n::AdjustStringForLocaleDirection(min_string, &min_string);
- return min_string;
-}
diff --git a/chrome/browser/views/location_bar/selected_keyword_view.h b/chrome/browser/views/location_bar/selected_keyword_view.h
index 8a3afbf..143025f 100644
--- a/chrome/browser/views/location_bar/selected_keyword_view.h
+++ b/chrome/browser/views/location_bar/selected_keyword_view.h
@@ -38,9 +38,6 @@ class SelectedKeywordView : public IconLabelBubbleView {
void set_profile(Profile* profile) { profile_ = profile; }
private:
- // Returns the truncated version of description to use.
- std::wstring CalculateMinString(const std::wstring& description);
-
// The keyword we're showing. If empty, no keyword is selected.
// NOTE: we don't cache the TemplateURL as it is possible for it to get
// deleted out from under us.
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index b441a88..ed1893c 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1613,6 +1613,8 @@
'browser/load_from_memory_cache_details.h',
'browser/load_notification_details.h',
'browser/location_bar.h',
+ 'browser/location_bar_util.cc',
+ 'browser/location_bar_util.h',
'browser/login_model.h',
'browser/login_prompt.cc',
'browser/login_prompt.h',