Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: ui/base/ime/input_method_factory.cc

Issue 1991953002: Implement a runtime headless mode for Linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/ime/input_method_factory.h" 5 #include "ui/base/ime/input_method_factory.h"
6 6
7 #include "base/command_line.h"
7 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
8 #include "build/build_config.h" 9 #include "build/build_config.h"
9 #include "ui/base/ime/mock_input_method.h" 10 #include "ui/base/ime/mock_input_method.h"
11 #include "ui/gfx/switches.h"
10 12
11 #if defined(OS_CHROMEOS) 13 #if defined(OS_CHROMEOS)
12 #include "ui/base/ime/input_method_chromeos.h" 14 #include "ui/base/ime/input_method_chromeos.h"
13 #elif defined(OS_WIN) 15 #elif defined(OS_WIN)
14 #include "ui/base/ime/input_method_win.h" 16 #include "ui/base/ime/input_method_win.h"
15 #elif defined(OS_MACOSX) 17 #elif defined(OS_MACOSX)
16 #include "ui/base/ime/input_method_mac.h" 18 #include "ui/base/ime/input_method_mac.h"
17 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) 19 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11)
18 #include "ui/base/ime/input_method_auralinux.h" 20 #include "ui/base/ime/input_method_auralinux.h"
19 #elif defined(OS_ANDROID) 21 #elif defined(OS_ANDROID)
20 #include "ui/base/ime/input_method_android.h" 22 #include "ui/base/ime/input_method_android.h"
21 #else 23 #else
22 #include "ui/base/ime/input_method_minimal.h" 24 #include "ui/base/ime/input_method_minimal.h"
23 #endif 25 #endif
24 26
25 namespace { 27 namespace {
26 28
27 ui::InputMethod* g_input_method_for_testing = nullptr; 29 ui::InputMethod* g_input_method_for_testing = nullptr;
28 30
29 bool g_input_method_set_for_testing = false; 31 bool g_input_method_set_for_testing = false;
30 32
31 bool g_create_input_method_called = false; 33 bool g_create_input_method_called = false;
32 34
33 } // namespace 35 } // namespace
34 36
35 namespace ui { 37 namespace ui {
38 namespace {
39
40 bool RunningInHeadlessMode() {
41 return base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless);
42 }
43
44 } // namespace
36 45
37 std::unique_ptr<InputMethod> CreateInputMethod( 46 std::unique_ptr<InputMethod> CreateInputMethod(
38 internal::InputMethodDelegate* delegate, 47 internal::InputMethodDelegate* delegate,
39 gfx::AcceleratedWidget widget) { 48 gfx::AcceleratedWidget widget) {
40 if (!g_create_input_method_called) 49 if (!g_create_input_method_called)
41 g_create_input_method_called = true; 50 g_create_input_method_called = true;
42 51
43 if (g_input_method_for_testing) { 52 if (g_input_method_for_testing) {
44 ui::InputMethod* ret = g_input_method_for_testing; 53 ui::InputMethod* ret = g_input_method_for_testing;
45 g_input_method_for_testing = nullptr; 54 g_input_method_for_testing = nullptr;
46 return base::WrapUnique(ret); 55 return base::WrapUnique(ret);
47 } 56 }
48 57
49 if (g_input_method_set_for_testing) 58 if (g_input_method_set_for_testing)
50 return base::MakeUnique<MockInputMethod>(delegate); 59 return base::MakeUnique<MockInputMethod>(delegate);
51 60
61 if (RunningInHeadlessMode())
62 return base::WrapUnique(new MockInputMethod(delegate));
63
52 #if defined(OS_CHROMEOS) 64 #if defined(OS_CHROMEOS)
53 return base::MakeUnique<InputMethodChromeOS>(delegate); 65 return base::MakeUnique<InputMethodChromeOS>(delegate);
54 #elif defined(OS_WIN) 66 #elif defined(OS_WIN)
55 return base::MakeUnique<InputMethodWin>(delegate, widget); 67 return base::MakeUnique<InputMethodWin>(delegate, widget);
56 #elif defined(OS_MACOSX) 68 #elif defined(OS_MACOSX)
57 return base::MakeUnique<InputMethodMac>(delegate); 69 return base::MakeUnique<InputMethodMac>(delegate);
58 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) 70 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11)
59 return base::MakeUnique<InputMethodAuraLinux>(delegate); 71 return base::MakeUnique<InputMethodAuraLinux>(delegate);
60 #elif defined(OS_ANDROID) 72 #elif defined(OS_ANDROID)
61 return base::MakeUnique<InputMethodAndroid>(delegate); 73 return base::MakeUnique<InputMethodAndroid>(delegate);
(...skipping 12 matching lines...) Expand all
74 << "ui::SetUpInputMethodFactoryForTesting earlier."; 86 << "ui::SetUpInputMethodFactoryForTesting earlier.";
75 87
76 g_input_method_set_for_testing = true; 88 g_input_method_set_for_testing = true;
77 } 89 }
78 90
79 void SetUpInputMethodForTesting(InputMethod* input_method) { 91 void SetUpInputMethodForTesting(InputMethod* input_method) {
80 g_input_method_for_testing = input_method; 92 g_input_method_for_testing = input_method;
81 } 93 }
82 94
83 } // namespace ui 95 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698