| 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.h" | 5 #include "chrome/renderer/spellchecker/spellcheck.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 12 #include "chrome/common/spellcheck_common.h" | 12 #include "chrome/common/spellcheck_common.h" |
| 13 #include "chrome/common/spellcheck_messages.h" | 13 #include "chrome/common/spellcheck_messages.h" |
| 14 #include "chrome/common/spellcheck_result.h" |
| 14 #include "content/public/renderer/render_thread.h" | 15 #include "content/public/renderer/render_thread.h" |
| 15 #include "third_party/hunspell/src/hunspell/hunspell.hxx" | 16 #include "third_party/hunspell/src/hunspell/hunspell.hxx" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult
.h" | |
| 17 | 17 |
| 18 using base::TimeTicks; | 18 using base::TimeTicks; |
| 19 using content::RenderThread; | 19 using content::RenderThread; |
| 20 | 20 |
| 21 SpellCheck::SpellCheck() | 21 SpellCheck::SpellCheck() |
| 22 : file_(base::kInvalidPlatformFileValue), | 22 : file_(base::kInvalidPlatformFileValue), |
| 23 auto_spell_correct_turned_on_(false), | 23 auto_spell_correct_turned_on_(false), |
| 24 is_using_platform_spelling_engine_(false), | 24 is_using_platform_spelling_engine_(false), |
| 25 initialized_(false) { | 25 initialized_(false) { |
| 26 // Wait till we check the first word before doing any initializing. | 26 // Wait till we check the first word before doing any initializing. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 FillSuggestionList(word, optional_suggestions); | 141 FillSuggestionList(word, optional_suggestions); |
| 142 return false; | 142 return false; |
| 143 } | 143 } |
| 144 | 144 |
| 145 return true; | 145 return true; |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool SpellCheck::SpellCheckParagraph( | 148 bool SpellCheck::SpellCheckParagraph( |
| 149 const string16& text, | 149 const string16& text, |
| 150 int tag, | 150 int tag, |
| 151 std::vector<WebKit::WebTextCheckingResult>* results) { | 151 std::vector<SpellCheckResult>* results) { |
| 152 #if !defined(OS_MACOSX) | 152 #if !defined(OS_MACOSX) |
| 153 // Mac has its own spell checker, so this method will not be used. | 153 // Mac has its own spell checker, so this method will not be used. |
| 154 | 154 |
| 155 DCHECK(results); | 155 DCHECK(results); |
| 156 | 156 |
| 157 size_t length = text.length(); | 157 size_t length = text.length(); |
| 158 size_t offset = 0; | 158 size_t offset = 0; |
| 159 | 159 |
| 160 // Spellcheck::SpellCheckWord() automatically breaks text into words and | 160 // Spellcheck::SpellCheckWord() automatically breaks text into words and |
| 161 // checks the spellings of the extracted words. This function sets the | 161 // checks the spellings of the extracted words. This function sets the |
| 162 // position and length of the first misspelled word and returns false when | 162 // position and length of the first misspelled word and returns false when |
| 163 // the text includes misspelled words. Therefore, we just repeat calling the | 163 // the text includes misspelled words. Therefore, we just repeat calling the |
| 164 // function until it returns true to check the whole text. | 164 // function until it returns true to check the whole text. |
| 165 int misspelling_start = 0; | 165 int misspelling_start = 0; |
| 166 int misspelling_length = 0; | 166 int misspelling_length = 0; |
| 167 while (offset <= length) { | 167 while (offset <= length) { |
| 168 if (SpellCheckWord(&text[offset], | 168 if (SpellCheckWord(&text[offset], |
| 169 length - offset, | 169 length - offset, |
| 170 0, | 170 0, |
| 171 &misspelling_start, | 171 &misspelling_start, |
| 172 &misspelling_length, | 172 &misspelling_length, |
| 173 NULL)) { | 173 NULL)) { |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 | 176 |
| 177 if (results) { | 177 if (results) { |
| 178 results->push_back(WebKit::WebTextCheckingResult( | 178 results->push_back(SpellCheckResult( |
| 179 WebKit::WebTextCheckingTypeSpelling, | 179 SpellCheckResult::Spelling, |
| 180 misspelling_start + offset, | 180 misspelling_start + offset, |
| 181 misspelling_length)); | 181 misspelling_length)); |
| 182 } | 182 } |
| 183 offset += misspelling_start + misspelling_length; | 183 offset += misspelling_start + misspelling_length; |
| 184 } | 184 } |
| 185 | 185 |
| 186 return false; | 186 return false; |
| 187 #else | 187 #else |
| 188 return true; | 188 return true; |
| 189 #endif | 189 #endif |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 360 |
| 361 string16 word; | 361 string16 word; |
| 362 int word_start; | 362 int word_start; |
| 363 int word_length; | 363 int word_length; |
| 364 while (contraction_iterator_.GetNextWord(&word, &word_start, &word_length)) { | 364 while (contraction_iterator_.GetNextWord(&word, &word_start, &word_length)) { |
| 365 if (!CheckSpelling(word, tag)) | 365 if (!CheckSpelling(word, tag)) |
| 366 return false; | 366 return false; |
| 367 } | 367 } |
| 368 return true; | 368 return true; |
| 369 } | 369 } |
| OLD | NEW |