Rename input_method_linux_x11 as input_method_auralinux.
[chromium-blink-merge.git] / ui / base / ime / input_method_factory.cc
blob11dfb7efab46fffcdfc8715d2e35697f388e37d3
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"
12 #elif defined(OS_WIN)
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"
19 #else
20 #include "ui/base/ime/input_method_minimal.h"
21 #endif
23 namespace {
25 ui::InputMethodFactory* g_input_method_factory = NULL;
27 #if defined(OS_WIN)
28 ui::InputMethod* g_shared_input_method = NULL;
29 #endif
31 } // namespace
33 namespace ui {
35 // static
36 InputMethodFactory* InputMethodFactory::GetInstance() {
37 if (!g_input_method_factory)
38 SetInstance(DefaultInputMethodFactory::GetInstance());
40 return g_input_method_factory;
43 // static
44 void InputMethodFactory::SetInstance(InputMethodFactory* instance) {
45 g_input_method_factory = instance;
48 // DefaultInputMethodFactory
50 // static
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));
60 #elif defined(OS_WIN)
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));
68 #else
69 return scoped_ptr<InputMethod>(new InputMethodMinimal(delegate));
70 #endif
73 // MockInputMethodFactory
75 // static
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));
86 // Shorthands
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());
98 #if defined(OS_WIN)
99 InputMethod* GetSharedInputMethod() {
100 if (!g_shared_input_method)
101 g_shared_input_method = CreateInputMethod(NULL, NULL).release();
102 return g_shared_input_method;
105 namespace internal {
107 void DestroySharedInputMethod() {
108 delete g_shared_input_method;
109 g_shared_input_method = NULL;
112 } // namespace internal
113 #endif
115 } // namespace ui