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_options_submenu_observer
.h" | 5 #include "chrome/browser/renderer_context_menu/spelling_options_submenu_observer
.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 12 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
13 #include "chrome/browser/spellchecker/spellcheck_service.h" | 13 #include "chrome/browser/spellchecker/spellcheck_service.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/pref_names.h" | |
16 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
17 #include "components/prefs/pref_member.h" | 16 #include "components/prefs/pref_member.h" |
18 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
19 #include "components/renderer_context_menu/render_view_context_menu_proxy.h" | 18 #include "components/renderer_context_menu/render_view_context_menu_proxy.h" |
| 19 #include "components/spellcheck/browser/pref_names.h" |
20 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/models/menu_separator_types.h" | 23 #include "ui/base/models/menu_separator_types.h" |
24 | 24 |
25 using content::BrowserThread; | 25 using content::BrowserThread; |
26 | 26 |
27 SpellingOptionsSubMenuObserver::SpellingOptionsSubMenuObserver( | 27 SpellingOptionsSubMenuObserver::SpellingOptionsSubMenuObserver( |
28 RenderViewContextMenuProxy* proxy, | 28 RenderViewContextMenuProxy* proxy, |
29 ui::SimpleMenuModel::Delegate* delegate, | 29 ui::SimpleMenuModel::Delegate* delegate, |
30 int group_id) | 30 int group_id) |
31 : proxy_(proxy), | 31 : proxy_(proxy), |
32 submenu_model_(delegate), | 32 submenu_model_(delegate), |
33 language_group_id_(group_id), | 33 language_group_id_(group_id), |
34 num_selected_dictionaries_(0) { | 34 num_selected_dictionaries_(0) { |
35 if (proxy_ && proxy_->GetBrowserContext()) { | 35 if (proxy_ && proxy_->GetBrowserContext()) { |
36 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); | 36 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); |
37 use_spelling_service_.Init(prefs::kSpellCheckUseSpellingService, | 37 use_spelling_service_.Init(spellcheck::prefs::kSpellCheckUseSpellingService, |
38 profile->GetPrefs()); | 38 profile->GetPrefs()); |
39 } | 39 } |
40 DCHECK(proxy_); | 40 DCHECK(proxy_); |
41 } | 41 } |
42 | 42 |
43 SpellingOptionsSubMenuObserver::~SpellingOptionsSubMenuObserver() {} | 43 SpellingOptionsSubMenuObserver::~SpellingOptionsSubMenuObserver() {} |
44 | 44 |
45 void SpellingOptionsSubMenuObserver::InitMenu( | 45 void SpellingOptionsSubMenuObserver::InitMenu( |
46 const content::ContextMenuParams& params) { | 46 const content::ContextMenuParams& params) { |
47 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 return dictionaries_.size() == 1; | 128 return dictionaries_.size() == 1; |
129 | 129 |
130 size_t dictionary_index = | 130 size_t dictionary_index = |
131 static_cast<size_t>(command_id - IDC_SPELLCHECK_LANGUAGES_FIRST); | 131 static_cast<size_t>(command_id - IDC_SPELLCHECK_LANGUAGES_FIRST); |
132 return dictionaries_[dictionary_index].used_for_spellcheck; | 132 return dictionaries_[dictionary_index].used_for_spellcheck; |
133 } | 133 } |
134 | 134 |
135 // Check box for 'Check Spelling while typing'. | 135 // Check box for 'Check Spelling while typing'. |
136 if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) { | 136 if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) { |
137 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); | 137 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); |
138 return profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck); | 138 return profile->GetPrefs()->GetBoolean( |
| 139 spellcheck::prefs::kEnableContinuousSpellcheck); |
139 } | 140 } |
140 | 141 |
141 return false; | 142 return false; |
142 } | 143 } |
143 | 144 |
144 bool SpellingOptionsSubMenuObserver::IsCommandIdEnabled(int command_id) { | 145 bool SpellingOptionsSubMenuObserver::IsCommandIdEnabled(int command_id) { |
145 DCHECK(IsCommandIdSupported(command_id)); | 146 DCHECK(IsCommandIdSupported(command_id)); |
146 | 147 |
147 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); | 148 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); |
148 DCHECK(profile); | 149 DCHECK(profile); |
149 const PrefService* pref = profile->GetPrefs(); | 150 const PrefService* pref = profile->GetPrefs(); |
150 if ((command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && | 151 if ((command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && |
151 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) || | 152 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) || |
152 command_id == IDC_SPELLCHECK_MULTI_LINGUAL) { | 153 command_id == IDC_SPELLCHECK_MULTI_LINGUAL) { |
153 return pref->GetBoolean(prefs::kEnableContinuousSpellcheck); | 154 return pref->GetBoolean(spellcheck::prefs::kEnableContinuousSpellcheck); |
154 } | 155 } |
155 | 156 |
156 switch (command_id) { | 157 switch (command_id) { |
157 case IDC_CHECK_SPELLING_WHILE_TYPING: | 158 case IDC_CHECK_SPELLING_WHILE_TYPING: |
158 case IDC_SPELLCHECK_MENU: | 159 case IDC_SPELLCHECK_MENU: |
159 return true; | 160 return true; |
160 } | 161 } |
161 | 162 |
162 return false; | 163 return false; |
163 } | 164 } |
164 | 165 |
165 void SpellingOptionsSubMenuObserver::ExecuteCommand(int command_id) { | 166 void SpellingOptionsSubMenuObserver::ExecuteCommand(int command_id) { |
166 DCHECK(IsCommandIdSupported(command_id)); | 167 DCHECK(IsCommandIdSupported(command_id)); |
167 | 168 |
168 // Check to see if one of the spell check language ids have been clicked. | 169 // Check to see if one of the spell check language ids have been clicked. |
169 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); | 170 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); |
170 DCHECK(profile); | 171 DCHECK(profile); |
171 | 172 |
172 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && | 173 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && |
173 static_cast<size_t>(command_id) < | 174 static_cast<size_t>(command_id) < |
174 IDC_SPELLCHECK_LANGUAGES_FIRST + dictionaries_.size()) { | 175 IDC_SPELLCHECK_LANGUAGES_FIRST + dictionaries_.size()) { |
175 size_t dictionary_index = | 176 size_t dictionary_index = |
176 static_cast<size_t>(command_id - IDC_SPELLCHECK_LANGUAGES_FIRST); | 177 static_cast<size_t>(command_id - IDC_SPELLCHECK_LANGUAGES_FIRST); |
177 StringListPrefMember dictionaries_pref; | 178 StringListPrefMember dictionaries_pref; |
178 dictionaries_pref.Init(prefs::kSpellCheckDictionaries, profile->GetPrefs()); | 179 dictionaries_pref.Init(spellcheck::prefs::kSpellCheckDictionaries, |
| 180 profile->GetPrefs()); |
179 dictionaries_pref.SetValue({dictionaries_[dictionary_index].language}); | 181 dictionaries_pref.SetValue({dictionaries_[dictionary_index].language}); |
180 return; | 182 return; |
181 } | 183 } |
182 | 184 |
183 switch (command_id) { | 185 switch (command_id) { |
184 case IDC_CHECK_SPELLING_WHILE_TYPING: | 186 case IDC_CHECK_SPELLING_WHILE_TYPING: |
185 profile->GetPrefs()->SetBoolean( | 187 profile->GetPrefs()->SetBoolean( |
186 prefs::kEnableContinuousSpellcheck, | 188 spellcheck::prefs::kEnableContinuousSpellcheck, |
187 !profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck)); | 189 !profile->GetPrefs()->GetBoolean( |
| 190 spellcheck::prefs::kEnableContinuousSpellcheck)); |
188 break; | 191 break; |
189 | 192 |
190 case IDC_SPELLCHECK_MULTI_LINGUAL: | 193 case IDC_SPELLCHECK_MULTI_LINGUAL: |
191 StringListPrefMember dictionaries_pref; | 194 StringListPrefMember dictionaries_pref; |
192 dictionaries_pref.Init(prefs::kSpellCheckDictionaries, | 195 dictionaries_pref.Init(spellcheck::prefs::kSpellCheckDictionaries, |
193 profile->GetPrefs()); | 196 profile->GetPrefs()); |
194 std::vector<std::string> all_languages; | 197 std::vector<std::string> all_languages; |
195 for (const auto& dictionary : dictionaries_) | 198 for (const auto& dictionary : dictionaries_) |
196 all_languages.push_back(dictionary.language); | 199 all_languages.push_back(dictionary.language); |
197 dictionaries_pref.SetValue(all_languages); | 200 dictionaries_pref.SetValue(all_languages); |
198 break; | 201 break; |
199 } | 202 } |
200 } | 203 } |
OLD | NEW |