20
20
#include " content/public/browser/render_widget_host_view.h"
21
21
#include " third_party/blink/public/mojom/context_menu/context_menu.mojom.h"
22
22
23
+ #if BUILDFLAG(IS_WIN)
24
+ #include " chrome/browser/spellchecker/spellcheck_factory.h"
25
+ #include " chrome/browser/spellchecker/spellcheck_service.h"
26
+ #include " components/spellcheck/browser/spellcheck_platform.h"
27
+ #endif
28
+
23
29
namespace {
24
30
25
31
CefString GetLabel (int message_id) {
@@ -120,8 +126,8 @@ bool CefMenuManager::IsShowingContextMenu() {
120
126
return web_contents ()->IsShowingContextMenu ();
121
127
}
122
128
123
- bool CefMenuManager::CreateContextMenu (
124
- const content::ContextMenuParams& params ) {
129
+ bool CefMenuManager::CreateContextMenu (const content::ContextMenuParams& params,
130
+ bool query_spellcheck ) {
125
131
// The renderer may send the "show context menu" message multiple times, one
126
132
// for each right click mouse event it receives. Normally, this doesn't happen
127
133
// because mouse events are not forwarded once the context menu is showing.
@@ -134,6 +140,24 @@ bool CefMenuManager::CreateContextMenu(
134
140
}
135
141
136
142
params_ = params;
143
+
144
+ #if BUILDFLAG(IS_WIN)
145
+ // System spellcheck suggestions need to be queried asynchronously.
146
+ if (query_spellcheck && !params_.misspelled_word .empty () &&
147
+ params_.dictionary_suggestions .empty ()) {
148
+ SpellcheckService* spellcheck_service =
149
+ SpellcheckServiceFactory::GetForContext (
150
+ browser_->web_contents ()->GetBrowserContext ());
151
+ if (spellcheck_service) {
152
+ spellcheck_platform::GetPerLanguageSuggestions (
153
+ spellcheck_service->platform_spell_checker (), params_.misspelled_word ,
154
+ base::BindOnce (&CefMenuManager::OnGetPlatformSuggestionsComplete,
155
+ weak_ptr_factory_.GetWeakPtr ()));
156
+ }
157
+ return true ;
158
+ }
159
+ #endif
160
+
137
161
model_->Clear ();
138
162
139
163
// Create the default menu model.
@@ -511,3 +535,18 @@ bool CefMenuManager::IsCustomContextMenuCommand(int command_id) {
511
535
}
512
536
return false ;
513
537
}
538
+
539
+ #if BUILDFLAG(IS_WIN)
540
+ void CefMenuManager::OnGetPlatformSuggestionsComplete (
541
+ const spellcheck::PerLanguageSuggestions&
542
+ platform_per_language_suggestions) {
543
+ std::vector<std::u16string> combined_suggestions;
544
+ spellcheck::FillSuggestions (platform_per_language_suggestions,
545
+ &combined_suggestions);
546
+
547
+ params_.dictionary_suggestions = combined_suggestions;
548
+
549
+ // Now that we have spelling suggestions, call CreateContextMenu again.
550
+ CreateContextMenu (params_, /* query_spellcheck=*/ false );
551
+ }
552
+ #endif
0 commit comments