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

Side by Side Diff: ui/base/ime/chromeos/character_composer.cc

Issue 1284433002: Revise ui::DomKey to unify character and non-character codes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IsDead Created 5 years, 3 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 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
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
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 int32_t character = -1;
217 if (keystroke.IsDeadKey()) {
218 tree_index += 2 * data_.tree[tree_index] + 1; // internal unicode table 218 tree_index += 2 * data_.tree[tree_index] + 1; // internal unicode table
219 tree_index += 2 * data_.tree[tree_index] + 1; // leaf unicode table 219 tree_index += 2 * data_.tree[tree_index] + 1; // leaf unicode table
220 } else if (keystroke.key != ui::DomKey::CHARACTER) { 220 character = keystroke.ToDeadKeyCombiningCharacter();
221 } else if (keystroke.IsCharacter()) {
222 character = keystroke.ToCharacter();
223 }
224 if (character < 0 || character > 0xFFFF)
221 return CheckSequenceResult::NO_MATCH; 225 return CheckSequenceResult::NO_MATCH;
222 }
223 226
224 // Check the internal subtree table. 227 // Check the internal subtree table.
225 uint16_t result = 0; 228 uint16_t result = 0;
226 uint16_t entries = data_.tree[tree_index++]; 229 uint16_t entries = data_.tree[tree_index++];
227 if (entries && Find(tree_index, entries, keystroke.character, &result)) { 230 if (entries &&
231 Find(tree_index, entries, static_cast<uint16_t>(character), &result)) {
228 tree_index = result; 232 tree_index = result;
229 continue; 233 continue;
230 } 234 }
231 235
232 // Skip over the internal subtree table and check the leaf table. 236 // Skip over the internal subtree table and check the leaf table.
233 tree_index += 2 * entries; 237 tree_index += 2 * entries;
234 entries = data_.tree[tree_index++]; 238 entries = data_.tree[tree_index++];
235 if (entries && Find(tree_index, entries, keystroke.character, &result)) { 239 if (entries &&
240 Find(tree_index, entries, static_cast<uint16_t>(character), &result)) {
236 *composed_character = result; 241 *composed_character = result;
237 return CheckSequenceResult::FULL_MATCH; 242 return CheckSequenceResult::FULL_MATCH;
238 } 243 }
239 return CheckSequenceResult::NO_MATCH; 244 return CheckSequenceResult::NO_MATCH;
240 } 245 }
241 return CheckSequenceResult::PREFIX_MATCH; 246 return CheckSequenceResult::PREFIX_MATCH;
242 } 247 }
243 248
244 bool TreeComposeChecker::Find(uint16_t index, 249 bool TreeComposeChecker::Find(uint16_t index,
245 uint16_t size, 250 uint16_t size,
(...skipping 11 matching lines...) Expand all
257 const TableEntry target = {key, 0}; 262 const TableEntry target = {key, 0};
258 const TableEntry* it = std::lower_bound(a, z, target); 263 const TableEntry* it = std::lower_bound(a, z, target);
259 if ((it != z) && (it->key == key)) { 264 if ((it != z) && (it->key == key)) {
260 *value = it->value; 265 *value = it->value;
261 return true; 266 return true;
262 } 267 }
263 return false; 268 return false;
264 } 269 }
265 270
266 } // namespace ui 271 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/ime/chromeos/character_composer.h ('k') | ui/base/ime/chromeos/character_composer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698