Title: [245782] branches/safari-608.1.24.20-branch
Revision
245782
Author
[email protected]
Date
2019-05-26 12:05:26 -0700 (Sun, 26 May 2019)

Log Message

Cherry-pick r245637. rdar://problem/35205373

    [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 Wenson Hsieh.

    Source/WebCore:

    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):

    Source/WebKit:

    * UIProcess/API/Cocoa/_WKElementAction.mm:
    (addToReadingList):
    * UIProcess/ios/WKActionSheetAssistant.mm:
    (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
    (-[WKActionSheetAssistant defaultActionsForImageSheet:]):

    Tools:

    * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:
    (TestWebKitAPI::TEST):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245637 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/ChangeLog	2019-05-26 19:05:26 UTC (rev 245782)
@@ -1,5 +1,83 @@
 2019-05-26  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r245637. rdar://problem/35205373
+
+    [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 Wenson Hsieh.
+    
+    Source/WebCore:
+    
+    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):
+    
+    Source/WebKit:
+    
+    * UIProcess/API/Cocoa/_WKElementAction.mm:
+    (addToReadingList):
+    * UIProcess/ios/WKActionSheetAssistant.mm:
+    (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+    (-[WKActionSheetAssistant defaultActionsForImageSheet:]):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:
+    (TestWebKitAPI::TEST):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245637 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-05-22  Zalan Bujtas  <[email protected]>
+
+            [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 Wenson Hsieh.
+
+            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-26  Babak Shafiei  <[email protected]>
+
         Cherry-pick r245778. rdar://problem/35205373
 
     [iOS] Dropped text, attachments, and images should animate into place

Modified: branches/safari-608.1.24.20-branch/Source/WebCore/editing/WebContentReader.h (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebCore/editing/WebContentReader.h	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/editing/WebContentReader.h	2019-05-26 19:05:26 UTC (rev 245782)
@@ -76,7 +76,7 @@
     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, Optional<FloatSize> preferredPresentationSize = { }) override;
 #endif
@@ -100,7 +100,7 @@
     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&, Optional<FloatSize> = { }) override { return false; }
 #endif

Modified: branches/safari-608.1.24.20-branch/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2019-05-26 19:05:26 UTC (rev 245782)
@@ -246,7 +246,7 @@
 
 #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 @@
             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 @@
     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;
 }

Modified: branches/safari-608.1.24.20-branch/Source/WebCore/editing/gtk/EditorGtk.cpp (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebCore/editing/gtk/EditorGtk.cpp	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/editing/gtk/EditorGtk.cpp	2019-05-26 19:05:26 UTC (rev 245782)
@@ -69,7 +69,7 @@
             auto blob = Blob::create(WTFMove(buffer), "image/png");
             if (!frame.document())
                 return nullptr;
-            return createFragmentForImageAndURL(*frame.document(), DOMURL::createObjectURL(*frame.document(), blob));
+            return createFragmentForImageAndURL(*frame.document(), DOMURL::createObjectURL(*frame.document(), blob), { });
         }
     }
 

Modified: branches/safari-608.1.24.20-branch/Source/WebCore/editing/markup.cpp (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebCore/editing/markup.cpp	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/editing/markup.cpp	2019-05-26 19:05:26 UTC (rev 245782)
@@ -1226,10 +1226,14 @@
     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);

Modified: branches/safari-608.1.24.20-branch/Source/WebCore/editing/markup.h (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebCore/editing/markup.h	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/editing/markup.h	2019-05-26 19:05:26 UTC (rev 245782)
@@ -59,7 +59,7 @@
 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*);

Modified: branches/safari-608.1.24.20-branch/Source/WebCore/platform/Pasteboard.h (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebCore/platform/Pasteboard.h	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/platform/Pasteboard.h	2019-05-26 19:05:26 UTC (rev 245782)
@@ -141,7 +141,7 @@
     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, Optional<FloatSize> preferredPresentationSize = { }) = 0;
 #endif
@@ -289,7 +289,7 @@
         DidNotReadType,
         PasteboardWasChangedExternally
     };
