Skip to content

Commit 1018cb1

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
<view> elements should apply to the root element
https://bugs.webkit.org/show_bug.cgi?id=298206 Reviewed by Said Abou-Hallawa. This patch aligns WebKit with Gecko / Firefox and Blink / Chromium. Inspired by: https://chromium.googlesource.com/chromium/src.git/+/17ee10504ffe050b3926fa4be7262f8a21ac4e2d As the comment here indicates, it wasn't clear which <svg> a <view> element should apply to. This was clarified in SVG2 [1] to be the "root 'svg' element", which is the same as for a "svgView(...)" fragment. The comment is updated to reflect the new spec text and 'findRootAnchor' was updated to align with specification. [1] https://svgwg.org/svg2-draft/linking.html#SVGFragmentIdentifiersDefinitions * Source/WebCore/svg/SVGSVGElement.cpp: (WebCore::SVGSVGElement::findRootAnchor const): (WebCore::SVGSVGElement::scrollToFragment): * LayoutTests/svg/as-image/resources/view-in-inner-svg.svg: Added. * LayoutTests/svg/as-image/view-in-inner-svg-expected.html: Added. * LayoutTests/svg/as-image/view-in-inner-svg.html: Added. Canonical link: https://commits.webkit.org/299459@main
1 parent f30213f commit 1018cb1

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!DOCTYPE html>
2+
<div style="width: 100px; height: 100px; background-color: green"></div>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!DOCTYPE html>
2+
<img src="resources/view-in-inner-svg.svg#innerview" width="100">

Source/WebCore/svg/SVGSVGElement.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,11 @@ RefPtr<SVGViewElement> SVGSVGElement::findViewAnchor(StringView fragmentIdentifi
700700

701701
SVGSVGElement* SVGSVGElement::findRootAnchor(const SVGViewElement* viewElement) const
702702
{
703-
return dynamicDowncast<SVGSVGElement>(SVGLocatable::nearestViewportElement(viewElement));
703+
if (!viewElement)
704+
return nullptr;
705+
706+
auto& document = viewElement->document();
707+
return dynamicDowncast<SVGSVGElement>(document.documentElement());
704708
}
705709

706710
SVGSVGElement* SVGSVGElement::findRootAnchor(StringView fragmentIdentifier) const
@@ -743,9 +747,9 @@ bool SVGSVGElement::scrollToFragment(StringView fragmentIdentifier)
743747
}
744748

745749
// Spec: If the SVG fragment identifier addresses a "view" element within an SVG document (e.g., MyDrawing.svg#MyView)
746-
// then the closest ancestor "svg" element is displayed in the viewport.
750+
// then the root 'svg' element is displayed in the SVG viewport.
747751
// Any view specification attributes included on the given "view" element override the corresponding view specification
748-
// attributes on the closest ancestor "svg" element.
752+
// attributes on the root 'svg' element.
749753
if (RefPtr viewElement = findViewAnchor(fragmentIdentifier)) {
750754
if (RefPtr rootElement = findRootAnchor(viewElement.get())) {
751755
if (rootElement->m_currentViewElement) {

0 commit comments

Comments
 (0)