| OLD | NEW |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 ibus::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 ibus::IBusText()), |
| 52 preedit_cursor_(0), | 52 preedit_cursor_(0), |
| 53 component_(new ibus::IBusComponent()), | 53 component_(new ibus::IBusComponent()), |
| 54 table_(new ibus::IBusLookupTable()), | 54 table_(new ibus::IBusLookupTable()), |
| 55 table_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 GetCurrentService()->UnsetEngine(); | 60 GetCurrentService()->UnsetEngine(); |
| 61 input_method::GetInputMethodManager()->RemoveInputMethodExtension(ibus_id_); | 61 input_method::GetInputMethodManager()->RemoveInputMethodExtension(ibus_id_); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void InputMethodEngineIBus::Initialize( | 64 void InputMethodEngineIBus::Initialize( |
| 65 InputMethodEngine::Observer* observer, | 65 InputMethodEngine::Observer* observer, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return true; | 202 return true; |
| 203 } | 203 } |
| 204 | 204 |
| 205 bool InputMethodEngineIBus::SetCandidateWindowVisible(bool visible, | 205 bool InputMethodEngineIBus::SetCandidateWindowVisible(bool visible, |
| 206 std::string* error) { | 206 std::string* error) { |
| 207 if (!active_) { | 207 if (!active_) { |
| 208 *error = kErrorNotActive; | 208 *error = kErrorNotActive; |
| 209 return false; | 209 return false; |
| 210 } | 210 } |
| 211 | 211 |
| 212 table_visible_ = visible; | 212 window_visible_ = visible; |
| 213 GetCurrentService()->UpdateLookupTable(*table_.get(), table_visible_); | 213 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_); |
| 214 return true; | 214 return true; |
| 215 } | 215 } |
| 216 | 216 |
| 217 void InputMethodEngineIBus::SetCandidateWindowCursorVisible(bool visible) { | 217 void InputMethodEngineIBus::SetCandidateWindowCursorVisible(bool visible) { |
| 218 if (!active_) | |
| 219 return; | |
| 220 table_->set_is_cursor_visible(visible); | 218 table_->set_is_cursor_visible(visible); |
| 221 GetCurrentService()->UpdateLookupTable(*table_.get(), table_visible_); | 219 if (active_) |
| 220 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_); |
| 222 } | 221 } |
| 223 | 222 |
| 224 void InputMethodEngineIBus::SetCandidateWindowVertical(bool vertical) { | 223 void InputMethodEngineIBus::SetCandidateWindowVertical(bool vertical) { |
| 225 if (!active_) | |
| 226 return; | |
| 227 table_->set_orientation( | 224 table_->set_orientation( |
| 228 vertical ? ibus::IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_VERTICAL : | 225 vertical ? ibus::IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_VERTICAL : |
| 229 ibus::IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_HORIZONTAL); | 226 ibus::IBusLookupTable::IBUS_LOOKUP_TABLE_ORIENTATION_HORIZONTAL); |
| 230 GetCurrentService()->UpdateLookupTable(*table_.get(), table_visible_); | 227 if (active_) |
| 228 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_); |
| 231 } | 229 } |
| 232 | 230 |
| 233 void InputMethodEngineIBus::SetCandidateWindowPageSize(int size) { | 231 void InputMethodEngineIBus::SetCandidateWindowPageSize(int size) { |
| 234 if (!active_) | |
| 235 return; | |
| 236 table_->set_page_size(size); | 232 table_->set_page_size(size); |
| 237 GetCurrentService()->UpdateLookupTable(*table_.get(), table_visible_); | 233 if (active_) |
| 234 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_); |
| 238 } | 235 } |
| 239 | 236 |
| 240 void InputMethodEngineIBus::SetCandidateWindowAuxText(const char* text) { | 237 void InputMethodEngineIBus::SetCandidateWindowAuxText(const char* text) { |
| 241 if (!active_) | |
| 242 return; | |
| 243 aux_text_->set_text(text); | 238 aux_text_->set_text(text); |
| 244 GetCurrentService()->UpdateAuxiliaryText(*aux_text_.get(), aux_text_visible_); | 239 if (active_) { |
| 240 // Should not show auxiliary text if the whole window visibility is false. |
| 241 GetCurrentService()->UpdateAuxiliaryText( |
| 242 *aux_text_.get(), |
| 243 window_visible_ && aux_text_visible_); |
| 244 } |
| 245 } | 245 } |
| 246 | 246 |
| 247 void InputMethodEngineIBus::SetCandidateWindowAuxTextVisible(bool visible) { | 247 void InputMethodEngineIBus::SetCandidateWindowAuxTextVisible(bool visible) { |
| 248 if (!active_) | |
| 249 return; | |
| 250 aux_text_visible_ = visible; | 248 aux_text_visible_ = visible; |
| 251 GetCurrentService()->UpdateAuxiliaryText(*aux_text_.get(), aux_text_visible_); | 249 if (active_) { |
| 250 // Should not show auxiliary text if the whole window visibility is false. |
| 251 GetCurrentService()->UpdateAuxiliaryText( |
| 252 *aux_text_.get(), |
| 253 window_visible_ && aux_text_visible_); |
| 254 } |
| 252 } | 255 } |
| 253 | 256 |
| 254 bool InputMethodEngineIBus::SetCandidates( | 257 bool InputMethodEngineIBus::SetCandidates( |
| 255 int context_id, | 258 int context_id, |
| 256 const std::vector<Candidate>& candidates, | 259 const std::vector<Candidate>& candidates, |
| 257 std::string* error) { | 260 std::string* error) { |
| 258 if (!active_) { | 261 if (!active_) { |
| 259 *error = kErrorNotActive; | 262 *error = kErrorNotActive; |
| 260 return false; | 263 return false; |
| 261 } | 264 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 276 entry.annotation = ix->annotation; | 279 entry.annotation = ix->annotation; |
| 277 entry.description_title = ix->usage.title; | 280 entry.description_title = ix->usage.title; |
| 278 entry.description_body = ix->usage.body; | 281 entry.description_body = ix->usage.body; |
| 279 | 282 |
| 280 // 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. |
| 281 candidate_indexes_[ix->id] = candidate_ids_.size(); | 284 candidate_indexes_[ix->id] = candidate_ids_.size(); |
| 282 candidate_ids_.push_back(ix->id); | 285 candidate_ids_.push_back(ix->id); |
| 283 | 286 |
| 284 table_->mutable_candidates()->push_back(entry); | 287 table_->mutable_candidates()->push_back(entry); |
| 285 } | 288 } |
| 286 GetCurrentService()->UpdateLookupTable(*table_.get(), table_visible_); | 289 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_); |
| 287 return true; | 290 return true; |
| 288 } | 291 } |
| 289 | 292 |
| 290 bool InputMethodEngineIBus::SetCursorPosition(int context_id, int candidate_id, | 293 bool InputMethodEngineIBus::SetCursorPosition(int context_id, int candidate_id, |
| 291 std::string* error) { | 294 std::string* error) { |
| 292 if (!active_) { | 295 if (!active_) { |
| 293 *error = kErrorNotActive; | 296 *error = kErrorNotActive; |
| 294 return false; | 297 return false; |
| 295 } | 298 } |
| 296 if (context_id != context_id_ || context_id_ == -1) { | 299 if (context_id != context_id_ || context_id_ == -1) { |
| 297 *error = kErrorWrongContext; | 300 *error = kErrorWrongContext; |
| 298 return false; | 301 return false; |
| 299 } | 302 } |
| 300 | 303 |
| 301 std::map<int, int>::const_iterator position = | 304 std::map<int, int>::const_iterator position = |
| 302 candidate_indexes_.find(candidate_id); | 305 candidate_indexes_.find(candidate_id); |
| 303 if (position == candidate_indexes_.end()) { | 306 if (position == candidate_indexes_.end()) { |
| 304 *error = kCandidateNotFound; | 307 *error = kCandidateNotFound; |
| 305 return false; | 308 return false; |
| 306 } | 309 } |
| 307 | 310 |
| 308 table_->set_cursor_position(position->second); | 311 table_->set_cursor_position(position->second); |
| 309 GetCurrentService()->UpdateLookupTable(*table_.get(), table_visible_); | 312 GetCurrentService()->UpdateLookupTable(*table_.get(), window_visible_); |
| 310 return true; | 313 return true; |
| 311 } | 314 } |
| 312 | 315 |
| 313 bool InputMethodEngineIBus::SetMenuItems(const std::vector<MenuItem>& items) { | 316 bool InputMethodEngineIBus::SetMenuItems(const std::vector<MenuItem>& items) { |
| 314 if (!active_) | 317 if (!active_) |
| 315 return false; | 318 return false; |
| 316 | 319 |
| 317 ibus::IBusPropertyList properties; | 320 ibus::IBusPropertyList properties; |
| 318 for (std::vector<MenuItem>::const_iterator item = items.begin(); | 321 for (std::vector<MenuItem>::const_iterator item = items.begin(); |
| 319 item != items.end(); ++item) { | 322 item != items.end(); ++item) { |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 DBusThreadManager::Get()->RemoveIBusEngineService(object_path_); | 575 DBusThreadManager::Get()->RemoveIBusEngineService(object_path_); |
| 573 | 576 |
| 574 current_object_path_++; | 577 current_object_path_++; |
| 575 object_path_ = dbus::ObjectPath(kObjectPathPrefix + | 578 object_path_ = dbus::ObjectPath(kObjectPathPrefix + |
| 576 base::IntToString(current_object_path_)); | 579 base::IntToString(current_object_path_)); |
| 577 GetCurrentService()->SetEngine(this); | 580 GetCurrentService()->SetEngine(this); |
| 578 sender.Run(object_path_); | 581 sender.Run(object_path_); |
| 579 } | 582 } |
| 580 | 583 |
| 581 } // namespace chromeos | 584 } // namespace chromeos |
| OLD | NEW |