Chromium Code Reviews| 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 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #undef FocusIn | 9 #undef FocusIn |
| 10 #undef FocusOut | 10 #undef FocusOut |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 const char kErrorNotActive[] = "IME is not active"; | 49 const char kErrorNotActive[] = "IME is not active"; |
| 50 const char kErrorWrongContext[] = "Context is not active"; | 50 const char kErrorWrongContext[] = "Context is not active"; |
| 51 const char kCandidateNotFound[] = "Candidate not found"; | 51 const char kCandidateNotFound[] = "Candidate not found"; |
| 52 | 52 |
| 53 // The default entry number of a page in CandidateWindowProperty. | 53 // The default entry number of a page in CandidateWindowProperty. |
| 54 const int kDefaultPageSize = 9; | 54 const int kDefaultPageSize = 9; |
| 55 | 55 |
| 56 // Returns the length of characters of a UTF-8 string with unknown string | |
| 57 // length. Cannot apply faster algorithm to count characters in an utf-8 | |
| 58 // string without knowing the string length, so just does a full scan. | |
| 59 size_t GetUtf8StringLength(const char* s) { | |
|
Devlin
2016/02/04 00:09:17
Is this *really* that much faster than std::string
Azure Wei
2016/02/04 03:21:19
Abandoned these codes.
| |
| 60 size_t ret = 0; | |
| 61 while (*s) { | |
| 62 if ((*s & 0xC0) != 0x80) | |
| 63 ret++; | |
| 64 ++s; | |
| 65 } | |
| 66 return ret; | |
| 67 } | |
| 68 | |
| 56 } // namespace | 69 } // namespace |
| 57 | 70 |
| 58 InputMethodEngine::MenuItem::MenuItem() {} | 71 InputMethodEngine::MenuItem::MenuItem() {} |
| 59 | 72 |
| 60 InputMethodEngine::MenuItem::~MenuItem() {} | 73 InputMethodEngine::MenuItem::~MenuItem() {} |
| 61 | 74 |
| 62 InputMethodEngine::Candidate::Candidate() {} | 75 InputMethodEngine::Candidate::Candidate() {} |
| 63 | 76 |
| 64 InputMethodEngine::Candidate::~Candidate() {} | 77 InputMethodEngine::Candidate::~Candidate() {} |
| 65 | 78 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 case MENU_ITEM_STYLE_SEPARATOR: | 350 case MENU_ITEM_STYLE_SEPARATOR: |
| 338 // TODO(nona): Implement it. | 351 // TODO(nona): Implement it. |
| 339 break; | 352 break; |
| 340 } | 353 } |
| 341 } | 354 } |
| 342 } | 355 } |
| 343 | 356 |
| 344 // TODO(nona): Support item.children. | 357 // TODO(nona): Support item.children. |
| 345 } | 358 } |
| 346 | 359 |
| 360 void InputMethodEngine::UpdateComposition( | |
| 361 const ui::CompositionText& composition_text, | |
| 362 uint32_t cursor_pos, | |
| 363 bool is_visible) { | |
| 364 ui::IMEInputContextHandlerInterface* input_context = | |
| 365 ui::IMEBridge::Get()->GetInputContextHandler(); | |
| 366 if (input_context) | |
| 367 input_context->UpdateCompositionText(composition_text, cursor_pos, | |
| 368 is_visible); | |
| 369 } | |
| 370 | |
| 371 void InputMethodEngine::CommitTextToInputContext(int context_id, | |
| 372 const char* text) { | |
| 373 ui::IMEBridge::Get()->GetInputContextHandler()->CommitText(text); | |
| 374 | |
| 375 // Records histograms for committed characters. | |
| 376 if (!composition_text_->text.empty()) { | |
| 377 size_t len = GetUtf8StringLength(text); | |
| 378 UMA_HISTOGRAM_CUSTOM_COUNTS("InputMethod.CommitLength", len, 1, 25, 25); | |
| 379 composition_text_.reset(new ui::CompositionText()); | |
| 380 } | |
| 381 } | |
| 382 | |
| 347 } // namespace chromeos | 383 } // namespace chromeos |
| OLD | NEW |