Title: [274443] trunk
- Revision
- 274443
- Author
- wenson_hs...@apple.com
- Date
- 2021-03-15 15:39:14 -0700 (Mon, 15 Mar 2021)
Log Message
Image overlay creation should be idempotent
https://bugs.webkit.org/show_bug.cgi?id=223199
Reviewed by Tim Horton.
Source/WebCore:
Make sure that `updateWithImageExtractionResult` is idempotent given the same results object, and does not
inject redundant styles or DOM elements in the user agent shadow root.
Test: fast/images/image-extraction/image-overlay-creation-is-idempotent.html
* html/HTMLElement.cpp:
(WebCore::HTMLElement::updateWithImageExtractionResult):
When updating the image overlay, remove the existing overlay container element if needed, and don't bother
re-injecting the style sheet if it has already been created and inserted.
LayoutTests:
* fast/images/image-extraction/image-overlay-creation-is-idempotent-expected.txt: Added.
* fast/images/image-extraction/image-overlay-creation-is-idempotent.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (274442 => 274443)
--- trunk/LayoutTests/ChangeLog 2021-03-15 22:25:52 UTC (rev 274442)
+++ trunk/LayoutTests/ChangeLog 2021-03-15 22:39:14 UTC (rev 274443)
@@ -1,3 +1,13 @@
+2021-03-15 Wenson Hsieh <wenson_hs...@apple.com>
+
+ Image overlay creation should be idempotent
+ https://bugs.webkit.org/show_bug.cgi?id=223199
+
+ Reviewed by Tim Horton.
+
+ * fast/images/image-extraction/image-overlay-creation-is-idempotent-expected.txt: Added.
+ * fast/images/image-extraction/image-overlay-creation-is-idempotent.html: Added.
+
2021-03-15 Zalan Bujtas <za...@apple.com>
RenderStyle::getRoundedInnerBorderFor should never produce a rect with negative width/height
Added: trunk/LayoutTests/fast/images/image-extraction/image-overlay-creation-is-idempotent-expected.txt (0 => 274443)
--- trunk/LayoutTests/fast/images/image-extraction/image-overlay-creation-is-idempotent-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/images/image-extraction/image-overlay-creation-is-idempotent-expected.txt 2021-03-15 22:39:14 UTC (rev 274443)
@@ -0,0 +1,5 @@
+PASS internals.shadowRoot(image).childElementCount is 2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/images/image-extraction/image-overlay-creation-is-idempotent.html (0 => 274443)
--- trunk/LayoutTests/fast/images/image-extraction/image-overlay-creation-is-idempotent.html (rev 0)
+++ trunk/LayoutTests/fast/images/image-extraction/image-overlay-creation-is-idempotent.html 2021-03-15 22:39:14 UTC (rev 274443)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<script src=""
+<body>
+<img src=""
+<script>
+addEventListener("load", () => {
+ image = document.querySelector("img");
+ for (let i = 0; i < 10; ++i) {
+ internals.installImageOverlay(image, [{
+ text : "Hello",
+ topLeft : new DOMPointReadOnly(0.5, 0.5),
+ topRight : new DOMPointReadOnly(1, 0.5),
+ bottomRight : new DOMPointReadOnly(1, 1),
+ bottomLeft : new DOMPointReadOnly(0.5, 1),
+ }]);
+ }
+ shouldBe("internals.shadowRoot(image).childElementCount", "2");
+});
+</script>
+</body>
+</html>
\ No newline at end of file
Modified: trunk/Source/WebCore/ChangeLog (274442 => 274443)
--- trunk/Source/WebCore/ChangeLog 2021-03-15 22:25:52 UTC (rev 274442)
+++ trunk/Source/WebCore/ChangeLog 2021-03-15 22:39:14 UTC (rev 274443)
@@ -1,3 +1,21 @@
+2021-03-15 Wenson Hsieh <wenson_hs...@apple.com>
+
+ Image overlay creation should be idempotent
+ https://bugs.webkit.org/show_bug.cgi?id=223199
+
+ Reviewed by Tim Horton.
+
+ Make sure that `updateWithImageExtractionResult` is idempotent given the same results object, and does not
+ inject redundant styles or DOM elements in the user agent shadow root.
+
+ Test: fast/images/image-extraction/image-overlay-creation-is-idempotent.html
+
+ * html/HTMLElement.cpp:
+ (WebCore::HTMLElement::updateWithImageExtractionResult):
+
+ When updating the image overlay, remove the existing overlay container element if needed, and don't bother
+ re-injecting the style sheet if it has already been created and inserted.
+
2021-03-15 Zalan Bujtas <za...@apple.com>
RenderStyle::getRoundedInnerBorderFor should never produce a rect with negative width/height
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (274442 => 274443)
--- trunk/Source/WebCore/html/HTMLElement.cpp 2021-03-15 22:25:52 UTC (rev 274442)
+++ trunk/Source/WebCore/html/HTMLElement.cpp 2021-03-15 22:39:14 UTC (rev 274443)
@@ -1256,6 +1256,20 @@
void HTMLElement::updateWithImageExtractionResult(ImageExtractionResult&& result)
{
+ RefPtr<HTMLDivElement> previousContainer;
+ if (auto shadowRoot = userAgentShadowRoot(); shadowRoot && hasImageOverlay()) {
+ for (auto& child : childrenOfType<HTMLDivElement>(*shadowRoot)) {
+ if (child.getIdAttribute() == imageOverlayElementIdentifier()) {
+ previousContainer = &child;
+ break;
+ }
+ }
+ if (previousContainer)
+ previousContainer->remove();
+ else
+ ASSERT_NOT_REACHED();
+ }
+
if (result.isEmpty())
return;
@@ -1266,12 +1280,13 @@
downcast<RenderImage>(*renderer).setHasImageOverlay();
}
- static NeverDestroyed<const String> shadowStyle(imageOverlayUserAgentStyleSheet, String::ConstructFromLiteral);
- auto style = HTMLStyleElement::create(HTMLNames::styleTag, document(), false);
- style->setTextContent(shadowStyle);
-
auto shadowRoot = makeRef(ensureUserAgentShadowRoot());
- shadowRoot->appendChild(WTFMove(style));
+ if (!previousContainer) {
+ static NeverDestroyed<const String> shadowStyle(imageOverlayUserAgentStyleSheet, String::ConstructFromLiteral);
+ auto style = HTMLStyleElement::create(HTMLNames::styleTag, document(), false);
+ style->setTextContent(shadowStyle);
+ shadowRoot->appendChild(WTFMove(style));
+ }
auto container = HTMLDivElement::create(document());
container->setIdAttribute(imageOverlayElementIdentifier());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes