Skip to content
Permalink
Browse files
CSS - overflow: clip is not working on SVG elements
https://bugs.webkit.org/show_bug.cgi?id=244706

Reviewed by Simon Fraser.

Implement overflow: clip for SVG containers.

* LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/nested-svg-overflow-clip-expected.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/nested-svg-overflow-clip.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/overflow-clip-expected.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/overflow-clip.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/w3c-import.log:
* Source/WebCore/rendering/style/RenderStyle.h:
(WebCore::isNonVisibleOverflow):
* Source/WebCore/rendering/svg/LegacyRenderSVGRoot.cpp:
(WebCore::LegacyRenderSVGRoot::shouldApplyViewportClip const):
* Source/WebCore/rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::shouldApplyViewportClip const):
* Source/WebCore/rendering/svg/SVGRenderSupport.cpp:
(WebCore::SVGRenderSupport::isOverflowHidden):

Canonical link: https://commits.webkit.org/254295@main
  • Loading branch information
rwlbuis committed Sep 9, 2022
1 parent 05ce373 commit 88bf94fa06f3c8a3d9415cf12d0dfdc34ccf9506
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 9 deletions.
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<svg xmlns="http://www.w3.org/2000/svg">
<rect width="100" height="100" fill="green" />
</svg>
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<link rel="match" href="rect-ref.html">
<style>
svg {
overflow: visible;
}
</style>
<svg style="width: 100px; height: 100px">
<svg style="overflow: clip;">
<rect height="250" width="250" fill="green">
</svg>
</svg>
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<svg xmlns="http://www.w3.org/2000/svg">
<rect width="100" height="100" fill="green" />
</svg>
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<link rel="match" href="rect-ref.html">
<style>
svg {
overflow: visible;
}
</style>
<svg style="overflow: clip; width: 100px; height: 100px">
<rect width="200" height="200" fill="green">
</svg>
@@ -26,5 +26,9 @@ List of files:
/LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/change-sync-for-nested-use.html
/LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/filter-effects-on-pattern-expected.html
/LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/filter-effects-on-pattern.html
/LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/nested-svg-overflow-clip-expected.html
/LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/nested-svg-overflow-clip.html
/LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/overflow-clip-expected.html
/LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/overflow-clip.html
/LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/render-sync-with-font-size-expected.html
/LayoutTests/imported/w3c/web-platform-tests/svg/render/reftests/render-sync-with-font-size.html
@@ -2550,4 +2550,9 @@ inline bool generatesBox(const RenderStyle& style)
return style.display() != DisplayType::None && style.display() != DisplayType::Contents;
}

inline bool isNonVisibleOverflow(Overflow overflow)
{
return overflow == Overflow::Hidden || overflow == Overflow::Scroll || overflow == Overflow::Clip;
}

} // namespace WebCore
@@ -213,10 +213,7 @@ bool LegacyRenderSVGRoot::shouldApplyViewportClip() const
// the outermost svg is clipped if auto, and svg document roots are always clipped
// When the svg is stand-alone (isDocumentElement() == true) the viewport clipping should always
// be applied, noting that the window scrollbars should be hidden if overflow=hidden.
return effectiveOverflowX() == Overflow::Hidden
|| style().overflowX() == Overflow::Auto
|| style().overflowX() == Overflow::Scroll
|| this->isDocumentElementRenderer();
return isNonVisibleOverflow(effectiveOverflowX()) || style().overflowX() == Overflow::Auto || this->isDocumentElementRenderer();
}

void LegacyRenderSVGRoot::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
@@ -240,10 +240,7 @@ bool RenderSVGRoot::shouldApplyViewportClip() const
// the outermost svg is clipped if auto, and svg document roots are always clipped
// When the svg is stand-alone (isDocumentElement() == true) the viewport clipping should always
// be applied, noting that the window scrollbars should be hidden if overflow=hidden.
return effectiveOverflowX() == Overflow::Hidden
|| style().overflowX() == Overflow::Auto
|| style().overflowX() == Overflow::Scroll
|| this->isDocumentElementRenderer();
return isNonVisibleOverflow(effectiveOverflowX()) || style().overflowX() == Overflow::Auto || this->isDocumentElementRenderer();
}

// FIXME: Basically a copy of RenderBlock::paint() - ideally one would share this code.
@@ -305,7 +305,7 @@ bool SVGRenderSupport::isOverflowHidden(const RenderElement& renderer)
// LegacyRenderSVGRoot should never query for overflow state - it should always clip itself to the initial viewport size.
ASSERT(!renderer.isDocumentElementRenderer());

return renderer.style().overflowX() == Overflow::Hidden || renderer.style().overflowX() == Overflow::Scroll;
return isNonVisibleOverflow(renderer.style().overflowX());
}

void SVGRenderSupport::intersectRepaintRectWithResources(const RenderElement& renderer, FloatRect& repaintRect)

0 comments on commit 88bf94f

Please sign in to comment.