OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #ifndef CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_LANGUAGE_H_ | |
6 #define CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_LANGUAGE_H_ | |
7 | |
8 #include <memory> | |
9 #include <queue> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/files/file.h" | |
14 #include "base/macros.h" | |
15 #include "base/strings/string16.h" | |
16 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h" | |
17 | |
18 class SpellingEngine; | |
19 | |
20 class SpellcheckLanguage { | |
21 public: | |
22 enum SpellcheckWordResult { | |
23 // Denotes that every recognized word is spelled correctly, from the point | |
24 // of spellchecking to the end of the text. | |
25 IS_CORRECT, | |
26 // A sequence of skippable characters, such as punctuation, spaces, or | |
27 // characters not recognized by the current spellchecking language. | |
28 IS_SKIPPABLE, | |
29 // A misspelled word has been found in the text. | |
30 IS_MISSPELLED | |
31 }; | |
32 | |
33 SpellcheckLanguage(); | |
34 ~SpellcheckLanguage(); | |
35 | |
36 void Init(base::File file, const std::string& language); | |
37 | |
38 // Spellcheck a sequence of text. | |
39 // |text_length| is the length of the text being spellchecked. The |tag| | |
40 // parameter should either be a unique identifier for the document that the | |
41 // word came from (if the current platform requires it), or 0. | |
42 // | |
43 // - Returns IS_CORRECT if every word from |position_in_text| to the end of | |
44 // the text is recognized and spelled correctly. Also, returns IS_CORRECT if | |
45 // the spellchecker failed to initialize. | |
46 // | |
47 // - Returns IS_SKIPPABLE if a sequence of skippable characters, such as | |
48 // punctuation, spaces, or unrecognized characters, is found. | |
49 // |skip_or_misspelling_start| and |skip_or_misspelling_len| are then set to | |
50 // the position and the length of the sequence of skippable characters. | |
51 // | |
52 // - Returns IS_MISSPELLED if a misspelled word is found. | |
53 // |skip_or_misspelling_start| and |skip_or_misspelling_len| are then set to | |
54 // the position and length of the misspelled word. In addition, finds the | |
55 // suggested words for a given misspelled word and puts them into | |
56 // |*optional_suggestions|. If optional_suggestions is NULL, suggested words | |
57 // will not be looked up. Note that doing suggest lookups can be slow. | |
58 SpellcheckWordResult SpellCheckWord( | |
59 const base::char16* text_begin, | |
60 int position_in_text, | |
61 int text_length, | |
62 int tag, | |
63 int* skip_or_misspelling_start, | |
64 int* skip_or_misspelling_len, | |
65 std::vector<base::string16>* optional_suggestions); | |
66 | |
67 // Initialize |spellcheck_| if that hasn't happened yet. | |
68 bool InitializeIfNeeded(); | |
69 | |
70 // Return true if the underlying spellcheck engine is enabled. | |
71 bool IsEnabled(); | |
72 | |
73 private: | |
74 friend class SpellCheckTest; | |
75 | |
76 // Returns whether or not the given word is a contraction of valid words | |
77 // (e.g. "word:word"). | |
78 bool IsValidContraction(const base::string16& word, int tag); | |
79 | |
80 // Represents character attributes used for filtering out characters which | |
81 // are not supported by this SpellCheck object. | |
82 SpellcheckCharAttribute character_attributes_; | |
83 | |
84 // Represents word iterators used in this spellchecker. The |text_iterator_| | |
85 // splits text provided by WebKit into words, contractions, or concatenated | |
86 // words. The |contraction_iterator_| splits a concatenated word extracted by | |
87 // |text_iterator_| into word components so we can treat a concatenated word | |
88 // consisting only of correct words as a correct word. | |
89 SpellcheckWordIterator text_iterator_; | |
90 SpellcheckWordIterator contraction_iterator_; | |
91 | |
92 // Pointer to a platform-specific spelling engine, if it is in use. This | |
93 // should only be set if hunspell is not used. (I.e. on OSX, for now) | |
94 std::unique_ptr<SpellingEngine> platform_spelling_engine_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(SpellcheckLanguage); | |
97 }; | |
98 | |
99 #endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_LANGUAGE_H_ | |
OLD | NEW |