Convert MathML to use flexboxes
authordbarton@mathscribe.com <dbarton@mathscribe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Sep 2012 01:37:18 +0000 (01:37 +0000)
committerdbarton@mathscribe.com <dbarton@mathscribe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Sep 2012 01:37:18 +0000 (01:37 +0000)
commit560f8cbbc08db1cbba49bd207238ec0c9427579c
tree046c0b0c8266202ffc95fab370b37869772996ac
parent3a9e9f74df661166acd6d6ab3af79776db2af82a
Convert MathML to use flexboxes
https://bugs.webkit.org/show_bug.cgi?id=96843

Reviewed by Eric Seidel.

Source/WebCore:

Using the CSS Flexible Box Model simplifies MathML in many ways. Control over alignment, row vs.
column layout, and child layout order are all much easier. Complexities involving floats,
continuations, and most anonymous boxes are eliminated, as are their potential for crashes and
security vulnerabilities.

In a flexbox, column alignment is done with align-items or align-self, instead of text-align.
vertical-align and baselinePosition() are replaced by the firstLineBoxBaseline() virtual
function.

Tested by existing tests.

* css/mathml.css:
(math):
(math[display="block"]):
(mo, mrow, mfenced, mfrac, msub, msup, msubsup, munder, mover, munderover, msqrt, mroot):
(math, mrow, mfenced, msqrt, mroot):
(msqrt > *):
(mo, mfrac, munder, mover, munderover):
(munder, mover, munderover):
(mfrac > *):
(mfrac[numalign="left"] > :first-child):
(mfrac[numalign="right"] > :first-child):
(mfrac[denomalign="left"] > :last-child):
(mfrac[denomalign="right"] > :last-child):
(msubsup > :last-child, mover > :last-child, munderover > :last-child):
(msub > * + *, msup > * + *, msubsup > * + *, munder > * + *, mover > * + *, munderover > * + *):
(mroot):
(mroot > * + *):
(mtable):

* mathml/MathMLInlineContainerElement.cpp:
(WebCore::MathMLInlineContainerElement::createRenderer):
* mathml/mathtags.in:

* rendering/mathml/RenderMathMLBlock.cpp:
(WebCore::RenderMathMLBlock::RenderMathMLBlock):
(WebCore::RenderMathMLBlock::computePreferredLogicalWidths):
(WebCore::RenderMathMLBlock::baselinePosition):
(WebCore::RenderMathMLBlock::renderName):
(WebCore::RenderMathMLBlock::paint):
(WebCore::RenderMathMLTable::firstLineBoxBaseline):
* rendering/mathml/RenderMathMLBlock.h:
(RenderMathMLBlock):
(RenderMathMLTable):
(WebCore::RenderMathMLTable::RenderMathMLTable):
    - Change RenderMathMLBlock's base class to RenderFlexibleBox, and its display to FLEX or INLINE_FLEX.
    - Add RenderMathMLTable for its firstLineBoxBaseline() function, like { vertical-align: middle }.

* rendering/mathml/RenderMathMLFenced.cpp:
(WebCore::RenderMathMLFenced::createMathMLOperator):
(WebCore::RenderMathMLFenced::makeFences):
    - Use RenderMathMLRow::addChild as a more robust name for RenderBlock::addChild.
(WebCore::RenderMathMLFenced::addChild):
    - All inline children of a flexbox are treated as blocks automatically.

* rendering/mathml/RenderMathMLFraction.cpp:
(WebCore::RenderMathMLFraction::fixChildStyle):
(WebCore::RenderMathMLFraction::updateFromElement):
    - numalign and denomalign attributes are now handled by mathml.css.
(WebCore::RenderMathMLFraction::addChild):
(WebCore::RenderMathMLFraction::layout):
(WebCore::RenderMathMLFraction::firstLineBoxBaseline):
* rendering/mathml/RenderMathMLFraction.h:
(RenderMathMLFraction):

* rendering/mathml/RenderMathMLOperator.cpp:
(WebCore::RenderMathMLOperator::updateFromElement):
(WebCore::RenderMathMLOperator::createStackableStyle):
(WebCore::RenderMathMLOperator::firstLineBoxBaseline):
* rendering/mathml/RenderMathMLOperator.h:
* rendering/mathml/RenderMathMLRow.cpp:
(WebCore::RenderMathMLRow::createAnonymousWithParentRenderer):

