| 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 "ui/base/ime/chromeos/character_composer.h" | 5 #include "ui/base/ime/chromeos/character_composer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 case HEX_MODE: | 103 case HEX_MODE: |
| 104 return FilterKeyPressHexMode(event); | 104 return FilterKeyPressHexMode(event); |
| 105 default: | 105 default: |
| 106 NOTREACHED(); | 106 NOTREACHED(); |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool CharacterComposer::FilterKeyPressSequenceMode(const KeyEvent& event) { | 111 bool CharacterComposer::FilterKeyPressSequenceMode(const KeyEvent& event) { |
| 112 DCHECK(composition_mode_ == KEY_SEQUENCE_MODE); | 112 DCHECK(composition_mode_ == KEY_SEQUENCE_MODE); |
| 113 compose_buffer_.push_back( | 113 compose_buffer_.push_back(event.GetDomKey()); |
| 114 KeystrokeMeaning(event.GetDomKey(), event.GetCharacter())); | |
| 115 | 114 |
| 116 // Check compose table. | 115 // Check compose table. |
| 117 uint32 composed_character_utf32 = 0; | 116 uint32 composed_character_utf32 = 0; |
| 118 if (CheckCharacterComposeTable(compose_buffer_, &composed_character_utf32)) { | 117 if (CheckCharacterComposeTable(compose_buffer_, &composed_character_utf32)) { |
| 119 // Key press is recognized as a part of composition. | 118 // Key press is recognized as a part of composition. |
| 120 if (composed_character_utf32 != 0) { | 119 if (composed_character_utf32 != 0) { |
| 121 // We get a composed character. | 120 // We get a composed character. |
| 122 compose_buffer_.clear(); | 121 compose_buffer_.clear(); |
| 123 UTF32CharacterToUTF16(composed_character_utf32, &composed_character_); | 122 UTF32CharacterToUTF16(composed_character_utf32, &composed_character_); |
| 124 } | 123 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 uint32_t* composed_character) const { | 206 uint32_t* composed_character) const { |
| 208 *composed_character = 0; | 207 *composed_character = 0; |
| 209 if (sequence.size() > data_.maximum_sequence_length) | 208 if (sequence.size() > data_.maximum_sequence_length) |
| 210 return CheckSequenceResult::NO_MATCH; | 209 return CheckSequenceResult::NO_MATCH; |
| 211 | 210 |
| 212 uint16_t tree_index = 0; | 211 uint16_t tree_index = 0; |
| 213 for (const auto& keystroke : sequence) { | 212 for (const auto& keystroke : sequence) { |
| 214 DCHECK(tree_index < data_.tree_entries); | 213 DCHECK(tree_index < data_.tree_entries); |
| 215 | 214 |
| 216 // If we are looking up a dead key, skip over the character tables. | 215 // If we are looking up a dead key, skip over the character tables. |
| 217 if (keystroke.key == ui::DomKey::DEAD) { | 216 if (keystroke.IsDead()) { |
| 218 tree_index += 2 * data_.tree[tree_index] + 1; // internal unicode table | 217 tree_index += 2 * data_.tree[tree_index] + 1; // internal unicode table |
| 219 tree_index += 2 * data_.tree[tree_index] + 1; // leaf unicode table | 218 tree_index += 2 * data_.tree[tree_index] + 1; // leaf unicode table |
| 220 } else if (keystroke.key != ui::DomKey::CHARACTER) { | 219 } else if (!keystroke.IsUnicode()) { |
| 221 return CheckSequenceResult::NO_MATCH; | 220 return CheckSequenceResult::NO_MATCH; |
| 222 } | 221 } |
| 223 | 222 |
| 224 // Check the internal subtree table. | 223 // Check the internal subtree table. |
| 225 uint16_t result = 0; | 224 uint16_t result = 0; |
| 226 uint16_t entries = data_.tree[tree_index++]; | 225 uint16_t entries = data_.tree[tree_index++]; |
| 227 if (entries && Find(tree_index, entries, keystroke.character, &result)) { | 226 if (entries && |
| 227 Find(tree_index, entries, keystroke.GetCodePoint(), &result)) { |
| 228 tree_index = result; | 228 tree_index = result; |
| 229 continue; | 229 continue; |
| 230 } | 230 } |
| 231 | 231 |
| 232 // Skip over the internal subtree table and check the leaf table. | 232 // Skip over the internal subtree table and check the leaf table. |
| 233 tree_index += 2 * entries; | 233 tree_index += 2 * entries; |
| 234 entries = data_.tree[tree_index++]; | 234 entries = data_.tree[tree_index++]; |
| 235 if (entries && Find(tree_index, entries, keystroke.character, &result)) { | 235 if (entries && |
| 236 Find(tree_index, entries, keystroke.GetCodePoint(), &result)) { |
| 236 *composed_character = result; | 237 *composed_character = result; |
| 237 return CheckSequenceResult::FULL_MATCH; | 238 return CheckSequenceResult::FULL_MATCH; |
| 238 } | 239 } |
| 239 return CheckSequenceResult::NO_MATCH; | 240 return CheckSequenceResult::NO_MATCH; |
| 240 } | 241 } |
| 241 return CheckSequenceResult::PREFIX_MATCH; | 242 return CheckSequenceResult::PREFIX_MATCH; |
| 242 } | 243 } |
| 243 | 244 |
| 244 bool TreeComposeChecker::Find(uint16_t index, | 245 bool TreeComposeChecker::Find(uint16_t index, |
| 245 uint16_t size, | 246 uint16_t size, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 257 const TableEntry target = {key, 0}; | 258 const TableEntry target = {key, 0}; |
| 258 const TableEntry* it = std::lower_bound(a, z, target); | 259 const TableEntry* it = std::lower_bound(a, z, target); |
| 259 if ((it != z) && (it->key == key)) { | 260 if ((it != z) && (it->key == key)) { |
| 260 *value = it->value; | 261 *value = it->value; |
| 261 return true; | 262 return true; |
| 262 } | 263 } |
| 263 return false; | 264 return false; |
| 264 } | 265 } |
| 265 | 266 |
| 266 } // namespace ui | 267 } // namespace ui |
| OLD | NEW |