-    ReaderResult readPasteboardWebContentDataForType(PasteboardWebContentReader&, PasteboardStrategy&, NSString *type, int itemIndex);
+    ReaderResult readPasteboardWebContentDataForType(PasteboardWebContentReader&, PasteboardStrategy&, NSString *type, const PasteboardItemInfo&, int itemIndex);
 #endif
 
 #if PLATFORM(WIN)

Modified: branches/safari-608.1.24.20-branch/Source/WebCore/platform/PasteboardItemInfo.h (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebCore/platform/PasteboardItemInfo.h	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/platform/PasteboardItemInfo.h	2019-05-26 19:05:26 UTC (rev 245782)
@@ -42,6 +42,7 @@
     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 @@
 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 @@
     if (!decoder.decode(result.suggestedFileName))
         return WTF::nullopt;
 
+    if (!decoder.decode(result.preferredPresentationSize))
+        return WTF::nullopt;
+
     if (!decoder.decode(result.isNonTextType))
         return WTF::nullopt;
 

Modified: branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PasteboardIOS.mm (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PasteboardIOS.mm	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PasteboardIOS.mm	2019-05-26 19:05:26 UTC (rev 245782)
@@ -181,7 +181,7 @@
         || [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, const 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 @@
         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 @@
             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 @@
             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)

Modified: branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm	2019-05-26 19:05:26 UTC (rev 245782)
@@ -155,6 +155,8 @@
 #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;

Modified: branches/safari-608.1.24.20-branch/Source/WebKit/ChangeLog (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Source/WebKit/ChangeLog	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Source/WebKit/ChangeLog	2019-05-26 19:05:26 UTC (rev 245782)
@@ -1,5 +1,68 @@
 2019-05-26  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r245637. rdar://problem/35205373
+
+    [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 Wenson Hsieh.
+    
+    Source/WebCore:
+    
+    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):
+    
+    Source/WebKit:
+    
+    * UIProcess/API/Cocoa/_WKElementAction.mm:
+    (addToReadingList):
+    * UIProcess/ios/WKActionSheetAssistant.mm:
+    (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+    (-[WKActionSheetAssistant defaultActionsForImageSheet:]):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:
+    (TestWebKitAPI::TEST):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245637 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-05-22  Zalan Bujtas  <[email protected]>
+
+            [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 Wenson Hsieh.
+
+            * UIProcess/API/Cocoa/_WKElementAction.mm:
+            (addToReadingList):
+            * UIProcess/ios/WKActionSheetAssistant.mm:
+            (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+            (-[WKActionSheetAssistant defaultActionsForImageSheet:]):
+
+2019-05-26  Babak Shafiei  <[email protected]>
+
         Cherry-pick r245778. rdar://problem/35205373
 
     [iOS] Dropped text, attachments, and images should animate into place

Modified: branches/safari-608.1.24.20-branch/Tools/ChangeLog (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Tools/ChangeLog	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Tools/ChangeLog	2019-05-26 19:05:26 UTC (rev 245782)
@@ -1,5 +1,65 @@
 2019-05-26  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r245637. rdar://problem/35205373
+
+    [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 Wenson Hsieh.
+    
+    Source/WebCore:
+    
+    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):
+    
+    Source/WebKit:
+    
+    * UIProcess/API/Cocoa/_WKElementAction.mm:
+    (addToReadingList):
+    * UIProcess/ios/WKActionSheetAssistant.mm:
+    (-[WKActionSheetAssistant defaultActionsForLinkSheet:]):
+    (-[WKActionSheetAssistant defaultActionsForImageSheet:]):
+    
+    Tools:
+    
+    * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:
+    (TestWebKitAPI::TEST):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245637 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-05-22  Zalan Bujtas  <[email protected]>
+
+            [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 Wenson Hsieh.
+
+            * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:
+            (TestWebKitAPI::TEST):
+
+2019-05-26  Babak Shafiei  <[email protected]>
+
         Cherry-pick r245778. rdar://problem/35205373
 
     [iOS] Dropped text, attachments, and images should animate into place

Modified: branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm (245781 => 245782)


--- branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm	2019-05-26 18:21:55 UTC (rev 245781)
+++ branches/safari-608.1.24.20-branch/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm	2019-05-26 19:05:26 UTC (rev 245782)
@@ -302,6 +302,52 @@
     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
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to