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 "base/memory/singleton.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 #include "ui/base/ime/remote_input_method_win.h"
17 #elif defined(USE_AURA) && defined(USE_X11)
18 #include "ui/base/ime/input_method_auralinux.h"
20 #include "ui/base/ime/input_method_minimal.h"
25 ui::InputMethodFactory
* g_input_method_factory
= NULL
;
28 ui::InputMethod
* g_shared_input_method
= NULL
;
36 InputMethodFactory
* InputMethodFactory::GetInstance() {
37 if (!g_input_method_factory
)
38 SetInstance(DefaultInputMethodFactory::GetInstance());
40 return g_input_method_factory
;
44 void InputMethodFactory::SetInstance(InputMethodFactory
* instance
) {
45 g_input_method_factory
= instance
;
48 // DefaultInputMethodFactory
51 DefaultInputMethodFactory
* DefaultInputMethodFactory::GetInstance() {
52 return Singleton
<DefaultInputMethodFactory
>::get();
55 scoped_ptr
<InputMethod
> DefaultInputMethodFactory::CreateInputMethod(
56 internal::InputMethodDelegate
* delegate
,
57 gfx::AcceleratedWidget widget
) {
58 #if defined(OS_CHROMEOS) && defined(USE_X11)
59 return scoped_ptr
<InputMethod
>(new InputMethodIBus(delegate
));
61 if (base::win::IsTSFAwareRequired())
62 return scoped_ptr
<InputMethod
>(new InputMethodTSF(delegate
, widget
));
63 if (IsRemoteInputMethodWinRequired(widget
))
64 return CreateRemoteInputMethodWin(delegate
);
65 return scoped_ptr
<InputMethod
>(new InputMethodIMM32(delegate
, widget
));
66 #elif defined(USE_AURA) && defined(USE_X11)
67 return scoped_ptr
<InputMethod
>(new InputMethodAuraLinux(delegate
));
69 return scoped_ptr
<InputMethod
>(new InputMethodMinimal(delegate
));
73 // MockInputMethodFactory
76 MockInputMethodFactory
* MockInputMethodFactory::GetInstance() {
77 return Singleton
<MockInputMethodFactory
>::get();
80 scoped_ptr
<InputMethod
> MockInputMethodFactory::CreateInputMethod(
81 internal::InputMethodDelegate
* delegate
,
82 gfx::AcceleratedWidget
/* widget */) {
83 return scoped_ptr
<InputMethod
>(new MockInputMethod(delegate
));
88 scoped_ptr
<InputMethod
> CreateInputMethod(
89 internal::InputMethodDelegate
* delegate
,
90 gfx::AcceleratedWidget widget
) {
91 return InputMethodFactory::GetInstance()->CreateInputMethod(delegate
, widget
);
94 void SetUpInputMethodFactoryForTesting() {
95 InputMethodFactory::SetInstance(MockInputMethodFactory::GetInstance());
99 InputMethod
* GetSharedInputMethod() {
100 if (!g_shared_input_method
)
101 g_shared_input_method
= CreateInputMethod(NULL
, NULL
).release();
102 return g_shared_input_method
;
107 void DestroySharedInputMethod() {
108 delete g_shared_input_method
;
109 g_shared_input_method
= NULL
;
112 } // namespace internal