* rendering/mathml/RenderMathMLSubSup.cpp:
(WebCore::RenderMathMLSubSup::RenderMathMLSubSup):
(WebCore::RenderMathMLSubSup::fixScriptsStyle):
(WebCore::RenderMathMLSubSup::addChild):
(WebCore::RenderMathMLSubSup::styleDidChange):
(WebCore::RenderMathMLSubSup::layout):
* rendering/mathml/RenderMathMLSubSup.h:
    - Rename Sup to Super, to make it more readable vs. Sub.
    - Instead of vertical-align, msub and msup now use the m_scripts anonymous box like msubsup does.
    - Individual anonymous block wrappers are no longer needed around the superscript and subscript to
      lay them out in a column.
    - Handle msub and msup layout, and improve msubsup layout, by requiring a superscript's baseline
      to be at least (int) fontSize / 3 + 1 above the main baseline, and a subscript's baseline to be
      at least (int) fontSize / 5 + 1 below it.

* rendering/mathml/RenderMathMLUnderOver.cpp:
(WebCore::RenderMathMLUnderOver::unembellishedOperator):
(WebCore::RenderMathMLUnderOver::firstLineBoxBaseline):
* rendering/mathml/RenderMathMLUnderOver.h:
(RenderMathMLUnderOver):
    - RenderMathMLUnderOver no longer needs to use anonymous wrappers for column layout. Centering and
      child layout order (overscript first) are also handled by mathml.css.

LayoutTests:

* mathml/EmptyMFracCrash-expected.txt:
* mathml/EmptyMunderOverCrash-expected.txt:
* mathml/empty-mroot-crash-expected.txt:
* mathml/fenced-whitespace-separators-crash-expected.txt:
* mathml/msub-anonymous-child-render-crash-expected.txt:
* mathml/msubsup-no-grandchild-expected.txt:
* mathml/msubsup-remove-children-expected.txt:
* mathml/munderover-remove-children-expected.txt:

* mathml/presentation/fenced.xhtml:
* mathml/presentation/mo.xhtml:
* mathml/presentation/row.xhtml:
* mathml/xHeight.xhtml:
    - The <div>s are wrapped in <mtext> elements to make them valid in MathML, with the intended layout.

