Title: [201942] trunk/Source
Revision
201942
Author
[email protected]
Date
2016-06-10 15:00:23 -0700 (Fri, 10 Jun 2016)

Log Message

Add SPI to disable spellchecking on auto-fillable text fields
https://bugs.webkit.org/show_bug.cgi?id=158611

Reviewed by Anders Carlsson.

Source/WebCore:

Added a boolean flag m_isSpellCheckingEnabled to HTMLInputElement. This flag defaults to true, and can be set
to false by WebKit2 C API.

* editing/Editor.cpp:
(WebCore::Editor::isSpellCheckingEnabledFor): Fixed a bug that we were calling isSpellCheckingEnabled on
the div inside an input element's shadow tree instead of the input element itself.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::HTMLInputElement): Initialize m_spellcheckEnabled to true (it's a bit field).
(WebCore::HTMLInputElement::isSpellCheckingEnabled): Added. Return false if m_spellcheckEnabled is false.
* html/HTMLInputElement.h:
(WebCore::HTMLInputElement::setSpellcheckEnabled): Added.

Source/WebKit2:

Added WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled to disable spellchecking on a text field.

This is used by WebKit2 client which desires to disable spellchecking and notably autocorrection on
login forms, etc... where such feature would interfere with user's actions.

* WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp:
(WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled): Added.
* WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h:
* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
(WebKit::InjectedBundleNodeHandle::setHTMLInputElementSpellcheckEnabled): Added.
* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (201941 => 201942)


--- trunk/Source/WebCore/ChangeLog	2016-06-10 21:26:00 UTC (rev 201941)
+++ trunk/Source/WebCore/ChangeLog	2016-06-10 22:00:23 UTC (rev 201942)
@@ -1,3 +1,22 @@
+2016-06-09  Ryosuke Niwa  <[email protected]>
+
+        Add SPI to disable spellchecking on auto-fillable text fields
+        https://bugs.webkit.org/show_bug.cgi?id=158611
+
+        Reviewed by Anders Carlsson.
+
+        Added a boolean flag m_isSpellCheckingEnabled to HTMLInputElement. This flag defaults to true, and can be set
+        to false by WebKit2 C API.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::isSpellCheckingEnabledFor): Fixed a bug that we were calling isSpellCheckingEnabled on
+        the div inside an input element's shadow tree instead of the input element itself.
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::HTMLInputElement): Initialize m_spellcheckEnabled to true (it's a bit field).
+        (WebCore::HTMLInputElement::isSpellCheckingEnabled): Added. Return false if m_spellcheckEnabled is false.
+        * html/HTMLInputElement.h:
+        (WebCore::HTMLInputElement::setSpellcheckEnabled): Added.
+
 2016-06-10  Alex Christensen  <[email protected]>
 
         Introduce WTF::UniqueRef

Modified: trunk/Source/WebCore/editing/Editor.cpp (201941 => 201942)


--- trunk/Source/WebCore/editing/Editor.cpp	2016-06-10 21:26:00 UTC (rev 201941)
+++ trunk/Source/WebCore/editing/Editor.cpp	2016-06-10 22:00:23 UTC (rev 201942)
@@ -2372,10 +2372,14 @@
 {
     if (!node)
         return false;
-    const Element* focusedElement = is<Element>(*node) ? downcast<Element>(node) : node->parentElement();
-    if (!focusedElement)
+    Element* element = is<Element>(*node) ? downcast<Element>(node) : node->parentElement();
+    if (!element)
         return false;
-    return focusedElement->isSpellCheckingEnabled();
+    if (element->isInUserAgentShadowTree()) {
+        if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(firstPositionInOrBeforeNode(element)))
+            return textControl->isSpellCheckingEnabled();
+    }
+    return element->isSpellCheckingEnabled();
 }
 
 bool Editor::isSpellCheckingEnabledInFocusedNode() const

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (201941 => 201942)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2016-06-10 21:26:00 UTC (rev 201941)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2016-06-10 22:00:23 UTC (rev 201942)
@@ -117,6 +117,7 @@
 #if ENABLE(TOUCH_EVENTS)
     , m_hasTouchEventHandler(false)
 #endif
+    , m_isSpellCheckingEnabled(true)
     // m_inputType is lazily created when constructed by the parser to avoid constructing unnecessarily a text inputType and
     // its shadow subtree, just to destroy them when the |type| attribute gets set by the parser to something else than 'text'.
     , m_inputType(createdByParser ? nullptr : InputType::createText(*this))
@@ -423,6 +424,11 @@
     return m_inputType->shouldUseInputMethod();
 }
 
+bool HTMLInputElement::isSpellCheckingEnabled() const
+{
+    return m_isSpellCheckingEnabled && HTMLTextFormControlElement::isSpellCheckingEnabled();
+}
+
 void HTMLInputElement::handleFocusEvent(Node* oldFocusedNode, FocusDirection direction)
 {
     m_inputType->handleFocusEvent(oldFocusedNode, direction);

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (201941 => 201942)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2016-06-10 21:26:00 UTC (rev 201941)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2016-06-10 22:00:23 UTC (rev 201942)
@@ -307,6 +307,8 @@
 
     void endEditing();
 
+    void setSpellcheckEnabled(bool enabled) { m_isSpellCheckingEnabled = enabled; }
+
     static Vector<FileChooserFileInfo> filesFromFileInputFormControlState(const FormControlState&);
 
     bool matchesReadWritePseudoClass() const final;
@@ -348,6 +350,7 @@
     bool supportLabels() const final;
     void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode) final;
     bool shouldUseInputMethod() final;
+    bool isSpellCheckingEnabled() const final;
 
     bool isTextFormControl() const final { return isTextField(); }
 
@@ -448,6 +451,7 @@
 #if ENABLE(TOUCH_EVENTS)
     bool m_hasTouchEventHandler : 1;
 #endif
+    bool m_isSpellCheckingEnabled : 1;
     std::unique_ptr<InputType> m_inputType;
     // The ImageLoader must be owned by this element because the loader code assumes
     // that it lives as long as its owning element lives. If we move the loader into

Modified: trunk/Source/WebKit2/ChangeLog (201941 => 201942)


--- trunk/Source/WebKit2/ChangeLog	2016-06-10 21:26:00 UTC (rev 201941)
+++ trunk/Source/WebKit2/ChangeLog	2016-06-10 22:00:23 UTC (rev 201942)
@@ -1,3 +1,22 @@
+2016-06-09  Ryosuke Niwa  <[email protected]>
+
+        Add SPI to disable spellchecking on auto-fillable text fields
+        https://bugs.webkit.org/show_bug.cgi?id=158611
+
+        Reviewed by Anders Carlsson.
+
+        Added WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled to disable spellchecking on a text field.
+
+        This is used by WebKit2 client which desires to disable spellchecking and notably autocorrection on
+        login forms, etc... where such feature would interfere with user's actions.
+
+        * WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp:
+        (WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled): Added.
+        * WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h:
+        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
+        (WebKit::InjectedBundleNodeHandle::setHTMLInputElementSpellcheckEnabled): Added.
+        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h:
+
 2016-06-10  Alex Christensen  <[email protected]>
 
         Introduce WTF::UniqueRef

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp (201941 => 201942)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp	2016-06-10 21:26:00 UTC (rev 201941)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp	2016-06-10 22:00:23 UTC (rev 201942)
@@ -95,6 +95,11 @@
     toImpl(htmlInputElementHandleRef)->setHTMLInputElementValueForUser(toWTFString(valueRef));
 }
 
+void WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool enabled)
+{
+    toImpl(htmlInputElementHandleRef)->setHTMLInputElementSpellcheckEnabled(enabled);
+}
+
 bool WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef htmlInputElementHandleRef)
 {
     return toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutoFilled();

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h (201941 => 201942)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h	2016-06-10 21:26:00 UTC (rev 201941)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h	2016-06-10 22:00:23 UTC (rev 201942)
@@ -59,6 +59,7 @@
 
 /* HTMLInputElement Specific Operations */
 WK_EXPORT void WKBundleNodeHandleSetHTMLInputElementValueForUser(WKBundleNodeHandleRef htmlInputElementHandle, WKStringRef value);
+WK_EXPORT void WKBundleNodeHandleSetHTMLInputElementSpellcheckEnabled(WKBundleNodeHandleRef htmlInputElementHandle, bool enabled);
 WK_EXPORT bool WKBundleNodeHandleGetHTMLInputElementAutoFilled(WKBundleNodeHandleRef htmlInputElementHandle);
 WK_EXPORT void WKBundleNodeHandleSetHTMLInputElementAutoFilled(WKBundleNodeHandleRef htmlInputElementHandle, bool filled);
 WK_EXPORT bool WKBundleNodeHandleGetHTMLInputElementAutoFillButtonEnabled(WKBundleNodeHandleRef htmlInputElementHandle);

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp (201941 => 201942)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp	2016-06-10 21:26:00 UTC (rev 201941)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp	2016-06-10 22:00:23 UTC (rev 201942)
@@ -210,6 +210,14 @@
     downcast<HTMLInputElement>(m_node.get()).setValueForUser(value);
 }
 
+void InjectedBundleNodeHandle::setHTMLInputElementSpellcheckEnabled(bool enabled)
+{
+    if (!is<HTMLInputElement>(m_node))
+        return;
+
+    downcast<HTMLInputElement>(m_node.get()).setSpellcheckEnabled(enabled);
+}
+
 bool InjectedBundleNodeHandle::isHTMLInputElementAutoFilled() const
 {
     if (!is<HTMLInputElement>(m_node))

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h (201941 => 201942)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h	2016-06-10 21:26:00 UTC (rev 201941)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h	2016-06-10 22:00:23 UTC (rev 201942)
@@ -66,6 +66,7 @@
     PassRefPtr<WebImage> renderedImage(SnapshotOptions);
     PassRefPtr<InjectedBundleRangeHandle> visibleRange();
     void setHTMLInputElementValueForUser(const String&);
+    void setHTMLInputElementSpellcheckEnabled(bool);
     bool isHTMLInputElementAutoFilled() const;
     void setHTMLInputElementAutoFilled(bool);
     bool isHTMLInputElementAutoFillButtonEnabled() const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to