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