WebKit Bugzilla
Attachment 371589 Details for
Bug 198623
: Images are not resizing correctly when dragged to a message in 1/3 view
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-198623-20190607094456.patch (text/plain), 18.86 KB, created by
zalan
on 2019-06-07 09:44:56 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
zalan
Created:
2019-06-07 09:44:56 PDT
Size:
18.86 KB
patch
obsolete
>Subversion Revision: 246067 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index ce97d1d8dfb9d3d9c0cdb9e031f2b073905c6594..cc32fcbbee3f7cacf309ed9af918f10206fe5b19 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,41 @@ >+2019-06-06 Zalan Bujtas <zalan@apple.com> >+ >+ 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 NOBODY (OOPS!). >+ >+ 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-04 Zalan Bujtas <zalan@apple.com> > > [LFC][IFC] Decouple float placement and line shrinking >diff --git a/Source/WebCore/editing/WebContentReader.h b/Source/WebCore/editing/WebContentReader.h >index 2b9e99999cb778591a60ac0d3d96aebbaadef1c4..87f45550309b595298050b1d595705fbdc79718b 100644 >--- a/Source/WebCore/editing/WebContentReader.h >+++ b/Source/WebCore/editing/WebContentReader.h >@@ -71,14 +71,14 @@ public: > 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 @@ public: > 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; } > }; >diff --git a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >index be85b0ab30a3ba7873d6aabc60ba54ab334f2068..bf29a86c491ef39ac45fc28d892fb7fe483df499 100644 >--- a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >+++ b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm >@@ -247,7 +247,7 @@ static bool supportsClientSideAttachmentData(const Frame& frame) > > #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 @@ static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Docu > 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 @@ bool WebContentReader::readPlainText(const String& text) > 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 @@ static String typeForAttachmentElement(const String& contentType) > 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 @@ static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, > 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 @@ static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, > 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 @@ static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, co > 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 @@ static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, co > > #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 @@ bool WebContentReader::readURL(const URL& url, const String& title) > 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; >diff --git a/Source/WebCore/editing/markup.cpp b/Source/WebCore/editing/markup.cpp >index d9ecf15967eafc0ef1dfeaf25a70084dd0e63db8..cac009732125cc899590e4b44a645ec4eff17905 100644 >--- a/Source/WebCore/editing/markup.cpp >+++ b/Source/WebCore/editing/markup.cpp >@@ -1236,15 +1236,14 @@ RefPtr<DocumentFragment> createFragmentForTransformToFragment(Document& outputDo > 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); > >diff --git a/Source/WebCore/editing/markup.h b/Source/WebCore/editing/markup.h >index e8696bb142b5306c245af2a90e5de0d344538425..a5eb8244fe49d414c4385df52703e857827ff45f 100644 >--- a/Source/WebCore/editing/markup.h >+++ b/Source/WebCore/editing/markup.h >@@ -44,6 +44,7 @@ class Frame; > class HTMLElement; > class Node; > class Page; >+struct PresentationSize; > class QualifiedName; > class Range; > class VisibleSelection; >@@ -60,7 +61,7 @@ WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromText(Range& context, cons > 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*); >diff --git a/Source/WebCore/platform/Pasteboard.h b/Source/WebCore/platform/Pasteboard.h >index 97eeb1f510fcc3b16d2fea0e77a40fbd59a19dfa..2877cedbe60826cc20850c9171eb8965d5a943aa 100644 >--- a/Source/WebCore/platform/Pasteboard.h >+++ b/Source/WebCore/platform/Pasteboard.h >@@ -136,14 +136,14 @@ public: > > #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; > }; >diff --git a/Source/WebCore/platform/PasteboardItemInfo.h b/Source/WebCore/platform/PasteboardItemInfo.h >index 903996245e85567147f24da93adc6e1a3cbf4903..d1d2308ad995acf9c7a5f53ded9fd2a080eecf75 100644 >--- a/Source/WebCore/platform/PasteboardItemInfo.h >+++ b/Source/WebCore/platform/PasteboardItemInfo.h >@@ -37,12 +37,39 @@ enum class PasteboardItemPresentationStyle { > 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 }; >diff --git a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm b/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >index 8a86e4a4007dd5038eff308057fc07bc22597a24..2f539743d1c31965e8f405f6cb4c8b52d6c91d77 100644 >--- a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >+++ b/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >@@ -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 @@ PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(int index) > #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;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198623
:
371527
| 371589