Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 88bf94f
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>
Expand Up @@ -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
5 changes: 5 additions & 0 deletions Source/WebCore/rendering/style/RenderStyle.h
Expand Up @@ -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
5 changes: 1 addition & 4 deletions Source/WebCore/rendering/svg/LegacyRenderSVGRoot.cpp
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions Source/WebCore/rendering/svg/RenderSVGRoot.cpp
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/svg/SVGRenderSupport.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit 88bf94f

Please sign in to comment.