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

Side by Side Diff: chrome/browser/tab_contents/spellchecker_submenu_observer_mac.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/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" 10 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
11 #include "chrome/browser/tab_contents/render_view_context_menu.h" 11 #include "chrome/browser/tab_contents/render_view_context_menu.h"
12 #include "chrome/browser/tab_contents/spelling_bubble_model.h" 12 #include "chrome/browser/tab_contents/spelling_bubble_model.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "chrome/common/spellcheck_messages.h" 15 #include "chrome/common/spellcheck_messages.h"
16 #include "content/public/browser/render_view_host.h" 16 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/render_widget_host_view.h" 17 #include "content/public/browser/render_widget_host_view.h"
18 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/models/simple_menu_model.h" 20 #include "ui/base/models/simple_menu_model.h"
21 21
22 using content::BrowserThread; 22 using content::BrowserThread;
23 23
24 SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver( 24 SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver(
25 RenderViewContextMenuProxy* proxy, 25 RenderViewContextMenuProxy* proxy,
26 ui::SimpleMenuModel::Delegate* delegate, 26 ui::SimpleMenuModel::Delegate* delegate,
27 int group) 27 int group)
28 : proxy_(proxy), 28 : proxy_(proxy),
29 submenu_model_(delegate), 29 submenu_model_(delegate) {
30 check_spelling_while_typing_(false) {
31 DCHECK(proxy_); 30 DCHECK(proxy_);
32 } 31 }
33 32
34 SpellCheckerSubMenuObserver::~SpellCheckerSubMenuObserver() { 33 SpellCheckerSubMenuObserver::~SpellCheckerSubMenuObserver() {
35 } 34 }
36 35
37 void SpellCheckerSubMenuObserver::InitMenu( 36 void SpellCheckerSubMenuObserver::InitMenu(
38 const content::ContextMenuParams& params) { 37 const content::ContextMenuParams& params) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
40 39
41 check_spelling_while_typing_ = params.spellcheck_enabled;
42
43 // Add an item that toggles the spelling panel. 40 // Add an item that toggles the spelling panel.
44 submenu_model_.AddCheckItem( 41 submenu_model_.AddCheckItem(
45 IDC_SPELLPANEL_TOGGLE, 42 IDC_SPELLPANEL_TOGGLE,
46 l10n_util::GetStringUTF16( 43 l10n_util::GetStringUTF16(
47 spellcheck_mac::SpellingPanelVisible() ? 44 spellcheck_mac::SpellingPanelVisible() ?
48 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : 45 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL :
49 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); 46 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL));
50 submenu_model_.AddSeparator(); 47 submenu_model_.AddSeparator();
51 48
52 // Add a 'Check Spelling While Typing' item in the sub menu. 49 // Add a 'Check Spelling While Typing' item in the sub menu.
(...skipping 24 matching lines...) Expand all
77 74
78 return false; 75 return false;
79 } 76 }
80 77
81 bool SpellCheckerSubMenuObserver::IsCommandIdChecked(int command_id) { 78 bool SpellCheckerSubMenuObserver::IsCommandIdChecked(int command_id) {
82 DCHECK(IsCommandIdSupported(command_id)); 79 DCHECK(IsCommandIdSupported(command_id));
83 80
84 // Check box for 'Check Spelling while typing'. 81 // Check box for 'Check Spelling while typing'.
85 if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) { 82 if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) {
86 Profile* profile = proxy_->GetProfile(); 83 Profile* profile = proxy_->GetProfile();
87 if (!profile || !profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck)) 84 DCHECK(profile);
88 return false; 85 return profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck);
89 return check_spelling_while_typing_;
90 } 86 }
91 87
92 return false; 88 return false;
93 } 89 }
94 90
95 bool SpellCheckerSubMenuObserver::IsCommandIdEnabled(int command_id) { 91 bool SpellCheckerSubMenuObserver::IsCommandIdEnabled(int command_id) {
96 DCHECK(IsCommandIdSupported(command_id)); 92 DCHECK(IsCommandIdSupported(command_id));
97 93
98 Profile* profile = proxy_->GetProfile();
99 if (!profile)
100 return false;
101
102 const PrefService* pref = profile->GetPrefs();
103
104 switch (command_id) { 94 switch (command_id) {
105 case IDC_CHECK_SPELLING_WHILE_TYPING: 95 case IDC_CHECK_SPELLING_WHILE_TYPING:
106 return pref->GetBoolean(prefs::kEnableSpellCheck);
107
108 case IDC_SPELLPANEL_TOGGLE: 96 case IDC_SPELLPANEL_TOGGLE:
109 case IDC_SPELLCHECK_MENU: 97 case IDC_SPELLCHECK_MENU:
110 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: 98 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE:
111 return true; 99 return true;
112 } 100 }
113 101
114 return false; 102 return false;
115 } 103 }
116 104
117 void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) { 105 void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) {
118 DCHECK(IsCommandIdSupported(command_id)); 106 DCHECK(IsCommandIdSupported(command_id));
119 107
120 content::RenderViewHost* rvh = proxy_->GetRenderViewHost(); 108 content::RenderViewHost* rvh = proxy_->GetRenderViewHost();
109 Profile* profile = proxy_->GetProfile();
110 DCHECK(profile);
121 switch (command_id) { 111 switch (command_id) {
122 case IDC_CHECK_SPELLING_WHILE_TYPING: 112 case IDC_CHECK_SPELLING_WHILE_TYPING:
123 rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->GetRoutingID())); 113 profile->GetPrefs()->SetBoolean(
114 prefs::kEnableSpellCheck,
115 !profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck));
116 if (rvh)
117 rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->GetRoutingID()));
124 break; 118 break;
125 119
126 case IDC_SPELLPANEL_TOGGLE: 120 case IDC_SPELLPANEL_TOGGLE:
127 rvh->Send(new SpellCheckMsg_ToggleSpellPanel( 121 rvh->Send(new SpellCheckMsg_ToggleSpellPanel(
128 rvh->GetRoutingID(), spellcheck_mac::SpellingPanelVisible())); 122 rvh->GetRoutingID(), spellcheck_mac::SpellingPanelVisible()));
129 break; 123 break;
130 } 124 }
131 } 125 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/spellchecker_submenu_observer_hunspell.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698