<!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>[245780] branches/safari-608.1.24.20-branch</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/245780">245780</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2019-05-26 11:21:44 -0700 (Sun, 26 May 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/245775">r245775</a>. rdar://problem/35205373

    [iOS] Respect -[NSItemProvider preferredPresentationSize] when dropping images
    https://bugs.webkit.org/show_bug.cgi?id=198242

    Reviewed by Beth Dakin.

    Source/WebCore:

    Teach the web content reader to respect the -preferredPresentationSize when creating attachment-backed image
    elements. See below for more details.

    Test: WKAttachmentTestsIOS.InsertDroppedImageWithPreferredPresentationSize

    * editing/WebContentReader.h:
    * editing/cocoa/WebContentReaderCocoa.mm:
    (WebCore::attachmentForFilePath):
    (WebCore::attachmentForData):

    When creating attachment-backed image elements, additionally set width and height attributes from the preferred
    presentation size, if specified.

    (WebCore::WebContentReader::readFilePath):

    Add a version of readFilePath that takes a single file path, and an optional preferred presentation size.

    (WebCore::WebContentReader::readFilePaths):

    Reimplement readFilePaths in terms of readFilePath.

    (WebCore::WebContentReader::readDataBuffer):

    Add more plumbing for preferredPresentationSize.

    * platform/Pasteboard.h:
    (WebCore::PasteboardWebContentReader::readFilePath):
    (WebCore::PasteboardWebContentReader::readDataBuffer):
    * platform/ios/PasteboardIOS.mm:
    (WebCore::Pasteboard::read):
    (WebCore::Pasteboard::readRespectingUTIFidelities):

    Forward PasteboardItemInfo's preferredPresentationSize to the web content reader.

    Tools:

    Add a new test that simulates dropping an image with a preferred presentation size into an editable element
    with attachment elements enabled.

    * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
    (TestWebKitAPI::TEST):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245775 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari60812420branchSourceWebCoreChangeLog">branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari60812420branchSourceWebCoreeditingWebContentReaderh">branches/safari-608.1.24.20-branch/Source/WebCore/editing/WebContentReader.h</a></li>
