OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ | 5 #ifndef CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ |
6 #define CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ | 6 #define CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
13 #include "base/file_descriptor_posix.h" | 13 #include "base/platform_file.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h" | 16 #include "chrome/renderer/spellchecker/spellcheck_worditerator.h" |
17 #include "unicode/uscript.h" | 17 #include "unicode/uscript.h" |
18 | 18 |
19 class Hunspell; | 19 class Hunspell; |
20 | 20 |
21 namespace base { | |
22 class FileDescriptor; | |
23 } | |
24 | |
25 namespace file_util { | 21 namespace file_util { |
26 class MemoryMappedFile; | 22 class MemoryMappedFile; |
27 } | 23 } |
28 | 24 |
29 class SpellCheck { | 25 class SpellCheck { |
30 public: | 26 public: |
31 SpellCheck(); | 27 SpellCheck(); |
32 | 28 |
33 ~SpellCheck(); | 29 ~SpellCheck(); |
34 | 30 |
35 void Init(const base::FileDescriptor& bdict_fd, | 31 void Init(base::PlatformFile file, |
36 const std::vector<std::string>& custom_words, | 32 const std::vector<std::string>& custom_words, |
37 const std::string language); | 33 const std::string language); |
38 | 34 |
39 // SpellCheck a word. | 35 // SpellCheck a word. |
40 // Returns true if spelled correctly, false otherwise. | 36 // Returns true if spelled correctly, false otherwise. |
41 // If the spellchecker failed to initialize, always returns true. | 37 // If the spellchecker failed to initialize, always returns true. |
42 // The |tag| parameter should either be a unique identifier for the document | 38 // The |tag| parameter should either be a unique identifier for the document |
43 // that the word came from (if the current platform requires it), or 0. | 39 // that the word came from (if the current platform requires it), or 0. |
44 // In addition, finds the suggested words for a given word | 40 // In addition, finds the suggested words for a given word |
45 // and puts them into |*optional_suggestions|. | 41 // and puts them into |*optional_suggestions|. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 90 |
95 // Add the given custom word to |hunspell_|. | 91 // Add the given custom word to |hunspell_|. |
96 void AddWordToHunspell(const std::string& word); | 92 void AddWordToHunspell(const std::string& word); |
97 | 93 |
98 // We memory-map the BDict file. | 94 // We memory-map the BDict file. |
99 scoped_ptr<file_util::MemoryMappedFile> bdict_file_; | 95 scoped_ptr<file_util::MemoryMappedFile> bdict_file_; |
100 | 96 |
101 // The hunspell dictionary in use. | 97 // The hunspell dictionary in use. |
102 scoped_ptr<Hunspell> hunspell_; | 98 scoped_ptr<Hunspell> hunspell_; |
103 | 99 |
104 base::FileDescriptor fd_; | 100 base::PlatformFile file_; |
105 std::vector<std::string> custom_words_; | 101 std::vector<std::string> custom_words_; |
106 | 102 |
107 // Represents character attributes used for filtering out characters which | 103 // Represents character attributes used for filtering out characters which |
108 // are not supported by this SpellCheck object. | 104 // are not supported by this SpellCheck object. |
109 SpellcheckCharAttribute character_attributes_; | 105 SpellcheckCharAttribute character_attributes_; |
110 | 106 |
111 // Remember state for auto spell correct. | 107 // Remember state for auto spell correct. |
112 bool auto_spell_correct_turned_on_; | 108 bool auto_spell_correct_turned_on_; |
113 | 109 |
114 // True if a platform-specific spellchecking engine is being used, | 110 // True if a platform-specific spellchecking engine is being used, |
115 // and False if hunspell is being used. | 111 // and False if hunspell is being used. |
116 bool is_using_platform_spelling_engine_; | 112 bool is_using_platform_spelling_engine_; |
117 | 113 |
118 // This flags whether we have ever been initialized, or have asked the browser | 114 // This flags whether we have ever been initialized, or have asked the browser |
119 // for a dictionary. The value indicates whether we should request a | 115 // for a dictionary. The value indicates whether we should request a |
120 // dictionary from the browser when the render view asks us to check the | 116 // dictionary from the browser when the render view asks us to check the |
121 // spelling of a word. | 117 // spelling of a word. |
122 bool initialized_; | 118 bool initialized_; |
123 | 119 |
124 DISALLOW_COPY_AND_ASSIGN(SpellCheck); | 120 DISALLOW_COPY_AND_ASSIGN(SpellCheck); |
125 }; | 121 }; |
126 | 122 |
127 #endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ | 123 #endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ |
OLD | NEW |