Changeset 246207 in webkit
- Timestamp:
- Jun 7, 2019 10:50:49 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r246206 r246207 1 2019-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 1 39 2019-06-07 Zalan Bujtas <zalan@apple.com> 2 40 -
trunk/Source/WebCore/editing/WebContentReader.h
r245839 r246207 72 72 #if PLATFORM(COCOA) 73 73 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; 75 75 bool readFilePaths(const Vector<String>&) override; 76 76 bool readHTML(const String&) override; 77 77 bool readRTFD(SharedBuffer&) override; 78 78 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; 80 80 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; 82 82 #endif 83 83 bool readPlainText(const String&) override; … … 96 96 #if PLATFORM(COCOA) 97 97 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; } 99 99 bool readFilePaths(const Vector<String>&) override { return false; } 100 100 bool readHTML(const String&) override; 101 101 bool readRTFD(SharedBuffer&) override; 102 102 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; } 104 104 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; } 106 106 #endif 107 107 bool readPlainText(const String&) override { return false; } -
trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
r245839 r246207 248 248 #endif 249 249 250 static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Document& document, Ref<SharedBuffer>&& buffer, const String& contentType, Optional<FloatSize>preferredSize)250 static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Document& document, Ref<SharedBuffer>&& buffer, const String& contentType, PresentationSize preferredSize) 251 251 { 252 252 #if ENABLE(ATTACHMENT_ELEMENT) … … 262 262 image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, Blob::create(buffer.get(), contentType))); 263 263 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)); 268 268 fragment->appendChild(WTFMove(image)); 269 269 } else { … … 682 682 } 683 683 684 bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type, Optional<FloatSize>preferredPresentationSize)684 bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type, PresentationSize preferredPresentationSize) 685 685 { 686 686 ASSERT(frame.document()); … … 705 705 } 706 706 707 static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, Optional<FloatSize>preferredSize, const String& explicitContentType)707 static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, PresentationSize preferredSize, const String& explicitContentType) 708 708 { 709 709 auto document = makeRef(*frame.document()); … … 739 739 image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(path))); 740 740 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)); 745 745 return image; 746 746 } … … 750 750 } 751 751 752 static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name, Optional<FloatSize>preferredSize)752 static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name, PresentationSize preferredSize) 753 753 { 754 754 auto document = makeRef(*frame.document()); … … 776 776 image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(Blob::create(buffer, WTFMove(attachmentType)), WTFMove(fileName)))); 777 777 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)); 782 782 return image; 783 783 } … … 789 789 #endif // ENABLE(ATTACHMENT_ELEMENT) 790 790 791 bool WebContentReader::readFilePath(const String& path, Optional<FloatSize>preferredPresentationSize, const String& contentType)791 bool WebContentReader::readFilePath(const String& path, PresentationSize preferredPresentationSize, const String& contentType) 792 792 { 793 793 if (path.isEmpty() || !frame.document()) … … 848 848 } 849 849 850 bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name, Optional<FloatSize>preferredPresentationSize)850 bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name, PresentationSize preferredPresentationSize) 851 851 { 852 852 if (buffer.isEmpty()) -
trunk/Source/WebCore/editing/markup.cpp
r245912 r246207 1237 1237 } 1238 1238 1239 Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url, Optional<FloatSize>preferredSize)1239 Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url, PresentationSize preferredSize) 1240 1240 { 1241 1241 auto imageElement = HTMLImageElement::create(document); 1242 1242 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)); 1248 1247 auto fragment = document.createDocumentFragment(); 1249 1248 fragment->appendChild(imageElement); -
trunk/Source/WebCore/editing/markup.h
r245681 r246207 45 45 class Node; 46 46 class Page; 47 struct PresentationSize; 47 48 class QualifiedName; 48 49 class Range; … … 61 62 ExceptionOr<Ref<DocumentFragment>> createFragmentForInnerOuterHTML(Element&, const String& markup, ParserContentPolicy); 62 63 RefPtr<DocumentFragment> createFragmentForTransformToFragment(Document&, const String& sourceString, const String& sourceMIMEType); 63 Ref<DocumentFragment> createFragmentForImageAndURL(Document&, const String&, Optional<FloatSize>preferredSize);64 Ref<DocumentFragment> createFragmentForImageAndURL(Document&, const String&, PresentationSize preferredSize); 64 65 ExceptionOr<Ref<DocumentFragment>> createContextualFragment(Element&, const String& markup, ParserContentPolicy); 65 66 -
trunk/Source/WebCore/platform/Pasteboard.h
r245839 r246207 137 137 #if PLATFORM(COCOA) 138 138 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; 140 140 virtual bool readFilePaths(const Vector<String>&) = 0; 141 141 virtual bool readHTML(const String&) = 0; 142 142 virtual bool readRTFD(SharedBuffer&) = 0; 143 143 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; 145 145 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; 147 147 #endif 148 148 virtual bool readPlainText(const String&) = 0; -
trunk/Source/WebCore/platform/PasteboardItemInfo.h
r245637 r246207 38 38 }; 39 39 40 struct 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 48 template<class Encoder> 49 void PresentationSize::encode(Encoder& encoder) const 50 { 51 encoder << width << height; 52 } 53 54 template<class Decoder> 55 Optional<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 40 67 struct PasteboardItemInfo { 41 68 Vector<String> pathsForFileUpload; … … 43 70 Vector<String> contentTypesByFidelity; 44 71 String suggestedFileName; 45 Optional<FloatSize>preferredPresentationSize;72 PresentationSize preferredPresentationSize; 46 73 bool isNonTextType { false }; 47 74 bool containsFileURLAndFileUploadContent { false }; -
trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
r245637 r246207 32 32 #import "Image.h" 33 33 #import "Pasteboard.h" 34 #import "RuntimeApplicationChecks.h" 34 35 #import "SharedBuffer.h" 35 36 #import "UTIUtilities.h" … … 156 157 info.preferredPresentationStyle = pasteboardItemPresentationStyle(itemProvider.preferredPresentationStyle); 157 158 #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 } 160 168 info.containsFileURLAndFileUploadContent = itemProvider.web_containsFileURLAndFileUploadContent; 161 169 info.suggestedFileName = itemProvider.suggestedName;
Note: See TracChangeset
for help on using the changeset viewer.