Title: [246207] trunk/Source/WebCore
Revision
246207
Author
[email protected]
Date
2019-06-07 10:50:49 -0700 (Fri, 07 Jun 2019)

Log Message

Images are not resizing correctly when dragged to a message in 1/3 view
https://bugs.webkit.org/show_bug.cgi?id=198623
<rdar://problem/51185518>

Reviewed by Wenson Hsieh.

Mail's max-width: 100%; default style is in conflict with the preferred presentation size. This patch preserves the existing behaviour for Mail by
not setting the height (and rely on the width + aspect ratio).

* editing/WebContentReader.h:
* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::createFragmentForImageAttachment):
(WebCore::WebContentReader::readImage):
(WebCore::attachmentForFilePath):
(WebCore::attachmentForData):
(WebCore::WebContentReader::readFilePath):
(WebCore::WebContentReader::readDataBuffer):
* editing/gtk/EditorGtk.cpp:
(WebCore::createFragmentFromPasteboardData):
* editing/markup.cpp:
(WebCore::createFragmentForImageAndURL):
* editing/markup.h:
* platform/Pasteboard.h:
(WebCore::PasteboardWebContentReader::readFilePath):
(WebCore::PasteboardWebContentReader::readImage):
(WebCore::PasteboardWebContentReader::readDataBuffer):
* 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (246206 => 246207)


--- trunk/Source/WebCore/ChangeLog	2019-06-07 17:15:49 UTC (rev 246206)
+++ trunk/Source/WebCore/ChangeLog	2019-06-07 17:50:49 UTC (rev 246207)
@@ -1,5 +1,43 @@
 2019-06-07  Zalan Bujtas  <[email protected]>
 
+        Images are not resizing correctly when dragged to a message in 1/3 view
+        https://bugs.webkit.org/show_bug.cgi?id=198623
+        <rdar://problem/51185518>
+
+        Reviewed by Wenson Hsieh.
+
+        Mail's max-width: 100%; default style is in conflict with the preferred presentation size. This patch preserves the existing behaviour for Mail by
+        not setting the height (and rely on the width + aspect ratio). 
+
+        * editing/WebContentReader.h:
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::createFragmentForImageAttachment):
+        (WebCore::WebContentReader::readImage):
+        (WebCore::attachmentForFilePath):
+        (WebCore::attachmentForData):
+        (WebCore::WebContentReader::readFilePath):
+        (WebCore::WebContentReader::readDataBuffer):
+        * editing/gtk/EditorGtk.cpp:
+        (WebCore::createFragmentFromPasteboardData):
+        * editing/markup.cpp:
+        (WebCore::createFragmentForImageAndURL):
+        * editing/markup.h:
+        * platform/Pasteboard.h:
+        (WebCore::PasteboardWebContentReader::readFilePath):
+        (WebCore::PasteboardWebContentReader::readImage):
+        (WebCore::PasteboardWebContentReader::readDataBuffer):
+        * 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-06-07  Zalan Bujtas  <[email protected]>
+
         [LFC][IFC] Line should skip all vertical adjustment when running preferred width computation
         https://bugs.webkit.org/show_bug.cgi?id=198642
         <rdar://problem/51511043>

Modified: trunk/Source/WebCore/editing/WebContentReader.h (246206 => 246207)


--- trunk/Source/WebCore/editing/WebContentReader.h	2019-06-07 17:15:49 UTC (rev 246206)
+++ trunk/Source/WebCore/editing/WebContentReader.h	2019-06-07 17:50:49 UTC (rev 246207)
@@ -71,14 +71,14 @@
 private:
 #if PLATFORM(COCOA)
     bool readWebArchive(SharedBuffer&) override;
-    bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }, const String& contentType = { }) override;
+    bool readFilePath(const String&, PresentationSize preferredPresentationSize = { }, const String& contentType = { }) 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 readImage(Ref<SharedBuffer>&&, const String& type, PresentationSize preferredPresentationSize = { }) override;
     bool readURL(const URL&, const String& title) override;
-    bool readDataBuffer(SharedBuffer&, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize = { }) override;
+    bool readDataBuffer(SharedBuffer&, const String& type, const String& name, PresentationSize preferredPresentationSize = { }) override;
 #endif
     bool readPlainText(const String&) override;
 };
@@ -95,14 +95,14 @@
 private:
 #if PLATFORM(COCOA)
     bool readWebArchive(SharedBuffer&) override;
-    bool readFilePath(const String&, Optional<FloatSize> = { }, const String& = { }) override { return false; }
+    bool readFilePath(const String&, PresentationSize = { }, const String& = { }) 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 readImage(Ref<SharedBuffer>&&, const String&, PresentationSize = { }) override { return false; }
     bool readURL(const URL&, const String&) override { return false; }
