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

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

Issue 1357393002: Desktop context menu reorganisation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/renderer_context_menu/spelling_menu_observer.h" 5 #include "chrome/browser/renderer_context_menu/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 17 matching lines...) Expand all
28 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/render_widget_host_view.h" 29 #include "content/public/browser/render_widget_host_view.h"
30 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
31 #include "content/public/common/context_menu_params.h" 31 #include "content/public/common/context_menu_params.h"
32 #include "extensions/browser/view_type_utils.h" 32 #include "extensions/browser/view_type_utils.h"
33 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/gfx/geometry/rect.h" 34 #include "ui/gfx/geometry/rect.h"
35 35
36 using content::BrowserThread; 36 using content::BrowserThread;
37 37
38 const int kMaxSpellingSuggestions = 3;
39
38 SpellingMenuObserver::SpellingMenuObserver(RenderViewContextMenuProxy* proxy) 40 SpellingMenuObserver::SpellingMenuObserver(RenderViewContextMenuProxy* proxy)
39 : proxy_(proxy), 41 : proxy_(proxy),
40 loading_frame_(0), 42 loading_frame_(0),
41 succeeded_(false), 43 succeeded_(false),
42 misspelling_hash_(0), 44 misspelling_hash_(0),
43 client_(new SpellingServiceClient) { 45 client_(new SpellingServiceClient) {
44 if (proxy_ && proxy_->GetBrowserContext()) { 46 if (proxy_ && proxy_->GetBrowserContext()) {
45 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); 47 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext());
46 integrate_spelling_service_.Init(prefs::kSpellCheckUseSpellingService, 48 integrate_spelling_service_.Init(prefs::kSpellCheckUseSpellingService,
47 profile->GetPrefs()); 49 profile->GetPrefs());
(...skipping 24 matching lines...) Expand all
72 misspelled_word_ = params.misspelled_word; 74 misspelled_word_ = params.misspelled_word;
73 misspelling_hash_ = params.misspelling_hash; 75 misspelling_hash_ = params.misspelling_hash;
74 76
75 bool use_suggestions = SpellingServiceClient::IsAvailable( 77 bool use_suggestions = SpellingServiceClient::IsAvailable(
76 browser_context, SpellingServiceClient::SUGGEST); 78 browser_context, SpellingServiceClient::SUGGEST);
77 79
78 if (!suggestions_.empty() || use_suggestions) 80 if (!suggestions_.empty() || use_suggestions)
79 proxy_->AddSeparator(); 81 proxy_->AddSeparator();
80 82
81 // Append Dictionary spell check suggestions. 83 // Append Dictionary spell check suggestions.
82 for (size_t i = 0; i < params.dictionary_suggestions.size() && 84 size_t length = params.dictionary_suggestions.size() > kMaxSpellingSuggestions
85 ? kMaxSpellingSuggestions : params.dictionary_suggestions.size();
Avi (use Gerrit) 2015/09/26 02:26:15 std::min! (Bad indenting, anyway.)
edwardjung 2015/09/28 14:11:25 Apologies, my poor C++ knowledge is really showing
86 for (size_t i = 0; i < length &&
83 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; 87 IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST;
84 ++i) { 88 ++i) {
85 proxy_->AddMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i), 89 proxy_->AddMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i),
86 params.dictionary_suggestions[i]); 90 params.dictionary_suggestions[i]);
87 } 91 }
88 92
89 // The service types |SpellingServiceClient::SPELLCHECK| and 93 // The service types |SpellingServiceClient::SPELLCHECK| and
90 // |SpellingServiceClient::SUGGEST| are mutually exclusive. Only one is 94 // |SpellingServiceClient::SUGGEST| are mutually exclusive. Only one is
91 // available at at time. 95 // available at at time.
92 // 96 //
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 base::Bind(&SpellingMenuObserver::OnTextCheckComplete, 143 base::Bind(&SpellingMenuObserver::OnTextCheckComplete,
140 base::Unretained(this), 144 base::Unretained(this),
141 SpellingServiceClient::SUGGEST)); 145 SpellingServiceClient::SUGGEST));
142 if (result) { 146 if (result) {
143 loading_frame_ = 0; 147 loading_frame_ = 0;
144 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), 148 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1),
145 this, &SpellingMenuObserver::OnAnimationTimerExpired); 149 this, &SpellingMenuObserver::OnAnimationTimerExpired);
146 } 150 }
147 } 151 }
148 152
149 if (params.dictionary_suggestions.empty()) { 153 if (!params.dictionary_suggestions.empty()) {
150 proxy_->AddMenuItem(
151 IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS,
152 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS));
153 bool use_spelling_service = SpellingServiceClient::IsAvailable(
154 browser_context, SpellingServiceClient::SPELLCHECK);
155 if (use_suggestions || use_spelling_service)
156 proxy_->AddSeparator();
157 } else {
158 proxy_->AddSeparator();
159
160 // |spellcheck_service| can be null when the suggested word is 154 // |spellcheck_service| can be null when the suggested word is
161 // provided by Web SpellCheck API. 155 // provided by Web SpellCheck API.
162 SpellcheckService* spellcheck_service = 156 SpellcheckService* spellcheck_service =
163 SpellcheckServiceFactory::GetForContext(browser_context); 157 SpellcheckServiceFactory::GetForContext(browser_context);
164 if (spellcheck_service && spellcheck_service->GetMetrics()) 158 if (spellcheck_service && spellcheck_service->GetMetrics())
165 spellcheck_service->GetMetrics()->RecordSuggestionStats(1); 159 spellcheck_service->GetMetrics()->RecordSuggestionStats(1);
166 } 160 }
167 161
168 // If word is misspelled, give option for "Add to dictionary" and, if 162 // If word is misspelled, give option for "Add to dictionary" and, if
169 // multilingual spellchecking is not enabled, a check item "Ask Google for 163 // multilingual spellchecking is not enabled, a check item "Ask Google for
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // Append '.' characters to the end of "Checking". 403 // Append '.' characters to the end of "Checking".
410 loading_frame_ = (loading_frame_ + 1) & 3; 404 loading_frame_ = (loading_frame_ + 1) & 3;
411 base::string16 loading_message = 405 base::string16 loading_message =
412 loading_message_ + base::string16(loading_frame_,'.'); 406 loading_message_ + base::string16(loading_frame_,'.');
413 407
414 // 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
415 // from selecting it. 409 // from selecting it.
416 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, 410 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false,
417 loading_message); 411 loading_message);
418 } 412 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698