OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/platform_file.h" | 14 #include "base/platform_file.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "chrome/renderer/spellchecker/custom_dictionary_engine.h" | 16 #include "chrome/renderer/spellchecker/custom_dictionary_engine.h" |
17 #include "chrome/renderer/spellchecker/spellcheck_language.h" | 17 #include "chrome/renderer/spellchecker/spellcheck_language.h" |
18 #include "content/public/renderer/render_process_observer.h" | 18 #include "content/public/renderer/render_process_observer.h" |
19 #include "ipc/ipc_platform_file.h" | 19 #include "ipc/ipc_platform_file.h" |
20 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
21 | 21 |
22 struct SpellCheckResult; | 22 struct SpellCheckResult; |
23 | 23 |
24 namespace WebKit { | 24 namespace blink { |
25 class WebTextCheckingCompletion; | 25 class WebTextCheckingCompletion; |
26 struct WebTextCheckingResult; | 26 struct WebTextCheckingResult; |
27 } | 27 } |
28 | 28 |
29 // TODO(morrita): Needs reorg with SpellCheckProvider. | 29 // TODO(morrita): Needs reorg with SpellCheckProvider. |
30 // See http://crbug.com/73699. | 30 // See http://crbug.com/73699. |
31 // Shared spellchecking logic/data for a RenderProcess. All RenderViews use | 31 // Shared spellchecking logic/data for a RenderProcess. All RenderViews use |
32 // this object to perform spellchecking tasks. | 32 // this object to perform spellchecking tasks. |
33 class SpellCheck : public content::RenderProcessObserver, | 33 class SpellCheck : public content::RenderProcessObserver, |
34 public base::SupportsWeakPtr<SpellCheck> { | 34 public base::SupportsWeakPtr<SpellCheck> { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 int tag, | 71 int tag, |
72 int* misspelling_start, | 72 int* misspelling_start, |
73 int* misspelling_len, | 73 int* misspelling_len, |
74 std::vector<string16>* optional_suggestions); | 74 std::vector<string16>* optional_suggestions); |
75 | 75 |
76 // SpellCheck a paragraph. | 76 // SpellCheck a paragraph. |
77 // Returns true if |text| is correctly spelled, false otherwise. | 77 // Returns true if |text| is correctly spelled, false otherwise. |
78 // If the spellchecker failed to initialize, always returns true. | 78 // If the spellchecker failed to initialize, always returns true. |
79 bool SpellCheckParagraph( | 79 bool SpellCheckParagraph( |
80 const string16& text, | 80 const string16& text, |
81 WebKit::WebVector<WebKit::WebTextCheckingResult>* results); | 81 blink::WebVector<blink::WebTextCheckingResult>* results); |
82 | 82 |
83 // Find a possible correctly spelled word for a misspelled word. Computes an | 83 // Find a possible correctly spelled word for a misspelled word. Computes an |
84 // empty string if input misspelled word is too long, there is ambiguity, or | 84 // empty string if input misspelled word is too long, there is ambiguity, or |
85 // the correct spelling cannot be determined. | 85 // the correct spelling cannot be determined. |
86 // NOTE: If using the platform spellchecker, this will send a *lot* of sync | 86 // NOTE: If using the platform spellchecker, this will send a *lot* of sync |
87 // IPCs. We should probably refactor this if we ever plan to take it out from | 87 // IPCs. We should probably refactor this if we ever plan to take it out from |
88 // behind its command line flag. | 88 // behind its command line flag. |
89 string16 GetAutoCorrectionWord(const string16& word, int tag); | 89 string16 GetAutoCorrectionWord(const string16& word, int tag); |
90 | 90 |
91 // Requests to spellcheck the specified text in the background. This function | 91 // Requests to spellcheck the specified text in the background. This function |
92 // posts a background task and calls SpellCheckParagraph() in the task. | 92 // posts a background task and calls SpellCheckParagraph() in the task. |
93 #if !defined (OS_MACOSX) | 93 #if !defined (OS_MACOSX) |
94 void RequestTextChecking(const string16& text, | 94 void RequestTextChecking(const string16& text, |
95 WebKit::WebTextCheckingCompletion* completion); | 95 blink::WebTextCheckingCompletion* completion); |
96 #endif | 96 #endif |
97 | 97 |
98 // Creates a list of WebTextCheckingResult objects (used by WebKit) from a | 98 // Creates a list of WebTextCheckingResult objects (used by WebKit) from a |
99 // list of SpellCheckResult objects (used by Chrome). This function also | 99 // list of SpellCheckResult objects (used by Chrome). This function also |
100 // checks misspelled words returned by the Spelling service and changes the | 100 // checks misspelled words returned by the Spelling service and changes the |
101 // underline colors of contextually-misspelled words. | 101 // underline colors of contextually-misspelled words. |
102 void CreateTextCheckingResults( | 102 void CreateTextCheckingResults( |
103 ResultFilter filter, | 103 ResultFilter filter, |
104 int line_offset, | 104 int line_offset, |
105 const string16& line_text, | 105 const string16& line_text, |
106 const std::vector<SpellCheckResult>& spellcheck_results, | 106 const std::vector<SpellCheckResult>& spellcheck_results, |
107 WebKit::WebVector<WebKit::WebTextCheckingResult>* textcheck_results); | 107 blink::WebVector<blink::WebTextCheckingResult>* textcheck_results); |
108 | 108 |
109 bool is_spellcheck_enabled() { return spellcheck_enabled_; } | 109 bool is_spellcheck_enabled() { return spellcheck_enabled_; } |
110 | 110 |
111 private: | 111 private: |
112 friend class SpellCheckTest; | 112 friend class SpellCheckTest; |
113 FRIEND_TEST_ALL_PREFIXES(SpellCheckTest, GetAutoCorrectionWord_EN_US); | 113 FRIEND_TEST_ALL_PREFIXES(SpellCheckTest, GetAutoCorrectionWord_EN_US); |
114 FRIEND_TEST_ALL_PREFIXES(SpellCheckTest, | 114 FRIEND_TEST_ALL_PREFIXES(SpellCheckTest, |
115 RequestSpellCheckMultipleTimesWithoutInitialization); | 115 RequestSpellCheckMultipleTimesWithoutInitialization); |
116 | 116 |
117 // RenderProcessObserver implementation: | 117 // RenderProcessObserver implementation: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // Remember state for auto spell correct. | 153 // Remember state for auto spell correct. |
154 bool auto_spell_correct_turned_on_; | 154 bool auto_spell_correct_turned_on_; |
155 | 155 |
156 // Remember state for spellchecking. | 156 // Remember state for spellchecking. |
157 bool spellcheck_enabled_; | 157 bool spellcheck_enabled_; |
158 | 158 |
159 DISALLOW_COPY_AND_ASSIGN(SpellCheck); | 159 DISALLOW_COPY_AND_ASSIGN(SpellCheck); |
160 }; | 160 }; |
161 | 161 |
162 #endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ | 162 #endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_H_ |
OLD | NEW |