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

Unified Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 7713033: Integrate the Spelling service to Chrome. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/tab_contents/render_view_context_menu.cc
===================================================================
--- chrome/browser/tab_contents/render_view_context_menu.cc (revision 99616)
+++ chrome/browser/tab_contents/render_view_context_menu.cc (working copy)
@@ -37,6 +37,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/spelling_menu_observer.h"
#include "chrome/browser/translate/translate_manager.h"
#include "chrome/browser/translate/translate_prefs.h"
#include "chrome/browser/translate/translate_tab_helper.h"
@@ -552,6 +553,27 @@
#endif
}
+ 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());
+ }
+ }
+ }
+
+ // Ask our observers to add their menu items.
+ FOR_EACH_OBSERVER(RenderViewContextMenuObserver, observers_,
+ InitMenu(params_));
+
if (params_.is_editable)
AppendEditableItems();
else if (has_selection)
@@ -571,6 +593,27 @@
NOTREACHED();
}
+void RenderViewContextMenu::AddMenuItem(int command_id,
+ const string16& title) {
+ menu_model_.AddItem(command_id, title);
+}
+
+void RenderViewContextMenu::UpdateMenuItem(int command_id,
+ bool enabled,
+ const string16& label) {
+ // This function needs platform-specific implementation.
+ NOTIMPLEMENTED();
+}
+
+
+RenderViewHost* RenderViewContextMenu::GetRenderViewHost() const {
+ return source_tab_contents_->render_view_host();
+}
+
+Profile* RenderViewContextMenu::GetProfile() const {
+ return profile_;
+}
+
bool RenderViewContextMenu::AppendCustomItems() {
size_t total_items = 0;
AddCustomItemsToMenu(params_.custom_items, 0, &total_items, this,
@@ -794,7 +837,7 @@
}
// If word is misspelled, give option for "Add to dictionary"
- if (!params_.misspelled_word.empty()) {
+ if (!spelling_menu_observer_.get() && !params_.misspelled_word.empty()) {
if (params_.dictionary_suggestions.empty()) {
menu_model_.AddItem(IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS,
l10n_util::GetStringUTF16(
@@ -961,6 +1004,15 @@
// Menu delegate functions -----------------------------------------------------
bool RenderViewContextMenu::IsCommandIdEnabled(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->IsCommandIdEnabled(id);
+ }
+
if (id == IDC_PRINT &&
(source_tab_contents_->content_restrictions() &
CONTENT_RESTRICTION_PRINT)) {
@@ -1329,6 +1381,15 @@
}
void RenderViewContextMenu::ExecuteCommand(int id) {
+ // 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->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) {
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.h ('k') | chrome/browser/tab_contents/render_view_context_menu_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698