Upstream version 7.35.139.0
[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 "base/logging.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 #endif
29 }
30
31 void ShutdownInputMethod() {
32 #if defined(OS_CHROMEOS)
33   chromeos::IMEBridge::Shutdown();
34 #endif
35 }
36
37 void InitializeInputMethodForTesting() {
38 #if defined(OS_CHROMEOS)
39   chromeos::IMEBridge::Initialize();
40 #elif defined(USE_AURA) && defined(OS_LINUX) && !defined(USE_OZONE)
41   if (!g_linux_input_method_context_factory)
42     g_linux_input_method_context_factory = new FakeInputMethodContextFactory();
43   const LinuxInputMethodContextFactory* factory =
44       LinuxInputMethodContextFactory::instance();
45   CHECK(!factory || factory == g_linux_input_method_context_factory)
46       << "LinuxInputMethodContextFactory was already initialized somewhere "
47       << "else.";
48   LinuxInputMethodContextFactory::SetInstance(
49       g_linux_input_method_context_factory);
50 #endif
51 }
52
53 void ShutdownInputMethodForTesting() {
54 #if defined(OS_CHROMEOS)
55   chromeos::IMEBridge::Shutdown();
56 #elif defined(USE_AURA) && defined(OS_LINUX) && !defined(USE_OZONE)
57   const LinuxInputMethodContextFactory* factory =
58       LinuxInputMethodContextFactory::instance();
59   CHECK(!factory || factory == g_linux_input_method_context_factory)
60       << "An unknown LinuxInputMethodContextFactory was set.";
61   LinuxInputMethodContextFactory::SetInstance(NULL);
62   delete g_linux_input_method_context_factory;
63   g_linux_input_method_context_factory = NULL;
64 #endif
65 }
66
67 }  // namespace ui