Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: b86834d40591aed86d62b57dd4b7dd27aa6d6b7c
      
https://github.com/WebKit/WebKit/commit/b86834d40591aed86d62b57dd4b7dd27aa6d6b7c
  Author: Karl Dubost <[email protected]>
  Date:   2026-06-26 (Fri, 26 Jun 2026)

  Changed paths:
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-font-change-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-font-change.html
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-non-px-source-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-non-px-source.html
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-percentage-directionality-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-percentage-directionality.html
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-readonly-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-readonly.html
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-reserialization-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-reserialization.html
    M 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-px-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-px.html
    R LayoutTests/svg/dom/SVGLength-px-expected.txt
    R LayoutTests/svg/dom/SVGLength-px.html
    M Source/WebCore/svg/SVGLength.cpp
    M Source/WebCore/svg/SVGLengthContext.cpp

  Log Message:
  -----------
  convertToSpecifiedUnits - conversion from px to percentage, em and ex is 
failing
https://bugs.webkit.org/show_bug.cgi?id=308949
rdar://172056830

Reviewed by Nikolas Zimmermann.

Per the SVG2 spec algorithm for convertToSpecifiedUnits,
See 
https://w3c.github.io/svgwg/svg2-draft/single-page.html#types-__svg__SVGLength__convertToSpecifiedUnits

when an SVGLength has no associated element:
1. the viewport size basis is 100 for percentages
2. the font-size basis is the initial value of the font-size property for
   em/ex units.

CSS defines this initial value as 'medium' but does not specify its
absolute size. 16px is a universal UA convention, matching DefaultFontSize
in UnifiedWebPreferences.yaml.

Since detached SVGLengths have no document to query Settings from, the
value is hardcoded as a file-scope constant (initialFontSizePx).
Previously WebKit threw NotSupportedError for these conversions on detached
elements. This patch implements the spec-defined fallbacks in SVGLengthContext.

Additionally, SVGLength::convertToSpecifiedUnits was missing a call to
updateStyleIfNeeded() before performing the conversion, unlike 
valueForBindings().
This caused em/ex conversions on attached elements with custom font-sizes to
use stale style data (initial 16px instead of the element's computed font-size).

Also fixes the upstream WPT test SVGLength-px.html which called 
getComputedStyle()
on a detached element (returns empty string per CSSOM spec), producing NaN as
the reference font-size. The fix uses a temporary attached probe element 
instead.

This was also an opportunity to add more test cases in WPT for handling
different variations of the convertToSpecifiedUnits method.

Tests: 
imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-font-change.html
       
imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-non-px-source.html
       
imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-percentage-directionality.html
       
imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-readonly.html
       
imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-reserialization.html

* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-font-change-expected.txt:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-font-change.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-non-px-source-expected.txt:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-non-px-source.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-percentage-directionality-expected.txt:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-percentage-directionality.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-readonly-expected.txt:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-readonly.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-reserialization-expected.txt:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-convertToSpecifiedUnits-reserialization.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-px-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGLength-px.html:
  Fix getComputedStyle on detached element producing NaN; use attached probe 
element.
  Fix exact valueAsString comparison for em (trailing zero serialization 
varies).
* LayoutTests/svg/dom/SVGLength-px-expected.txt: Removed.
* LayoutTests/svg/dom/SVGLength-px.html: Removed.

* Source/WebCore/svg/SVGLength.cpp:
  (WebCore::SVGLength::convertToSpecifiedUnits):
  Add updateStyleIfNeeded() before conversion, matching valueForBindings().

(WebCore::SVGLength::convertToSpecifiedUnits):
* Source/WebCore/svg/SVGLengthContext.cpp:
  (WebCore::SVGLengthContext::computeNonCalcLength):
  Fall back to initial font-size (16px) for font-relative units when no 
associated element.
  (WebCore::SVGLengthContext::convertValueFromUserUnitsToPercentage):
  Fall back to viewport basis of 100 when no associated element.
  (WebCore::SVGLengthContext::convertValueFromPercentageToUserUnits):
  Same fallback for the reverse direction.
  (WebCore::SVGLengthContext::convertValueFromUserUnitsToEXS):
  Fall back to 0.5em (8px) x-height when no associated element.
  (WebCore::SVGLengthContext::convertValueFromEXSToUserUnits):
  Same fallback for the reverse direction.
(WebCore::SVGLengthContext::computeNonCalcLength const):
(WebCore::SVGLengthContext::convertValueFromUserUnitsToPercentage const):
(WebCore::SVGLengthContext::convertValueFromPercentageToUserUnits const):
(WebCore::SVGLengthContext::convertValueFromUserUnitsToEXS const):
(WebCore::SVGLengthContext::convertValueFromEXSToUserUnits const):

Canonical link: https://commits.webkit.org/315953@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to