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

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

Issue 15750002: Send IGNORE feedback to spellcheck service when user cancels spellcheck menu (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Initialize misspelling hash Created 7 years, 7 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
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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 20 matching lines...) Expand all
31 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
32 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/gfx/rect.h" 33 #include "ui/gfx/rect.h"
34 34
35 using content::BrowserThread; 35 using content::BrowserThread;
36 36
37 SpellingMenuObserver::SpellingMenuObserver(RenderViewContextMenuProxy* proxy) 37 SpellingMenuObserver::SpellingMenuObserver(RenderViewContextMenuProxy* proxy)
38 : proxy_(proxy), 38 : proxy_(proxy),
39 loading_frame_(0), 39 loading_frame_(0),
40 succeeded_(false), 40 succeeded_(false),
41 misspelling_hash_(0),
41 client_(new SpellingServiceClient) { 42 client_(new SpellingServiceClient) {
42 if (proxy && proxy->GetProfile()) { 43 if (proxy && proxy->GetProfile()) {
43 integrate_spelling_service_.Init(prefs::kSpellCheckUseSpellingService, 44 integrate_spelling_service_.Init(prefs::kSpellCheckUseSpellingService,
44 proxy->GetProfile()->GetPrefs()); 45 proxy->GetProfile()->GetPrefs());
45 autocorrect_spelling_.Init(prefs::kEnableAutoSpellCorrect, 46 autocorrect_spelling_.Init(prefs::kEnableAutoSpellCorrect,
46 proxy->GetProfile()->GetPrefs()); 47 proxy->GetProfile()->GetPrefs());
47 } 48 }
48 } 49 }
49 50
50 SpellingMenuObserver::~SpellingMenuObserver() { 51 SpellingMenuObserver::~SpellingMenuObserver() {
51 } 52 }
52 53
53 void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) { 54 void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) {
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
55 DCHECK(!params.misspelled_word.empty() || 56 DCHECK(!params.misspelled_word.empty() ||
56 params.dictionary_suggestions.empty()); 57 params.dictionary_suggestions.empty());
57 58
58 // Exit if we are not in an editable element because we add a menu item only 59 // Exit if we are not in an editable element because we add a menu item only
59 // for editable elements. 60 // for editable elements.
60 Profile* profile = proxy_->GetProfile(); 61 Profile* profile = proxy_->GetProfile();
61 if (!params.is_editable || !profile) 62 if (!params.is_editable || !profile)
62 return; 63 return;
63 64
64 // Exit if there is no misspelled word. 65 // Exit if there is no misspelled word.
65 if (params.misspelled_word.empty()) 66 if (params.misspelled_word.empty())
66 return; 67 return;
67 68
68 suggestions_ = params.dictionary_suggestions; 69 suggestions_ = params.dictionary_suggestions;
69 misspelled_word_ = params.misspelled_word; 70 misspelled_word_ = params.misspelled_word;
71 misspelling_hash_ = params.misspelling_hash;
70 72
71 bool use_suggestions = SpellingServiceClient::IsAvailable( 73 bool use_suggestions = SpellingServiceClient::IsAvailable(
72 profile, SpellingServiceClient::SUGGEST); 74 profile, SpellingServiceClient::SUGGEST);
73 75
74 if (!suggestions_.empty() || use_suggestions) 76 if (!suggestions_.empty() || use_suggestions)
75 proxy_->AddSeparator(); 77 proxy_->AddSeparator();
76 78
77 // Append Dictionary spell check suggestions. 79 // Append Dictionary spell check suggestions.
78 for (size_t i = 0; i < params.dictionary_suggestions.size() && 80 for (size_t i = 0; i < params.dictionary_suggestions.size() &&
79 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; 81 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 Profile* profile = proxy_->GetProfile(); 340 Profile* profile = proxy_->GetProfile();
339 if (profile) { 341 if (profile) {
340 bool current_value = autocorrect_spelling_.GetValue(); 342 bool current_value = autocorrect_spelling_.GetValue();
341 profile->GetPrefs()->SetBoolean(prefs::kEnableAutoSpellCorrect, 343 profile->GetPrefs()->SetBoolean(prefs::kEnableAutoSpellCorrect,
342 !current_value); 344 !current_value);
343 } 345 }
344 } 346 }
345 } 347 }
346 } 348 }
347 349
350 void SpellingMenuObserver::OnMenuCancel() {
351 Profile* profile = proxy_->GetProfile();
352 if (!profile)
353 return;
354 SpellcheckService* spellcheck =
355 SpellcheckServiceFactory::GetForProfile(profile);
356 if (!spellcheck)
357 return;
358 spellcheck->GetFeedbackSender()->IgnoredSuggestions(misspelling_hash_);
359 }
360
348 void SpellingMenuObserver::OnTextCheckComplete( 361 void SpellingMenuObserver::OnTextCheckComplete(
349 SpellingServiceClient::ServiceType type, 362 SpellingServiceClient::ServiceType type,
350 bool success, 363 bool success,
351 const string16& text, 364 const string16& text,
352 const std::vector<SpellCheckResult>& results) { 365 const std::vector<SpellCheckResult>& results) {
353 animation_timer_.Stop(); 366 animation_timer_.Stop();
354 367
355 // Scan the text-check results and replace the misspelled regions with 368 // Scan the text-check results and replace the misspelled regions with
356 // suggested words. If the replaced text is included in the suggestion list 369 // suggested words. If the replaced text is included in the suggestion list
357 // provided by the local spellchecker, we show a "No suggestions from Google" 370 // provided by the local spellchecker, we show a "No suggestions from Google"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 void SpellingMenuObserver::OnAnimationTimerExpired() { 403 void SpellingMenuObserver::OnAnimationTimerExpired() {
391 // Append '.' characters to the end of "Checking". 404 // Append '.' characters to the end of "Checking".
392 loading_frame_ = (loading_frame_ + 1) & 3; 405 loading_frame_ = (loading_frame_ + 1) & 3;
393 string16 loading_message = loading_message_ + string16(loading_frame_,'.'); 406 string16 loading_message = loading_message_ + string16(loading_frame_,'.');
394 407
395 // Update the menu item with the text. We disable this item to prevent users 408 // Update the menu item with the text. We disable this item to prevent users
396 // from selecting it. 409 // from selecting it.
397 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, 410 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false,
398 loading_message); 411 loading_message);
399 } 412 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/spelling_menu_observer.h ('k') | content/public/common/context_menu_params.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698