| OLD | NEW |
| 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/memory/ptr_util.h" |
| 7 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 8 #include "ui/base/ime/mock_input_method.h" | 9 #include "ui/base/ime/mock_input_method.h" |
| 9 | 10 |
| 10 #if defined(OS_CHROMEOS) | 11 #if defined(OS_CHROMEOS) |
| 11 #include "ui/base/ime/input_method_chromeos.h" | 12 #include "ui/base/ime/input_method_chromeos.h" |
| 12 #elif defined(OS_WIN) | 13 #elif defined(OS_WIN) |
| 13 #include "ui/base/ime/input_method_win.h" | 14 #include "ui/base/ime/input_method_win.h" |
| 14 #elif defined(OS_MACOSX) | 15 #elif defined(OS_MACOSX) |
| 15 #include "ui/base/ime/input_method_mac.h" | 16 #include "ui/base/ime/input_method_mac.h" |
| 16 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) && \ | 17 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) && \ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 ui::InputMethod* g_input_method_for_testing = nullptr; | 28 ui::InputMethod* g_input_method_for_testing = nullptr; |
| 28 | 29 |
| 29 bool g_input_method_set_for_testing = false; | 30 bool g_input_method_set_for_testing = false; |
| 30 | 31 |
| 31 bool g_create_input_method_called = false; | 32 bool g_create_input_method_called = false; |
| 32 | 33 |
| 33 } // namespace | 34 } // namespace |
| 34 | 35 |
| 35 namespace ui { | 36 namespace ui { |
| 36 | 37 |
| 37 scoped_ptr<InputMethod> CreateInputMethod( | 38 std::unique_ptr<InputMethod> CreateInputMethod( |
| 38 internal::InputMethodDelegate* delegate, | 39 internal::InputMethodDelegate* delegate, |
| 39 gfx::AcceleratedWidget widget) { | 40 gfx::AcceleratedWidget widget) { |
| 40 if (!g_create_input_method_called) | 41 if (!g_create_input_method_called) |
| 41 g_create_input_method_called = true; | 42 g_create_input_method_called = true; |
| 42 | 43 |
| 43 if (g_input_method_for_testing) { | 44 if (g_input_method_for_testing) { |
| 44 ui::InputMethod* ret = g_input_method_for_testing; | 45 ui::InputMethod* ret = g_input_method_for_testing; |
| 45 g_input_method_for_testing = nullptr; | 46 g_input_method_for_testing = nullptr; |
| 46 return make_scoped_ptr(ret); | 47 return base::WrapUnique(ret); |
| 47 } | 48 } |
| 48 | 49 |
| 49 if (g_input_method_set_for_testing) | 50 if (g_input_method_set_for_testing) |
| 50 return make_scoped_ptr(new MockInputMethod(delegate)); | 51 return base::WrapUnique(new MockInputMethod(delegate)); |
| 51 | 52 |
| 52 #if defined(OS_CHROMEOS) | 53 #if defined(OS_CHROMEOS) |
| 53 return make_scoped_ptr(new InputMethodChromeOS(delegate)); | 54 return base::WrapUnique(new InputMethodChromeOS(delegate)); |
| 54 #elif defined(OS_WIN) | 55 #elif defined(OS_WIN) |
| 55 return make_scoped_ptr(new InputMethodWin(delegate, widget)); | 56 return base::WrapUnique(new InputMethodWin(delegate, widget)); |
| 56 #elif defined(OS_MACOSX) | 57 #elif defined(OS_MACOSX) |
| 57 return make_scoped_ptr(new InputMethodMac(delegate)); | 58 return base::WrapUnique(new InputMethodMac(delegate)); |
| 58 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) && \ | 59 #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) && \ |
| 59 !defined(OS_CHROMEOS) | 60 !defined(OS_CHROMEOS) |
| 60 return make_scoped_ptr(new InputMethodAuraLinux(delegate)); | 61 return base::WrapUnique(new InputMethodAuraLinux(delegate)); |
| 61 #elif defined(OS_ANDROID) | 62 #elif defined(OS_ANDROID) |
| 62 return make_scoped_ptr(new InputMethodAndroid(delegate)); | 63 return base::WrapUnique(new InputMethodAndroid(delegate)); |
| 63 #else | 64 #else |
| 64 return make_scoped_ptr(new InputMethodMinimal(delegate)); | 65 return base::WrapUnique(new InputMethodMinimal(delegate)); |
| 65 #endif | 66 #endif |
| 66 } | 67 } |
| 67 | 68 |
| 68 void SetUpInputMethodFactoryForTesting() { | 69 void SetUpInputMethodFactoryForTesting() { |
| 69 if (g_input_method_set_for_testing) | 70 if (g_input_method_set_for_testing) |
| 70 return; | 71 return; |
| 71 | 72 |
| 72 CHECK(!g_create_input_method_called) | 73 CHECK(!g_create_input_method_called) |
| 73 << "ui::SetUpInputMethodFactoryForTesting was called after use of " | 74 << "ui::SetUpInputMethodFactoryForTesting was called after use of " |
| 74 << "ui::CreateInputMethod. You must call " | 75 << "ui::CreateInputMethod. You must call " |
| 75 << "ui::SetUpInputMethodFactoryForTesting earlier."; | 76 << "ui::SetUpInputMethodFactoryForTesting earlier."; |
| 76 | 77 |
| 77 g_input_method_set_for_testing = true; | 78 g_input_method_set_for_testing = true; |
| 78 } | 79 } |
| 79 | 80 |
| 80 void SetUpInputMethodForTesting(InputMethod* input_method) { | 81 void SetUpInputMethodForTesting(InputMethod* input_method) { |
| 81 g_input_method_for_testing = input_method; | 82 g_input_method_for_testing = input_method; |
| 82 } | 83 } |
| 83 | 84 |
| 84 } // namespace ui | 85 } // namespace ui |
| OLD | NEW |