Changeset 234885 in webkit
- Timestamp:
- Aug 15, 2018 7:26:05 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r234884 r234885 1 2018-08-15 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Attachment SPI] Remove attachment display mode options 4 https://bugs.webkit.org/show_bug.cgi?id=188596 5 6 Reviewed by Dan Bernstein. 7 8 Remove a layout test which verified that attachment elements with `-webkit-appearance: none` would render 9 child elements. This was only used to implement in-place attachment display modes. 10 11 * fast/attachment/attachment-without-appearance-expected.html: Removed. 12 * fast/attachment/attachment-without-appearance.html: Removed. 13 * platform/gtk/TestExpectations: 14 1 15 2018-08-15 Ali Juma <ajuma@chromium.org> 2 16 -
trunk/LayoutTests/platform/gtk/TestExpectations
r234821 r234885 3386 3386 webkit.org/b/179052 compositing/contents-format/subpixel-antialiased-nested-layer.html [ Failure ] 3387 3387 3388 webkit.org/b/180371 fast/attachment/attachment-without-appearance.html [ ImageOnlyFailure ]3389 3390 3388 webkit.org/b/180749 http/wpt/offscreen-canvas/transferToImageBitmap-webgl.html [ ImageOnlyFailure ] 3391 3389 -
trunk/Source/WebCore/ChangeLog
r234884 r234885 1 2018-08-15 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Attachment SPI] Remove attachment display mode options 4 https://bugs.webkit.org/show_bug.cgi?id=188596 5 6 Reviewed by Dan Bernstein. 7 8 Remove the ability to specify an "in-place" or "icon" representation for attachment elements, as well as logic 9 needed to allow an attachment element to render image or video elements in a shadow root. The requirements that 10 initially drove this effort are obviated by r227068, which allows Mail to intercept and provide a custom scheme 11 for images inserted into the document via rich editing operations. 12 13 Removed some existing API tests in _WKAttachmentTests that exercised this functionality. 14 15 * editing/Editor.cpp: 16 (WebCore::Editor::insertAttachmentFromFile): 17 * editing/cocoa/WebContentReaderCocoa.mm: 18 (WebCore::createFragmentForImageAttachment): 19 (WebCore::replaceRichContentWithAttachments): 20 * html/AttachmentTypes.h: 21 (WebCore::AttachmentDisplayOptions::encode const): 22 (WebCore::AttachmentDisplayOptions::decode): 23 24 Remove logic for encoding the attachment display mode. While this leaves AttachmentDisplayOptions completely 25 empty, I haven't removed AttachmentDisplayOptions as well in this patch, since it's not clear that we won't be 26 needing any mechanism for influencing the display of attachment elements inserted via native SPI. 27 28 (): Deleted. 29 * html/HTMLAttachmentElement.cpp: 30 (WebCore::HTMLAttachmentElement::createElementRenderer): 31 (WebCore::HTMLAttachmentElement::setFile): 32 (WebCore::HTMLAttachmentElement::parseAttribute): 33 (WebCore::HTMLAttachmentElement::invalidateShadowRootChildrenIfNecessary): Deleted. 34 (WebCore::HTMLAttachmentElement::attachmentRenderer const): Deleted. 35 (WebCore::HTMLAttachmentElement::updateDisplayMode): Deleted. 36 (WebCore::HTMLAttachmentElement::ensureInnerImage): Deleted. 37 (WebCore::HTMLAttachmentElement::ensureInnerVideo): Deleted. 38 (WebCore::HTMLAttachmentElement::innerImage const): Deleted. 39 (WebCore::HTMLAttachmentElement::innerVideo const): Deleted. 40 (WebCore::HTMLAttachmentElement::populateShadowRootIfNecessary): Deleted. 41 42 Remove logic for building the shadow root to house inline media elements. 43 44 * html/HTMLAttachmentElement.h: 45 46 The renderer of the attachment element is once again always a `RenderAttachment`, so we can remove 47 `attachmentRenderer()` altogether and revert to overriding `renderer()` to return a `RenderAttachment*`. 48 49 * page/DragController.cpp: 50 (WebCore::DragController::startDrag): 51 * rendering/RenderAttachment.h: 52 (WebCore::HTMLAttachmentElement::renderer const): 53 1 54 2018-08-15 Ali Juma <ajuma@chromium.org> 2 55 -
trunk/Source/WebCore/editing/Editor.cpp
r234808 r234885 3874 3874 } 3875 3875 3876 void Editor::insertAttachmentFromFile(const String& identifier, const AttachmentDisplayOptions& options, const String& filename, const String& contentType, Ref<File>&& file)3876 void Editor::insertAttachmentFromFile(const String& identifier, const AttachmentDisplayOptions&, const String& filename, const String& contentType, Ref<File>&& file) 3877 3877 { 3878 3878 auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document()); … … 3882 3882 attachment->setUniqueIdentifier(identifier); 3883 3883 attachment->setFile(WTFMove(file)); 3884 attachment->updateDisplayMode(options.mode);3885 3884 3886 3885 auto fragmentToInsert = document().createDocumentFragment(); -
trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
r234348 r234885 210 210 auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document); 211 211 attachment->setFile(File::create(blob, AtomicString("image")), HTMLAttachmentElement::UpdateDisplayAttributes::Yes); 212 attachment->updateDisplayMode(AttachmentDisplayMode::InPlace);213 212 214 213 auto fragment = document.createDocumentFragment(); … … 226 225 #if ENABLE(ATTACHMENT_ELEMENT) 227 226 struct AttachmentReplacementInfo { 228 AttachmentDisplayMode displayMode;229 227 Ref<File> file; 230 228 Ref<Element> elementToReplace; … … 258 256 title = AtomicString("media"); 259 257 260 attachmentReplacementInfo.append({ AttachmentDisplayMode::InPlace,File::create(*blob, title), image });258 attachmentReplacementInfo.append({ File::create(*blob, title), image }); 261 259 } 262 260 … … 278 276 title = AtomicString("file"); 279 277 280 attachmentReplacementInfo.append({ AttachmentDisplayMode::AsIcon,File::create(*blob, title), object });278 attachmentReplacementInfo.append({ File::create(*blob, title), object }); 281 279 } 282 280 … … 290 288 auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, fragment.document()); 291 289 attachment->setFile(WTFMove(file), HTMLAttachmentElement::UpdateDisplayAttributes::Yes); 292 attachment->updateDisplayMode(info.displayMode);293 290 parent->replaceChild(attachment, elementToReplace); 294 291 } -
trunk/Source/WebCore/html/AttachmentTypes.h
r226604 r234885 35 35 class SharedBuffer; 36 36 37 enum class AttachmentDisplayMode {38 Auto,39 InPlace,40 AsIcon41 };42 43 37 struct AttachmentDisplayOptions { 44 AttachmentDisplayMode mode { AttachmentDisplayMode::Auto };45 46 38 template<class Encoder> void encode(Encoder&) const; 47 39 template<class Decoder> static std::optional<AttachmentDisplayOptions> decode(Decoder&); … … 50 42 template<class Encoder> inline void AttachmentDisplayOptions::encode(Encoder& encoder) const 51 43 { 52 encoder.encodeEnum(mode);44 UNUSED_PARAM(encoder); 53 45 } 54 46 55 47 template<class Decoder> inline std::optional<AttachmentDisplayOptions> AttachmentDisplayOptions::decode(Decoder& decoder) 56 48 { 57 AttachmentDisplayMode mode; 58 if (!decoder.decodeEnum(mode)) 59 return std::nullopt; 60 61 return {{ mode }}; 49 UNUSED_PARAM(decoder); 50 return AttachmentDisplayOptions(); 62 51 } 63 52 -
trunk/Source/WebCore/html/HTMLAttachmentElement.cpp
r229694 r234885 36 36 #include "FileReaderLoaderClient.h" 37 37 #include "Frame.h" 38 #include "HTMLImageElement.h"39 38 #include "HTMLNames.h" 40 #include "HTMLVideoElement.h"41 #include "MIMETypeRegistry.h"42 39 #include "RenderAttachment.h" 43 #include "RenderBlockFlow.h"44 #include "ShadowRoot.h"45 40 #include "SharedBuffer.h" 46 41 #include <pal/FileSizeFormatter.h> 47 42 #include <wtf/IsoMallocInlines.h> 48 49 #if PLATFORM(COCOA)50 #include "UTIUtilities.h"51 #endif52 43 53 44 namespace WebCore { … … 102 93 RenderPtr<RenderElement> HTMLAttachmentElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) 103 94 { 104 if (!style.hasAppearance()) {105 // If this attachment element doesn't have an appearance, defer rendering to child elements.106 return createRenderer<RenderBlockFlow>(*this, WTFMove(style));107 }108 109 95 return createRenderer<RenderAttachment>(*this, WTFMove(style)); 110 96 } … … 136 122 } 137 123 138 if (auto* renderAttachment = attachmentRenderer()) 139 renderAttachment->invalidate(); 140 141 invalidateShadowRootChildrenIfNecessary(); 142 populateShadowRootIfNecessary(); 143 } 144 145 void HTMLAttachmentElement::invalidateShadowRootChildrenIfNecessary() 146 { 147 if (auto image = innerImage()) { 148 image->setAttributeWithoutSynchronization(srcAttr, emptyString()); 149 image->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true); 150 } 151 if (auto video = innerVideo()) { 152 video->setAttributeWithoutSynchronization(srcAttr, emptyString()); 153 video->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true); 154 } 155 } 156 157 RenderAttachment* HTMLAttachmentElement::attachmentRenderer() const 158 { 159 auto* renderer = this->renderer(); 160 return is<RenderAttachment>(renderer) ? downcast<RenderAttachment>(renderer) : nullptr; 124 if (auto* renderer = this->renderer()) 125 renderer->invalidate(); 161 126 } 162 127 … … 179 144 { 180 145 if (name == progressAttr || name == subtitleAttr || name == titleAttr || name == typeAttr) { 181 if (auto* render Attachment = attachmentRenderer())182 render Attachment->invalidate();146 if (auto* renderer = this->renderer()) 147 renderer->invalidate(); 183 148 } 184 149 … … 204 169 } 205 170 206 void HTMLAttachmentElement::updateDisplayMode(AttachmentDisplayMode mode)207 {208 mode = mode == AttachmentDisplayMode::Auto ? defaultDisplayMode() : mode;209 210 switch (mode) {211 case AttachmentDisplayMode::InPlace:212 populateShadowRootIfNecessary();213 setInlineStyleProperty(CSSPropertyWebkitAppearance, CSSValueNone, true);214 setInlineStyleProperty(CSSPropertyDisplay, CSSValueInlineBlock, true);215 break;216 case AttachmentDisplayMode::AsIcon:217 removeInlineStyleProperty(CSSPropertyWebkitAppearance);218 removeInlineStyleProperty(CSSPropertyDisplay);219 break;220 default:221 ASSERT_NOT_REACHED();222 break;223 }224 225 invalidateStyleAndRenderersForSubtree();226 }227 228 171 void HTMLAttachmentElement::updateFileWithData(Ref<SharedBuffer>&& data, std::optional<String>&& newContentType, std::optional<String>&& newFilename) 229 172 { … … 232 175 auto file = File::create(Blob::create(WTFMove(data), contentType), filename); 233 176 setFile(WTFMove(file), UpdateDisplayAttributes::Yes); 234 }235 236 Ref<HTMLImageElement> HTMLAttachmentElement::ensureInnerImage()237 {238 if (auto image = innerImage())239 return *image;240 241 auto image = HTMLImageElement::create(document());242 ensureUserAgentShadowRoot().appendChild(image);243 return image;244 }245 246 Ref<HTMLVideoElement> HTMLAttachmentElement::ensureInnerVideo()247 {248 if (auto video = innerVideo())249 return *video;250 251 auto video = HTMLVideoElement::create(document());252 ensureUserAgentShadowRoot().appendChild(video);253 return video;254 }255 256 RefPtr<HTMLImageElement> HTMLAttachmentElement::innerImage() const257 {258 if (auto root = userAgentShadowRoot())259 return childrenOfType<HTMLImageElement>(*root).first();260 return nullptr;261 }262 263 RefPtr<HTMLVideoElement> HTMLAttachmentElement::innerVideo() const264 {265 if (auto root = userAgentShadowRoot())266 return childrenOfType<HTMLVideoElement>(*root).first();267 return nullptr;268 }269 270 void HTMLAttachmentElement::populateShadowRootIfNecessary()271 {272 if (!m_file)273 return;274 275 auto mimeType = attachmentType();276 277 #if PLATFORM(COCOA)278 if (isDeclaredUTI(mimeType))279 mimeType = MIMETypeFromUTI(mimeType);280 #endif281 282 if (mimeType.isEmpty())283 return;284 285 if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType) || MIMETypeRegistry::isPDFMIMEType(mimeType)) {286 auto image = ensureInnerImage();287 if (image->attributeWithoutSynchronization(srcAttr).isEmpty()) {288 image->setAttributeWithoutSynchronization(srcAttr, DOMURL::createObjectURL(document(), *m_file));289 image->setAttributeWithoutSynchronization(draggableAttr, AtomicString("false"));290 image->setInlineStyleProperty(CSSPropertyDisplay, CSSValueInline, true);291 image->setInlineStyleProperty(CSSPropertyMaxWidth, 100, CSSPrimitiveValue::UnitType::CSS_PERCENTAGE, true);292 }293 294 } else if (MIMETypeRegistry::isSupportedMediaMIMEType(mimeType)) {295 auto video = ensureInnerVideo();296 if (video->attributeWithoutSynchronization(srcAttr).isEmpty()) {297 video->setAttributeWithoutSynchronization(srcAttr, DOMURL::createObjectURL(document(), *m_file));298 video->setAttributeWithoutSynchronization(controlsAttr, emptyString());299 video->setInlineStyleProperty(CSSPropertyDisplay, CSSValueInline, true);300 video->setInlineStyleProperty(CSSPropertyMaxWidth, 100, CSSPrimitiveValue::UnitType::CSS_PERCENTAGE, true);301 }302 }303 177 } 304 178 -
trunk/Source/WebCore/html/HTMLAttachmentElement.h
r229694 r234885 54 54 void setUniqueIdentifier(const String& uniqueIdentifier) { m_uniqueIdentifier = uniqueIdentifier; } 55 55 56 WEBCORE_EXPORT void updateDisplayMode(AttachmentDisplayMode);57 56 WEBCORE_EXPORT void updateFileWithData(Ref<SharedBuffer>&& data, std::optional<String>&& newContentType = std::nullopt, std::optional<String>&& newFilename = std::nullopt); 58 57 … … 64 63 String attachmentPath() const; 65 64 66 RenderAttachment* attachmentRenderer() const;65 RenderAttachment* renderer() const; 67 66 68 67 WEBCORE_EXPORT void requestInfo(Function<void(const AttachmentInfo&)>&& callback); … … 74 73 75 74 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final; 76 Ref<HTMLImageElement> ensureInnerImage();77 Ref<HTMLVideoElement> ensureInnerVideo();78 RefPtr<HTMLImageElement> innerImage() const;79 RefPtr<HTMLVideoElement> innerVideo() const;80 81 void populateShadowRootIfNecessary();82 void invalidateShadowRootChildrenIfNecessary();83 84 AttachmentDisplayMode defaultDisplayMode() const85 {86 // FIXME: For now, all attachment elements automatically display using a file icon.87 // In a followup patch, we'll change the default behavior to use in-place presentation88 // for certain image MIME types.89 return AttachmentDisplayMode::AsIcon;90 }91 92 75 bool shouldSelectOnMouseDown() final { 93 76 #if PLATFORM(IOS) -
trunk/Source/WebCore/page/DragController.cpp
r234801 r234885 1089 1089 if (is<HTMLAttachmentElement>(element) && m_dragSourceAction & DragSourceActionAttachment) { 1090 1090 auto& attachment = downcast<HTMLAttachmentElement>(element); 1091 auto* attachmentRenderer = attachment. attachmentRenderer();1091 auto* attachmentRenderer = attachment.renderer(); 1092 1092 1093 1093 src.editor().setIgnoreSelectionChanges(true); -
trunk/Source/WebCore/rendering/RenderAttachment.h
r225252 r234885 60 60 }; 61 61 62 inline RenderAttachment* HTMLAttachmentElement::renderer() const 63 { 64 return downcast<RenderAttachment>(HTMLElement::renderer()); 65 } 66 62 67 } // namespace WebCore 63 68 -
trunk/Source/WebKit/ChangeLog
r234875 r234885 1 2018-08-15 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Attachment SPI] Remove attachment display mode options 4 https://bugs.webkit.org/show_bug.cgi?id=188596 5 6 Reviewed by Dan Bernstein. 7 8 Remove attachment display mode from WebKit. Note that _WKAttachmentDisplayOptions needs to remain in the private 9 header for source compatibility with Mail. 10 11 * UIProcess/API/Cocoa/_WKAttachment.mm: 12 (-[_WKAttachmentDisplayOptions coreDisplayOptions]): Deleted. 13 * WebProcess/WebPage/WebPage.cpp: 14 (WebKit::WebPage::setAttachmentDisplayOptions): 15 1 16 2018-08-14 Sihui Liu <sihui_liu@apple.com> 2 17 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAttachment.mm
r226824 r234885 40 40 @implementation _WKAttachmentDisplayOptions : NSObject 41 41 42 - (instancetype)init43 {44 if (self = [super init])45 _mode = _WKAttachmentDisplayModeAuto;46 47 return self;48 }49 50 42 - (WebCore::AttachmentDisplayOptions)coreDisplayOptions 51 43 { 52 WebCore::AttachmentDisplayMode mode; 53 switch (self.mode) { 54 case _WKAttachmentDisplayModeAuto: 55 mode = WebCore::AttachmentDisplayMode::Auto; 56 break; 57 case _WKAttachmentDisplayModeAsIcon: 58 mode = WebCore::AttachmentDisplayMode::AsIcon; 59 break; 60 case _WKAttachmentDisplayModeInPlace: 61 mode = WebCore::AttachmentDisplayMode::InPlace; 62 break; 63 default: 64 ASSERT_NOT_REACHED(); 65 mode = WebCore::AttachmentDisplayMode::Auto; 66 } 67 return { mode }; 44 return { }; 68 45 } 69 46 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r234704 r234885 6106 6106 } 6107 6107 6108 void WebPage::setAttachmentDisplayOptions(const String& identifier, const AttachmentDisplayOptions& options, CallbackID callbackID) 6109 { 6110 if (auto attachment = attachmentElementWithIdentifier(identifier)) { 6111 attachment->document().updateLayout(); 6112 attachment->updateDisplayMode(options.mode); 6113 } 6108 void WebPage::setAttachmentDisplayOptions(const String&, const AttachmentDisplayOptions&, CallbackID callbackID) 6109 { 6114 6110 send(Messages::WebPageProxy::VoidCallback(callbackID)); 6115 6111 } -
trunk/Tools/ChangeLog
r234881 r234885 1 2018-08-15 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Attachment SPI] Remove attachment display mode options 4 https://bugs.webkit.org/show_bug.cgi?id=188596 5 6 Reviewed by Dan Bernstein. 7 8 Remove API tests and API test helpers for verifying the behavior of in-place media attachment elements. 9 10 * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm: 11 (-[TestWKWebView synchronouslyInsertAttachmentWithFilename:contentType:data:]): 12 (TestWebKitAPI::TEST): 13 (testVideoData): Deleted. 14 (displayOptionsWithMode): Deleted. 15 (-[TestWKWebView synchronouslyInsertAttachmentWithFilename:contentType:data:options:]): Deleted. 16 1 17 2018-08-14 Devin Rousso <drousso@apple.com> 2 18 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm
r234731 r234885 189 189 } 190 190 191 static NSData *testVideoData()192 {193 NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"mp4" subdirectory:@"TestWebKitAPI.resources"];194 return [NSData dataWithContentsOfURL:url];195 }196 197 191 static NSURL *testPDFFileURL() 198 192 { … … 203 197 { 204 198 return [NSData dataWithContentsOfURL:testPDFFileURL()]; 205 }206 207 static _WKAttachmentDisplayOptions *displayOptionsWithMode(_WKAttachmentDisplayMode mode)208 {209 _WKAttachmentDisplayOptions *options = [[[_WKAttachmentDisplayOptions alloc] init] autorelease];210 options.mode = mode;211 return options;212 199 } 213 200 … … 251 238 } 252 239 253 - (_WKAttachment *)synchronouslyInsertAttachmentWithFilename:(NSString *)filename contentType:(NSString *)contentType data:(NSData *)data options:(_WKAttachmentDisplayOptions *)options240 - (_WKAttachment *)synchronouslyInsertAttachmentWithFilename:(NSString *)filename contentType:(NSString *)contentType data:(NSData *)data 254 241 { 255 242 __block bool done = false; 256 RetainPtr<_WKAttachment> attachment = [self _insertAttachmentWithFilename:filename contentType:contentType data:data options: optionscompletion:^(BOOL) {243 RetainPtr<_WKAttachment> attachment = [self _insertAttachmentWithFilename:filename contentType:contentType data:data options:nil completion:^(BOOL) { 257 244 done = true; 258 245 }]; … … 506 493 ObserveAttachmentUpdatesForScope observer(webView.get()); 507 494 // Use the given content type for the attachment element's type. 508 firstAttachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo" contentType:@"text/html" data:testHTMLData() options:nil];495 firstAttachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo" contentType:@"text/html" data:testHTMLData()]; 509 496 EXPECT_WK_STREQ(@"foo", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]); 510 497 EXPECT_WK_STREQ(@"text/html", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]); … … 523 510 // Since no content type is explicitly specified, compute it from the file extension. 524 511 [webView _executeEditCommand:@"DeleteBackward" argument:nil completion:nil]; 525 secondAttachment = [webView synchronouslyInsertAttachmentWithFilename:@"bar.png" contentType:nil data:testImageData() options:nil];512 secondAttachment = [webView synchronouslyInsertAttachmentWithFilename:@"bar.png" contentType:nil data:testImageData()]; 526 513 EXPECT_WK_STREQ(@"bar.png", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]); 527 514 EXPECT_WK_STREQ(@"image/png", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]); … … 543 530 { 544 531 ObserveAttachmentUpdatesForScope observer(webView.get()); 545 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:testHTMLData() options:nil];532 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:testHTMLData()]; 546 533 observer.expectAttachmentUpdates(@[ ], @[attachment.get()]); 547 534 } … … 570 557 { 571 558 ObserveAttachmentUpdatesForScope observer(webView.get()); 572 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:testHTMLData() options:nil];559 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:testHTMLData()]; 573 560 observer.expectAttachmentUpdates(@[ ], @[attachment.get()]); 574 561 } … … 596 583 { 597 584 ObserveAttachmentUpdatesForScope observer(webView.get()); 598 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:testHTMLData() options:nil];585 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:testHTMLData()]; 599 586 observer.expectAttachmentUpdates(@[ ], @[attachment.get()]); 600 587 } … … 620 607 { 621 608 ObserveAttachmentUpdatesForScope observer(webView.get()); 622 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:testHTMLData() options:nil];609 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:testHTMLData()]; 623 610 observer.expectAttachmentUpdates(@[ ], @[attachment.get()]); 624 611 } … … 664 651 { 665 652 ObserveAttachmentUpdatesForScope observer(webView.get()); 666 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:testHTMLData() options:nil];653 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:testHTMLData()]; 667 654 observer.expectAttachmentUpdates(@[], @[attachment.get()]); 668 655 } … … 693 680 { 694 681 ObserveAttachmentUpdatesForScope observer(webView.get()); 695 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"empty.txt" contentType:@"text/plain" data:[NSData data] options:nil];682 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"empty.txt" contentType:@"text/plain" data:[NSData data]]; 696 683 observer.expectAttachmentUpdates(@[], @[attachment.get()]); 697 684 } … … 706 693 } 707 694 708 TEST(WKAttachmentTests, InsertedImageSizeIsClampedByMaxWidth)709 {710 auto webView = webViewForTestingAttachments(CGSizeMake(100, 100));711 RetainPtr<NSData> imageData = testImageData();712 RetainPtr<_WKAttachment> attachment;713 {714 ObserveAttachmentUpdatesForScope observer(webView.get());715 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"icon.png" contentType:@"image/png" data:imageData.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace)];716 [attachment expectRequestedDataToBe:imageData.get()];717 observer.expectAttachmentUpdates(@[], @[attachment.get()]);718 }719 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(84, 67)];720 }721 722 695 TEST(WKAttachmentTests, MultipleSimultaneousAttachmentDataRequests) 723 696 { … … 727 700 { 728 701 ObserveAttachmentUpdatesForScope observer(webView.get()); 729 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:htmlData.get() options:nil];702 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:htmlData.get()]; 730 703 observer.expectAttachmentUpdates(@[], @[attachment.get()]); 731 704 } … … 749 722 } 750 723 751 TEST(WKAttachmentTests, InPlaceImageAttachmentToggleDisplayMode) 752 { 753 auto webView = webViewForTestingAttachments(); 754 RetainPtr<NSData> imageData = testImageData(); 724 TEST(WKAttachmentTests, ChangeAttachmentDataAndFileInformation) 725 { 726 auto webView = webViewForTestingAttachments(); 755 727 RetainPtr<_WKAttachment> attachment; 756 728 { 757 ObserveAttachmentUpdatesForScope observer(webView.get());758 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"icon.png" contentType:@"image/png" data:imageData.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeAsIcon)];759 [attachment expectRequestedDataToBe:imageData.get()];760 observer.expectAttachmentUpdates(@[], @[attachment.get()]);761 }762 CGSize iconAttachmentSize = [webView attachmentElementSize];763 764 [attachment synchronouslySetDisplayOptions:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace) error:nil];765 [attachment expectRequestedDataToBe:imageData.get()];766 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(215, 174)];767 768 [attachment synchronouslySetDisplayOptions:displayOptionsWithMode(_WKAttachmentDisplayModeAsIcon) error:nil];769 [attachment expectRequestedDataToBe:imageData.get()];770 [webView waitForAttachmentElementSizeToBecome:iconAttachmentSize];771 772 [attachment synchronouslySetDisplayOptions:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace) error:nil];773 [attachment expectRequestedDataToBe:imageData.get()];774 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(215, 174)];775 }776 777 TEST(WKAttachmentTests, InPlaceImageAttachmentParagraphInsertion)778 {779 auto webView = webViewForTestingAttachments();780 RetainPtr<NSData> imageData = testImageData();781 RetainPtr<_WKAttachment> attachment;782 {783 ObserveAttachmentUpdatesForScope observer(webView.get());784 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"icon.png" contentType:@"image/png" data:imageData.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace)];785 observer.expectAttachmentUpdates(@[], @[attachment.get()]);786 }787 [webView expectUpdatesAfterCommand:@"InsertParagraph" withArgument:nil expectedRemovals:@[] expectedInsertions:@[]];788 [webView expectUpdatesAfterCommand:@"DeleteBackward" withArgument:nil expectedRemovals:@[] expectedInsertions:@[]];789 [webView stringByEvaluatingJavaScript:@"getSelection().collapse(document.body)"];790 [webView expectUpdatesAfterCommand:@"InsertParagraph" withArgument:nil expectedRemovals:@[] expectedInsertions:@[]];791 [webView expectUpdatesAfterCommand:@"DeleteBackward" withArgument:nil expectedRemovals:@[] expectedInsertions:@[]];792 793 [attachment expectRequestedDataToBe:imageData.get()];794 EXPECT_WK_STREQ([attachment uniqueIdentifier], [webView stringByEvaluatingJavaScript:@"document.querySelector('attachment').uniqueIdentifier"]);795 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(215, 174)];796 797 [webView expectUpdatesAfterCommand:@"DeleteForward" withArgument:nil expectedRemovals:@[attachment.get()] expectedInsertions:@[]];798 }799 800 TEST(WKAttachmentTests, InPlaceVideoAttachmentInsertionWithinList)801 {802 auto webView = webViewForTestingAttachments();803 RetainPtr<NSData> videoData = testVideoData();804 RetainPtr<_WKAttachment> attachment;805 806 [webView _synchronouslyExecuteEditCommand:@"InsertOrderedList" argument:nil];807 {808 ObserveAttachmentUpdatesForScope observer(webView.get());809 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"test.mp4" contentType:@"video/mp4" data:videoData.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace)];810 observer.expectAttachmentUpdates(@[], @[attachment.get()]);811 }812 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(320, 240)];813 814 [webView expectUpdatesAfterCommand:@"DeleteBackward" withArgument:nil expectedRemovals:@[attachment.get()] expectedInsertions:@[]];815 [webView expectUpdatesAfterCommand:@"Undo" withArgument:nil expectedRemovals:@[] expectedInsertions:@[attachment.get()]];816 [webView expectUpdatesAfterCommand:@"InsertOrderedList" withArgument:nil expectedRemovals:@[] expectedInsertions:@[]];817 818 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(320, 240)];819 [attachment expectRequestedDataToBe:videoData.get()];820 }821 822 TEST(WKAttachmentTests, InPlacePDFAttachmentCutAndPaste)823 {824 auto webView = webViewForTestingAttachments();825 RetainPtr<NSData> pdfData = testPDFData();826 RetainPtr<_WKAttachment> attachment;827 {828 ObserveAttachmentUpdatesForScope observer(webView.get());829 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"test.pdf" contentType:@"application/pdf" data:pdfData.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace)];830 observer.expectAttachmentUpdates(@[], @[attachment.get()]);831 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(130, 29)];832 }833 834 [webView _synchronouslyExecuteEditCommand:@"SelectAll" argument:nil];835 [webView expectUpdatesAfterCommand:@"Cut" withArgument:nil expectedRemovals:@[attachment.get()] expectedInsertions:@[]];836 837 [webView expectUpdatesAfterCommand:@"Paste" withArgument:nil expectedRemovals:@[] expectedInsertions:@[attachment.get()]];838 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(130, 29)];839 [attachment expectRequestedDataToBe:pdfData.get()];840 }841 842 TEST(WKAttachmentTests, ChangeAttachmentDataAndFileInformation)843 {844 auto webView = webViewForTestingAttachments();845 RetainPtr<_WKAttachment> attachment;846 {847 729 RetainPtr<NSData> pdfData = testPDFData(); 848 730 ObserveAttachmentUpdatesForScope observer(webView.get()); 849 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"test.pdf" contentType:@"application/pdf" data:pdfData.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeAsIcon)];731 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"test.pdf" contentType:@"application/pdf" data:pdfData.get()]; 850 732 [attachment expectRequestedDataToBe:pdfData.get()]; 851 733 EXPECT_WK_STREQ(@"test.pdf", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]); … … 865 747 RetainPtr<NSData> textData = testHTMLData(); 866 748 ObserveAttachmentUpdatesForScope observer(webView.get()); 867 [attachment synchronouslySetDisplayOptions:displayOptionsWithMode(_WKAttachmentDisplayModeAsIcon) error:nil];868 749 // The new content type should be inferred from the file name. 869 750 [attachment synchronouslySetData:textData.get() newContentType:nil newFilename:@"foo.txt" error:nil]; … … 881 762 EXPECT_WK_STREQ(@"foo.txt", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]); 882 763 EXPECT_WK_STREQ(@"text/plain", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]); 883 observer.expectAttachmentUpdates(@[], @[]);884 }885 [webView expectUpdatesAfterCommand:@"DeleteBackward" withArgument:nil expectedRemovals:@[attachment.get()] expectedInsertions:@[]];886 }887 888 TEST(WKAttachmentTests, ChangeAttachmentDataUpdatesWithInPlaceDisplay)889 {890 auto webView = webViewForTestingAttachments();891 RetainPtr<_WKAttachment> attachment;892 {893 RetainPtr<NSData> pdfData = testPDFData();894 ObserveAttachmentUpdatesForScope observer(webView.get());895 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"test.pdf" contentType:@"application/pdf" data:pdfData.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace)];896 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(130, 29)];897 [attachment expectRequestedDataToBe:pdfData.get()];898 EXPECT_WK_STREQ(@"test.pdf", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]);899 EXPECT_WK_STREQ(@"application/pdf", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]);900 observer.expectAttachmentUpdates(@[], @[attachment.get()]);901 }902 {903 RetainPtr<NSData> videoData = testVideoData();904 ObserveAttachmentUpdatesForScope observer(webView.get());905 [attachment synchronouslySetData:videoData.get() newContentType:@"video/mp4" newFilename:@"test.mp4" error:nil];906 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(320, 240)];907 [attachment expectRequestedDataToBe:videoData.get()];908 EXPECT_WK_STREQ(@"test.mp4", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]);909 EXPECT_WK_STREQ(@"video/mp4", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]);910 observer.expectAttachmentUpdates(@[], @[]);911 }912 {913 RetainPtr<NSData> imageData = testImageData();914 ObserveAttachmentUpdatesForScope observer(webView.get());915 [attachment synchronouslySetData:imageData.get() newContentType:@"image/png" newFilename:@"icon.png" error:nil];916 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(215, 174)];917 [attachment expectRequestedDataToBe:imageData.get()];918 EXPECT_WK_STREQ(@"icon.png", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]);919 EXPECT_WK_STREQ(@"image/png", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]);920 764 observer.expectAttachmentUpdates(@[], @[]); 921 765 } … … 1055 899 { 1056 900 ObserveAttachmentUpdatesForScope observer(webView.get()); 1057 originalAttachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:data.get() options:nil];901 originalAttachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:data.get()]; 1058 902 EXPECT_EQ(0U, observer.observer().removed.count); 1059 903 observer.expectAttachmentUpdates(@[], @[originalAttachment.get()]); … … 1091 935 { 1092 936 ObserveAttachmentUpdatesForScope observer(webView.get()); 1093 originalAttachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:originalData.get() options:nil];937 originalAttachment = [webView synchronouslyInsertAttachmentWithFilename:@"foo.txt" contentType:@"text/plain" data:originalData.get()]; 1094 938 EXPECT_EQ(0U, observer.observer().removed.count); 1095 939 observer.expectAttachmentUpdates(@[], @[originalAttachment.get()]); … … 1387 1231 { 1388 1232 ObserveAttachmentUpdatesForScope observer(webView.get()); 1389 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"document.pdf" contentType:@"application/pdf" data:data.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeAsIcon)];1233 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"document.pdf" contentType:@"application/pdf" data:data.get()]; 1390 1234 observer.expectAttachmentUpdates(@[], @[attachment.get()]); 1391 1235 } … … 1409 1253 } 1410 1254 1411 TEST(WKAttachmentTestsIOS, DragInPlaceVideoAttachmentElement)1412 {1413 auto webView = webViewForTestingAttachments();1414 auto data = retainPtr(testVideoData());1415 RetainPtr<_WKAttachment> attachment;1416 {1417 ObserveAttachmentUpdatesForScope observer(webView.get());1418 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"video.mp4" contentType:@"video/mp4" data:data.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace)];1419 observer.expectAttachmentUpdates(@[], @[attachment.get()]);1420 }1421 1422 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(320, 240)];1423 [attachment expectRequestedDataToBe:data.get()];1424 EXPECT_WK_STREQ("video.mp4", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]);1425 EXPECT_WK_STREQ("video/mp4", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]);1426 1427 [webView evaluateJavaScript:@"getSelection().removeAllRanges()" completionHandler:nil];1428 auto dragAndDropSimulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]);1429 [dragAndDropSimulator runFrom:CGPointMake(25, 25) to:CGPointMake(-100, -100)];1430 1431 EXPECT_EQ(1U, [dragAndDropSimulator sourceItemProviders].count);1432 NSItemProvider *itemProvider = [dragAndDropSimulator sourceItemProviders].firstObject;1433 EXPECT_EQ(UIPreferredPresentationStyleAttachment, itemProvider.preferredPresentationStyle);1434 [itemProvider expectType:(NSString *)kUTTypeMPEG4 withData:data.get()];1435 EXPECT_WK_STREQ("video.mp4", [itemProvider suggestedName]);1436 [dragAndDropSimulator endDataTransfer];1437 }1438 1439 1255 TEST(WKAttachmentTestsIOS, MoveAttachmentElementAsIconByDragging) 1440 1256 { … … 1444 1260 { 1445 1261 ObserveAttachmentUpdatesForScope observer(webView.get()); 1446 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"document.pdf" contentType:@"application/pdf" data:data.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeAsIcon)];1262 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"document.pdf" contentType:@"application/pdf" data:data.get()]; 1447 1263 observer.expectAttachmentUpdates(@[], @[attachment.get()]); 1448 1264 } … … 1465 1281 } 1466 1282 1467 TEST(WKAttachmentTestsIOS, MoveInPlaceAttachmentElementByDragging)1468 {1469 auto webView = webViewForTestingAttachments();1470 auto data = retainPtr(testImageData());1471 RetainPtr<_WKAttachment> attachment;1472 {1473 ObserveAttachmentUpdatesForScope observer(webView.get());1474 attachment = [webView synchronouslyInsertAttachmentWithFilename:@"icon.png" contentType:@"image/png" data:data.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace)];1475 observer.expectAttachmentUpdates(@[], @[attachment.get()]);1476 }1477 1478 [webView waitForAttachmentElementSizeToBecome:CGSizeMake(215, 174)];1479 [webView _executeEditCommand:@"InsertParagraph" argument:nil completion:nil];1480 [webView _executeEditCommand:@"InsertHTML" argument:@"<strong>text</strong>" completion:nil];1481 [webView _synchronouslyExecuteEditCommand:@"InsertParagraph" argument:nil];1482 [webView expectElementTag:@"ATTACHMENT" toComeBefore:@"STRONG"];1483 1484 auto dragAndDropSimulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]);1485 [dragAndDropSimulator runFrom:CGPointMake(25, 25) to:CGPointMake(25, 425)];1486 1487 attachment = [[dragAndDropSimulator insertedAttachments] firstObject];1488 [attachment expectRequestedDataToBe:data.get()];1489 EXPECT_WK_STREQ("icon.png", [webView valueOfAttribute:@"title" forQuerySelector:@"attachment"]);1490 EXPECT_WK_STREQ("image/png", [webView valueOfAttribute:@"type" forQuerySelector:@"attachment"]);1491 1492 [webView expectElementTag:@"STRONG" toComeBefore:@"ATTACHMENT"];1493 [dragAndDropSimulator endDataTransfer];1494 }1495 1496 1283 #endif // PLATFORM(IOS) 1497 1284
Note: See TracChangeset
for help on using the changeset viewer.