summaryrefslogtreecommitdiffstats
path: root/chrome/browser/spellchecker_mac.mm
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-09 21:16:05 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-09 21:16:05 +0000
commit98324891649cf5fa7430c2e231ad5493fdb76c8e (patch)
tree4c48f7d44d002691e717526bdb2d7870296b10df /chrome/browser/spellchecker_mac.mm
parent1edc999cee504ed756ee798dfb1bfd95f53b4262 (diff)
downloadchromium_src-98324891649cf5fa7430c2e231ad5493fdb76c8e.zip
chromium_src-98324891649cf5fa7430c2e231ad5493fdb76c8e.tar.gz
chromium_src-98324891649cf5fa7430c2e231ad5493fdb76c8e.tar.bz2
Adds support for the os x spelling panel to chromium. Users can
now access it from the main menu and context menu and use it to perform spelling tasks. For more detail, see http://code.google.com/p/chromium/wiki/SpellingPanelPlanningDoc Patch from pwicks86@gmail.com (Paul Wicks). BUG=None TEST=The spelling panel should work in os x. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25786 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/spellchecker_mac.mm')
-rw-r--r--chrome/browser/spellchecker_mac.mm57
1 files changed, 50 insertions, 7 deletions
diff --git a/chrome/browser/spellchecker_mac.mm b/chrome/browser/spellchecker_mac.mm
index f9bfac6..4fe6458 100644
--- a/chrome/browser/spellchecker_mac.mm
+++ b/chrome/browser/spellchecker_mac.mm
@@ -7,11 +7,12 @@
#import <Cocoa/Cocoa.h>
-#include "chrome/browser/spellchecker_common.h"
-#include "chrome/browser/spellchecker_platform_engine.h"
+#include "base/logging.h"
#include "base/time.h"
#include "base/histogram.h"
#include "base/sys_string_conversions.h"
+#include "chrome/browser/spellchecker_common.h"
+#include "chrome/browser/spellchecker_platform_engine.h"
using base::TimeTicks;
namespace {
@@ -92,9 +93,30 @@ bool SpellCheckerProvidesPanel() {
return true;
}
-bool SpellCheckerPanelVisible() {
- return [[[NSSpellChecker sharedSpellChecker] spellingPanel]
- isVisible] ? true : false;
+bool SpellingPanelVisible() {
+ // This should only be called from the main thread.
+ DCHECK([NSThread currentThread] == [NSThread mainThread]);
+ return [[[NSSpellChecker sharedSpellChecker] spellingPanel] isVisible];
+}
+
+void ShowSpellingPanel(bool show) {
+ if (show) {
+ [[[NSSpellChecker sharedSpellChecker] spellingPanel]
+ performSelectorOnMainThread:@selector(makeKeyAndOrderFront:)
+ withObject:nil
+ waitUntilDone:YES];
+ } else {
+ [[[NSSpellChecker sharedSpellChecker] spellingPanel]
+ performSelectorOnMainThread:@selector(close)
+ withObject:nil
+ waitUntilDone:YES];
+ }
+}
+
+void UpdateSpellingPanelWithMisspelledWord(const std::wstring& word) {
+ NSString * word_to_display = base::SysWideToNSString(word);
+ [[NSSpellChecker sharedSpellChecker]
+ updateSpellingPanelWithMisspelledWord:word_to_display];
}
void Init() {
@@ -121,7 +143,11 @@ void SetLanguage(const std::string& lang_to_set) {
[[NSSpellChecker sharedSpellChecker] setLanguage:NS_lang_to_set];
}
-bool CheckSpelling(const std::string& word_to_check) {
+static int last_seen_tag_;
+
+bool CheckSpelling(const std::string& word_to_check, int tag) {
+ last_seen_tag_ = tag;
+
// [[NSSpellChecker sharedSpellChecker] checkSpellingOfString] returns an
// NSRange that we can look at to determine if a word is misspelled.
NSRange spell_range = {0,0};
@@ -130,7 +156,9 @@ bool CheckSpelling(const std::string& word_to_check) {
NSString* NS_word_to_check = base::SysUTF8ToNSString(word_to_check);
// Check the spelling, starting at the beginning of the word.
spell_range = [[NSSpellChecker sharedSpellChecker]
- checkSpellingOfString:NS_word_to_check startingAt:0];
+ checkSpellingOfString:NS_word_to_check startingAt:0
+ language:nil wrap:NO inSpellDocumentWithTag:tag
+ wordCount:NULL];
// If the length of the misspelled word == 0,
// then there is no misspelled word.
@@ -165,5 +193,20 @@ void RemoveWord(const std::wstring& word) {
NSString *word_to_remove = base::SysWideToNSString(word);
[[NSSpellChecker sharedSpellChecker] unlearnWord:word_to_remove];
}
+
+int GetDocumentTag() {
+ NSInteger doc_tag = [NSSpellChecker uniqueSpellDocumentTag];
+ return static_cast<int>(doc_tag);
+}
+
+void IgnoreWord(const std::string& word) {
+ [[NSSpellChecker sharedSpellChecker] ignoreWord:base::SysUTF8ToNSString(word)
+ inSpellDocumentWithTag:last_seen_tag_];
+}
+
+void CloseDocumentWithTag(int tag) {
+ [[NSSpellChecker sharedSpellChecker]
+ closeSpellDocumentWithTag:static_cast<NSInteger>(tag)];
+}
} // namespace SpellCheckerPlatform