[webkit-dev] MathML Anonymous Block Conundrum
alex at milowski.org
Tue Jun 21 07:39:12 PDT 2011
I've run into a conundrum with "anonymous blocks" yet again. I was
helping track down a crash relating to DOM manipulation. While I
fixed that particular case by just marking all the instances as
anonymous blocks, this solution doesn't work in general.
In many places in the MathML rendering code we create
RenderMathMLBlock instances that are used to layout different
constructs. For example, for fractions we stack two RenderMathMLBlock
instances as wrappers for the numerator and denominator. In many
instances, that is all we need to do. In other instances, such as
fractions, we set style properties on each created instance.
Here's the problem:
If the created wrappers are marked as anonymous, the style created for
the wrapper is ignored due to this bit from the CSS 2.1
"The properties of anonymous boxes are inherited from the enclosing
non-anonymous box (e.g., in the example just below the subsection
heading "Anonymous block boxes", the one for DIV). Non-inherited
properties have their initial value. For example, the font of the
anonymous box is inherited from the DIV, but the margins will be 0."
If we don't mark them as anonymous, we can get a crash related to
where it is searching for the anonymous wrapper that doesn't exist.
In fact, I believe the problem is that the beforeChild parameter is
the rendering object that has been wrapped and not the wrapper. As
such, beforeChild is "wrong" and by adding something like:
if (beforeChild && !beforeChild->isRenderMathMLBlock())
beforeChild = beforeChild->parent();
I can fix that before I use it to add the wrapper. I would have to do
this in all places where I know that I have wrappers with styles and
where I could actually guarantee what I'm doing. In the case of
fractions, over/under, and a few others, this may work fine.
This doesn't feel like a good general solution.
Also, if I wrap an added child and code elsewhere assumes that the
parent/child relationship is the same as in the DOM, then I've broken
their assumption. I see this same kind of behavior with table
sections in the RenderTable object and I wonder why beforeChild isn't
a problem there.
I fail to understand why I need to mark things as anonymous as they
aren't anonymous in the same sense of CSS. This is a layout construct
needed to display the Mathematics. I need to create these rendering
objects that do not correspond directly to a element in the way as
most others do.
I think I'm beginning to appreciate some of what Dave Hyatt was
hinting at to me that I may need my own line layout algorithm but I
still really don't want to go there. That is, layout of a fraction
doesn't feel like line layout to me.
"The excellence of grammar as a guide is proportional to the paucity of the
inflexions, i.e. to the degree of analysis effected by the language
Bertrand Russell in a footnote of Principles of Mathematics
More information about the webkit-dev