Skip to content

Conversation

@eerii
Copy link
Member

@eerii eerii commented Sep 24, 2025

80e858b

Implement text-transform: math-auto.
https://bugs.webkit.org/show_bug.cgi?id=202302

Reviewed by Frédéric Wang and Tim Nguyen.

MathML Core defines the math-auto text-transform
(https://w3c.github.io/mathml-core/#math-auto-transform). On text nodes
containing a single character, it maps it to the italic counterpart.

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/css/css-text/parsing/text-transform-computed-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-text/parsing/text-transform-valid-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-text/text-transform/math/text-transform-math-auto-003-expected.txt:
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/css/CSSPrimitiveValueMappings.h:
* Source/WebCore/css/CSSProperties.json:
* Source/WebCore/css/CSSValueKeywords.in:
* Source/WebCore/css/parser/CSSParserContext.cpp:
(WebCore::applyUASheetBehaviorsToContext):
(WebCore::add):
* Source/WebCore/css/parser/CSSParserContext.h:
* Source/WebCore/rendering/RenderText.cpp:
(WebCore::convertToMathAuto):
(WebCore::applyTextTransform):
* Source/WebCore/rendering/style/RenderStyle.h:
* Source/WebCore/rendering/style/RenderStyleConstants.cpp:
(WebCore::operator<<):
* Source/WebCore/rendering/style/RenderStyleConstants.h:
* Source/WebCore/style/StyleBuilderConverter.h:
(WebCore::Style::BuilderConverter::convertTextTransform):
* Source/WebCore/style/StyleExtractorConverter.h:
(WebCore::Style::ExtractorConverter::convertTextTransform):
* Source/WebCore/style/StyleExtractorSerializer.h:
(WebCore::Style::ExtractorSerializer::serializeTextTransform):
* Source/WebInspectorUI/UserInterface/External/CSSDocumentation/CSSDocumentation.js:

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

38de434

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🛠 🧪 jsc ✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-arm64 ✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp ✅ 🛠 jsc-armv7
✅ 🛠 tv-sim ✅ 🧪 jsc-armv7-tests
✅ 🛠 watch
✅ 🛠 watch-sim

@Ahmad-S792 Ahmad-S792 added the MathML For bugs specific to MathML. label Sep 24, 2025
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Sep 24, 2025
@eerii eerii marked this pull request as draft September 25, 2025 10:38
@eerii eerii changed the title Implement text-transform: math-auto and adapt mathvariant attribute. Implement text-transform: math-auto. Sep 25, 2025
@eerii eerii marked this pull request as ready for review September 26, 2025 13:28
@eerii
Copy link
Member Author

eerii commented Sep 29, 2025

Hi @Ahmad-S792, whenever you can would it be ok for you to review this patch? Or maybe point me to another reviewer. Thanks! :)

@Ahmad-S792
Copy link
Contributor

Hi @Ahmad-S792, whenever you can would it be ok for you to review this patch? Or maybe point me to another reviewer. Thanks! :)

Unfortunately, I don't have reviewer rights, so I would defer the review from Apple side to @nt1m or @mdubet or @vitorroriz .

@eerii
Copy link
Member Author

eerii commented Oct 1, 2025

