Changeset 246207 in webkit


Ignore:
Timestamp:
Jun 7, 2019 10:50:49 AM (5 years ago)
Author:
Alan Bujtas
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):

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r246206 r246207  
     12019-06-07  Zalan Bujtas  <zalan@apple.com>
     2
     3        Images are not resizing correctly when dragged to a message in 1/3 view
     4        https://bugs.webkit.org/show_bug.cgi?id=198623
     5        <rdar://problem/51185518>
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        Mail's max-width: 100%; default style is in conflict with the preferred presentation size. This patch preserves the existing behaviour for Mail by
     10        not setting the height (and rely on the width + aspect ratio).
     11
     12        * editing/WebContentReader.h:
     13        * editing/cocoa/WebContentReaderCocoa.mm:
     14        (WebCore::createFragmentForImageAttachment):
     15        (WebCore::WebContentReader::readImage):
     16        (WebCore::attachmentForFilePath):
     17        (WebCore::attachmentForData):
     18        (WebCore::WebContentReader::readFilePath):
     19        (WebCore::WebContentReader::readDataBuffer):
     20        * editing/gtk/EditorGtk.cpp:
     21        (WebCore::createFragmentFromPasteboardData):
     22        * editing/markup.cpp:
     23        (WebCore::createFragmentForImageAndURL):
     24        * editing/markup.h:
     25        * platform/Pasteboard.h:
     26        (WebCore::PasteboardWebContentReader::readFilePath):
     27        (WebCore::PasteboardWebContentReader::readImage):
     28        (WebCore::PasteboardWebContentReader::readDataBuffer):
     29        * platform/PasteboardItemInfo.h:
     30        (WebCore::PasteboardItemInfo::encode const):
     31        (WebCore::PasteboardItemInfo::decode):
     32        * platform/ios/PasteboardIOS.mm:
     33        (WebCore::Pasteboard::readPasteboardWebContentDataForType):
     34        (WebCore::Pasteboard::read):
     35        (WebCore::Pasteboard::readRespectingUTIFidelities):
     36        * platform/ios/PlatformPasteboardIOS.mm:
     37        (WebCore::PlatformPasteboard::informationForItemAtIndex):
     38
    1392019-06-07  Zalan Bujtas  <zalan@apple.com>
    240
  • trunk/Source/WebCore/editing/WebContentReader.h

    r245839 r246207  
    7272#if PLATFORM(COCOA)
    7373    bool readWebArchive(SharedBuffer&) override;
    74     bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }, const String& contentType = { }) override;
     74    bool readFilePath(const String&, PresentationSize preferredPresentationSize = { }, const String& contentType = { }) override;
    7575    bool readFilePaths(const Vector<String>&) override;
    7676    bool readHTML(const String&) override;
    7777    bool readRTFD(SharedBuffer&) override;
    7878    bool readRTF(SharedBuffer&) override;
    79     bool readImage(Ref<SharedBuffer>&&, const String& type, Optional<FloatSize> preferredPresentationSize = { }) override;
     79    bool readImage(Ref<SharedBuffer>&&, const String& type, PresentationSize preferredPresentationSize = { }) override;
    8080    bool readURL(const URL&, const String& title) override;
    81     bool readDataBuffer(SharedBuffer&, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize = { }) override;
     81    bool readDataBuffer(SharedBuffer&, const String& type, const String& name, PresentationSize preferredPresentationSize = { }) override;
    8282#endif
    8383    bool readPlainText(const String&) override;
     
    9696#if PLATFORM(COCOA)
    9797    bool readWebArchive(SharedBuffer&) override;
    98     bool readFilePath(const String&, Optional<FloatSize> = { }, const String& = { }) override { return false; }
     98    bool readFilePath(const String&, PresentationSize = { }, const String& = { }) override { return false; }
    9999    bool readFilePaths(const Vector<String>&) override { return false; }
    100100    bool readHTML(const String&) override;
    101101    bool readRTFD(SharedBuffer&) override;
    102102    bool readRTF(SharedBuffer&) override;
    103     bool readImage(Ref<SharedBuffer>&&, const String&, Optional<FloatSize> = { }) override { return false; }
     103    bool readImage(Ref<SharedBuffer>&&, const String&, PresentationSize = { }) override { return false; }
    104104    bool readURL(const URL&, const String&) override { return false; }
    105     bool readDataBuffer(SharedBuffer&, const String&, const String&, Optional<FloatSize> = { }) override { return false; }
     105    bool readDataBuffer(SharedBuffer&, const String&, const String&, PresentationSize = { }) override { return false; }
    106106#endif
    107107    bool readPlainText(const String&) override { return false; }
  • trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm

    r245839 r246207  
    248248#endif
    249249
    250 static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Document& document, Ref<SharedBuffer>&& buffer, const String& contentType, Optional<FloatSize> preferredSize)
     250static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Document& document, Ref<SharedBuffer>&& buffer, const String& contentType, PresentationSize preferredSize)
    251251{
    252252#if ENABLE(ATTACHMENT_ELEMENT)
     
    262262            image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, Blob::create(buffer.get(), contentType)));
    263263            image->setAttachmentElement(WTFMove(attachment));
    264             if (preferredSize) {
    265                 image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width()));
    266                 image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height()));
    267             }
     264            if (preferredSize.width)
     265                image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(*preferredSize.width));
     266            if (preferredSize.height)
     267                image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(*preferredSize.height));
    268268            fragment->appendChild(WTFMove(image));
    269269        } else {
     
    682682}
    683683
    684 bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type, Optional<FloatSize> preferredPresentationSize)
     684bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type, PresentationSize preferredPresentationSize)
    685685{
    686686    ASSERT(frame.document());
     
    705705}
    706706
    707 static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, Optional<FloatSize> preferredSize, const String& explicitContentType)
     707static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, PresentationSize preferredSize, const String& explicitContentType)
    708708{
    709709    auto document = makeRef(*frame.document());
     
    739739        image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(path)));
    740740        image->setAttachmentElement(WTFMove(attachment));
    741         if (preferredSize) {
    742             image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width()));
    743             image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height()));
    744         }
     741        if (preferredSize.width)
     742            image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(*preferredSize.width));
     743        if (preferredSize.height)
     744            image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(*preferredSize.height));
    745745        return image;
    746746    }
     
    750750}
    751751
    752 static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name, Optional<FloatSize> preferredSize)
     752static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name, PresentationSize preferredSize)
    753753{
    754754    auto document = makeRef(*frame.document());
     
    776776        image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(Blob::create(buffer, WTFMove(attachmentType)), WTFMove(fileName))));
    777777        image->setAttachmentElement(WTFMove(attachment));
    778         if (preferredSize) {
    779             image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width()));
    780             image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height()));
    781         }
     778        if (preferredSize.width)
     779            image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(*preferredSize.width));
     780        if (preferredSize.height)
     781            image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(*preferredSize.height));
    782782        return image;
    783783    }
     
    789789#endif // ENABLE(ATTACHMENT_ELEMENT)
    790790
    791 bool WebContentReader::readFilePath(const String& path, Optional<FloatSize> preferredPresentationSize, const String& contentType)
     791bool WebContentReader::readFilePath(const String& path, PresentationSize preferredPresentationSize, const String& contentType)
    792792{
    793793    if (path.isEmpty() || !frame.document())
     
    848848}
    849849
    850 bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize)
     850bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name, PresentationSize preferredPresentationSize)
    851851{
    852852    if (buffer.isEmpty())
  • trunk/Source/WebCore/editing/markup.cpp

    r245912 r246207  
    12371237}
    12381238
    1239 Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url, Optional<FloatSize> preferredSize)
     1239Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url, PresentationSize preferredSize)
    12401240{
    12411241    auto imageElement = HTMLImageElement::create(document);
    12421242    imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, url);
    1243     if (preferredSize) {
    1244         imageElement->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width()));
    1245         imageElement->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height()));
    1246     }
    1247 
     1243    if (preferredSize.width)
     1244        imageElement->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(*preferredSize.width));
     1245    if (preferredSize.height)
     1246        imageElement->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(*preferredSize.height));
    12481247    auto fragment = document.createDocumentFragment();
    12491248    fragment->appendChild(imageElement);
  • trunk/Source/WebCore/editing/markup.h

    r245681 r246207  
    4545class Node;
    4646class Page;
     47struct PresentationSize;
    4748class QualifiedName;
    4849class Range;
     
    6162ExceptionOr<Ref<DocumentFragment>> createFragmentForInnerOuterHTML(Element&, const String& markup, ParserContentPolicy);
    6263RefPtr<DocumentFragment> createFragmentForTransformToFragment(Document&, const String& sourceString, const String& sourceMIMEType);
    63 Ref<DocumentFragment> createFragmentForImageAndURL(Document&, const String&, Optional<FloatSize> preferredSize);
     64Ref<DocumentFragment> createFragmentForImageAndURL(Document&, const String&, PresentationSize preferredSize);
    6465ExceptionOr<Ref<DocumentFragment>> createContextualFragment(Element&, const String& markup, ParserContentPolicy);
    6566
  • trunk/Source/WebCore/platform/Pasteboard.h

    r245839 r246207  
    137137#if PLATFORM(COCOA)
    138138    virtual bool readWebArchive(SharedBuffer&) = 0;
    139     virtual bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }, const String& contentType = { }) = 0;
     139    virtual bool readFilePath(const String&, PresentationSize preferredPresentationSize = { }, const String& contentType = { }) = 0;
    140140    virtual bool readFilePaths(const Vector<String>&) = 0;
    141141    virtual bool readHTML(const String&) = 0;
    142142    virtual bool readRTFD(SharedBuffer&) = 0;
    143143    virtual bool readRTF(SharedBuffer&) = 0;
    144     virtual bool readImage(Ref<SharedBuffer>&&, const String& type, Optional<FloatSize> preferredPresentationSize = { }) = 0;
     144    virtual bool readImage(Ref<SharedBuffer>&&, const String& type, PresentationSize preferredPresentationSize = { }) = 0;
    145145    virtual bool readURL(const URL&, const String& title) = 0;
    146     virtual bool readDataBuffer(SharedBuffer&, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize = { }) = 0;
     146    virtual bool readDataBuffer(SharedBuffer&, const String& type, const String& name, PresentationSize preferredPresentationSize = { }) = 0;
    147147#endif
    148148    virtual bool readPlainText(const String&) = 0;
  • trunk/Source/WebCore/platform/PasteboardItemInfo.h

    r245637 r246207  
    3838};
    3939
     40struct PresentationSize {
     41    Optional<double> width;
     42    Optional<double> height;
     43
     44    template<class Encoder> void encode(Encoder&) const;
     45    template<class Decoder> static Optional<PresentationSize> decode(Decoder&);
     46};
     47
     48template<class Encoder>
     49void PresentationSize::encode(Encoder& encoder) const
     50{
     51    encoder << width << height;
     52}
     53
     54template<class Decoder>
     55Optional<PresentationSize> PresentationSize::decode(Decoder& decoder)
     56{
     57    PresentationSize result;
     58    if (!decoder.decode(result.width))
     59        return WTF::nullopt;
     60
     61    if (!decoder.decode(result.height))
     62        return WTF::nullopt;
     63
     64    return WTFMove(result);
     65}
     66
    4067struct PasteboardItemInfo {
    4168    Vector<String> pathsForFileUpload;
     
    4370    Vector<String> contentTypesByFidelity;
    4471    String suggestedFileName;
    45     Optional<FloatSize> preferredPresentationSize;
     72    PresentationSize preferredPresentationSize;
    4673    bool isNonTextType { false };
    4774    bool containsFileURLAndFileUploadContent { false };
  • trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm

    r245637 r246207  
    3232#import "Image.h"
    3333#import "Pasteboard.h"
     34#import "RuntimeApplicationChecks.h"
    3435#import "SharedBuffer.h"
    3536#import "UTIUtilities.h"
     
    156157    info.preferredPresentationStyle = pasteboardItemPresentationStyle(itemProvider.preferredPresentationStyle);
    157158#endif
    158     if (!CGSizeEqualToSize(itemProvider.preferredPresentationSize, CGSizeZero))
    159         info.preferredPresentationSize = FloatSize { itemProvider.preferredPresentationSize };
     159    if (!CGSizeEqualToSize(itemProvider.preferredPresentationSize, CGSizeZero)) {
     160        auto adjustedPreferredPresentationHeight = [](auto height) -> Optional<double> {
     161            if (!IOSApplication::isMobileMail())
     162                return { height };
     163            // 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.
     164            return { };
     165        };
     166        info.preferredPresentationSize = PresentationSize { itemProvider.preferredPresentationSize.width, adjustedPreferredPresentationHeight(itemProvider.preferredPresentationSize.height) };
     167    }
    160168    info.containsFileURLAndFileUploadContent = itemProvider.web_containsFileURLAndFileUploadContent;
    161169    info.suggestedFileName = itemProvider.suggestedName;
Note: See TracChangeset for help on using the changeset viewer.