Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "chrome/browser/chromeos/input_method/input_method_util.h" | |
| 10 | |
| 11 #if _LIBCPP_STD_VER > 11 | |
|
sky
2017/01/04 16:35:52
Why do you need this?
Azure Wei
2017/01/05 15:41:28
I thought this would would be needed by make_uniqu
| |
| 12 #include <memory> | |
| 13 #endif | |
| 14 | |
| 15 namespace chromeos { | |
| 16 namespace input_method { | |
| 17 | |
| 18 MockInputMethodManagerImpl::State::State(MockInputMethodManagerImpl* manager) | |
| 19 : manager_(manager) { | |
| 20 active_input_method_ids.push_back("xkb:us::eng"); | |
| 21 } | |
| 22 | |
| 23 MockInputMethodManagerImpl::State::~State() {} | |
| 24 | |
| 25 MockInputMethodManagerImpl::MockInputMethodManagerImpl() | |
| 26 : state_(new State(this)), | |
| 27 add_observer_count_(0), | |
| 28 remove_observer_count_(0), | |
| 29 util_(new InputMethodUtil(&delegate_)), | |
| 30 mod3_used_(false) {} | |
| 31 | |
| 32 MockInputMethodManagerImpl::~MockInputMethodManagerImpl() {} | |
| 33 | |
| 34 void MockInputMethodManagerImpl::AddObserver( | |
| 35 InputMethodManager::Observer* observer) { | |
| 36 ++add_observer_count_; | |
| 37 } | |
| 38 | |
| 39 void MockInputMethodManagerImpl::RemoveObserver( | |
| 40 InputMethodManager::Observer* observer) { | |
| 41 ++remove_observer_count_; | |
| 42 } | |
| 43 | |
| 44 std::unique_ptr<InputMethodDescriptors> | |
| 45 MockInputMethodManagerImpl::GetSupportedInputMethods() const { | |
| 46 std::unique_ptr<InputMethodDescriptors> result; | |
| 47 #if _LIBCPP_STD_VER > 11 | |
| 48 result = std::make_unique<InputMethodDescriptors>(); | |
| 49 #else | |
| 50 result.reset(new InputMethodDescriptors); | |
| 51 #endif | |
| 52 result->push_back(InputMethodUtil::GetFallbackInputMethodDescriptor()); | |
| 53 return result; | |
| 54 } | |
| 55 | |
| 56 std::unique_ptr<InputMethodDescriptors> | |
| 57 MockInputMethodManagerImpl::State::GetActiveInputMethods() const { | |
| 58 std::unique_ptr<InputMethodDescriptors> result; | |
| 59 #if _LIBCPP_STD_VER > 11 | |
| 60 result = std::make_unique<InputMethodDescriptors>(); | |
| 61 #else | |
| 62 result.reset(new InputMethodDescriptors); | |
| 63 #endif | |
| 64 result->push_back(InputMethodUtil::GetFallbackInputMethodDescriptor()); | |
| 65 return result; | |
| 66 } | |
| 67 | |
| 68 const InputMethodDescriptor* | |
| 69 MockInputMethodManagerImpl::State::GetInputMethodFromId( | |
| 70 const std::string& input_method_id) const { | |
| 71 static const InputMethodDescriptor defaultInputMethod = | |
| 72 InputMethodUtil::GetFallbackInputMethodDescriptor(); | |
| 73 for (size_t i = 0; i < active_input_method_ids.size(); i++) { | |
| 74 if (input_method_id == active_input_method_ids[i]) { | |
| 75 return &defaultInputMethod; | |
| 76 } | |
| 77 } | |
| 78 return nullptr; | |
| 79 } | |
| 80 | |
| 81 InputMethodDescriptor MockInputMethodManagerImpl::State::GetCurrentInputMethod() | |
| 82 const { | |
| 83 InputMethodDescriptor descriptor = | |
| 84 InputMethodUtil::GetFallbackInputMethodDescriptor(); | |
| 85 if (!current_input_method_id.empty()) { | |
| 86 return InputMethodDescriptor( | |
| 87 current_input_method_id, descriptor.name(), descriptor.indicator(), | |
| 88 descriptor.keyboard_layouts(), descriptor.language_codes(), true, | |
| 89 GURL(), // options page url. | |
| 90 GURL()); // input view page url. | |
| 91 } | |
| 92 return descriptor; | |
| 93 } | |
| 94 | |
| 95 bool MockInputMethodManagerImpl::IsISOLevel5ShiftUsedByCurrentInputMethod() | |
| 96 const { | |
| 97 return mod3_used_; | |
| 98 } | |
| 99 | |
| 100 ImeKeyboard* MockInputMethodManagerImpl::GetImeKeyboard() { | |
| 101 return &keyboard_; | |
| 102 } | |
| 103 | |
| 104 InputMethodUtil* MockInputMethodManagerImpl::GetInputMethodUtil() { | |
| 105 return util_.get(); | |
| 106 } | |
| 107 | |
| 108 ComponentExtensionIMEManager* | |
| 109 MockInputMethodManagerImpl::GetComponentExtensionIMEManager() { | |
| 110 return comp_ime_manager_.get(); | |
| 111 } | |
| 112 | |
| 113 void MockInputMethodManagerImpl::SetComponentExtensionIMEManager( | |
| 114 std::unique_ptr<ComponentExtensionIMEManager> comp_ime_manager) { | |
| 115 comp_ime_manager_ = std::move(comp_ime_manager); | |
| 116 } | |
| 117 | |
| 118 void MockInputMethodManagerImpl::set_application_locale( | |
| 119 const std::string& value) { | |
| 120 delegate_.set_active_locale(value); | |
| 121 } | |
| 122 | |
| 123 scoped_refptr<InputMethodManager::State> | |
| 124 MockInputMethodManagerImpl::CreateNewState(Profile* profile) { | |
| 125 NOTIMPLEMENTED(); | |
| 126 return state_; | |
| 127 } | |
| 128 | |
| 129 scoped_refptr<InputMethodManager::State> | |
| 130 MockInputMethodManagerImpl::GetActiveIMEState() { | |
| 131 return scoped_refptr<InputMethodManager::State>(state_.get()); | |
| 132 } | |
| 133 | |
| 134 scoped_refptr<InputMethodManager::State> | |
| 135 MockInputMethodManagerImpl::State::Clone() const { | |
| 136 NOTIMPLEMENTED(); | |
| 137 return manager_->GetActiveIMEState(); | |
| 138 } | |
| 139 | |
| 140 void MockInputMethodManagerImpl::SetState( | |
| 141 scoped_refptr<InputMethodManager::State> state) { | |
| 142 state_ = scoped_refptr<MockInputMethodManagerImpl::State>( | |
| 143 static_cast<MockInputMethodManagerImpl::State*>(state.get())); | |
| 144 } | |
| 145 | |
| 146 void MockInputMethodManagerImpl::SetCurrentInputMethodId( | |
| 147 const std::string& input_method_id) { | |
| 148 state_->current_input_method_id = input_method_id; | |
| 149 } | |
| 150 | |
| 151 } // namespace input_method | |
| 152 } // namespace chromeos | |
| OLD | NEW |