Title: [292712] trunk
Revision
292712
Author
wenson_hs...@apple.com
Date
2022-04-11 12:02:22 -0700 (Mon, 11 Apr 2022)

Log Message

[Mail Compose] Preserve attachment identifiers when cloning attachment-backed images
https://bugs.webkit.org/show_bug.cgi?id=239040
rdar://91527065

Reviewed by Aditya Keerthi.

Source/WebCore:

Override HTMLImageElement's `cloneElementWithoutAttributesAndChildren` method so that it additionally clones the
attachment element underneath the original image element, if it exists. This ensures that an image element that
is copied from existing attachment-backed images using `cloneNode` will contain an `attachment` in its shadow
root that points to the same `_WKAttachment` in the embedding client.

Test: WKAttachmentTests.CloneImageWithAttachment

* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::cloneElementWithoutAttributesAndChildren):
* html/HTMLImageElement.h:

Tools:

Add an API test to exercise the change.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292711 => 292712)


--- trunk/Source/WebCore/ChangeLog	2022-04-11 16:47:10 UTC (rev 292711)
+++ trunk/Source/WebCore/ChangeLog	2022-04-11 19:02:22 UTC (rev 292712)
@@ -1,3 +1,22 @@
+2022-04-11  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [Mail Compose] Preserve attachment identifiers when cloning attachment-backed images
+        https://bugs.webkit.org/show_bug.cgi?id=239040
+        rdar://91527065
+
+        Reviewed by Aditya Keerthi.
+
+        Override HTMLImageElement's `cloneElementWithoutAttributesAndChildren` method so that it additionally clones the
+        attachment element underneath the original image element, if it exists. This ensures that an image element that
+        is copied from existing attachment-backed images using `cloneNode` will contain an `attachment` in its shadow
+        root that points to the same `_WKAttachment` in the embedding client.
+
+        Test: WKAttachmentTests.CloneImageWithAttachment
+
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::cloneElementWithoutAttributesAndChildren):
+        * html/HTMLImageElement.h:
+
 2022-04-11  Nikolas Zimmermann  <nzimmerm...@igalia.com>
 
         [LBSE] Activate SVG transform support through layers

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (292711 => 292712)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2022-04-11 16:47:10 UTC (rev 292711)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2022-04-11 19:02:22 UTC (rev 292712)
@@ -948,4 +948,17 @@
     invalidateStyle();
 }
 
+Ref<Element> HTMLImageElement::cloneElementWithoutAttributesAndChildren(Document& targetDocument)
+{
+    auto clone = create(targetDocument);
+#if ENABLE(ATTACHMENT_ELEMENT)
+    if (auto attachment = attachmentElement()) {
+        auto attachmentClone = attachment->cloneElementWithoutChildren(targetDocument);
+        RELEASE_ASSERT(is<HTMLAttachmentElement>(attachmentClone));
+        clone->setAttachmentElement(downcast<HTMLAttachmentElement>(attachmentClone.get()));
+    }
+#endif
+    return clone;
 }
+
+}

Modified: trunk/Source/WebCore/html/HTMLImageElement.h (292711 => 292712)


--- trunk/Source/WebCore/html/HTMLImageElement.h	2022-04-11 16:47:10 UTC (rev 292711)
+++ trunk/Source/WebCore/html/HTMLImageElement.h	2022-04-11 19:02:22 UTC (rev 292712)
@@ -165,6 +165,8 @@
     void collectExtraStyleForPresentationalHints(MutableStyleProperties&) override;
     void invalidateAttributeMapping();
 
+    Ref<Element> cloneElementWithoutAttributesAndChildren(Document& targetDocument) final;
+
     // ActiveDOMObject.
     const char* activeDOMObjectName() const final;
     bool virtualHasPendingActivity() const final;

Modified: trunk/Tools/ChangeLog (292711 => 292712)


--- trunk/Tools/ChangeLog	2022-04-11 16:47:10 UTC (rev 292711)
+++ trunk/Tools/ChangeLog	2022-04-11 19:02:22 UTC (rev 292712)
@@ -1,3 +1,16 @@
+2022-04-11  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [Mail Compose] Preserve attachment identifiers when cloning attachment-backed images
+        https://bugs.webkit.org/show_bug.cgi?id=239040
+        rdar://91527065
+
+        Reviewed by Aditya Keerthi.
+
+        Add an API test to exercise the change.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (TestWebKitAPI::TEST):
+
 2022-04-11  Andres Gonzalez  <andresg...@apple.com>
 
         TestRunner’s calls to [WebAccessibilityObjectWrapper accessibilityArrayAttributeCount:] need to be dispatch to the AX secondary thread.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (292711 => 292712)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2022-04-11 16:47:10 UTC (rev 292711)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2022-04-11 19:02:22 UTC (rev 292712)
@@ -1632,6 +1632,30 @@
     EXPECT_WK_STREQ([attachment uniqueIdentifier], [webView stringByEvaluatingJavaScript:@"document.body.cloneNode(true).querySelector('attachment').uniqueIdentifier"]);
 }
 
+TEST(WKAttachmentTests, CloneImageWithAttachment)
+{
+    auto webView = webViewForTestingAttachments();
+    platformCopyPNG();
+
+    RetainPtr<_WKAttachment> attachment;
+    {
+        ObserveAttachmentUpdatesForScope observer(webView.get());
+        [webView _synchronouslyExecuteEditCommand:@"Paste" argument:nil];
+        EXPECT_EQ(1U, observer.observer().inserted.count);
+
+        attachment = observer.observer().inserted.firstObject;
+        EXPECT_WK_STREQ("image/png", [attachment info].contentType);
+    }
+
+    NSString *clonedAttachmentIdentifier = [webView stringByEvaluatingJavaScript:@"const original = document.querySelector('img');"
+        "const clone = original.cloneNode();"
+        "original.remove();"
+        "document.body.appendChild(clone);"
+        "HTMLAttachmentElement.getAttachmentIdentifier(clone);"];
+
+    EXPECT_WK_STREQ([attachment uniqueIdentifier], clonedAttachmentIdentifier);
+}
+
 TEST(WKAttachmentTests, SetFileWrapperForPDFImageAttachment)
 {
     auto webView = webViewForTestingAttachments();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to