diff options
author | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-24 22:17:06 +0000 |
---|---|---|
committer | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-24 22:17:06 +0000 |
commit | d70539de3df8f214397881727229a7786da9be35 (patch) | |
tree | d10df8d461702c8de9b6df045955ee2226edc046 /chrome/browser/tab_contents | |
parent | 16792a730c621ed32aa53b57d57e6c88e232ea02 (diff) | |
download | chromium_src-d70539de3df8f214397881727229a7786da9be35.zip chromium_src-d70539de3df8f214397881727229a7786da9be35.tar.gz chromium_src-d70539de3df8f214397881727229a7786da9be35.tar.bz2 |
Replace std:;wstring with std::string and string16 in locale-name related APIs.
1. Change the locale param to be std::string because they're always ASCII and change call-sites accordingly.
2. Add GetStringFUTF16 to l10n_util. On Windows, they're inline helpers calling the correspondingGetStringF returning wstring while on Mac/Linux, they just return the result of |string16 GetStringF|without converting to wstring.
This is part 1 of the fix for issue 8647. Some of newly introduced conversions are temporary and will be removed later (e.g. ASCIIToWide applied to the result of GetApplicationLocale in a few places).
Note : this CL will be landed after http://codereview.chromium.org/147038 is landed.
BUG=8647 (http://crbug.com/8647)
TEST=Pass l10n_util_unittest and other unit tests
Review URL: http://codereview.chromium.org/126223
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19183 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
6 files changed, 49 insertions, 45 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 94c789d..3fae586 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -84,7 +84,8 @@ void RenderViewContextMenu::AppendLinkItems() { if (params_.link_url.SchemeIs(chrome::kMailToScheme)) { AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION, - l10n_util::GetString(IDS_CONTENT_CONTEXT_COPYEMAILADDRESS)); + l10n_util::GetStringUTF16( + IDS_CONTENT_CONTEXT_COPYEMAILADDRESS)); } else { AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION); } @@ -136,9 +137,10 @@ void RenderViewContextMenu::AppendSearchProvider() { std::wstring selection_text = l10n_util::TruncateString(params_.selection_text, 50); if (!selection_text.empty()) { - std::wstring label(l10n_util::GetStringF(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, - default_provider->short_name(), - selection_text)); + string16 label(WideToUTF16( + l10n_util::GetStringF(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, + default_provider->short_name(), + selection_text))); AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label); } } @@ -150,7 +152,7 @@ void RenderViewContextMenu::AppendEditableItems() { IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; ++i) { AppendMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i), - params_.dictionary_suggestions[i]); + WideToUTF16(params_.dictionary_suggestions[i])); } if (params_.dictionary_suggestions.size() > 0) AppendSeparator(); @@ -159,7 +161,8 @@ void RenderViewContextMenu::AppendEditableItems() { if (!params_.misspelled_word.empty()) { if (params_.dictionary_suggestions.size() == 0) { AppendMenuItem(0, - l10n_util::GetString(IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS)); + l10n_util::GetStringUTF16( + IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS)); } AppendMenuItem(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY); AppendSeparator(); @@ -176,19 +179,19 @@ void RenderViewContextMenu::AppendEditableItems() { // Add Spell Check options sub menu. StartSubMenu(IDC_SPELLCHECK_MENU, - l10n_util::GetString(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU)); + l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU)); // Add Spell Check languages to sub menu. - SpellChecker::Languages display_languages; + SpellChecker::Languages spellcheck_languages; SpellChecker::GetSpellCheckLanguages(profile_, - &display_languages); - DCHECK(display_languages.size() < + &spellcheck_languages); + DCHECK(spellcheck_languages.size() < IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST); - const std::wstring app_locale = g_browser_process->GetApplicationLocale(); - for (size_t i = 0; i < display_languages.size(); ++i) { - std::wstring local_language(l10n_util::GetLocalName( - display_languages[i], app_locale, true)); - AppendRadioMenuItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i, local_language); + const std::string app_locale = g_browser_process->GetApplicationLocale(); + for (size_t i = 0; i < spellcheck_languages.size(); ++i) { + string16 display_name(l10n_util::GetDisplayNameForLocale( + spellcheck_languages[i], app_locale, true)); + AppendRadioMenuItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i, display_name); } // Add item in the sub menu to pop up the fonts and languages options menu. @@ -198,7 +201,8 @@ void RenderViewContextMenu::AppendEditableItems() { // Add 'Check the spelling of this field' item in the sub menu. AppendCheckboxMenuItem( IDC_CHECK_SPELLING_OF_THIS_FIELD, - l10n_util::GetString(IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD)); + l10n_util::GetStringUTF16( + IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD)); FinishSubMenu(); diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h index e586c49..95595c1 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.h +++ b/chrome/browser/tab_contents/render_view_context_menu.h @@ -36,13 +36,13 @@ class RenderViewContextMenu { virtual void AppendMenuItem(int id) = 0; // Append a normal menu item, using |label| for the name. - virtual void AppendMenuItem(int id, const std::wstring& label) = 0; + virtual void AppendMenuItem(int id, const string16& label) = 0; // Append a radio menu item. - virtual void AppendRadioMenuItem(int id, const std::wstring& label) = 0; + virtual void AppendRadioMenuItem(int id, const string16& label) = 0; // Append a checkbox menu item. - virtual void AppendCheckboxMenuItem(int id, const std::wstring& label) = 0; + virtual void AppendCheckboxMenuItem(int id, const string16& label) = 0; // Append a separator. virtual void AppendSeparator() = 0; @@ -52,7 +52,7 @@ class RenderViewContextMenu { // the main menu we are building. We only support at most single-depth // submenus, so calls to StartSubMenu() while we are already building a // submenu will be ignored. - virtual void StartSubMenu(int id, const std::wstring& label) = 0; + virtual void StartSubMenu(int id, const string16& label) = 0; // Finish creating the submenu and attach it to the main menu. virtual void FinishSubMenu() = 0; diff --git a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc index d1a17e1..dcfdb74 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc @@ -61,29 +61,29 @@ void RenderViewContextMenuGtk::StoppedShowing() { } void RenderViewContextMenuGtk::AppendMenuItem(int id) { - AppendItem(id, std::wstring(), MENU_NORMAL); + AppendItem(id, string16(), MENU_NORMAL); } void RenderViewContextMenuGtk::AppendMenuItem(int id, - const std::wstring& label) { + const string16& label) { AppendItem(id, label, MENU_NORMAL); } void RenderViewContextMenuGtk::AppendRadioMenuItem(int id, - const std::wstring& label) { + const string16& label) { AppendItem(id, label, MENU_RADIO); } void RenderViewContextMenuGtk::AppendCheckboxMenuItem(int id, - const std::wstring& label) { + const string16& label) { AppendItem(id, label, MENU_CHECKBOX); } void RenderViewContextMenuGtk::AppendSeparator() { - AppendItem(0, std::wstring(), MENU_SEPARATOR); + AppendItem(0, string16(), MENU_SEPARATOR); } -void RenderViewContextMenuGtk::StartSubMenu(int id, const std::wstring& label) { +void RenderViewContextMenuGtk::StartSubMenu(int id, const string16& label) { AppendItem(id, label, MENU_NORMAL); making_submenu_ = true; } @@ -104,7 +104,7 @@ void RenderViewContextMenuGtk::DidWriteURLToClipboard( } void RenderViewContextMenuGtk::AppendItem( - int id, const std::wstring& label, MenuItemType type) { + int id, const string16& label, MenuItemType type) { MenuCreateMaterial menu_create_material = { type, id, 0, 0, NULL }; @@ -112,7 +112,7 @@ void RenderViewContextMenuGtk::AppendItem( if (label.empty()) menu_create_material.label_id = id; else - label_map_[id] = WideToUTF8(label); + label_map_[id] = UTF16ToUTF8(label); std::vector<MenuCreateMaterial>* menu = making_submenu_ ? &submenu_ : &menu_; diff --git a/chrome/browser/tab_contents/render_view_context_menu_gtk.h b/chrome/browser/tab_contents/render_view_context_menu_gtk.h index dd6cc92..d4fca48 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_gtk.h +++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.h @@ -41,16 +41,16 @@ class RenderViewContextMenuGtk : public RenderViewContextMenu, // RenderViewContextMenu implementation -------------------------------------- virtual void DoInit(); virtual void AppendMenuItem(int id); - virtual void AppendMenuItem(int id, const std::wstring& label); - virtual void AppendRadioMenuItem(int id, const std::wstring& label); - virtual void AppendCheckboxMenuItem(int id, const std::wstring& label); + virtual void AppendMenuItem(int id, const string16& label); + virtual void AppendRadioMenuItem(int id, const string16& label); + virtual void AppendCheckboxMenuItem(int id, const string16& label); virtual void AppendSeparator(); - virtual void StartSubMenu(int id, const std::wstring& label); + virtual void StartSubMenu(int id, const string16& label); virtual void FinishSubMenu(); virtual void DidWriteURLToClipboard(const std::string& url); private: - void AppendItem(int id, const std::wstring& label, MenuItemType type); + void AppendItem(int id, const string16& label, MenuItemType type); static void DoneMakingMenu(std::vector<MenuCreateMaterial>* menu); scoped_ptr<MenuGtk> gtk_menu_; diff --git a/chrome/browser/tab_contents/render_view_context_menu_mac.h b/chrome/browser/tab_contents/render_view_context_menu_mac.h index 8ca5e3c..0703a18 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_mac.h +++ b/chrome/browser/tab_contents/render_view_context_menu_mac.h @@ -29,15 +29,15 @@ class RenderViewContextMenuMac : public RenderViewContextMenu { // RenderViewContextMenu implementation- virtual void DoInit(); virtual void AppendMenuItem(int id); - virtual void AppendMenuItem(int id, const std::wstring& label); - virtual void AppendRadioMenuItem(int id, const std::wstring& label); - virtual void AppendCheckboxMenuItem(int id, const std::wstring& label); + virtual void AppendMenuItem(int id, const string16& label); + virtual void AppendRadioMenuItem(int id, const string16& label); + virtual void AppendCheckboxMenuItem(int id, const string16& label); virtual void AppendSeparator(); - virtual void StartSubMenu(int id, const std::wstring& label); + virtual void StartSubMenu(int id, const string16& label); virtual void FinishSubMenu(); // Do things like remove the windows accelerators. - static NSString* PrepareLabelForDisplay(const std::wstring& label); + static NSString* PrepareLabelForDisplay(const string16& label); private: NSMenu* menu_; diff --git a/chrome/browser/tab_contents/render_view_context_menu_mac.mm b/chrome/browser/tab_contents/render_view_context_menu_mac.mm index 4c0537f..34b49b3 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_mac.mm +++ b/chrome/browser/tab_contents/render_view_context_menu_mac.mm @@ -68,10 +68,10 @@ void RenderViewContextMenuMac::DoInit() { // TODO(pinkerton): Do we want to do anything like make a maximum string width // and middle-truncate? NSString* RenderViewContextMenuMac::PrepareLabelForDisplay( - const std::wstring& label) { + const string16& label) { // Strip out any "&"'s that are windows accelerators and we don't use. NSMutableString* title = - [NSMutableString stringWithString:base::SysWideToNSString(label)]; + [NSMutableString stringWithString:base::SysUTF16ToNSString(label)]; DCHECK(title); NSRange range = NSMakeRange(0, [title length]); [title replaceOccurrencesOfString:@"&" withString:@"" options:0 range:range]; @@ -79,11 +79,11 @@ NSString* RenderViewContextMenuMac::PrepareLabelForDisplay( } void RenderViewContextMenuMac::AppendMenuItem(int command_id) { - AppendMenuItem(command_id, l10n_util::GetString(command_id)); + AppendMenuItem(command_id, l10n_util::GetStringUTF16(command_id)); } void RenderViewContextMenuMac::AppendMenuItem(int command_id, - const std::wstring& label) { + const string16& label) { // Create the item and set its target/action to |target_| with the command // as |command_id|. Then add it to the menu at the end. NSMenuItem* item = @@ -97,12 +97,12 @@ void RenderViewContextMenuMac::AppendMenuItem(int command_id, } void RenderViewContextMenuMac::AppendRadioMenuItem(int id, - const std::wstring& label) { + const string16& label) { NOTIMPLEMENTED(); } void RenderViewContextMenuMac::AppendCheckboxMenuItem(int id, - const std::wstring& label) { + const string16& label) { NOTIMPLEMENTED(); } @@ -112,7 +112,7 @@ void RenderViewContextMenuMac::AppendSeparator() { } void RenderViewContextMenuMac::StartSubMenu(int command_id, - const std::wstring& label) { + const string16& label) { // I'm not a fan of this kind of API, but the other platforms have similar // guards so at least we know everyone will break together if someone // tries to mis-use the API. |