-    bool readDataBuffer(SharedBuffer&, const String&, const String&, Optional<FloatSize> = { }) override { return false; }
+    bool readDataBuffer(SharedBuffer&, const String&, const String&, PresentationSize = { }) override { return false; }
 #endif
     bool readPlainText(const String&) override { return false; }
 };

Modified: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (246206 => 246207)


--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2019-06-07 17:15:49 UTC (rev 246206)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2019-06-07 17:50:49 UTC (rev 246207)
@@ -247,7 +247,7 @@
 
 #endif
 
-static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Document& document, Ref<SharedBuffer>&& buffer, const String& contentType, Optional<FloatSize> preferredSize)
+static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Document& document, Ref<SharedBuffer>&& buffer, const String& contentType, PresentationSize preferredSize)
 {
 #if ENABLE(ATTACHMENT_ELEMENT)
     auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
@@ -261,10 +261,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()));
-            }
+            if (preferredSize.width)
+                image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(*preferredSize.width));
+            if (preferredSize.height)
+                image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(*preferredSize.height));
             fragment->appendChild(WTFMove(image));
         } else {
             attachment->updateAttributes(buffer->size(), contentType, defaultImageAttachmentName);
@@ -681,7 +681,7 @@
     return true;
 }
 
-bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type, Optional<FloatSize> preferredPresentationSize)
+bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type, PresentationSize preferredPresentationSize)
 {
     ASSERT(frame.document());
     auto& document = *frame.document();
@@ -704,7 +704,7 @@
     return mimeType.isEmpty() ? contentType : mimeType;
 }
 
-static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, Optional<FloatSize> preferredSize, const String& explicitContentType)
+static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, PresentationSize preferredSize, const String& explicitContentType)
 {
     auto document = makeRef(*frame.document());
     auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
@@ -738,10 +738,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()));
-        }
+        if (preferredSize.width)
+            image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(*preferredSize.width));
+        if (preferredSize.height)
+            image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(*preferredSize.height));
         return image;
     }
 
@@ -749,7 +749,7 @@
     return attachment;
 }
 
-static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name, Optional<FloatSize> preferredSize)
+static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name, PresentationSize preferredSize)
 {
     auto document = makeRef(*frame.document());
     auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
@@ -775,10 +775,10 @@
         auto image = HTMLImageElement::create(document);
         image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(Blob::create(buffer, WTFMove(attachmentType)), WTFMove(fileName))));
         image->setAttachmentElement(WTFMove(attachment));
-        if (preferredSize) {
-            image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width()));
-            image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height()));
-        }
+        if (preferredSize.width)
+            image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(*preferredSize.width));
+        if (preferredSize.height)
+            image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(*preferredSize.height));
         return image;
     }
 
@@ -788,7 +788,7 @@
 
 #endif // ENABLE(ATTACHMENT_ELEMENT)
 
-bool WebContentReader::readFilePath(const String& path, Optional<FloatSize> preferredPresentationSize, const String& contentType)
+bool WebContentReader::readFilePath(const String& path, PresentationSize preferredPresentationSize, const String& contentType)
 {
     if (path.isEmpty() || !frame.document())
         return false;
@@ -847,7 +847,7 @@
     return true;
 }
 
-bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize)
+bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name, PresentationSize preferredPresentationSize)
 {
     if (buffer.isEmpty())
         return false;

Modified: trunk/Source/WebCore/editing/markup.cpp (246206 => 246207)


--- trunk/Source/WebCore/editing/markup.cpp	2019-06-07 17:15:49 UTC (rev 246206)
+++ trunk/Source/WebCore/editing/markup.cpp	2019-06-07 17:50:49 UTC (rev 246207)
@@ -1236,15 +1236,14 @@
     return fragment;
 }
 
-Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url, Optional<FloatSize> preferredSize)
+Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url, PresentationSize 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()));
-    }
-
+    if (preferredSize.width)
+        imageElement->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(*preferredSize.width));
+    if (preferredSize.height)
+        imageElement->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(*preferredSize.height));
     auto fragment = document.createDocumentFragment();
     fragment->appendChild(imageElement);
 

Modified: trunk/Source/WebCore/editing/markup.h (246206 => 246207)


--- trunk/Source/WebCore/editing/markup.h	2019-06-07 17:15:49 UTC (rev 246206)
+++ trunk/Source/WebCore/editing/markup.h	2019-06-07 17:50:49 UTC (rev 246207)
@@ -44,6 +44,7 @@
 class HTMLElement;
 class Node;
 class Page;
+struct PresentationSize;
 class QualifiedName;
 class Range;
 class VisibleSelection;
