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

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

Issue 8422006: Adds a bubble that asks a user whether to integrate the Spelling service. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/spellchecker/spellcheck_host.h" 12 #include "chrome/browser/spellchecker/spellcheck_host.h"
13 #include "chrome/browser/spellchecker/spellchecker_platform_engine.h" 13 #include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
14 #include "chrome/browser/tab_contents/render_view_context_menu.h" 14 #include "chrome/browser/tab_contents/render_view_context_menu.h"
15 #include "chrome/browser/tab_contents/spelling_bubble_model.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "chrome/common/spellcheck_messages.h" 17 #include "chrome/common/spellcheck_messages.h"
17 #include "content/browser/renderer_host/render_view_host.h" 18 #include "content/browser/renderer_host/render_view_host.h"
19 #include "content/browser/renderer_host/render_widget_host_view.h"
18 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/models/simple_menu_model.h" 22 #include "ui/base/models/simple_menu_model.h"
21 23
22 SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver( 24 SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver(
23 RenderViewContextMenuProxy* proxy, 25 RenderViewContextMenuProxy* proxy,
24 ui::SimpleMenuModel::Delegate* delegate, 26 ui::SimpleMenuModel::Delegate* delegate,
25 int group) 27 int group)
26 : proxy_(proxy), 28 : proxy_(proxy),
27 submenu_model_(delegate), 29 submenu_model_(delegate),
28 spellcheck_enabled_(false), 30 spellcheck_enabled_(false),
31 integrate_spelling_service_(false),
29 language_group_(group), 32 language_group_(group),
30 language_selected_(0) { 33 language_selected_(0) {
31 DCHECK(proxy_); 34 DCHECK(proxy_);
32 } 35 }
33 36
34 SpellCheckerSubMenuObserver::~SpellCheckerSubMenuObserver() { 37 SpellCheckerSubMenuObserver::~SpellCheckerSubMenuObserver() {
35 } 38 }
36 39
37 void SpellCheckerSubMenuObserver::InitMenu(const ContextMenuParams& params) { 40 void SpellCheckerSubMenuObserver::InitMenu(const ContextMenuParams& params) {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (SpellCheckerPlatform::SpellCheckerAvailable() && 74 if (SpellCheckerPlatform::SpellCheckerAvailable() &&
72 SpellCheckerPlatform::SpellCheckerProvidesPanel()) { 75 SpellCheckerPlatform::SpellCheckerProvidesPanel()) {
73 submenu_model_.AddCheckItem( 76 submenu_model_.AddCheckItem(
74 IDC_SPELLPANEL_TOGGLE, 77 IDC_SPELLPANEL_TOGGLE,
75 l10n_util::GetStringUTF16( 78 l10n_util::GetStringUTF16(
76 SpellCheckerPlatform::SpellingPanelVisible() ? 79 SpellCheckerPlatform::SpellingPanelVisible() ?
77 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : 80 IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL :
78 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); 81 IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL));
79 } 82 }
80 83
84 #if defined(OS_WIN)
85 // If we have not integrated the spelling service, we show an "Ask Google for
86 // spelling suggestions" item. On the other hand, if we have integrated the
87 // spelling service, we show "Stop asking Google for spelling suggestions"
88 // item.
89 integrate_spelling_service_ =
90 profile->GetPrefs()->GetBoolean(prefs::kSpellCheckUseSpellingService);
91 int spelling_message = integrate_spelling_service_ ?
92 IDS_CONTENT_CONTEXT_SPELLING_STOP_ASKING_GOOGLE :
93 IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE;
94 submenu_model_.AddCheckItem(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE,
95 l10n_util::GetStringUTF16(spelling_message));
96 #endif
97
81 proxy_->AddSubMenu( 98 proxy_->AddSubMenu(
82 IDC_SPELLCHECK_MENU, 99 IDC_SPELLCHECK_MENU,
83 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU), 100 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU),
84 &submenu_model_); 101 &submenu_model_);
85 } 102 }
86 103
87 bool SpellCheckerSubMenuObserver::IsCommandIdSupported(int command_id) { 104 bool SpellCheckerSubMenuObserver::IsCommandIdSupported(int command_id) {
88 // Allow Spell Check language items on sub menu for text area context menu. 105 // Allow Spell Check language items on sub menu for text area context menu.
89 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 106 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
90 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) { 107 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
91 return true; 108 return true;
92 } 109 }
93 110
94 switch (command_id) { 111 switch (command_id) {
95 case IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS: 112 case IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS:
96 // Return false so RenderViewContextMenu can handle this item because it 113 // Return false so RenderViewContextMenu can handle this item because it
97 // is hard for this class to handle it. 114 // is hard for this class to handle it.
98 return false; 115 return false;
99 116
100 case IDC_CHECK_SPELLING_OF_THIS_FIELD: 117 case IDC_CHECK_SPELLING_OF_THIS_FIELD:
101 case IDC_SPELLPANEL_TOGGLE: 118 case IDC_SPELLPANEL_TOGGLE:
102 case IDC_SPELLCHECK_MENU: 119 case IDC_SPELLCHECK_MENU:
120 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE:
103 return true; 121 return true;
104 } 122 }
105 123
106 return false; 124 return false;
107 } 125 }
108 126
109 bool SpellCheckerSubMenuObserver::IsCommandIdChecked(int command_id) { 127 bool SpellCheckerSubMenuObserver::IsCommandIdChecked(int command_id) {
110 DCHECK(IsCommandIdSupported(command_id)); 128 DCHECK(IsCommandIdSupported(command_id));
111 129
112 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 130 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
(...skipping 23 matching lines...) Expand all
136 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && 154 if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
137 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) { 155 command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
138 return pref->GetBoolean(prefs::kEnableSpellCheck); 156 return pref->GetBoolean(prefs::kEnableSpellCheck);
139 } 157 }
140 158
141 switch (command_id) { 159 switch (command_id) {
142 case IDC_CHECK_SPELLING_OF_THIS_FIELD: 160 case IDC_CHECK_SPELLING_OF_THIS_FIELD:
143 return pref->GetBoolean(prefs::kEnableSpellCheck); 161 return pref->GetBoolean(prefs::kEnableSpellCheck);
144 162
145 case IDC_SPELLPANEL_TOGGLE: 163 case IDC_SPELLPANEL_TOGGLE:
146 return true;
147
148 case IDC_SPELLCHECK_MENU: 164 case IDC_SPELLCHECK_MENU:
165 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE:
149 return true; 166 return true;
150 } 167 }
151 168
152 return false; 169 return false;
153 } 170 }
154 171
155 void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) { 172 void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) {
156 DCHECK(IsCommandIdSupported(command_id)); 173 DCHECK(IsCommandIdSupported(command_id));
157 174
158 // Check to see if one of the spell check language ids have been clicked. 175 // Check to see if one of the spell check language ids have been clicked.
(...skipping 14 matching lines...) Expand all
173 RenderViewHost* rvh = proxy_->GetRenderViewHost(); 190 RenderViewHost* rvh = proxy_->GetRenderViewHost();
174 switch (command_id) { 191 switch (command_id) {
175 case IDC_CHECK_SPELLING_OF_THIS_FIELD: 192 case IDC_CHECK_SPELLING_OF_THIS_FIELD:
176 rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->routing_id())); 193 rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->routing_id()));
177 break; 194 break;
178 195
179 case IDC_SPELLPANEL_TOGGLE: 196 case IDC_SPELLPANEL_TOGGLE:
180 rvh->Send(new SpellCheckMsg_ToggleSpellPanel( 197 rvh->Send(new SpellCheckMsg_ToggleSpellPanel(
181 rvh->routing_id(), SpellCheckerPlatform::SpellingPanelVisible())); 198 rvh->routing_id(), SpellCheckerPlatform::SpellingPanelVisible()));
182 break; 199 break;
200
201 #if defined(OS_WIN)
202 case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE:
203 // When a user chooses the "Ask Google for spelling suggestions" item, we
204 // show a bubble to confirm it. On the other hand, when a user chooses the
205 // "Stop asking Google for spelling suggestions" item, we directly update
206 // the profile and stop integrating the spelling service immediately.
207 if (!integrate_spelling_service_) {
208 gfx::Rect bounds = rvh->view()->GetViewBounds();
209 bounds.Inset(bounds.width() / 2, 0);
210 ConfirmBubbleModel::Show(rvh->view()->GetNativeView(), bounds.origin(),
211 new SpellingBubbleModel(proxy_->GetProfile()));
212 } else {
213 Profile* profile = proxy_->GetProfile();
214 if (profile)
215 profile->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService,
216 false);
217 }
218 break;
219 #endif
183 } 220 }
184 } 221 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/spellchecker_submenu_observer.h ('k') | chrome/browser/tab_contents/spelling_bubble_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698