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/mock_input_method.h"
9 #if defined(OS_CHROMEOS)
10 #include "ui/base/ime/input_method_chromeos.h"
12 #include "base/win/metro.h"
13 #include "ui/base/ime/input_method_win.h"
14 #include "ui/base/ime/remote_input_method_win.h"
15 #elif defined(OS_MACOSX)
16 #include "ui/base/ime/input_method_mac.h"
17 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) && \
19 #include "ui/base/ime/input_method_auralinux.h"
21 #include "ui/base/ime/input_method_minimal.h"
26 ui::InputMethod
* g_input_method_for_testing
= nullptr;
28 bool g_input_method_set_for_testing
= false;
30 bool g_create_input_method_called
= false;
36 scoped_ptr
<InputMethod
> CreateInputMethod(
37 internal::InputMethodDelegate
* delegate
,
38 gfx::AcceleratedWidget widget
) {
39 if (!g_create_input_method_called
)
40 g_create_input_method_called
= true;
42 if (g_input_method_for_testing
) {
43 ui::InputMethod
* ret
= g_input_method_for_testing
;
44 g_input_method_for_testing
= nullptr;
45 return make_scoped_ptr(ret
);
48 if (g_input_method_set_for_testing
)
49 return make_scoped_ptr(new MockInputMethod(delegate
));
51 #if defined(OS_CHROMEOS)
52 return make_scoped_ptr(new InputMethodChromeOS(delegate
));
54 if (IsRemoteInputMethodWinRequired(widget
))
55 return CreateRemoteInputMethodWin(delegate
);
56 return make_scoped_ptr(new InputMethodWin(delegate
, widget
));
57 #elif defined(OS_MACOSX)
58 return make_scoped_ptr(new InputMethodMac(delegate
));
59 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) && \
61 return make_scoped_ptr(new InputMethodAuraLinux(delegate
));
63 return make_scoped_ptr(new InputMethodMinimal(delegate
));
67 void SetUpInputMethodFactoryForTesting() {
68 if (g_input_method_set_for_testing
)
71 CHECK(!g_create_input_method_called
)
72 << "ui::SetUpInputMethodFactoryForTesting was called after use of "
73 << "ui::CreateInputMethod. You must call "
74 << "ui::SetUpInputMethodFactoryForTesting earlier.";
76 g_input_method_set_for_testing
= true;
79 void SetUpInputMethodForTesting(InputMethod
* input_method
) {
80 g_input_method_for_testing
= input_method
;