Log Message
2011-07-05 Kentaro Hara <[email protected]> Trigger a 'change' event whenever selected files are changed https://bugs.webkit.org/show_bug.cgi?id=63929
Reviewed by Kent Tamura.
Record previously selected files and then compare them with newly selected files.
If the previously selected files and their order are not equal to those of
the newly selected files, we trigger the 'change' event.
* fast/forms/file-input-change-event-expected.txt: Added.
* fast/forms/file-input-change-event.html: Added.
2011-07-05 Kentaro Hara <[email protected]>
Trigger a 'change' event whenever selected files are changed
https://bugs.webkit.org/show_bug.cgi?id=63929
Reviewed by Kent Tamura.
Record previously selected files and then compare them with newly selected files.
If the previously selected files and their order are not equal to those of
the newly selected files, we trigger the 'change' event.
Test: fast/forms/file-input-change-event.html
* html/FileInputType.cpp:
(WebCore::FileInputType::filesChosen): Calls dispathChangeEvent() only when the previously selected files are different from the newly selected files
Modified Paths
- trunk/LayoutTests/ChangeLog
- trunk/Source/WebCore/ChangeLog
- trunk/Source/WebCore/html/FileInputType.cpp
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (90437 => 90438)
--- trunk/LayoutTests/ChangeLog 2011-07-06 06:35:44 UTC (rev 90437)
+++ trunk/LayoutTests/ChangeLog 2011-07-06 06:36:56 UTC (rev 90438)
@@ -1,3 +1,17 @@
+2011-07-05 Kentaro Hara <[email protected]>
+
+ Trigger a 'change' event whenever selected files are changed
+ https://bugs.webkit.org/show_bug.cgi?id=63929
+
+ Reviewed by Kent Tamura.
+
+ Record previously selected files and then compare them with newly selected files.
+ If the previously selected files and their order are not equal to those of
+ the newly selected files, we trigger the 'change' event.
+
+ * fast/forms/file-input-change-event-expected.txt: Added.
+ * fast/forms/file-input-change-event.html: Added.
+
2011-06-29 Kent Tamura <[email protected]>
Reviewed by Alexey Proskuryakov.
Added: trunk/LayoutTests/fast/forms/file-input-change-event-expected.txt (0 => 90438)
--- trunk/LayoutTests/fast/forms/file-input-change-event-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/forms/file-input-change-event-expected.txt 2011-07-06 06:36:56 UTC (rev 90438)
@@ -0,0 +1,40 @@
+
+This tests the condition that triggers a 'change' event on file input forms.
+
+Test that the 'change' event is triggered on a single file form when a selected file is changed:
+PASS singleFileInput.value is "C:\\fakepath\\foo.txt"
+PASS changeDispatched is true
+PASS singleFileInput.value is "C:\\fakepath\\bar.txt"
+PASS changeDispatched is true
+PASS singleFileInput.value is "C:\\fakepath\\bar.txt"
+PASS changeDispatched is false
+PASS singleFileInput.value is "C:\\fakepath\\foo.txt"
+PASS changeDispatched is true
+Test that the 'change' event is triggered on a multiple file form when a selected file is changed:
+PASS multipleFilesInput.value is "C:\\fakepath\\foo.txt"
+PASS changeDispatched is true
+PASS multipleFilesInput.value is "C:\\fakepath\\bar.txt"
+PASS changeDispatched is true
+PASS multipleFilesInput.value is "C:\\fakepath\\bar.txt"
+PASS changeDispatched is false
+PASS multipleFilesInput.value is "C:\\fakepath\\foo.txt"
+PASS changeDispatched is true
+Test that the 'change' event is triggered on a multiple file form when selected files are changed:
+PASS multipleFilesInput.value is "C:\\fakepath\\foo.txt"
+PASS changeDispatched is true
+PASS multipleFilesInput.value is "C:\\fakepath\\foo.txt"
+PASS changeDispatched is true
+PASS multipleFilesInput.value is "C:\\fakepath\\foo.txt"
+PASS changeDispatched is true
+PASS multipleFilesInput.value is "C:\\fakepath\\foo.txt"
+PASS changeDispatched is true
+PASS multipleFilesInput.value is "C:\\fakepath\\foo.txt"
+PASS changeDispatched is true
+PASS multipleFilesInput.value is "C:\\fakepath\\bar.txt"
+PASS changeDispatched is true
+PASS multipleFilesInput.value is "C:\\fakepath\\bar.txt"
+PASS changeDispatched is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/forms/file-input-change-event.html (0 => 90438)
--- trunk/LayoutTests/fast/forms/file-input-change-event.html (rev 0)
+++ trunk/LayoutTests/fast/forms/file-input-change-event.html 2011-07-06 06:36:56 UTC (rev 90438)
@@ -0,0 +1,110 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<input type="file" id="singleFile" name="upfile" _onchange_="singleFileSelected()" />
+<input type="file" id="multipleFiles" name="upfile[]" multiple="multiple" _onchange_="multipleFilesSelected()" />
+<div id="console">
+<p>
+This tests the condition that triggers a 'change' event on file input forms.
+</p>
+</div>
+<script>
+var changeDispatched;
+
+if (window.layoutTestController) {
+ var singleFileInput = document.getElementById("singleFile");
+ var multipleFilesInput = document.getElementById("multipleFiles");
+
+ debug("Test that the 'change' event is triggered on a single file form when a selected file is changed:");
+ dragFilesOntoInput(singleFileInput, ["foo.txt"]);
+ shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\foo.txt");
+ shouldBe("changeDispatched", "true");
+
+ dragFilesOntoInput(singleFileInput, ["bar.txt"]);
+ shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\bar.txt");
+ shouldBe("changeDispatched", "true");
+
+ dragFilesOntoInput(singleFileInput, ["bar.txt"]);
+ shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\bar.txt");
+ shouldBe("changeDispatched", "false");
+
+ dragFilesOntoInput(singleFileInput, ["foo.txt"]);
+ shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\foo.txt");
+ shouldBe("changeDispatched", "true");
+
+ debug("Test that the 'change' event is triggered on a multiple file form when a selected file is changed:");
+ dragFilesOntoInput(multipleFilesInput, ["foo.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
+ shouldBe("changeDispatched", "true");
+
+ dragFilesOntoInput(multipleFilesInput, ["bar.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
+ shouldBe("changeDispatched", "true");
+
+ dragFilesOntoInput(multipleFilesInput, ["bar.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
+ shouldBe("changeDispatched", "false");
+
+ dragFilesOntoInput(multipleFilesInput, ["foo.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
+ shouldBe("changeDispatched", "true");
+
+ debug("Test that the 'change' event is triggered on a multiple file form when selected files are changed:");
+ dragFilesOntoInput(multipleFilesInput, ["foo.txt", "bar.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
+ shouldBe("changeDispatched", "true");
+
+ dragFilesOntoInput(multipleFilesInput, ["foo.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
+ shouldBe("changeDispatched", "true");
+
+ dragFilesOntoInput(multipleFilesInput, ["foo.txt", "bar.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
+ shouldBe("changeDispatched", "true");
+
+ dragFilesOntoInput(multipleFilesInput, ["foo.txt", "bar.txt", "baz.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
+ shouldBe("changeDispatched", "true");
+
+ dragFilesOntoInput(multipleFilesInput, ["foo.txt", "bar.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
+ shouldBe("changeDispatched", "true");
+
+ dragFilesOntoInput(multipleFilesInput, ["bar.txt", "foo.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
+ shouldBe("changeDispatched", "true");
+
+ dragFilesOntoInput(multipleFilesInput, ["bar.txt", "foo.txt"]);
+ shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
+ shouldBe("changeDispatched", "false");
+}
+
+function singleFileSelected() {
+ changeDispatched = true;
+}
+
+function multipleFilesSelected() {
+ changeDispatched = true;
+}
+
+function moveMouseToCenterOfElement(element) {
+ var centerX = element.offsetLeft + element.offsetWidth / 2;
+ var centerY = element.offsetTop + element.offsetHeight / 2;
+ eventSender.mouseMoveTo(centerX, centerY);
+}
+
+function dragFilesOntoInput(input, files) {
+ changeDispatched = false;
+ eventSender.beginDragWithFiles(files);
+ moveMouseToCenterOfElement(input);
+ eventSender.mouseUp();
+}
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (90437 => 90438)
--- trunk/Source/WebCore/ChangeLog 2011-07-06 06:35:44 UTC (rev 90437)
+++ trunk/Source/WebCore/ChangeLog 2011-07-06 06:36:56 UTC (rev 90438)
@@ -1,3 +1,19 @@
+2011-07-05 Kentaro Hara <[email protected]>
+
+ Trigger a 'change' event whenever selected files are changed
+ https://bugs.webkit.org/show_bug.cgi?id=63929
+
+ Reviewed by Kent Tamura.
+
+ Record previously selected files and then compare them with newly selected files.
+ If the previously selected files and their order are not equal to those of
+ the newly selected files, we trigger the 'change' event.
+
+ Test: fast/forms/file-input-change-event.html
+
+ * html/FileInputType.cpp:
+ (WebCore::FileInputType::filesChosen): Calls dispathChangeEvent() only when the previously selected files are different from the newly selected files
+
2011-06-29 Kent Tamura <[email protected]>
Reviewed by Alexey Proskuryakov.
Modified: trunk/Source/WebCore/html/FileInputType.cpp (90437 => 90438)
--- trunk/Source/WebCore/html/FileInputType.cpp 2011-07-06 06:35:44 UTC (rev 90437)
+++ trunk/Source/WebCore/html/FileInputType.cpp 2011-07-06 06:36:56 UTC (rev 90438)
@@ -277,7 +277,20 @@
void FileInputType::filesChosen(const Vector<String>& paths)
{
- HTMLInputElement* input = element();
+ RefPtr<HTMLInputElement> input = element();
+
+ bool pathsChanged = false;
+ if (paths.size() != m_fileList->length())
+ pathsChanged = true;
+ else {
+ for (unsigned i = 0; i < paths.size(); ++i) {
+ if (paths[i] != m_fileList->item(i)->path()) {
+ pathsChanged = true;
+ break;
+ }
+ }
+ }
+
setFileList(paths);
input->setFormControlValueMatchesRenderer(true);
@@ -288,8 +301,13 @@
if (input->renderer())
input->renderer()->repaint();
- // This call may cause destruction of this instance and thus must always be last in the function.
- input->dispatchFormControlChangeEvent();
+
+ if (pathsChanged) {
+ // This call may cause destruction of this instance.
+ // input instance is safe since it is ref-counted.
+ input->HTMLElement::dispatchChangeEvent();
+ }
+ input->setChangedSinceLastFormControlChangeEvent(false);
}
#if ENABLE(DIRECTORY_UPLOAD)
_______________________________________________ webkit-changes mailing list [email protected] http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes
