OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
6 | 6 |
7 #undef FocusIn | 7 #undef FocusIn |
8 #undef FocusOut | 8 #undef FocusOut |
9 #undef RootWindow | 9 #undef RootWindow |
10 #include <map> | 10 #include <map> |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 ext_event->ctrl_key = event.IsControlDown(); | 105 ext_event->ctrl_key = event.IsControlDown(); |
106 ext_event->shift_key = event.IsShiftDown(); | 106 ext_event->shift_key = event.IsShiftDown(); |
107 ext_event->caps_lock = event.IsCapsLockDown(); | 107 ext_event->caps_lock = event.IsCapsLockDown(); |
108 ext_event->key = GetKeyFromEvent(event); | 108 ext_event->key = GetKeyFromEvent(event); |
109 } | 109 } |
110 | 110 |
111 } // namespace | 111 } // namespace |
112 | 112 |
113 InputMethodEngine::InputMethodEngine() | 113 InputMethodEngine::InputMethodEngine() |
114 : current_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 114 : current_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
115 active_(false), | |
116 context_id_(0), | 115 context_id_(0), |
117 next_context_id_(1), | 116 next_context_id_(1), |
118 composition_text_(new CompositionText()), | 117 composition_text_(new CompositionText()), |
119 composition_cursor_(0), | 118 composition_cursor_(0), |
120 candidate_window_(new ui::CandidateWindow()), | 119 candidate_window_(new ui::CandidateWindow()), |
121 window_visible_(false), | 120 window_visible_(false), |
122 sent_key_event_(NULL), | 121 sent_key_event_(NULL) { |
123 profile_(NULL) { | |
124 } | 122 } |
125 | 123 |
126 InputMethodEngine::~InputMethodEngine() { | 124 InputMethodEngine::~InputMethodEngine() { |
127 if (start_time_.ToInternalValue()) | 125 if (start_time_.ToInternalValue()) |
128 RecordHistogram("WorkingTime", (end_time_ - start_time_).InSeconds()); | 126 RecordHistogram("WorkingTime", (end_time_ - start_time_).InSeconds()); |
129 input_method::InputMethodManager::Get()->RemoveInputMethodExtension(profile_, | |
130 imm_id_); | |
131 } | 127 } |
132 | 128 |
133 void InputMethodEngine::Initialize( | 129 void InputMethodEngine::Initialize( |
134 Profile* profile, | |
135 scoped_ptr<InputMethodEngineInterface::Observer> observer, | 130 scoped_ptr<InputMethodEngineInterface::Observer> observer, |
136 const char* engine_name, | 131 const char* extension_id) { |
137 const char* extension_id, | |
138 const char* engine_id, | |
139 const std::vector<std::string>& languages, | |
140 const std::vector<std::string>& layouts, | |
141 const GURL& options_page, | |
142 const GURL& input_view) { | |
143 DCHECK(observer) << "Observer must not be null."; | 132 DCHECK(observer) << "Observer must not be null."; |
144 | 133 |
145 profile_ = profile; | |
146 | |
147 // TODO(komatsu): It is probably better to set observer out of Initialize. | 134 // TODO(komatsu): It is probably better to set observer out of Initialize. |
148 observer_ = observer.Pass(); | 135 observer_ = observer.Pass(); |
149 engine_id_ = engine_id; | |
150 extension_id_ = extension_id; | 136 extension_id_ = extension_id; |
151 | |
152 input_method::InputMethodManager* manager = | |
153 input_method::InputMethodManager::Get(); | |
154 ComponentExtensionIMEManager* comp_ext_ime_manager = | |
155 manager->GetComponentExtensionIMEManager(); | |
156 | |
157 if (comp_ext_ime_manager->IsWhitelistedExtension(extension_id)) { | |
158 imm_id_ = comp_ext_ime_manager->GetId(extension_id, engine_id); | |
159 } else { | |
160 imm_id_ = extension_ime_util::GetInputMethodID(extension_id, engine_id); | |
161 } | |
162 | |
163 input_view_url_ = input_view; | |
164 descriptor_ = input_method::InputMethodDescriptor( | |
165 imm_id_, | |
166 engine_name, | |
167 std::string(), // TODO(uekawa): Set short name. | |
168 layouts, | |
169 languages, | |
170 extension_ime_util::IsKeyboardLayoutExtension( | |
171 imm_id_), // is_login_keyboard | |
172 options_page, | |
173 input_view); | |
174 | |
175 // TODO(komatsu): It is probably better to call AddInputMethodExtension | |
176 // out of Initialize. | |
177 manager->AddInputMethodExtension(profile, imm_id_, this); | |
178 } | |
179 | |
180 const input_method::InputMethodDescriptor& InputMethodEngine::GetDescriptor() | |
181 const { | |
182 return descriptor_; | |
183 } | 137 } |
184 | 138 |
185 void InputMethodEngine::RecordHistogram(const char* name, int count) { | 139 void InputMethodEngine::RecordHistogram(const char* name, int count) { |
186 std::string histo_name = | 140 std::string histo_name = base::StringPrintf( |
187 base::StringPrintf("InputMethod.%s.%s", name, engine_id_.c_str()); | 141 "InputMethod.%s.%s", name, active_component_id_.c_str()); |
188 base::HistogramBase* counter = base::Histogram::FactoryGet( | 142 base::HistogramBase* counter = base::Histogram::FactoryGet( |
189 histo_name, 0, 1000000, 50, base::HistogramBase::kNoFlags); | 143 histo_name, 0, 1000000, 50, base::HistogramBase::kNoFlags); |
190 if (counter) | 144 if (counter) |
191 counter->Add(count); | 145 counter->Add(count); |
192 } | 146 } |
193 | 147 |
194 void InputMethodEngine::NotifyImeReady() { | 148 const std::string& InputMethodEngine::GetActiveComponentId() const { |
195 input_method::InputMethodManager* manager = | 149 return active_component_id_; |
196 input_method::InputMethodManager::Get(); | |
197 if (manager && imm_id_ == manager->GetCurrentInputMethod().id()) | |
198 Enable(); | |
199 } | 150 } |
200 | 151 |
201 bool InputMethodEngine::SetComposition( | 152 bool InputMethodEngine::SetComposition( |
202 int context_id, | 153 int context_id, |
203 const char* text, | 154 const char* text, |
204 int selection_start, | 155 int selection_start, |
205 int selection_end, | 156 int selection_end, |
206 int cursor, | 157 int cursor, |
207 const std::vector<SegmentInfo>& segments, | 158 const std::vector<SegmentInfo>& segments, |
208 std::string* error) { | 159 std::string* error) { |
209 if (!active_) { | 160 if (!IsActive()) { |
210 *error = kErrorNotActive; | 161 *error = kErrorNotActive; |
211 return false; | 162 return false; |
212 } | 163 } |
213 if (context_id != context_id_ || context_id_ == -1) { | 164 if (context_id != context_id_ || context_id_ == -1) { |
214 *error = kErrorWrongContext; | 165 *error = kErrorWrongContext; |
215 return false; | 166 return false; |
216 } | 167 } |
217 | 168 |
218 composition_cursor_ = cursor; | 169 composition_cursor_ = cursor; |
219 composition_text_.reset(new CompositionText()); | 170 composition_text_.reset(new CompositionText()); |
(...skipping 23 matching lines...) Expand all Loading... | |
243 composition_text_->mutable_underline_attributes()->push_back(underline); | 194 composition_text_->mutable_underline_attributes()->push_back(underline); |
244 } | 195 } |
245 | 196 |
246 // TODO(nona): Makes focus out mode configuable, if necessary. | 197 // TODO(nona): Makes focus out mode configuable, if necessary. |
247 UpdateComposition(*composition_text_, composition_cursor_, true); | 198 UpdateComposition(*composition_text_, composition_cursor_, true); |
248 return true; | 199 return true; |
249 } | 200 } |
250 | 201 |
251 bool InputMethodEngine::ClearComposition(int context_id, | 202 bool InputMethodEngine::ClearComposition(int context_id, |
252 std::string* error) { | 203 std::string* error) { |
253 if (!active_) { | 204 if (!IsActive()) { |
254 *error = kErrorNotActive; | 205 *error = kErrorNotActive; |
255 return false; | 206 return false; |
256 } | 207 } |
257 if (context_id != context_id_ || context_id_ == -1) { | 208 if (context_id != context_id_ || context_id_ == -1) { |
258 *error = kErrorWrongContext; | 209 *error = kErrorWrongContext; |
259 return false; | 210 return false; |
260 } | 211 } |
261 | 212 |
262 composition_cursor_ = 0; | 213 composition_cursor_ = 0; |
263 composition_text_.reset(new CompositionText()); | 214 composition_text_.reset(new CompositionText()); |
264 UpdateComposition(*composition_text_, composition_cursor_, false); | 215 UpdateComposition(*composition_text_, composition_cursor_, false); |
265 return true; | 216 return true; |
266 } | 217 } |
267 | 218 |
268 bool InputMethodEngine::CommitText(int context_id, const char* text, | 219 bool InputMethodEngine::CommitText(int context_id, const char* text, |
269 std::string* error) { | 220 std::string* error) { |
270 if (!active_) { | 221 if (!IsActive()) { |
271 // TODO: Commit the text anyways. | 222 // TODO: Commit the text anyways. |
272 *error = kErrorNotActive; | 223 *error = kErrorNotActive; |
273 return false; | 224 return false; |
274 } | 225 } |
275 if (context_id != context_id_ || context_id_ == -1) { | 226 if (context_id != context_id_ || context_id_ == -1) { |
276 *error = kErrorWrongContext; | 227 *error = kErrorWrongContext; |
277 return false; | 228 return false; |
278 } | 229 } |
279 | 230 |
280 IMEBridge::Get()->GetInputContextHandler()->CommitText(text); | 231 IMEBridge::Get()->GetInputContextHandler()->CommitText(text); |
281 | 232 |
282 // Records times for using input method. | 233 // Records times for using input method. |
283 if (!start_time_.ToInternalValue()) | 234 if (!start_time_.ToInternalValue()) |
284 start_time_ = base::Time::Now(); | 235 start_time_ = base::Time::Now(); |
285 end_time_ = base::Time::Now(); | 236 end_time_ = base::Time::Now(); |
286 // Records histograms for counts of commits and committed characters. | 237 // Records histograms for counts of commits and committed characters. |
287 RecordHistogram("Commit", 1); | 238 RecordHistogram("Commit", 1); |
288 RecordHistogram("CommitCharacter", GetUtf8StringLength(text)); | 239 RecordHistogram("CommitCharacter", GetUtf8StringLength(text)); |
289 return true; | 240 return true; |
290 } | 241 } |
291 | 242 |
292 bool InputMethodEngine::SendKeyEvents( | 243 bool InputMethodEngine::SendKeyEvents( |
293 int context_id, | 244 int context_id, |
294 const std::vector<KeyboardEvent>& events) { | 245 const std::vector<KeyboardEvent>& events) { |
295 if (!active_) { | 246 if (!IsActive()) { |
296 return false; | 247 return false; |
297 } | 248 } |
298 // context_id == 0, means sending key events to non-input field. | 249 // context_id == 0, means sending key events to non-input field. |
299 // context_id_ == -1, means the focus is not in an input field. | 250 // context_id_ == -1, means the focus is not in an input field. |
300 if (context_id != 0 && (context_id != context_id_ || context_id_ == -1)) { | 251 if (context_id != 0 && (context_id != context_id_ || context_id_ == -1)) { |
301 return false; | 252 return false; |
302 } | 253 } |
303 | 254 |
304 ui::EventProcessor* dispatcher = | 255 ui::EventProcessor* dispatcher = |
305 ash::Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); | 256 ash::Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 dest_property.show_window_at_composition = | 305 dest_property.show_window_at_composition = |
355 property.show_window_at_composition; | 306 property.show_window_at_composition; |
356 dest_property.cursor_position = | 307 dest_property.cursor_position = |
357 candidate_window_->GetProperty().cursor_position; | 308 candidate_window_->GetProperty().cursor_position; |
358 dest_property.auxiliary_text = property.auxiliary_text; | 309 dest_property.auxiliary_text = property.auxiliary_text; |
359 dest_property.is_auxiliary_text_visible = property.is_auxiliary_text_visible; | 310 dest_property.is_auxiliary_text_visible = property.is_auxiliary_text_visible; |
360 | 311 |
361 candidate_window_->SetProperty(dest_property); | 312 candidate_window_->SetProperty(dest_property); |
362 candidate_window_property_ = property; | 313 candidate_window_property_ = property; |
363 | 314 |
364 if (active_) { | 315 if (IsActive()) { |
365 IMECandidateWindowHandlerInterface* cw_handler = | 316 IMECandidateWindowHandlerInterface* cw_handler = |
366 IMEBridge::Get()->GetCandidateWindowHandler(); | 317 IMEBridge::Get()->GetCandidateWindowHandler(); |
367 if (cw_handler) | 318 if (cw_handler) |
368 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_); | 319 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_); |
369 } | 320 } |
370 } | 321 } |
371 | 322 |
372 bool InputMethodEngine::SetCandidateWindowVisible(bool visible, | 323 bool InputMethodEngine::SetCandidateWindowVisible(bool visible, |
373 std::string* error) { | 324 std::string* error) { |
374 if (!active_) { | 325 if (!IsActive()) { |
375 *error = kErrorNotActive; | 326 *error = kErrorNotActive; |
376 return false; | 327 return false; |
377 } | 328 } |
378 | 329 |
379 window_visible_ = visible; | 330 window_visible_ = visible; |
380 IMECandidateWindowHandlerInterface* cw_handler = | 331 IMECandidateWindowHandlerInterface* cw_handler = |
381 IMEBridge::Get()->GetCandidateWindowHandler(); | 332 IMEBridge::Get()->GetCandidateWindowHandler(); |
382 if (cw_handler) | 333 if (cw_handler) |
383 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_); | 334 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_); |
384 return true; | 335 return true; |
385 } | 336 } |
386 | 337 |
387 bool InputMethodEngine::SetCandidates( | 338 bool InputMethodEngine::SetCandidates( |
388 int context_id, | 339 int context_id, |
389 const std::vector<Candidate>& candidates, | 340 const std::vector<Candidate>& candidates, |
390 std::string* error) { | 341 std::string* error) { |
391 if (!active_) { | 342 if (!IsActive()) { |
392 *error = kErrorNotActive; | 343 *error = kErrorNotActive; |
393 return false; | 344 return false; |
394 } | 345 } |
395 if (context_id != context_id_ || context_id_ == -1) { | 346 if (context_id != context_id_ || context_id_ == -1) { |
396 *error = kErrorWrongContext; | 347 *error = kErrorWrongContext; |
397 return false; | 348 return false; |
398 } | 349 } |
399 | 350 |
400 // TODO: Nested candidates | 351 // TODO: Nested candidates |
401 candidate_ids_.clear(); | 352 candidate_ids_.clear(); |
402 candidate_indexes_.clear(); | 353 candidate_indexes_.clear(); |
403 candidate_window_->mutable_candidates()->clear(); | 354 candidate_window_->mutable_candidates()->clear(); |
404 for (std::vector<Candidate>::const_iterator ix = candidates.begin(); | 355 for (std::vector<Candidate>::const_iterator ix = candidates.begin(); |
405 ix != candidates.end(); ++ix) { | 356 ix != candidates.end(); ++ix) { |
406 ui::CandidateWindow::Entry entry; | 357 ui::CandidateWindow::Entry entry; |
407 entry.value = base::UTF8ToUTF16(ix->value); | 358 entry.value = base::UTF8ToUTF16(ix->value); |
408 entry.label = base::UTF8ToUTF16(ix->label); | 359 entry.label = base::UTF8ToUTF16(ix->label); |
409 entry.annotation = base::UTF8ToUTF16(ix->annotation); | 360 entry.annotation = base::UTF8ToUTF16(ix->annotation); |
410 entry.description_title = base::UTF8ToUTF16(ix->usage.title); | 361 entry.description_title = base::UTF8ToUTF16(ix->usage.title); |
411 entry.description_body = base::UTF8ToUTF16(ix->usage.body); | 362 entry.description_body = base::UTF8ToUTF16(ix->usage.body); |
412 | 363 |
413 // Store a mapping from the user defined ID to the candidate index. | 364 // Store a mapping from the user defined ID to the candidate index. |
414 candidate_indexes_[ix->id] = candidate_ids_.size(); | 365 candidate_indexes_[ix->id] = candidate_ids_.size(); |
415 candidate_ids_.push_back(ix->id); | 366 candidate_ids_.push_back(ix->id); |
416 | 367 |
417 candidate_window_->mutable_candidates()->push_back(entry); | 368 candidate_window_->mutable_candidates()->push_back(entry); |
418 } | 369 } |
419 if (active_) { | 370 if (IsActive()) { |
420 IMECandidateWindowHandlerInterface* cw_handler = | 371 IMECandidateWindowHandlerInterface* cw_handler = |
421 IMEBridge::Get()->GetCandidateWindowHandler(); | 372 IMEBridge::Get()->GetCandidateWindowHandler(); |
422 if (cw_handler) | 373 if (cw_handler) |
423 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_); | 374 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_); |
424 } | 375 } |
425 return true; | 376 return true; |
426 } | 377 } |
427 | 378 |
428 bool InputMethodEngine::SetCursorPosition(int context_id, int candidate_id, | 379 bool InputMethodEngine::SetCursorPosition(int context_id, int candidate_id, |
429 std::string* error) { | 380 std::string* error) { |
430 if (!active_) { | 381 if (!IsActive()) { |
431 *error = kErrorNotActive; | 382 *error = kErrorNotActive; |
432 return false; | 383 return false; |
433 } | 384 } |
434 if (context_id != context_id_ || context_id_ == -1) { | 385 if (context_id != context_id_ || context_id_ == -1) { |
435 *error = kErrorWrongContext; | 386 *error = kErrorWrongContext; |
436 return false; | 387 return false; |
437 } | 388 } |
438 | 389 |
439 std::map<int, int>::const_iterator position = | 390 std::map<int, int>::const_iterator position = |
440 candidate_indexes_.find(candidate_id); | 391 candidate_indexes_.find(candidate_id); |
441 if (position == candidate_indexes_.end()) { | 392 if (position == candidate_indexes_.end()) { |
442 *error = kCandidateNotFound; | 393 *error = kCandidateNotFound; |
443 return false; | 394 return false; |
444 } | 395 } |
445 | 396 |
446 candidate_window_->set_cursor_position(position->second); | 397 candidate_window_->set_cursor_position(position->second); |
447 IMECandidateWindowHandlerInterface* cw_handler = | 398 IMECandidateWindowHandlerInterface* cw_handler = |
448 IMEBridge::Get()->GetCandidateWindowHandler(); | 399 IMEBridge::Get()->GetCandidateWindowHandler(); |
449 if (cw_handler) | 400 if (cw_handler) |
450 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_); | 401 cw_handler->UpdateLookupTable(*candidate_window_, window_visible_); |
451 return true; | 402 return true; |
452 } | 403 } |
453 | 404 |
454 bool InputMethodEngine::SetMenuItems(const std::vector<MenuItem>& items) { | 405 bool InputMethodEngine::SetMenuItems(const std::vector<MenuItem>& items) { |
455 return UpdateMenuItems(items); | 406 return UpdateMenuItems(items); |
456 } | 407 } |
457 | 408 |
458 bool InputMethodEngine::UpdateMenuItems( | 409 bool InputMethodEngine::UpdateMenuItems( |
459 const std::vector<MenuItem>& items) { | 410 const std::vector<MenuItem>& items) { |
460 if (!active_) | 411 if (!IsActive()) |
461 return false; | 412 return false; |
462 | 413 |
463 ash::ime::InputMethodMenuItemList menu_item_list; | 414 ash::ime::InputMethodMenuItemList menu_item_list; |
464 for (std::vector<MenuItem>::const_iterator item = items.begin(); | 415 for (std::vector<MenuItem>::const_iterator item = items.begin(); |
465 item != items.end(); ++item) { | 416 item != items.end(); ++item) { |
466 ash::ime::InputMethodMenuItem property; | 417 ash::ime::InputMethodMenuItem property; |
467 MenuItemToProperty(*item, &property); | 418 MenuItemToProperty(*item, &property); |
468 menu_item_list.push_back(property); | 419 menu_item_list.push_back(property); |
469 } | 420 } |
470 | 421 |
471 ash::ime::InputMethodMenuManager::GetInstance()-> | 422 ash::ime::InputMethodMenuManager::GetInstance()-> |
472 SetCurrentInputMethodMenuItemList( | 423 SetCurrentInputMethodMenuItemList( |
473 menu_item_list); | 424 menu_item_list); |
474 return true; | 425 return true; |
475 } | 426 } |
476 | 427 |
477 bool InputMethodEngine::IsActive() const { | 428 bool InputMethodEngine::IsActive() const { |
478 return active_; | 429 return !active_component_id_.empty(); |
479 } | 430 } |
480 | 431 |
481 bool InputMethodEngine::DeleteSurroundingText(int context_id, | 432 bool InputMethodEngine::DeleteSurroundingText(int context_id, |
482 int offset, | 433 int offset, |
483 size_t number_of_chars, | 434 size_t number_of_chars, |
484 std::string* error) { | 435 std::string* error) { |
485 if (!active_) { | 436 if (!IsActive()) { |
486 *error = kErrorNotActive; | 437 *error = kErrorNotActive; |
487 return false; | 438 return false; |
488 } | 439 } |
489 if (context_id != context_id_ || context_id_ == -1) { | 440 if (context_id != context_id_ || context_id_ == -1) { |
490 *error = kErrorWrongContext; | 441 *error = kErrorWrongContext; |
491 return false; | 442 return false; |
492 } | 443 } |
493 | 444 |
494 if (offset < 0 && static_cast<size_t>(-1 * offset) != size_t(number_of_chars)) | 445 if (offset < 0 && static_cast<size_t>(-1 * offset) != size_t(number_of_chars)) |
495 return false; // Currently we can only support preceding text. | 446 return false; // Currently we can only support preceding text. |
(...skipping 10 matching lines...) Expand all Loading... | |
506 | 457 |
507 void InputMethodEngine::HideInputView() { | 458 void InputMethodEngine::HideInputView() { |
508 keyboard::KeyboardController* keyboard_controller = | 459 keyboard::KeyboardController* keyboard_controller = |
509 keyboard::KeyboardController::GetInstance(); | 460 keyboard::KeyboardController::GetInstance(); |
510 if (keyboard_controller) { | 461 if (keyboard_controller) { |
511 keyboard_controller->HideKeyboard( | 462 keyboard_controller->HideKeyboard( |
512 keyboard::KeyboardController::HIDE_REASON_MANUAL); | 463 keyboard::KeyboardController::HIDE_REASON_MANUAL); |
513 } | 464 } |
514 } | 465 } |
515 | 466 |
516 void InputMethodEngine::EnableInputView(bool enabled) { | 467 void InputMethodEngine::EnableInputView() { |
517 const GURL& url = enabled ? input_view_url_ : GURL(); | 468 keyboard::SetOverrideContentUrl(input_method::InputMethodManager::Get() |
518 keyboard::SetOverrideContentUrl(url); | 469 ->GetCurrentInputMethod() |
470 .input_view_url()); | |
519 keyboard::KeyboardController* keyboard_controller = | 471 keyboard::KeyboardController* keyboard_controller = |
520 keyboard::KeyboardController::GetInstance(); | 472 keyboard::KeyboardController::GetInstance(); |
521 if (keyboard_controller) | 473 if (keyboard_controller) |
522 keyboard_controller->Reload(); | 474 keyboard_controller->Reload(); |
523 } | 475 } |
524 | 476 |
525 void InputMethodEngine::FocusIn( | 477 void InputMethodEngine::FocusIn( |
526 const IMEEngineHandlerInterface::InputContext& input_context) { | 478 const IMEEngineHandlerInterface::InputContext& input_context) { |
527 current_input_type_ = input_context.type; | 479 current_input_type_ = input_context.type; |
528 | 480 |
529 if (!active_ || current_input_type_ == ui::TEXT_INPUT_TYPE_NONE) | 481 if (!IsActive() || current_input_type_ == ui::TEXT_INPUT_TYPE_NONE) |
530 return; | 482 return; |
531 | 483 |
532 context_id_ = next_context_id_; | 484 context_id_ = next_context_id_; |
533 ++next_context_id_; | 485 ++next_context_id_; |
534 | 486 |
535 InputMethodEngineInterface::InputContext context; | 487 InputMethodEngineInterface::InputContext context; |
536 context.id = context_id_; | 488 context.id = context_id_; |
537 switch (current_input_type_) { | 489 switch (current_input_type_) { |
538 case ui::TEXT_INPUT_TYPE_SEARCH: | 490 case ui::TEXT_INPUT_TYPE_SEARCH: |
539 context.type = "search"; | 491 context.type = "search"; |
(...skipping 15 matching lines...) Expand all Loading... | |
555 break; | 507 break; |
556 default: | 508 default: |
557 context.type = "text"; | 509 context.type = "text"; |
558 break; | 510 break; |
559 } | 511 } |
560 | 512 |
561 observer_->OnFocus(context); | 513 observer_->OnFocus(context); |
562 } | 514 } |
563 | 515 |
564 void InputMethodEngine::FocusOut() { | 516 void InputMethodEngine::FocusOut() { |
565 if (!active_ || current_input_type_ == ui::TEXT_INPUT_TYPE_NONE) | 517 if (!IsActive() || current_input_type_ == ui::TEXT_INPUT_TYPE_NONE) |
566 return; | 518 return; |
567 | 519 |
568 current_input_type_ = ui::TEXT_INPUT_TYPE_NONE; | 520 current_input_type_ = ui::TEXT_INPUT_TYPE_NONE; |
569 | 521 |
570 int context_id = context_id_; | 522 int context_id = context_id_; |
571 context_id_ = -1; | 523 context_id_ = -1; |
572 observer_->OnBlur(context_id); | 524 observer_->OnBlur(context_id); |
573 } | 525 } |
574 | 526 |
575 void InputMethodEngine::Enable() { | 527 void InputMethodEngine::Enable(const std::string& component_id) { |
576 active_ = true; | 528 DCHECK(!component_id.empty()); |
577 observer_->OnActivate(engine_id_); | 529 active_component_id_ = component_id; |
530 observer_->OnActivate(component_id); | |
578 current_input_type_ = IMEBridge::Get()->GetCurrentTextInputType(); | 531 current_input_type_ = IMEBridge::Get()->GetCurrentTextInputType(); |
579 FocusIn(IMEEngineHandlerInterface::InputContext( | 532 FocusIn(IMEEngineHandlerInterface::InputContext( |
580 current_input_type_, ui::TEXT_INPUT_MODE_DEFAULT)); | 533 current_input_type_, ui::TEXT_INPUT_MODE_DEFAULT)); |
581 EnableInputView(true); | 534 EnableInputView(); |
582 | 535 |
583 start_time_ = base::Time(); | 536 start_time_ = base::Time(); |
584 end_time_ = base::Time(); | 537 end_time_ = base::Time(); |
585 RecordHistogram("Enable", 1); | 538 RecordHistogram("Enable", 1); |
586 } | 539 } |
587 | 540 |
588 void InputMethodEngine::Disable() { | 541 void InputMethodEngine::Disable() { |
589 active_ = false; | 542 active_component_id_ = ""; |
Yuki
2014/08/06 04:42:23
active_component_id_.clear() could be slightly bet
Shu Chen
2014/08/06 05:45:03
Done.
| |
590 observer_->OnDeactivated(engine_id_); | 543 observer_->OnDeactivated(active_component_id_); |
591 | 544 |
592 if (start_time_.ToInternalValue()) | 545 if (start_time_.ToInternalValue()) |
593 RecordHistogram("WorkingTime", (end_time_ - start_time_).InSeconds()); | 546 RecordHistogram("WorkingTime", (end_time_ - start_time_).InSeconds()); |
594 } | 547 } |
595 | 548 |
596 void InputMethodEngine::PropertyActivate(const std::string& property_name) { | 549 void InputMethodEngine::PropertyActivate(const std::string& property_name) { |
597 observer_->OnMenuItemActivated(engine_id_, property_name); | 550 observer_->OnMenuItemActivated(active_component_id_, property_name); |
598 } | 551 } |
599 | 552 |
600 void InputMethodEngine::Reset() { | 553 void InputMethodEngine::Reset() { |
601 observer_->OnReset(engine_id_); | 554 observer_->OnReset(active_component_id_); |
602 } | 555 } |
603 | 556 |
604 void InputMethodEngine::ProcessKeyEvent( | 557 void InputMethodEngine::ProcessKeyEvent( |
605 const ui::KeyEvent& key_event, | 558 const ui::KeyEvent& key_event, |
606 const KeyEventDoneCallback& callback) { | 559 const KeyEventDoneCallback& callback) { |
607 | 560 |
608 KeyEventDoneCallback *handler = new KeyEventDoneCallback(); | 561 KeyEventDoneCallback *handler = new KeyEventDoneCallback(); |
609 *handler = callback; | 562 *handler = callback; |
610 | 563 |
611 KeyboardEvent ext_event; | 564 KeyboardEvent ext_event; |
612 GetExtensionKeyboardEventFromKeyEvent(key_event, &ext_event); | 565 GetExtensionKeyboardEventFromKeyEvent(key_event, &ext_event); |
613 | 566 |
614 // If the given key event is equal to the key event sent by | 567 // If the given key event is equal to the key event sent by |
615 // SendKeyEvents, this engine ID is propagated to the extension IME. | 568 // SendKeyEvents, this engine ID is propagated to the extension IME. |
616 // Note, this check relies on that ui::KeyEvent is propagated as | 569 // Note, this check relies on that ui::KeyEvent is propagated as |
617 // reference without copying. | 570 // reference without copying. |
618 if (&key_event == sent_key_event_) | 571 if (&key_event == sent_key_event_) |
619 ext_event.extension_id = extension_id_; | 572 ext_event.extension_id = extension_id_; |
620 | 573 |
621 observer_->OnKeyEvent( | 574 observer_->OnKeyEvent( |
622 engine_id_, | 575 active_component_id_, |
623 ext_event, | 576 ext_event, |
624 reinterpret_cast<input_method::KeyEventHandle*>(handler)); | 577 reinterpret_cast<input_method::KeyEventHandle*>(handler)); |
625 } | 578 } |
626 | 579 |
627 void InputMethodEngine::CandidateClicked(uint32 index) { | 580 void InputMethodEngine::CandidateClicked(uint32 index) { |
628 if (index > candidate_ids_.size()) { | 581 if (index > candidate_ids_.size()) { |
629 return; | 582 return; |
630 } | 583 } |
631 | 584 |
632 // Only left button click is supported at this moment. | 585 // Only left button click is supported at this moment. |
633 observer_->OnCandidateClicked( | 586 observer_->OnCandidateClicked( |
634 engine_id_, candidate_ids_.at(index), MOUSE_BUTTON_LEFT); | 587 active_component_id_, candidate_ids_.at(index), MOUSE_BUTTON_LEFT); |
635 } | 588 } |
636 | 589 |
637 void InputMethodEngine::SetSurroundingText(const std::string& text, | 590 void InputMethodEngine::SetSurroundingText(const std::string& text, |
638 uint32 cursor_pos, | 591 uint32 cursor_pos, |
639 uint32 anchor_pos) { | 592 uint32 anchor_pos) { |
640 observer_->OnSurroundingTextChanged(engine_id_, | 593 observer_->OnSurroundingTextChanged(active_component_id_, |
641 text, | 594 text, |
642 static_cast<int>(cursor_pos), | 595 static_cast<int>(cursor_pos), |
643 static_cast<int>(anchor_pos)); | 596 static_cast<int>(anchor_pos)); |
644 } | 597 } |
645 | 598 |
646 // TODO(uekawa): rename this method to a more reasonable name. | 599 // TODO(uekawa): rename this method to a more reasonable name. |
647 void InputMethodEngine::MenuItemToProperty( | 600 void InputMethodEngine::MenuItemToProperty( |
648 const MenuItem& item, | 601 const MenuItem& item, |
649 ash::ime::InputMethodMenuItem* property) { | 602 ash::ime::InputMethodMenuItem* property) { |
650 property->key = item.id; | 603 property->key = item.id; |
(...skipping 28 matching lines...) Expand all Loading... | |
679 // TODO(nona): Implement it. | 632 // TODO(nona): Implement it. |
680 break; | 633 break; |
681 } | 634 } |
682 } | 635 } |
683 } | 636 } |
684 | 637 |
685 // TODO(nona): Support item.children. | 638 // TODO(nona): Support item.children. |
686 } | 639 } |
687 | 640 |
688 } // namespace chromeos | 641 } // namespace chromeos |
OLD | NEW |