Index: chrome/browser/tab_contents/spellchecker_submenu_observer.cc |
=================================================================== |
--- chrome/browser/tab_contents/spellchecker_submenu_observer.cc (revision 108037) |
+++ chrome/browser/tab_contents/spellchecker_submenu_observer.cc (working copy) |
@@ -12,9 +12,11 @@ |
#include "chrome/browser/spellchecker/spellcheck_host.h" |
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h" |
#include "chrome/browser/tab_contents/render_view_context_menu.h" |
+#include "chrome/browser/tab_contents/spelling_bubble_model.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/common/spellcheck_messages.h" |
#include "content/browser/renderer_host/render_view_host.h" |
+#include "content/browser/renderer_host/render_widget_host_view.h" |
#include "grit/generated_resources.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/models/simple_menu_model.h" |
@@ -26,6 +28,7 @@ |
: proxy_(proxy), |
submenu_model_(delegate), |
spellcheck_enabled_(false), |
+ integrate_spelling_service_(false), |
language_group_(group), |
language_selected_(0) { |
DCHECK(proxy_); |
@@ -78,6 +81,20 @@ |
IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); |
} |
+#if defined(OS_WIN) |
+ // If we have not integrated the spelling service, we show an "Ask Google for |
+ // spelling suggestions" item. On the other hand, if we have integrated the |
+ // spelling service, we show "Stop asking Google for spelling suggestions" |
+ // item. |
+ integrate_spelling_service_ = |
+ profile->GetPrefs()->GetBoolean(prefs::kSpellCheckUseSpellingService); |
+ int spelling_message = integrate_spelling_service_ ? |
+ IDS_CONTENT_CONTEXT_SPELLING_STOP_ASKING_GOOGLE : |
+ IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE; |
+ submenu_model_.AddCheckItem(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE, |
+ l10n_util::GetStringUTF16(spelling_message)); |
+#endif |
+ |
proxy_->AddSubMenu( |
IDC_SPELLCHECK_MENU, |
l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU), |
@@ -100,6 +117,7 @@ |
case IDC_CHECK_SPELLING_OF_THIS_FIELD: |
case IDC_SPELLPANEL_TOGGLE: |
case IDC_SPELLCHECK_MENU: |
+ case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: |
return true; |
} |
@@ -143,9 +161,8 @@ |
return pref->GetBoolean(prefs::kEnableSpellCheck); |
case IDC_SPELLPANEL_TOGGLE: |
- return true; |
- |
case IDC_SPELLCHECK_MENU: |
+ case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: |
return true; |
} |
@@ -180,5 +197,25 @@ |
rvh->Send(new SpellCheckMsg_ToggleSpellPanel( |
rvh->routing_id(), SpellCheckerPlatform::SpellingPanelVisible())); |
break; |
+ |
+#if defined(OS_WIN) |
+ case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: |
+ // When a user chooses the "Ask Google for spelling suggestions" item, we |
+ // show a bubble to confirm it. On the other hand, when a user chooses the |
+ // "Stop asking Google for spelling suggestions" item, we directly update |
+ // the profile and stop integrating the spelling service immediately. |
+ if (!integrate_spelling_service_) { |
+ gfx::Rect bounds = rvh->view()->GetViewBounds(); |
+ bounds.Inset(bounds.width() / 2, 0); |
+ ConfirmBubbleModel::Show(rvh->view()->GetNativeView(), bounds.origin(), |
+ new SpellingBubbleModel(proxy_->GetProfile())); |
+ } else { |
+ Profile* profile = proxy_->GetProfile(); |
+ if (profile) |
+ profile->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, |
+ false); |
+ } |
+ break; |
+#endif |
} |
} |