Delaying 'change' and 'input' event dispatching during HTMLInputElement::setValue
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2012 05:19:21 +0000 (05:19 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2012 05:19:21 +0000 (05:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=100772

Reviewed by Abhishek Arya.

Source/WebCore:

'change' and 'input' events are asynchronous and not
cancelable. We can use ScopedEvent.

Test: fast/forms/range/range-type-change-onchange.html

* dom/Node.cpp:
(WebCore::Node::dispatchChangeEvent): Use dispatchScopedEvent.
(WebCore::Node::dispatchInputEvent): Ditto.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::setValue):
Make a scope to delay event dispatching.
* html/RangeInputType.cpp:
(WebCore::RangeInputType::handleKeydownEvent): Ditto.

LayoutTests:

* fast/forms/range/range-type-change-onchange-expected.txt: Added.
* fast/forms/range/range-type-change-onchange.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/forms/range/range-type-change-onchange-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/range/range-type-change-onchange.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Node.cpp
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/RangeInputType.cpp

index fa8e50b..9fcaa39 100644 (file)
@@ -1,3 +1,13 @@
+2012-10-30  Kent Tamura  <tkent@chromium.org>
+
+        Delaying 'change' and 'input' event dispatching during HTMLInputElement::setValue
+        https://bugs.webkit.org/show_bug.cgi?id=100772
+
+        Reviewed by Abhishek Arya.
+
+        * fast/forms/range/range-type-change-onchange-expected.txt: Added.
+        * fast/forms/range/range-type-change-onchange.html: Added.
+
 2012-10-30  Simon Fraser  <simon.fraser@apple.com>
 
         Fix issues with filters and reflections
diff --git a/LayoutTests/fast/forms/range/range-type-change-onchange-expected.txt b/LayoutTests/fast/forms/range/range-type-change-onchange-expected.txt
new file mode 100644 (file)
index 0000000..a9cdc89
--- /dev/null
@@ -0,0 +1,10 @@
+Check if no problem happens by type change in onchange handler.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS unless crash
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/range/range-type-change-onchange.html b/LayoutTests/fast/forms/range/range-type-change-onchange.html
new file mode 100644 (file)
index 0000000..2fa67ec
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<body>
+<script src="../../js/resources/js-test-pre.js"></script>
+
+<input id="range1" type="range" onchange="updateType(this)" autofocus>
+<script>
+description('Check if no problem happens by type change in onchange handler.');
+
+function updateType(input) {
+    input.type = 'text';
+    setTimeout(finish, 0);
+}
+
+function finish() {
+    testPassed('unless crash');
+    finishJSTest();
+}
+
+jsTestIsAsync = true;
+eventSender.keyDown('upArrow');
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
index 90aec0a..7249c89 100644 (file)
@@ -1,3 +1,24 @@
+2012-10-30  Kent Tamura  <tkent@chromium.org>
+
+        Delaying 'change' and 'input' event dispatching during HTMLInputElement::setValue
+        https://bugs.webkit.org/show_bug.cgi?id=100772
+
+        Reviewed by Abhishek Arya.
+
+        'change' and 'input' events are asynchronous and not
+        cancelable. We can use ScopedEvent.
+
+        Test: fast/forms/range/range-type-change-onchange.html
+
+        * dom/Node.cpp:
+        (WebCore::Node::dispatchChangeEvent): Use dispatchScopedEvent.
+        (WebCore::Node::dispatchInputEvent): Ditto.
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::setValue):
+        Make a scope to delay event dispatching.
+        * html/RangeInputType.cpp:
+        (WebCore::RangeInputType::handleKeydownEvent): Ditto.
+
 2012-10-30  Simon Fraser  <simon.fraser@apple.com>
 
         Fix issues with filters and reflections
index 60300fa..55375a6 100644 (file)
@@ -2665,12 +2665,12 @@ void Node::dispatchBlurEvent(PassRefPtr<Node> newFocusedNode)
 
 void Node::dispatchChangeEvent()
 {
-    dispatchEvent(Event::create(eventNames().changeEvent, true, false));
+    dispatchScopedEvent(Event::create(eventNames().changeEvent, true, false));
 }
 
 void Node::dispatchInputEvent()
 {
-    dispatchEvent(Event::create(eventNames().inputEvent, true, false));
+    dispatchScopedEvent(Event::create(eventNames().inputEvent, true, false));
 }
 
 bool Node::disabled() const
index bda4471..e02df26 100644 (file)
@@ -54,6 +54,7 @@
 #include "NumberInputType.h"
 #include "RenderTextControlSingleLine.h"
 #include "RenderTheme.h"
+#include "ScopedEventQueue.h"
 #include "SearchInputType.h"
 #include "ShadowRoot.h"
 #include "ScriptEventListener.h"
@@ -1021,6 +1022,7 @@ void HTMLInputElement::setValue(const String& value, TextFieldEventBehavior even
         return;
 
     RefPtr<HTMLInputElement> protector(this);
+    EventQueueScope scope;
     String sanitizedValue = sanitizeValue(value);
     bool valueChanged = sanitizedValue != this->value();
 
index 4c70608..1e83844 100644 (file)
@@ -43,6 +43,7 @@
 #include "MouseEvent.h"
 #include "PlatformMouseEvent.h"
 #include "RenderSlider.h"
+#include "ScopedEventQueue.h"
 #include "ShadowRoot.h"
 #include "SliderThumbElement.h"
 #include "StepRange.h"
@@ -235,6 +236,7 @@ void RangeInputType::handleKeydownEvent(KeyboardEvent* event)
     newValue = stepRange.clampValue(newValue);
 
     if (newValue != current) {
+        EventQueueScope scope;
         ExceptionCode ec;
         TextFieldEventBehavior eventBehavior = DispatchChangeEvent;
         setValueAsDecimal(newValue, eventBehavior, ec);