OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 // This file implements the interface defined in spellchecker_platform_engine.h | 5 // This file implements the interface defined in spellchecker_platform_engine.h |
6 // for the OS X platform. | 6 // for the OS X platform. |
7 | 7 |
| 8 #include "chrome/browser/spellchecker_platform_engine.h" |
| 9 |
8 #import <Cocoa/Cocoa.h> | 10 #import <Cocoa/Cocoa.h> |
9 | 11 |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/time.h" | 13 #include "base/time.h" |
12 #include "base/histogram.h" | 14 #include "base/histogram.h" |
13 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
14 #include "chrome/browser/spellchecker_common.h" | 16 #include "chrome/common/spellcheck_common.h" |
15 #include "chrome/browser/spellchecker_platform_engine.h" | |
16 | 17 |
17 using base::TimeTicks; | 18 using base::TimeTicks; |
18 namespace { | 19 namespace { |
19 // The number of characters in the first part of the language code. | 20 // The number of characters in the first part of the language code. |
20 const unsigned int kShortLanguageCodeSize = 2; | 21 const unsigned int kShortLanguageCodeSize = 2; |
21 | 22 |
22 // A private utility function to convert hunspell language codes to os x | 23 // A private utility function to convert hunspell language codes to os x |
23 // language codes. | 24 // language codes. |
24 NSString* ConvertLanguageCodeToMac(const std::string& hunspell_lang_code) { | 25 NSString* ConvertLanguageCodeToMac(const std::string& hunspell_lang_code) { |
25 NSString* whole_code = base::SysUTF8ToNSString(hunspell_lang_code); | 26 NSString* whole_code = base::SysUTF8ToNSString(hunspell_lang_code); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 std::vector<string16>* optional_suggestions) { | 169 std::vector<string16>* optional_suggestions) { |
169 NSString* NS_wrong_word = base::SysUTF16ToNSString(wrong_word); | 170 NSString* NS_wrong_word = base::SysUTF16ToNSString(wrong_word); |
170 TimeTicks begin_time = TimeTicks::Now(); | 171 TimeTicks begin_time = TimeTicks::Now(); |
171 // The suggested words for |wrong_word|. | 172 // The suggested words for |wrong_word|. |
172 NSArray* guesses = | 173 NSArray* guesses = |
173 [[NSSpellChecker sharedSpellChecker] guessesForWord:NS_wrong_word]; | 174 [[NSSpellChecker sharedSpellChecker] guessesForWord:NS_wrong_word]; |
174 DHISTOGRAM_TIMES("Spellcheck.SuggestTime", | 175 DHISTOGRAM_TIMES("Spellcheck.SuggestTime", |
175 TimeTicks::Now() - begin_time); | 176 TimeTicks::Now() - begin_time); |
176 | 177 |
177 for (int i = 0; i < static_cast<int>([guesses count]); i++) { | 178 for (int i = 0; i < static_cast<int>([guesses count]); i++) { |
178 if (i < kMaxSuggestions) { | 179 if (i < SpellCheckCommon::kMaxSuggestions) { |
179 optional_suggestions->push_back(base::SysNSStringToUTF16( | 180 optional_suggestions->push_back(base::SysNSStringToUTF16( |
180 [guesses objectAtIndex:i])); | 181 [guesses objectAtIndex:i])); |
181 } | 182 } |
182 } | 183 } |
183 } | 184 } |
184 | 185 |
185 void AddWord(const string16& word) { | 186 void AddWord(const string16& word) { |
186 NSString* word_to_add = base::SysUTF16ToNSString(word); | 187 NSString* word_to_add = base::SysUTF16ToNSString(word); |
187 [[NSSpellChecker sharedSpellChecker] learnWord:word_to_add]; | 188 [[NSSpellChecker sharedSpellChecker] learnWord:word_to_add]; |
188 } | 189 } |
(...skipping 12 matching lines...) Expand all Loading... |
201 [[NSSpellChecker sharedSpellChecker] ignoreWord:base::SysUTF16ToNSString(word) | 202 [[NSSpellChecker sharedSpellChecker] ignoreWord:base::SysUTF16ToNSString(word) |
202 inSpellDocumentWithTag:last_seen_tag_]; | 203 inSpellDocumentWithTag:last_seen_tag_]; |
203 } | 204 } |
204 | 205 |
205 void CloseDocumentWithTag(int tag) { | 206 void CloseDocumentWithTag(int tag) { |
206 [[NSSpellChecker sharedSpellChecker] | 207 [[NSSpellChecker sharedSpellChecker] |
207 closeSpellDocumentWithTag:static_cast<NSInteger>(tag)]; | 208 closeSpellDocumentWithTag:static_cast<NSInteger>(tag)]; |
208 } | 209 } |
209 | 210 |
210 } // namespace SpellCheckerPlatform | 211 } // namespace SpellCheckerPlatform |
OLD | NEW |