OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/spellchecker/spellcheck_language.h" | 5 #include "chrome/renderer/spellchecker/spellcheck_language.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h" | 8 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h" |
9 #include "chrome/renderer/spellchecker/spelling_engine.h" | 9 #include "chrome/renderer/spellchecker/spelling_engine.h" |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 int word_length; | 60 int word_length; |
61 if (!text_iterator_.IsInitialized() && | 61 if (!text_iterator_.IsInitialized() && |
62 !text_iterator_.Initialize(&character_attributes_, true)) { | 62 !text_iterator_.Initialize(&character_attributes_, true)) { |
63 // We failed to initialize text_iterator_, return as spelled correctly. | 63 // We failed to initialize text_iterator_, return as spelled correctly. |
64 VLOG(1) << "Failed to initialize SpellcheckWordIterator"; | 64 VLOG(1) << "Failed to initialize SpellcheckWordIterator"; |
65 return true; | 65 return true; |
66 } | 66 } |
67 | 67 |
68 text_iterator_.SetText(in_word, in_word_len); | 68 text_iterator_.SetText(in_word, in_word_len); |
69 DCHECK(platform_spelling_engine_.get()); | 69 DCHECK(platform_spelling_engine_.get()); |
70 while (text_iterator_.GetNextWord(&word, &word_start, &word_length)) { | 70 for (SpellcheckWordIterator::WordIteratorStatus status = |
| 71 text_iterator_.GetNextWord(&word, &word_start, &word_length); |
| 72 status != SpellcheckWordIterator::IS_END_OF_TEXT; |
| 73 status = text_iterator_.GetNextWord(&word, &word_start, &word_length)) { |
| 74 // Found a character that is not able to be spellchecked so skip it. |
| 75 if (status == SpellcheckWordIterator::IS_SKIPPABLE) |
| 76 continue; |
| 77 |
71 // Found a word (or a contraction) that the spellchecker can check the | 78 // Found a word (or a contraction) that the spellchecker can check the |
72 // spelling of. | 79 // spelling of. |
73 if (platform_spelling_engine_->CheckSpelling(word, tag)) | 80 if (platform_spelling_engine_->CheckSpelling(word, tag)) |
74 continue; | 81 continue; |
75 | 82 |
76 // If the given word is a concatenated word of two or more valid words | 83 // If the given word is a concatenated word of two or more valid words |
77 // (e.g. "hello:hello"), we should treat it as a valid word. | 84 // (e.g. "hello:hello"), we should treat it as a valid word. |
78 if (IsValidContraction(word, tag)) | 85 if (IsValidContraction(word, tag)) |
79 continue; | 86 continue; |
80 | 87 |
(...skipping 24 matching lines...) Expand all Loading... |
105 return true; | 112 return true; |
106 } | 113 } |
107 | 114 |
108 contraction_iterator_.SetText(contraction.c_str(), contraction.length()); | 115 contraction_iterator_.SetText(contraction.c_str(), contraction.length()); |
109 | 116 |
110 base::string16 word; | 117 base::string16 word; |
111 int word_start; | 118 int word_start; |
112 int word_length; | 119 int word_length; |
113 | 120 |
114 DCHECK(platform_spelling_engine_.get()); | 121 DCHECK(platform_spelling_engine_.get()); |
115 while (contraction_iterator_.GetNextWord(&word, &word_start, &word_length)) { | 122 for (SpellcheckWordIterator::WordIteratorStatus status = |
| 123 contraction_iterator_.GetNextWord(&word, &word_start, &word_length); |
| 124 status != SpellcheckWordIterator::IS_END_OF_TEXT; |
| 125 status = contraction_iterator_.GetNextWord(&word, &word_start, |
| 126 &word_length)) { |
| 127 if (status == SpellcheckWordIterator::IS_SKIPPABLE) |
| 128 continue; |
| 129 |
116 if (!platform_spelling_engine_->CheckSpelling(word, tag)) | 130 if (!platform_spelling_engine_->CheckSpelling(word, tag)) |
117 return false; | 131 return false; |
118 } | 132 } |
119 return true; | 133 return true; |
120 } | 134 } |
121 | 135 |
122 bool SpellcheckLanguage::IsEnabled() { | 136 bool SpellcheckLanguage::IsEnabled() { |
123 DCHECK(platform_spelling_engine_.get()); | 137 DCHECK(platform_spelling_engine_.get()); |
124 return platform_spelling_engine_->IsEnabled(); | 138 return platform_spelling_engine_->IsEnabled(); |
125 } | 139 } |
OLD | NEW |