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 // Integration with OS X native spellchecker. | 5 // Integration with OS X native spellchecker. |
6 | 6 |
7 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" | 7 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" |
8 | 8 |
9 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
15 #include "base/mac/scoped_nsexception_enabler.h" | 15 #include "base/mac/scoped_nsexception_enabler.h" |
16 #include "base/metrics/histogram.h" | |
17 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
18 #include "base/time/time.h" | 17 #include "base/time/time.h" |
19 #include "chrome/common/spellcheck_common.h" | 18 #include "chrome/common/spellcheck_common.h" |
20 #include "chrome/common/spellcheck_messages.h" | 19 #include "chrome/common/spellcheck_messages.h" |
21 #include "chrome/common/spellcheck_result.h" | 20 #include "chrome/common/spellcheck_result.h" |
22 #include "content/public/browser/browser_message_filter.h" | 21 #include "content/public/browser/browser_message_filter.h" |
23 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
24 | 23 |
25 using base::TimeTicks; | 24 using base::TimeTicks; |
26 using content::BrowserMessageFilter; | 25 using content::BrowserMessageFilter; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 189 |
191 // If the length of the misspelled word == 0, | 190 // If the length of the misspelled word == 0, |
192 // then there is no misspelled word. | 191 // then there is no misspelled word. |
193 bool word_correct = (spell_range.length == 0); | 192 bool word_correct = (spell_range.length == 0); |
194 return word_correct; | 193 return word_correct; |
195 } | 194 } |
196 | 195 |
197 void FillSuggestionList(const base::string16& wrong_word, | 196 void FillSuggestionList(const base::string16& wrong_word, |
198 std::vector<base::string16>* optional_suggestions) { | 197 std::vector<base::string16>* optional_suggestions) { |
199 NSString* NS_wrong_word = base::SysUTF16ToNSString(wrong_word); | 198 NSString* NS_wrong_word = base::SysUTF16ToNSString(wrong_word); |
200 TimeTicks debug_begin_time = base::Histogram::DebugNow(); | |
201 // The suggested words for |wrong_word|. | 199 // The suggested words for |wrong_word|. |
202 NSArray* guesses = [SharedSpellChecker() guessesForWord:NS_wrong_word]; | 200 NSArray* guesses = [SharedSpellChecker() guessesForWord:NS_wrong_word]; |
203 DHISTOGRAM_TIMES("Spellcheck.SuggestTime", | |
204 base::Histogram::DebugNow() - debug_begin_time); | |
205 | |
206 for (int i = 0; i < static_cast<int>([guesses count]); ++i) { | 201 for (int i = 0; i < static_cast<int>([guesses count]); ++i) { |
207 if (i < chrome::spellcheck_common::kMaxSuggestions) { | 202 if (i < chrome::spellcheck_common::kMaxSuggestions) { |
208 optional_suggestions->push_back(base::SysNSStringToUTF16( | 203 optional_suggestions->push_back(base::SysNSStringToUTF16( |
209 [guesses objectAtIndex:i])); | 204 [guesses objectAtIndex:i])); |
210 } | 205 } |
211 } | 206 } |
212 } | 207 } |
213 | 208 |
214 void AddWord(const base::string16& word) { | 209 void AddWord(const base::string16& word) { |
215 NSString* word_to_add = base::SysUTF16ToNSString(word); | 210 NSString* word_to_add = base::SysUTF16ToNSString(word); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 292 |
298 ScopedEnglishLanguageForTest::ScopedEnglishLanguageForTest() | 293 ScopedEnglishLanguageForTest::ScopedEnglishLanguageForTest() |
299 : state_(new SpellcheckerStateInternal) { | 294 : state_(new SpellcheckerStateInternal) { |
300 } | 295 } |
301 | 296 |
302 ScopedEnglishLanguageForTest::~ScopedEnglishLanguageForTest() { | 297 ScopedEnglishLanguageForTest::~ScopedEnglishLanguageForTest() { |
303 delete state_; | 298 delete state_; |
304 } | 299 } |
305 | 300 |
306 } // namespace spellcheck_mac | 301 } // namespace spellcheck_mac |
OLD | NEW |