diff options
author | sidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-15 20:18:04 +0000 |
---|---|---|
committer | sidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-15 20:18:04 +0000 |
commit | bbbd545cc226d409d131afb806e1ae5df3e5aa73 (patch) | |
tree | 6c87d2afde518b04a7b19813c2ec360ba6afbf1f /chrome | |
parent | bdb1d32442597e46583a79c0af560e6cc9e57214 (diff) | |
download | chromium_src-bbbd545cc226d409d131afb806e1ae5df3e5aa73.zip chromium_src-bbbd545cc226d409d131afb806e1ae5df3e5aa73.tar.gz chromium_src-bbbd545cc226d409d131afb806e1ae5df3e5aa73.tar.bz2 |
Add "Enable spell check for this field" menu option in sub context menu for context menu over text box, and deploy its functionality accordingly across the code. This patch also allows manual switch-on of spell check in single line text box fields.
Review URL: http://codereview.chromium.org/13731
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7000 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/chrome_dll_resource.h | 2 | ||||
-rw-r--r-- | chrome/browser/render_view_context_menu.cc | 7 | ||||
-rw-r--r-- | chrome/browser/render_view_context_menu_controller.cc | 8 | ||||
-rw-r--r-- | chrome/browser/render_view_host.cc | 4 | ||||
-rw-r--r-- | chrome/browser/render_view_host.h | 1 | ||||
-rw-r--r-- | chrome/browser/resource_message_filter.cc | 2 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 5 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 1 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 1 |
10 files changed, 39 insertions, 2 deletions
diff --git a/chrome/app/chrome_dll_resource.h b/chrome/app/chrome_dll_resource.h index a0613af..b5fa1a9 100644 --- a/chrome/app/chrome_dll_resource.h +++ b/chrome/app/chrome_dll_resource.h @@ -185,7 +185,7 @@ // [_FIRST, _LAST). #define IDC_SPELLCHECK_LANGUAGES_FIRST 41006 #define IDC_SPELLCHECK_LANGUAGES_LAST 41106 - +#define IDC_CHECK_SPELLING_OF_THIS_FIELD 41107 // Next default values for new objects // #ifdef APSTUDIO_INVOKED diff --git a/chrome/browser/render_view_context_menu.cc b/chrome/browser/render_view_context_menu.cc index 9634197..83082b4 100644 --- a/chrome/browser/render_view_context_menu.cc +++ b/chrome/browser/render_view_context_menu.cc @@ -168,6 +168,13 @@ void RenderViewContextMenu::AppendEditableItems() { spellchecker_sub_menu_->AppendSeparator(); spellchecker_sub_menu_->AppendDelegateMenuItem( IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); + + // Add 'Check the spelling of this field' item in the sub menu. + spellchecker_sub_menu_->AppendMenuItem( + IDC_CHECK_SPELLING_OF_THIS_FIELD, + l10n_util::GetString(IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD), + CHECKBOX); + AppendSeparator(); AppendDelegateMenuItem(IDS_CONTENT_CONTEXT_SELECTALL); } diff --git a/chrome/browser/render_view_context_menu_controller.cc b/chrome/browser/render_view_context_menu_controller.cc index 186fe0b..76a6279 100644 --- a/chrome/browser/render_view_context_menu_controller.cc +++ b/chrome/browser/render_view_context_menu_controller.cc @@ -190,6 +190,7 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const { case IDC_SPELLCHECK_SUGGESTION_3: case IDC_SPELLCHECK_SUGGESTION_4: case IDC_SPELLCHECK_MENU: + case IDC_CHECK_SPELLING_OF_THIS_FIELD: case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS: case IDS_CONTENT_CONTEXT_VIEWFRAMEINFO: return true; @@ -203,6 +204,10 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const { } bool RenderViewContextMenuController::IsItemChecked(int id) const { + // Check box for 'Check the Spelling of this field'. + if (id == IDC_CHECK_SPELLING_OF_THIS_FIELD) + return params_.spellcheck_enabled; + // Don't bother getting the display language vector if this isn't a spellcheck // language. if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) || @@ -446,6 +451,9 @@ void RenderViewContextMenuController::ExecuteCommand(int id) { params_.dictionary_suggestions[id - IDC_SPELLCHECK_SUGGESTION_0]); break; + case IDC_CHECK_SPELLING_OF_THIS_FIELD: + source_web_contents_->render_view_host()->ToggleSpellCheck(); + break; case IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY: source_web_contents_->render_view_host()->AddToDictionary( params_.misspelled_word); diff --git a/chrome/browser/render_view_host.cc b/chrome/browser/render_view_host.cc index 4623978..f3b8e2b 100644 --- a/chrome/browser/render_view_host.cc +++ b/chrome/browser/render_view_host.cc @@ -450,6 +450,10 @@ void RenderViewHost::Replace(const std::wstring& text_to_replace) { Send(new ViewMsg_Replace(routing_id_, text_to_replace)); } +void RenderViewHost::ToggleSpellCheck() { + Send(new ViewMsg_ToggleSpellCheck(routing_id_)); +} + void RenderViewHost::AddToDictionary(const std::wstring& word) { process_->AddWord(word); } diff --git a/chrome/browser/render_view_host.h b/chrome/browser/render_view_host.h index 5ccd88f..17d8f97 100644 --- a/chrome/browser/render_view_host.h +++ b/chrome/browser/render_view_host.h @@ -251,6 +251,7 @@ class RenderViewHost : public RenderWidgetHost { void Copy(); void Paste(); void Replace(const std::wstring& text); + void ToggleSpellCheck(); void AddToDictionary(const std::wstring& word); void Delete(); void SelectAll(); diff --git a/chrome/browser/resource_message_filter.cc b/chrome/browser/resource_message_filter.cc index a674628..e4e8409 100644 --- a/chrome/browser/resource_message_filter.cc +++ b/chrome/browser/resource_message_filter.cc @@ -197,7 +197,7 @@ void ResourceMessageFilter::OnReceiveContextMenuMsg(const IPC::Message& msg) { // Fill in the dictionary suggestions if required. if (!params.misspelled_word.empty() && - spellchecker_ != NULL) { + spellchecker_ != NULL && params.spellcheck_enabled) { int misspell_location, misspell_length; bool is_misspelled = !spellchecker_->SpellCheckWord( params.misspelled_word.c_str(), diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index b359e12..fa19f82 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -158,6 +158,9 @@ struct ViewHostMsg_ContextMenu_Params { // and the misspelled_word is not empty. std::vector<std::wstring> dictionary_suggestions; + // If editable, flag for whether spell check is enabled or not. + bool spellcheck_enabled; + // These flags indicate to the browser whether the renderer believes it is // able to perform the corresponding action. int edit_flags; @@ -945,6 +948,7 @@ struct ParamTraits<ViewHostMsg_ContextMenu_Params> { WriteParam(m, p.selection_text); WriteParam(m, p.misspelled_word); WriteParam(m, p.dictionary_suggestions); + WriteParam(m, p.spellcheck_enabled); WriteParam(m, p.edit_flags); WriteParam(m, p.security_info); } @@ -960,6 +964,7 @@ struct ParamTraits<ViewHostMsg_ContextMenu_Params> { ReadParam(m, iter, &p->selection_text) && ReadParam(m, iter, &p->misspelled_word) && ReadParam(m, iter, &p->dictionary_suggestions) && + ReadParam(m, iter, &p->spellcheck_enabled) && ReadParam(m, iter, &p->edit_flags) && ReadParam(m, iter, &p->security_info); } diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index a852732..a671e3e 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -144,6 +144,7 @@ IPC_BEGIN_MESSAGES(View, 1) IPC_MESSAGE_ROUTED0(ViewMsg_Copy) IPC_MESSAGE_ROUTED0(ViewMsg_Paste) IPC_MESSAGE_ROUTED1(ViewMsg_Replace, std::wstring) + IPC_MESSAGE_ROUTED0(ViewMsg_ToggleSpellCheck) IPC_MESSAGE_ROUTED0(ViewMsg_Delete) IPC_MESSAGE_ROUTED0(ViewMsg_SelectAll) diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 4b00d9b..87dc54e 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -329,6 +329,7 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) + IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) @@ -976,6 +977,13 @@ void RenderView::OnReplace(const std::wstring& text) { webview()->GetFocusedFrame()->Replace(text); } +void RenderView::OnToggleSpellCheck() { + if (!webview()) + return; + + webview()->GetFocusedFrame()->ToggleSpellCheck(); +} + void RenderView::OnDelete() { if (!webview()) return; @@ -1951,6 +1959,8 @@ void RenderView::ShowContextMenu(WebView* webview, params.frame_url = frame_url; params.selection_text = selection_text; params.misspelled_word = misspelled_word; + params.spellcheck_enabled = + webview->GetFocusedFrame()->SpellCheckEnabled(); params.edit_flags = edit_flags; params.security_info = security_info; Send(new ViewHostMsg_ContextMenu(routing_id_, params)); diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 0d6cda8..e82ebac 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -396,6 +396,7 @@ class RenderView : public RenderWidget, public WebViewDelegate, void OnCopy(); void OnPaste(); void OnReplace(const std::wstring& text); + void OnToggleSpellCheck(); void OnDelete(); void OnSelectAll(); void OnCopyImageAt(int x, int y); |