summaryrefslogtreecommitdiffstats
path: root/chromium/ui/base/ime/input_method_factory.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/base/ime/input_method_factory.cc')
-rw-r--r--chromium/ui/base/ime/input_method_factory.cc107
1 files changed, 26 insertions, 81 deletions
diff --git a/chromium/ui/base/ime/input_method_factory.cc b/chromium/ui/base/ime/input_method_factory.cc
index 616dd22bd24..876817c86a4 100644
--- a/chromium/ui/base/ime/input_method_factory.cc
+++ b/chromium/ui/base/ime/input_method_factory.cc
@@ -4,17 +4,17 @@
#include "ui/base/ime/input_method_factory.h"
-#include "base/memory/singleton.h"
#include "ui/base/ime/mock_input_method.h"
#if defined(OS_CHROMEOS) && defined(USE_X11)
-#include "ui/base/ime/input_method_ibus.h"
+#include "ui/base/ime/input_method_chromeos.h"
#elif defined(OS_WIN)
#include "base/win/metro.h"
-#include "ui/base/ime/input_method_imm32.h"
-#include "ui/base/ime/input_method_tsf.h"
+#include "ui/base/ime/input_method_win.h"
#include "ui/base/ime/remote_input_method_win.h"
-#elif defined(USE_AURA) && defined(USE_X11)
+#elif defined(OS_MACOSX)
+#include "ui/base/ime/input_method_mac.h"
+#elif defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
#include "ui/base/ime/input_method_auralinux.h"
#else
#include "ui/base/ime/input_method_minimal.h"
@@ -22,103 +22,48 @@
namespace {
-ui::InputMethodFactory* g_input_method_factory = NULL;
+bool g_input_method_set_for_testing = false;
-#if defined(OS_WIN)
-ui::InputMethod* g_shared_input_method = NULL;
-#endif
+bool g_create_input_method_called = false;
} // namespace
namespace ui {
-// static
-InputMethodFactory* InputMethodFactory::GetInstance() {
- if (!g_input_method_factory)
- SetInstance(DefaultInputMethodFactory::GetInstance());
-
- return g_input_method_factory;
-}
-
-// static
-void InputMethodFactory::SetInstance(InputMethodFactory* instance) {
- CHECK(!g_input_method_factory);
- CHECK(instance);
-
- g_input_method_factory = instance;
-}
-
-// static
-void InputMethodFactory::ClearInstance() {
- // It's a client's duty to delete the object.
- g_input_method_factory = NULL;
-}
-
-// DefaultInputMethodFactory
-
-// static
-DefaultInputMethodFactory* DefaultInputMethodFactory::GetInstance() {
- return Singleton<DefaultInputMethodFactory>::get();
-}
-
-scoped_ptr<InputMethod> DefaultInputMethodFactory::CreateInputMethod(
+scoped_ptr<InputMethod> CreateInputMethod(
internal::InputMethodDelegate* delegate,
gfx::AcceleratedWidget widget) {
+ if (!g_create_input_method_called)
+ g_create_input_method_called = true;
+
+ if (g_input_method_set_for_testing)
+ return scoped_ptr<InputMethod>(new MockInputMethod(delegate));
+
#if defined(OS_CHROMEOS) && defined(USE_X11)
- return scoped_ptr<InputMethod>(new InputMethodIBus(delegate));
+ return scoped_ptr<InputMethod>(new InputMethodChromeOS(delegate));
#elif defined(OS_WIN)
- if (base::win::IsTSFAwareRequired())
- return scoped_ptr<InputMethod>(new InputMethodTSF(delegate, widget));
if (IsRemoteInputMethodWinRequired(widget))
return CreateRemoteInputMethodWin(delegate);
- return scoped_ptr<InputMethod>(new InputMethodIMM32(delegate, widget));
-#elif defined(USE_AURA) && defined(USE_X11)
+ return scoped_ptr<InputMethod>(new InputMethodWin(delegate, widget));
+#elif defined(OS_MACOSX)
+ return scoped_ptr<InputMethod>(new InputMethodMac(delegate));
+#elif defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
return scoped_ptr<InputMethod>(new InputMethodAuraLinux(delegate));
#else
return scoped_ptr<InputMethod>(new InputMethodMinimal(delegate));
#endif
}
-// MockInputMethodFactory
-
-// static
-MockInputMethodFactory* MockInputMethodFactory::GetInstance() {
- return Singleton<MockInputMethodFactory>::get();
-}
-
-scoped_ptr<InputMethod> MockInputMethodFactory::CreateInputMethod(
- internal::InputMethodDelegate* delegate,
- gfx::AcceleratedWidget /* widget */) {
- return scoped_ptr<InputMethod>(new MockInputMethod(delegate));
-}
-
-// Shorthands
-
-scoped_ptr<InputMethod> CreateInputMethod(
- internal::InputMethodDelegate* delegate,
- gfx::AcceleratedWidget widget) {
- return InputMethodFactory::GetInstance()->CreateInputMethod(delegate, widget);
-}
-
void SetUpInputMethodFactoryForTesting() {
- InputMethodFactory::SetInstance(MockInputMethodFactory::GetInstance());
-}
+ if (g_input_method_set_for_testing)
+ return;
-#if defined(OS_WIN)
-InputMethod* GetSharedInputMethod() {
- if (!g_shared_input_method)
- g_shared_input_method = CreateInputMethod(NULL, NULL).release();
- return g_shared_input_method;
-}
-
-namespace internal {
+ CHECK(!g_create_input_method_called)
+ << "ui::SetUpInputMethodFactoryForTesting was called after use of "
+ << "ui::CreateInputMethod. You must call "
+ << "ui::SetUpInputMethodFactoryForTesting earlier.";
-void DestroySharedInputMethod() {
- delete g_shared_input_method;
- g_shared_input_method = NULL;
+ g_input_method_set_for_testing = true;
}
-} // namespace internal
-#endif
-
} // namespace ui