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

Side by Side Diff: chrome/renderer/spellchecker/custom_dictionary_engine.cc

Issue 2159283003: [WIP][DO NOT LAND] Componentize spellcheck Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/spellchecker/custom_dictionary_engine.h"
6
7 #include <stddef.h>
8
9 #include "base/strings/utf_string_conversions.h"
10
11 CustomDictionaryEngine::CustomDictionaryEngine() {
12 }
13
14 CustomDictionaryEngine::~CustomDictionaryEngine() {
15 }
16
17 void CustomDictionaryEngine::Init(const std::set<std::string>& custom_words) {
18 dictionary_.clear();
19
20 // SpellingMenuOberver calls UTF16ToUTF8(word) to convert words for storage,
21 // synchronization, and use in the custom dictionary engine. Since
22 // (UTF8ToUTF16(UTF16ToUTF8(word)) == word) holds, the engine does not need to
23 // normalize the strings.
24 for (const std::string& word : custom_words)
25 dictionary_.insert(base::UTF8ToUTF16(word));
26 }
27
28 void CustomDictionaryEngine::OnCustomDictionaryChanged(
29 const std::set<std::string>& words_added,
30 const std::set<std::string>& words_removed) {
31 for (const std::string& word : words_added)
32 dictionary_.insert(base::UTF8ToUTF16(word));
33
34 for (const std::string& word : words_removed)
35 dictionary_.erase(base::UTF8ToUTF16(word));
36 }
37
38 bool CustomDictionaryEngine::SpellCheckWord(
39 const base::string16& text,
40 int misspelling_start,
41 int misspelling_len) {
42 // The text to be checked is empty on OSX(async) right now.
43 // TODO(groby): Fix as part of async hook-up. (http://crbug.com/178241)
44 return
45 misspelling_start >= 0 &&
46 misspelling_len > 0 &&
47 size_t(misspelling_start + misspelling_len) <= text.length() &&
48 dictionary_.count(text.substr(misspelling_start, misspelling_len)) > 0;
49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698