Changeset 245637 in webkit
- Timestamp:
- May 22, 2019, 12:13:34 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/editing/WebContentReader.h (modified) (2 diffs)
-
Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (modified) (3 diffs)
-
Source/WebCore/editing/gtk/EditorGtk.cpp (modified) (1 diff)
-
Source/WebCore/editing/markup.cpp (modified) (1 diff)
-
Source/WebCore/editing/markup.h (modified) (1 diff)
-
Source/WebCore/platform/Pasteboard.h (modified) (2 diffs)
-
Source/WebCore/platform/PasteboardItemInfo.h (modified) (3 diffs)
-
Source/WebCore/platform/ios/PasteboardIOS.mm (modified) (4 diffs)
-
Source/WebCore/platform/ios/PlatformPasteboardIOS.mm (modified) (1 diff)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r245636 r245637 1 2019-05-22 Zalan Bujtas <zalan@apple.com> 2 3 [Paste] Add support for preferred presentation size when pasting an image 4 https://bugs.webkit.org/show_bug.cgi?id=198132 5 <rdar://problem/50886917> 6 7 Reviewed by Wenson Hsieh. 8 9 Set the pasted <img> width/height attributes when the preferred presentation size is available. 10 11 * editing/WebContentReader.h: 12 * editing/cocoa/WebContentReaderCocoa.mm: 13 (WebCore::createFragmentForImageAttachment): 14 (WebCore::WebContentReader::readImage): 15 * editing/markup.cpp: 16 (WebCore::createFragmentForImageAndURL): 17 * editing/markup.h: 18 * platform/Pasteboard.h: 19 (WebCore::PasteboardWebContentReader::readImage): 20 * platform/PasteboardItemInfo.h: 21 (WebCore::PasteboardItemInfo::encode const): 22 (WebCore::PasteboardItemInfo::decode): 23 * platform/ios/PasteboardIOS.mm: 24 (WebCore::Pasteboard::readPasteboardWebContentDataForType): 25 (WebCore::Pasteboard::read): 26 (WebCore::Pasteboard::readRespectingUTIFidelities): 27 * platform/ios/PlatformPasteboardIOS.mm: 28 (WebCore::PlatformPasteboard::informationForItemAtIndex): 29 1 30 2019-05-22 Jer Noble <jer.noble@apple.com> 2 31 -
trunk/Source/WebCore/editing/WebContentReader.h
r243695 r245637 76 76 bool readRTFD(SharedBuffer&) override; 77 77 bool readRTF(SharedBuffer&) override; 78 bool readImage(Ref<SharedBuffer>&&, const String& type ) override;78 bool readImage(Ref<SharedBuffer>&&, const String& type, Optional<FloatSize> preferredPresentationSize = { }) override; 79 79 bool readURL(const URL&, const String& title) override; 80 80 bool readDataBuffer(SharedBuffer&, const String& type, const String& name) override; … … 99 99 bool readRTFD(SharedBuffer&) override; 100 100 bool readRTF(SharedBuffer&) override; 101 bool readImage(Ref<SharedBuffer>&&, const String& ) override { return false; }101 bool readImage(Ref<SharedBuffer>&&, const String&, Optional<FloatSize> = { }) override { return false; } 102 102 bool readURL(const URL&, const String&) override { return false; } 103 103 bool readDataBuffer(SharedBuffer&, const String&, const String&) override { return false; } -
trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
r245508 r245637 248 248 #endif 249 249 250 static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Document& document, Ref<SharedBuffer>&& buffer, const String& contentType )250 static Ref<DocumentFragment> createFragmentForImageAttachment(Frame& frame, Document& document, Ref<SharedBuffer>&& buffer, const String& contentType, Optional<FloatSize> 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 268 fragment->appendChild(WTFMove(image)); 265 269 } else { … … 678 682 } 679 683 680 bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type )684 bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type, Optional<FloatSize> preferredPresentationSize) 681 685 { 682 686 ASSERT(frame.document()); 683 687 auto& document = *frame.document(); 684 688 if (shouldReplaceRichContentWithAttachments()) 685 addFragment(createFragmentForImageAttachment(frame, document, WTFMove(buffer), type ));689 addFragment(createFragmentForImageAttachment(frame, document, WTFMove(buffer), type, preferredPresentationSize)); 686 690 else 687 addFragment(createFragmentForImageAndURL(document, DOMURL::createObjectURL(document, Blob::create(buffer.get(), type)) ));691 addFragment(createFragmentForImageAndURL(document, DOMURL::createObjectURL(document, Blob::create(buffer.get(), type)), preferredPresentationSize)); 688 692 689 693 return fragment; -
trunk/Source/WebCore/editing/gtk/EditorGtk.cpp
r236785 r245637 70 70 if (!frame.document()) 71 71 return nullptr; 72 return createFragmentForImageAndURL(*frame.document(), DOMURL::createObjectURL(*frame.document(), blob) );72 return createFragmentForImageAndURL(*frame.document(), DOMURL::createObjectURL(*frame.document(), blob), { }); 73 73 } 74 74 } -
trunk/Source/WebCore/editing/markup.cpp
r245508 r245637 1228 1228 } 1229 1229 1230 Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url )1230 Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url, Optional<FloatSize> preferredSize) 1231 1231 { 1232 1232 auto imageElement = HTMLImageElement::create(document); 1233 1233 imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, url); 1234 if (preferredSize) { 1235 imageElement->setAttributeWithoutSynchronization(HTMLNames::widthAttr, AtomicString::number(preferredSize->width())); 1236 imageElement->setAttributeWithoutSynchronization(HTMLNames::heightAttr, AtomicString::number(preferredSize->height())); 1237 } 1234 1238 1235 1239 auto fragment = document.createDocumentFragment(); -
trunk/Source/WebCore/editing/markup.h
r239427 r245637 60 60 ExceptionOr<Ref<DocumentFragment>> createFragmentForInnerOuterHTML(Element&, const String& markup, ParserContentPolicy); 61 61 RefPtr<DocumentFragment> createFragmentForTransformToFragment(Document&, const String& sourceString, const String& sourceMIMEType); 62 Ref<DocumentFragment> createFragmentForImageAndURL(Document&, const String& );62 Ref<DocumentFragment> createFragmentForImageAndURL(Document&, const String&, Optional<FloatSize> preferredSize); 63 63 ExceptionOr<Ref<DocumentFragment>> createContextualFragment(Element&, const String& markup, ParserContentPolicy); 64 64 -
trunk/Source/WebCore/platform/Pasteboard.h
r243695 r245637 141 141 virtual bool readRTFD(SharedBuffer&) = 0; 142 142 virtual bool readRTF(SharedBuffer&) = 0; 143 virtual bool readImage(Ref<SharedBuffer>&&, const String& type ) = 0;143 virtual bool readImage(Ref<SharedBuffer>&&, const String& type, Optional<FloatSize> preferredPresentationSize = { }) = 0; 144 144 virtual bool readURL(const URL&, const String& title) = 0; 145 145 virtual bool readDataBuffer(SharedBuffer&, const String& type, const String& name) = 0; … … 289 289 PasteboardWasChangedExternally 290 290 }; 291 ReaderResult readPasteboardWebContentDataForType(PasteboardWebContentReader&, PasteboardStrategy&, NSString *type, int itemIndex);291 ReaderResult readPasteboardWebContentDataForType(PasteboardWebContentReader&, PasteboardStrategy&, NSString *type, const PasteboardItemInfo&, int itemIndex); 292 292 #endif 293 293 -
trunk/Source/WebCore/platform/PasteboardItemInfo.h
r243713 r245637 43 43 Vector<String> contentTypesByFidelity; 44 44 String suggestedFileName; 45 Optional<FloatSize> preferredPresentationSize; 45 46 bool isNonTextType { false }; 46 47 bool containsFileURLAndFileUploadContent { false }; … … 98 99 void PasteboardItemInfo::encode(Encoder& encoder) const 99 100 { 100 encoder << pathsForFileUpload << contentTypesForFileUpload << contentTypesByFidelity << suggestedFileName << isNonTextType << containsFileURLAndFileUploadContent;101 encoder << pathsForFileUpload << contentTypesForFileUpload << contentTypesByFidelity << suggestedFileName << preferredPresentationSize << isNonTextType << containsFileURLAndFileUploadContent; 101 102 encoder.encodeEnum(preferredPresentationStyle); 102 103 } … … 116 117 117 118 if (!decoder.decode(result.suggestedFileName)) 119 return WTF::nullopt; 120 121 if (!decoder.decode(result.preferredPresentationSize)) 118 122 return WTF::nullopt; 119 123 -
trunk/Source/WebCore/platform/ios/PasteboardIOS.mm
r243713 r245637 182 182 } 183 183 184 Pasteboard::ReaderResult Pasteboard::readPasteboardWebContentDataForType(PasteboardWebContentReader& reader, PasteboardStrategy& strategy, NSString *type, int itemIndex)184 Pasteboard::ReaderResult Pasteboard::readPasteboardWebContentDataForType(PasteboardWebContentReader& reader, PasteboardStrategy& strategy, NSString *type, const PasteboardItemInfo& itemInfo, int itemIndex) 185 185 { 186 186 if ([type isEqualToString:WebArchivePboardType] || [type isEqualToString:(__bridge NSString *)kUTTypeWebArchive]) { … … 226 226 if (m_changeCount != changeCount()) 227 227 return ReaderResult::PasteboardWasChangedExternally; 228 return buffer && reader.readImage(buffer.releaseNonNull(), type ) ? ReaderResult::ReadType : ReaderResult::DidNotReadType;228 return buffer && reader.readImage(buffer.releaseNonNull(), type, itemInfo.preferredPresentationSize) ? ReaderResult::ReadType : ReaderResult::DidNotReadType; 229 229 } 230 230 … … 319 319 continue; 320 320 321 auto itemResult = readPasteboardWebContentDataForType(reader, strategy, type, i );321 auto itemResult = readPasteboardWebContentDataForType(reader, strategy, type, info, i); 322 322 if (itemResult == ReaderResult::PasteboardWasChangedExternally) 323 323 return; … … 359 359 continue; 360 360 361 result = readPasteboardWebContentDataForType(reader, strategy, type, in dex);361 result = readPasteboardWebContentDataForType(reader, strategy, type, info, index); 362 362 if (result == ReaderResult::PasteboardWasChangedExternally) 363 363 return; -
trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
r244953 r245637 156 156 info.preferredPresentationStyle = pasteboardItemPresentationStyle(itemProvider.preferredPresentationStyle); 157 157 #endif 158 if (!CGSizeEqualToSize(itemProvider.preferredPresentationSize, CGSizeZero)) 159 info.preferredPresentationSize = FloatSize { itemProvider.preferredPresentationSize }; 158 160 info.containsFileURLAndFileUploadContent = itemProvider.web_containsFileURLAndFileUploadContent; 159 161 info.suggestedFileName = itemProvider.suggestedName; -
trunk/Source/WebKit/ChangeLog
r245625 r245637 1 2019-05-22 Zalan Bujtas <zalan@apple.com> 2 3 [Paste] Add support for preferred presentation size when pasting an image 4 https://bugs.webkit.org/show_bug.cgi?id=198132 5 <rdar://problem/50886917> 6 7 Reviewed by Wenson Hsieh. 8 9 * UIProcess/API/Cocoa/_WKElementAction.mm: 10 (addToReadingList): 11 * UIProcess/ios/WKActionSheetAssistant.mm: 12 (-[WKActionSheetAssistant defaultActionsForLinkSheet:]): 13 (-[WKActionSheetAssistant defaultActionsForImageSheet:]): 14 1 15 2019-05-22 Youenn Fablet <youenn@apple.com> 2 16 -
trunk/Tools/ChangeLog
r245635 r245637 1 2019-05-22 Zalan Bujtas <zalan@apple.com> 2 3 [Paste] Add support for preferred presentation size when pasting an image 4 https://bugs.webkit.org/show_bug.cgi?id=198132 5 <rdar://problem/50886917> 6 7 Reviewed by Wenson Hsieh. 8 9 * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm: 10 (TestWebKitAPI::TEST): 11 1 12 2019-05-22 Keith Rollin <krollin@apple.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm
r244955 r245637 303 303 } 304 304 305 TEST(UIPasteboardTests, ValidPreferredPresentationSizeForImage) 306 { 307 auto webView = setUpWebViewForPasteboardTests(@"autofocus-contenteditable"); 308 auto itemProvider = adoptNS([[NSItemProvider alloc] init]); 309 [itemProvider setPreferredPresentationSize:CGSizeMake(10, 20)]; 310 [itemProvider registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypePNG visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[] (DataLoadCompletionBlock completionHandler) -> NSProgress * { 311 completionHandler([NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]], nil); 312 return nil; 313 }]; 314 [UIPasteboard generalPasteboard].itemProviders = @[ itemProvider.get() ]; 315 [webView paste:nil]; 316 317 EXPECT_WK_STREQ("10", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').width"]); 318 EXPECT_WK_STREQ("20", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').height"]); 319 } 320 321 TEST(UIPasteboardTests, InvalidPreferredPresentationSizeForImage) 322 { 323 auto webView = setUpWebViewForPasteboardTests(@"autofocus-contenteditable"); 324 auto itemProvider = adoptNS([[NSItemProvider alloc] init]); 325 [itemProvider setPreferredPresentationSize:CGSizeMake(-10, -20)]; 326 [itemProvider registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypePNG visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[] (DataLoadCompletionBlock completionHandler) -> NSProgress * { 327 completionHandler([NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]], nil); 328 return nil; 329 }]; 330 [UIPasteboard generalPasteboard].itemProviders = @[ itemProvider.get() ]; 331 [webView paste:nil]; 332 333 EXPECT_WK_STREQ("0", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').width"]); 334 EXPECT_WK_STREQ("174", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').height"]); 335 } 336 337 TEST(UIPasteboardTests, MissingPreferredPresentationSizeForImage) 338 { 339 auto webView = setUpWebViewForPasteboardTests(@"autofocus-contenteditable"); 340 auto itemProvider = adoptNS([[NSItemProvider alloc] init]); 341 [itemProvider registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypePNG visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[] (DataLoadCompletionBlock completionHandler) -> NSProgress * { 342 completionHandler([NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]], nil); 343 return nil; 344 }]; 345 [UIPasteboard generalPasteboard].itemProviders = @[ itemProvider.get() ]; 346 [webView paste:nil]; 347 348 EXPECT_WK_STREQ("0", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').width"]); 349 EXPECT_WK_STREQ("174", [webView stringByEvaluatingJavaScript:@"document.querySelector('img').height"]); 350 } 305 351 #endif // PLATFORM(IOS) 306 352
Note:
See TracChangeset
for help on using the changeset viewer.