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

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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 DCHECK(IsCommandIdSupported(command_id)); 108 DCHECK(IsCommandIdSupported(command_id));
109 109
110 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 110 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
111 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) { 111 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
112 return language_selected_ == command_id - IDC_SPELLCHECK_LANGUAGES_FIRST; 112 return language_selected_ == command_id - IDC_SPELLCHECK_LANGUAGES_FIRST;
113 } 113 }
114 114
115 // Check box for 'Check Spelling while typing'. 115 // Check box for 'Check Spelling while typing'.
116 if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) { 116 if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) {
117 Profile* profile = proxy_->GetProfile(); 117 Profile* profile = proxy_->GetProfile();
118 if (!profile || !profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)) 118 return profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck);
119 return false;
120 return spellcheck_enabled_;
121 } 119 }
122 120
123 return false; 121 return false;
124 } 122 }
125 123
126 bool SpellCheckerSubMenuObserver::IsCommandIdEnabled(int command_id) { 124 bool SpellCheckerSubMenuObserver::IsCommandIdEnabled(int command_id) {
127 DCHECK(IsCommandIdSupported(command_id)); 125 DCHECK(IsCommandIdSupported(command_id));
128 126
129 Profile* profile = proxy_->GetProfile(); 127 Profile* profile = proxy_->GetProfile();
130 if (!profile) 128 if (!profile)
131 return false; 129 return false;
132 130
133 const PrefService* pref = profile->GetPrefs(); 131 const PrefService* pref = profile->GetPrefs();
134 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 132 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
135 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) { 133 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
136 return pref->GetBoolean(prefs::kEnableSpellCheck); 134 return pref->GetBoolean(prefs::kEnableSpellCheck);
137 } 135 }
138 136
139 switch (command_id) { 137 switch (command_id) {
140 case IDC_CHECK_SPELLING_WHILE_TYPING: 138 case IDC_CHECK_SPELLING_WHILE_TYPING:
141 return pref->GetBoolean(prefs::kEnableSpellCheck);
142
143 case IDC_SPELLPANEL_TOGGLE: 139 case IDC_SPELLPANEL_TOGGLE:
144 case IDC_SPELLCHECK_MENU: 140 case IDC_SPELLCHECK_MENU:
145 return true; 141 return true;
146 } 142 }
147 143
148 return false; 144 return false;
149 } 145 }
150 146
151 void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) { 147 void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) {
152 DCHECK(IsCommandIdSupported(command_id)); 148 DCHECK(IsCommandIdSupported(command_id));
153 149
154 // Check to see if one of the spell check language ids have been clicked. 150 // Check to see if one of the spell check language ids have been clicked.
151 Profile* profile = proxy_->GetProfile();
155 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 152 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
156 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) { 153 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
157 Profile* profile = proxy_->GetProfile();
158 const size_t language = command_id - IDC_SPELLCHECK_LANGUAGES_FIRST; 154 const size_t language = command_id - IDC_SPELLCHECK_LANGUAGES_FIRST;
159 if (profile && language < languages_.size()) { 155 if (profile && language < languages_.size()) {
160 StringPrefMember dictionary_language; 156 StringPrefMember dictionary_language;
161 dictionary_language.Init(prefs::kSpellCheckDictionary, 157 dictionary_language.Init(prefs::kSpellCheckDictionary,
162 profile->GetPrefs(), 158 profile->GetPrefs(),
163 NULL); 159 NULL);
164 dictionary_language.SetValue(languages_[language]); 160 dictionary_language.SetValue(languages_[language]);
165 } 161 }
166 return; 162 return;
167 } 163 }
168 164
169 content::RenderViewHost* rvh = proxy_->GetRenderViewHost(); 165 content::RenderViewHost* rvh = proxy_->GetRenderViewHost();
170 switch (command_id) { 166 switch (command_id) {
171 case IDC_CHECK_SPELLING_WHILE_TYPING: 167 case IDC_CHECK_SPELLING_WHILE_TYPING:
168 profile->GetPrefs()->SetBoolean(
169 prefs::kEnableSpellCheck,
170 !profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck));
172 rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->GetRoutingID())); 171 rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->GetRoutingID()));
173 break; 172 break;
174 } 173 }
175 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698