507b51f708cfee030cf6376d291438c082c78405
[platform/framework/web/crosswalk.git] / src / ui / base / ime / input_method_initializer.cc
1 // Copyright 2013 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_initializer.h"
6
7 #if defined(OS_CHROMEOS)
8 #include "ui/base/ime/chromeos/ime_bridge.h"
9 #elif defined(USE_AURA) && defined(OS_LINUX) && !defined(USE_OZONE)
10 #include "ui/base/ime/input_method_auralinux.h"
11 #include "ui/base/ime/linux/fake_input_method_context_factory.h"
12 #endif
13
14 namespace {
15
16 #if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX) && \
17     !defined(USE_OZONE)
18 const ui::LinuxInputMethodContextFactory* g_linux_input_method_context_factory;
19 #endif
20
21 }  // namespace
22
23 namespace ui {
24
25 void InitializeInputMethod() {
26 #if defined(OS_CHROMEOS)
27   chromeos::IMEBridge::Initialize();
28 #elif defined(USE_AURA) && defined(OS_LINUX) && !defined(USE_OZONE)
29   InputMethodAuraLinux::Initialize();
30 #endif
31 }
32
33 void ShutdownInputMethod() {
34 #if defined(OS_CHROMEOS)
35   chromeos::IMEBridge::Shutdown();
36 #endif
37 }
38
39 void InitializeInputMethodForTesting() {
40 #if defined(OS_CHROMEOS)
41   chromeos::IMEBridge::Initialize();
42 #elif defined(USE_AURA) && defined(OS_LINUX) && !defined(USE_OZONE)
43   if (!g_linux_input_method_context_factory)
44     g_linux_input_method_context_factory = new FakeInputMethodContextFactory();
45   const LinuxInputMethodContextFactory* factory =
46       LinuxInputMethodContextFactory::instance();
47   CHECK(!factory || factory == g_linux_input_method_context_factory)
48       << "LinuxInputMethodContextFactory was already initialized somewhere "
49       << "else.";
50   LinuxInputMethodContextFactory::SetInstance(
51       g_linux_input_method_context_factory);
52 #endif
53 }
54
55 void ShutdownInputMethodForTesting() {
56 #if defined(OS_CHROMEOS)
57   chromeos::IMEBridge::Shutdown();
58 #elif defined(USE_AURA) && defined(OS_LINUX) && !defined(USE_OZONE)
59   const LinuxInputMethodContextFactory* factory =
60       LinuxInputMethodContextFactory::instance();
61   CHECK(!factory || factory == g_linux_input_method_context_factory)
62       << "An unknown LinuxInputMethodContextFactory was set.";
63   LinuxInputMethodContextFactory::SetInstance(NULL);
64   delete g_linux_input_method_context_factory;
65   g_linux_input_method_context_factory = NULL;
66 #endif
67 }
68
69 }  // namespace ui