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

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

Issue 10548022: Synchronize the check status of the "Check Spelling While Typing" item. (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
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/spellchecker_submenu_observer.h" 5 #include "chrome/browser/tab_contents/spellchecker_submenu_observer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/prefs/pref_member.h" 10 #include "chrome/browser/prefs/pref_member.h"
(...skipping 10 matching lines...) Expand all
21 #include "ui/base/models/simple_menu_model.h" 21 #include "ui/base/models/simple_menu_model.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 24
25 SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver( 25 SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver(
26 RenderViewContextMenuProxy* proxy, 26 RenderViewContextMenuProxy* proxy,
27 ui::SimpleMenuModel::Delegate* delegate, 27 ui::SimpleMenuModel::Delegate* delegate,
28 int group) 28 int group)
29 : proxy_(proxy), 29 : proxy_(proxy),
30 submenu_model_(delegate), 30 submenu_model_(delegate),
31 spellcheck_enabled_(false),
32 language_group_(group), 31 language_group_(group),
33 language_selected_(0) { 32 language_selected_(0) {
34 DCHECK(proxy_); 33 DCHECK(proxy_);
35 } 34 }
36 35
37 SpellCheckerSubMenuObserver::~SpellCheckerSubMenuObserver() { 36 SpellCheckerSubMenuObserver::~SpellCheckerSubMenuObserver() {
38 } 37 }
39 38
40 void SpellCheckerSubMenuObserver::InitMenu( 39 void SpellCheckerSubMenuObserver::InitMenu(
41 const content::ContextMenuParams& params) { 40 const content::ContextMenuParams& params) {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
43 42
44 spellcheck_enabled_ = params.spellcheck_enabled;
45
46 // Add available spell-checker languages to the sub menu. 43 // Add available spell-checker languages to the sub menu.
47 Profile* profile = proxy_->GetProfile(); 44 Profile* profile = proxy_->GetProfile();
48 language_selected_ = 45 language_selected_ =
49 SpellCheckHost::GetSpellCheckLanguages(profile, &languages_); 46 SpellCheckHost::GetSpellCheckLanguages(profile, &languages_);
50 DCHECK(languages_.size() < 47 DCHECK(languages_.size() <
51 IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST); 48 IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST);
52 const std::string app_locale = g_browser_process->GetApplicationLocale(); 49 const std::string app_locale = g_browser_process->GetApplicationLocale();
53 for (size_t i = 0; i < languages_.size(); ++i) { 50 for (size_t i = 0; i < languages_.size(); ++i) {
54 string16 display_name( 51 string16 display_name(
55 l10n_util::GetDisplayNameForLocale(languages_[i], app_locale, true)); 52 l10n_util::GetDisplayNameForLocale(languages_[i], app_locale, true));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 DCHECK(IsCommandIdSupported(command_id)); 105 DCHECK(IsCommandIdSupported(command_id));
109 106
110 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 107 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
111 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) { 108 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
112 return language_selected_ == command_id - IDC_SPELLCHECK_LANGUAGES_FIRST; 109 return language_selected_ == command_id - IDC_SPELLCHECK_LANGUAGES_FIRST;
113 } 110 }
114 111
115 // Check box for 'Check Spelling while typing'. 112 // Check box for 'Check Spelling while typing'.
116 if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) { 113 if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) {
117 Profile* profile = proxy_->GetProfile(); 114 Profile* profile = proxy_->GetProfile();
118 if (!profile || !profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)) 115 return profile && profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck);
jeremy 2012/06/14 14:49:50 nit: can you be more explicite here: if (!profile
Hironori Bono 2012/06/18 07:23:55 Thanks for your comment. I have added a DCHECK() s
119 return false;
120 return spellcheck_enabled_;
121 } 116 }
122 117
123 return false; 118 return false;
124 } 119 }
125 120
126 bool SpellCheckerSubMenuObserver::IsCommandIdEnabled(int command_id) { 121 bool SpellCheckerSubMenuObserver::IsCommandIdEnabled(int command_id) {
127 DCHECK(IsCommandIdSupported(command_id)); 122 DCHECK(IsCommandIdSupported(command_id));
128 123
129 Profile* profile = proxy_->GetProfile(); 124 Profile* profile = proxy_->GetProfile();
130 if (!profile) 125 if (!profile)
131 return false; 126 return false;
132 127
133 const PrefService* pref = profile->GetPrefs(); 128 const PrefService* pref = profile->GetPrefs();
134 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 129 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
135 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) { 130 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
136 return pref->GetBoolean(prefs::kEnableSpellCheck); 131 return pref->GetBoolean(prefs::kEnableSpellCheck);
137 } 132 }
138 133
139 switch (command_id) { 134 switch (command_id) {
140 case IDC_CHECK_SPELLING_WHILE_TYPING: 135 case IDC_CHECK_SPELLING_WHILE_TYPING:
141 return pref->GetBoolean(prefs::kEnableSpellCheck);
142
143 case IDC_SPELLPANEL_TOGGLE: 136 case IDC_SPELLPANEL_TOGGLE:
144 case IDC_SPELLCHECK_MENU: 137 case IDC_SPELLCHECK_MENU:
145 return true; 138 return true;
146 } 139 }
147 140
148 return false; 141 return false;
149 } 142 }
150 143
151 void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) { 144 void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) {
152 DCHECK(IsCommandIdSupported(command_id)); 145 DCHECK(IsCommandIdSupported(command_id));
153 146
154 // Check to see if one of the spell check language ids have been clicked. 147 // Check to see if one of the spell check language ids have been clicked.
148 Profile* profile = proxy_->GetProfile();
155 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 149 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
156 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) { 150 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
157 Profile* profile = proxy_->GetProfile();
158 const size_t language = command_id - IDC_SPELLCHECK_LANGUAGES_FIRST; 151 const size_t language = command_id - IDC_SPELLCHECK_LANGUAGES_FIRST;
159 if (profile && language < languages_.size()) { 152 if (profile && language < languages_.size()) {
160 StringPrefMember dictionary_language; 153 StringPrefMember dictionary_language;
161 dictionary_language.Init(prefs::kSpellCheckDictionary, 154 dictionary_language.Init(prefs::kSpellCheckDictionary,
162 profile->GetPrefs(), 155 profile->GetPrefs(),
163 NULL); 156 NULL);
164 dictionary_language.SetValue(languages_[language]); 157 dictionary_language.SetValue(languages_[language]);
165 } 158 }
166 return; 159 return;
167 } 160 }
168 161
169 content::RenderViewHost* rvh = proxy_->GetRenderViewHost(); 162 content::RenderViewHost* rvh = proxy_->GetRenderViewHost();
170 switch (command_id) { 163 switch (command_id) {
171 case IDC_CHECK_SPELLING_WHILE_TYPING: 164 case IDC_CHECK_SPELLING_WHILE_TYPING:
165 profile->GetPrefs()->SetBoolean(
jeremy 2012/06/14 14:49:50 Do you need to null-check profile here too?
Hironori Bono 2012/06/18 07:23:55 Thanks for your comment. Same as above, I have add
166 prefs::kEnableSpellCheck,
167 !profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck));
172 rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->GetRoutingID())); 168 rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->GetRoutingID()));
173 break; 169 break;
174 } 170 }
175 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698