- add sources.
[platform/framework/web/crosswalk.git] / src / ui / base / ime / input_method_factory.cc
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.
4
5 #include "ui/base/ime/input_method_factory.h"
6
7 #include "ui/base/ime/input_method_delegate.h"
8 #include "ui/base/ime/mock_input_method.h"
9
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 #elif defined(USE_AURA) && defined(USE_X11)
17 #include "ui/base/ime/input_method_linux_x11.h"
18 #else
19 #include "ui/base/ime/fake_input_method.h"
20 #endif
21
22 namespace ui {
23 namespace {
24
25 bool g_input_method_set_for_testing = false;
26 InputMethod* g_shared_input_method = NULL;
27
28 #if defined(OS_WIN)
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);
35   else
36     return new InputMethodIMM32(delegate, widget);
37 }
38 #endif
39
40 }  // namespace
41
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);
48 #elif defined(OS_WIN)
49   return CreateInputMethodWinInternal(delegate, widget);
50 #elif defined(USE_AURA) && defined(USE_X11)
51   return new InputMethodLinuxX11(delegate);
52 #else
53   return new FakeInputMethod(delegate);
54 #endif
55 }
56
57 void SetUpInputMethodFactoryForTesting() {
58   g_input_method_set_for_testing = true;
59 }
60
61 InputMethod* GetSharedInputMethod() {
62 #if defined(OS_WIN)
63   if (!g_shared_input_method)
64     g_shared_input_method = CreateInputMethod(NULL, NULL);
65 #else
66   NOTREACHED();
67 #endif
68   return g_shared_input_method;
69 }
70
71 namespace internal {
72
73 void DestroySharedInputMethod() {
74   delete g_shared_input_method;
75   g_shared_input_method = NULL;
76 }
77
78 }  // namespace internal
79 }  // namespace ui