summaryrefslogtreecommitdiffstats
path: root/ui/base/ime/input_method_factory.cc
blob: 018823f1634b46662ad46caed20cb376bd30167b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/base/ime/input_method_factory.h"

#include "ui/base/ime/input_method_delegate.h"
#include "ui/base/ime/mock_input_method.h"

#if defined(OS_CHROMEOS) && defined(USE_X11)
#include "ui/base/ime/input_method_ibus.h"
#elif defined(OS_WIN)
#include "base/win/metro.h"
#include "ui/base/ime/input_method_imm32.h"
#include "ui/base/ime/input_method_tsf.h"
#else
#include "ui/base/ime/fake_input_method.h"
#endif

namespace ui {
namespace {

bool g_input_method_set_for_testing = false;
InputMethod* g_shared_input_method = NULL;

#if defined(OS_WIN)
// Returns a new instance of input method object for IMM32 or TSF.
InputMethod* CreateInputMethodWinInternal(
    internal::InputMethodDelegate* delegate,
    gfx::AcceleratedWidget widget) {
  if (base::win::IsTSFAwareRequired())
    return new InputMethodTSF(delegate, widget);
  else
    return new InputMethodIMM32(delegate, widget);
}
#endif

}  // namespace

InputMethod* CreateInputMethod(internal::InputMethodDelegate* delegate,
                               gfx::AcceleratedWidget widget) {
  if (g_input_method_set_for_testing)
    return new MockInputMethod(delegate);
#if defined(OS_CHROMEOS) && defined(USE_X11)
  return new InputMethodIBus(delegate);
#elif defined(OS_WIN)
  return CreateInputMethodWinInternal(delegate, widget);
#else
  return new FakeInputMethod(delegate);
#endif
}

void SetUpInputMethodFactoryForTesting() {
  g_input_method_set_for_testing = true;
}

InputMethod* GetSharedInputMethod() {
#if defined(OS_WIN)
  if (!g_shared_input_method)
    g_shared_input_method = CreateInputMethod(NULL, NULL);
#else
  NOTREACHED();
#endif
  return g_shared_input_method;
}

namespace internal {

void DestroySharedInputMethod() {
  delete g_shared_input_method;
  g_shared_input_method = NULL;
}

}  // namespace internal
}  // namespace ui