WebKit Bugzilla
Attachment 370425 Details for
Bug 198132
: [Paste] Add support for preferred presentation size when pasting an image
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-198132-20190522110535.patch (text/plain), 19.38 KB, created by
zalan
on 2019-05-22 11:05:36 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
zalan
Created:
2019-05-22 11:05:36 PDT
Size:
19.38 KB
patch
obsolete
>Subversion Revision: 245361 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 9ed9c6c5e895ef6ac3448758ba6dc232be832f3b..97b7c382b8ddd40b5584ce1e1d3c1247cff1f545 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,32 @@ >+2019-05-22 Zalan Bujtas <zalan@apple.com> >+ >+ [Paste] Add support for preferred presentation size when pasting an image >+ https://bugs.webkit.org/show_bug.cgi?id=198132 >+ <rdar://problem/50886917> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Set the pasted <img> width/height attributes when the preferred presentation size is available. >+ >+ * editing/WebContentReader.h: >+ * editing/cocoa/WebContentReaderCocoa.mm: >+ (WebCore::createFragmentForImageAttachment): >+ (WebCore::WebContentReader::readImage): >+ * editing/markup.cpp: >+ (WebCore::createFragmentForImageAndURL): >+ * editing/markup.h: >+ * platform/Pasteboard.h: >+ (WebCore::PasteboardWebContentReader::readImage): >+ * platform/PasteboardItemInfo.h: >+ (WebCore::PasteboardItemInfo::encode const): >+ (WebCore::PasteboardItemInfo::decode): >+ * platform/ios/PasteboardIOS.mm: >+ (WebCore::Pasteboard::readPasteboardWebContentDataForType): >+ (WebCore::Pasteboard::read): >+ (WebCore::Pasteboard::readRespectingUTIFidelities): >+ * platform/ios/PlatformPasteboardIOS.mm: >+ (WebCore::PlatformPasteboard::informationForItemAtIndex): >+ > 2019-05-15 Zalan Bujtas <zalan@apple.com> > > Do not create a shape object outside of the layout context >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 80bf8a30a4138e8d1b9971e6a2ac5e7e5fa67a48..522ffdb701c73ec0a268a4457847ae37578a58c4 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,17 @@ >+2019-05-22 Zalan Bujtas <zalan@apple.com> >+ >+ [Paste] Add support for preferred presentation size when pasting an image >+ https://bugs.webkit.org/show_bug.cgi?id=198132 >+ <rdar://problem/50886917> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * UIProcess/API/Cocoa/_WKElementAction.mm: >+ (addToReadingList): >+ * UIProcess/ios/WKActionSheetAssistant.mm: >+ (-[WKActionSheetAssistant defaultActionsForLinkSheet:]): >+ (-[WKActionSheetAssistant defaultActionsForImageSheet:]): >+ > 2019-05-15 Brent Fulgham <bfulgham@apple.com> > > Revise sandbox to allow IOKit properties needed by Metal and LaunchServices >diff --git a/Source/WebCore/editing/WebContentReader.h b/Source/WebCore/editing/WebContentReader.h >index 3c31112fbe43997a464220205fd19403437f2436..30c08ce43c1abc022477b2ae9b3370d41253f64a 100644 >--- a/Source/WebCore/editing/WebContentReader.h >+++ b/Source/WebCore/editing/WebContentReader.h >@@ -75,7 +75,7 @@ private: > bool readHTML(const String&) override; > bool readRTFD(SharedBuffer&) override; > bool readRTF(SharedBuffer&) override; >- bool readImage(Ref<SharedBuffer>&&, const String& type) 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; > #endif >@@ -98,7 +98,7 @@ private: > bool readHTML(const String&) override; > bool readRTFD(SharedBuffer&) override; > bool readRTF(SharedBuffer&) override; >- bool readImage(Ref<SharedBuffer>&&, const String&) override { return false; } >+ 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; } > #endif >diff --git a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >index 8c331ff732e83049ca38874841de3b2a4ddf5ed0..561a07304899e98335d61172a76229b2533e82b4 100644 >--- a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >+++ b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >@@ -246,7 +246,7 @@ static bool supportsClientSideAttachmentData(const Frame& frame) > > #endif > >-static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Document& document, Ref<SharedBuffer>&& buffer, const String& contentType) >+static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Document& document, Ref<SharedBuffer>&& buffer, const String& contentType, Optional<FloatSize> preferredSize) > { > #if ENABLE(ATTACHMENT_ELEMENT) > auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document); >@@ -260,6 +260,10 @@ static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Docu > auto image = HTMLImageElement::create(document); > image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, Blob::create(buffer.get(), contentType))); > image->setAttachmentElement(WTFMove(attachment)); >+ if (preferredSize) { >+ image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width())); >+ image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height())); >+ } > fragment->appendChild(WTFMove(image)); > } else { > attachment->updateAttributes(buffer->size(), contentType, defaultImageAttachmentName); >@@ -676,14 +680,14 @@ bool WebContentReader::readPlainText(const String& text) > return true; > } > >-bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type) >+bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type, Optional<FloatSize> preferredPresentationSize) > { > ASSERT(frame.document()); > auto& document = *frame.document(); > if (shouldReplaceRichContentWithAttachments()) >- addFragment(createFragmentForImageAttachment(frame, document, WTFMove(buffer), type)); >+ addFragment(createFragmentForImageAttachment(frame, document, WTFMove(buffer), type, preferredPresentationSize)); > else >- addFragment(createFragmentForImageAndURL(document, DOMURL::createObjectURL(document, Blob::create(buffer.get(), type)))); >+ addFragment(createFragmentForImageAndURL(document, DOMURL::createObjectURL(document, Blob::create(buffer.get(), type)), preferredPresentationSize)); > > return fragment; > } >diff --git a/Source/WebCore/editing/markup.cpp b/Source/WebCore/editing/markup.cpp >index 00cb4e98f3070d54fad03ed407fb15a3494da85b..6dcc7e4900168d5facce6bf245be03b549689caf 100644 >--- a/Source/WebCore/editing/markup.cpp >+++ b/Source/WebCore/editing/markup.cpp >@@ -1226,10 +1226,14 @@ RefPtr<DocumentFragment> createFragmentForTransformToFragment(Document& outputDo > return fragment; > } > >-Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url) >+Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url, Optional<FloatSize> preferredSize) > { > auto imageElement = HTMLImageElement::create(document); > imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, url); >+ if (preferredSize) { >+ imageElement->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width())); >+ imageElement->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height())); >+ } > > auto fragment = document.createDocumentFragment(); > fragment->appendChild(imageElement); >diff --git a/Source/WebCore/editing/markup.h b/Source/WebCore/editing/markup.h >index f22a464f902ab649ff4f654049f8a732bd808512..7922a78b8055bab2f23fb18b59fc688717a9d0a7 100644 >--- a/Source/WebCore/editing/markup.h >+++ b/Source/WebCore/editing/markup.h >@@ -59,7 +59,7 @@ WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromText(Range& context, cons > WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromMarkup(Document&, const String& markup, const String& baseURL, ParserContentPolicy = AllowScriptingContent); > ExceptionOr<Ref<DocumentFragment>> createFragmentForInnerOuterHTML(Element&, const String& markup, ParserContentPolicy); > RefPtr<DocumentFragment> createFragmentForTransformToFragment(Document&, const String& sourceString, const String& sourceMIMEType); >-Ref<DocumentFragment> createFragmentForImageAndURL(Document&, const String&); >+Ref<DocumentFragment> createFragmentForImageAndURL(Document&, const String&, Optional<FloatSize> preferredSize); > ExceptionOr<Ref<DocumentFragment>> createContextualFragment(Element&, const String& markup, ParserContentPolicy); > > bool isPlainTextMarkup(Node*); >diff --git a/Source/WebCore/platform/Pasteboard.h b/Source/WebCore/platform/Pasteboard.h >index 4a2f3645c4039abdbe8b468a42883c0bd4ed6fc4..3c15ebe0580e733530561fb487cb4c6010a27c30 100644 >--- a/Source/WebCore/platform/Pasteboard.h >+++ b/Source/WebCore/platform/Pasteboard.h >@@ -140,7 +140,7 @@ public: > virtual bool readHTML(const String&) = 0; > virtual bool readRTFD(SharedBuffer&) = 0; > virtual bool readRTF(SharedBuffer&) = 0; >- virtual bool readImage(Ref<SharedBuffer>&&, const String& type) = 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; > #endif >@@ -288,7 +288,7 @@ private: > DidNotReadType, > PasteboardWasChangedExternally > }; >- ReaderResult readPasteboardWebContentDataForType(PasteboardWebContentReader&, PasteboardStrategy&, NSString *type, int itemIndex); >+ ReaderResult readPasteboardWebContentDataForType(PasteboardWebContentReader&, PasteboardStrategy&, NSString *type, PasteboardItemInfo, int itemIndex); > #endif > > #if PLATFORM(WIN) >diff --git a/Source/WebCore/platform/PasteboardItemInfo.h b/Source/WebCore/platform/PasteboardItemInfo.h >index 6d578385b1846f28c46788afb04e85cb90a0c2a0..903996245e85567147f24da93adc6e1a3cbf4903 100644 >--- a/Source/WebCore/platform/PasteboardItemInfo.h >+++ b/Source/WebCore/platform/PasteboardItemInfo.h >@@ -42,6 +42,7 @@ struct PasteboardItemInfo { > Vector<String> contentTypesForFileUpload; > Vector<String> contentTypesByFidelity; > String suggestedFileName; >+ Optional<FloatSize> preferredPresentationSize; > bool isNonTextType { false }; > bool containsFileURLAndFileUploadContent { false }; > PasteboardItemPresentationStyle preferredPresentationStyle { PasteboardItemPresentationStyle::Unspecified }; >@@ -97,7 +98,7 @@ struct PasteboardItemInfo { > template<class Encoder> > void PasteboardItemInfo::encode(Encoder& encoder) const > { >- encoder << pathsForFileUpload << contentTypesForFileUpload << contentTypesByFidelity << suggestedFileName << isNonTextType << containsFileURLAndFileUploadContent; >+ encoder << pathsForFileUpload << contentTypesForFileUpload << contentTypesByFidelity << suggestedFileName << preferredPresentationSize << isNonTextType << containsFileURLAndFileUploadContent; > encoder.encodeEnum(preferredPresentationStyle); > } > >@@ -117,6 +118,9 @@ Optional<PasteboardItemInfo> PasteboardItemInfo::decode(Decoder& decoder) > if (!decoder.decode(result.suggestedFileName)) > return WTF::nullopt; > >+ if (!decoder.decode(result.preferredPresentationSize)) >+ return WTF::nullopt; >+ > if (!decoder.decode(result.isNonTextType)) > return WTF::nullopt; > >diff --git a/Source/WebCore/platform/ios/PasteboardIOS.mm b/Source/WebCore/platform/ios/PasteboardIOS.mm >index 06584a0ac9d559ae90a396394a03e58d225e380f..6ca70e1b89630843316fbfe68ed5057685a870d9 100644 >--- a/Source/WebCore/platform/ios/PasteboardIOS.mm >+++ b/Source/WebCore/platform/ios/PasteboardIOS.mm >@@ -181,7 +181,7 @@ static bool isTypeAllowedByReadingPolicy(NSString *type, WebContentReadingPolicy > || [type isEqualToString:(__bridge NSString *)kUTTypeFlatRTFD]; > } > >-Pasteboard::ReaderResult Pasteboard::readPasteboardWebContentDataForType(PasteboardWebContentReader& reader, PasteboardStrategy& strategy, NSString *type, int itemIndex) >+Pasteboard::ReaderResult Pasteboard::readPasteboardWebContentDataForType(PasteboardWebContentReader& reader, PasteboardStrategy& strategy, NSString *type, PasteboardItemInfo itemInfo, int itemIndex) > { > if ([type isEqualToString:WebArchivePboardType] || [type isEqualToString:(__bridge NSString *)kUTTypeWebArchive]) { > auto buffer = strategy.readBufferFromPasteboard(itemIndex, type, m_pasteboardName); >@@ -225,7 +225,7 @@ Pasteboard::ReaderResult Pasteboard::readPasteboardWebContentDataForType(Pastebo > RefPtr<SharedBuffer> buffer = strategy.readBufferFromPasteboard(itemIndex, type, m_pasteboardName); > if (m_changeCount != changeCount()) > return ReaderResult::PasteboardWasChangedExternally; >- return buffer && reader.readImage(buffer.releaseNonNull(), type) ? ReaderResult::ReadType : ReaderResult::DidNotReadType; >+ return buffer && reader.readImage(buffer.releaseNonNull(), type, itemInfo.preferredPresentationSize) ? ReaderResult::ReadType : ReaderResult::DidNotReadType; > } > > if ([type isEqualToString:(__bridge NSString *)kUTTypeURL]) { >@@ -318,7 +318,7 @@ void Pasteboard::read(PasteboardWebContentReader& reader, WebContentReadingPolic > if (!isTypeAllowedByReadingPolicy(type, policy)) > continue; > >- auto itemResult = readPasteboardWebContentDataForType(reader, strategy, type, i); >+ auto itemResult = readPasteboardWebContentDataForType(reader, strategy, type, info, i); > if (itemResult == ReaderResult::PasteboardWasChangedExternally) > return; > >@@ -358,7 +358,7 @@ void Pasteboard::readRespectingUTIFidelities(PasteboardWebContentReader& reader, > if (!isTypeAllowedByReadingPolicy(type, policy)) > continue; > >- result = readPasteboardWebContentDataForType(reader, strategy, type, index); >+ result = readPasteboardWebContentDataForType(reader, strategy, type, info, index); > if (result == ReaderResult::PasteboardWasChangedExternally) > return; > if (result == ReaderResult::ReadType) >diff --git a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm b/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >index aff35ed5dfc13113ca28f18d6f19623da9c221d5..8a86e4a4007dd5038eff308057fc07bc22597a24 100644 >--- a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >+++ b/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >@@ -155,6 +155,8 @@ PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(int index) > #if PASTEBOARD_SUPPORTS_PRESENTATION_STYLE_AND_TEAM_DATA > info.preferredPresentationStyle = pasteboardItemPresentationStyle(itemProvider.preferredPresentationStyle); > #endif >+ if (!CGSizeEqualToSize(itemProvider.preferredPresentationSize, CGSizeZero)) >+ info.preferredPresentationSize = FloatSize { itemProvider.preferredPresentationSize }; > info.containsFileURLAndFileUploadContent = itemProvider.web_containsFileURLAndFileUploadContent; > info.suggestedFileName = itemProvider.suggestedName; > NSArray<NSString *> *registeredTypeIdentifiers = itemProvider.registeredTypeIdentifiers; >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 547a1b9dc604419a0ad2a4b6eb8b5c32fe3f1370..dbf5d33de6b7889c62cad4dc31d68c0a3c126abb 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,14 @@ >+2019-05-22 Zalan Bujtas <zalan@apple.com> >+ >+ [Paste] Add support for preferred presentation size when pasting an image >+ https://bugs.webkit.org/show_bug.cgi?id=198132 >+ <rdar://problem/50886917> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm: >+ (TestWebKitAPI::TEST): >+ > 2019-05-15 Aakash Jain <aakash_jain@apple.com> > > [ews-build] Enabling uploading EWS archives to S3 >diff --git a/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm b/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm >index b87806454db98e3fa1f10e4013d7d3ecc9ef9f2c..0da450bf15d816bc8608c31f10f33c1ee0edc721 100644 >--- a/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm >+++ b/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm >@@ -302,6 +302,52 @@ TEST(UIPasteboardTests, DataTransferURIListContainsMultipleURLs) > EXPECT_WK_STREQ("https://www.apple.com/", [webView stringByEvaluatingJavaScript:@"textData.textContent"]); > } > >+TEST(UIPasteboardTests, ValidPreferredPresentationSizeForImage) >+{ >+ auto webView = setUpWebViewForPasteboardTests(@"autofocus-contenteditable"); >+ auto itemProvider = adoptNS([[NSItemProvider alloc] init]); >+ [itemProvider setPreferredPresentationSize:CGSizeMake(10, 20)]; >+ [itemProvider registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypePNG visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[] (DataLoadCompletionBlock completionHandler) -> NSProgress * { >+ completionHandler([NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]], nil); >+ return nil; >+ }]; >+ [UIPasteboard generalPasteboard].itemProviders = @[ itemProvider.get() ]; >+ [webView paste:nil]; >+ >+ EXPECT_WK_STREQ("10", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').width"]); >+ EXPECT_WK_STREQ("20", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').height"]); >+} >+ >+TEST(UIPasteboardTests, InvalidPreferredPresentationSizeForImage) >+{ >+ auto webView = setUpWebViewForPasteboardTests(@"autofocus-contenteditable"); >+ auto itemProvider = adoptNS([[NSItemProvider alloc] init]); >+ [itemProvider setPreferredPresentationSize:CGSizeMake(-10, -20)]; >+ [itemProvider registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypePNG visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[] (DataLoadCompletionBlock completionHandler) -> NSProgress * { >+ completionHandler([NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]], nil); >+ return nil; >+ }]; >+ [UIPasteboard generalPasteboard].itemProviders = @[ itemProvider.get() ]; >+ [webView paste:nil]; >+ >+ EXPECT_WK_STREQ("0", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').width"]); >+ EXPECT_WK_STREQ("174", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').height"]); >+} >+ >+TEST(UIPasteboardTests, MissingPreferredPresentationSizeForImage) >+{ >+ auto webView = setUpWebViewForPasteboardTests(@"autofocus-contenteditable"); >+ auto itemProvider = adoptNS([[NSItemProvider alloc] init]); >+ [itemProvider registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypePNG visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[] (DataLoadCompletionBlock completionHandler) -> NSProgress * { >+ completionHandler([NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]], nil); >+ return nil; >+ }]; >+ [UIPasteboard generalPasteboard].itemProviders = @[ itemProvider.get() ]; >+ [webView paste:nil]; >+ >+ EXPECT_WK_STREQ("0", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').width"]); >+ EXPECT_WK_STREQ("174", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').height"]); >+} > #endif // PLATFORM(IOS) > > } // namespace TestWebKitAPI
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 198132
:
370425
|
370431