WebKit Bugzilla
Attachment 370622 Details for
Bug 198242
: [iOS] Respect -[NSItemProvider preferredPresentationSize] when dropping images
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-198242-20190524222215.patch (text/plain), 14.12 KB, created by
Wenson Hsieh
on 2019-05-24 22:22:16 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2019-05-24 22:22:16 PDT
Size:
14.12 KB
patch
obsolete
>Subversion Revision: 245751 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 572b81f7e6e7e17c52c71e8ba9c38fe7d763630e..eb2cc42118d96c9cb4c4c92e6961280e9de67e35 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,44 @@ >+2019-05-24 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [iOS] Respect -[NSItemProvider preferredPresentationSize] when dropping images >+ https://bugs.webkit.org/show_bug.cgi?id=198242 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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 Youenn Fablet <youenn@apple.com> > > Make sure completion handler is always called in SWServer::startSuspension >diff --git a/Source/WebCore/editing/WebContentReader.h b/Source/WebCore/editing/WebContentReader.h >index 30c08ce43c1abc022477b2ae9b3370d41253f64a..9c9641029d6123445cfe58e6e570e28370962501 100644 >--- a/Source/WebCore/editing/WebContentReader.h >+++ b/Source/WebCore/editing/WebContentReader.h >@@ -71,13 +71,14 @@ public: > 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; > bool readRTF(SharedBuffer&) override; > bool readImage(Ref<SharedBuffer>&&, const String& type, Optional<FloatSize> preferredPresentationSize = { }) 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,13 +95,14 @@ public: > 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; > bool readRTF(SharedBuffer&) override; > bool readImage(Ref<SharedBuffer>&&, const String&, Optional<FloatSize> = { }) 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; } > }; >diff --git a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >index a70589e99f3f741080b6255417ee9c2ae28befaa..532a84a9c45e1f24460da25758939815b08a8252 100644 >--- a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >+++ b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >@@ -695,7 +695,7 @@ bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type, > > #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); >@@ -723,6 +723,10 @@ static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path) > 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; > } > >@@ -730,7 +734,7 @@ static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path) > 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); >@@ -757,6 +761,10 @@ static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, co > 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; > } > >@@ -766,9 +774,9 @@ static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, co > > #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(); >@@ -776,15 +784,24 @@ bool WebContentReader::readFilePaths(const Vector<String>& paths) > 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()) >@@ -816,7 +833,7 @@ bool WebContentReader::readURL(const URL& url, const String& title) > 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; >@@ -832,7 +849,7 @@ bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, > 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); >diff --git a/Source/WebCore/platform/Pasteboard.h b/Source/WebCore/platform/Pasteboard.h >index 2c17415e889b334b83cf9b936737b611148b903a..647dc5fc4a9bb0d9b435ec181c4e5236fcc1dc10 100644 >--- a/Source/WebCore/platform/Pasteboard.h >+++ b/Source/WebCore/platform/Pasteboard.h >@@ -136,13 +136,14 @@ public: > > #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; > virtual bool readRTF(SharedBuffer&) = 0; > virtual bool readImage(Ref<SharedBuffer>&&, const String& type, Optional<FloatSize> preferredPresentationSize = { }) = 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; > }; >diff --git a/Source/WebCore/platform/ios/PasteboardIOS.mm b/Source/WebCore/platform/ios/PasteboardIOS.mm >index 6fe23d9d87d3d56bfae8ff823e6b50523c0efa43..416295677f7aef2d3b8dab1ed6e4777f972d3ea5 100644 >--- a/Source/WebCore/platform/ios/PasteboardIOS.mm >+++ b/Source/WebCore/platform/ios/PasteboardIOS.mm >@@ -307,7 +307,7 @@ void Pasteboard::read(PasteboardWebContentReader& reader, WebContentReadingPolic > 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 @@ void Pasteboard::readRespectingUTIFidelities(PasteboardWebContentReader& reader, > 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 @@ void Pasteboard::readRespectingUTIFidelities(PasteboardWebContentReader& reader, > } > #if ENABLE(ATTACHMENT_ELEMENT) > if (canReadAttachment && result == ReaderResult::DidNotReadType) >- reader.readFilePaths({ WTFMove(attachmentFilePath) }); >+ reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize); > #endif > } > } >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 01011fd55370e4eef3c60ca174919a4dd65d8c06..32d61c644eadf2bf2ab12779b1c3e0e7e92367cb 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,16 @@ >+2019-05-24 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [iOS] Respect -[NSItemProvider preferredPresentationSize] when dropping images >+ https://bugs.webkit.org/show_bug.cgi?id=198242 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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-24 Yusuke Suzuki <ysuzuki@apple.com> > > Make display-profiler-output work with newer HighLine >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm >index 01c0c255d70a7371607726b5b9650a8e9a071c8f..109116bc4c67001a0ea26f633dd400d403906731 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm >@@ -1631,6 +1631,21 @@ TEST(WKAttachmentTestsIOS, InsertDroppedImageAsAttachment) > } > } > >+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();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198242
: 370622