Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / base / ime / input_method_factory.cc
blobb4aa3cd9e4a3dc618d98f48bf6ebb225c25e06ba
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.
5 #include "ui/base/ime/input_method_factory.h"
7 #include "ui/base/ime/mock_input_method.h"
9 #if defined(OS_CHROMEOS)
10 #include "ui/base/ime/input_method_chromeos.h"
11 #elif defined(OS_WIN)
12 #include "base/win/metro.h"
13 #include "ui/base/ime/input_method_win.h"
14 #include "ui/base/ime/remote_input_method_win.h"
15 #elif defined(OS_MACOSX)
16 #include "ui/base/ime/input_method_mac.h"
17 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) && \
18 !defined(OS_CHROMEOS)
19 #include "ui/base/ime/input_method_auralinux.h"
20 #else
21 #include "ui/base/ime/input_method_minimal.h"
22 #endif
24 namespace {
26 ui::InputMethod* g_input_method_for_testing = nullptr;
28 bool g_input_method_set_for_testing = false;
30 bool g_create_input_method_called = false;
32 } // namespace
34 namespace ui {
36 scoped_ptr<InputMethod> CreateInputMethod(
37 internal::InputMethodDelegate* delegate,
38 gfx::AcceleratedWidget widget) {
39 if (!g_create_input_method_called)
40 g_create_input_method_called = true;
42 if (g_input_method_for_testing) {
43 ui::InputMethod* ret = g_input_method_for_testing;
44 g_input_method_for_testing = nullptr;
45 return make_scoped_ptr(ret);
48 if (g_input_method_set_for_testing)
49 return make_scoped_ptr(new MockInputMethod(delegate));
51 #if defined(OS_CHROMEOS)
52 return make_scoped_ptr(new InputMethodChromeOS(delegate));
53 #elif defined(OS_WIN)
54 if (IsRemoteInputMethodWinRequired(widget))
55 return CreateRemoteInputMethodWin(delegate);
56 return make_scoped_ptr(new InputMethodWin(delegate, widget));
57 #elif defined(OS_MACOSX)
58 return make_scoped_ptr(new InputMethodMac(delegate));
59 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) && \
60 !defined(OS_CHROMEOS)
61 return make_scoped_ptr(new InputMethodAuraLinux(delegate));
62 #else
63 return make_scoped_ptr(new InputMethodMinimal(delegate));
64 #endif
67 void SetUpInputMethodFactoryForTesting() {
68 if (g_input_method_set_for_testing)
69 return;
71 CHECK(!g_create_input_method_called)
72 << "ui::SetUpInputMethodFactoryForTesting was called after use of "
73 << "ui::CreateInputMethod. You must call "
74 << "ui::SetUpInputMethodFactoryForTesting earlier.";
76 g_input_method_set_for_testing = true;
79 void SetUpInputMethodForTesting(InputMethod* input_method) {
80 g_input_method_for_testing = input_method;
83 } // namespace ui