⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 246209 in webkit


Ignore:
Timestamp:
Jun 7, 2019, 11:05:42 AM (7 years ago)
Author:
bshafiei@apple.com
Message:

Cherry-pick r246207. rdar://problem/51185518

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

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

Location:
branches/safari-608.1.27-branch/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-608.1.27-branch/Source/WebCore/ChangeLog

    r246208 r246209  
     12019-06-07  Babak Shafiei  <bshafiei@apple.com>
     2
     3        Cherry-pick r246207. rdar://problem/51185518
     4
     5    Images are not resizing correctly when dragged to a message in 1/3 view
     6    https://bugs.webkit.org/show_bug.cgi?id=198623
     7    <rdar://problem/51185518>
     8   
     9    Reviewed by Wenson Hsieh.
     10   
     11    Mail's max-width: 100%; default style is in conflict with the preferred presentation size. This patch preserves the existing behaviour for Mail by
     12    not setting the height (and rely on the width + aspect ratio).
     13   
     14    * editing/WebContentReader.h:
     15    * editing/cocoa/WebContentReaderCocoa.mm:
     16    (WebCore::createFragmentForImageAttachment):
     17    (WebCore::WebContentReader::readImage):
     18    (WebCore::attachmentForFilePath):
     19    (WebCore::attachmentForData):
     20    (WebCore::WebContentReader::readFilePath):
     21    (WebCore::WebContentReader::readDataBuffer):
     22    * editing/gtk/EditorGtk.cpp:
     23    (WebCore::createFragmentFromPasteboardData):
     24    * editing/markup.cpp:
     25    (WebCore::createFragmentForImageAndURL):
     26    * editing/markup.h:
     27    * platform/Pasteboard.h:
     28    (WebCore::PasteboardWebContentReader::readFilePath):
     29    (WebCore::PasteboardWebContentReader::readImage):
     30    (WebCore::PasteboardWebContentReader::readDataBuffer):
     31    * platform/PasteboardItemInfo.h:
     32    (WebCore::PasteboardItemInfo::encode const):
     33    (WebCore::PasteboardItemInfo::decode):
     34    * platform/ios/PasteboardIOS.mm:
     35    (WebCore::Pasteboard::readPasteboardWebContentDataForType):
     36    (WebCore::Pasteboard::read):
     37    (WebCore::Pasteboard::readRespectingUTIFidelities):
     38    * platform/ios/PlatformPasteboardIOS.mm:
     39    (WebCore::PlatformPasteboard::informationForItemAtIndex):
     40   
     41   
     42    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246207 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     43
     44    2019-06-07  Zalan Bujtas  <zalan@apple.com>
     45
     46            Images are not resizing correctly when dragged to a message in 1/3 view
     47            https://bugs.webkit.org/show_bug.cgi?id=198623
     48            <rdar://problem/51185518>
     49
     50            Reviewed by Wenson Hsieh.
     51
     52            Mail's max-width: 100%; default style is in conflict with the preferred presentation size. This patch preserves the existing behaviour for Mail by
     53            not setting the height (and rely on the width + aspect ratio).
     54
     55            * editing/WebContentReader.h:
     56            * editing/cocoa/WebContentReaderCocoa.mm:
     57            (WebCore::createFragmentForImageAttachment):
     58            (WebCore::WebContentReader::readImage):
     59            (WebCore::attachmentForFilePath):
     60            (WebCore::attachmentForData):
     61            (WebCore::WebContentReader::readFilePath):
     62            (WebCore::WebContentReader::readDataBuffer):
     63            * editing/gtk/EditorGtk.cpp:
     64            (WebCore::createFragmentFromPasteboardData):
     65            * editing/markup.cpp:
     66            (WebCore::createFragmentForImageAndURL):
     67            * editing/markup.h:
     68            * platform/Pasteboard.h:
     69            (WebCore::PasteboardWebContentReader::readFilePath):
     70            (WebCore::PasteboardWebContentReader::readImage):
     71            (WebCore::PasteboardWebContentReader::readDataBuffer):
     72            * platform/PasteboardItemInfo.h:
     73            (WebCore::PasteboardItemInfo::encode const):
     74            (WebCore::PasteboardItemInfo::decode):
     75            * platform/ios/PasteboardIOS.mm:
     76            (WebCore::Pasteboard::readPasteboardWebContentDataForType):
     77            (WebCore::Pasteboard::read):
     78            (WebCore::Pasteboard::readRespectingUTIFidelities):
     79            * platform/ios/PlatformPasteboardIOS.mm:
     80            (WebCore::PlatformPasteboard::informationForItemAtIndex):
     81
    1822019-06-07  Babak Shafiei  <bshafiei@apple.com>
    283
  • branches/safari-608.1.27-branch/Source/WebCore/editing/WebContentReader.h

    r245839 r246209  
    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; }
  • branches/safari-608.1.27-branch/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm

    r245839 r246209  
    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())
  • branches/safari-608.1.27-branch/Source/WebCore/editing/markup.cpp

    r245912 r246209  
    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);
  • branches/safari-608.1.27-branch/Source/WebCore/editing/markup.h

    r245681 r246209  
    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
  • branches/safari-608.1.27-branch/Source/WebCore/platform/Pasteboard.h

    r245839 r246209  
    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;
  • branches/safari-608.1.27-branch/Source/WebCore/platform/PasteboardItemInfo.h

    r245637 r246209  
    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 };
  • branches/safari-608.1.27-branch/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm

    r245637 r246209  
    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.