Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / spellchecker / spellcheck_platform.h
blob4a7a6c9ed86a1aeae8c56b59dfe7a7624a0f874d
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.
5 // This file defines the interface that any platform-specific spellchecker
6 // needs to implement in order to be used by the browser.
8 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PLATFORM_H_
9 #define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PLATFORM_H_
11 #include <string>
12 #include <vector>
14 #include "base/callback_forward.h"
15 #include "base/strings/string16.h"
17 struct SpellCheckResult;
19 namespace content {
20 class BrowserMessageFilter;
21 } // namespace content
23 namespace spellcheck_platform {
25 typedef base::Callback<void(
26 const std::vector<SpellCheckResult>& /* results */)>
27 TextCheckCompleteCallback;
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.
32 void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages);
34 // Returns true if there is a platform-specific spellchecker that can be used.
35 bool SpellCheckerAvailable();
37 // Returns true if the platform spellchecker has a spelling panel.
38 bool SpellCheckerProvidesPanel();
40 // Returns true if the platform spellchecker panel is visible.
41 bool SpellingPanelVisible();
43 // Shows the spelling panel if |show| is true and hides it if it is not.
44 void ShowSpellingPanel(bool show);
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.
48 void UpdateSpellingPanelWithMisspelledWord(const base::string16& word);
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.
54 bool PlatformSupportsLanguage(const std::string& current_language);
56 // Sets the language for the platform-specific spellchecker.
57 void SetLanguage(const std::string& lang_to_set);
59 // Checks the spelling of the given string, using the platform-specific
60 // spellchecker. Returns true if the word is spelled correctly.
61 bool CheckSpelling(const base::string16& word_to_check, int tag);
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|.
66 void FillSuggestionList(const base::string16& wrong_word,
67 std::vector<base::string16>* optional_suggestions);
69 // Adds the given word to the platform dictionary.
70 void AddWord(const base::string16& word);
72 // Remove a given word from the platform dictionary.
73 void RemoveWord(const base::string16& word);
75 // Gets a unique tag to identify a document. Used in ignoring words.
76 int GetDocumentTag();
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.
83 void IgnoreWord(const base::string16& word);
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.
88 void CloseDocumentWithTag(int tag);
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.
93 void RequestTextCheck(int document_tag,
94 const base::string16& text,
95 TextCheckCompleteCallback callback);
97 // Internal state, to restore system state after testing.
98 // Not public since it contains Cocoa data types.
99 class SpellcheckerStateInternal;
101 // Test helper, forces the system spellchecker to en-US for its lifetime.
102 class ScopedEnglishLanguageForTest {
103 public:
104 ScopedEnglishLanguageForTest();
105 ~ScopedEnglishLanguageForTest();
106 private:
107 SpellcheckerStateInternal* state_;
110 } // namespace spellcheck_platform
112 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PLATFORM_H_