1 // Copyright (c) 2009 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_PLATFORM_ENGINE_H_ 9 #define CHROME_BROWSER_SPELLCHECKER_PLATFORM_ENGINE_H_ 10 #pragma once 11 12 #include <string> 13 #include <vector> 14 15 #include "base/callback.h" 16 #include "base/string16.h" 17 18 class BrowserMessageFilter; 19 20 namespace SpellCheckerPlatform { 21 22 // Get the languages supported by the platform spellchecker and store them in 23 // |spellcheck_languages|. Note that they must be converted to 24 // Chromium style codes (en-US not en_US). See spellchecker.cc for a full list. 25 void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages); 26 27 // Returns true if there is a platform-specific spellchecker that can be used. 28 bool SpellCheckerAvailable(); 29 30 // Returns true if the platform spellchecker has a spelling panel. 31 bool SpellCheckerProvidesPanel(); 32 33 // Returns true if the platform spellchecker panel is visible. 34 bool SpellingPanelVisible(); 35 36 // Shows the spelling panel if |show| is true and hides it if it is not. 37 void ShowSpellingPanel(bool show); 38 39 // Changes the word show in the spelling panel to be |word|. Note that the 40 // spelling panel need not be displayed for this to work. 41 void UpdateSpellingPanelWithMisspelledWord(const string16& word); 42 43 // Do any initialization needed for spellchecker. 44 void Init(); 45 // TODO(pwicks): should we add a companion to this, TearDown or something? 46 47 // Translates the codes used by chrome to the language codes used by os x 48 // and checks the given language agains the languages that the current system 49 // supports. If the platform-specific spellchecker supports the language, 50 // then returns true, otherwise false. 51 bool PlatformSupportsLanguage(const std::string& current_language); 52 53 // Sets the language for the platform-specific spellchecker. 54 void SetLanguage(const std::string& lang_to_set); 55 56 // Checks the spelling of the given string, using the platform-specific 57 // spellchecker. Returns true if the word is spelled correctly. 58 bool CheckSpelling(const string16& word_to_check, int tag); 59 60 // Fills the given vector |optional_suggestions| with a number (up to 61 // kMaxSuggestions, which is defined in spellchecker_common.h) of suggestions 62 // for the string |wrong_word|. 63 void FillSuggestionList(const string16& wrong_word, 64 std::vector<string16>* optional_suggestions); 65 66 // Adds the given word to the platform dictionary. 67 void AddWord(const string16& word); 68 69 // Remove a given word from the platform dictionary. 70 void RemoveWord(const string16& word); 71 72 // Gets a unique tag to identify a document. Used in ignoring words. 73 int GetDocumentTag(); 74 75 // Tells the platform spellchecker to ignore a word. This doesn't take a tag 76 // because in most of the situations in which it is called, the only way to know 77 // the tag for sure is to ask the renderer, which would mean blocking in the 78 // browser, so (on the mac, anyway) we remember the most recent tag and use 79 // it, since it should always be from the same document. 80 void IgnoreWord(const string16& word); 81 82 // Tells the platform spellchecker that a document associated with a tag has 83 // closed. Generally, this means that any ignored words associated with that 84 // document can now be forgotten. 85 void CloseDocumentWithTag(int tag); 86 87 // Requests an asyncronous spell and grammar checking. 88 // The result is returned to an IPC message to |destination| thus it should 89 // not be null. 90 void RequestTextCheck(int route_id, 91 int identifier, 92 int document_tag, 93 const string16& text, 94 BrowserMessageFilter* destination); 95 96 } // namespace SpellCheckerPlatform 97 98 #endif // CHROME_BROWSER_SPELLCHECKER_PLATFORM_ENGINE_H_ 99