Clean-up: Retires ui::InputMethodFactory.
[chromium-blink-merge.git] / ui / base / ime / input_method_factory.cc
blob0f000f6387c00d098ba35d3133cbb93e9d2eae2d
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) && defined(USE_X11)
10 #include "ui/base/ime/input_method_ibus.h"
11 #elif defined(OS_WIN)
12 #include "base/win/metro.h"
13 #include "ui/base/ime/input_method_imm32.h"
14 #include "ui/base/ime/input_method_tsf.h"
15 #include "ui/base/ime/remote_input_method_win.h"
16 #elif defined(USE_AURA) && defined(OS_LINUX)
17 #include "ui/base/ime/input_method_auralinux.h"
18 #else
19 #include "ui/base/ime/input_method_minimal.h"
20 #endif
22 namespace {
24 bool g_input_method_set_for_testing = false;
26 bool g_create_input_method_called = false;
28 #if defined(OS_WIN)
29 ui::InputMethod* g_shared_input_method = NULL;
30 #endif
32 } // namespace
34 namespace ui {
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_set_for_testing)
43 return scoped_ptr<InputMethod>(new MockInputMethod(delegate));
45 #if defined(OS_CHROMEOS) && defined(USE_X11)
46 return scoped_ptr<InputMethod>(new InputMethodIBus(delegate));
47 #elif defined(OS_WIN)
48 if (base::win::IsTSFAwareRequired())
49 return scoped_ptr<InputMethod>(new InputMethodTSF(delegate, widget));
50 if (IsRemoteInputMethodWinRequired(widget))
51 return CreateRemoteInputMethodWin(delegate);
52 return scoped_ptr<InputMethod>(new InputMethodIMM32(delegate, widget));
53 #elif defined(USE_AURA) && defined(OS_LINUX)
54 return scoped_ptr<InputMethod>(new InputMethodAuraLinux(delegate));
55 #else
56 return scoped_ptr<InputMethod>(new InputMethodMinimal(delegate));
57 #endif
60 void SetUpInputMethodFactoryForTesting() {
61 CHECK(!g_create_input_method_called)
62 << "ui::SetUpInputMethodFactoryForTesting was called after use of "
63 << "ui::CreateInputMethod. You must call "
64 << "ui::SetUpInputMethodFactoryForTesting earlier.";
66 g_input_method_set_for_testing = true;
69 #if defined(OS_WIN)
70 InputMethod* GetSharedInputMethod() {
71 if (!g_shared_input_method)
72 g_shared_input_method = CreateInputMethod(NULL, NULL).release();
73 return g_shared_input_method;
76 namespace internal {
78 void DestroySharedInputMethod() {
79 delete g_shared_input_method;
80 g_shared_input_method = NULL;
83 } // namespace internal
84 #endif
86 } // namespace ui