<li><a href="#branchessafari60812420branchSourceWebCoreeditingcocoaWebContentReaderCocoamm">branches/safari-608.1.24.20-branch/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm</a></li>
<li><a href="#branchessafari60812420branchSourceWebCoreplatformPasteboardh">branches/safari-608.1.24.20-branch/Source/WebCore/platform/Pasteboard.h</a></li>
<li><a href="#branchessafari60812420branchSourceWebCoreplatformiosPasteboardIOSmm">branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PasteboardIOS.mm</a></li>
<li><a href="#branchessafari60812420branchToolsChangeLog">branches/safari-608.1.24.20-branch/Tools/ChangeLog</a></li>
<li><a href="#branchessafari60812420branchToolsTestWebKitAPITestsWebKitCocoaWKAttachmentTestsmm">branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari60812420branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog (245779 => 245780)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog      2019-05-26 14:04:13 UTC (rev 245779)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog 2019-05-26 18:21:44 UTC (rev 245780)
</span><span class="lines">@@ -1,3 +1,100 @@
</span><ins>+2019-05-26  Babak Shafiei  <bshafiei@apple.com>
+
+        Cherry-pick r245775. rdar://problem/35205373
+
+    [iOS] Respect -[NSItemProvider preferredPresentationSize] when dropping images
+    https://bugs.webkit.org/show_bug.cgi?id=198242
+    
+    Reviewed by Beth Dakin.
+    
+    Source/WebCore:
+    
+    Teach the web content reader to respect the -preferredPresentationSize when creating attachment-backed image
+    elements. See below for more details.
+    
+    Test: WKAttachmentTestsIOS.InsertDroppedImageWithPreferredPresentationSize
+    
+    * editing/WebContentReader.h:
+    * editing/cocoa/WebContentReaderCocoa.mm:
+    (WebCore::attachmentForFilePath):
+    (WebCore::attachmentForData):
+    
+    When creating attachment-backed image elements, additionally set width and height attributes from the preferred
+    presentation size, if specified.
+    
+    (WebCore::WebContentReader::readFilePath):
+    
+    Add a version of readFilePath that takes a single file path, and an optional preferred presentation size.
+    
+    (WebCore::WebContentReader::readFilePaths):
+    
+    Reimplement readFilePaths in terms of readFilePath.
+    
+    (WebCore::WebContentReader::readDataBuffer):
+    
+    Add more plumbing for preferredPresentationSize.
+    
+    * platform/Pasteboard.h:
+    (WebCore::PasteboardWebContentReader::readFilePath):
+    (WebCore::PasteboardWebContentReader::readDataBuffer):
+    * platform/ios/PasteboardIOS.mm:
+    (WebCore::Pasteboard::read):
+    (WebCore::Pasteboard::readRespectingUTIFidelities):
+    
+    Forward PasteboardItemInfo's preferredPresentationSize to the web content reader.
+    
+    Tools:
+    
+    Add a new test that simulates dropping an image with a preferred presentation size into an editable element
+    with attachment elements enabled.
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+    (TestWebKitAPI::TEST):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245775 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-05-25  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+            [iOS] Respect -[NSItemProvider preferredPresentationSize] when dropping images
+            https://bugs.webkit.org/show_bug.cgi?id=198242
+
+            Reviewed by Beth Dakin.
+
+            Teach the web content reader to respect the -preferredPresentationSize when creating attachment-backed image
+            elements. See below for more details.
+
+            Test: WKAttachmentTestsIOS.InsertDroppedImageWithPreferredPresentationSize
+
+            * editing/WebContentReader.h:
+            * editing/cocoa/WebContentReaderCocoa.mm:
+            (WebCore::attachmentForFilePath):
+            (WebCore::attachmentForData):
+
+            When creating attachment-backed image elements, additionally set width and height attributes from the preferred
+            presentation size, if specified.
+
+            (WebCore::WebContentReader::readFilePath):
+
+            Add a version of readFilePath that takes a single file path, and an optional preferred presentation size.
+
+            (WebCore::WebContentReader::readFilePaths):
+
+            Reimplement readFilePaths in terms of readFilePath.
+
+            (WebCore::WebContentReader::readDataBuffer):
+
+            Add more plumbing for preferredPresentationSize.
+
+            * platform/Pasteboard.h:
+            (WebCore::PasteboardWebContentReader::readFilePath):
+            (WebCore::PasteboardWebContentReader::readDataBuffer):
+            * platform/ios/PasteboardIOS.mm:
+            (WebCore::Pasteboard::read):
+            (WebCore::Pasteboard::readRespectingUTIFidelities):
+
+            Forward PasteboardItemInfo's preferredPresentationSize to the web content reader.
+
</ins><span class="cx"> 2019-05-24  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Cherry-pick r245753. rdar://problem/51068494
</span></span></pre></div>
<a id="branchessafari60812420branchSourceWebCoreeditingWebContentReaderh"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Source/WebCore/editing/WebContentReader.h (245779 => 245780)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Source/WebCore/editing/WebContentReader.h     2019-05-26 14:04:13 UTC (rev 245779)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/editing/WebContentReader.h        2019-05-26 18:21:44 UTC (rev 245780)
</span><span class="lines">@@ -71,6 +71,7 @@
</span><span class="cx"> private:
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     bool readWebArchive(SharedBuffer&) override;
</span><ins>+    bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }) override;
</ins><span class="cx">     bool readFilePaths(const Vector<String>&) override;
</span><span class="cx">     bool readHTML(const String&) override;
</span><span class="cx">     bool readRTFD(SharedBuffer&) override;
</span><span class="lines">@@ -77,7 +78,7 @@
</span><span class="cx">     bool readRTF(SharedBuffer&) override;
</span><span class="cx">     bool readImage(Ref<SharedBuffer>&&, const String& type) override;
</span><span class="cx">     bool readURL(const URL&, const String& title) override;
</span><del>-    bool readDataBuffer(SharedBuffer&, const String& type, const String& name) override;
</del><ins>+    bool readDataBuffer(SharedBuffer&, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize = { }) override;
</ins><span class="cx"> #endif
</span><span class="cx">     bool readPlainText(const String&) override;
</span><span class="cx"> };
</span><span class="lines">@@ -94,6 +95,7 @@
</span><span class="cx"> private:
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     bool readWebArchive(SharedBuffer&) override;
</span><ins>+    bool readFilePath(const String&, Optional<FloatSize> = { }) override { return false; }
</ins><span class="cx">     bool readFilePaths(const Vector<String>&) override { return false; }
</span><span class="cx">     bool readHTML(const String&) override;
</span><span class="cx">     bool readRTFD(SharedBuffer&) override;
</span><span class="lines">@@ -100,7 +102,7 @@
</span><span class="cx">     bool readRTF(SharedBuffer&) override;
</span><span class="cx">     bool readImage(Ref<SharedBuffer>&&, const String&) override { return false; }
</span><span class="cx">     bool readURL(const URL&, const String&) override { return false; }
</span><del>-    bool readDataBuffer(SharedBuffer&, const String&, const String&) override { return false; }
</del><ins>+    bool readDataBuffer(SharedBuffer&, const String&, const String&, Optional<FloatSize> = { }) override { return false; }
</ins><span class="cx"> #endif
</span><span class="cx">     bool readPlainText(const String&) override { return false; }
</span><span class="cx"> };
</span></span></pre></div>
<a id="branchessafari60812420branchSourceWebCoreeditingcocoaWebContentReaderCocoamm"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (245779 => 245780)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm 2019-05-26 14:04:13 UTC (rev 245779)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm    2019-05-26 18:21:44 UTC (rev 245780)
</span><span class="lines">@@ -690,7 +690,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx"> 
</span><del>-static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path)
</del><ins>+static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, Optional<FloatSize> preferredSize)
</ins><span class="cx"> {
</span><span class="cx">     auto document = makeRef(*frame.document());
</span><span class="cx">     auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
</span><span class="lines">@@ -718,6 +718,10 @@
</span><span class="cx">         auto image = HTMLImageElement::create(document);
</span><span class="cx">         image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(path)));
</span><span class="cx">         image->setAttachmentElement(WTFMove(attachment));
</span><ins>+        if (preferredSize) {
+            image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width()));
+            image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height()));
+        }
</ins><span class="cx">         return image;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -725,7 +729,7 @@
</span><span class="cx">     return attachment;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name)
</del><ins>+static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name, Optional<FloatSize> preferredSize)
</ins><span class="cx"> {
</span><span class="cx">     auto document = makeRef(*frame.document());
</span><span class="cx">     auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
</span><span class="lines">@@ -752,6 +756,10 @@
</span><span class="cx">         auto image = HTMLImageElement::create(document);
</span><span class="cx">         image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(Blob::create(buffer, WTFMove(typeForAttachmentElement)), WTFMove(fileName))));
</span><span class="cx">         image->setAttachmentElement(WTFMove(attachment));
</span><ins>+        if (preferredSize) {
+            image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width()));
+            image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height()));
+        }
</ins><span class="cx">         return image;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -761,9 +769,9 @@
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx"> 
</span><del>-bool WebContentReader::readFilePaths(const Vector<String>& paths)
</del><ins>+bool WebContentReader::readFilePath(const String& path, Optional<FloatSize> preferredPresentationSize)
</ins><span class="cx"> {
</span><del>-    if (paths.isEmpty() || !frame.document())
</del><ins>+    if (path.isEmpty() || !frame.document())
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     auto& document = *frame.document();
</span><span class="lines">@@ -771,15 +779,24 @@
</span><span class="cx">         fragment = document.createDocumentFragment();
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><del>-    if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) {
-        for (auto& path : paths)
-            fragment->appendChild(attachmentForFilePath(frame, path));
-    }
</del><ins>+    if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled())
+        fragment->appendChild(attachmentForFilePath(frame, path, preferredPresentationSize));
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool WebContentReader::readFilePaths(const Vector<String>& paths)
+{
+    if (paths.isEmpty() || !frame.document())
+        return false;
+
+    for (auto& path : paths)
+        readFilePath(path);
+
+    return true;
+}
+
</ins><span class="cx"> bool WebContentReader::readURL(const URL& url, const String& title)
</span><span class="cx"> {
</span><span class="cx">     if (url.isEmpty())
</span><span class="lines">@@ -811,7 +828,7 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name)
</del><ins>+bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize)
</ins><span class="cx"> {
</span><span class="cx">     if (buffer.isEmpty())
</span><span class="cx">         return false;
</span><span class="lines">@@ -827,7 +844,7 @@
</span><span class="cx">         fragment = document->createDocumentFragment();
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><del>-    fragment->appendChild(attachmentForData(frame, buffer, type, name));
</del><ins>+    fragment->appendChild(attachmentForData(frame, buffer, type, name, preferredPresentationSize));
</ins><span class="cx"> #else
</span><span class="cx">     UNUSED_PARAM(type);
</span><span class="cx">     UNUSED_PARAM(name);
</span></span></pre></div>
<a id="branchessafari60812420branchSourceWebCoreplatformPasteboardh"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Source/WebCore/platform/Pasteboard.h (245779 => 245780)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Source/WebCore/platform/Pasteboard.h  2019-05-26 14:04:13 UTC (rev 245779)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/platform/Pasteboard.h     2019-05-26 18:21:44 UTC (rev 245780)
</span><span class="lines">@@ -136,6 +136,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     virtual bool readWebArchive(SharedBuffer&) = 0;
</span><ins>+    virtual bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }) = 0;
</ins><span class="cx">     virtual bool readFilePaths(const Vector<String>&) = 0;
</span><span class="cx">     virtual bool readHTML(const String&) = 0;
</span><span class="cx">     virtual bool readRTFD(SharedBuffer&) = 0;
</span><span class="lines">@@ -142,7 +143,7 @@
</span><span class="cx">     virtual bool readRTF(SharedBuffer&) = 0;
</span><span class="cx">     virtual bool readImage(Ref<SharedBuffer>&&, const String& type) = 0;
</span><span class="cx">     virtual bool readURL(const URL&, const String& title) = 0;
</span><del>-    virtual bool readDataBuffer(SharedBuffer&, const String& type, const String& name) = 0;
</del><ins>+    virtual bool readDataBuffer(SharedBuffer&, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize = { }) = 0;
</ins><span class="cx"> #endif
</span><span class="cx">     virtual bool readPlainText(const String&) = 0;
</span><span class="cx"> };
</span></span></pre></div>
<a id="branchessafari60812420branchSourceWebCoreplatformiosPasteboardIOSmm"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PasteboardIOS.mm (245779 => 245780)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PasteboardIOS.mm  2019-05-26 14:04:13 UTC (rev 245779)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PasteboardIOS.mm     2019-05-26 18:21:44 UTC (rev 245780)
</span><span class="lines">@@ -307,7 +307,7 @@
</span><span class="cx">             auto typeForFileUpload = info.contentTypeForHighestFidelityItem();
</span><span class="cx">             if (auto buffer = strategy.readBufferFromPasteboard(i, typeForFileUpload, m_pasteboardName)) {
</span><span class="cx">                 readURLAlongsideAttachmentIfNecessary(reader, strategy, typeForFileUpload, m_pasteboardName, i);
</span><del>-                reader.readDataBuffer(*buffer, typeForFileUpload, info.suggestedFileName);
</del><ins>+                reader.readDataBuffer(*buffer, typeForFileUpload, info.suggestedFileName, info.preferredPresentationSize);
</ins><span class="cx">                 continue;
</span><span class="cx">             }
</span><span class="cx">         }
</span><span class="lines">@@ -347,7 +347,7 @@
</span><span class="cx">         bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !attachmentFilePath.isEmpty();
</span><span class="cx">         if (canReadAttachment && prefersAttachmentRepresentation(info)) {
</span><span class="cx">             readURLAlongsideAttachmentIfNecessary(reader, strategy, info.contentTypeForHighestFidelityItem(), m_pasteboardName, index);
</span><del>-            reader.readFilePaths({ WTFMove(attachmentFilePath) });
</del><ins>+            reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize);
</ins><span class="cx">             continue;
</span><span class="cx">         }
</span><span class="cx"> #endif
</span><span class="lines">@@ -366,7 +366,7 @@
</span><span class="cx">         }
</span><span class="cx"> #if ENABLE(ATTACHMENT_ELEMENT)
</span><span class="cx">         if (canReadAttachment && result == ReaderResult::DidNotReadType)
</span><del>-            reader.readFilePaths({ WTFMove(attachmentFilePath) });
</del><ins>+            reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize);
</ins><span class="cx"> #endif
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari60812420branchToolsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Tools/ChangeLog (245779 => 245780)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Tools/ChangeLog       2019-05-26 14:04:13 UTC (rev 245779)
+++ branches/safari-608.1.24.20-branch/Tools/ChangeLog  2019-05-26 18:21:44 UTC (rev 245780)
</span><span class="lines">@@ -1,3 +1,72 @@
</span><ins>+2019-05-26  Babak Shafiei  <bshafiei@apple.com>
+
+        Cherry-pick r245775. rdar://problem/35205373
+
+    [iOS] Respect -[NSItemProvider preferredPresentationSize] when dropping images
+    https://bugs.webkit.org/show_bug.cgi?id=198242
+    
+    Reviewed by Beth Dakin.
+    
+    Source/WebCore:
+    
+    Teach the web content reader to respect the -preferredPresentationSize when creating attachment-backed image
+    elements. See below for more details.
+    
+    Test: WKAttachmentTestsIOS.InsertDroppedImageWithPreferredPresentationSize
+    
+    * editing/WebContentReader.h:
+    * editing/cocoa/WebContentReaderCocoa.mm:
+    (WebCore::attachmentForFilePath):
+    (WebCore::attachmentForData):
+    
+    When creating attachment-backed image elements, additionally set width and height attributes from the preferred
+    presentation size, if specified.
+    
+    (WebCore::WebContentReader::readFilePath):
+    
+    Add a version of readFilePath that takes a single file path, and an optional preferred presentation size.
+    
+    (WebCore::WebContentReader::readFilePaths):
+    
+    Reimplement readFilePaths in terms of readFilePath.
+    
+    (WebCore::WebContentReader::readDataBuffer):
+    
+    Add more plumbing for preferredPresentationSize.
+    
+    * platform/Pasteboard.h:
+    (WebCore::PasteboardWebContentReader::readFilePath):
+    (WebCore::PasteboardWebContentReader::readDataBuffer):
+    * platform/ios/PasteboardIOS.mm:
+    (WebCore::Pasteboard::read):
+    (WebCore::Pasteboard::readRespectingUTIFidelities):
+    
+    Forward PasteboardItemInfo's preferredPresentationSize to the web content reader.
+    
+    Tools:
+    
+    Add a new test that simulates dropping an image with a preferred presentation size into an editable element
+    with attachment elements enabled.
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+    (TestWebKitAPI::TEST):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245775 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-05-25  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+            [iOS] Respect -[NSItemProvider preferredPresentationSize] when dropping images
+            https://bugs.webkit.org/show_bug.cgi?id=198242
+
+            Reviewed by Beth Dakin.
+
+            Add a new test that simulates dropping an image with a preferred presentation size into an editable element
+            with attachment elements enabled.
+
+            * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+            (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2019-05-22  Ryan Haddad  <ryanhaddad@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Land workaround for rdar://problem/51031394.
</span></span></pre></div>
<a id="branchessafari60812420branchToolsTestWebKitAPITestsWebKitCocoaWKAttachmentTestsmm"></a>
<div class="modfile"><h4>Modified: branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (245779 => 245780)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm    2019-05-26 14:04:13 UTC (rev 245779)
+++ branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm       2019-05-26 18:21:44 UTC (rev 245780)
</span><span class="lines">@@ -1631,6 +1631,21 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+TEST(WKAttachmentTestsIOS, InsertDroppedImageWithPreferredPresentationSize)
+{
+    auto webView = webViewForTestingAttachments();
+    auto dragAndDropSimulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]);
+    auto item = adoptNS([[NSItemProvider alloc] init]);
+    [item registerData:testImageData() type:(__bridge NSString *)kUTTypePNG];
+    [item setPreferredPresentationSize:CGSizeMake(200, 100)];
+    [dragAndDropSimulator setExternalItemProviders:@[ item.get() ]];
+    [dragAndDropSimulator runFrom:CGPointZero to:CGPointMake(50, 50)];
+
+    CGSize imageElementSize = [webView imageElementSize];
+    EXPECT_EQ(200, imageElementSize.width);
+    EXPECT_EQ(100, imageElementSize.height);
+}
+
</ins><span class="cx"> TEST(WKAttachmentTestsIOS, InsertDroppedAttributedStringContainingAttachment)
</span><span class="cx"> {
</span><span class="cx">     auto webView = webViewForTestingAttachments();
</span></span></pre>
</div>
</div>

</body>
</html>