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#else
17#include "ui/base/ime/fake_input_method.h"
18#endif
19
20namespace ui {
21namespace {
22
23bool g_input_method_set_for_testing = false;
24InputMethod* g_shared_input_method = NULL;
25
26#if defined(OS_WIN)
27// Returns a new instance of input method object for IMM32 or TSF.
28InputMethod* CreateInputMethodWinInternal(
29    internal::InputMethodDelegate* delegate,
30    gfx::AcceleratedWidget widget) {
31  if (base::win::IsTSFAwareRequired())
32    return new InputMethodTSF(delegate, widget);
33  else
34    return new InputMethodIMM32(delegate, widget);
35}
36#endif
37
38}  // namespace
39
40InputMethod* CreateInputMethod(internal::InputMethodDelegate* delegate,
41                               gfx::AcceleratedWidget widget) {
42  if (g_input_method_set_for_testing)
43    return new MockInputMethod(delegate);
44#if defined(OS_CHROMEOS) && defined(USE_X11)
45  return new InputMethodIBus(delegate);
46#elif defined(OS_WIN)
47  return CreateInputMethodWinInternal(delegate, widget);
48#else
49  return new FakeInputMethod(delegate);
50#endif
51}
52
53void SetUpInputMethodFactoryForTesting() {
54  g_input_method_set_for_testing = true;
55}
56
57InputMethod* GetSharedInputMethod() {
58#if defined(OS_WIN)
59  if (!g_shared_input_method)
60    g_shared_input_method = CreateInputMethod(NULL, NULL);
61#else
62  NOTREACHED();
63#endif
64  return g_shared_input_method;
65}
66
67namespace internal {
68
69void DestroySharedInputMethod() {
70  delete g_shared_input_method;
71  g_shared_input_method = NULL;
72}
73
74}  // namespace internal
75}  // namespace ui
76