Align definition of MathML length values on CSS <length-percentage>
Categories
(Core :: MathML, defect)
Tracking
()
People
(Reporter: fwang, Assigned: fwang)
References
(Depends on 1 open bug, Blocks 1 open bug)
Details
(Keywords: dev-doc-needed, site-compat)
... and use the CSS parser instead.
Main differences:
- keywords values: bug 1548527, bug 1548529, bug 1574750
- nonzero unitless: bug 1574749
They are probably a few minor differences that I hope won't affect users:
- leading/trailing whitespace in attribute value: The MathML CG has not decided about this yet. I guess it's not a big burden to keep supporting it, though.
- definition of numbers: MathML3 allows things like "5." (no digit after the dot) which are not supported by CSS and conversely CSS allows things like "1E1em" (E notation) which are not supported by MathML3. The MathML CG agrees it should be safe to move to the CSS definition: https://github.com/mathml-refresh/mathml/issues/23
MathML Core defines lengths here, relying on CSS:
https://mathml-refresh.github.io/mathml-core/#types-for-mathml-attribute-values
For now, mpadded still has its own syntax:
https://mathml-refresh.github.io/mathml-core/#attribute-mpadded-width
| Assignee | ||
Comment 1•7 years ago
|
||
Quick analysis: https://searchfox.org/mozilla-central/search?q=ParseNumericValue
*: scripminsize (see bug 1548471) and mathsize (mapped to font-size).
mtable: width (mapped to width)
mo: lspace, rspace, minsize, maxsize (default/reference values involved DOM/operator dictionary)
mfrac@linethickness (default/reference values is read from the font)
msub/msup/msubsup/mmultiscripts: subscriptshift and superscriptshift (see https://github.com/mathml-refresh/mathml/issues/27)
mspace: width, height, depth (default/reference values are 0)
mpadded: width, height and depth. This element has its own syntax and uses nsMathMLElement::ParseNumericValue to parse some token.
mtable/mtr/mtd: rowspacing, columnspacing, framespacing (no idea what we will do with these yet, MathML core only describes simple table layout). This also relies on nsMathMLElement::ParseNumericValue as a helper to parse a more general syntax.
| Assignee | ||
Comment 2•7 years ago
|
||
MathML 3:
https://www.w3.org/TR/MathML3/chapter2.html#fund.units
- a number: an optional prefix of "-" (U+002D), followed by a a string of
decimal digits with up to one decimal point (U+002E).
(the RelaxNG schema https://www.w3.org/TR/MathML3/appendixa.html#parsing_length requires at least one digit and that's what we support.) - or a number followed by a unit
- units are em, ex, px, in, cm, mm, pt, pc, %
- or a namedspace: "thickmathspace" etc.
MathML Core / CSS:
https://mathml-refresh.github.io/mathml-core/#dfn-length-percentage
-
length-percentage:
- a length: number immediately followed by a unit identifier
- unit is em, ex, ch, rem, vw, vh, vmin, vmax, cm, mm, Q, in, pc, pt or px.
- unit is optional for 0.
- or a percentage: number immediately followed by a '%'
- a length: number immediately followed by a unit identifier
-
number:
- integer: one or more decimal digits 0 through 9
- or zero or more decimal digits followed by a dot (.) followed by one or
more decimal digits and optionally an exponent composed of "e" or "E" and
an integer. - may be immediately preceded by - or +.
@emilio: So if I'm correct after we remove namedspace (bug 1574750) and nonzero unitless (bug 1574749) then the only remaining possible regression is the case when the number has a dot but no digits after it e.g. "123456789." ; In that case, for now we coud just update nsMathMLElement::ParseNumericValue to treat this case as invalid. I wonder if we could just do an "intent to unship" with that change directly rather than using counters / deprecation warning. WDYT?
Comment 3•7 years ago
|
||
CSS has also the case of preceding comments or such right? Is /**/10px supposed to parse or not?
I think changing ParseNumericValue would be fine, but probably would be better with a use counter, or at the very least without a runtime switch.
| Assignee | ||
Comment 4•7 years ago
|
||
(In reply to Emilio Cobos Álvarez (:emilio) from comment #3)
CSS has also the case of preceding comments or such right? Is
/**/10pxsupposed to parse or not?
I copied the definition from here: https://www.w3.org/TR/css-values-3/#typedef-length-percentage
Comments are not part of this definition.
I think changing ParseNumericValue would be fine, but probably would be better with a use counter, or at the very least without a runtime switch.
The tentative change is small: https://phabricator.services.mozilla.com/D42907
Do you mean with a runtime switch?
So you pref to do an intent to deprecate + warning / counter as in bug 1575542?
Comment 5•7 years ago
|
||
(In reply to Frédéric Wang (:fredw) from comment #4)
Do you mean with a runtime switch?
Err, yes. Intent to unship for that change + a pref to default-error for that case seems ok to me.
| Assignee | ||
Comment 6•6 years ago
|
||
(In reply to Frédéric Wang (:fredw) from comment #0)
- leading/trailing whitespace in attribute value: The MathML CG has not decided about this yet. I guess it's not a big burden to keep supporting it, though.
For the record, it's https://github.com/mathml-refresh/mathml/issues/122
| Assignee | ||
Comment 7•6 years ago
|
||
Idea after discussion with Emilio:
- Introduce new internal CSS properties for MathML length attributes.
- Compare with SVG: https://searchfox.org/mozilla-central/source/servo/components/style/properties/longhands/svg.mako.rs#108
Can you please complete that, pointing to the relevant part of the code?
Comment 8•6 years ago
|
||
Yeah, so:
- Probably you need a setup like the SVG setup for mapped attributes, so storing a declaration block in MathMLElement: https://searchfox.org/mozilla-central/rev/17756e2a5c180d980a4b08d99f8cc0c97290ae8d/dom/svg/SVGElement.h#592
- We'd need to use something similar to SVG's MappedAttrParser: https://searchfox.org/mozilla-central/rev/17756e2a5c180d980a4b08d99f8cc0c97290ae8d/dom/svg/SVGElement.cpp#1126, but that potentially gets the
nsCSSPropertyIDfrom an attribute name, or calls directly into there, or something. It'd be nice not to duplicate the URL data bits. - We may want to use a separate style struct for these properties (instead of
nsStyleSVG/nsStyleSVGReset). It may need a pair if there are both inherited and non-inherited properties. But probably to prototype this a single property innsStyleSVGor such could do. - You need to return the declaration from: https://searchfox.org/mozilla-central/rev/17756e2a5c180d980a4b08d99f8cc0c97290ae8d/layout/style/GeckoBindings.cpp#376. Probably we should rename that function somehow.
Maybe it'd be worth trying to unify a bit the mapped attribute setup... Boris, do you know why the SVG setup looks like it does rather than reusing nsMappedAttributes? Or vice-versa, couldn't we have a declaration block in the slots in Element and unify all of HTML / SVG / MathML handling of presentation attributes?
I suspect that may also fix the bug where we reorder attributes due to some of them being mapped. This last bit is probably work that shouldn't block the MathML stuff either way (should be done either before that or once that lands).
Comment 9•6 years ago
|
||
Boris, do you know why the SVG setup looks like it does rather than reusing nsMappedAttributes?
nsMappedAttributes is designed to solve a specific problem: a web page that has 5000 <font face="Arial"> elements on it. nsMappedAttributes, in that setup, produces a single declaration block containing font-family: Arial that is shared by all the elements involved. This made a lot of sense in the early 2000s, because that style of HTML was quite common at the time. I don't know how common it is nowadays; it would be interesting to get some telemetry about how much sharing we get out of nsMappedAttributes in practice.
In SVG, my understanding is that it's not very common to have identical sets of mapped attributes across multiple elements, because in practice that would mean that those elements are positioned on top of each other and look identical or close to it, which is not what SVG authors typically want. So there was no particular reason to add the overhead of nsMappedAttributes there, because there would not be much of a win from doing it, if any.
At least I would say that's the main reason we haven't unified them in the recent past. I don't know whether the initial implementation actually considered any of that or just Did Something Because It Worked.
Comment 10•6 years ago
|
||
(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #9)
Boris, do you know why the SVG setup looks like it does rather than reusing nsMappedAttributes?
nsMappedAttributesis designed to solve a specific problem: a web page that has 5000<font face="Arial">elements on it.nsMappedAttributes, in that setup, produces a single declaration block containingfont-family: Arialthat is shared by all the elements involved. This made a lot of sense in the early 2000s, because that style of HTML was quite common at the time. I don't know how common it is nowadays; it would be interesting to get some telemetry about how much sharing we get out ofnsMappedAttributesin practice.In SVG, my understanding is that it's not very common to have identical sets of mapped attributes across multiple elements, because in practice that would mean that those elements are positioned on top of each other and look identical or close to it, which is not what SVG authors typically want. So there was no particular reason to add the overhead of
nsMappedAttributesthere, because there would not be much of a win from doing it, if any.
For what is worth I'm not too clear that it wouldn't be worth sharing in SVG, given <svg:use> and co. See bug 1485402 for example.
Though now that declaration blocks are not stored in a linked list in the rule tree (bug 1493420) the performance impact of having them should be minor, it'd be just a memory optimization (maybe still worth it).
Comment 11•6 years ago
|
||
Right, pre-stylo sharing declaration blocks was both a memory optimization and a performance optimization (because it enabled a lot more caching to work). It's possible it's not as much of a win now.
Comment 12•6 years ago
|
||
Well I guess with stylo it also enables to share styles across siblings and such, though probably much less indeed...
Updated•3 years ago
|
| Assignee | ||
Comment 13•1 year ago
|
||
Simon Fraser reported an interesting bug for WebKit: https://bugs.webkit.org/show_bug.cgi?id=281232
| Assignee | ||
Updated•1 year ago
|
Description
•