Open Bug 1264520 Opened 8 years ago Updated 7 months ago

Support mixed number, unit value, and percent for calc() parser including type checking

Categories

(Core :: CSS Parsing and Computation, defect, P3)

defect

Tracking

()

People

(Reporter: boris, Unassigned)

References

(Blocks 2 open bugs, )

Details

(Keywords: dev-doc-needed)

According to Bug 594933 comment 28 and 29, the unit checking in the parsing code needs additional changes. For example, our code can parse calc(1 + 2) and calc(1px + 2px),

but doesn't accept calc(1 + 2px),

which ought to be accepted for line-height, stroke-dashoffset, and stroke-width. There is various code in the functions inside of ParseCalc that needs updating, and some comments also need updating. There's currently no spec for it, but it's better to handle this case.
Also, my understanding from bug 594933 is that other browser engines don't currently support this (I think that's silly, but it's also the reason I said fixing bug 594933 without this was OK).  If that changes, somebody should update this bug to say so!
Blocks: 1218257
No longer depends on: 1218257
(In reply to Boris Chiou [:boris] from comment #0)
> For example, our code can parse calc(1 + 2)

(To clarify something that confused me initially -- so, you're right that we do support that expression *for line-height*, but we don't support calc(number+number) or calc(integer+integer) in general, e.g. in the number-valued "opacity" property or the integer-valued "z-index" property.  Bug 1296209 partly covers that.  calc(1+2) only works for "line-height" via a custom "SetLineHeightCalcOps" calc-handling class that lives in nsRuleNode.cpp right now.)
See Also: → 1278264
Blocks: 1278264
Priority: -- → P3
Blocks: 1298537
What's possible for calc() and what not is outlined in https://drafts.csswg.org/css-values-3/#calc-notation.

Sebastian

Does this bug cover type checking as defined in CSS Values 4? I.e. will it be used to cover unit algebra with multiplication and division like calc(3rem / 2rem)?

Sebastian

Flags: needinfo?(boris.chiou)

This bug was filed for the legacy implementation of calc(). Now we are using Rust to parse calc(), so I think we definitely can extend this bug to cover the case you mentioned (i.e. including all the type checking for calc()). Feel free to update the title if needed.

Flags: needinfo?(boris.chiou)
Severity: normal → S3
Summary: Support mixed number, unit value, and percent for calc() parser → Support mixed number, unit value, and percent for calc() parser including type checking
You need to log in before you can comment on or make changes to this bug.