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

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

Issue 9562002: Use a check item instead of changing its text. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
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/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 proxy_->AddSeparator(); 100 proxy_->AddSeparator();
101 101
102 // |spellcheck_host| can be null when the suggested word is 102 // |spellcheck_host| can be null when the suggested word is
103 // provided by Web SpellCheck API. 103 // provided by Web SpellCheck API.
104 SpellCheckHost* spellcheck_host = 104 SpellCheckHost* spellcheck_host =
105 SpellCheckFactory::GetHostForProfile(profile); 105 SpellCheckFactory::GetHostForProfile(profile);
106 if (spellcheck_host && spellcheck_host->GetMetrics()) 106 if (spellcheck_host && spellcheck_host->GetMetrics())
107 spellcheck_host->GetMetrics()->RecordSuggestionStats(1); 107 spellcheck_host->GetMetrics()->RecordSuggestionStats(1);
108 } 108 }
109 109
110 // If word is misspelled, give option for "Add to dictionary" and "Ask Google 110 // If word is misspelled, give option for "Add to dictionary" and a check item
111 // for suggestions". (The SpellCheckerSubMenuObserver class handles the "Ask 111 // "Ask Google for suggestions".
112 // Goole for suggestions" item so this class does not have to handle it.)
113 if (!params.misspelled_word.empty()) { 112 if (!params.misspelled_word.empty()) {
114 if (params.dictionary_suggestions.empty()) { 113 if (params.dictionary_suggestions.empty()) {
115 proxy_->AddMenuItem(IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS, 114 proxy_->AddMenuItem(IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS,
116 l10n_util::GetStringUTF16( 115 l10n_util::GetStringUTF16(
117 IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS)); 116 IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS));
118 } 117 }
119 misspelled_word_ = params.misspelled_word; 118 misspelled_word_ = params.misspelled_word;
120 proxy_->AddMenuItem(IDC_SPELLCHECK_ADD_TO_DICTIONARY, 119 proxy_->AddMenuItem(IDC_SPELLCHECK_ADD_TO_DICTIONARY,
121 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY)); 120 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY));
122 121
123 integrate_spelling_service_ = 122 integrate_spelling_service_ =
124 profile->GetPrefs()->GetBoolean(prefs::kSpellCheckUseSpellingService); 123 profile->GetPrefs()->GetBoolean(prefs::kSpellCheckUseSpellingService);
125 int spelling_message = integrate_spelling_service_ ? 124 proxy_->AddCheckItem(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE,
126 IDS_CONTENT_CONTEXT_SPELLING_STOP_ASKING_GOOGLE : 125 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE));
127 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE;
128 proxy_->AddMenuItem(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE,
129 l10n_util::GetStringUTF16(spelling_message));
130 126
131 proxy_->AddSeparator(); 127 proxy_->AddSeparator();
132 } 128 }
133 } 129 }
134 130
135 bool SpellingMenuObserver::IsCommandIdSupported(int command_id) { 131 bool SpellingMenuObserver::IsCommandIdSupported(int command_id) {
136 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && 132 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 &&
137 command_id <= IDC_SPELLCHECK_SUGGESTION_4) 133 command_id <= IDC_SPELLCHECK_SUGGESTION_4)
138 return true; 134 return true;
139 135
140 switch (command_id) { 136 switch (command_id) {
141 case IDC_SPELLCHECK_ADD_TO_DICTIONARY: 137 case IDC_SPELLCHECK_ADD_TO_DICTIONARY:
142 case IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS: 138 case IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS:
143 case IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION: 139 case IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION:
144 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: 140 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE:
145 return true; 141 return true;
146 142
147 default: 143 default:
148 return false; 144 return false;
149 } 145 }
150 return false; 146 return false;
151 } 147 }
152 148
149 bool SpellingMenuObserver::IsCommandIdChecked(int command_id) {
150 DCHECK(IsCommandIdSupported(command_id));
151
152 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_TOGGLE)
153 return integrate_spelling_service_;
154 return false;
155 }
156
153 bool SpellingMenuObserver::IsCommandIdEnabled(int command_id) { 157 bool SpellingMenuObserver::IsCommandIdEnabled(int command_id) {
154 DCHECK(IsCommandIdSupported(command_id)); 158 DCHECK(IsCommandIdSupported(command_id));
155 159
156 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && 160 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 &&
157 command_id <= IDC_SPELLCHECK_SUGGESTION_4) 161 command_id <= IDC_SPELLCHECK_SUGGESTION_4)
158 return true; 162 return true;
159 163
160 switch (command_id) { 164 switch (command_id) {
161 case IDC_SPELLCHECK_ADD_TO_DICTIONARY: 165 case IDC_SPELLCHECK_ADD_TO_DICTIONARY:
162 return !misspelled_word_.empty(); 166 return !misspelled_word_.empty();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 SpellCheckHost* host = SpellCheckFactory::GetHostForProfile(profile); 216 SpellCheckHost* host = SpellCheckFactory::GetHostForProfile(profile);
213 if (host) 217 if (host)
214 host->AddWord(UTF16ToUTF8(misspelled_word_)); 218 host->AddWord(UTF16ToUTF8(misspelled_word_));
215 } 219 }
216 #if defined(OS_MACOSX) 220 #if defined(OS_MACOSX)
217 spellcheck_mac::AddWord(misspelled_word_); 221 spellcheck_mac::AddWord(misspelled_word_);
218 #endif 222 #endif
219 } 223 }
220 224
221 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_TOGGLE) { 225 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_TOGGLE) {
222 // When a user chooses the "Ask Google for spelling suggestions" item, we 226 // When a user enables the "Ask Google for spelling suggestions" item, we
223 // show a bubble to confirm it. On the other hand, when a user chooses the 227 // show a bubble to confirm it. On the other hand, when a user disables this
224 // "Stop asking Google for spelling suggestions" item, we directly update 228 // item, we directly update/ the profile and stop integrating the spelling
225 // the profile and stop integrating the spelling service immediately. 229 // service immediately.
226 if (!integrate_spelling_service_) { 230 if (!integrate_spelling_service_) {
227 RenderViewHost* rvh = proxy_->GetRenderViewHost(); 231 RenderViewHost* rvh = proxy_->GetRenderViewHost();
228 gfx::Rect rect = rvh->view()->GetViewBounds(); 232 gfx::Rect rect = rvh->view()->GetViewBounds();
229 ConfirmBubbleModel::Show(rvh->view()->GetNativeView(), 233 ConfirmBubbleModel::Show(rvh->view()->GetNativeView(),
230 gfx::Point(rect.CenterPoint().x(), rect.y()), 234 gfx::Point(rect.CenterPoint().x(), rect.y()),
231 new SpellingBubbleModel(proxy_->GetProfile())); 235 new SpellingBubbleModel(proxy_->GetProfile()));
232 } else { 236 } else {
233 Profile* profile = proxy_->GetProfile(); 237 Profile* profile = proxy_->GetProfile();
234 if (profile) 238 if (profile)
235 profile->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, 239 profile->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 loading_frame_ = (loading_frame_ + 1) & 3; 284 loading_frame_ = (loading_frame_ + 1) & 3;
281 string16 loading_message = loading_message_; 285 string16 loading_message = loading_message_;
282 for (int i = 0; i < loading_frame_; ++i) 286 for (int i = 0; i < loading_frame_; ++i)
283 loading_message.push_back('.'); 287 loading_message.push_back('.');
284 288
285 // Update the menu item with the text. We disable this item to prevent users 289 // Update the menu item with the text. We disable this item to prevent users
286 // from selecting it. 290 // from selecting it.
287 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, 291 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false,
288 loading_message); 292 loading_message);
289 } 293 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698