Since this is quite a large diff from the previous version, here is a list of changes and the motivation behind them:

  • Moved RenderMathMLToken::transformToMathVariant to TextTransform::transformToMathAuto. Removed the MathVariant argument since this is supposed to only do the italic transformation.
  • Moved RenderMathMLToken::mathVariant to TextTransform::mathVariantLegacy. This is the part that is still called from RenderMathMLToken when CSSTextTransformMathVariantEnabled is off.
  • Moved MathMLElement::MathVariant to TextTransform::MathVariant.
  • Moved MathMLTokenElement::convertToSingleCodePoint to TextTransform::convertToSingleCodePoint. Now it doesn't trim the whitespace around the codepoint. It was only called in two places, one of them RenderMathMLToken::updateMathVariantGlyph, which now do the trimming before calling the function. transformToMathVariant doesn't trim it to align more with how MathML Core is defined right now (pending Simplify whitespace collapsing/trimming for text nodes ; Support in Core? w3c/mathml-core#272 resolution). Perhaps this part should be in StringView or other utility header?

Additionally I removed the exceptions in the test expectations for iOS and Mac, let's see what the failures are in the EWS. Maybe they are not doing the text transform properly or maybe it's an issue with fonts.

WebKitLegacy:
default: false
WebKit:
"PLATFORM(GTK) || PLATFORM(WPE)": true
Copy link
Contributor

@vitorroriz vitorroriz Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this on by default for these platforms?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I started developing this under coreMathMLEnabled, which is on for GTK and WPE. We thought it was better to move it to a standalone preference, so when I was making it I set the same defaults as the previous one. The next step should be disabling the legacy mathvariant behaviour when MathML Core and this preference are enabled, so I think it makes sense having that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could enable text-transform: math-auto on all platforms. However, this is interacting with the mathvariant attribute and may lead to unexpected results for web developers when the legacy mathvariant attribute values are enabled. So probably better to keep math-auto disabled on platforms that have MathML Core disabled.

eerii added a commit to eerii/WebKit that referenced this pull request Oct 2, 2025
https://bugs.webkit.org/show_bug.cgi?id=202302

Reviewed by NOBODY (OOPS!).

Part of WebKit#51271. Moves the MathVariant enum and the mathVariant function to
the TextTransform file, making it easier to implement
text-transform: math-auto in the next patch without having RenderText
depend on various MathML classes.

Also moves the convertToSingleCodePoint function there, which now
doesn't perform whitespace trimming of the input string, as MathML Core
doesn't define this. The two existing callers of this function are changed
to do the trimming beforehand.

No behaviour change.

* Source/WebCore/mathml/MathMLElement.h:
* Source/WebCore/mathml/MathMLOperatorElement.cpp:
(WebCore::MathMLOperatorElement::parseOperatorChar):
* Source/WebCore/mathml/MathMLPresentationElement.cpp:
(WebCore::MathMLPresentationElement::parseMathVariantAttribute):
(WebCore::MathMLPresentationElement::specifiedMathVariant):
* Source/WebCore/mathml/MathMLTokenElement.cpp:
(WebCore::MathMLTokenElement::convertToSingleCodePoint): Deleted.
* Source/WebCore/mathml/MathMLTokenElement.h:
* Source/WebCore/platform/graphics/TextTransform.cpp:
(WebCore::convertToSingleCodePoint):
(WebCore::ExtractKey):
(WebCore::MathVariantMappingSearch):
(WebCore::legacyMathVariant):
* Source/WebCore/platform/graphics/TextTransform.h:
* Source/WebCore/rendering/mathml/MathMLStyle.cpp:
(WebCore::MathMLStyle::updateStyleIfNeeded):
(WebCore::MathMLStyle::resolveMathMLStyle):
* Source/WebCore/rendering/mathml/MathMLStyle.h:
* Source/WebCore/rendering/mathml/RenderMathMLToken.cpp:
(WebCore::RenderMathMLToken::updateMathVariantGlyph):
(WebCore::ExtractKey): Deleted.
(WebCore::MathVariantMappingSearch): Deleted.
(WebCore::mathVariant): Deleted.
@eerii eerii marked this pull request as draft October 2, 2025 11:41
@eerii eerii requested a review from fred-wang October 17, 2025 09:46
Copy link
Contributor

@fred-wang fred-wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit difficult for me to understand this code without digging more, so I'll defer to other reviewers.

But as I see math-auto cannot be combined with other values per https://www.w3.org/TR/css-text-4/#text-transform-property

So your code does really follow the spec.

Do we have WPT tests to check different cases of math-auto combined with other values? Can we add some?

Copy link
Contributor

@fred-wang fred-wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but deferring to CSS reviewers.

@eerii
Copy link
Member Author

eerii commented Oct 22, 2025

@nt1m, @vitorroriz could you take a look at the updated version whenever you can? Thanks!

@eerii eerii requested review from nt1m and vitorroriz October 22, 2025 07:12
@fred-wang fred-wang added safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks and removed merging-blocked Applied to prevent a change from being merged labels Oct 23, 2025
@webkit-ews-buildbot webkit-ews-buildbot added merge-queue Applied to send a pull request to merge-queue and removed safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks labels Oct 23, 2025
@webkit-ews-buildbot
Copy link
Collaborator

Safe-Merge-Queue: Build #72940.

https://bugs.webkit.org/show_bug.cgi?id=202302

Reviewed by Frédéric Wang and Tim Nguyen.

MathML Core defines the math-auto text-transform
(https://w3c.github.io/mathml-core/#math-auto-transform). On text nodes
containing a single character, it maps it to the italic counterpart.

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/css/css-text/parsing/text-transform-computed-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-text/parsing/text-transform-valid-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-text/text-transform/math/text-transform-math-auto-003-expected.txt:
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/css/CSSPrimitiveValueMappings.h:
* Source/WebCore/css/CSSProperties.json:
* Source/WebCore/css/CSSValueKeywords.in:
* Source/WebCore/css/parser/CSSParserContext.cpp:
(WebCore::applyUASheetBehaviorsToContext):
(WebCore::add):
* Source/WebCore/css/parser/CSSParserContext.h:
* Source/WebCore/rendering/RenderText.cpp:
(WebCore::convertToMathAuto):
(WebCore::applyTextTransform):
* Source/WebCore/rendering/style/RenderStyle.h:
* Source/WebCore/rendering/style/RenderStyleConstants.cpp:
(WebCore::operator<<):
* Source/WebCore/rendering/style/RenderStyleConstants.h:
* Source/WebCore/style/StyleBuilderConverter.h:
(WebCore::Style::BuilderConverter::convertTextTransform):
* Source/WebCore/style/StyleExtractorConverter.h:
(WebCore::Style::ExtractorConverter::convertTextTransform):
* Source/WebCore/style/StyleExtractorSerializer.h:
(WebCore::Style::ExtractorSerializer::serializeTextTransform):
* Source/WebInspectorUI/UserInterface/External/CSSDocumentation/CSSDocumentation.js:

Canonical link: https://commits.webkit.org/302003@main
@webkit-commit-queue
Copy link
Collaborator

Committed 302003@main (80e858b): https://commits.webkit.org/302003@main

Reviewed commits have been landed. Closing PR #51271 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 80e858b into WebKit:main Oct 23, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Oct 23, 2025
@rkirsling
Copy link
Member

This broke PlayStation (which has a committer-restricted EWS) due to a missing include (or #if):

C:/BW/PlayStation-Debug-Build/build/Source/WebCore\rendering/RenderText.cpp:1677:84: error: use of undeclared identifier 'MathVariant'
 1677 |         char32_t transformedCodePoint = mathVariantMapCodePoint(codePoint.value(), MathVariant::Italic);
      |                                                                                    ^

This should be trivial enough to not warrant a revert; let me know if you can fix this quickly, otherwise I can do so this time.

@rkirsling
Copy link
Member

Fixing in #52864.

@eerii
Copy link
Member Author

eerii commented Oct 23, 2025

Thanks for the quick fix @rkirsling

@eerii eerii deleted the mathvariant branch October 29, 2025 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MathML For bugs specific to MathML.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants