[chromium] Add WebKit API to access inner text value of input element
authorkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 May 2012 11:55:20 +0000 (11:55 +0000)
committerkeishi@webkit.org <keishi@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 May 2012 11:55:20 +0000 (11:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=85353

Reviewed by Kent Tamura.

.:

* Source/autotools/symbols.filter: Added HTMLInputElement::setEditingValue

Source/WebCore:

Test: fast/forms/editing-value.html

We need this to implement the datalist UI for  <input type=email multiple>.
HTMLInputElement.value gives you the sanitized value so the whitespace between values are trimmed.
We need to append the selected suggestion to the end without modifying the rest of the text.

* WebCore.exp.in: Added HTMLInputElement::setEditingValue
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::setEditingValue):
(WebCore):
* html/HTMLInputElement.h:
(HTMLInputElement):
* testing/Internals.cpp:
(WebCore::Internals::setEditingValue):
(WebCore):
* testing/Internals.h:
(Internals):
* testing/Internals.idl:

Source/WebKit/chromium:

* public/WebInputElement.h:
(WebInputElement):
* src/WebInputElement.cpp:
(WebKit::WebInputElement::editingValue):
(WebKit):
(WebKit::WebInputElement::setEditingValue):

Source/WebKit2:

* win/WebKit2.def: Added HTMLInputElement::setEditingValue
* win/WebKit2CFLite.def: Added HTMLInputElement::setEditingValue

LayoutTests:

* fast/forms/editing-value-expected.txt: Added.
* fast/forms/editing-value.html: Added. Tests that setting the editing value takes care of the style and placeholder, and that it fires an input event.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@117263 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/fast/forms/editing-value-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/editing-value.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebInputElement.h
Source/WebKit/chromium/src/WebInputElement.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/win/WebKit2.def
Source/WebKit2/win/WebKit2CFLite.def
Source/autotools/symbols.filter

index d7b004a..8e99e9e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-05-16  Keishi Hattori  <keishi@webkit.org>
+
+        [chromium] Add WebKit API to access inner text value of input element
+        https://bugs.webkit.org/show_bug.cgi?id=85353
+
+        Reviewed by Kent Tamura.
+
+        * Source/autotools/symbols.filter: Added HTMLInputElement::setEditingValue
+
 2012-05-15  Kihong Kwon  <kihong.kwon@samsung.com>
 
         [EFL] Enable Fullscreen API
index 6c7ee01..01dd504 100644 (file)
@@ -1,3 +1,13 @@
+2012-05-16  Keishi Hattori  <keishi@webkit.org>
+
+        [chromium] Add WebKit API to access inner text value of input element
+        https://bugs.webkit.org/show_bug.cgi?id=85353
+
+        Reviewed by Kent Tamura.
+
+        * fast/forms/editing-value-expected.txt: Added.
+        * fast/forms/editing-value.html: Added. Tests that setting the editing value takes care of the style and placeholder, and that it fires an input event.
+
 2012-05-16  Ádám Kallai  <kadam@inf.u-szeged.hu>
 
         [Qt] Gardening. Skip failing test after 117246.
diff --git a/LayoutTests/fast/forms/editing-value-expected.txt b/LayoutTests/fast/forms/editing-value-expected.txt
new file mode 100644 (file)
index 0000000..2f5311a
--- /dev/null
@@ -0,0 +1,13 @@
+This tests setting the editing value of an input.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS oninput event was fired.
+PASS input.value is "foo"
+PASS document.querySelector(":invalid") is input
+PASS onchange event was fired.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/editing-value.html b/LayoutTests/fast/forms/editing-value.html
new file mode 100644 (file)
index 0000000..4acc59e
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<input type="email" id="test" placeholder="FAIL: placeholder should disappear">
+
+<script>
+description('This tests setting the editing value of an input.');
+
+var input = document.getElementById('test');
+input.onchange = function() {
+    testPassed("onchange event was fired.");
+};
+input.oninput = function() {
+    testPassed("oninput event was fired.");
+};
+
+input.focus();
+if (window.internals) {
+    internals.setEditingValue(input, " foo ");
+} else {
+    debug('This test requires window.internals object.');
+}
+shouldBe('input.value', '"foo"');
+shouldBe('document.querySelector(":invalid")', 'input');
+input.blur();
+
+</script>
+
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index 99f72b4..036a9ce 100644 (file)
@@ -1,3 +1,29 @@
+2012-05-16  Keishi Hattori  <keishi@webkit.org>
+
+        [chromium] Add WebKit API to access inner text value of input element
+        https://bugs.webkit.org/show_bug.cgi?id=85353
+
+        Reviewed by Kent Tamura.
+
+        Test: fast/forms/editing-value.html
+
+        We need this to implement the datalist UI for  <input type=email multiple>.
+        HTMLInputElement.value gives you the sanitized value so the whitespace between values are trimmed.
+        We need to append the selected suggestion to the end without modifying the rest of the text.
+
+        * WebCore.exp.in: Added HTMLInputElement::setEditingValue
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::setEditingValue):
+        (WebCore):
+        * html/HTMLInputElement.h:
+        (HTMLInputElement):
+        * testing/Internals.cpp:
+        (WebCore::Internals::setEditingValue):
+        (WebCore):
+        * testing/Internals.h:
+        (Internals):
+        * testing/Internals.idl:
+
 2012-05-16  Jason Liu  <jason.liu@torchmobile.com.cn>
 
         [BlackBerry] Cookies should be checked during parsing to improve performance.
index 74fa604..38f68a8 100644 (file)
@@ -484,6 +484,7 @@ __ZN7WebCore16FontPlatformDataD1Ev
 __ZN7WebCore16HTMLInputElement13setAutofilledEb
 __ZN7WebCore16HTMLInputElement15setValueForUserERKN3WTF6StringE
 __ZN7WebCore16HTMLInputElement17setSuggestedValueERKN3WTF6StringE
+__ZN7WebCore16HTMLInputElement15setEditingValueERKN3WTF6StringE
 __ZN7WebCore16IconDatabaseBase28synchronousIconURLForPageURLERKN3WTF6StringE
 __ZN7WebCore16IconDatabaseBase4openERKN3WTF6StringES4_
 __ZN7WebCore16LegacyWebArchive19createFromSelectionEPNS_5FrameE
index e7fde13..05d4797 100644 (file)
@@ -889,6 +889,22 @@ void HTMLInputElement::setSuggestedValue(const String& value)
     updateInnerTextValue();
 }
 
+void HTMLInputElement::setEditingValue(const String& value)
+{
+    if (!renderer() || !isTextField())
+        return;
+    setInnerTextValue(value);
+    subtreeHasChanged();
+
+    unsigned max = value.length();
+    if (focused())
+        setSelectionRange(max, max);
+    else
+        cacheSelectionInResponseToSetValue(max);
+
+    dispatchInputEvent();
+}
+
 void HTMLInputElement::setValue(const String& value, TextFieldEventBehavior eventBehavior)
 {
     if (!m_inputType->canSetValue(value))
index 74ba054..1d5c4e6 100644 (file)
@@ -156,6 +156,8 @@ public:
     const String& suggestedValue() const;
     void setSuggestedValue(const String&);
 
+    void setEditingValue(const String&);
+
     double valueAsDate() const;
     void setValueAsDate(double, ExceptionCode&);
 
index c56080b..e17185f 100644 (file)
@@ -634,6 +634,22 @@ void Internals::setSuggestedValue(Element* element, const String& value, Excepti
     inputElement->setSuggestedValue(value);
 }
 
+void Internals::setEditingValue(Element* element, const String& value, ExceptionCode& ec)
+{
+    if (!element) {
+        ec = INVALID_ACCESS_ERR;
+        return;
+    }
+
+    HTMLInputElement* inputElement = element->toInputElement();
+    if (!inputElement) {
+        ec = INVALID_NODE_TYPE_ERR;
+        return;
+    }
+
+    inputElement->setEditingValue(value);
+}
+
 void Internals::scrollElementToRect(Element* element, long x, long y, long w, long h, ExceptionCode& ec)
 {
     if (!element || !element->document() || !element->document()->view()) {
index fd8747d..89faeac 100644 (file)
@@ -113,6 +113,7 @@ public:
     bool wasLastChangeUserEdit(Element* textField, ExceptionCode&);
     String suggestedValue(Element* inputElement, ExceptionCode&);
     void setSuggestedValue(Element* inputElement, const String&, ExceptionCode&);
+    void setEditingValue(Element* inputElement, const String&, ExceptionCode&);
     void scrollElementToRect(Element*, long x, long y, long w, long h, ExceptionCode&);
 
     void paintControlTints(Document*, ExceptionCode&);
index 7f5a211..6c9e88e 100644 (file)
@@ -85,6 +85,7 @@ module window {
         boolean wasLastChangeUserEdit(in Element textField) raises (DOMException);
         DOMString suggestedValue(in Element inputElement) raises (DOMException);
         void setSuggestedValue(in Element inputElement, in DOMString value) raises (DOMException);
+        void setEditingValue(in Element inputElement, in DOMString value) raises (DOMException);
 
         void paintControlTints(in Document document) raises (DOMException);
 
index ca3f19e..1a5c7dc 100644 (file)
@@ -1,3 +1,17 @@
+2012-05-16  Keishi Hattori  <keishi@webkit.org>
+
+        [chromium] Add WebKit API to access inner text value of input element
+        https://bugs.webkit.org/show_bug.cgi?id=85353
+
+        Reviewed by Kent Tamura.
+
+        * public/WebInputElement.h:
+        (WebInputElement):
+        * src/WebInputElement.cpp:
+        (WebKit::WebInputElement::editingValue):
+        (WebKit):
+        (WebKit::WebInputElement::setEditingValue):
+
 2012-05-16  Hans Wennborg  <hans@chromium.org>
 
         Speech JavaScript API: pass WebSecurityOrigin to embedder
index b1c407c..23e85aa 100644 (file)
@@ -74,6 +74,12 @@ namespace WebKit {
         WEBKIT_EXPORT int size() const;
         WEBKIT_EXPORT void setValue(const WebString&, bool sendChangeEvent = false);
         WEBKIT_EXPORT WebString value() const;
+        // This returns the non-sanitized, exact value inside the text field.
+        WEBKIT_EXPORT WebString editingValue() const;
+        // Sets the value inside the text field without being sanitized.
+        // Can't be used if a renderer doesn't exist or on a non text field type.
+        // Caret will be moved to the end.
+        WEBKIT_EXPORT void setEditingValue(const WebString&);
         WEBKIT_EXPORT void setSuggestedValue(const WebString&);
         WEBKIT_EXPORT WebString suggestedValue() const;
         WEBKIT_EXPORT void setPlaceholder(const WebString&);
index c0037a0..adae9da 100644 (file)
@@ -98,6 +98,16 @@ WebString WebInputElement::value() const
     return constUnwrap<HTMLInputElement>()->value();
 }
 
+WebString WebInputElement::editingValue() const
+{
+    return constUnwrap<HTMLInputElement>()->innerTextValue();
+}
+
+void WebInputElement::setEditingValue(const WebString& value)
+{
+    unwrap<HTMLInputElement>()->setEditingValue(value);
+}
+
 void WebInputElement::setSuggestedValue(const WebString& value)
 {
     unwrap<HTMLInputElement>()->setSuggestedValue(value);
index 7c5ab7e..a0a1178 100644 (file)
@@ -1,3 +1,13 @@
+2012-05-16  Keishi Hattori  <keishi@webkit.org>
+
+        [chromium] Add WebKit API to access inner text value of input element
+        https://bugs.webkit.org/show_bug.cgi?id=85353
+
+        Reviewed by Kent Tamura.
+
+        * win/WebKit2.def: Added HTMLInputElement::setEditingValue
+        * win/WebKit2CFLite.def: Added HTMLInputElement::setEditingValue
+
 2012-05-16  Zalan Bujtas  <zbujtas@gmail.com>
 
         [Qt][WK2] Move WebFrameNetworkingContext to WebKit namespace.
index ff89a56..8e3c2c4 100644 (file)
@@ -224,6 +224,7 @@ EXPORTS
         ?setSerifFontFamily@Settings@WebCore@@QAEXABVAtomicString@WTF@@W4UScriptCode@@@Z
         ?setStandardFontFamily@Settings@WebCore@@QAEXABVAtomicString@WTF@@W4UScriptCode@@@Z
         ?setSuggestedValue@HTMLInputElement@WebCore@@QAEXABVString@WTF@@@Z
+        ?setEditingValue@HTMLInputElement@WebCore@@QAEXABVString@WTF@@@Z
         ?settings@Document@WebCore@@QBEPAVSettings@2@XZ
         ?settings@Frame@WebCore@@QBEPAVSettings@2@XZ
         ?setFixedElementsLayoutRelativeToFrame@Settings@WebCore@@QAEX_N@Z
index 11e4834..7cf9083 100644 (file)
@@ -217,6 +217,7 @@ EXPORTS
         ?setSerifFontFamily@Settings@WebCore@@QAEXABVAtomicString@WTF@@W4UScriptCode@@@Z
         ?setStandardFontFamily@Settings@WebCore@@QAEXABVAtomicString@WTF@@W4UScriptCode@@@Z
         ?setSuggestedValue@HTMLInputElement@WebCore@@QAEXABVString@WTF@@@Z
+        ?setEditingValue@HTMLInputElement@WebCore@@QAEXABVString@WTF@@@Z
         ?settings@Document@WebCore@@QBEPAVSettings@2@XZ
         ?settings@Frame@WebCore@@QBEPAVSettings@2@XZ
         ?setFixedElementsLayoutRelativeToFrame@Settings@WebCore@@QAEX_N@Z
index f507272..09a95ea 100644 (file)
@@ -55,6 +55,7 @@ _ZN7WebCore14ClientRectListC1Ev;
 _ZN7WebCore14ClientRectListD1Ev;
 _ZN7WebCore15setDOMExceptionEPN3JSC9ExecStateEi;
 _ZN7WebCore16HTMLInputElement17setSuggestedValueERKN3WTF6StringE;
+_ZN7WebCore16HTMLInputElement15setEditingValueERKN3WTF6StringE;
 _ZN7WebCore16jsStringSlowCaseEPN3JSC9ExecStateERN3WTF7HashMapIPNS3_10StringImplENS0_4WeakINS0_8JSStringEEENS3_10StringHashENS3_10HashTraitsIS6_EENSB_IS9_EEEES6_;
 _ZN7WebCore16scriptNameToCodeERKN3WTF6StringE;
 _ZN7WebCore17cacheDOMStructureEPNS_17JSDOMGlobalObjectEPN3JSC9StructureEPKNS2_9ClassInfoE;