<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[180785] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/180785">180785</a></dd>
<dt>Author</dt> <dd>enrica@apple.com</dd>
<dt>Date</dt> <dd>2015-02-27 15:07:03 -0800 (Fri, 27 Feb 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Adding support for serializing HTMLAttachment elements.
https://bugs.webkit.org/show_bug.cgi?id=142026
Reviewed by Tim Horton.
Source/WebCore:
Test: editing/pasteboard/copy-paste-attachment.html
Adding support to serialize the attachment element
and properly handle it when converting a DOM range
to NSAttributedString.
* editing/cocoa/HTMLConverter.mm:
(HTMLConverter::_processElement):
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::appendCustomAttributes): Create new attribute
for attachment element when serializating.
(WebCore::StyledMarkupAccumulator::appendElement):
(WebCore::createFragmentFromMarkup): Remove the attribute from the attachment element
when creating the fragment.
* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::file): Added const to file() to
use it in appendCustonAttributes where the element is a const reference.
* html/HTMLAttachmentElement.h:
* html/HTMLAttributeNames.in:
LayoutTests:
* editing/pasteboard/copy-paste-attachment-expected.txt: Added.
* editing/pasteboard/copy-paste-attachment.html: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreeditingcocoaHTMLConvertermm">trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm</a></li>
<li><a href="#trunkSourceWebCoreeditingmarkupcpp">trunk/Source/WebCore/editing/markup.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLAttachmentElementcpp">trunk/Source/WebCore/html/HTMLAttachmentElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLAttachmentElementh">trunk/Source/WebCore/html/HTMLAttachmentElement.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLAttributeNamesin">trunk/Source/WebCore/html/HTMLAttributeNames.in</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestseditingpasteboardcopypasteattachmentexpectedtxt">trunk/LayoutTests/editing/pasteboard/copy-paste-attachment-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardcopypasteattachmenthtml">trunk/LayoutTests/editing/pasteboard/copy-paste-attachment.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (180784 => 180785)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-02-27 23:00:03 UTC (rev 180784)
+++ trunk/LayoutTests/ChangeLog        2015-02-27 23:07:03 UTC (rev 180785)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2015-02-27 Enrica Casucci <enrica@apple.com>
+
+ Adding support for serializing HTMLAttachment elements.
+ https://bugs.webkit.org/show_bug.cgi?id=142026
+
+ Reviewed by Tim Horton.
+
+ * editing/pasteboard/copy-paste-attachment-expected.txt: Added.
+ * editing/pasteboard/copy-paste-attachment.html: Added.
+
</ins><span class="cx"> 2015-02-27 Brady Eidson <beidson@apple.com>
</span><span class="cx">
</span><span class="cx"> Add a "block-cookies" rule to the user content filter.
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardcopypasteattachmentexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/pasteboard/copy-paste-attachment-expected.txt (0 => 180785)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/copy-paste-attachment-expected.txt         (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/copy-paste-attachment-expected.txt        2015-02-27 23:07:03 UTC (rev 180785)
</span><span class="lines">@@ -0,0 +1,14 @@
</span><ins>+These tests cutting content with one attachemnt and pasting it back
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Checking the file name for the attachment element
+PASS attachment.file.name is 'abe.png'
+Perform Cut on the entire selection followed by Paste
+Checking the file name for the pasted attachment element
+PASS attachment.file.name is 'abe.png'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+This is a paragraph with an attachment and some other text.
</ins></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardcopypasteattachmenthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/pasteboard/copy-paste-attachment.html (0 => 180785)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/copy-paste-attachment.html         (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/copy-paste-attachment.html        2015-02-27 23:07:03 UTC (rev 180785)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+<html>
+<head>
+<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<div contenteditable="true" id="test1">This is a paragraph with an attachment
+ <attachment id='attachment'></attachment> and some other text.
+</div>
+<script>
+var file;
+if (window.internals) {
+ var file = window.internals.createFile("../resources/abe.png");
+ var attachment = document.getElementById('attachment');
+ attachment.file = file;
+
+ description('These tests cutting content with one attachemnt and pasting it back');
+
+ var e = document.getElementById("test1");
+ var s = window.getSelection();
+
+ debug('Checking the file name for the attachment element');
+ shouldBe("attachment.file.name", "'abe.png'");
+ s.setPosition(e, 0);
+ document.execCommand("SelectAll");
+ document.execCommand("Cut");
+ debug('Perform Cut on the entire selection followed by Paste');
+ document.execCommand("Paste");
+ debug('Checking the file name for the pasted attachment element');
+ attachment = document.getElementById('attachment')
+ shouldBe("attachment.file.name", "'abe.png'");
+}
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (180784 => 180785)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-02-27 23:00:03 UTC (rev 180784)
+++ trunk/Source/WebCore/ChangeLog        2015-02-27 23:07:03 UTC (rev 180785)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2015-02-27 Enrica Casucci <enrica@apple.com>
+
+ Adding support for serializing HTMLAttachment elements.
+ https://bugs.webkit.org/show_bug.cgi?id=142026
+
+ Reviewed by Tim Horton.
+
+ Test: editing/pasteboard/copy-paste-attachment.html
+
+ Adding support to serialize the attachment element
+ and properly handle it when converting a DOM range
+ to NSAttributedString.
+
+ * editing/cocoa/HTMLConverter.mm:
+ (HTMLConverter::_processElement):
+ * editing/markup.cpp:
+ (WebCore::StyledMarkupAccumulator::appendCustomAttributes): Create new attribute
+ for attachment element when serializating.
+ (WebCore::StyledMarkupAccumulator::appendElement):
+ (WebCore::createFragmentFromMarkup): Remove the attribute from the attachment element
+ when creating the fragment.
+ * html/HTMLAttachmentElement.cpp:
+ (WebCore::HTMLAttachmentElement::file): Added const to file() to
+ use it in appendCustonAttributes where the element is a const reference.
+ * html/HTMLAttachmentElement.h:
+ * html/HTMLAttributeNames.in:
+
</ins><span class="cx"> 2015-02-27 Timothy Horton <timothy_horton@apple.com>
</span><span class="cx">
</span><span class="cx"> <attachment> should have an inactive style (gray in background)
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingcocoaHTMLConvertermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm (180784 => 180785)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm        2015-02-27 23:00:03 UTC (rev 180784)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm        2015-02-27 23:07:03 UTC (rev 180785)
</span><span class="lines">@@ -37,9 +37,11 @@
</span><span class="cx"> #import "DocumentLoader.h"
</span><span class="cx"> #import "Element.h"
</span><span class="cx"> #import "ElementTraversal.h"
</span><ins>+#import "File.h"
</ins><span class="cx"> #import "FontCascade.h"
</span><span class="cx"> #import "Frame.h"
</span><span class="cx"> #import "FrameLoader.h"
</span><ins>+#import "HTMLAttachmentElement.h"
</ins><span class="cx"> #import "HTMLElement.h"
</span><span class="cx"> #import "HTMLFrameElementBase.h"
</span><span class="cx"> #import "HTMLImageElement.h"
</span><span class="lines">@@ -1961,6 +1963,16 @@
</span><span class="cx"> while ([_textTables count] < [_textBlocks count] + 1)
</span><span class="cx"> _addTableForElement(nil);
</span><span class="cx"> _addTableCellForElement(&element);
</span><ins>+#if ENABLE(ATTACHMENT_ELEMENT)
+ } else if (is<HTMLAttachmentElement>(element)) {
+ HTMLAttachmentElement& attachment = downcast<HTMLAttachmentElement>(element);
+ if (attachment.file()) {
+ NSURL *url = [NSURL fileURLWithPath:attachment.file()->path()];
+ if (url)
+ _addAttachmentForElement(element, url, isBlockLevel, NO);
+ }
+ retval = NO;
+#endif
</ins><span class="cx"> } else if (element.hasTagName(imgTag)) {
</span><span class="cx"> NSString *urlString = element.getAttribute(srcAttr);
</span><span class="cx"> if (urlString && [urlString length] > 0) {
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingmarkupcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/markup.cpp (180784 => 180785)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/markup.cpp        2015-02-27 23:00:03 UTC (rev 180784)
+++ trunk/Source/WebCore/editing/markup.cpp        2015-02-27 23:07:03 UTC (rev 180785)
</span><span class="lines">@@ -41,7 +41,9 @@
</span><span class="cx"> #include "ElementIterator.h"
</span><span class="cx"> #include "ExceptionCode.h"
</span><span class="cx"> #include "ExceptionCodePlaceholder.h"
</span><ins>+#include "File.h"
</ins><span class="cx"> #include "Frame.h"
</span><ins>+#include "HTMLAttachmentElement.h"
</ins><span class="cx"> #include "HTMLBodyElement.h"
</span><span class="cx"> #include "HTMLDivElement.h"
</span><span class="cx"> #include "HTMLElement.h"
</span><span class="lines">@@ -51,6 +53,7 @@
</span><span class="cx"> #include "HTMLTextFormControlElement.h"
</span><span class="cx"> #include "URL.h"
</span><span class="cx"> #include "MarkupAccumulator.h"
</span><ins>+#include "NodeList.h"
</ins><span class="cx"> #include "Range.h"
</span><span class="cx"> #include "RenderBlock.h"
</span><span class="cx"> #include "Settings.h"
</span><span class="lines">@@ -135,6 +138,7 @@
</span><span class="cx"> String stringValueForRange(const Node&, const Range*);
</span><span class="cx">
</span><span class="cx"> void appendElement(StringBuilder& out, const Element&, bool addDisplayInline, RangeFullySelectsNode);
</span><ins>+ virtual void appendCustomAttributes(StringBuilder&, const Element&, Namespaces*) override;
</ins><span class="cx">
</span><span class="cx"> virtual void appendText(StringBuilder& out, const Text&) override;
</span><span class="cx"> virtual void appendElement(StringBuilder& out, const Element& element, Namespaces*) override
</span><span class="lines">@@ -292,11 +296,29 @@
</span><span class="cx"> return nodeValue;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void StyledMarkupAccumulator::appendCustomAttributes(StringBuilder& out, const Element&element, Namespaces* namespaces)
+{
+#if ENABLE(ATTACHMENT_ELEMENT)
+ if (!is<HTMLAttachmentElement>(element))
+ return;
+
+ const HTMLAttachmentElement& attachment = downcast<HTMLAttachmentElement>(element);
+ if (attachment.file())
+ appendAttribute(out, element, Attribute(webkitattachmentpathAttr, attachment.file()->path()), namespaces);
+#else
+ UNUSED_PARAM(out);
+ UNUSED_PARAM(element);
+ UNUSED_PARAM(namespaces);
+#endif
+}
+
</ins><span class="cx"> void StyledMarkupAccumulator::appendElement(StringBuilder& out, const Element& element, bool addDisplayInline, RangeFullySelectsNode rangeFullySelectsNode)
</span><span class="cx"> {
</span><span class="cx"> const bool documentIsHTML = element.document().isHTMLDocument();
</span><span class="cx"> appendOpenTag(out, element, 0);
</span><span class="cx">
</span><ins>+ appendCustomAttributes(out, element, nullptr);
+
</ins><span class="cx"> const bool shouldAnnotateOrForceInline = element.isHTMLElement() && (shouldAnnotate() || addDisplayInline);
</span><span class="cx"> const bool shouldOverrideStyleAttr = shouldAnnotateOrForceInline || shouldApplyWrappingStyle(element);
</span><span class="cx"> if (element.hasAttributes()) {
</span><span class="lines">@@ -658,6 +680,17 @@
</span><span class="cx">
</span><span class="cx"> fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy);
</span><span class="cx">
</span><ins>+#if ENABLE(ATTACHMENT_ELEMENT)
+ // When creating a fragment we must strip the webkit-attachment-path attribute after restoring the File object.
+ RefPtr<NodeList> nodes = fragment->getElementsByTagName("attachment");
+ for (size_t i = 0; i < nodes->length(); ++i) {
+ if (!is<HTMLAttachmentElement>(*nodes->item(i)))
+ continue;
+ HTMLAttachmentElement& element = downcast<HTMLAttachmentElement>(*nodes->item(i));
+ element.setFile(File::create(element.fastGetAttribute(webkitattachmentpathAttr)).ptr());
+ element.removeAttribute(webkitattachmentpathAttr);
+ }
+#endif
</ins><span class="cx"> if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseURL())
</span><span class="cx"> completeURLs(fragment.get(), baseURL);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLAttachmentElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.cpp (180784 => 180785)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLAttachmentElement.cpp        2015-02-27 23:00:03 UTC (rev 180784)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.cpp        2015-02-27 23:07:03 UTC (rev 180785)
</span><span class="lines">@@ -56,7 +56,7 @@
</span><span class="cx"> return createRenderer<RenderAttachment>(*this, WTF::move(style));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-File* HTMLAttachmentElement::file()
</del><ins>+File* HTMLAttachmentElement::file() const
</ins><span class="cx"> {
</span><span class="cx"> return m_file.get();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLAttachmentElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.h (180784 => 180785)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLAttachmentElement.h        2015-02-27 23:00:03 UTC (rev 180784)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.h        2015-02-27 23:07:03 UTC (rev 180785)
</span><span class="lines">@@ -37,8 +37,8 @@
</span><span class="cx"> class HTMLAttachmentElement final : public HTMLElement {
</span><span class="cx"> public:
</span><span class="cx"> static Ref<HTMLAttachmentElement> create(const QualifiedName&, Document&);
</span><del>-
- File* file();
</del><ins>+ virtual bool canContainRangeEndPoint() const override { return false; }
+ File* file() const;
</ins><span class="cx"> void setFile(File*);
</span><span class="cx">
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLAttributeNamesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLAttributeNames.in (180784 => 180785)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLAttributeNames.in        2015-02-27 23:00:03 UTC (rev 180784)
+++ trunk/Source/WebCore/html/HTMLAttributeNames.in        2015-02-27 23:07:03 UTC (rev 180785)
</span><span class="lines">@@ -349,6 +349,7 @@
</span><span class="cx"> vlink
</span><span class="cx"> vspace
</span><span class="cx"> webkitallowfullscreen
</span><ins>+webkitattachmentpath
</ins><span class="cx"> width
</span><span class="cx"> wrap
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>