summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authornona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-18 15:20:16 +0000
committernona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-18 15:20:16 +0000
commit20fd79eeb79b9a0f8770a708ddcbf7f66564b57f (patch)
tree6748353019aa0dd758b5bfc820b6c1a3279f706d /chromeos
parent002aec6aa74169469c214ec1a2b66f91678bf823 (diff)
downloadchromium_src-20fd79eeb79b9a0f8770a708ddcbf7f66564b57f.zip
chromium_src-20fd79eeb79b9a0f8770a708ddcbf7f66564b57f.tar.gz
chromium_src-20fd79eeb79b9a0f8770a708ddcbf7f66564b57f.tar.bz2
Decouple l10n_util from InputMethodUtil.
This CL changes: - Moving localization related function into delegate class. - Removing GetLanguageDisplayNameFromCode and GetLanguageNativeDisplayNameFromCode from InputMethodUtil because they are just thin wrapper function of l10n_util and only used from CrosLanguageOptionHandler. This CL does not change any test expectations except TestGetLanguageNativeDisplayNameFromCode for checking regressions. And I'm going to refactor strings related stuff to more appropriate location. So let me keep tests as is. BUG=164375 TEST=ran unit_tests and also checked there is no regression with this CL on actual devices. Review URL: https://chromiumcodereview.appspot.com/14200032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194927 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/chromeos.gyp4
-rw-r--r--chromeos/ime/fake_input_method_delegate.cc35
-rw-r--r--chromeos/ime/fake_input_method_delegate.h62
-rw-r--r--chromeos/ime/input_method_delegate.h13
-rw-r--r--chromeos/ime/mock_input_method_delegate.cc26
-rw-r--r--chromeos/ime/mock_input_method_delegate.h42
-rw-r--r--chromeos/ime/xkeyboard_unittest.cc3
7 files changed, 110 insertions, 75 deletions
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_;