diff options
-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 | ||||
-rw-r--r-- | webkit/glue/context_menu_client_impl.cc | 3 | ||||
-rw-r--r-- | webkit/glue/editor_client_impl.cc | 45 | ||||
-rw-r--r-- | webkit/glue/editor_client_impl.h | 18 | ||||
-rw-r--r-- | webkit/glue/webframe.h | 6 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.cc | 8 | ||||
-rw-r--r-- | webkit/glue/webframe_impl.h | 2 | ||||
-rw-r--r-- | webkit/glue/webview.h | 9 | ||||
-rw-r--r-- | webkit/glue/webview_impl.cc | 24 | ||||
-rw-r--r-- | webkit/glue/webview_impl.h | 1 |
19 files changed, 112 insertions, 45 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); diff --git a/webkit/glue/context_menu_client_impl.cc b/webkit/glue/context_menu_client_impl.cc index 4e20cbe..e2fbfcf 100644 --- a/webkit/glue/context_menu_client_impl.cc +++ b/webkit/glue/context_menu_client_impl.cc @@ -184,7 +184,8 @@ WebCore::PlatformMenuDescription if (type == ContextNode::NONE) { if (r.isContentEditable()) { type = ContextNode::EDITABLE; - if (webview_->FocusedFrameNeedsSpellchecking()) { + if (webview_->GetFocusedWebCoreFrame()->editor()-> + isContinuousSpellCheckingEnabled()) { misspelled_word_string = GetMisspelledWord(default_menu, selected_frame); } diff --git a/webkit/glue/editor_client_impl.cc b/webkit/glue/editor_client_impl.cc index d2eb18c..5c16e87 100644 --- a/webkit/glue/editor_client_impl.cc +++ b/webkit/glue/editor_client_impl.cc @@ -73,7 +73,8 @@ EditorClientImpl::EditorClientImpl(WebView* web_view) backspace_pressed_(false), // Don't complain about using "this" in initializer list. MSVC_PUSH_DISABLE_WARNING(4355) - autofill_factory_(this) { + autofill_factory_(this), + spell_check_this_field_status_(SPELLCHECK_AUTOMATIC) { MSVC_POP_WARNING() } @@ -113,16 +114,44 @@ bool EditorClientImpl::isSelectTrailingWhitespaceEnabled() { return true; } +bool EditorClientImpl::ShouldSpellcheckByDefault() { + const WebCore::Frame* frame = web_view_->GetFocusedWebCoreFrame(); + if (!frame) + return false; + const WebCore::Editor* editor = frame->editor(); + if (!editor) + return false; + const WebCore::Document* document = frame->document(); + if (!document) + return false; + const WebCore::Node* node = document->focusedNode(); + if (!node) + return false; + const WebCore::RenderObject* renderer = node->renderer(); + if (!renderer) + return false; + // We should also retrieve the contenteditable attribute of this element to + // determine if this element needs spell-checking. + const WebCore::EUserModify user_modify = renderer->style()->userModify(); + return (renderer->isTextArea() && editor->canEdit()) || + user_modify == WebCore::READ_WRITE || + user_modify == WebCore::READ_WRITE_PLAINTEXT_ONLY; +} + bool EditorClientImpl::isContinuousSpellCheckingEnabled() { - // Spell check everything if possible. - // FIXME(brettw) This should be modified to do reasonable defaults depending - // on input type, and probably also allow the user to turn spellchecking on - // for individual fields. - return true; + if (spell_check_this_field_status_ == SPELLCHECK_FORCED_OFF) + return false; + else if (spell_check_this_field_status_ == SPELLCHECK_FORCED_ON) + return true; + else + return ShouldSpellcheckByDefault(); } void EditorClientImpl::toggleContinuousSpellChecking() { - NOTIMPLEMENTED(); + if (isContinuousSpellCheckingEnabled()) + spell_check_this_field_status_ = SPELLCHECK_FORCED_OFF; + else + spell_check_this_field_status_ = SPELLCHECK_FORCED_ON; } bool EditorClientImpl::isGrammarCheckingEnabled() { @@ -718,7 +747,7 @@ void EditorClientImpl::checkSpellingOfString(const UChar* str, int length, int spell_location = -1; int spell_length = 0; WebViewDelegate* d = web_view_->delegate(); - if (web_view_->FocusedFrameNeedsSpellchecking() && d) { + if (isContinuousSpellCheckingEnabled() && d) { std::wstring word = webkit_glue::StringToStdWString(WebCore::String(str, length)); d->SpellCheck(word, spell_location, spell_length); diff --git a/webkit/glue/editor_client_impl.h b/webkit/glue/editor_client_impl.h index 52f725a..3870923 100644 --- a/webkit/glue/editor_client_impl.h +++ b/webkit/glue/editor_client_impl.h @@ -135,9 +135,27 @@ class EditorClientImpl : public WebCore::EditorClient { EditCommandStack redo_stack_; private: + // Returns whether or not the focused control needs spell-checking. + // Currently, this function just retrieves the focused node and determines + // whether or not it is a <textarea> element or an element whose + // contenteditable attribute is true. + // TODO(hbono): Bug 740540: This code just implements the default behavior + // proposed in this issue. We should also retrieve "spellcheck" attributes + // for text fields and create a flag to over-write the default behavior. + bool ShouldSpellcheckByDefault(); + // Whether the last entered key was a backspace. bool backspace_pressed_; + // This flag is set to false if spell check for this editor is manually + // turned off. The default setting is SPELLCHECK_AUTOMATIC. + enum { + SPELLCHECK_AUTOMATIC, + SPELLCHECK_FORCED_ON, + SPELLCHECK_FORCED_OFF + }; + int spell_check_this_field_status_; + // The method factory used to post autofill related tasks. ScopedRunnableMethodFactory<EditorClientImpl> autofill_factory_; }; diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h index 2edc1eb..6235586 100644 --- a/webkit/glue/webframe.h +++ b/webkit/glue/webframe.h @@ -262,6 +262,12 @@ class WebFrame : public base::RefCounted<WebFrame> { // Replace the selection text by a given text. virtual void Replace(const std::wstring& text) = 0; + // Toggle spell check on and off. + virtual void ToggleSpellCheck() = 0; + + // Return whether spell check is enabled or not in this frame. + virtual bool SpellCheckEnabled() = 0; + // // - (void)delete:(id)sender; // Delete as in similar to Cut, not as in teardown diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index d091422..40a2842 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -1309,6 +1309,14 @@ void WebFrameImpl::Replace(const std::wstring& wtext) { frame()->document(), fragment.get(), false, true, true)); } +void WebFrameImpl::ToggleSpellCheck() { + frame()->editor()->toggleContinuousSpellChecking(); +} + +bool WebFrameImpl::SpellCheckEnabled() { + return frame()->editor()->isContinuousSpellCheckingEnabled(); +} + void WebFrameImpl::Delete() { frame()->editor()->command("Delete").execute(); diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index cdca806..7530170 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -134,6 +134,8 @@ class WebFrameImpl : public WebFrame { virtual void Cut(); virtual void Paste(); virtual void Replace(const std::wstring& text); + virtual void ToggleSpellCheck(); + virtual bool SpellCheckEnabled(); virtual void Delete(); virtual void Undo(); virtual void Redo(); diff --git a/webkit/glue/webview.h b/webkit/glue/webview.h index 1c67c4f4..39d608c 100644 --- a/webkit/glue/webview.h +++ b/webkit/glue/webview.h @@ -121,15 +121,6 @@ class WebView : public WebWidget { // bug is fixed. virtual void StoreFocusForFrame(WebFrame* frame) = 0; - // Returns whether or not the focused control needs spell-checking. - // Currently, this function just retrieves the focused node and determines - // whether or not it is a <textarea> element or an element whose - // contenteditable attribute is true. - // TODO(hbono): Bug 740540: This code just implements the default behavior - // proposed in this issue. We should also retrieve "spellcheck" attributes - // for text fields and create a flag to over-write the default behavior. - virtual bool FocusedFrameNeedsSpellchecking() = 0; - // Requests the webview to download an image. When done, the delegate is // notified by way of DidDownloadImage. Returns true if the request was // successfully started, false otherwise. id is used to uniquely identify the diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index dbb2bd4..c04b649 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -1173,30 +1173,6 @@ void WebViewImpl::SetInitialFocus(bool reverse) { } } -bool WebViewImpl::FocusedFrameNeedsSpellchecking() { - const WebCore::Frame* frame = GetFocusedWebCoreFrame(); - if (!frame) - return false; - const WebCore::Editor* editor = frame->editor(); - if (!editor) - return false; - const WebCore::Document* document = frame->document(); - if (!document) - return false; - const WebCore::Node* node = document->focusedNode(); - if (!node) - return false; - const WebCore::RenderObject* renderer = node->renderer(); - if (!renderer) - return false; - // We should also retrieve the contenteditable attribute of this element to - // determine if this element needs spell-checking. - const WebCore::EUserModify user_modify = renderer->style()->userModify(); - return (renderer->isTextArea() && editor->canEdit()) || - user_modify == WebCore::READ_WRITE || - user_modify == WebCore::READ_WRITE_PLAINTEXT_ONLY; -} - // Releases references used to restore focus. void WebViewImpl::ReleaseFocusReferences() { if (last_focused_frame_.get()) { diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index 502ee3a..e0f693e 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -78,7 +78,6 @@ class WebViewImpl : public WebView { virtual void SetBackForwardListSize(int size); virtual void RestoreFocus(); virtual void SetInitialFocus(bool reverse); - virtual bool FocusedFrameNeedsSpellchecking(); virtual bool DownloadImage(int id, const GURL& image_url, int image_size); virtual void SetPreferences(const WebPreferences& preferences); virtual const WebPreferences& GetPreferences(); |