@@ -60,7 +61,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&, Optional<FloatSize> preferredSize);
+Ref<DocumentFragment> createFragmentForImageAndURL(Document&, const String&, PresentationSize preferredSize);
 ExceptionOr<Ref<DocumentFragment>> createContextualFragment(Element&, const String& markup, ParserContentPolicy);
 
 bool isPlainTextMarkup(Node*);

Modified: trunk/Source/WebCore/platform/Pasteboard.h (246206 => 246207)


--- trunk/Source/WebCore/platform/Pasteboard.h	2019-06-07 17:15:49 UTC (rev 246206)
+++ trunk/Source/WebCore/platform/Pasteboard.h	2019-06-07 17:50:49 UTC (rev 246207)
@@ -136,14 +136,14 @@
 
 #if PLATFORM(COCOA)
     virtual bool readWebArchive(SharedBuffer&) = 0;
-    virtual bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }, const String& contentType = { }) = 0;
+    virtual bool readFilePath(const String&, PresentationSize preferredPresentationSize = { }, const String& contentType = { }) = 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 readImage(Ref<SharedBuffer>&&, const String& type, PresentationSize 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;
+    virtual bool readDataBuffer(SharedBuffer&, const String& type, const String& name, PresentationSize preferredPresentationSize = { }) = 0;
 #endif
     virtual bool readPlainText(const String&) = 0;
 };

Modified: trunk/Source/WebCore/platform/PasteboardItemInfo.h (246206 => 246207)


--- trunk/Source/WebCore/platform/PasteboardItemInfo.h	2019-06-07 17:15:49 UTC (rev 246206)
+++ trunk/Source/WebCore/platform/PasteboardItemInfo.h	2019-06-07 17:50:49 UTC (rev 246207)
@@ -37,12 +37,39 @@
     Attachment
 };
 
+struct PresentationSize {
+    Optional<double> width;
+    Optional<double> height;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<PresentationSize> decode(Decoder&);
+};
+
+template<class Encoder>
+void PresentationSize::encode(Encoder& encoder) const
+{
+    encoder << width << height;
+}
+
+template<class Decoder>
+Optional<PresentationSize> PresentationSize::decode(Decoder& decoder)
+{
+    PresentationSize result;
+    if (!decoder.decode(result.width))
+        return WTF::nullopt;
+
+    if (!decoder.decode(result.height))
+        return WTF::nullopt;
+
+    return WTFMove(result);
+}
+
 struct PasteboardItemInfo {
     Vector<String> pathsForFileUpload;
     Vector<String> contentTypesForFileUpload;
     Vector<String> contentTypesByFidelity;
     String suggestedFileName;
-    Optional<FloatSize> preferredPresentationSize;
+    PresentationSize preferredPresentationSize;
     bool isNonTextType { false };
     bool containsFileURLAndFileUploadContent { false };
     PasteboardItemPresentationStyle preferredPresentationStyle { PasteboardItemPresentationStyle::Unspecified };

Modified: trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm (246206 => 246207)


--- trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm	2019-06-07 17:15:49 UTC (rev 246206)
+++ trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm	2019-06-07 17:50:49 UTC (rev 246207)
@@ -31,6 +31,7 @@
 #import "Color.h"
 #import "Image.h"
 #import "Pasteboard.h"
+#import "RuntimeApplicationChecks.h"
 #import "SharedBuffer.h"
 #import "UTIUtilities.h"
 #import "WebItemProviderPasteboard.h"
@@ -155,8 +156,15 @@
 #if PASTEBOARD_SUPPORTS_PRESENTATION_STYLE_AND_TEAM_DATA
     info.preferredPresentationStyle = pasteboardItemPresentationStyle(itemProvider.preferredPresentationStyle);
 #endif
-    if (!CGSizeEqualToSize(itemProvider.preferredPresentationSize, CGSizeZero))
-        info.preferredPresentationSize = FloatSize { itemProvider.preferredPresentationSize };
+    if (!CGSizeEqualToSize(itemProvider.preferredPresentationSize, CGSizeZero)) {
+        auto adjustedPreferredPresentationHeight = [](auto height) -> Optional<double> {
+            if (!IOSApplication::isMobileMail())
+                return { height };
+            // Mail's max-width: 100%; default style is in conflict with the preferred presentation size and can lead to unexpectedly stretched images. Not setting the height forces layout to preserve the aspect ratio.
+            return { };
+        };
+        info.preferredPresentationSize = PresentationSize { itemProvider.preferredPresentationSize.width, adjustedPreferredPresentationHeight(itemProvider.preferredPresentationSize.height) };
+    }
     info.containsFileURLAndFileUploadContent = itemProvider.web_containsFileURLAndFileUploadContent;
     info.suggestedFileName = itemProvider.suggestedName;
     NSArray<NSString *> *registeredTypeIdentifiers = itemProvider.registeredTypeIdentifiers;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to