summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/context_menu_client_impl.cc3
-rw-r--r--webkit/glue/editor_client_impl.cc45
-rw-r--r--webkit/glue/editor_client_impl.h18
-rw-r--r--webkit/glue/webframe.h6
-rw-r--r--webkit/glue/webframe_impl.cc8
-rw-r--r--webkit/glue/webframe_impl.h2
-rw-r--r--webkit/glue/webview.h9
-rw-r--r--webkit/glue/webview_impl.cc24
-rw-r--r--webkit/glue/webview_impl.h1
9 files changed, 73 insertions, 43 deletions
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();