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

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

Issue 11783053: Clean Up: Remove ibus namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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/input_method_engine_ibus.h" 5 #include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 27 matching lines...) Expand all
38 const uint32 kIBusShiftKeyMask = 1 << 0; 38 const uint32 kIBusShiftKeyMask = 1 << 0;
39 const uint32 kIBusKeyReleaseMask = 1 << 30; 39 const uint32 kIBusKeyReleaseMask = 1 << 30;
40 } 40 }
41 41
42 InputMethodEngineIBus::InputMethodEngineIBus() 42 InputMethodEngineIBus::InputMethodEngineIBus()
43 : focused_(false), 43 : focused_(false),
44 active_(false), 44 active_(false),
45 context_id_(0), 45 context_id_(0),
46 next_context_id_(1), 46 next_context_id_(1),
47 current_object_path_(0), 47 current_object_path_(0),
48 aux_text_(new ibus::IBusText()), 48 aux_text_(new IBusText()),
49 aux_text_visible_(false), 49 aux_text_visible_(false),
50 observer_(NULL), 50 observer_(NULL),
51 preedit_text_(new ibus::IBusText()), 51 preedit_text_(new IBusText()),
52 preedit_cursor_(0), 52 preedit_cursor_(0),
53 component_(new ibus::IBusComponent()), 53 component_(new IBusComponent()),
54 table_(new ibus::IBusLookupTable()), 54 table_(new IBusLookupTable()),
55 window_visible_(false), 55 window_visible_(false),
56 weak_ptr_factory_(this) { 56 weak_ptr_factory_(this) {
57 } 57 }
58 58
59 InputMethodEngineIBus::~InputMethodEngineIBus() { 59 InputMethodEngineIBus::~InputMethodEngineIBus() {
60 if (object_path_.IsValid()) 60 if (object_path_.IsValid())
61 GetCurrentService()->UnsetEngine(); 61 GetCurrentService()->UnsetEngine();
62 input_method::GetInputMethodManager()->RemoveInputMethodExtension(ibus_id_); 62 input_method::GetInputMethodManager()->RemoveInputMethodExtension(ibus_id_);
63 } 63 }
64 64
(...skipping 21 matching lines...) Expand all
86 layout = JoinString(layouts, ','); 86 layout = JoinString(layouts, ',');
87 } else { 87 } else {
88 const std::string fallback_id = 88 const std::string fallback_id =
89 manager->GetInputMethodUtil()->GetHardwareInputMethodId(); 89 manager->GetInputMethodUtil()->GetHardwareInputMethodId();
90 const input_method::InputMethodDescriptor* fallback_desc = 90 const input_method::InputMethodDescriptor* fallback_desc =
91 manager->GetInputMethodUtil()->GetInputMethodDescriptorFromId( 91 manager->GetInputMethodUtil()->GetInputMethodDescriptorFromId(
92 fallback_id); 92 fallback_id);
93 layout = fallback_desc->keyboard_layout(); 93 layout = fallback_desc->keyboard_layout();
94 } 94 }
95 95
96 component_.reset(new ibus::IBusComponent()); 96 component_.reset(new IBusComponent());
97 component_->set_name(std::string(kEngineBusPrefix) + std::string(engine_id)); 97 component_->set_name(std::string(kEngineBusPrefix) + std::string(engine_id));
98 component_->set_description(description); 98 component_->set_description(description);
99 component_->set_author(engine_name); 99 component_->set_author(engine_name);
100 100
101 chromeos::ibus::IBusComponent::EngineDescription engine_desc; 101 chromeos::IBusComponent::EngineDescription engine_desc;
102 engine_desc.engine_id = ibus_id_; 102 engine_desc.engine_id = ibus_id_;
103 engine_desc.display_name = description; 103 engine_desc.display_name = description;
104 engine_desc.description = description; 104 engine_desc.description = description;
105 engine_desc.language_code = language; 105 engine_desc.language_code = language;
106 engine_desc.author = ibus_id_; 106 engine_desc.author = ibus_id_;
107 engine_desc.layout = layout.c_str(); 107 engine_desc.layout = layout.c_str();
108 108
109 component_->mutable_engine_description()->push_back(engine_desc); 109 component_->mutable_engine_description()->push_back(engine_desc);
110 manager->AddInputMethodExtension(ibus_id_, engine_name, layouts, language, 110 manager->AddInputMethodExtension(ibus_id_, engine_name, layouts, language,
111 this); 111 this);
(...skipping 14 matching lines...) Expand all
126 if (!active_) { 126 if (!active_) {
127 *error = kErrorNotActive; 127 *error = kErrorNotActive;
128 return false; 128 return false;
129 } 129 }
130 if (context_id != context_id_ || context_id_ == -1) { 130 if (context_id != context_id_ || context_id_ == -1) {
131 *error = kErrorWrongContext; 131 *error = kErrorWrongContext;
132 return false; 132 return false;
133 } 133 }
134 134
135 preedit_cursor_ = cursor; 135 preedit_cursor_ = cursor;
136 preedit_text_.reset(new ibus::IBusText()); 136 preedit_text_.reset(new IBusText());
137 preedit_text_->set_text(text); 137 preedit_text_->set_text(text);
138 138
139 // TODO: Add support for displaying selected text in the composition string. 139 // TODO: Add support for displaying selected text in the composition string.
140 for (std::vector<SegmentInfo>::const_iterator segment = segments.begin(); 140 for (std::vector<SegmentInfo>::const_iterator segment = segments.begin();
141 segment != segments.end(); ++segment) { 141 segment != segments.end(); ++segment) {
142 ibus::IBusText::UnderlineAttribute underline; 142 IBusText::UnderlineAttribute underline;
143 143
144 switch (segment->style) { 144 switch (segment->style) {
145 case SEGMENT_STYLE_UNDERLINE: 145 case SEGMENT_STYLE_UNDERLINE:
146 underline.type = ibus::IBusText::IBUS_TEXT_UNDERLINE_SINGLE; 146 underline.type = IBusText::IBUS_TEXT_UNDERLINE_SINGLE;
147 break; 147 break;
148 case SEGMENT_STYLE_DOUBLE_UNDERLINE: 148 case SEGMENT_STYLE_DOUBLE_UNDERLINE:
149 underline.type = ibus::IBusText::IBUS_TEXT_UNDERLINE_DOUBLE; 149 underline.type = IBusText::IBUS_TEXT_UNDERLINE_DOUBLE;
150 break; 150 break;
151 default: 151 default:
152 continue; 152 continue;
153 } 153 }
154 154
155 underline.start_index = segment->start; 155 underline.start_index = segment->start;
156 underline.end_index = segment->end; 156 underline.end_index = segment->end;
157 preedit_text_->mutable_underline_attributes()->push_back(underline); 157 preedit_text_->mutable_underline_attributes()->push_back(underline);
158 } 158 }
159 159
(...skipping 11 matching lines...) Expand all
171 if (!active_) { 171 if (!active_) {
172 *error = kErrorNotActive; 172 *error = kErrorNotActive;
173 return false; 173 return false;
174 } 174 }
175 if (context_id != context_id_ || context_id_ == -1) { 175 if (context_id != context_id_ || context_id_ == -1) {
176 *error = kErrorWrongContext; 176 *error = kErrorWrongContext;
177 return false; 177 return false;
178 } 178 }
179 179
180 preedit_cursor_ = 0; 180 preedit_cursor_ = 0;
181 preedit_text_.reset(new ibus::IBusText()); 181 preedit_text_.reset(new IBusText());
182 GetCurrentService()->UpdatePreedit( 182 GetCurrentService()->UpdatePreedit(
183 *preedit_text_.get(), 183 *preedit_text_.get(),
184 0, 184 0,
185 true, 185 true,
186 chromeos::IBusEngineService::IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_COMMIT); 186 chromeos::IBusEngineService::IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_COMMIT);
187 return true; 187 return true;
188 } 188 }
189 189
190 bool InputMethodEngineIBus::CommitText(int context_id, const char* text, 190 bool InputMethodEngineIBus::CommitText(int context_id, const char* text,
191 std::string* error) { 191 std::string* error) {
(...skipping 23 matching lines...) Expand all
215 return true; 215 return true;
216 } 216 }
217 217
218 void InputMethodEngineIBus::SetCandidateWindowCursorVisible(bool visible) { 218 void InputMethodEngineIBus::SetCandidateWindowCursorVisible(bool visible) {
219 table_->set_is_cursor_visible(visible); 219 table_->set_is_cursor_visible(visible);
220 if (active_) 220 if (active_)
221 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_); 221 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_);
222 } 222 }
223 223
224 void InputMethodEngineIBus::SetCandidateWindowVertical(bool vertical) { 224 void InputMethodEngineIBus::SetCandidateWindowVertical(bool vertical) {
225 table_->set_orientation(vertical ? ibus::IBusLookupTable::VERTICAL : 225 table_->set_orientation(vertical ? IBusLookupTable::VERTICAL :
226 ibus::IBusLookupTable::HORIZONTAL); 226 IBusLookupTable::HORIZONTAL);
227 if (active_) 227 if (active_)
228 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_); 228 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_);
229 } 229 }
230 230
231 void InputMethodEngineIBus::SetCandidateWindowPageSize(int size) { 231 void InputMethodEngineIBus::SetCandidateWindowPageSize(int size) {
232 table_->set_page_size(size); 232 table_->set_page_size(size);
233 if (active_) 233 if (active_)
234 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_); 234 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_);
235 } 235 }
236 236
(...skipping 29 matching lines...) Expand all
266 *error = kErrorWrongContext; 266 *error = kErrorWrongContext;
267 return false; 267 return false;
268 } 268 }
269 269
270 // TODO: Nested candidates 270 // TODO: Nested candidates
271 candidate_ids_.clear(); 271 candidate_ids_.clear();
272 candidate_indexes_.clear(); 272 candidate_indexes_.clear();
273 table_->mutable_candidates()->clear(); 273 table_->mutable_candidates()->clear();
274 for (std::vector<Candidate>::const_iterator ix = candidates.begin(); 274 for (std::vector<Candidate>::const_iterator ix = candidates.begin();
275 ix != candidates.end(); ++ix) { 275 ix != candidates.end(); ++ix) {
276 ibus::IBusLookupTable::Entry entry; 276 IBusLookupTable::Entry entry;
277 entry.value = ix->value; 277 entry.value = ix->value;
278 entry.label = ix->label; 278 entry.label = ix->label;
279 entry.annotation = ix->annotation; 279 entry.annotation = ix->annotation;
280 entry.description_title = ix->usage.title; 280 entry.description_title = ix->usage.title;
281 entry.description_body = ix->usage.body; 281 entry.description_body = ix->usage.body;
282 282
283 // Store a mapping from the user defined ID to the candidate index. 283 // Store a mapping from the user defined ID to the candidate index.
284 candidate_indexes_[ix->id] = candidate_ids_.size(); 284 candidate_indexes_[ix->id] = candidate_ids_.size();
285 candidate_ids_.push_back(ix->id); 285 candidate_ids_.push_back(ix->id);
286 286
(...skipping 23 matching lines...) Expand all
310 310
311 table_->set_cursor_position(position->second); 311 table_->set_cursor_position(position->second);
312 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_); 312 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_);
313 return true; 313 return true;
314 } 314 }
315 315
316 bool InputMethodEngineIBus::SetMenuItems(const std::vector<MenuItem>& items) { 316 bool InputMethodEngineIBus::SetMenuItems(const std::vector<MenuItem>& items) {
317 if (!active_) 317 if (!active_)
318 return false; 318 return false;
319 319
320 ibus::IBusPropertyList properties; 320 IBusPropertyList properties;
321 for (std::vector<MenuItem>::const_iterator item = items.begin(); 321 for (std::vector<MenuItem>::const_iterator item = items.begin();
322 item != items.end(); ++item) { 322 item != items.end(); ++item) {
323 ibus::IBusProperty* property = new ibus::IBusProperty(); 323 IBusProperty* property = new IBusProperty();
324 if (!MenuItemToProperty(*item, property)) { 324 if (!MenuItemToProperty(*item, property)) {
325 delete property; 325 delete property;
326 DVLOG(1) << "Bad menu item"; 326 DVLOG(1) << "Bad menu item";
327 return false; 327 return false;
328 } 328 }
329 properties.push_back(property); 329 properties.push_back(property);
330 } 330 }
331 GetCurrentService()->RegisterProperties(properties); 331 GetCurrentService()->RegisterProperties(properties);
332 return true; 332 return true;
333 } 333 }
334 334
335 bool InputMethodEngineIBus::UpdateMenuItems( 335 bool InputMethodEngineIBus::UpdateMenuItems(
336 const std::vector<MenuItem>& items) { 336 const std::vector<MenuItem>& items) {
337 if (!active_) 337 if (!active_)
338 return false; 338 return false;
339 339
340 ibus::IBusPropertyList properties; 340 IBusPropertyList properties;
341 for (std::vector<MenuItem>::const_iterator item = items.begin(); 341 for (std::vector<MenuItem>::const_iterator item = items.begin();
342 item != items.end(); ++item) { 342 item != items.end(); ++item) {
343 ibus::IBusProperty* property = new ibus::IBusProperty(); 343 IBusProperty* property = new IBusProperty();
344 if (!MenuItemToProperty(*item, property)) { 344 if (!MenuItemToProperty(*item, property)) {
345 delete property; 345 delete property;
346 DVLOG(1) << "Bad menu item"; 346 DVLOG(1) << "Bad menu item";
347 return false; 347 return false;
348 } 348 }
349 properties.push_back(property); 349 properties.push_back(property);
350 } 350 }
351 GetCurrentService()->RegisterProperties(properties); 351 GetCurrentService()->RegisterProperties(properties);
352 return true; 352 return true;
353 } 353 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 FocusIn(); 394 FocusIn();
395 } 395 }
396 396
397 void InputMethodEngineIBus::Disable() { 397 void InputMethodEngineIBus::Disable() {
398 active_ = false; 398 active_ = false;
399 observer_->OnDeactivated(engine_id_); 399 observer_->OnDeactivated(engine_id_);
400 } 400 }
401 401
402 void InputMethodEngineIBus::PropertyActivate( 402 void InputMethodEngineIBus::PropertyActivate(
403 const std::string& property_name, 403 const std::string& property_name,
404 IBusPropertyState property_state) { 404 ibus::IBusPropertyState property_state) {
405 observer_->OnMenuItemActivated(engine_id_, property_name); 405 observer_->OnMenuItemActivated(engine_id_, property_name);
406 } 406 }
407 407
408 void InputMethodEngineIBus::PropertyShow( 408 void InputMethodEngineIBus::PropertyShow(
409 const std::string& property_name) { 409 const std::string& property_name) {
410 } 410 }
411 411
412 void InputMethodEngineIBus::PropertyHide( 412 void InputMethodEngineIBus::PropertyHide(
413 const std::string& property_name) { 413 const std::string& property_name) {
414 } 414 }
(...skipping 19 matching lines...) Expand all
434 event.key = input_method::GetIBusKey(keysym); 434 event.key = input_method::GetIBusKey(keysym);
435 event.alt_key = state & kIBusAltKeyMask; 435 event.alt_key = state & kIBusAltKeyMask;
436 event.ctrl_key = state & kIBusCtrlKeyMask; 436 event.ctrl_key = state & kIBusCtrlKeyMask;
437 event.shift_key = state & kIBusShiftKeyMask; 437 event.shift_key = state & kIBusShiftKeyMask;
438 observer_->OnKeyEvent( 438 observer_->OnKeyEvent(
439 engine_id_, 439 engine_id_,
440 event, 440 event,
441 reinterpret_cast<input_method::KeyEventHandle*>(handler)); 441 reinterpret_cast<input_method::KeyEventHandle*>(handler));
442 } 442 }
443 443
444 void InputMethodEngineIBus::CandidateClicked( 444 void InputMethodEngineIBus::CandidateClicked(uint32 index,
445 uint32 index, 445 ibus::IBusMouseButton button,
446 ibus::IBusMouseButton button, 446 uint32 state) {
447 uint32 state) {
448 if (index > candidate_ids_.size()) { 447 if (index > candidate_ids_.size()) {
449 return; 448 return;
450 } 449 }
451 450
452 MouseButtonEvent pressed_button; 451 MouseButtonEvent pressed_button;
453 switch (button) { 452 switch (button) {
454 case ibus::IBUS_MOUSE_BUTTON_LEFT: 453 case ibus::IBUS_MOUSE_BUTTON_LEFT:
455 pressed_button = MOUSE_BUTTON_LEFT; 454 pressed_button = MOUSE_BUTTON_LEFT;
456 break; 455 break;
457 case ibus::IBUS_MOUSE_BUTTON_MIDDLE: 456 case ibus::IBUS_MOUSE_BUTTON_MIDDLE:
(...skipping 17 matching lines...) Expand all
475 uint32 cursor_pos, 474 uint32 cursor_pos,
476 uint32 anchor_pos) { 475 uint32 anchor_pos) {
477 } 476 }
478 477
479 IBusEngineService* InputMethodEngineIBus::GetCurrentService() { 478 IBusEngineService* InputMethodEngineIBus::GetCurrentService() {
480 return DBusThreadManager::Get()->GetIBusEngineService(object_path_); 479 return DBusThreadManager::Get()->GetIBusEngineService(object_path_);
481 } 480 }
482 481
483 bool InputMethodEngineIBus::MenuItemToProperty( 482 bool InputMethodEngineIBus::MenuItemToProperty(
484 const MenuItem& item, 483 const MenuItem& item,
485 ibus::IBusProperty* property) { 484 IBusProperty* property) {
486 property->set_key(item.id); 485 property->set_key(item.id);
487 486
488 if (item.modified & MENU_ITEM_MODIFIED_LABEL) { 487 if (item.modified & MENU_ITEM_MODIFIED_LABEL) {
489 property->set_label(item.label); 488 property->set_label(item.label);
490 } 489 }
491 if (item.modified & MENU_ITEM_MODIFIED_VISIBLE) { 490 if (item.modified & MENU_ITEM_MODIFIED_VISIBLE) {
492 property->set_visible(item.visible); 491 property->set_visible(item.visible);
493 } 492 }
494 if (item.modified & MENU_ITEM_MODIFIED_CHECKED) { 493 if (item.modified & MENU_ITEM_MODIFIED_CHECKED) {
495 property->set_checked(item.checked); 494 property->set_checked(item.checked);
496 } 495 }
497 if (item.modified & MENU_ITEM_MODIFIED_ENABLED) { 496 if (item.modified & MENU_ITEM_MODIFIED_ENABLED) {
498 // TODO(nona): implement sensitive entry(crbug.com/140192). 497 // TODO(nona): implement sensitive entry(crbug.com/140192).
499 } 498 }
500 if (item.modified & MENU_ITEM_MODIFIED_STYLE) { 499 if (item.modified & MENU_ITEM_MODIFIED_STYLE) {
501 ibus::IBusProperty::IBusPropertyType type = 500 IBusProperty::IBusPropertyType type =
502 ibus::IBusProperty::IBUS_PROPERTY_TYPE_NORMAL; 501 IBusProperty::IBUS_PROPERTY_TYPE_NORMAL;
503 if (!item.children.empty()) { 502 if (!item.children.empty()) {
504 type = ibus::IBusProperty::IBUS_PROPERTY_TYPE_MENU; 503 type = IBusProperty::IBUS_PROPERTY_TYPE_MENU;
505 } else { 504 } else {
506 switch (item.style) { 505 switch (item.style) {
507 case MENU_ITEM_STYLE_NONE: 506 case MENU_ITEM_STYLE_NONE:
508 type = ibus::IBusProperty::IBUS_PROPERTY_TYPE_NORMAL; 507 type = IBusProperty::IBUS_PROPERTY_TYPE_NORMAL;
509 break; 508 break;
510 case MENU_ITEM_STYLE_CHECK: 509 case MENU_ITEM_STYLE_CHECK:
511 type = ibus::IBusProperty::IBUS_PROPERTY_TYPE_TOGGLE; 510 type = IBusProperty::IBUS_PROPERTY_TYPE_TOGGLE;
512 break; 511 break;
513 case MENU_ITEM_STYLE_RADIO: 512 case MENU_ITEM_STYLE_RADIO:
514 type = ibus::IBusProperty::IBUS_PROPERTY_TYPE_RADIO; 513 type = IBusProperty::IBUS_PROPERTY_TYPE_RADIO;
515 break; 514 break;
516 case MENU_ITEM_STYLE_SEPARATOR: 515 case MENU_ITEM_STYLE_SEPARATOR:
517 type = ibus::IBusProperty::IBUS_PROPERTY_TYPE_SEPARATOR; 516 type = IBusProperty::IBUS_PROPERTY_TYPE_SEPARATOR;
518 break; 517 break;
519 } 518 }
520 } 519 }
521 property->set_type(type); 520 property->set_type(type);
522 } 521 }
523 522
524 for (std::vector<MenuItem>::const_iterator child = item.children.begin(); 523 for (std::vector<MenuItem>::const_iterator child = item.children.begin();
525 child != item.children.end(); ++child) { 524 child != item.children.end(); ++child) {
526 ibus::IBusProperty* new_property = new ibus::IBusProperty(); 525 IBusProperty* new_property = new IBusProperty();
527 if (!MenuItemToProperty(*child, new_property)) { 526 if (!MenuItemToProperty(*child, new_property)) {
528 delete new_property; 527 delete new_property;
529 DVLOG(1) << "Bad menu item child"; 528 DVLOG(1) << "Bad menu item child";
530 return false; 529 return false;
531 } 530 }
532 property->mutable_sub_properties()->push_back(new_property); 531 property->mutable_sub_properties()->push_back(new_property);
533 } 532 }
534 533
535 return true; 534 return true;
536 } 535 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 DBusThreadManager::Get()->RemoveIBusEngineService(object_path_); 574 DBusThreadManager::Get()->RemoveIBusEngineService(object_path_);
576 575
577 current_object_path_++; 576 current_object_path_++;
578 object_path_ = dbus::ObjectPath(kObjectPathPrefix + 577 object_path_ = dbus::ObjectPath(kObjectPathPrefix +
579 base::IntToString(current_object_path_)); 578 base::IntToString(current_object_path_));
580 GetCurrentService()->SetEngine(this); 579 GetCurrentService()->SetEngine(this);
581 sender.Run(object_path_); 580 sender.Run(object_path_);
582 } 581 }
583 582
584 } // namespace chromeos 583 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/input_method/input_method_engine_ibus.h ('k') | chromeos/dbus/dbus_thread_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698