Skip to content


Browse files Browse the repository at this point in the history
Resolve percentage in use against the instance's viewport element

Reviewed by Simon Fraser.

This patch aligns WebKit with Blink / Chromium and Gecko / Firefox.


In RenderSVGTransformableContainer::calculateLocalTransform, 'x' and 'y'
were resolved against the original (corresponding) element. For a `use`
nested within a `symbol`, this would mean that when were going to look
up the viewport element, we would return the outer `symbol` element and thus
fail to get a viewport.
Use the instance element to setup the SVGLengthContext instead.

* Source/WebCore/rendering/svg/LegacyRenderSVGTransformableContainer.cpp:
(LegacyRenderSVGTransformableContainer::calculateLocalTransform): Use 'element' rather than 'useElement'
* LayoutTests/svg/custom/use-nested-symbol-viewport.html: Add Test Case
* LayoutTests/svg/custom/use-nested-symbol-viewport-expected.html: Add Test Case Expectation

Canonical link:
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed May 26, 2023
1 parent b3b7524 commit 590f8fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<div style="width: 100px; height: 100px; background-color: green"></div>
12 changes: 12 additions & 0 deletions LayoutTests/svg/custom/use-nested-symbol-viewport.html
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<svg width="200" height="100">
<rect width="100" height="100" fill="red"/>
<symbol id="inner">
<rect width="100" height="100"/>
<symbol id="outer">
<rect x="50%" width="100" height="100" fill="red"/>
<use xlink:href="#inner" x="50%" fill="green"/>
<use xlink:href="#outer" transform="translate(-100, 0)"/>
@@ -1,7 +1,7 @@
* Copyright (C) 2004, 2005 Nikolas Zimmermann <>
* Copyright (C) 2004, 2005, 2006 Rob Buis <>
* Copyright (C) 2009 Google, Inc.
* Copyright (C) 2009-2016 Google, Inc.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -58,7 +58,7 @@ bool LegacyRenderSVGTransformableContainer::calculateLocalTransform()

if (useElement) {
SVGLengthContext lengthContext(useElement);
SVGLengthContext lengthContext(&element);
FloatSize translation(useElement->x().value(lengthContext), useElement->y().value(lengthContext));
if (translation != m_lastTranslation)
m_needsTransformUpdate = true;
Expand Down

0 comments on commit 590f8fc

Please sign in to comment.