OLD | NEW |
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 case IDC_SPELLCHECK_ADD_TO_DICTIONARY: | 194 case IDC_SPELLCHECK_ADD_TO_DICTIONARY: |
195 case IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS: | 195 case IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS: |
196 case IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION: | 196 case IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION: |
197 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: | 197 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: |
198 case IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE: | 198 case IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE: |
199 return true; | 199 return true; |
200 | 200 |
201 default: | 201 default: |
202 return false; | 202 return false; |
203 } | 203 } |
204 return false; | |
205 } | 204 } |
206 | 205 |
207 bool SpellingMenuObserver::IsCommandIdChecked(int command_id) { | 206 bool SpellingMenuObserver::IsCommandIdChecked(int command_id) { |
208 DCHECK(IsCommandIdSupported(command_id)); | 207 DCHECK(IsCommandIdSupported(command_id)); |
209 | 208 |
210 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_TOGGLE) | 209 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_TOGGLE) |
211 return integrate_spelling_service_.GetValue() && | 210 return integrate_spelling_service_.GetValue() && |
212 !proxy_->GetProfile()->IsOffTheRecord(); | 211 !proxy_->GetProfile()->IsOffTheRecord(); |
213 else if (command_id == IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE) | 212 if (command_id == IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE) |
214 return autocorrect_spelling_.GetValue() && | 213 return autocorrect_spelling_.GetValue() && |
215 !proxy_->GetProfile()->IsOffTheRecord(); | 214 !proxy_->GetProfile()->IsOffTheRecord(); |
216 return false; | 215 return false; |
217 } | 216 } |
218 | 217 |
219 bool SpellingMenuObserver::IsCommandIdEnabled(int command_id) { | 218 bool SpellingMenuObserver::IsCommandIdEnabled(int command_id) { |
220 DCHECK(IsCommandIdSupported(command_id)); | 219 DCHECK(IsCommandIdSupported(command_id)); |
221 | 220 |
222 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && | 221 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && |
223 command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) | 222 command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) |
(...skipping 13 matching lines...) Expand all Loading... |
237 return integrate_spelling_service_.IsUserModifiable() && | 236 return integrate_spelling_service_.IsUserModifiable() && |
238 !proxy_->GetProfile()->IsOffTheRecord(); | 237 !proxy_->GetProfile()->IsOffTheRecord(); |
239 | 238 |
240 case IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE: | 239 case IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE: |
241 return integrate_spelling_service_.IsUserModifiable() && | 240 return integrate_spelling_service_.IsUserModifiable() && |
242 !proxy_->GetProfile()->IsOffTheRecord(); | 241 !proxy_->GetProfile()->IsOffTheRecord(); |
243 | 242 |
244 default: | 243 default: |
245 return false; | 244 return false; |
246 } | 245 } |
247 return false; | |
248 } | 246 } |
249 | 247 |
250 void SpellingMenuObserver::ExecuteCommand(int command_id) { | 248 void SpellingMenuObserver::ExecuteCommand(int command_id) { |
251 DCHECK(IsCommandIdSupported(command_id)); | 249 DCHECK(IsCommandIdSupported(command_id)); |
252 | 250 |
253 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && | 251 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && |
254 command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) { | 252 command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) { |
255 int suggestion_index = command_id - IDC_SPELLCHECK_SUGGESTION_0; | 253 int suggestion_index = command_id - IDC_SPELLCHECK_SUGGESTION_0; |
256 proxy_->GetRenderViewHost()->ReplaceMisspelling( | 254 proxy_->GetRenderViewHost()->ReplaceMisspelling( |
257 suggestions_[suggestion_index]); | 255 suggestions_[suggestion_index]); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 // Append '.' characters to the end of "Checking". | 409 // Append '.' characters to the end of "Checking". |
412 loading_frame_ = (loading_frame_ + 1) & 3; | 410 loading_frame_ = (loading_frame_ + 1) & 3; |
413 base::string16 loading_message = | 411 base::string16 loading_message = |
414 loading_message_ + base::string16(loading_frame_,'.'); | 412 loading_message_ + base::string16(loading_frame_,'.'); |
415 | 413 |
416 // Update the menu item with the text. We disable this item to prevent users | 414 // Update the menu item with the text. We disable this item to prevent users |
417 // from selecting it. | 415 // from selecting it. |
418 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, | 416 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, |
419 loading_message); | 417 loading_message); |
420 } | 418 } |
OLD | NEW |