Handling Ignorable Text in a Renderer
In certain MathML constructs (e.g. mfenced) there are a number of child elements that make up the construct and need to be rendered. Any text between those child elements should be ignored. In fact, non-whitespace text in the wrong place is most certainly incorrect but something that can be recovered from. I don't want to remove the text from the DOM nodes but I need to keep the RenderText instances from being created or displayed. What is the correct way to do this? I've been trying to handle this in the renderer but it seems like that is really too late. I though about changing the attach method to exclude such ignorable text. -- --Alex Milowski "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 considered." Bertrand Russell in a footnote of Principles of Mathematics
On Wed, Aug 26, 2009 at 12:06 PM, Alex Milowski<alex@milowski.org> wrote:
In certain MathML constructs (e.g. mfenced) there are a number of child elements that make up the construct and need to be rendered. Any text between those child elements should be ignored. In fact, non-whitespace text in the wrong place is most certainly incorrect but something that can be recovered from.
I don't want to remove the text from the DOM nodes but I need to keep the RenderText instances from being created or displayed. What is the correct way to do this?
I've been trying to handle this in the renderer but it seems like that is really too late. I though about changing the attach method to exclude such ignorable text.
Here's what works but it feels like a hack: RenderBlock* none = new (renderArena()) RenderBlock(document()); RefPtr<RenderStyle> newStyle = RenderStyle::create(); newStyle->inheritFrom(style()); newStyle->setDisplay(INLINE_BLOCK); newStyle->setMaxWidth(Length(0,Fixed)); newStyle->setMaxHeight(Length(0,Fixed)); newStyle->setOverflowX(OHIDDEN); newStyle->setOverflowY(OHIDDEN); none->setStyle(newStyle.release()); RenderBlock::addChild(none, beforeChild); none->addChild(child); I basically create an inline block with zero width and height and then set the overflow to hidden. -- --Alex Milowski "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 considered." Bertrand Russell in a footnote of Principles of Mathematics
If you have your own renderobject subclass you can override: virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; } If you don't have your own subclass, then it's trickier. You basically can suppress the creation of RenderTexts completely inside bool Text::rendererIsNeeded(RenderStyle *style) However, that function is extremely performance critical, so any code that gets added to that function would need to be examined very carefully. You might want to study some of what SVG did on the DOM side of things to suppress the creation of renderers. I believe Eric Seidel did that work and could help you out. I suspect there might be similarities. dave (hyatt@apple.com) On Aug 26, 2009, at 1:19 PM, Alex Milowski wrote:
On Wed, Aug 26, 2009 at 12:06 PM, Alex Milowski<alex@milowski.org> wrote:
In certain MathML constructs (e.g. mfenced) there are a number of child elements that make up the construct and need to be rendered. Any text between those child elements should be ignored. In fact, non- whitespace text in the wrong place is most certainly incorrect but something that can be recovered from.
I don't want to remove the text from the DOM nodes but I need to keep the RenderText instances from being created or displayed. What is the correct way to do this?
I've been trying to handle this in the renderer but it seems like that is really too late. I though about changing the attach method to exclude such ignorable text.
Here's what works but it feels like a hack:
RenderBlock* none = new (renderArena()) RenderBlock(document()); RefPtr<RenderStyle> newStyle = RenderStyle::create(); newStyle->inheritFrom(style()); newStyle->setDisplay(INLINE_BLOCK); newStyle->setMaxWidth(Length(0,Fixed)); newStyle->setMaxHeight(Length(0,Fixed)); newStyle->setOverflowX(OHIDDEN); newStyle->setOverflowY(OHIDDEN); none->setStyle(newStyle.release()); RenderBlock::addChild(none, beforeChild); none->addChild(child);
I basically create an inline block with zero width and height and then set the overflow to hidden.
-- --Alex Milowski "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 considered."
Bertrand Russell in a footnote of Principles of Mathematics _______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
On Wed, Aug 26, 2009 at 1:36 PM, David Hyatt<hyatt@apple.com> wrote:
If you have your own renderobject subclass you can override:
virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; }
Excellent. That works and is much cleaner. I'll need renderers for all the element containers in MathML so this will probably work out just fine. Thanks! -- --Alex Milowski "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 considered." Bertrand Russell in a footnote of Principles of Mathematics
participants (2)
-
Alex Milowski
-
David Hyatt