* platform/mac/mathml/presentation/attributes-expected.png:
* platform/mac/mathml/presentation/attributes-expected.txt:
* platform/mac/mathml/presentation/fenced-expected.txt:
* platform/mac/mathml/presentation/fenced-mi-expected.png:
* platform/mac/mathml/presentation/fenced-mi-expected.txt:
* platform/mac/mathml/presentation/fractions-expected.txt:
* platform/mac/mathml/presentation/fractions-vertical-alignment-expected.txt:
* platform/mac/mathml/presentation/mo-expected.png:
* platform/mac/mathml/presentation/mo-expected.txt:
* platform/mac/mathml/presentation/mo-stretch-expected.png:
* platform/mac/mathml/presentation/mo-stretch-expected.txt:
* platform/mac/mathml/presentation/mroot-pref-width-expected.txt:
* platform/mac/mathml/presentation/over-expected.png:
* platform/mac/mathml/presentation/over-expected.txt:
* platform/mac/mathml/presentation/roots-expected.png:
* platform/mac/mathml/presentation/roots-expected.txt:
* platform/mac/mathml/presentation/row-alignment-expected.png:
* platform/mac/mathml/presentation/row-alignment-expected.txt:
* platform/mac/mathml/presentation/row-expected.png:
* platform/mac/mathml/presentation/row-expected.txt:
* platform/mac/mathml/presentation/style-expected.png:
* platform/mac/mathml/presentation/style-expected.txt:
* platform/mac/mathml/presentation/sub-expected.png:
* platform/mac/mathml/presentation/sub-expected.txt:
* platform/mac/mathml/presentation/subsup-expected.png:
* platform/mac/mathml/presentation/subsup-expected.txt:
* platform/mac/mathml/presentation/sup-expected.txt:
* platform/mac/mathml/presentation/tables-expected.png:
* platform/mac/mathml/presentation/tables-expected.txt:
* platform/mac/mathml/presentation/tokenElements-expected.txt:
* platform/mac/mathml/presentation/under-expected.txt:
* platform/mac/mathml/presentation/underover-expected.png:
* platform/mac/mathml/presentation/underover-expected.txt:
* platform/mac/mathml/xHeight-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@128837 268f45cc-cd09-0410-ab3c-d52691b4dbfc
63 files changed:
LayoutTests/ChangeLog
LayoutTests/mathml/EmptyMFracCrash-expected.txt
LayoutTests/mathml/EmptyMunderOverCrash-expected.txt
LayoutTests/mathml/empty-mroot-crash-expected.txt
LayoutTests/mathml/fenced-whitespace-separators-crash-expected.txt
LayoutTests/mathml/msub-anonymous-child-render-crash-expected.txt
LayoutTests/mathml/msubsup-no-grandchild-expected.txt
LayoutTests/mathml/msubsup-remove-children-expected.txt
LayoutTests/mathml/munderover-remove-children-expected.txt
LayoutTests/mathml/presentation/fenced.xhtml
LayoutTests/mathml/presentation/mo.xhtml
LayoutTests/mathml/presentation/row.xhtml
LayoutTests/mathml/xHeight.xhtml
LayoutTests/platform/mac/mathml/presentation/attributes-expected.png
LayoutTests/platform/mac/mathml/presentation/attributes-expected.txt
LayoutTests/platform/mac/mathml/presentation/fenced-expected.txt
LayoutTests/platform/mac/mathml/presentation/fenced-mi-expected.png
LayoutTests/platform/mac/mathml/presentation/fenced-mi-expected.txt
LayoutTests/platform/mac/mathml/presentation/fractions-expected.txt
LayoutTests/platform/mac/mathml/presentation/fractions-vertical-alignment-expected.txt
LayoutTests/platform/mac/mathml/presentation/mo-expected.png
LayoutTests/platform/mac/mathml/presentation/mo-expected.txt
LayoutTests/platform/mac/mathml/presentation/mo-stretch-expected.png
LayoutTests/platform/mac/mathml/presentation/mo-stretch-expected.txt
LayoutTests/platform/mac/mathml/presentation/mroot-pref-width-expected.txt
LayoutTests/platform/mac/mathml/presentation/over-expected.png
LayoutTests/platform/mac/mathml/presentation/over-expected.txt
LayoutTests/platform/mac/mathml/presentation/roots-expected.png
LayoutTests/platform/mac/mathml/presentation/roots-expected.txt
LayoutTests/platform/mac/mathml/presentation/row-alignment-expected.png
LayoutTests/platform/mac/mathml/presentation/row-alignment-expected.txt
LayoutTests/platform/mac/mathml/presentation/row-expected.png
LayoutTests/platform/mac/mathml/presentation/row-expected.txt
LayoutTests/platform/mac/mathml/presentation/style-expected.png
LayoutTests/platform/mac/mathml/presentation/style-expected.txt
LayoutTests/platform/mac/mathml/presentation/sub-expected.png
LayoutTests/platform/mac/mathml/presentation/sub-expected.txt
LayoutTests/platform/mac/mathml/presentation/subsup-expected.png
LayoutTests/platform/mac/mathml/presentation/subsup-expected.txt
LayoutTests/platform/mac/mathml/presentation/sup-expected.txt
LayoutTests/platform/mac/mathml/presentation/tables-expected.png
LayoutTests/platform/mac/mathml/presentation/tables-expected.txt
LayoutTests/platform/mac/mathml/presentation/tokenElements-expected.txt
LayoutTests/platform/mac/mathml/presentation/under-expected.txt
LayoutTests/platform/mac/mathml/presentation/underover-expected.png
LayoutTests/platform/mac/mathml/presentation/underover-expected.txt
LayoutTests/platform/mac/mathml/xHeight-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/css/mathml.css
Source/WebCore/mathml/MathMLInlineContainerElement.cpp
Source/WebCore/mathml/mathtags.in
Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp
Source/WebCore/rendering/mathml/RenderMathMLBlock.h
Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp
Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp
Source/WebCore/rendering/mathml/RenderMathMLFraction.h
Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp
Source/WebCore/rendering/mathml/RenderMathMLOperator.h
Source/WebCore/rendering/mathml/RenderMathMLRow.cpp
Source/WebCore/rendering/mathml/RenderMathMLSubSup.cpp
Source/WebCore/rendering/mathml/RenderMathMLSubSup.h
Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp
Source/WebCore/rendering/mathml/RenderMathMLUnderOver.h