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

Unified Diff: chrome/browser/spellchecker_mac.mm

Issue 6392045: Integrating Mac OS Grammar checker into Chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Caught up some more missings. I'm sorry for the distraction... Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/spellchecker_mac.mm
diff --git a/chrome/browser/spellchecker_mac.mm b/chrome/browser/spellchecker_mac.mm
index ead554fd8292fc67c21834d33ef255643ec79d34..9b7799184a3f300a538285f11f693183d8d4080a 100644
--- a/chrome/browser/spellchecker_mac.mm
+++ b/chrome/browser/spellchecker_mac.mm
@@ -11,15 +11,73 @@
#include "base/logging.h"
#include "base/metrics/histogram.h"
+#include "base/task.h"
#include "base/time.h"
#include "base/sys_string_conversions.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/browser/browser_message_filter.h"
+#include "chrome/common/render_messages.h"
#include "chrome/common/spellcheck_common.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult.h"
using base::TimeTicks;
namespace {
// The number of characters in the first part of the language code.
const unsigned int kShortLanguageCodeSize = 2;
+class TextCheckingTask : public Task {
Hironori Bono 2011/02/10 11:02:56 nit: I would be great if this class has a class co
pink (ping after 24hrs) 2011/02/11 17:33:40 100% agreed. not a nit at all.
gmorrita 2011/02/17 11:39:44 Added an description.
+ public:
+ TextCheckingTask(BrowserMessageFilter* destination,
+ int route_id,
+ int identifier,
+ const string16& text,
+ int document_tag)
+ : destination_(destination_),
+ route_id_(route_id),
+ identifier_(identifier),
+ text_(text),
+ document_tag_(document_tag) {
+ }
+
+ virtual void Run() {
+ // TODO(morrita): Use [NSSpellChecker requestCheckingOfString]
+ // when the build target goes upto 10.6
pink (ping after 24hrs) 2011/02/11 17:33:40 s/upto/up to. Can you do a respondsToSelector: ch
gmorrita 2011/02/17 11:39:44 Fixed.
+ std::vector<WebKit::WebTextCheckingResult> check_results;
+ NSString* text_to_check = base::SysUTF16ToNSString(text_);
+ size_t starting_at = 0;
+ while (starting_at < text_.size()) {
+ NSRange range = [[NSSpellChecker sharedSpellChecker]
+ checkSpellingOfString:text_to_check
+ startingAt:starting_at
pink (ping after 24hrs) 2011/02/11 17:33:40 line up colons
gmorrita 2011/02/17 11:39:44 Done.
+ language:nil wrap:NO
+ inSpellDocumentWithTag:document_tag_
+ wordCount:NULL];
+ if (0 == range.length)
pink (ping after 24hrs) 2011/02/11 17:33:40 if (range.length == 0). The constant before is muc
gmorrita 2011/02/17 11:39:44 Done.
+ break;
+ check_results.push_back(WebKit::WebTextCheckingResult(
+ WebKit::WebTextCheckingResult::ErrorSpelling,
+ range.location,
+ range.length));
+ starting_at = range.location + range.length;
+ }
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE, NewRunnableMethod(
+ destination_, &BrowserMessageFilter::Send,
+ new ViewMsg_SpellChecker_RespondTextCheck(route_id_,
+ identifier_,
+ document_tag_,
+ check_results)));
+ }
+
+ private:
+ BrowserMessageFilter* destination_;
pink (ping after 24hrs) 2011/02/11 17:33:40 comment this is a weak pointer.
gmorrita 2011/02/17 11:39:44 Noticed we have to own it to avoiding the dangling
+ int route_id_;
+ int identifier_;
+ string16 text_;
+ int document_tag_;
+};
+
// A private utility function to convert hunspell language codes to os x
// language codes.
NSString* ConvertLanguageCodeToMac(const std::string& hunspell_lang_code) {
@@ -208,7 +266,17 @@ void IgnoreWord(const string16& word) {
void CloseDocumentWithTag(int tag) {
[[NSSpellChecker sharedSpellChecker]
- closeSpellDocumentWithTag:static_cast<NSInteger>(tag)];
+ closeSpellDocumentWithTag:static_cast<NSInteger>(tag)];
+}
+
+void RequestTextCheck(int route_id,
+ int identifier,
+ int document_tag,
+ const string16& text, BrowserMessageFilter* destination) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ new TextCheckingTask(
+ destination, route_id, identifier, text, document_tag));
}
} // namespace SpellCheckerPlatform

Powered by Google App Engine
This is Rietveld 408576698