Changeset 245775 in webkit
- Timestamp:
- May 25, 2019 11:59:22 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r245774 r245775 1 2019-05-25 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] Respect -[NSItemProvider preferredPresentationSize] when dropping images 4 https://bugs.webkit.org/show_bug.cgi?id=198242 5 6 Reviewed by Beth Dakin. 7 8 Teach the web content reader to respect the -preferredPresentationSize when creating attachment-backed image 9 elements. See below for more details. 10 11 Test: WKAttachmentTestsIOS.InsertDroppedImageWithPreferredPresentationSize 12 13 * editing/WebContentReader.h: 14 * editing/cocoa/WebContentReaderCocoa.mm: 15 (WebCore::attachmentForFilePath): 16 (WebCore::attachmentForData): 17 18 When creating attachment-backed image elements, additionally set width and height attributes from the preferred 19 presentation size, if specified. 20 21 (WebCore::WebContentReader::readFilePath): 22 23 Add a version of readFilePath that takes a single file path, and an optional preferred presentation size. 24 25 (WebCore::WebContentReader::readFilePaths): 26 27 Reimplement readFilePaths in terms of readFilePath. 28 29 (WebCore::WebContentReader::readDataBuffer): 30 31 Add more plumbing for preferredPresentationSize. 32 33 * platform/Pasteboard.h: 34 (WebCore::PasteboardWebContentReader::readFilePath): 35 (WebCore::PasteboardWebContentReader::readDataBuffer): 36 * platform/ios/PasteboardIOS.mm: 37 (WebCore::Pasteboard::read): 38 (WebCore::Pasteboard::readRespectingUTIFidelities): 39 40 Forward PasteboardItemInfo's preferredPresentationSize to the web content reader. 41 1 42 2019-05-25 Antoine Quint <graouts@apple.com> 2 43 -
trunk/Source/WebCore/editing/WebContentReader.h
r245637 r245775 72 72 #if PLATFORM(COCOA) 73 73 bool readWebArchive(SharedBuffer&) override; 74 bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }) override; 74 75 bool readFilePaths(const Vector<String>&) override; 75 76 bool readHTML(const String&) override; … … 78 79 bool readImage(Ref<SharedBuffer>&&, const String& type, Optional<FloatSize> preferredPresentationSize = { }) override; 79 80 bool readURL(const URL&, const String& title) override; 80 bool readDataBuffer(SharedBuffer&, const String& type, const String& name ) override;81 bool readDataBuffer(SharedBuffer&, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize = { }) override; 81 82 #endif 82 83 bool readPlainText(const String&) override; … … 95 96 #if PLATFORM(COCOA) 96 97 bool readWebArchive(SharedBuffer&) override; 98 bool readFilePath(const String&, Optional<FloatSize> = { }) override { return false; } 97 99 bool readFilePaths(const Vector<String>&) override { return false; } 98 100 bool readHTML(const String&) override; … … 101 103 bool readImage(Ref<SharedBuffer>&&, const String&, Optional<FloatSize> = { }) override { return false; } 102 104 bool readURL(const URL&, const String&) override { return false; } 103 bool readDataBuffer(SharedBuffer&, const String&, const String& ) override { return false; }105 bool readDataBuffer(SharedBuffer&, const String&, const String&, Optional<FloatSize> = { }) override { return false; } 104 106 #endif 105 107 bool readPlainText(const String&) override { return false; } -
trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
r245637 r245775 696 696 #if ENABLE(ATTACHMENT_ELEMENT) 697 697 698 static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path )698 static Ref<HTMLElement> attachmentForFilePath(Frame& frame, const String& path, Optional<FloatSize> preferredSize) 699 699 { 700 700 auto document = makeRef(*frame.document()); … … 724 724 image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(path))); 725 725 image->setAttachmentElement(WTFMove(attachment)); 726 if (preferredSize) { 727 image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width())); 728 image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height())); 729 } 726 730 return image; 727 731 } … … 731 735 } 732 736 733 static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name )737 static Ref<HTMLElement> attachmentForData(Frame& frame, SharedBuffer& buffer, const String& contentType, const String& name, Optional<FloatSize> preferredSize) 734 738 { 735 739 auto document = makeRef(*frame.document()); … … 758 762 image->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document, File::create(Blob::create(buffer, WTFMove(typeForAttachmentElement)), WTFMove(fileName)))); 759 763 image->setAttachmentElement(WTFMove(attachment)); 764 if (preferredSize) { 765 image->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width())); 766 image->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height())); 767 } 760 768 return image; 761 769 } … … 767 775 #endif // ENABLE(ATTACHMENT_ELEMENT) 768 776 769 bool WebContentReader::readFilePath s(const Vector<String>& paths)770 { 771 if (path s.isEmpty() || !frame.document())777 bool WebContentReader::readFilePath(const String& path, Optional<FloatSize> preferredPresentationSize) 778 { 779 if (path.isEmpty() || !frame.document()) 772 780 return false; 773 781 … … 777 785 778 786 #if ENABLE(ATTACHMENT_ELEMENT) 779 if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) { 780 for (auto& path : paths) 781 fragment->appendChild(attachmentForFilePath(frame, path)); 782 } 783 #endif 787 if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) 788 fragment->appendChild(attachmentForFilePath(frame, path, preferredPresentationSize)); 789 #endif 790 791 return true; 792 } 793 794 bool WebContentReader::readFilePaths(const Vector<String>& paths) 795 { 796 if (paths.isEmpty() || !frame.document()) 797 return false; 798 799 for (auto& path : paths) 800 readFilePath(path); 784 801 785 802 return true; … … 817 834 } 818 835 819 bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name )836 bool WebContentReader::readDataBuffer(SharedBuffer& buffer, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize) 820 837 { 821 838 if (buffer.isEmpty()) … … 833 850 834 851 #if ENABLE(ATTACHMENT_ELEMENT) 835 fragment->appendChild(attachmentForData(frame, buffer, type, name ));852 fragment->appendChild(attachmentForData(frame, buffer, type, name, preferredPresentationSize)); 836 853 #else 837 854 UNUSED_PARAM(type); -
trunk/Source/WebCore/platform/Pasteboard.h
r245637 r245775 137 137 #if PLATFORM(COCOA) 138 138 virtual bool readWebArchive(SharedBuffer&) = 0; 139 virtual bool readFilePath(const String&, Optional<FloatSize> preferredPresentationSize = { }) = 0; 139 140 virtual bool readFilePaths(const Vector<String>&) = 0; 140 141 virtual bool readHTML(const String&) = 0; … … 143 144 virtual bool readImage(Ref<SharedBuffer>&&, const String& type, Optional<FloatSize> preferredPresentationSize = { }) = 0; 144 145 virtual bool readURL(const URL&, const String& title) = 0; 145 virtual bool readDataBuffer(SharedBuffer&, const String& type, const String& name ) = 0;146 virtual bool readDataBuffer(SharedBuffer&, const String& type, const String& name, Optional<FloatSize> preferredPresentationSize = { }) = 0; 146 147 #endif 147 148 virtual bool readPlainText(const String&) = 0; -
trunk/Source/WebCore/platform/ios/PasteboardIOS.mm
r245637 r245775 308 308 if (auto buffer = strategy.readBufferFromPasteboard(i, typeForFileUpload, m_pasteboardName)) { 309 309 readURLAlongsideAttachmentIfNecessary(reader, strategy, typeForFileUpload, m_pasteboardName, i); 310 reader.readDataBuffer(*buffer, typeForFileUpload, info.suggestedFileName );310 reader.readDataBuffer(*buffer, typeForFileUpload, info.suggestedFileName, info.preferredPresentationSize); 311 311 continue; 312 312 } … … 348 348 if (canReadAttachment && prefersAttachmentRepresentation(info)) { 349 349 readURLAlongsideAttachmentIfNecessary(reader, strategy, info.contentTypeForHighestFidelityItem(), m_pasteboardName, index); 350 reader.readFilePath s({ WTFMove(attachmentFilePath) });350 reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize); 351 351 continue; 352 352 } … … 367 367 #if ENABLE(ATTACHMENT_ELEMENT) 368 368 if (canReadAttachment && result == ReaderResult::DidNotReadType) 369 reader.readFilePath s({ WTFMove(attachmentFilePath) });369 reader.readFilePath(WTFMove(attachmentFilePath), info.preferredPresentationSize); 370 370 #endif 371 371 } -
trunk/Tools/ChangeLog
r245744 r245775 1 2019-05-25 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] Respect -[NSItemProvider preferredPresentationSize] when dropping images 4 https://bugs.webkit.org/show_bug.cgi?id=198242 5 6 Reviewed by Beth Dakin. 7 8 Add a new test that simulates dropping an image with a preferred presentation size into an editable element 9 with attachment elements enabled. 10 11 * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm: 12 (TestWebKitAPI::TEST): 13 1 14 2019-05-24 Yusuke Suzuki <ysuzuki@apple.com> 2 15 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm
r244251 r245775 1632 1632 } 1633 1633 1634 TEST(WKAttachmentTestsIOS, InsertDroppedImageWithPreferredPresentationSize) 1635 { 1636 auto webView = webViewForTestingAttachments(); 1637 auto dragAndDropSimulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]); 1638 auto item = adoptNS([[NSItemProvider alloc] init]); 1639 [item registerData:testImageData() type:(__bridge NSString *)kUTTypePNG]; 1640 [item setPreferredPresentationSize:CGSizeMake(200, 100)]; 1641 [dragAndDropSimulator setExternalItemProviders:@[ item.get() ]]; 1642 [dragAndDropSimulator runFrom:CGPointZero to:CGPointMake(50, 50)]; 1643 1644 CGSize imageElementSize = [webView imageElementSize]; 1645 EXPECT_EQ(200, imageElementSize.width); 1646 EXPECT_EQ(100, imageElementSize.height); 1647 } 1648 1634 1649 TEST(WKAttachmentTestsIOS, InsertDroppedAttributedStringContainingAttachment) 1635 1650 {
Note: See TracChangeset
for help on using the changeset viewer.