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

Side by Side Diff: chrome/browser/spellchecker/spellcheck_platform_mac.mm

Issue 9368052: Removed WebTextCheckingResult legacy API use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another trial... Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
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" 16 #include "base/metrics/histogram.h"
17 #include "base/sys_string_conversions.h" 17 #include "base/sys_string_conversions.h"
18 #include "base/time.h" 18 #include "base/time.h"
19 #include "chrome/common/spellcheck_common.h" 19 #include "chrome/common/spellcheck_common.h"
20 #include "chrome/common/spellcheck_messages.h" 20 #include "chrome/common/spellcheck_messages.h"
21 #include "chrome/common/spellcheck_result.h"
21 #include "content/public/browser/browser_message_filter.h" 22 #include "content/public/browser/browser_message_filter.h"
22 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult .h"
24 24
25 using base::TimeTicks; 25 using base::TimeTicks;
26 using content::BrowserMessageFilter; 26 using content::BrowserMessageFilter;
27 using content::BrowserThread; 27 using content::BrowserThread;
28 28
29 namespace { 29 namespace {
30 // The number of characters in the first part of the language code. 30 // The number of characters in the first part of the language code.
31 const unsigned int kShortLanguageCodeSize = 2; 31 const unsigned int kShortLanguageCodeSize = 2;
32 32
33 // +[NSSpellChecker sharedSpellChecker] can throw exceptions depending 33 // +[NSSpellChecker sharedSpellChecker] can throw exceptions depending
(...skipping 17 matching lines...) Expand all
51 // The result of the check is returned back as a 51 // The result of the check is returned back as a
52 // SpellCheckMsg_RespondTextCheck message. 52 // SpellCheckMsg_RespondTextCheck message.
53 void TextCheckingCallback( 53 void TextCheckingCallback(
54 const scoped_refptr<BrowserMessageFilter>& destination, 54 const scoped_refptr<BrowserMessageFilter>& destination,
55 int route_id, 55 int route_id,
56 int identifier, 56 int identifier,
57 const string16& text, 57 const string16& text,
58 int document_tag) { 58 int document_tag) {
59 // TODO(morrita): Use [NSSpellChecker requestCheckingOfString] 59 // TODO(morrita): Use [NSSpellChecker requestCheckingOfString]
60 // when the build target goes up to 10.6 60 // when the build target goes up to 10.6
61 std::vector<WebKit::WebTextCheckingResult> check_results; 61 std::vector<SpellCheckResult> check_results;
62 NSString* text_to_check = base::SysUTF16ToNSString(text); 62 NSString* text_to_check = base::SysUTF16ToNSString(text);
63 size_t starting_at = 0; 63 size_t starting_at = 0;
64 while (starting_at < text.size()) { 64 while (starting_at < text.size()) {
65 NSRange range = [SharedSpellChecker() 65 NSRange range = [SharedSpellChecker()
66 checkSpellingOfString:text_to_check 66 checkSpellingOfString:text_to_check
67 startingAt:starting_at 67 startingAt:starting_at
68 language:nil 68 language:nil
69 wrap:NO 69 wrap:NO
70 inSpellDocumentWithTag:document_tag 70 inSpellDocumentWithTag:document_tag
71 wordCount:NULL]; 71 wordCount:NULL];
72 if (range.length == 0) 72 if (range.length == 0)
73 break; 73 break;
74 check_results.push_back(WebKit::WebTextCheckingResult( 74 check_results.push_back(SpellCheckResult(
75 WebKit::WebTextCheckingResult::ErrorSpelling, 75 SpellCheckResult::SPELLING,
76 range.location, 76 range.location,
77 range.length)); 77 range.length));
78 starting_at = range.location + range.length; 78 starting_at = range.location + range.length;
79 } 79 }
80 80
81 destination->Send( 81 destination->Send(
82 new SpellCheckMsg_RespondTextCheck(route_id, 82 new SpellCheckMsg_RespondTextCheck(route_id,
83 identifier, 83 identifier,
84 document_tag, 84 document_tag,
85 check_results)); 85 check_results));
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 int identifier, 277 int identifier,
278 int document_tag, 278 int document_tag,
279 const string16& text, BrowserMessageFilter* destination) { 279 const string16& text, BrowserMessageFilter* destination) {
280 BrowserThread::PostTask( 280 BrowserThread::PostTask(
281 BrowserThread::FILE, FROM_HERE, 281 BrowserThread::FILE, FROM_HERE,
282 base::Bind(&TextCheckingCallback, make_scoped_refptr(destination), 282 base::Bind(&TextCheckingCallback, make_scoped_refptr(destination),
283 route_id, identifier, text, document_tag)); 283 route_id, identifier, text, document_tag));
284 } 284 }
285 285
286 } // namespace spellcheck_mac 286 } // namespace spellcheck_mac
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698