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

Side by Side Diff: chrome/browser/chromeos/input_method/ibus_controller.cc

Issue 9701095: cleanup: Split ibus_controller.h into 5 headers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 8 years, 9 months 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 | Annotate | Revision Log
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 "chrome/browser/chromeos/input_method/ibus_controller.h" 5 #include "chrome/browser/chromeos/input_method/ibus_controller.h"
6 6
7 #if defined(HAVE_IBUS) 7 #if defined(HAVE_IBUS)
8 #include <ibus.h> 8 #include <ibus.h>
9 #endif 9 #endif
10 10
11 #include <algorithm> // for std::reverse. 11 #include <algorithm> // for std::reverse.
12 #include <cstdio> 12 #include <cstdio>
13 #include <cstring> // for std::strcmp. 13 #include <cstring> // for std::strcmp.
14 #include <set> 14 #include <set>
15 #include <sstream> 15 #include <sstream>
16 #include <stack> 16 #include <stack>
17 #include <utility> 17 #include <utility>
18 18
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/observer_list.h" 20 #include "base/observer_list.h"
21 #include "chrome/browser/chromeos/input_method/ibus_input_methods.h" 21 #include "chrome/browser/chromeos/input_method/ibus_input_methods.h"
22 #include "chrome/browser/chromeos/input_method/input_method_engine.h" 22 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
23 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 23 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
24 #include "chrome/browser/chromeos/input_method/input_method_util.h" 24 #include "chrome/browser/chromeos/input_method/input_method_util.h"
25 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h"
25 26
26 namespace chromeos { 27 namespace chromeos {
27 namespace input_method { 28 namespace input_method {
28 29
29 namespace {
30
31 const char kFallbackLayout[] = "us";
32
33 InputMethodDescriptors* GetSupportedInputMethodsInternal(
34 const InputMethodWhitelist& whitelist) {
35 InputMethodDescriptors* input_methods = new InputMethodDescriptors;
36 input_methods->reserve(arraysize(kIBusEngines));
37 for (size_t i = 0; i < arraysize(kIBusEngines); ++i) {
38 input_methods->push_back(InputMethodDescriptor(
39 whitelist,
40 kIBusEngines[i].input_method_id,
41 "",
42 kIBusEngines[i].xkb_layout_id,
43 kIBusEngines[i].language_code));
44 }
45 return input_methods;
46 }
47
48 } // namespace
49
50 class InputMethodWhitelist {
51 public:
52 InputMethodWhitelist() {
53 for (size_t i = 0; i < arraysize(kIBusEngines); ++i) {
54 supported_input_methods_.insert(kIBusEngines[i].input_method_id);
55 }
56 for (size_t i = 0; i < arraysize(kIBusEngines); ++i) {
57 supported_layouts_.insert(kIBusEngines[i].xkb_layout_id);
58 }
59 }
60
61 // Returns true if |input_method_id| is whitelisted.
62 bool InputMethodIdIsWhitelisted(const std::string& input_method_id) const {
63 return (supported_input_methods_.count(input_method_id) > 0);
64 }
65
66 // Returns true if |xkb_layout| is supported.
67 bool XkbLayoutIsSupported(const std::string& xkb_layout) const {
68 return (supported_layouts_.count(xkb_layout) > 0);
69 }
70
71 private:
72 std::set<std::string> supported_input_methods_;
73 std::set<std::string> supported_layouts_;
74
75 DISALLOW_COPY_AND_ASSIGN(InputMethodWhitelist);
76 };
77
78 InputMethodDescriptor::InputMethodDescriptor(
79 const InputMethodWhitelist& whitelist,
80 const std::string& id,
81 const std::string& name,
82 const std::string& raw_layout,
83 const std::string& language_code)
84 : id_(id),
85 name_(name),
86 language_code_(language_code) {
87 keyboard_layout_ = kFallbackLayout;
88 base::SplitString(raw_layout, ',', &virtual_keyboard_layouts_);
89
90 // Find a valid XKB layout name from the comma-separated list, |raw_layout|.
91 // Only the first acceptable XKB layout name in the list is used as the
92 // |keyboard_layout| value of the InputMethodDescriptor object to be created
93 for (size_t i = 0; i < virtual_keyboard_layouts_.size(); ++i) {
94 if (whitelist.XkbLayoutIsSupported(virtual_keyboard_layouts_[i])) {
95 keyboard_layout_ = virtual_keyboard_layouts_[i];
96 DCHECK(keyboard_layout_.find(",") == std::string::npos);
97 break;
98 }
99 }
100 }
101
102 InputMethodDescriptor::InputMethodDescriptor() {
103 }
104
105 InputMethodDescriptor::~InputMethodDescriptor() {
106 }
107
108 InputMethodDescriptor::InputMethodDescriptor(
109 const std::string& in_id,
110 const std::string& in_name,
111 const std::string& in_keyboard_layout,
112 const std::string& in_virtual_keyboard_layouts,
113 const std::string& in_language_code)
114 : id_(in_id),
115 name_(in_name),
116 keyboard_layout_(in_keyboard_layout),
117 language_code_(in_language_code) {
118 DCHECK(keyboard_layout_.find(",") == std::string::npos);
119 base::SplitString(
120 in_virtual_keyboard_layouts, ',', &virtual_keyboard_layouts_);
121 }
122
123 // static
124 InputMethodDescriptor
125 InputMethodDescriptor::GetFallbackInputMethodDescriptor() {
126 return InputMethodDescriptor(
127 "xkb:us::eng", "", kFallbackLayout, kFallbackLayout, "en-US");
128 }
129
130 std::string InputMethodDescriptor::ToString() const {
131 std::stringstream stream;
132 stream << "id=" << id()
133 << ", name=" << name()
134 << ", keyboard_layout=" << keyboard_layout()
135 << ", virtual_keyboard_layouts=" << virtual_keyboard_layouts_.size()
136 << ", language_code=" << language_code();
137 return stream.str();
138 }
139
140 InputMethodProperty::InputMethodProperty(const std::string& in_key,
141 const std::string& in_label,
142 bool in_is_selection_item,
143 bool in_is_selection_item_checked,
144 int in_selection_item_id)
145 : key(in_key),
146 label(in_label),
147 is_selection_item(in_is_selection_item),
148 is_selection_item_checked(in_is_selection_item_checked),
149 selection_item_id(in_selection_item_id) {
150 DCHECK(!key.empty());
151 }
152
153 InputMethodProperty::InputMethodProperty()
154 : is_selection_item(false),
155 is_selection_item_checked(false),
156 selection_item_id(kInvalidSelectionItemId) {
157 }
158
159 InputMethodProperty::~InputMethodProperty() {
160 }
161
162 std::string InputMethodProperty::ToString() const {
163 std::stringstream stream;
164 stream << "key=" << key
165 << ", label=" << label
166 << ", is_selection_item=" << is_selection_item
167 << ", is_selection_item_checked=" << is_selection_item_checked
168 << ", selection_item_id=" << selection_item_id;
169 return stream.str();
170 }
171
172 InputMethodConfigValue::InputMethodConfigValue()
173 : type(kValueTypeString),
174 int_value(0),
175 bool_value(false) {
176 }
177
178 InputMethodConfigValue::~InputMethodConfigValue() {
179 }
180
181 std::string InputMethodConfigValue::ToString() const {
182 std::stringstream stream;
183 stream << "type=" << type;
184 switch (type) {
185 case kValueTypeString:
186 stream << ", string_value=" << string_value;
187 break;
188 case kValueTypeInt:
189 stream << ", int_value=" << int_value;
190 break;
191 case kValueTypeBool:
192 stream << ", bool_value=" << (bool_value ? "true" : "false");
193 break;
194 case kValueTypeStringList:
195 stream << ", string_list_value=";
196 for (size_t i = 0; i < string_list_value.size(); ++i) {
197 if (i) {
198 stream << ",";
199 }
200 stream << string_list_value[i];
201 }
202 break;
203 }
204 return stream.str();
205 }
206
207 #if defined(HAVE_IBUS) 30 #if defined(HAVE_IBUS)
208 const char kPanelObjectKey[] = "panel-object"; 31 const char kPanelObjectKey[] = "panel-object";
209 32
210 namespace { 33 namespace {
211 34
212 // Also defined in chrome/browser/chromeos/language_preferences.h (Chrome tree). 35 // Also defined in chrome/browser/chromeos/language_preferences.h (Chrome tree).
213 const char kGeneralSectionName[] = "general"; 36 const char kGeneralSectionName[] = "general";
214 const char kPreloadEnginesConfigName[] = "preload_engines"; 37 const char kPreloadEnginesConfigName[] = "preload_engines";
215 38
216 // The list of input method property keys that we don't handle. 39 // The list of input method property keys that we don't handle.
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 615
793 virtual InputMethodDescriptor CreateInputMethodDescriptor( 616 virtual InputMethodDescriptor CreateInputMethodDescriptor(
794 const std::string& id, 617 const std::string& id,
795 const std::string& name, 618 const std::string& name,
796 const std::string& raw_layout, 619 const std::string& raw_layout,
797 const std::string& language_code) { 620 const std::string& language_code) {
798 return InputMethodDescriptor(whitelist_, id, name, raw_layout, 621 return InputMethodDescriptor(whitelist_, id, name, raw_layout,
799 language_code); 622 language_code);
800 } 623 }
801 624
802 virtual InputMethodDescriptors* GetSupportedInputMethods() {
803 return GetSupportedInputMethodsInternal(whitelist_);
804 }
805
806 // IBusController override. 625 // IBusController override.
807 virtual void AddObserver(Observer* observer) { 626 virtual void AddObserver(Observer* observer) {
808 observers_.AddObserver(observer); 627 observers_.AddObserver(observer);
809 } 628 }
810 629
811 // IBusController override. 630 // IBusController override.
812 virtual void RemoveObserver(Observer* observer) { 631 virtual void RemoveObserver(Observer* observer) {
813 observers_.RemoveObserver(observer); 632 observers_.RemoveObserver(observer);
814 } 633 }
815 634
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 // See the comment above. We have to keep the implementation the same as 1181 // See the comment above. We have to keep the implementation the same as
1363 // IBusControllerImpl. 1182 // IBusControllerImpl.
1364 virtual InputMethodDescriptor CreateInputMethodDescriptor( 1183 virtual InputMethodDescriptor CreateInputMethodDescriptor(
1365 const std::string& id, 1184 const std::string& id,
1366 const std::string& name, 1185 const std::string& name,
1367 const std::string& raw_layout, 1186 const std::string& raw_layout,
1368 const std::string& language_code) { 1187 const std::string& language_code) {
1369 return InputMethodDescriptor(whitelist_, id, name, raw_layout, 1188 return InputMethodDescriptor(whitelist_, id, name, raw_layout,
1370 language_code); 1189 language_code);
1371 } 1190 }
1372 // See the comment above. We have to keep the implementation the same as
1373 // IBusControllerImpl.
1374 virtual InputMethodDescriptors* GetSupportedInputMethods() {
1375 return GetSupportedInputMethodsInternal(whitelist_);
1376 }
1377 1191
1378 private: 1192 private:
1379 InputMethodWhitelist whitelist_; 1193 InputMethodWhitelist whitelist_;
1380 1194
1381 DISALLOW_COPY_AND_ASSIGN(IBusControllerStubImpl); 1195 DISALLOW_COPY_AND_ASSIGN(IBusControllerStubImpl);
1382 }; 1196 };
1383 1197
1384 IBusController* IBusController::Create() { 1198 IBusController* IBusController::Create() {
1385 #if defined(HAVE_IBUS) 1199 #if defined(HAVE_IBUS)
1386 return new IBusControllerImpl; 1200 return new IBusControllerImpl;
1387 #else 1201 #else
1388 return new IBusControllerStubImpl; 1202 return new IBusControllerStubImpl;
1389 #endif 1203 #endif
1390 } 1204 }
1391 1205
1392 IBusController::~IBusController() { 1206 IBusController::~IBusController() {
1393 } 1207 }
1394 1208
1395 } // namespace input_method 1209 } // namespace input_method
1396 } // namespace chromeos 1210 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698