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

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

Issue 24946003: Rename IBusLookupTable to CandidateWindow, and move it to chromeos/ime. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 7 years, 2 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
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 #define XK_MISCELLANY 7 #define XK_MISCELLANY
8 #include <X11/keysymdef.h> 8 #include <X11/keysymdef.h>
9 #include <map> 9 #include <map>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chromeos/dbus/dbus_thread_manager.h" 16 #include "chromeos/dbus/dbus_thread_manager.h"
17 #include "chromeos/dbus/ibus/ibus_client.h" 17 #include "chromeos/dbus/ibus/ibus_client.h"
18 #include "chromeos/dbus/ibus/ibus_component.h" 18 #include "chromeos/dbus/ibus/ibus_component.h"
19 #include "chromeos/dbus/ibus/ibus_engine_factory_service.h" 19 #include "chromeos/dbus/ibus/ibus_engine_factory_service.h"
20 #include "chromeos/dbus/ibus/ibus_engine_service.h" 20 #include "chromeos/dbus/ibus/ibus_engine_service.h"
21 #include "chromeos/dbus/ibus/ibus_lookup_table.h"
22 #include "chromeos/dbus/ibus/ibus_text.h" 21 #include "chromeos/dbus/ibus/ibus_text.h"
22 #include "chromeos/ime/candidate_window.h"
23 #include "chromeos/ime/component_extension_ime_manager.h" 23 #include "chromeos/ime/component_extension_ime_manager.h"
24 #include "chromeos/ime/extension_ime_util.h" 24 #include "chromeos/ime/extension_ime_util.h"
25 #include "chromeos/ime/ibus_keymap.h" 25 #include "chromeos/ime/ibus_keymap.h"
26 #include "chromeos/ime/input_method_manager.h" 26 #include "chromeos/ime/input_method_manager.h"
27 #include "dbus/object_path.h" 27 #include "dbus/object_path.h"
28 28
29 namespace chromeos { 29 namespace chromeos {
30 const char* kErrorNotActive = "IME is not active"; 30 const char* kErrorNotActive = "IME is not active";
31 const char* kErrorWrongContext = "Context is not active"; 31 const char* kErrorWrongContext = "Context is not active";
32 const char* kCandidateNotFound = "Candidate not found"; 32 const char* kCandidateNotFound = "Candidate not found";
(...skipping 11 matching lines...) Expand all
44 : focused_(false), 44 : focused_(false),
45 active_(false), 45 active_(false),
46 context_id_(0), 46 context_id_(0),
47 next_context_id_(1), 47 next_context_id_(1),
48 aux_text_(new 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 IBusText()), 51 preedit_text_(new IBusText()),
52 preedit_cursor_(0), 52 preedit_cursor_(0),
53 component_(new IBusComponent()), 53 component_(new IBusComponent()),
54 table_(new IBusLookupTable()), 54 candidate_window_(new input_method::CandidateWindow()),
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 input_method::InputMethodManager::Get()->RemoveInputMethodExtension(ibus_id_); 60 input_method::InputMethodManager::Get()->RemoveInputMethodExtension(ibus_id_);
61 61
62 // Do not unset engine before removing input method extension, above function 62 // Do not unset engine before removing input method extension, above function
63 // may call reset function of engine object. 63 // may call reset function of engine object.
64 // TODO(nona): Call Reset manually here and remove relevant code from 64 // TODO(nona): Call Reset manually here and remove relevant code from
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 return true; 219 return true;
220 } 220 }
221 221
222 const InputMethodEngineIBus::CandidateWindowProperty& 222 const InputMethodEngineIBus::CandidateWindowProperty&
223 InputMethodEngineIBus::GetCandidateWindowProperty() const { 223 InputMethodEngineIBus::GetCandidateWindowProperty() const {
224 return candidate_window_property_; 224 return candidate_window_property_;
225 } 225 }
226 226
227 void InputMethodEngineIBus::SetCandidateWindowProperty( 227 void InputMethodEngineIBus::SetCandidateWindowProperty(
228 const CandidateWindowProperty& property) { 228 const CandidateWindowProperty& property) {
229 IBusLookupTable::CandidateWindowProperty ibus_property; 229 // Type conversion from InputMethodEngine::CandidateWindowProperty to
230 ibus_property.page_size = property.page_size; 230 // CandidateWindow::CandidateWindowProperty defined in chromeos/ime/.
231 ibus_property.is_cursor_visible = property.is_cursor_visible; 231 input_method::CandidateWindow::CandidateWindowProperty dest_property;
232 ibus_property.is_vertical = property.is_vertical; 232 dest_property.page_size = property.page_size;
233 ibus_property.show_window_at_composition = 233 dest_property.is_cursor_visible = property.is_cursor_visible;
234 dest_property.is_vertical = property.is_vertical;
235 dest_property.show_window_at_composition =
234 property.show_window_at_composition; 236 property.show_window_at_composition;
235 ibus_property.cursor_position = table_->GetProperty().cursor_position; 237 dest_property.cursor_position =
236 table_->SetProperty(ibus_property); 238 candidate_window_->GetProperty().cursor_position;
239 candidate_window_->SetProperty(dest_property);
237 candidate_window_property_ = property; 240 candidate_window_property_ = property;
238 241
239 if (active_) { 242 if (active_) {
240 IBusPanelCandidateWindowHandlerInterface* candidate_window = 243 IBusPanelCandidateWindowHandlerInterface* cw_handler =
241 IBusBridge::Get()->GetCandidateWindowHandler(); 244 IBusBridge::Get()->GetCandidateWindowHandler();
242 if (candidate_window) 245 if (cw_handler)
243 candidate_window->UpdateLookupTable(*table_, window_visible_); 246 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_);
244 } 247 }
245 } 248 }
246 249
247 bool InputMethodEngineIBus::SetCandidateWindowVisible(bool visible, 250 bool InputMethodEngineIBus::SetCandidateWindowVisible(bool visible,
248 std::string* error) { 251 std::string* error) {
249 if (!active_) { 252 if (!active_) {
250 *error = kErrorNotActive; 253 *error = kErrorNotActive;
251 return false; 254 return false;
252 } 255 }
253 256
254 window_visible_ = visible; 257 window_visible_ = visible;
255 IBusPanelCandidateWindowHandlerInterface* candidate_window = 258 IBusPanelCandidateWindowHandlerInterface* cw_handler =
256 IBusBridge::Get()->GetCandidateWindowHandler(); 259 IBusBridge::Get()->GetCandidateWindowHandler();
257 if (candidate_window) 260 if (cw_handler)
258 candidate_window->UpdateLookupTable(*table_, window_visible_); 261 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_);
259 return true; 262 return true;
260 } 263 }
261 264
262 void InputMethodEngineIBus::SetCandidateWindowAuxText(const char* text) { 265 void InputMethodEngineIBus::SetCandidateWindowAuxText(const char* text) {
263 aux_text_->set_text(text); 266 aux_text_->set_text(text);
264 if (active_) { 267 if (active_) {
265 // Should not show auxiliary text if the whole window visibility is false. 268 // Should not show auxiliary text if the whole window visibility is false.
266 GetCurrentService()->UpdateAuxiliaryText( 269 GetCurrentService()->UpdateAuxiliaryText(
267 *aux_text_.get(), 270 *aux_text_.get(),
268 window_visible_ && aux_text_visible_); 271 window_visible_ && aux_text_visible_);
(...skipping 19 matching lines...) Expand all
288 return false; 291 return false;
289 } 292 }
290 if (context_id != context_id_ || context_id_ == -1) { 293 if (context_id != context_id_ || context_id_ == -1) {
291 *error = kErrorWrongContext; 294 *error = kErrorWrongContext;
292 return false; 295 return false;
293 } 296 }
294 297
295 // TODO: Nested candidates 298 // TODO: Nested candidates
296 candidate_ids_.clear(); 299 candidate_ids_.clear();
297 candidate_indexes_.clear(); 300 candidate_indexes_.clear();
298 table_->mutable_candidates()->clear(); 301 candidate_window_->mutable_candidates()->clear();
299 for (std::vector<Candidate>::const_iterator ix = candidates.begin(); 302 for (std::vector<Candidate>::const_iterator ix = candidates.begin();
300 ix != candidates.end(); ++ix) { 303 ix != candidates.end(); ++ix) {
301 IBusLookupTable::Entry entry; 304 input_method::CandidateWindow::Entry entry;
302 entry.value = ix->value; 305 entry.value = ix->value;
303 entry.label = ix->label; 306 entry.label = ix->label;
304 entry.annotation = ix->annotation; 307 entry.annotation = ix->annotation;
305 entry.description_title = ix->usage.title; 308 entry.description_title = ix->usage.title;
306 entry.description_body = ix->usage.body; 309 entry.description_body = ix->usage.body;
307 310
308 // Store a mapping from the user defined ID to the candidate index. 311 // Store a mapping from the user defined ID to the candidate index.
309 candidate_indexes_[ix->id] = candidate_ids_.size(); 312 candidate_indexes_[ix->id] = candidate_ids_.size();
310 candidate_ids_.push_back(ix->id); 313 candidate_ids_.push_back(ix->id);
311 314
312 table_->mutable_candidates()->push_back(entry); 315 candidate_window_->mutable_candidates()->push_back(entry);
313 } 316 }
314 if (active_) { 317 if (active_) {
315 IBusPanelCandidateWindowHandlerInterface* candidate_window = 318 IBusPanelCandidateWindowHandlerInterface* cw_handler =
316 IBusBridge::Get()->GetCandidateWindowHandler(); 319 IBusBridge::Get()->GetCandidateWindowHandler();
317 if (candidate_window) 320 if (cw_handler)
318 candidate_window->UpdateLookupTable(*table_, window_visible_); 321 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_);
319 } 322 }
320 return true; 323 return true;
321 } 324 }
322 325
323 bool InputMethodEngineIBus::SetCursorPosition(int context_id, int candidate_id, 326 bool InputMethodEngineIBus::SetCursorPosition(int context_id, int candidate_id,
324 std::string* error) { 327 std::string* error) {
325 if (!active_) { 328 if (!active_) {
326 *error = kErrorNotActive; 329 *error = kErrorNotActive;
327 return false; 330 return false;
328 } 331 }
329 if (context_id != context_id_ || context_id_ == -1) { 332 if (context_id != context_id_ || context_id_ == -1) {
330 *error = kErrorWrongContext; 333 *error = kErrorWrongContext;
331 return false; 334 return false;
332 } 335 }
333 336
334 std::map<int, int>::const_iterator position = 337 std::map<int, int>::const_iterator position =
335 candidate_indexes_.find(candidate_id); 338 candidate_indexes_.find(candidate_id);
336 if (position == candidate_indexes_.end()) { 339 if (position == candidate_indexes_.end()) {
337 *error = kCandidateNotFound; 340 *error = kCandidateNotFound;
338 return false; 341 return false;
339 } 342 }
340 343
341 table_->set_cursor_position(position->second); 344 candidate_window_->set_cursor_position(position->second);
342 IBusPanelCandidateWindowHandlerInterface* candidate_window = 345 IBusPanelCandidateWindowHandlerInterface* cw_handler =
343 IBusBridge::Get()->GetCandidateWindowHandler(); 346 IBusBridge::Get()->GetCandidateWindowHandler();
344 if (candidate_window) 347 if (cw_handler)
345 candidate_window->UpdateLookupTable(*table_, window_visible_); 348 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_);
346 return true; 349 return true;
347 } 350 }
348 351
349 bool InputMethodEngineIBus::SetMenuItems(const std::vector<MenuItem>& items) { 352 bool InputMethodEngineIBus::SetMenuItems(const std::vector<MenuItem>& items) {
350 return UpdateMenuItems(items); 353 return UpdateMenuItems(items);
351 } 354 }
352 355
353 bool InputMethodEngineIBus::UpdateMenuItems( 356 bool InputMethodEngineIBus::UpdateMenuItems(
354 const std::vector<MenuItem>& items) { 357 const std::vector<MenuItem>& items) {
355 if (!active_) 358 if (!active_)
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 DBusThreadManager::Get()->RemoveIBusEngineService(object_path_); 613 DBusThreadManager::Get()->RemoveIBusEngineService(object_path_);
611 614
612 object_path_ = DBusThreadManager::Get()->GetIBusEngineFactoryService()-> 615 object_path_ = DBusThreadManager::Get()->GetIBusEngineFactoryService()->
613 GenerateUniqueObjectPath(); 616 GenerateUniqueObjectPath();
614 617
615 GetCurrentService()->SetEngine(this); 618 GetCurrentService()->SetEngine(this);
616 sender.Run(object_path_); 619 sender.Run(object_path_);
617 } 620 }
618 621
619 } // namespace chromeos 622 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698