OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "character_composer.h" | 5 #include "character_composer.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 | 8 |
9 #include "third_party/gtk+/gdk/gdkkeysyms.h" | 9 #include "third_party/gtk+/gdk/gdkkeysyms.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 inline int CompareSequenceValue(unsigned int key, uint16 value) { | 13 inline int CompareSequenceValue(unsigned int key, uint16 value) { |
14 return (key > value) ? 1 : ((key < value) ? -1 : 0); | 14 return (key > value) ? 1 : ((key < value) ? -1 : 0); |
15 } | 15 } |
16 | 16 |
17 class ComposeChecker { | 17 class ComposeChecker { |
18 public: | 18 public: |
19 ComposeChecker(const uint16* data, int max_sequence_length, int n_sequences); | 19 ComposeChecker(const uint16* data, int max_sequence_length, int n_sequences); |
brettw
2011/06/29 20:31:56
Can you clarify the ownership of "data" in a comme
hashimoto
2011/06/30 07:19:22
Fixed
| |
20 bool CheckSequence(const std::vector<unsigned int>& sequence, | 20 bool CheckSequence(const std::vector<unsigned int>& sequence, |
21 uint32* composed_character) const; | 21 uint32* composed_character) const; |
22 | 22 |
23 private: | 23 private: |
24 static int CompareSequence(const void* key_void, const void* value_void); | 24 static int CompareSequence(const void* key_void, const void* value_void); |
25 | 25 |
26 const uint16* data_; | 26 const uint16* data_; |
brettw
2011/06/29 20:31:56
I also like to make the ownership of member pointe
hashimoto
2011/06/30 07:19:22
Fixed
| |
27 int max_sequence_length_; | 27 int max_sequence_length_; |
28 int n_sequences_; | 28 int n_sequences_; |
29 int row_stride_; | 29 int row_stride_; |
30 | 30 |
31 DISALLOW_COPY_AND_ASSIGN(ComposeChecker); | 31 DISALLOW_COPY_AND_ASSIGN(ComposeChecker); |
32 }; | 32 }; |
33 | 33 |
34 ComposeChecker::ComposeChecker(const uint16* data, | 34 ComposeChecker::ComposeChecker(const uint16* data, |
35 int max_sequence_length, | 35 int max_sequence_length, |
36 int n_sequences) | 36 int n_sequences) |
(...skipping 30 matching lines...) Expand all Loading... | |
67 found[max_sequence_length_ + 1]; | 67 found[max_sequence_length_ + 1]; |
68 *composed_character = value; | 68 *composed_character = value; |
69 } | 69 } |
70 } | 70 } |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 // static | 74 // static |
75 int ComposeChecker::CompareSequence(const void* key_void, | 75 int ComposeChecker::CompareSequence(const void* key_void, |
76 const void* value_void) { | 76 const void* value_void) { |
77 typedef std::vector<unsigned int> KeyType; | 77 typedef std::vector<unsigned int> KeyType; |
brettw
2011/06/29 20:31:56
This typedef appears 3 times, does it make sense t
hashimoto
2011/06/30 07:19:22
typedef std::vector<unsigned int> ComposeBufferTyp
| |
78 const KeyType& key = *static_cast<const KeyType*>(key_void); | 78 const KeyType& key = *static_cast<const KeyType*>(key_void); |
79 const uint16* value = static_cast<const uint16*>(value_void); | 79 const uint16* value = static_cast<const uint16*>(value_void); |
80 | 80 |
81 for(size_t i = 0; i < key.size(); ++i) { | 81 for(size_t i = 0; i < key.size(); ++i) { |
82 const int compare_result = CompareSequenceValue(key[i], value[i]); | 82 const int compare_result = CompareSequenceValue(key[i], value[i]); |
83 if(compare_result) | 83 if(compare_result) |
84 return compare_result; | 84 return compare_result; |
85 } | 85 } |
86 return 0; | 86 return 0; |
87 } | 87 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 // Check for composition sequences | 135 // Check for composition sequences |
136 for (int length = compose_length - 1; length < max_sequence_length_; | 136 for (int length = compose_length - 1; length < max_sequence_length_; |
137 ++length) { | 137 ++length) { |
138 const uint16* table = data_ + index[length]; | 138 const uint16* table = data_ + index[length]; |
139 const uint16* table_next = data_ + index[length + 1]; | 139 const uint16* table_next = data_ + index[length + 1]; |
140 if (table_next > table) { | 140 if (table_next > table) { |
141 // There are composition sequences for this |length| | 141 // There are composition sequences for this |length| |
142 const int row_stride = length + 1; | 142 const int row_stride = length + 1; |
143 const int n_sequences = (table_next - table)/row_stride; | 143 const int n_sequences = (table_next - table)/row_stride; |
144 const uint16* seq = static_cast<const uint16*>( | 144 const uint16* seq = static_cast<const uint16*>( |
145 bsearch(&sequence, table, n_sequences, | 145 bsearch(&sequence, table, n_sequences, |
brettw
2011/06/29 20:31:56
This bsearch stuff is kind of awkward because you
hashimoto
2011/06/30 07:19:22
I use ugly bsearch instead of typesafe STL algorit
brettw
2011/07/01 22:21:18
A raw pointer is actually a valid iterator for STL
hashimoto
2011/07/04 04:45:20
Yes, that's true about operator<, but I could not
| |
146 sizeof(uint16)*row_stride, CompareSequenceSkipFront)); | 146 sizeof(uint16)*row_stride, CompareSequenceSkipFront)); |
147 if (seq) { | 147 if (seq) { |
148 if (length == compose_length - 1) // exact match | 148 if (length == compose_length - 1) // exact match |
149 *composed_character = seq[length]; | 149 *composed_character = seq[length]; |
150 return true; | 150 return true; |
151 } | 151 } |
152 } | 152 } |
153 } | 153 } |
154 return false; | 154 return false; |
155 } | 155 } |
(...skipping 20 matching lines...) Expand all Loading... | |
176 for(size_t i = 1; i < key.size(); ++i) { | 176 for(size_t i = 1; i < key.size(); ++i) { |
177 const int compare_result = CompareSequenceValue(key[i], value[i - 1]); | 177 const int compare_result = CompareSequenceValue(key[i], value[i - 1]); |
178 if(compare_result) | 178 if(compare_result) |
179 return compare_result; | 179 return compare_result; |
180 } | 180 } |
181 return 0; | 181 return 0; |
182 } | 182 } |
183 | 183 |
184 // Main table | 184 // Main table |
185 typedef uint16 guint16; | 185 typedef uint16 guint16; |
186 #include "third_party/gtk+/gtk/gtkimcontextsimpleseqs.h" | 186 #include "third_party/gtk+/gtk/gtkimcontextsimpleseqs.h" |
brettw
2011/06/29 20:31:56
It's not clear to me why this include is here in t
hashimoto
2011/06/30 07:19:22
Added #include "ui/base/gtk/gtk_integers.h" instea
| |
187 | 187 |
188 // Additional table | 188 // Additional table |
189 | 189 |
190 // The difference between this and the default input method is the handling | 190 // The difference between this and the default input method is the handling |
191 // of C+acute - this method produces C WITH CEDILLA rather than C WITH ACUTE. | 191 // of C+acute - this method produces C WITH CEDILLA rather than C WITH ACUTE. |
192 // For languages that use CCedilla and not acute, this is the preferred mapping, | 192 // For languages that use CCedilla and not acute, this is the preferred mapping, |
193 // and is particularly important for pt_BR, where the us-intl keyboard is | 193 // and is particularly important for pt_BR, where the us-intl keyboard is |
194 // used extensively. | 194 // used extensively. |
195 | 195 |
196 const uint16 cedilla_compose_seqs[] = { | 196 const uint16 cedilla_compose_seqs[] = { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 return true; | 229 return true; |
230 default: | 230 default: |
231 return false; | 231 return false; |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 bool CheckCharacterComposeTable(const std::vector<unsigned int>& sequence, | 235 bool CheckCharacterComposeTable(const std::vector<unsigned int>& sequence, |
236 uint32* composed_character) { | 236 uint32* composed_character) { |
237 // Check cedilla compose table | 237 // Check cedilla compose table |
238 const ComposeChecker kCedillaComposeChecker( | 238 const ComposeChecker kCedillaComposeChecker( |
239 cedilla_compose_seqs, 4, arraysize(cedilla_compose_seqs)/(4 + 2)); | 239 cedilla_compose_seqs, 4, arraysize(cedilla_compose_seqs)/(4 + 2)); |
brettw
2011/06/29 20:31:56
Wrapped lines should be indented 4 spaces.
hashimoto
2011/06/30 07:19:22
Fixed
| |
240 if (kCedillaComposeChecker.CheckSequence(sequence, composed_character)) | 240 if (kCedillaComposeChecker.CheckSequence(sequence, composed_character)) |
241 return true; | 241 return true; |
242 | 242 |
243 // Check main compose table | 243 // Check main compose table |
244 const ComposeCheckerWithCompactTable kMainComposeChecker( | 244 const ComposeCheckerWithCompactTable kMainComposeChecker( |
245 gtk_compose_seqs_compact, 5, 24, 6); | 245 gtk_compose_seqs_compact, 5, 24, 6); |
246 if (kMainComposeChecker.CheckSequence(sequence, composed_character)) | 246 if (kMainComposeChecker.CheckSequence(sequence, composed_character)) |
247 return true; | 247 return true; |
248 | 248 |
249 return false; | 249 return false; |
250 } | 250 } |
251 | 251 |
252 } // anonymous namespace | 252 } // anonymous namespace |
brettw
2011/06/29 20:31:56
You don't need the "anonymous" here, just "// name
hashimoto
2011/06/30 07:19:22
Fixed all two
| |
253 | 253 |
254 namespace views { | 254 namespace views { |
255 | 255 |
256 CharacterComposer::CharacterComposer() {} | 256 CharacterComposer::CharacterComposer() {} |
257 | 257 |
258 CharacterComposer::~CharacterComposer() {} | 258 CharacterComposer::~CharacterComposer() {} |
259 | 259 |
260 void CharacterComposer::Reset() { | 260 void CharacterComposer::Reset() { |
261 compose_buffer_.clear(); | 261 compose_buffer_.clear(); |
262 composed_character_.clear(); | 262 composed_character_.clear(); |
(...skipping 13 matching lines...) Expand all Loading... | |
276 if (composed_character_utf32 !=0) { | 276 if (composed_character_utf32 !=0) { |
277 // We get a composed character | 277 // We get a composed character |
278 compose_buffer_.clear(); | 278 compose_buffer_.clear(); |
279 // We assume that composed character is in BMP | 279 // We assume that composed character is in BMP |
280 if (composed_character_utf32 <= 0xffff) | 280 if (composed_character_utf32 <= 0xffff) |
281 composed_character_ += static_cast<char16>(composed_character_utf32); | 281 composed_character_ += static_cast<char16>(composed_character_utf32); |
282 } | 282 } |
283 return true; | 283 return true; |
284 } | 284 } |
285 // Key press is not a part of composition | 285 // Key press is not a part of composition |
286 compose_buffer_.pop_back(); // remove the keypress added this time | 286 compose_buffer_.pop_back(); // remove the keypress added this time |
brettw
2011/06/29 20:31:56
Please be sure all your comments begin with a capi
hashimoto
2011/06/30 07:19:22
Fixed
| |
287 if (!compose_buffer_.empty()) { | 287 if (!compose_buffer_.empty()) { |
288 compose_buffer_.clear(); | 288 compose_buffer_.clear(); |
289 return true; | 289 return true; |
290 } | 290 } |
291 return false; | 291 return false; |
292 } | 292 } |
293 | 293 |
294 } // namespace views | 294 } // namespace views |
295 // | |
brettw
2011/06/29 20:31:56
Be sure to delete this once you've made other chan
hashimoto
2011/06/30 07:19:22
Deleted all three.
| |
OLD | NEW |