1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// This file defines the interface that any platform-specific spellchecker
6// needs to implement in order to be used by the browser.
7
8#ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PLATFORM_MAC_H_
9#define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PLATFORM_MAC_H_
10
11#include <string>
12#include <vector>
13
14#include "base/callback_forward.h"
15#include "base/strings/string16.h"
16
17struct SpellCheckResult;
18
19namespace content {
20class BrowserMessageFilter;
21}  // namespace content
22
23namespace spellcheck_mac {
24
25typedef base::Callback<void(
26        const std::vector<SpellCheckResult>& /* results */)>
27            TextCheckCompleteCallback;
28
29// Get the languages supported by the platform spellchecker and store them in
30// |spellcheck_languages|. Note that they must be converted to
31// Chromium style codes (en-US not en_US). See spellchecker.cc for a full list.
32void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages);
33
34// Returns true if there is a platform-specific spellchecker that can be used.
35bool SpellCheckerAvailable();
36
37// Returns true if the platform spellchecker has a spelling panel.
38bool SpellCheckerProvidesPanel();
39
40// Returns true if the platform spellchecker panel is visible.
41bool SpellingPanelVisible();
42
43// Shows the spelling panel if |show| is true and hides it if it is not.
44void ShowSpellingPanel(bool show);
45
46// Changes the word show in the spelling panel to be |word|. Note that the
47// spelling panel need not be displayed for this to work.
48void UpdateSpellingPanelWithMisspelledWord(const base::string16& word);
49
50// Translates the codes used by chrome to the language codes used by os x
51// and checks the given language agains the languages that the current system
52// supports. If the platform-specific spellchecker supports the language,
53// then returns true, otherwise false.
54bool PlatformSupportsLanguage(const std::string& current_language);
55
56// Sets the language for the platform-specific spellchecker.
57void SetLanguage(const std::string& lang_to_set);
58
59// Checks the spelling of the given string, using the platform-specific
60// spellchecker. Returns true if the word is spelled correctly.
61bool CheckSpelling(const base::string16& word_to_check, int tag);
62
63// Fills the given vector |optional_suggestions| with a number (up to
64// kMaxSuggestions, which is defined in spellchecker_common.h) of suggestions
65// for the string |wrong_word|.
66void FillSuggestionList(const base::string16& wrong_word,
67                        std::vector<base::string16>* optional_suggestions);
68
69// Adds the given word to the platform dictionary.
70void AddWord(const base::string16& word);
71
72// Remove a given word from the platform dictionary.
73void RemoveWord(const base::string16& word);
74
75// Gets a unique tag to identify a document. Used in ignoring words.
76int GetDocumentTag();
77
78// Tells the platform spellchecker to ignore a word. This doesn't take a tag
79// because in most of the situations in which it is called, the only way to know
80// the tag for sure is to ask the renderer, which would mean blocking in the
81// browser, so (on the mac, anyway) we remember the most recent tag and use
82// it, since it should always be from the same document.
83void IgnoreWord(const base::string16& word);
84
85// Tells the platform spellchecker that a document associated with a tag has
86// closed. Generally, this means that any ignored words associated with that
87// document can now be forgotten.
88void CloseDocumentWithTag(int tag);
89
90// Requests an asyncronous spell and grammar checking.
91// The result is returned to an IPC message to |destination| thus it should
92// not be null.
93void RequestTextCheck(int document_tag,
94                      const base::string16& text,
95                      TextCheckCompleteCallback callback);
96
97// Internal state, to restore system state after testing.
98// Not public since it contains Cocoa data types.
99class SpellcheckerStateInternal;
100
101// Test helper, forces the system spellchecker to en-US for its lifetime.
102class ScopedEnglishLanguageForTest {
103 public:
104  ScopedEnglishLanguageForTest();
105  ~ScopedEnglishLanguageForTest();
106 private:
107  SpellcheckerStateInternal* state_;
108};
109
110}  // namespace spellcheck_mac
111
112#endif  // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PLATFORM_MAC_H_
113