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/custom_dictionary_engine.h" | 5 #include "chrome/renderer/spellchecker/custom_dictionary_engine.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 | 9 |
10 CustomDictionaryEngine::CustomDictionaryEngine() { | 10 CustomDictionaryEngine::CustomDictionaryEngine() { |
11 } | 11 } |
12 | 12 |
13 CustomDictionaryEngine::~CustomDictionaryEngine() { | 13 CustomDictionaryEngine::~CustomDictionaryEngine() { |
14 } | 14 } |
15 | 15 |
16 void CustomDictionaryEngine::Init( | 16 void CustomDictionaryEngine::Init(const std::set<std::string>& custom_words) { |
17 const std::vector<std::string>& custom_words) { | |
18 // SpellingMenuOberver calls UTF16ToUTF8(word) to convert words for storage, | 17 // SpellingMenuOberver calls UTF16ToUTF8(word) to convert words for storage, |
19 // synchronization, and use in the custom dictionary engine. Since | 18 // synchronization, and use in the custom dictionary engine. Since |
20 // (UTF8ToUTF16(UTF16ToUTF8(word)) == word) holds, the engine does not need to | 19 // (UTF8ToUTF16(UTF16ToUTF8(word)) == word) holds, the engine does not need to |
21 // normalize the strings. | 20 // normalize the strings. |
22 for (std::vector<std::string>::const_iterator it = custom_words.begin(); | 21 for (std::set<std::string>::const_iterator it = custom_words.begin(); |
23 it != custom_words.end(); | 22 it != custom_words.end(); |
24 ++it) { | 23 ++it) { |
25 dictionary_.insert(UTF8ToUTF16(*it)); | 24 dictionary_.insert(UTF8ToUTF16(*it)); |
26 } | 25 } |
27 } | 26 } |
28 | 27 |
29 void CustomDictionaryEngine::OnCustomDictionaryChanged( | 28 void CustomDictionaryEngine::OnCustomDictionaryChanged( |
30 const std::vector<std::string>& words_added, | 29 const std::vector<std::string>& words_added, |
31 const std::vector<std::string>& words_removed) { | 30 const std::vector<std::string>& words_removed) { |
32 for (std::vector<std::string>::const_iterator it = words_added.begin(); | 31 for (std::vector<std::string>::const_iterator it = words_added.begin(); |
(...skipping 17 matching lines...) Expand all Loading... |
50 | 49 |
51 // The text to be checked is empty on OSX(async) right now. | 50 // The text to be checked is empty on OSX(async) right now. |
52 // TODO(groby): Fix as part of async hook-up. (http://crbug.com/178241) | 51 // TODO(groby): Fix as part of async hook-up. (http://crbug.com/178241) |
53 if (text16.empty()) | 52 if (text16.empty()) |
54 return false; | 53 return false; |
55 DCHECK(text16.length() >= size_t(misspelling_start + misspelling_len)); | 54 DCHECK(text16.length() >= size_t(misspelling_start + misspelling_len)); |
56 return misspelling_start >= 0 && | 55 return misspelling_start >= 0 && |
57 misspelling_len > 0 && | 56 misspelling_len > 0 && |
58 dictionary_.count(text16.substr(misspelling_start, misspelling_len)) > 0; | 57 dictionary_.count(text16.substr(misspelling_start, misspelling_len)) > 0; |
59 } | 58 } |
OLD | NEW |