Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/tab_contents/spelling_menu_observer.cc

Issue 10536190: Use WebFrame::replaceMisspelledRange() to replace a misspelled range with text. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/spellcheck_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/tab_contents/spelling_menu_observer.h" 5 #include "chrome/browser/tab_contents/spelling_menu_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/spellchecker/spellcheck_factory.h" 13 #include "chrome/browser/spellchecker/spellcheck_factory.h"
14 #include "chrome/browser/spellchecker/spellcheck_host.h" 14 #include "chrome/browser/spellchecker/spellcheck_host.h"
15 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" 15 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
16 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" 16 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
17 #include "chrome/browser/spellchecker/spelling_service_client.h" 17 #include "chrome/browser/spellchecker/spelling_service_client.h"
18 #include "chrome/browser/tab_contents/render_view_context_menu.h" 18 #include "chrome/browser/tab_contents/render_view_context_menu.h"
19 #include "chrome/browser/tab_contents/spelling_bubble_model.h" 19 #include "chrome/browser/tab_contents/spelling_bubble_model.h"
20 #include "chrome/browser/ui/confirm_bubble.h" 20 #include "chrome/browser/ui/confirm_bubble.h"
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/spellcheck_messages.h"
23 #include "chrome/common/spellcheck_result.h" 24 #include "chrome/common/spellcheck_result.h"
24 #include "content/public/browser/render_view_host.h" 25 #include "content/public/browser/render_view_host.h"
25 #include "content/public/browser/render_widget_host_view.h" 26 #include "content/public/browser/render_widget_host_view.h"
26 #include "content/public/common/context_menu_params.h" 27 #include "content/public/common/context_menu_params.h"
27 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
28 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/gfx/rect.h" 30 #include "ui/gfx/rect.h"
30 31
31 using content::BrowserThread; 32 using content::BrowserThread;
32 33
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return false; 179 return false;
179 } 180 }
180 return false; 181 return false;
181 } 182 }
182 183
183 void SpellingMenuObserver::ExecuteCommand(int command_id) { 184 void SpellingMenuObserver::ExecuteCommand(int command_id) {
184 DCHECK(IsCommandIdSupported(command_id)); 185 DCHECK(IsCommandIdSupported(command_id));
185 186
186 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && 187 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 &&
187 command_id <= IDC_SPELLCHECK_SUGGESTION_4) { 188 command_id <= IDC_SPELLCHECK_SUGGESTION_4) {
188 proxy_->GetRenderViewHost()->Replace( 189 content::RenderViewHost* host = proxy_->GetRenderViewHost();
189 suggestions_[command_id - IDC_SPELLCHECK_SUGGESTION_0]); 190 host->Send(new SpellCheckMsg_Replace(
191 host->GetRoutingID(),
192 suggestions_[command_id - IDC_SPELLCHECK_SUGGESTION_0]));
190 // GetSpellCheckHost() can return null when the suggested word is 193 // GetSpellCheckHost() can return null when the suggested word is
191 // provided by Web SpellCheck API. 194 // provided by Web SpellCheck API.
192 Profile* profile = proxy_->GetProfile(); 195 Profile* profile = proxy_->GetProfile();
193 if (profile) { 196 if (profile) {
194 SpellCheckHost* spellcheck_host = 197 SpellCheckHost* spellcheck_host =
195 SpellCheckFactory::GetHostForProfile(profile); 198 SpellCheckFactory::GetHostForProfile(profile);
196 if (spellcheck_host && spellcheck_host->GetMetrics()) 199 if (spellcheck_host && spellcheck_host->GetMetrics())
197 spellcheck_host->GetMetrics()->RecordReplacedWordStats(1); 200 spellcheck_host->GetMetrics()->RecordReplacedWordStats(1);
198 } 201 }
199 return; 202 return;
200 } 203 }
201 204
202 // When we choose the suggestion sent from the Spelling service, we replace 205 // When we choose the suggestion sent from the Spelling service, we replace
203 // the misspelled word with the suggestion and add it to our custom-word 206 // the misspelled word with the suggestion and add it to our custom-word
204 // dictionary so this word is not marked as misspelled any longer. 207 // dictionary so this word is not marked as misspelled any longer.
205 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION) { 208 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION) {
206 proxy_->GetRenderViewHost()->Replace(result_); 209 content::RenderViewHost* host = proxy_->GetRenderViewHost();
210 host->Send(new SpellCheckMsg_Replace(host->GetRoutingID(), result_));
207 misspelled_word_ = result_; 211 misspelled_word_ = result_;
208 } 212 }
209 213
210 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION || 214 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION ||
211 command_id == IDC_SPELLCHECK_ADD_TO_DICTIONARY) { 215 command_id == IDC_SPELLCHECK_ADD_TO_DICTIONARY) {
212 // GetHostForProfile() can return null when the suggested word is 216 // GetHostForProfile() can return null when the suggested word is
213 // provided by Web SpellCheck API. 217 // provided by Web SpellCheck API.
214 Profile* profile = proxy_->GetProfile(); 218 Profile* profile = proxy_->GetProfile();
215 if (profile) { 219 if (profile) {
216 SpellCheckHost* host = SpellCheckFactory::GetHostForProfile(profile); 220 SpellCheckHost* host = SpellCheckFactory::GetHostForProfile(profile);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 loading_frame_ = (loading_frame_ + 1) & 3; 291 loading_frame_ = (loading_frame_ + 1) & 3;
288 string16 loading_message = loading_message_; 292 string16 loading_message = loading_message_;
289 for (int i = 0; i < loading_frame_; ++i) 293 for (int i = 0; i < loading_frame_; ++i)
290 loading_message.push_back('.'); 294 loading_message.push_back('.');
291 295
292 // Update the menu item with the text. We disable this item to prevent users 296 // Update the menu item with the text. We disable this item to prevent users
293 // from selecting it. 297 // from selecting it.
294 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, 298 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false,
295 loading_message); 299 loading_message);
296 } 300 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/spellcheck_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698