1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/ime/input_method_factory.h"
7 #include "ui/base/ime/input_method_delegate.h"
8 #include "ui/base/ime/mock_input_method.h"
10 #if defined(OS_CHROMEOS) && defined(USE_X11)
11 #include "ui/base/ime/input_method_ibus.h"
13 #include "base/win/metro.h"
14 #include "ui/base/ime/input_method_imm32.h"
15 #include "ui/base/ime/input_method_tsf.h"
16 #elif defined(USE_AURA) && defined(USE_X11)
17 #include "ui/base/ime/input_method_linux_x11.h"
19 #include "ui/base/ime/fake_input_method.h"
25 bool g_input_method_set_for_testing = false;
26 InputMethod* g_shared_input_method = NULL;
29 // Returns a new instance of input method object for IMM32 or TSF.
30 InputMethod* CreateInputMethodWinInternal(
31 internal::InputMethodDelegate* delegate,
32 gfx::AcceleratedWidget widget) {
33 if (base::win::IsTSFAwareRequired())
34 return new InputMethodTSF(delegate, widget);
36 return new InputMethodIMM32(delegate, widget);
42 InputMethod* CreateInputMethod(internal::InputMethodDelegate* delegate,
43 gfx::AcceleratedWidget widget) {
44 if (g_input_method_set_for_testing)
45 return new MockInputMethod(delegate);
46 #if defined(OS_CHROMEOS) && defined(USE_X11)
47 return new InputMethodIBus(delegate);
49 return CreateInputMethodWinInternal(delegate, widget);
50 #elif defined(USE_AURA) && defined(USE_X11)
51 return new InputMethodLinuxX11(delegate);
53 return new FakeInputMethod(delegate);
57 void SetUpInputMethodFactoryForTesting() {
58 g_input_method_set_for_testing = true;
61 InputMethod* GetSharedInputMethod() {
63 if (!g_shared_input_method)
64 g_shared_input_method = CreateInputMethod(NULL, NULL);
68 return g_shared_input_method;
73 void DestroySharedInputMethod() {
74 delete g_shared_input_method;
75 g_shared_input_method = NULL;
78 } // namespace internal