1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/logging.h"
#include "chromeos/ime/component_extension_ime_manager.h"
#include "chromeos/ime/extension_ime_util.h"
namespace chromeos {
ComponentExtensionIME::ComponentExtensionIME() {
}
ComponentExtensionIME::~ComponentExtensionIME() {
}
ComponentExtensionIMEManagerDelegate::ComponentExtensionIMEManagerDelegate() {
}
ComponentExtensionIMEManagerDelegate::~ComponentExtensionIMEManagerDelegate() {
}
ComponentExtensionIMEManager::ComponentExtensionIMEManager()
: is_initialized_(false) {
}
ComponentExtensionIMEManager::~ComponentExtensionIMEManager() {
}
void ComponentExtensionIMEManager::Initialize(
scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) {
delegate_ = delegate.Pass();
component_extension_imes_ = delegate_->ListIME();
is_initialized_ = true;
FOR_EACH_OBSERVER(Observer, observers_, OnInitialized());
}
bool ComponentExtensionIMEManager::IsInitialized() {
return is_initialized_;
}
bool ComponentExtensionIMEManager::LoadComponentExtensionIME(
const std::string& input_method_id) {
ComponentExtensionIME ime;
if (FindEngineEntry(input_method_id, &ime, NULL))
return delegate_->Load(ime.id, ime.manifest, ime.path);
else
return false;
}
bool ComponentExtensionIMEManager::UnloadComponentExtensionIME(
const std::string& input_method_id) {
ComponentExtensionIME ime;
if (FindEngineEntry(input_method_id, &ime, NULL))
return delegate_->Unload(ime.id, ime.path);
else
return false;
}
bool ComponentExtensionIMEManager::IsComponentExtensionIMEId(
const std::string& input_method_id) {
return FindEngineEntry(input_method_id, NULL, NULL);
}
std::string ComponentExtensionIMEManager::GetName(
const std::string& input_method_id) {
IBusComponent::EngineDescription engine;
if (!FindEngineEntry(input_method_id, NULL, &engine))
return "";
return engine.display_name;
}
std::string ComponentExtensionIMEManager::GetDescription(
const std::string& input_method_id) {
IBusComponent::EngineDescription engine;
if (!FindEngineEntry(input_method_id, NULL, &engine))
return "";
return engine.description;
}
std::vector<std::string> ComponentExtensionIMEManager::ListIMEByLanguage(
const std::string& language) {
std::vector<std::string> result;
for (size_t i = 0; i < component_extension_imes_.size(); ++i) {
for (size_t j = 0; j < component_extension_imes_[i].engines.size(); ++j) {
if (component_extension_imes_[i].engines[j].language_code == language)
result.push_back(
extension_ime_util::GetInputMethodID(
component_extension_imes_[i].id,
component_extension_imes_[i].engines[j].engine_id));
}
}
return result;
}
input_method::InputMethodDescriptors
ComponentExtensionIMEManager::GetAllIMEAsInputMethodDescriptor() {
input_method::InputMethodDescriptors result;
for (size_t i = 0; i < component_extension_imes_.size(); ++i) {
for (size_t j = 0; j < component_extension_imes_[i].engines.size(); ++j) {
result.push_back(
input_method::InputMethodDescriptor(
extension_ime_util::GetInputMethodID(
component_extension_imes_[i].id,
component_extension_imes_[i].engines[j].engine_id),
component_extension_imes_[i].engines[j].display_name,
component_extension_imes_[i].engines[j].layout,
component_extension_imes_[i].engines[j].language_code,
false));
}
}
return result;
}
void ComponentExtensionIMEManager::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void ComponentExtensionIMEManager::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
bool ComponentExtensionIMEManager::FindEngineEntry(
const std::string& input_method_id,
ComponentExtensionIME* out_extension,
IBusComponent::EngineDescription* out_engine) {
if (!extension_ime_util::IsExtensionIME(input_method_id))
return false;
for (size_t i = 0; i < component_extension_imes_.size(); ++i) {
const std::string extension_id = component_extension_imes_[i].id;
if (!extension_ime_util::IsMemberOfExtension(input_method_id, extension_id))
continue;
const std::vector<IBusComponent::EngineDescription>& engines =
component_extension_imes_[i].engines;
for (size_t j = 0; j < engines.size(); ++j) {
const std::string trial_ime_id =
extension_ime_util::GetInputMethodID(extension_id,
engines[j].engine_id);
if (trial_ime_id != input_method_id)
continue;
if (out_extension)
*out_extension = component_extension_imes_[i];
if (out_engine)
*out_engine = component_extension_imes_[i].engines[j];
return true;
}
}
return false;
}
} // namespace chromeos
|