[chromium] Support file drag out using DataTransferItemList::add(File)
authordcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Mar 2012 22:25:16 +0000 (22:25 +0000)
committerdcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Mar 2012 22:25:16 +0000 (22:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81261

Reviewed by Tony Chang.

Source/WebCore:

Original patch by Varun Jain <varunjain@chromium.org>.
I've updated the original patch to remove 'downloadurl' handling since it's not tested, nor
is it necessary for File objects, since File objects correspond to a native filesystem path.

Test: fast/events/drag-dataTransferItemList-file-handling.html

* platform/chromium/DataTransferItemListChromium.cpp:
(WebCore::DataTransferItemListChromium::add):

Source/WebKit/chromium:

Original patch by Varun Jain <varunjain@chromium.org>.
I've updated the original patch to add some asserts for conditions we shouldn't encounter as
well as removing some redundant null checks.

* src/WebDragData.cpp:
(WebKit::WebDragData::items):

LayoutTests:

* fast/events/drag-dataTransferItemList-file-handling-expected.txt: Added.
* fast/events/drag-dataTransferItemList-file-handling.html: Added.
* platform/gtk/Skipped:
* platform/mac/Skipped:
* platform/qt/Skipped:
* platform/win/Skipped:

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

LayoutTests/ChangeLog
LayoutTests/fast/events/drag-dataTransferItemList-file-handling-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/drag-dataTransferItemList-file-handling.html [new file with mode: 0644]
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/mac/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
Source/WebCore/ChangeLog
Source/WebCore/platform/chromium/DataTransferItemListChromium.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebDragData.cpp

index 343c525ebdf8cb58944cfa8f0e354fb66d9c5a5a..23ad922ddec188a605cbf7efce785ae378e39d7a 100644 (file)
@@ -1,3 +1,17 @@
+2012-03-23  Daniel Cheng  <dcheng@chromium.org>
+
+        [chromium] Support file drag out using DataTransferItemList::add(File)
+        https://bugs.webkit.org/show_bug.cgi?id=81261
+
+        Reviewed by Tony Chang.
+
+        * fast/events/drag-dataTransferItemList-file-handling-expected.txt: Added.
+        * fast/events/drag-dataTransferItemList-file-handling.html: Added.
+        * platform/gtk/Skipped:
+        * platform/mac/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+
 2012-03-23  Dan Bernstein  <mitz@apple.com>
 
         Added all tests that crashed more than once on the Lion WebKit2 bots between r111867
diff --git a/LayoutTests/fast/events/drag-dataTransferItemList-file-handling-expected.txt b/LayoutTests/fast/events/drag-dataTransferItemList-file-handling-expected.txt
new file mode 100644 (file)
index 0000000..0720a97
--- /dev/null
@@ -0,0 +1,8 @@
+To manually test, select a text file for the file input element, and then drag 'Drag Me' to 'Drop Here' and drop. Several lines that say 'PASS' should appear below. 
+
+Drag Me
+Drop Here
+PASS: 1 === 1
+PASS: file === file
+PASS: text/plain === text/plain
+
diff --git a/LayoutTests/fast/events/drag-dataTransferItemList-file-handling.html b/LayoutTests/fast/events/drag-dataTransferItemList-file-handling.html
new file mode 100644 (file)
index 0000000..48ffb6b
--- /dev/null
@@ -0,0 +1,96 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+#drag {
+    border: 1px solid black;
+    height: 200px;
+    width: 200px;
+}
+#drop {
+    border: 1px solid black;
+    height: 200px;
+    width: 200px;
+}
+</style>
+<script>
+function assertEq(left, right)
+{
+    if (left === right)
+        log('PASS: ' + left + " === " + right);
+    else
+        log('FAIL: ' + left + " (of type " + (typeof left) + ") !== " + right + " (of type " + (typeof right) + ")");
+}
+function log(str)
+{
+    var result = document.getElementById('result');
+    result.appendChild(document.createTextNode(str));
+    result.appendChild(document.createElement('br'));
+}
+
+var testFile;
+function dragstart(event)
+{
+    event.dataTransfer.items.add(testFile);
+}
+
+function dragenter(event)
+{
+    event.preventDefault();
+}
+
+function dragover(event)
+{
+    event.preventDefault();
+}
+
+function drop(event)
+{
+    assertEq(1, event.dataTransfer.items.length);
+    assertEq('file', event.dataTransfer.items[0].kind);
+    assertEq('text/plain', event.dataTransfer.items[0].type);
+    layoutTestController.notifyDone();
+}
+
+function runTest()
+{
+    // First, we need to generate a File object to use for our tests.
+    eventSender.beginDragWithFiles(['test.txt']);
+    var inputElement = document.getElementsByTagName('input')[0];
+    eventSender.mouseMoveTo(inputElement.offsetLeft + inputElement.offsetWidth / 2,
+                            inputElement.offsetTop + inputElement.offsetHeight / 2);
+    eventSender.mouseUp();
+    testFile = inputElement.files[0];
+
+    // Now run the actual test.
+    var dragElement = document.getElementById('drag');
+    eventSender.mouseMoveTo(dragElement.offsetLeft + dragElement.offsetWidth / 2,
+                            dragElement.offsetTop + dragElement.offsetHeight / 2);
+    eventSender.mouseDown();
+    eventSender.leapForward(100);
+    var dropElement = document.getElementById('drop');
+    eventSender.mouseMoveTo(dropElement.offsetLeft + dropElement.offsetWidth / 2,
+                            dropElement.offsetTop + dropElement.offsetHeight / 2);
+    eventSender.mouseUp();
+}
+
+window.onload = function()
+{
+    if (!window.layoutTestController)
+        return;
+    layoutTestController.dumpAsText();
+    layoutTestController.waitUntilDone();
+
+    runTest();
+}
+</script>
+</head>
+<body>
+<p>To manually test, select a text file for the file input element, and then drag 'Drag Me' to 'Drop Here' and drop.  Several lines that say 'PASS' should appear below.
+<input type="file"></input>
+<div draggable="true" id="drag" ondragstart="dragstart(event)">Drag Me</div>
+<div id="drop" ondragenter="dragenter(event)" ondragover="dragover(event)" ondrop="drop(event)">Drop Here</div>
+</div>
+<div id="result"></div>
+</body>
+</html>
index 7bc95905b1b4c4bbc6f13205e4aeeb40db17fac0..d06ca9f39fafa64a29dd58a4995ecc26dac962dd 100644 (file)
@@ -307,6 +307,7 @@ editing/pasteboard/data-transfer-items-drag-drop-file.html
 editing/pasteboard/data-transfer-items-drag-drop-string.html
 fast/events/clipboard-dataTransferItemList.html
 fast/events/drag-dataTransferItemList.html
+fast/events/drag-dataTransferItemList-file-handling.html
 
 # Custom MIME type support in DataTransfer is not yet implemented.
 editing/pasteboard/clipboard-customData.html
index 66fe1afbf3f1da5512ccf31eac61f842f042f548..91433e288a5f1f0366f48037fdad229df285d066 100644 (file)
@@ -354,6 +354,7 @@ editing/pasteboard/data-transfer-items-drag-drop-file.html
 editing/pasteboard/data-transfer-items-drag-drop-string.html
 fast/events/clipboard-dataTransferItemList.html
 fast/events/drag-dataTransferItemList.html
+fast/events/drag-dataTransferItemList-file-handling.html
 
 # Replacement text for misspelling is not given from NSSpellChecker.
 # https://bugs.webkit.org/show_bug.cgi?id=77934
index ddd7e5154b7fc6e7492183d757a46e788ecf0706..a79c53dbfcd3d88d2373780e554656cd499728fa 100644 (file)
@@ -459,6 +459,7 @@ editing/pasteboard/data-transfer-items-drag-drop-file.html
 editing/pasteboard/data-transfer-items-drag-drop-string.html
 fast/events/clipboard-dataTransferItemList.html
 fast/events/drag-dataTransferItemList.html
+fast/events/drag-dataTransferItemList-file-handling.html
 
 # PasteBoard::plainText() does not support file names.
 editing/pasteboard/drag-files-to-editable-element.html
index cd5e23f7192c310d5229a2921d03c2f8069be656..2477f1e69243999c3905b94ab4b99a8797291e7b 100644 (file)
@@ -1338,6 +1338,7 @@ editing/pasteboard/data-transfer-items-drag-drop-file.html
 editing/pasteboard/data-transfer-items-drag-drop-string.html
 fast/events/clipboard-dataTransferItemList.html
 fast/events/drag-dataTransferItemList.html
+fast/events/drag-dataTransferItemList-file-handling.html
 
 # Custom MIME type support in DataTransfer not yet implemented.
 editing/pasteboard/clipboard-customData.html
index 5966f2362e797a71c909bbfb9806fc7100d0f3d2..3e2ab78c4482fac5c04ac5abd0b79e1087e57b70 100644 (file)
@@ -1,3 +1,19 @@
+2012-03-23  Daniel Cheng  <dcheng@chromium.org>
+
+        [chromium] Support file drag out using DataTransferItemList::add(File)
+        https://bugs.webkit.org/show_bug.cgi?id=81261
+
+        Reviewed by Tony Chang.
+
+        Original patch by Varun Jain <varunjain@chromium.org>.
+        I've updated the original patch to remove 'downloadurl' handling since it's not tested, nor
+        is it necessary for File objects, since File objects correspond to a native filesystem path.
+
+        Test: fast/events/drag-dataTransferItemList-file-handling.html
+
+        * platform/chromium/DataTransferItemListChromium.cpp:
+        (WebCore::DataTransferItemListChromium::add):
+
 2012-03-23  Zan Dobersek  <zandobersek@gmail.com>
 
         [GObject bindings] Supplemental interfaces are not disabled with the "Conditional" attribute
index 7befb805742a08ca88ee7953a1bfd693bae2fec3..df763d704159ae8194a95d3088e1f74c01d534aa 100644 (file)
@@ -106,19 +106,6 @@ void DataTransferItemListChromium::add(PassRefPtr<File> file, ScriptExecutionCon
         return;
 
     m_itemList.append(DataTransferItemChromium::createFromFile(file));
-
-    // FIXME: Allow multiple files to be dragged out at once if more than one file is added to the storage.
-    KURL urlForDownload = BlobURL::createPublicURL(context->securityOrigin());
-    ThreadableBlobRegistry::registerBlobURL(urlForDownload, file->url());
-
-    StringBuilder downloadUrl;
-    downloadUrl.append(file->type());
-    downloadUrl.append(":");
-    downloadUrl.append(encodeWithURLEscapeSequences(file->name()));
-    downloadUrl.append(":");
-    downloadUrl.append(urlForDownload.string());
-
-    internalAddStringItem(DataTransferItemChromium::createFromString(mimeTypeDownloadURL, downloadUrl.toString()));
 }
 
 // FIXME: Make sure item is released correctly in case of failure.
index e0e6513396365281af68786e1309ff55a5e1cd1d..27e9043b8112849a5447835afd6162448b147857 100644 (file)
@@ -1,3 +1,17 @@
+2012-03-23  Daniel Cheng  <dcheng@chromium.org>
+
+        [chromium] Support file drag out using DataTransferItemList::add(File)
+        https://bugs.webkit.org/show_bug.cgi?id=81261
+
+        Reviewed by Tony Chang.
+
+        Original patch by Varun Jain <varunjain@chromium.org>.
+        I've updated the original patch to add some asserts for conditions we shouldn't encounter as
+        well as removing some redundant null checks.
+
+        * src/WebDragData.cpp:
+        (WebKit::WebDragData::items):
+
 2012-03-23  Dana Jansens  <danakj@chromium.org>
 
         [chromium] Record painted pixel counts for measuring effectiveness of per-tile painting
index fbf5da7bd3f744ea8b8498f2a0a82d45b4f7dfa9..dbef95a0cefdc6686a4391ee1c1597b609512fb6 100644 (file)
@@ -72,8 +72,6 @@ WebVector<WebDragData::Item> WebDragData::items() const
     Vector<Item> itemList;
     for (size_t i = 0; i < m_private->items()->length(); ++i) {
         DataTransferItemChromium* originalItem = m_private->items()->item(i).get();
-        // We don't handle filenames here, since they are never used for dragging out.
-        ASSERT(!originalItem->isFilename());
         WebDragData::Item item;
         if (originalItem->kind() == DataTransferItem::kindString) {
             item.storageType = Item::StorageTypeString;
@@ -83,10 +81,16 @@ WebVector<WebDragData::Item> WebDragData::items() const
             if (originalItem->sharedBuffer()) {
                 item.storageType = Item::StorageTypeBinaryData;
                 item.binaryData = originalItem->sharedBuffer();
+            } else if (originalItem->isFilename()) {
+                item.storageType = Item::StorageTypeFilename;
+                RefPtr<WebCore::Blob> blob = originalItem->getAsFile();
+                if (blob->isFile()) {
+                    File* file = static_cast<File*>(blob.get());
+                    item.filenameData = file->path();
+                } else
+                    ASSERT_NOT_REACHED();
             } else
-                // FIXME: Currently we only handle image dragouts using the default drag handling.
-                // If we want to plumb DataTransferItemList::add(File), we'll need to add logic.
-                continue;
+                ASSERT_NOT_REACHED();
         } else
             ASSERT_NOT_REACHED();
         item.title = originalItem->title();