summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-28 08:08:26 +0000
committerhbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-28 08:08:26 +0000
commitefce6bcf5eb7fea63f7635497e3a0540235bbd08 (patch)
treef44cb4c5829ac6b2613947de6c3dc069de4a225d
parent63d199acbd41b5ad09b8327c1aad9dbdcf4b42f5 (diff)
downloadchromium_src-efce6bcf5eb7fea63f7635497e3a0540235bbd08.zip
chromium_src-efce6bcf5eb7fea63f7635497e3a0540235bbd08.tar.gz
chromium_src-efce6bcf5eb7fea63f7635497e3a0540235bbd08.tar.bz2
Refactor the "spell-checker options" submenu.
This change adds a SpellCheckSubMenuObserver class and move code of the "spell-checker options" submenu there. BUG=93746 TEST=none Review URL: http://codereview.chromium.org/8363042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107698 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc126
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.h19
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_observer.cc4
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_observer.h1
-rw-r--r--chrome/browser/tab_contents/spellchecker_submenu_observer.cc184
-rw-r--r--chrome/browser/tab_contents/spellchecker_submenu_observer.h55
-rw-r--r--chrome/chrome_browser.gypi2
7 files changed, 290 insertions, 101 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index aa556a5e..01af4ed 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -39,6 +39,7 @@
#include "chrome/browser/spellchecker/spellcheck_host.h"
#include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
#include "chrome/browser/spellchecker/spellchecker_platform_engine.h"
+#include "chrome/browser/tab_contents/spellchecker_submenu_observer.h"
#include "chrome/browser/tab_contents/spelling_menu_observer.h"
#include "chrome/browser/translate/translate_manager.h"
#include "chrome/browser/translate/translate_prefs.h"
@@ -227,7 +228,6 @@ RenderViewContextMenu::RenderViewContextMenu(
profile_(Profile::FromBrowserContext(tab_contents->browser_context())),
ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)),
external_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(spellcheck_submenu_model_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(speech_input_submenu_model_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(bidi_submenu_model_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(protocol_handler_submenu_model_(this)),
@@ -574,20 +574,13 @@ void RenderViewContextMenu::InitMenu() {
}
if (params_.is_editable) {
- // Add a menu item that shows suggestions from the Spelling service.
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
- PrefService* pref = profile_->GetPrefs();
- bool use_spelling_service =
- pref && pref->GetBoolean(prefs::kSpellCheckUseSpellingService);
- if (use_spelling_service) {
- if (!spelling_menu_observer_.get())
- spelling_menu_observer_.reset(new SpellingMenuObserver(this));
-
- if (spelling_menu_observer_.get())
- observers_.AddObserver(spelling_menu_observer_.get());
- }
+ // Add a menu item that shows suggestions.
+ if (!spelling_menu_observer_.get()) {
+ spelling_menu_observer_.reset(
+ new SpellingMenuObserver(this));
}
+ if (spelling_menu_observer_.get())
+ observers_.AddObserver(spelling_menu_observer_.get());
}
// Ask our observers to add their menu items.
@@ -618,6 +611,12 @@ void RenderViewContextMenu::AddMenuItem(int command_id,
menu_model_.AddItem(command_id, title);
}
+void RenderViewContextMenu::AddSubMenu(int command_id,
+ const string16& label,
+ ui::MenuModel* model) {
+ menu_model_.AddSubMenu(command_id, label, model);
+}
+
void RenderViewContextMenu::UpdateMenuItem(int command_id,
bool enabled,
bool hidden,
@@ -626,7 +625,6 @@ void RenderViewContextMenu::UpdateMenuItem(int command_id,
NOTIMPLEMENTED();
}
-
RenderViewHost* RenderViewContextMenu::GetRenderViewHost() const {
return source_tab_contents_->render_view_host();
}
@@ -908,50 +906,14 @@ void RenderViewContextMenu::AppendEditableItems() {
}
void RenderViewContextMenu::AppendSpellcheckOptionsSubMenu() {
- // Add Spell Check languages to sub menu.
- std::vector<std::string> spellcheck_languages;
- SpellCheckHost::GetSpellCheckLanguages(profile_,
- &spellcheck_languages);
- DCHECK(spellcheck_languages.size() <
- IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST);
- const std::string app_locale = g_browser_process->GetApplicationLocale();
- for (size_t i = 0; i < spellcheck_languages.size(); ++i) {
- string16 display_name(l10n_util::GetDisplayNameForLocale(
- spellcheck_languages[i], app_locale, true));
- spellcheck_submenu_model_.AddRadioItem(
- IDC_SPELLCHECK_LANGUAGES_FIRST + i,
- display_name,
- kSpellcheckRadioGroup);
+ if (!spellchecker_submenu_observer_.get()) {
+ spellchecker_submenu_observer_.reset(new SpellCheckerSubMenuObserver(
+ this, this, kSpellcheckRadioGroup));
}
-
- // Add item in the sub menu to pop up the fonts and languages options menu.
- spellcheck_submenu_model_.AddSeparator();
- spellcheck_submenu_model_.AddItemWithStringId(
- IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS,
- IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS);
-
- // Add 'Check the spelling of this field' item in the sub menu.
- spellcheck_submenu_model_.AddCheckItem(
- IDC_CHECK_SPELLING_OF_THIS_FIELD,
- l10n_util::GetStringUTF16(
- IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD));
-
- // Add option for showing the spelling panel if the platform spellchecker
- // supports it.
- if (SpellCheckerPlatform::SpellCheckerAvailable() &&
- SpellCheckerPlatform::SpellCheckerProvidesPanel()) {
- spellcheck_submenu_model_.AddCheckItem(
- IDC_SPELLPANEL_TOGGLE,
- l10n_util::GetStringUTF16(
- SpellCheckerPlatform::SpellingPanelVisible() ?
- IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL :
- IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL));
+ if (spellchecker_submenu_observer_.get()) {
+ spellchecker_submenu_observer_->InitMenu(params_);
+ observers_.AddObserver(spellchecker_submenu_observer_.get());
}
-
- menu_model_.AddSubMenu(
- IDC_SPELLCHECK_MENU,
- l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU),
- &spellcheck_submenu_model_);
}
void RenderViewContextMenu::AppendSpeechInputOptionsSubMenu() {
@@ -1340,6 +1302,15 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const {
}
bool RenderViewContextMenu::IsCommandIdChecked(int id) const {
+ // If this command is is added by one of our observers, we dispatch it to the
+ // observer.
+ ObserverListBase<RenderViewContextMenuObserver>::Iterator it(observers_);
+ RenderViewContextMenuObserver* observer;
+ while ((observer = it.GetNext()) != NULL) {
+ if (observer->IsCommandIdSupported(id))
+ return observer->IsCommandIdChecked(id);
+ }
+
// See if the video is set to looping.
if (id == IDC_CONTENT_CONTEXT_LOOP) {
return (params_.media_flags &
@@ -1381,27 +1352,13 @@ bool RenderViewContextMenu::IsCommandIdChecked(int id) const {
return false;
#endif // OS_MACOSX
- // Check box for 'Check the Spelling of this field'.
- if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) {
- return (params_.spellcheck_enabled &&
- profile_->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck));
- }
-
// Check box for menu item 'Block offensive words'.
if (id == IDC_CONTENT_CONTEXT_SPEECH_INPUT_FILTER_PROFANITIES) {
return profile_->GetPrefs()->GetBoolean(
prefs::kSpeechInputFilterProfanities);
}
- // Don't bother getting the display language vector if this isn't a spellcheck
- // language.
- if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) ||
- (id >= IDC_SPELLCHECK_LANGUAGES_LAST))
- return false;
-
- std::vector<std::string> languages;
- return SpellCheckHost::GetSpellCheckLanguages(profile_, &languages) ==
- (id - IDC_SPELLCHECK_LANGUAGES_FIRST);
+ return false;
}
void RenderViewContextMenu::ExecuteCommand(int id) {
@@ -1418,21 +1375,6 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
return observer->ExecuteCommand(id);
}
- // Check to see if one of the spell check language ids have been clicked.
- if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
- id < IDC_SPELLCHECK_LANGUAGES_LAST) {
- const size_t language_number = id - IDC_SPELLCHECK_LANGUAGES_FIRST;
- std::vector<std::string> languages;
- SpellCheckHost::GetSpellCheckLanguages(profile_, &languages);
- if (language_number < languages.size()) {
- StringPrefMember dictionary_language;
- dictionary_language.Init(prefs::kSpellCheckDictionary,
- profile_->GetPrefs(), NULL);
- dictionary_language.SetValue(languages[language_number]);
- }
- return;
- }
-
RenderViewHost* rvh = source_tab_contents_->render_view_host();
// Process custom actions range.
@@ -1761,10 +1703,6 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
spellcheck_host->GetMetrics()->RecordReplacedWordStats(1);
break;
}
- case IDC_CHECK_SPELLING_OF_THIS_FIELD: {
- rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->routing_id()));
- break;
- }
case IDC_SPELLCHECK_ADD_TO_DICTIONARY: {
// GetSpellCheckHost() can return null when the suggested word is
// provided by Web SpellCheck API.
@@ -1784,12 +1722,6 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
break;
}
- case IDC_SPELLPANEL_TOGGLE: {
- rvh->Send(new SpellCheckMsg_ToggleSpellPanel(
- rvh->routing_id(), SpellCheckerPlatform::SpellingPanelVisible()));
- break;
- }
-
#if defined(OS_MACOSX)
case IDC_WRITING_DIRECTION_DEFAULT:
// WebKit's current behavior is for this menu item to always be disabled.
diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h
index 6b99562..7b9b32a 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.h
+++ b/chrome/browser/tab_contents/render_view_context_menu.h
@@ -27,6 +27,7 @@ class Profile;
class RenderViewHost;
class TabContents;
class SpellingMenuObserver;
+class SpellCheckerSubMenuObserver;
namespace gfx {
class Point;
@@ -91,6 +92,11 @@ class RenderViewContextMenuProxy {
// Add a menu item to a context menu.
virtual void AddMenuItem(int command_id, const string16& title) = 0;
+ // Add a submenu item to a context menu.
+ virtual void AddSubMenu(int command_id,
+ const string16& label,
+ ui::MenuModel* model) = 0;
+
// Update the status and text of the specified context-menu item.
virtual void UpdateMenuItem(int command_id,
bool enabled,
@@ -130,12 +136,15 @@ class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
// RenderViewContextMenuDelegate implementation.
virtual void AddMenuItem(int command_id, const string16& title) OVERRIDE;
+ virtual void AddSubMenu(int command_id,
+ const string16& label,
+ ui::MenuModel* model) OVERRIDE;
virtual void UpdateMenuItem(int command_id,
bool enabled,
bool hidden,
const string16& title) OVERRIDE;
- virtual RenderViewHost* GetRenderViewHost() const;
- virtual Profile* GetProfile() const;
+ virtual RenderViewHost* GetRenderViewHost() const OVERRIDE;
+ virtual Profile* GetProfile() const OVERRIDE;
protected:
void InitMenu();
@@ -245,16 +254,18 @@ class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
// a text selection.
GURL selection_navigation_url_;
- ui::SimpleMenuModel spellcheck_submenu_model_;
ui::SimpleMenuModel speech_input_submenu_model_;
ui::SimpleMenuModel bidi_submenu_model_;
ui::SimpleMenuModel protocol_handler_submenu_model_;
ScopedVector<ui::SimpleMenuModel> extension_menu_models_;
scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_;
- // An observer that handles a spelling-menu items.
+ // An observer that handles spelling-menu items.
scoped_ptr<SpellingMenuObserver> spelling_menu_observer_;
+ // An observer that handles a 'spell-checker options' submenu.
+ scoped_ptr<SpellCheckerSubMenuObserver> spellchecker_submenu_observer_;
+
// Our observers.
mutable ObserverList<RenderViewContextMenuObserver> observers_;
diff --git a/chrome/browser/tab_contents/render_view_context_menu_observer.cc b/chrome/browser/tab_contents/render_view_context_menu_observer.cc
index b6311c6..705878a 100644
--- a/chrome/browser/tab_contents/render_view_context_menu_observer.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu_observer.cc
@@ -11,6 +11,10 @@ bool RenderViewContextMenuObserver::IsCommandIdSupported(int command_id) {
return false;
}
+bool RenderViewContextMenuObserver::IsCommandIdChecked(int command_id) {
+ return false;
+}
+
bool RenderViewContextMenuObserver::IsCommandIdEnabled(int command_id) {
return false;
}
diff --git a/chrome/browser/tab_contents/render_view_context_menu_observer.h b/chrome/browser/tab_contents/render_view_context_menu_observer.h
index 34823e8..f70c9cc 100644
--- a/chrome/browser/tab_contents/render_view_context_menu_observer.h
+++ b/chrome/browser/tab_contents/render_view_context_menu_observer.h
@@ -93,6 +93,7 @@ class RenderViewContextMenuObserver {
// Called when the RenderViewContextMenu class sets the initial status of the
// specified context-menu item. If we need to enable or disable a context-menu
// item while showing, use RenderViewContextMenuDelegate::UpdateMenuItem().
+ virtual bool IsCommandIdChecked(int command_id);
virtual bool IsCommandIdEnabled(int command_id);
// Called when a user selects the specified context-menu item.
diff --git a/chrome/browser/tab_contents/spellchecker_submenu_observer.cc b/chrome/browser/tab_contents/spellchecker_submenu_observer.cc
new file mode 100644
index 0000000..d568309
--- /dev/null
+++ b/chrome/browser/tab_contents/spellchecker_submenu_observer.cc
@@ -0,0 +1,184 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/tab_contents/spellchecker_submenu_observer.h"
+
+#include "base/logging.h"
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/prefs/pref_member.h"
+#include "chrome/browser/prefs/pref_service.h"
+#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/common/pref_names.h"
+#include "chrome/common/spellcheck_messages.h"
+#include "content/browser/renderer_host/render_view_host.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/models/simple_menu_model.h"
+
+SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver(
+ RenderViewContextMenuProxy* proxy,
+ ui::SimpleMenuModel::Delegate* delegate,
+ int group)
+ : proxy_(proxy),
+ submenu_model_(delegate),
+ spellcheck_enabled_(false),
+ language_group_(group),
+ language_selected_(0) {
+ DCHECK(proxy_);
+}
+
+SpellCheckerSubMenuObserver::~SpellCheckerSubMenuObserver() {
+}
+
+void SpellCheckerSubMenuObserver::InitMenu(const ContextMenuParams& params) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ spellcheck_enabled_ = params.spellcheck_enabled;
+
+ // Add available spell-checker languages to the sub menu.
+ Profile* profile = proxy_->GetProfile();
+ language_selected_ =
+ SpellCheckHost::GetSpellCheckLanguages(profile, &languages_);
+ DCHECK(languages_.size() <
+ IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST);
+ const std::string app_locale = g_browser_process->GetApplicationLocale();
+ for (size_t i = 0; i < languages_.size(); ++i) {
+ string16 display_name(
+ l10n_util::GetDisplayNameForLocale(languages_[i], app_locale, true));
+ submenu_model_.AddRadioItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i,
+ display_name,
+ language_group_);
+ }
+
+ // Add an item that opens the 'fonts and languages options' page.
+ submenu_model_.AddSeparator();
+ submenu_model_.AddItemWithStringId(
+ IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS,
+ IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS);
+
+ // Add a 'Check the spelling of this field' item in the sub menu.
+ submenu_model_.AddCheckItem(
+ IDC_CHECK_SPELLING_OF_THIS_FIELD,
+ l10n_util::GetStringUTF16(
+ IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD));
+
+ // Add an item that shows the spelling panel if the platform spellchecker
+ // supports it.
+ if (SpellCheckerPlatform::SpellCheckerAvailable() &&
+ SpellCheckerPlatform::SpellCheckerProvidesPanel()) {
+ submenu_model_.AddCheckItem(
+ IDC_SPELLPANEL_TOGGLE,
+ l10n_util::GetStringUTF16(
+ SpellCheckerPlatform::SpellingPanelVisible() ?
+ IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL :
+ IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL));
+ }
+
+ proxy_->AddSubMenu(
+ IDC_SPELLCHECK_MENU,
+ l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU),
+ &submenu_model_);
+}
+
+bool SpellCheckerSubMenuObserver::IsCommandIdSupported(int command_id) {
+ // Allow Spell Check language items on sub menu for text area context menu.
+ if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
+ command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
+ return true;
+ }
+
+ switch (command_id) {
+ case IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS:
+ // Return false so RenderViewContextMenu can handle this item because it
+ // is hard for this class to handle it.
+ return false;
+
+ case IDC_CHECK_SPELLING_OF_THIS_FIELD:
+ case IDC_SPELLPANEL_TOGGLE:
+ case IDC_SPELLCHECK_MENU:
+ return true;
+ }
+
+ return false;
+}
+
+bool SpellCheckerSubMenuObserver::IsCommandIdChecked(int command_id) {
+ DCHECK(IsCommandIdSupported(command_id));
+
+ if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
+ command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
+ return language_selected_ == command_id - IDC_SPELLCHECK_LANGUAGES_FIRST;
+ }
+
+ // Check box for 'Check the Spelling of this field'.
+ if (command_id == IDC_CHECK_SPELLING_OF_THIS_FIELD) {
+ Profile* profile = proxy_->GetProfile();
+ if (!profile || !profile->GetPrefs()->GetBoolean(prefs::kEnableSpellCheck))
+ return false;
+ return spellcheck_enabled_;
+ }
+
+ return false;
+}
+
+bool SpellCheckerSubMenuObserver::IsCommandIdEnabled(int command_id) {
+ DCHECK(IsCommandIdSupported(command_id));
+
+ Profile* profile = proxy_->GetProfile();
+ if (!profile)
+ return false;
+
+ const PrefService* pref = profile->GetPrefs();
+ if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
+ command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
+ return pref->GetBoolean(prefs::kEnableSpellCheck);
+ }
+
+ switch (command_id) {
+ case IDC_CHECK_SPELLING_OF_THIS_FIELD:
+ return pref->GetBoolean(prefs::kEnableSpellCheck);
+
+ case IDC_SPELLPANEL_TOGGLE:
+ return true;
+
+ case IDC_SPELLCHECK_MENU:
+ return true;
+ }
+
+ return false;
+}
+
+void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) {
+ DCHECK(IsCommandIdSupported(command_id));
+
+ // Check to see if one of the spell check language ids have been clicked.
+ if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
+ command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
+ Profile* profile = proxy_->GetProfile();
+ const size_t language = command_id - IDC_SPELLCHECK_LANGUAGES_FIRST;
+ if (profile && language < languages_.size()) {
+ StringPrefMember dictionary_language;
+ dictionary_language.Init(prefs::kSpellCheckDictionary,
+ profile->GetPrefs(),
+ NULL);
+ dictionary_language.SetValue(languages_[language]);
+ }
+ return;
+ }
+
+ RenderViewHost* rvh = proxy_->GetRenderViewHost();
+ switch (command_id) {
+ case IDC_CHECK_SPELLING_OF_THIS_FIELD:
+ rvh->Send(new SpellCheckMsg_ToggleSpellCheck(rvh->routing_id()));
+ break;
+
+ case IDC_SPELLPANEL_TOGGLE:
+ rvh->Send(new SpellCheckMsg_ToggleSpellPanel(
+ rvh->routing_id(), SpellCheckerPlatform::SpellingPanelVisible()));
+ break;
+ }
+}
diff --git a/chrome/browser/tab_contents/spellchecker_submenu_observer.h b/chrome/browser/tab_contents/spellchecker_submenu_observer.h
new file mode 100644
index 0000000..c87cce6
--- /dev/null
+++ b/chrome/browser/tab_contents/spellchecker_submenu_observer.h
@@ -0,0 +1,55 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_TAB_CONTENTS_SPELLCHECKER_SUBMENU_OBSERVER_H_
+#define CHROME_BROWSER_TAB_CONTENTS_SPELLCHECKER_SUBMENU_OBSERVER_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/tab_contents/render_view_context_menu_observer.h"
+#include "ui/base/models/simple_menu_model.h"
+
+class RenderViewContextMenuProxy;
+
+// A class that implements the 'spell-checker options' submenu. This class
+// creates the submenu, add it to the parent menu, and handles events.
+class SpellCheckerSubMenuObserver : public RenderViewContextMenuObserver {
+ public:
+ SpellCheckerSubMenuObserver(RenderViewContextMenuProxy* proxy,
+ ui::SimpleMenuModel::Delegate* delegate,
+ int group);
+ virtual ~SpellCheckerSubMenuObserver();
+
+ // RenderViewContextMenuObserver implementation.
+ virtual void InitMenu(const ContextMenuParams& params) OVERRIDE;
+ virtual bool IsCommandIdSupported(int command_id) OVERRIDE;
+ virtual bool IsCommandIdChecked(int command_id) OVERRIDE;
+ virtual bool IsCommandIdEnabled(int command_id) OVERRIDE;
+ virtual void ExecuteCommand(int command_id) OVERRIDE;
+
+ private:
+ // The interface for adding a submenu to the parent.
+ RenderViewContextMenuProxy* proxy_;
+
+ // The submenu of the 'spell-checker options'. This class adds items to this
+ // submenu and add it to the parent menu.
+ ui::SimpleMenuModel submenu_model_;
+
+ // Whether spellchecking is enabled in the focused element or not.
+ bool spellcheck_enabled_;
+
+ // The radio items representing languages available for spellchecking.
+ int language_group_;
+ int language_selected_;
+ std::vector<std::string> languages_;
+
+ DISALLOW_COPY_AND_ASSIGN(SpellCheckerSubMenuObserver);
+};
+
+#endif // CHROME_BROWSER_TAB_CONTENTS_SPELLCHECKER_SUBMENU_OBSERVER_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 7f8423b..eb71fb4 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2320,6 +2320,8 @@
'browser/tab_contents/tab_util.h',
'browser/tab_contents/thumbnail_generator.cc',
'browser/tab_contents/thumbnail_generator.h',
+ 'browser/tab_contents/spellchecker_submenu_observer.cc',
+ 'browser/tab_contents/spellchecker_submenu_observer.h',
'browser/tab_contents/spelling_menu_observer.cc',
'browser/tab_contents/spelling_menu_observer.h',
'browser/tab_contents/web_drag_bookmark_handler_gtk.cc',