Diff
Modified: branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog (245779 => 245780)
--- 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)
@@ -1,3 +1,100 @@
+2019-05-26 Babak Shafiei <[email protected]>
+
+ 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 <[email protected]>
+
+ [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.
+
2019-05-24 Alan Coon <[email protected]>
Cherry-pick r245753. rdar://problem/51068494
Modified: branches/safari-608.1.24.20-branch/Source/WebCore/editing/WebContentReader.h (245779 => 245780)
--- 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)
@@ -71,6 +71,7 @@
private:
#if PLATFORM(COCOA)
bool readWebArchive(SharedBuffer&) override;
+ bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }) override;
bool readFilePaths(const Vector<String>&) override;
bool readHTML(const String&) override;
bool readRTFD(SharedBuffer&) override;
@@ -77,7 +78,7 @@
bool readRTF(SharedBuffer&) override;
bool readImage(Ref<SharedBuffer>&&, const String& type) override;
bool readURL(const URL&, const String& title) override;
- bool readDataBuffer(SharedBuffer&, const String& type, const String& name) override;
+ bool readDataBuffer(SharedBuffer&, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize = { }) override;
#endif
bool readPlainText(const String&) override;
};
@@ -94,6 +95,7 @@
private:
#if PLATFORM(COCOA)
bool readWebArchive(SharedBuffer&) override;
+ bool readFilePath(const String&, Optional<FloatSize> = { }) override { return false; }
bool readFilePaths(const Vector<String>&) override { return false; }
bool readHTML(const String&) override;
bool readRTFD(SharedBuffer&) override;
@@ -100,7 +102,7 @@
bool readRTF(SharedBuffer&) override;
bool readImage(Ref<SharedBuffer>&&, const String&) override { return false; }
bool readURL(const URL&, const String&) override { return false; }
- bool readDataBuffer(SharedBuffer&, const String&, const String&) override { return false; }
+ bool readDataBuffer(SharedBuffer&, const String&, const String&, Optional<FloatSize> = { }) override { return false; }
#endif
bool readPlainText(const String&) override { return false; }
};
Modified: branches/safari-608.1.24.20-branch/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (245779 => 245780)
--- 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)
@@ -690,7 +690,7 @@
#if ENABLE(ATTACHMENT_ELEMENT)
-static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path)
+static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, Optional<FloatSize> preferredSize)
{
auto document = makeRef(*frame.document());
auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
@@ -718,6 +718,10 @@
auto image = HTMLImageElement::create(document);
image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(path)));
image->setAttachmentElement(WTFMove(attachment));
+ if (preferredSize) {
+ image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width()));
+ image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height()));
+ }
return image;
}
@@ -725,7 +729,7 @@
return attachment;
}
-static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name)
+static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name, Optional<FloatSize> preferredSize)
{
auto document = makeRef(*frame.document());
auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
@@ -752,6 +756,10 @@
auto image = HTMLImageElement::create(document);
image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(Blob::create(buffer, WTFMove(typeForAttachmentElement)), WTFMove(fileName))));
image->setAttachmentElement(WTFMove(attachment));
+ if (preferredSize) {
+ image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width()));
+ image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height()));
+ }
return image;
}
@@ -761,9 +769,9 @@
#endif // ENABLE(ATTACHMENT_ELEMENT)
-bool WebContentReader::readFilePaths(const Vector<String>& paths)
+bool WebContentReader::readFilePath(const String& path, Optional<FloatSize> preferredPresentationSize)
{
- if (paths.isEmpty() || !frame.document())
+ if (path.isEmpty() || !frame.document())
return false;
auto& document = *frame.document();
@@ -771,15 +779,24 @@
fragment = document.createDocumentFragment();
#if ENABLE(ATTACHMENT_ELEMENT)
- if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) {
- for (auto& path : paths)
- fragment->appendChild(attachmentForFilePath(frame, path));
- }
+ if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled())
+ fragment->appendChild(attachmentForFilePath(frame, path, preferredPresentationSize));
#endif
return true;
}
+bool WebContentReader::readFilePaths(const Vector<String>& paths)
+{
+ if (paths.isEmpty() || !frame.document())
+ return false;
+
+ for (auto& path : paths)
+ readFilePath(path);
+
+ return true;
+}
+
bool WebContentReader::readURL(const URL& url, const String& title)
{
if (url.isEmpty())
@@ -811,7 +828,7 @@
return true;
}
-bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name)
+bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize)
{
if (buffer.isEmpty())
return false;
@@ -827,7 +844,7 @@
fragment = document->createDocumentFragment();
#if ENABLE(ATTACHMENT_ELEMENT)
- fragment->appendChild(attachmentForData(frame, buffer, type, name));
+ fragment->appendChild(attachmentForData(frame, buffer, type, name, preferredPresentationSize));
#else
UNUSED_PARAM(type);
UNUSED_PARAM(name);
Modified: branches/safari-608.1.24.20-branch/Source/WebCore/platform/Pasteboard.h (245779 => 245780)
--- 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)
@@ -136,6 +136,7 @@
#if PLATFORM(COCOA)
virtual bool readWebArchive(SharedBuffer&) = 0;
+ virtual bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }) = 0;
virtual bool readFilePaths(const Vector<String>&) = 0;
virtual bool readHTML(const String&) = 0;
virtual bool readRTFD(SharedBuffer&) = 0;
@@ -142,7 +143,7 @@
virtual bool readRTF(SharedBuffer&) = 0;
virtual bool readImage(Ref<SharedBuffer>&&, const String& type) = 0;
virtual bool readURL(const URL&, const String& title) = 0;
- virtual bool readDataBuffer(SharedBuffer&, const String& type, const String& name) = 0;
+ virtual bool readDataBuffer(SharedBuffer&, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize = { }) = 0;
#endif
virtual bool readPlainText(const String&) = 0;
};
Modified: branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PasteboardIOS.mm (245779 => 245780)
--- 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)
@@ -307,7 +307,7 @@
auto typeForFileUpload = info.contentTypeForHighestFidelityItem();
if (auto buffer = strategy.readBufferFromPasteboard(i, typeForFileUpload, m_pasteboardName)) {
readURLAlongsideAttachmentIfNecessary(reader, strategy, typeForFileUpload, m_pasteboardName, i);
- reader.readDataBuffer(*buffer, typeForFileUpload, info.suggestedFileName);
+ reader.readDataBuffer(*buffer, typeForFileUpload, info.suggestedFileName, info.preferredPresentationSize);
continue;
}
}
@@ -347,7 +347,7 @@
bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !attachmentFilePath.isEmpty();
if (canReadAttachment && prefersAttachmentRepresentation(info)) {
readURLAlongsideAttachmentIfNecessary(reader, strategy, info.contentTypeForHighestFidelityItem(), m_pasteboardName, index);
- reader.readFilePaths({ WTFMove(attachmentFilePath) });
+ reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize);
continue;
}
#endif
@@ -366,7 +366,7 @@
}
#if ENABLE(ATTACHMENT_ELEMENT)
if (canReadAttachment && result == ReaderResult::DidNotReadType)
- reader.readFilePaths({ WTFMove(attachmentFilePath) });
+ reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize);
#endif
}
}
Modified: branches/safari-608.1.24.20-branch/Tools/ChangeLog (245779 => 245780)
--- 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)
@@ -1,3 +1,72 @@
+2019-05-26 Babak Shafiei <[email protected]>
+
+ 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 <[email protected]>
+
+ [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):
+
2019-05-22 Ryan Haddad <[email protected]>
Land workaround for rdar://problem/51031394.
Modified: branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (245779 => 245780)
--- 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)
@@ -1631,6 +1631,21 @@
}
}
+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);
+}
+
TEST(WKAttachmentTestsIOS, InsertDroppedAttributedStringContainingAttachment)
{
auto webView = webViewForTestingAttachments();