diff options
15 files changed, 149 insertions, 157 deletions
diff --git a/chrome/browser/chromeos/input_method/input_method_delegate_impl.cc b/chrome/browser/chromeos/input_method/input_method_delegate_impl.cc index 56e1190..50a70b8 100644 --- a/chrome/browser/chromeos/input_method/input_method_delegate_impl.cc +++ b/chrome/browser/chromeos/input_method/input_method_delegate_impl.cc @@ -8,6 +8,7 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/browser_process.h" #include "chrome/common/pref_names.h" +#include "ui/base/l10n/l10n_util.h" namespace chromeos { namespace input_method { @@ -25,12 +26,17 @@ std::string InputMethodDelegateImpl::GetHardwareKeyboardLayout() const { return std::string(); } -std::string InputMethodDelegateImpl::GetActiveLocale() const { - if (g_browser_process) - return g_browser_process->GetApplicationLocale(); +string16 InputMethodDelegateImpl::GetLocalizedString(int resource_id) const { + return l10n_util::GetStringUTF16(resource_id); +} - NOTREACHED(); - return std::string(); +string16 InputMethodDelegateImpl::GetDisplayLanguageName( + const std::string& language_code) const { + DCHECK(g_browser_process); + return l10n_util::GetDisplayNameForLocale( + language_code, + g_browser_process->GetApplicationLocale(), + true); } } // namespace input_method diff --git a/chrome/browser/chromeos/input_method/input_method_delegate_impl.h b/chrome/browser/chromeos/input_method/input_method_delegate_impl.h index 541aa71..cb15566 100644 --- a/chrome/browser/chromeos/input_method/input_method_delegate_impl.h +++ b/chrome/browser/chromeos/input_method/input_method_delegate_impl.h @@ -22,7 +22,9 @@ class InputMethodDelegateImpl : public InputMethodDelegate { // InputMethodDelegate implementation. virtual std::string GetHardwareKeyboardLayout() const OVERRIDE; - virtual std::string GetActiveLocale() const OVERRIDE; + virtual string16 GetLocalizedString(int resource_id) const OVERRIDE; + virtual string16 GetDisplayLanguageName( + const std::string& language_code) const OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(InputMethodDelegateImpl); diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc index 705fa01..e0e356a 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc @@ -17,9 +17,9 @@ #include "chromeos/dbus/ibus/mock_ibus_input_context_client.h" #include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h" #include "chromeos/ime/extension_ime_util.h" +#include "chromeos/ime/fake_input_method_delegate.h" #include "chromeos/ime/mock_component_extension_ime_manager_delegate.h" #include "chromeos/ime/mock_ibus_daemon_controller.h" -#include "chromeos/ime/mock_input_method_delegate.h" #include "chromeos/ime/mock_xkeyboard.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/accelerators/accelerator.h" @@ -52,7 +52,7 @@ class InputMethodManagerImplTest : public testing::Test { mock_ibus_client_ = mock_dbus_thread_manager_->mock_ibus_client(); mock_ibus_input_context_client_ = mock_dbus_thread_manager_->mock_ibus_input_context_client(); - delegate_ = new MockInputMethodDelegate(); + delegate_ = new FakeInputMethodDelegate(); manager_.reset(new InputMethodManagerImpl( scoped_ptr<InputMethodDelegate>(delegate_))); controller_ = new MockIBusController; @@ -113,7 +113,7 @@ class InputMethodManagerImplTest : public testing::Test { } scoped_ptr<InputMethodManagerImpl> manager_; - MockInputMethodDelegate* delegate_; + FakeInputMethodDelegate* delegate_; MockIBusController* controller_; MockCandidateWindowController* candidate_window_controller_; MockIBusDaemonController* mock_ibus_daemon_controller_; diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc index f8ad46a..2133080 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.cc +++ b/chrome/browser/chromeos/input_method/input_method_util.cc @@ -18,10 +18,8 @@ #include "chromeos/ime/component_extension_ime_manager.h" #include "chromeos/ime/extension_ime_util.h" #include "chromeos/ime/input_method_delegate.h" +// TODO(nona): move this header from this file. #include "grit/generated_resources.h" -#include "third_party/icu/public/common/unicode/uloc.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/l10n/l10n_util_collator.h" namespace { @@ -259,29 +257,6 @@ const struct EnglishToResouceId { const size_t kEnglishToResourceIdArraySize = arraysize(kEnglishToResourceIdArray); -// The comparator is used for sorting language codes by their -// corresponding language names, using the ICU collator. -struct CompareLanguageCodesByLanguageName - : std::binary_function<const std::string&, const std::string&, bool> { - CompareLanguageCodesByLanguageName(InputMethodUtil* util, - icu::Collator* collator) - : util_(util), collator_(collator) { - } - - // Calling GetLanguageDisplayNameFromCode() in the comparator is not - // efficient, but acceptable as the function is cheap, and the language - // list is short (about 60 at most). - bool operator()(const std::string& s1, const std::string& s2) const { - const string16 key1 = util_->GetLanguageDisplayNameFromCode(s1); - const string16 key2 = util_->GetLanguageDisplayNameFromCode(s2); - return l10n_util::StringComparator<string16>(collator_)(key1, key2); - } - - private: - InputMethodUtil* util_; - icu::Collator* collator_; -}; - // The list of language that do not have associated input methods in IBus. // For these languages, we associate input methods here. const struct ExtraLanguage { @@ -342,7 +317,7 @@ bool InputMethodUtil::TranslateStringInternal( return false; } - *out_string = l10n_util::GetStringUTF16(iter->second); + *out_string = delegate_->GetLocalizedString(iter->second); return true; } @@ -449,7 +424,7 @@ string16 InputMethodUtil::GetInputMethodMediumName( for (size_t i = 0; i < kMappingImeIdToMediumLenNameResourceIdLen; ++i) { if (kMappingImeIdToMediumLenNameResourceId[i].input_method_id == input_method.id()) { - return l10n_util::GetStringUTF16( + return delegate_->GetLocalizedString( kMappingImeIdToMediumLenNameResourceId[i].resource_id); } } @@ -470,7 +445,7 @@ string16 InputMethodUtil::GetInputMethodLongName( // keyboard layouts and share the same layout of keyboard (Belgian). We need // to show explicitly the language for the layout. For Arabic, Amharic, and // Indic languages: they share "Standard Input Method". - const string16 standard_input_method_text = l10n_util::GetStringUTF16( + const string16 standard_input_method_text = delegate_->GetLocalizedString( IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD); const std::string language_code = input_method.language_code(); @@ -479,8 +454,8 @@ string16 InputMethodUtil::GetInputMethodLongName( language_code == "de" || language_code == "fr" || language_code == "nl") { - const string16 language_name = l10n_util::GetDisplayNameForLocale( - language_code, delegate_->GetActiveLocale(), true); + const string16 language_name = delegate_->GetDisplayLanguageName( + language_code); text = language_name + UTF8ToUTF16(" - ") + text; } @@ -496,19 +471,6 @@ const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( return (iter == id_to_descriptor_.end()) ? NULL : &(iter->second); } -// static -string16 InputMethodUtil::GetLanguageDisplayNameFromCode( - const std::string& language_code) { - return l10n_util::GetDisplayNameForLocale( - language_code, delegate_->GetActiveLocale(), true); -} - -// static -string16 InputMethodUtil::GetLanguageNativeDisplayNameFromCode( - const std::string& language_code) { - return l10n_util::GetDisplayNameForLocale(language_code, language_code, true); -} - std::vector<std::string> InputMethodUtil::GetExtraLanguageCodesFromId( const std::string& input_method_id) const { std::vector<std::string> result; diff --git a/chrome/browser/chromeos/input_method/input_method_util.h b/chrome/browser/chromeos/input_method/input_method_util.h index 7a13a7e..cb03e5f 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.h +++ b/chrome/browser/chromeos/input_method/input_method_util.h @@ -103,21 +103,6 @@ class InputMethodUtil { // Returns true if the given input method id is for a keyboard layout. static bool IsKeyboardLayout(const std::string& input_method_id); - // Converts a language code to a language display name, using the - // current application locale. MaybeRewriteLanguageName() is called - // internally. - // Examples: "fi" => "Finnish" - // "en-US" => "English (United States)" - string16 GetLanguageDisplayNameFromCode( - const std::string& language_code); - - // Converts a language code to a language native display name. - // MaybeRewriteLanguageName() is called internally. - // Examples: "fi" => "suomi" (rather than Finnish) - // "en-US" => "English (United States)" - static string16 GetLanguageNativeDisplayNameFromCode( - const std::string& language_code); - // Returns extra language code list associated with |input_method_id|. If // there is no associated langauge code, this function returns empty list. std::vector<std::string> GetExtraLanguageCodesFromId( diff --git a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc index acaa277..6a1e521 100644 --- a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc +++ b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc @@ -6,11 +6,12 @@ #include <string> +#include "base/bind.h" #include "base/memory/scoped_ptr.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/input_method/input_method_manager.h" +#include "chromeos/ime/fake_input_method_delegate.h" #include "chromeos/ime/input_method_whitelist.h" -#include "chromeos/ime/mock_input_method_delegate.h" #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/l10n/l10n_util.h" @@ -42,6 +43,10 @@ class InputMethodUtilTest : public testing::Test { public: InputMethodUtilTest() : util_(&delegate_, whitelist_.GetSupportedInputMethods()) { + delegate_.set_get_localized_string_callback( + base::Bind(&l10n_util::GetStringUTF16)); + delegate_.set_get_display_language_name_callback( + base::Bind(&InputMethodUtilTest::GetDisplayLanguageName)); } InputMethodDescriptor GetDesc(const std::string& id, @@ -55,7 +60,11 @@ class InputMethodUtilTest : public testing::Test { false); } - MockInputMethodDelegate delegate_; + static string16 GetDisplayLanguageName(const std::string& language_code) { + return l10n_util::GetDisplayNameForLocale(language_code, "en", true); + } + + FakeInputMethodDelegate delegate_; InputMethodWhitelist whitelist_; TestableInputMethodUtil util_; }; @@ -342,11 +351,6 @@ TEST_F(InputMethodUtilTest, TestGetInputMethodDescriptorFromId) { EXPECT_EQ("zh-CN", descriptor->language_code()); } -TEST_F(InputMethodUtilTest, TestGetLanguageNativeDisplayNameFromCode) { - EXPECT_EQ(UTF8ToUTF16("suomi"), - InputMethodUtil::GetLanguageNativeDisplayNameFromCode("fi")); -} - TEST_F(InputMethodUtilTest, TestGetInputMethodIdsForLanguageCode) { std::multimap<std::string, std::string> language_code_to_ids_map; language_code_to_ids_map.insert(std::make_pair("ja", "mozc")); diff --git a/chrome/browser/chromeos/input_method/mock_input_method_manager.h b/chrome/browser/chromeos/input_method/mock_input_method_manager.h index 24aec77..bef207c 100644 --- a/chrome/browser/chromeos/input_method/mock_input_method_manager.h +++ b/chrome/browser/chromeos/input_method/mock_input_method_manager.h @@ -7,8 +7,8 @@ #include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" +#include "chromeos/ime/fake_input_method_delegate.h" #include "chromeos/ime/input_method_whitelist.h" -#include "chromeos/ime/mock_input_method_delegate.h" #include "chromeos/ime/mock_xkeyboard.h" namespace chromeos { @@ -81,7 +81,7 @@ class MockInputMethodManager : public InputMethodManager { std::string current_input_method_id_; InputMethodWhitelist whitelist_; - MockInputMethodDelegate delegate_; // used by util_ + FakeInputMethodDelegate delegate_; // used by util_ InputMethodUtil util_; MockXKeyboard xkeyboard_; diff --git a/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc index 4a345f2..46b7c3c 100644 --- a/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc @@ -185,13 +185,11 @@ ListValue* CrosLanguageOptionsHandler::GetLanguageListInternal( *iter) == base_language_codes.end()) { continue; } - input_method::InputMethodUtil* input_method_util = - input_method::GetInputMethodManager()->GetInputMethodUtil(); const string16 display_name = - input_method_util->GetLanguageDisplayNameFromCode(*iter); + l10n_util::GetDisplayNameForLocale(*iter, app_locale, true); const string16 native_display_name = - input_method::InputMethodUtil::GetLanguageNativeDisplayNameFromCode( - *iter); + l10n_util::GetDisplayNameForLocale(*iter, *iter, true); + display_names.push_back(display_name); language_map[display_name] = std::make_pair(*iter, native_display_name); diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 9a1b58c..cec0da2 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -392,10 +392,10 @@ 'dbus/ibus/mock_ibus_engine_service.h', 'dbus/ibus/mock_ibus_panel_service.cc', 'dbus/ibus/mock_ibus_panel_service.h', + 'ime/fake_input_method_delegate.cc', + 'ime/fake_input_method_delegate.h', 'ime/mock_ibus_daemon_controller.cc', 'ime/mock_ibus_daemon_controller.h', - 'ime/mock_input_method_delegate.cc', - 'ime/mock_input_method_delegate.h', 'ime/mock_xkeyboard.cc', 'ime/mock_xkeyboard.h', ], diff --git a/chromeos/ime/fake_input_method_delegate.cc b/chromeos/ime/fake_input_method_delegate.cc new file mode 100644 index 0000000..b364260 --- /dev/null +++ b/chromeos/ime/fake_input_method_delegate.cc @@ -0,0 +1,35 @@ +// Copyright 2013 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 "chromeos/ime/fake_input_method_delegate.h" + +namespace chromeos { +namespace input_method { + +FakeInputMethodDelegate::FakeInputMethodDelegate() + : active_locale_("en") { +} + +FakeInputMethodDelegate::~FakeInputMethodDelegate() { +} + +std::string FakeInputMethodDelegate::GetHardwareKeyboardLayout() const { + return hardware_keyboard_layout_; +} + +string16 FakeInputMethodDelegate::GetLocalizedString(int resource_id) const { + if (!get_localized_string_callback_.is_null()) + return get_localized_string_callback_.Run(resource_id); + return string16(); +} + +string16 FakeInputMethodDelegate::GetDisplayLanguageName( + const std::string& language_code) const { + if (!get_display_language_name_callback_.is_null()) + return get_display_language_name_callback_.Run(language_code); + return string16(); +} + +} // namespace input_method +} // namespace chromeos diff --git a/chromeos/ime/fake_input_method_delegate.h b/chromeos/ime/fake_input_method_delegate.h new file mode 100644 index 0000000..c6c300e --- /dev/null +++ b/chromeos/ime/fake_input_method_delegate.h @@ -0,0 +1,62 @@ +// Copyright 2013 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 CHROMEOS_IME_FAKE_INPUT_METHOD_DELEGATE_H_ +#define CHROMEOS_IME_FAKE_INPUT_METHOD_DELEGATE_H_ + +#include "base/basictypes.h" +#include "base/callback.h" +#include "base/compiler_specific.h" +#include "chromeos/chromeos_export.h" +#include "chromeos/ime/input_method_delegate.h" + +namespace chromeos { +namespace input_method { + +class CHROMEOS_EXPORT FakeInputMethodDelegate : public InputMethodDelegate { + public: + typedef base::Callback<string16 (const std::string& language_code)> + LanguageNameLocalizationCallback; + typedef base::Callback<string16 (int resource_id)> + GetLocalizedStringCallback; + + FakeInputMethodDelegate(); + virtual ~FakeInputMethodDelegate(); + + // InputMethodDelegate implementation: + virtual std::string GetHardwareKeyboardLayout() const OVERRIDE; + virtual string16 GetLocalizedString(int resource_id) const OVERRIDE; + virtual string16 GetDisplayLanguageName( + const std::string& language_code) const OVERRIDE; + + void set_hardware_keyboard_layout(const std::string& value) { + hardware_keyboard_layout_ = value; + } + + void set_active_locale(const std::string& value) { + active_locale_ = value; + } + + void set_get_display_language_name_callback( + const LanguageNameLocalizationCallback& callback) { + get_display_language_name_callback_ = callback; + } + + void set_get_localized_string_callback( + const GetLocalizedStringCallback& callback) { + get_localized_string_callback_ = callback; + } + + private: + std::string hardware_keyboard_layout_; + std::string active_locale_; + LanguageNameLocalizationCallback get_display_language_name_callback_; + GetLocalizedStringCallback get_localized_string_callback_; + DISALLOW_COPY_AND_ASSIGN(FakeInputMethodDelegate); +}; + +} // namespace input_method +} // namespace chromeos + +#endif // CHROMEOS_IME_FAKE_INPUT_METHOD_DELEGATE_H_ diff --git a/chromeos/ime/input_method_delegate.h b/chromeos/ime/input_method_delegate.h index e242f3b..906cfb1 100644 --- a/chromeos/ime/input_method_delegate.h +++ b/chromeos/ime/input_method_delegate.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/string16.h" namespace chromeos { namespace input_method { @@ -21,8 +22,16 @@ class InputMethodDelegate { // Retrieves the hardware keyboard layout ID. May return an empty string if // the ID is unknown. virtual std::string GetHardwareKeyboardLayout() const = 0; - // Retrieves the currently active UI locale. - virtual std::string GetActiveLocale() const = 0; + + // Retrieves localized string for |resource_id|. + virtual string16 GetLocalizedString(int resource_id) const = 0; + + // Converts a language code to a language display name, using the + // current application locale. + // Examples: "fi" => "Finnish" + // "en-US" => "English (United States)" + virtual string16 GetDisplayLanguageName( + const std::string& language_code) const = 0; private: DISALLOW_COPY_AND_ASSIGN(InputMethodDelegate); diff --git a/chromeos/ime/mock_input_method_delegate.cc b/chromeos/ime/mock_input_method_delegate.cc deleted file mode 100644 index 0f68132..0000000 --- a/chromeos/ime/mock_input_method_delegate.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2013 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 "chromeos/ime/mock_input_method_delegate.h" - -namespace chromeos { -namespace input_method { - -MockInputMethodDelegate::MockInputMethodDelegate() - : active_locale_("en") { -} - -MockInputMethodDelegate::~MockInputMethodDelegate() { -} - -std::string MockInputMethodDelegate::GetHardwareKeyboardLayout() const { - return hardware_keyboard_layout_; -} - -std::string MockInputMethodDelegate::GetActiveLocale() const { - return active_locale_; -} - -} // namespace input_method -} // namespace chromeos diff --git a/chromeos/ime/mock_input_method_delegate.h b/chromeos/ime/mock_input_method_delegate.h deleted file mode 100644 index f7f2be9..0000000 --- a/chromeos/ime/mock_input_method_delegate.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2013 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 CHROMEOS_IME_MOCK_INPUT_METHOD_DELEGATE_H_ -#define CHROMEOS_IME_MOCK_INPUT_METHOD_DELEGATE_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "chromeos/chromeos_export.h" -#include "chromeos/ime/input_method_delegate.h" - -namespace chromeos { -namespace input_method { - -class CHROMEOS_EXPORT MockInputMethodDelegate : public InputMethodDelegate { - public: - MockInputMethodDelegate(); - virtual ~MockInputMethodDelegate(); - - // InputMethodDelegate implementation: - virtual std::string GetHardwareKeyboardLayout() const OVERRIDE; - virtual std::string GetActiveLocale() const OVERRIDE; - - void set_hardware_keyboard_layout(const std::string& value) { - hardware_keyboard_layout_ = value; - } - - void set_active_locale(const std::string& value) { - active_locale_ = value; - } - - private: - std::string hardware_keyboard_layout_; - std::string active_locale_; - DISALLOW_COPY_AND_ASSIGN(MockInputMethodDelegate); -}; - -} // namespace input_method -} // namespace chromeos - -#endif // CHROMEOS_IME_MOCK_INPUT_METHOD_DELEGATE_H_ diff --git a/chromeos/ime/xkeyboard_unittest.cc b/chromeos/ime/xkeyboard_unittest.cc index 6048c4c..af71702 100644 --- a/chromeos/ime/xkeyboard_unittest.cc +++ b/chromeos/ime/xkeyboard_unittest.cc @@ -11,8 +11,6 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "chromeos/ime/input_method_whitelist.h" -#include "chromeos/ime/mock_input_method_delegate.h" #include "testing/gtest/include/gtest/gtest.h" #include <X11/Xlib.h> @@ -35,7 +33,6 @@ class XKeyboardTest : public testing::Test { xkey_.reset(); } - InputMethodWhitelist whitelist_; scoped_ptr<XKeyboard> xkey_; MessageLoopForUI message_loop_; |