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