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