Open Bug 2044096 Opened 5 days ago Updated 28 minutes ago

Add missing pieces for CSSMathValue objects

Categories

(Core :: CSS Parsing and Computation, task)

task

Tracking

()

ASSIGNED

People

(Reporter: janv, Assigned: janv)

References

(Blocks 2 open bugs)

Details

(Keywords: leave-open)

Attachments

(19 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

This bug tracks additional implementation work for CSSMathValue objects as defined in the CSS Typed OM Level 1 specification.

The work focuses on object infrastructure, including constructors, attribute getters, and serialization support for CSSMathValue subclasses.

This complements the existing stub CSSMathValue implementation and provides the remaining pieces needed for CSSMathProduct, CSSMathNegate, CSSMathInvert, CSSMathMin, CSSMathMax, and CSSMathClamp objects to be usable from JS.

This intentionally excludes CSSMathSum, which already gained most of the required infrastructure to support reification and associated WPT coverage. However, this bug may still include additional improvements that are shared with or benefit CSSMathSum as well.

Change MathSum from a wrapper struct to a type alias for ThinVec<NumericValue>,
matching the representation used by some other types.

This reduces boilerplate when constructing and iterating over sum values, and
prepares for introducing a separate MathValue enum matching CSSMathValue and
its subclasses.

Change CSSNumericValue::ToStyleNumericValue() to return
Maybe<StyleNumericValue> instead of StyleNumericValueResult.

This matches the style planned for future conversion helpers and avoids the
need for dedicated result wrapper types for each return value.

Introduce MathValue as the representation for CSSMathValue subclasses and move
MathSum under it.

This makes NumericValue distinguish between CSSUnitValue and CSSMathValue at
the top level, with individual CSSMathValue subclasses represented by
MathValue. Although this adds a small amount of construction boilerplate, it
gives the C++ side a cleaner type hierarchy and allows CSSMathValue-specific
switch statements without mixing in unrelated CSSUnitValue handling.

This also prepares adding the remaining CSSMathValue subclasses.

Return the CSSMathOperator value corresponding to the stored MathValueType.

This currently only handles CSSMathSum, with the temporary uninitialized state
falling back to "sum". Follow-up patches will extend this as more CSSMathValue
subclasses are added.

Make CSSMathSum use the existing CSSNumericValue creation, serialization, and
conversion helpers instead of handling CSSUnitValue directly.

This removes CSSMathSum-specific type checks and keeps the implementation
consistent with the rest of the code. It also prepares for adding the remaining
CSSMathValue subclasses, which will rely on the same CSSNumericValue entry
points.

Add a CSSNumericValue::ToCssTextWithProperty overload with an explicit nested
flag and propagate it to CSSMathSum::ToCssTextWithProperty.

CSSMathSum currently always serializes as calc(...), even when nested inside
another math expression, resulting in output such as calc(calc(...)). With the
nested serialization context, nested sums are serialized using parentheses
instead, matching the CSSMathSum serialization algorithm.

While this fixes CSSMathSum serialization behavior, it also prepares for adding
other CSSMathValue subclasses that may need nested serialization support.

Fix what appears to be a copy-and-paste error in the CSS Typed OM
serialization tests.

The "CSSMathMax with pixel arguments" test was constructing CSSMathMin and
expecting min(...) serialization. Update it to construct CSSMathMax and expect
max(...) serialization, matching the test description and surrounding
CSSMathMax coverage.

Implement the remaining CSSMathMin object infrastructure, including the
constructor, values getter, and serialization support.

This makes CSSMathMin usable from JS and removes the corresponding WPT
expectations. Some functionality, such as type checking and future conversion
to StyleMathMin, will be implemented in follow-up bugs.

Bug 2035572 refactored numeric types to distinguish between NoCalc and Calc
variants. As a result, percentage reification no longer receives values that
need the was_calc flag, and the flag is always false.

Remove the unused parameter and the corresponding dead code.

Implement the remaining CSSMathMax object infrastructure, including the
constructor, values getter, and serialization support.

This makes CSSMathMax usable from JS and removes the corresponding WPT
expectations. Some functionality, such as type checking and future conversion
to StyleMathMax, will be implemented in follow-up bugs.

Implement the remaining CSSMathClamp object infrastructure, including the
constructor, values getter, and serialization support.

This makes CSSMathClamp usable from JS and removes the corresponding WPT
expectations. Some functionality, such as type checking and future conversion
to StyleMathClamp, will be implemented in follow-up bugs.

Implement the remaining CSSMathNegate object infrastructure, including the
constructor, values getter, and serialization support.

This makes CSSMathNegate usable from JS and removes the corresponding WPT
expectations. Some functionality, such as type checking and future conversion
to StyleMathNegate, will be implemented in follow-up bugs.

Implement the remaining CSSMathInvert object infrastructure, including the
constructor, values getter, and serialization support.

This makes CSSMathInvert usable from JS and removes the corresponding WPT
expectations. Some functionality, such as type checking and future conversion
to StyleMathInvert, will be implemented in follow-up bugs.

Implement the remaining CSSMathProduct object infrastructure, including the
constructor, values getter, and serialization support.

This makes CSSMathProduct usable from JS and removes the corresponding WPT
expectations. Some functionality, such as type checking and future conversion
to StyleMathProduct, will be implemented in follow-up bugs.

Add a CSSNumericValue::ToCssTextWithProperty overload with an explicit
paren-less flag and propagate it to CSSMathValue::ToCssTextWithProperty.

For example, CSSMathMin currently always serializes nested values with
parentheses, resulting in output such as min((1 + 2), 3). With the paren-less
serialization context, nested values can be serialized as min(1 + 2, 3),
matching the CSSMathMin serialization algorithm.

This builds on the nested serialization context added previously and adjusts
the remaining CSSMathValue subclasses for correct serialization behavior.

Replace the nested and paren-less boolean parameters with a dedicated
CSSNumericValue::SerializationContext.

The previous API allowed an invalid combination where paren-less serialization
was requested without nested serialization. The new context represents only the
valid serialization states: root, nested, and nested paren-less.

This keeps the serialization code aligned with the CSSMathValue serialization
algorithms in the spec while making the call sites harder to misuse.

Handle CSSMathNegate children specially when serializing CSSMathSum.

The CSSMathSum serialization algorithm represents CSSMathNegate arguments after
the first value using subtraction syntax. For example, a sum that previously
serialized as calc(1 + (-2) + 3) now correctly serializes as calc(1 - 2 + 3).

This fixes the corresponding CSSMathSum serialization WPT.

Update the CSSTransformValue serialization expectation for a nested
CSSMathProduct containing CSSMathInvert.

The CSSMathProduct serialization algorithm represents CSSMathInvert arguments
after the first value using division syntax. As a result, the value should
serialize as calc(1deg / 0), not calc(1deg * (1 / 0)).

This matches the current WebKit behavior and the serialization behavior fixed
in the following patch.

Handle CSSMathInvert children specially when serializing CSSMathProduct.

The CSSMathProduct serialization algorithm represents CSSMathInvert arguments
after the first value using division syntax. For example, a product that
previously serialized as calc(1 * (1 / 2) * 3) now correctly serializes as
calc(1 / 2 * 3).

This fixes the corresponding CSSMathProduct serialization WPT.

Blocks: 2044316
Keywords: leave-open
Pushed by jvarga@igalia.com: https://github.com/mozilla-firefox/firefox/commit/77662ae96590 https://hg.mozilla.org/integration/autoland/rev/b5210a0ee254 Remove unused was_calc handling from percentage reification; r=emilio,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/beded41cea13 https://hg.mozilla.org/integration/autoland/rev/fab306bc6a8a Make MathSum a type alias; r=emilio,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/c90554021172 https://hg.mozilla.org/integration/autoland/rev/c53dc24d26e0 Use Maybe for CSSNumericValue::ToStyleNumericValue; r=firefox-style-system-reviewers,dshin https://github.com/mozilla-firefox/firefox/commit/81d0a185449e https://hg.mozilla.org/integration/autoland/rev/35c9fc741bc1 Add a separate MathValue type; r=emilio,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/dee878f2a31b https://hg.mozilla.org/integration/autoland/rev/88fe2a75d85e Implement CSSMathValue::Operator(); r=emilio,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/66cbbebccad8 https://hg.mozilla.org/integration/autoland/rev/d08eb505617c Use CSSNumericValue helpers in CSSMathSum; r=emilio,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/c61c00aeecd9 https://hg.mozilla.org/integration/autoland/rev/d8a64705b7dc Add nested serialization context to CSSMathSum; r=emilio,firefox-style-system-reviewers
Pushed by jvarga@igalia.com: https://github.com/mozilla-firefox/firefox/commit/39703d56d65e https://hg.mozilla.org/integration/autoland/rev/31564683ac06 Fix CSSMathMax serialization WPT test case; r=emilio,firefox-style-system-reviewers

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/60440 for changes under testing/web-platform/tests

Pushed by jvarga@igalia.com: https://github.com/mozilla-firefox/firefox/commit/0666876e3904 https://hg.mozilla.org/integration/autoland/rev/ff06f41d002e Add missing pieces for CSSMathMin; r=emilio,webidl,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/d9102c650e5c https://hg.mozilla.org/integration/autoland/rev/8c1ada690a80 Add missing pieces for CSSMathMax; r=emilio,webidl,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/1f1e044e308e https://hg.mozilla.org/integration/autoland/rev/9c69d00bedd5 Add missing pieces for CSSMathClamp; r=emilio,webidl,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/0266d34f9e32 https://hg.mozilla.org/integration/autoland/rev/a2f4d0464f3e Add missing pieces for CSSMathNegate; r=emilio,webidl,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/f25af4aca18f https://hg.mozilla.org/integration/autoland/rev/311b17731c38 Add missing pieces for CSSMathInvert; r=emilio,webidl,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/c36c6f6c4231 https://hg.mozilla.org/integration/autoland/rev/f66c946fa0d8 Add missing pieces for CSSMathProduct; r=emilio,webidl,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/159b59dacf46 https://hg.mozilla.org/integration/autoland/rev/843a5278d889 Add paren-less serialization context to CSSMathValue; r=emilio,firefox-style-system-reviewers https://github.com/mozilla-firefox/firefox/commit/7f77147a08d8 https://hg.mozilla.org/integration/autoland/rev/a3ed973d36f5 Add serialization context to CSSNumericValue; r=firefox-style-system-reviewers,dshin https://github.com/mozilla-firefox/firefox/commit/2f7837ee4bf7 https://hg.mozilla.org/integration/autoland/rev/413370c0ff62 Serialize CSSMathNegate children in CSSMathSum as subtraction; r=firefox-style-system-reviewers,dshin
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: