<attachment>s should be created when dropping files onto contentEditable areas
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Mar 2015 18:21:05 +0000 (18:21 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Mar 2015 18:21:05 +0000 (18:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142494
<rdar://problem/19982553>

Reviewed by Anders Carlsson.

Covered by existing tests.

* editing/mac/EditorMac.mm:
(WebCore::Editor::WebContentReader::readFilenames):
Instead of inserting the dropped URLs as strings, make an <attachment>
for each.

* editing/pasteboard/drag-files-to-editable-element-expected.txt:
* editing/pasteboard/drag-files-to-editable-element.html:
Update the test to expect <attachment>s instead of filenames.

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

LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/drag-files-to-editable-element-expected.txt
LayoutTests/editing/pasteboard/drag-files-to-editable-element.html
Source/WebCore/ChangeLog
Source/WebCore/editing/mac/EditorMac.mm

index 0c6dbc3..9206a35 100644 (file)
@@ -1,3 +1,15 @@
+2015-03-11  Tim Horton  <timothy_horton@apple.com>
+
+        <attachment>s should be created when dropping files onto contentEditable areas
+        https://bugs.webkit.org/show_bug.cgi?id=142494
+        <rdar://problem/19982553>
+
+        Reviewed by Anders Carlsson.
+
+        * editing/pasteboard/drag-files-to-editable-element-expected.txt:
+        * editing/pasteboard/drag-files-to-editable-element.html:
+        Update the test to expect <attachment>s instead of filenames.
+
 2015-03-11  David Hyatt  <hyatt@apple.com>
 
         Optimize offsetWidth and offsetHeight to avoid doing layouts.
index 515d15a..89befb0 100644 (file)
@@ -1,9 +1,12 @@
-If we drag files onto an editable area, then the filenames should be inserted into the editable area.
+If we drag files onto an editable area, then attachments should be inserted into the editable area.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS result is "<div>LayoutTests/editing/pasteboard/foo</div><div>LayoutTests/editing/pasteboard/bar</div><div>LayoutTests/editing/pasteboard/baz</div>"
+PASS attachment.nodeName is "ATTACHMENT"
+PASS attachment.nodeName is "ATTACHMENT"
+PASS attachment.nodeName is "ATTACHMENT"
+PASS fileNames is "foo bar baz "
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 395e02d..8c845e1 100644 (file)
@@ -7,13 +7,19 @@
 <div id="console"></div>
 <div id="editable" contentEditable=true style="width:200px; height:200px"></div>
 <script>
-description('If we drag files onto an editable area, then the filenames should be inserted into the editable area.');
+description('If we drag files onto an editable area, then attachments should be inserted into the editable area.');
 
 var editable = document.getElementById("editable");
 if (window.eventSender) {
     dragFilesOntoEditable(['foo', 'bar', 'baz']);
-    var result = editable.innerHTML.replace(/file.*?LayoutTests/g, "LayoutTests");
-    shouldBeEqualToString('result', '<div>LayoutTests/editing/pasteboard/foo</div><div>LayoutTests/editing/pasteboard/bar</div><div>LayoutTests/editing/pasteboard/baz</div>');
+    var resultChildren = editable.children;
+    var fileNames = "";
+    for (var i = 0; i < resultChildren.length; i++) {
+        var attachment = resultChildren[i];
+        shouldBeEqualToString('attachment.nodeName', 'ATTACHMENT');
+        fileNames += attachment.file.name + " ";
+    }
+    shouldBeEqualToString('fileNames', 'foo bar baz ');
     editable.innerHTML = '';
 }
 
index 709e691..e726848 100644 (file)
@@ -1,3 +1,18 @@
+2015-03-11  Timothy Horton  <timothy_horton@apple.com>
+
+        <attachment>s should be created when dropping files onto contentEditable areas
+        https://bugs.webkit.org/show_bug.cgi?id=142494
+        <rdar://problem/19982553>
+
+        Reviewed by Anders Carlsson.
+
+        Covered by existing tests.
+
+        * editing/mac/EditorMac.mm:
+        (WebCore::Editor::WebContentReader::readFilenames):
+        Instead of inserting the dropped URLs as strings, make an <attachment>
+        for each.
+
 2015-03-11  David Hyatt  <hyatt@apple.com>
 
         Optimize offsetWidth and offsetHeight to avoid doing layouts.
index 0f0a849..5af3f38 100644 (file)
 #import "DocumentLoader.h"
 #import "Editor.h"
 #import "EditorClient.h"
+#import "File.h"
 #import "FontCascade.h"
 #import "Frame.h"
 #import "FrameLoaderClient.h"
 #import "FrameView.h"
+#import "HTMLAttachmentElement.h"
 #import "HTMLConverter.h"
 #import "HTMLElement.h"
 #import "HTMLNames.h"
@@ -529,11 +531,17 @@ bool Editor::WebContentReader::readFilenames(const Vector<String>& paths)
 
     for (size_t i = 0; i < size; i++) {
         String text = paths[i];
+#if ENABLE(ATTACHMENT_ELEMENT)
+        RefPtr<HTMLAttachmentElement> attachment = HTMLAttachmentElement::create(attachmentTag, document);
+        attachment->setFile(File::create([[NSURL fileURLWithPath:text] path]).ptr());
+        fragment->appendChild(attachment.release());
+#else
         text = frame.editor().client()->userVisibleString([NSURL fileURLWithPath:text]);
 
         RefPtr<HTMLElement> paragraph = createDefaultParagraphElement(document);
         paragraph->appendChild(document.createTextNode(text));
         fragment->appendChild(paragraph.release());
+#endif
     }
 
     return true;