Changeset 166065 in webkit


Ignore:
Timestamp:
Mar 21, 2014 9:19:36 AM (10 years ago)
Author:
fred.wang@free.fr
Message:

Bug 130345 - Refine childShouldCreateRenderer for MathML elements
https://bugs.webkit.org/show_bug.cgi?id=130345

Reviewed by Chris Fleizach.

Source/WebCore:

This is a follow-up of bug 124128. We add more restrictions on foreign
content of MathML elements.

Tests: mathml/presentation/annotation-children.html

mathml/presentation/foreign-element-in-token.html

  • mathml/MathMLElement.cpp:

(WebCore::MathMLElement::isPresentationMathML): fix line wrapping
(WebCore::MathMLElement::isPhrasingContent):

  • move the function from MathMLSelectElement.cpp
  • add the constraint "is descendant of a map element" for area.

(WebCore::MathMLElement::isFlowContent): new function to test flow content.
(WebCore::MathMLElement::childShouldCreateRenderer):

  • remove annotation since it is now tested in MathMLTextElement
  • refine testing of annotation-xml
  • do not create renderer for text content in MathML. Such content is only allowed inside token elements.
  • mathml/MathMLElement.h: Declare isPhrasingContent and isFlowContent.
  • mathml/MathMLSelectElement.cpp: Add new function to test MathML/SVG/HTML encodings.

(WebCore::MathMLSelectElement::isMathMLEncoding):
(WebCore::MathMLSelectElement::isSVGEncoding):
(WebCore::MathMLSelectElement::isHTMLEncoding):
(WebCore::MathMLSelectElement::getSelectedSemanticsChild): use the new functions.

  • mathml/MathMLSelectElement.h: Declare the new public functions.
  • mathml/MathMLTextElement.cpp: remove the isPhrasingContent function.

(WebCore::MathMLTextElement::childShouldCreateRenderer): Just in case, use the generic StyledElement::childShouldCreateRenderer.

LayoutTests:

We update the references of some tests after the additional
restrictions on MathML children. We replace the foreign-*.html with a
single foreign-element-in-token.html and write more tests to verify the
accepted and reject content.

  • mathml/msub-anonymous-child-render-crash-expected.txt: Update reference now that text is only allowed in some token MathML elements.
  • mathml/presentation/annotation-children-expected.html: Added.
  • mathml/presentation/annotation-children.html: Added.
  • mathml/presentation/foreign-element-in-annotation-xml.html: Added.
  • mathml/presentation/foreign-element-in-annotation-xml-expected.txt: Added.
  • mathml/presentation/foreign-element-in-token-expected.txt: Added.
  • mathml/presentation/foreign-element-in-token.html: Added.
  • mathml/presentation/foreign-mi-expected-mismatch.html: Removed.
  • mathml/presentation/foreign-mi.html: Removed.
  • mathml/presentation/foreign-mn-expected-mismatch.html: Removed.
  • mathml/presentation/foreign-mn.html: Removed.
  • mathml/presentation/foreign-mtext-expected-mismatch.html: Removed.
  • mathml/presentation/foreign-mtext-rejected-expected.html: Removed.
  • mathml/presentation/foreign-mtext-rejected.html: Removed.
  • mathml/presentation/foreign-mtext.html: Removed.
  • mathml/presentation/semantics-2.html: the mtext elements can not be direct child of annotation-xml. wrap them in a math tag.
  • mathml/presentation/semantics-3.html: ditto.
  • mathml/presentation/semantics-4.html: ditto.
Location:
trunk
Files:
6 added
8 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r166064 r166065  
     12014-03-21  Frédéric Wang  <fred.wang@free.fr>
     2
     3        Bug 130345 - Refine childShouldCreateRenderer for MathML elements
     4        https://bugs.webkit.org/show_bug.cgi?id=130345
     5
     6        Reviewed by Chris Fleizach.
     7
     8        We update the references of some tests after the additional
     9        restrictions on MathML children. We replace the foreign-*.html with a
     10        single foreign-element-in-token.html and write more tests to verify the
     11        accepted and reject content.
     12
     13        * mathml/msub-anonymous-child-render-crash-expected.txt: Update reference now that text is only allowed in some token MathML elements.
     14        * mathml/presentation/annotation-children-expected.html: Added.
     15        * mathml/presentation/annotation-children.html: Added.
     16        * mathml/presentation/foreign-element-in-annotation-xml.html: Added.
     17        * mathml/presentation/foreign-element-in-annotation-xml-expected.txt: Added.
     18        * mathml/presentation/foreign-element-in-token-expected.txt: Added.
     19        * mathml/presentation/foreign-element-in-token.html: Added.
     20        * mathml/presentation/foreign-mi-expected-mismatch.html: Removed.
     21        * mathml/presentation/foreign-mi.html: Removed.
     22        * mathml/presentation/foreign-mn-expected-mismatch.html: Removed.
     23        * mathml/presentation/foreign-mn.html: Removed.
     24        * mathml/presentation/foreign-mtext-expected-mismatch.html: Removed.
     25        * mathml/presentation/foreign-mtext-rejected-expected.html: Removed.
     26        * mathml/presentation/foreign-mtext-rejected.html: Removed.
     27        * mathml/presentation/foreign-mtext.html: Removed.
     28        * mathml/presentation/semantics-2.html: the mtext elements can not be direct child of annotation-xml. wrap them in a math tag.
     29        * mathml/presentation/semantics-3.html: ditto.
     30        * mathml/presentation/semantics-4.html: ditto.
     31
    1322014-03-21  Mark Lam  <mark.lam@apple.com>
    233
  • trunk/LayoutTests/mathml/msub-anonymous-child-render-crash-expected.txt

    r128837 r166065  
    22
    33X
    4 3
    54Y
    6 3
    75X
    8 3
    962
    107Y
    11 3
    1282
    139
  • trunk/LayoutTests/mathml/presentation/semantics-2.html

    r161430 r166065  
    33<head>
    44  <title>Semantics</title>
     5  <style type="text/css">
     6    .nospacing {
     7      border: 0 !important;
     8      padding: 0 !important;
     9      margin: 0 !important;
     10    }
     11  </style>
    512</head>
    613
     
    1320  <!-- Presentation MathML: the child is displayed -->
    1421  <p>presentation MathML ; annotation: <math><semantics><mtext>presentation MathML</mtext><annotation>annotation</annotation></semantics></math></p>
    15   <p>presentation MathML ; annotation-xml: <math><semantics><mtext>presentation MathML</mtext><annotation-xml encoding="application/mathml-presentation+xml"><mtext>annotation-xml</mtext></annotation-xml></semantics></math></p>
     22  <p>presentation MathML ; annotation-xml: <math><semantics><mtext>presentation MathML</mtext><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>annotation-xml</mtext></math></annotation-xml></semantics></math></p>
    1623
    1724  <!-- Content MathML: the annotation is displayed -->
    1825  <p>content MathML ; annotation: <math><semantics><csymbol>content MathML</csymbol><annotation>annotation</annotation></semantics></math></p>
    19   <p>content MathML ; annotation-xml: <math><semantics><csymbol>content MathML</csymbol><annotation-xml encoding="application/mathml-presentation+xml"><mtext>annotation-xml</mtext></annotation-xml></semantics></math></p>
     26  <p>content MathML ; annotation-xml: <math><semantics><csymbol>content MathML</csymbol><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>annotation-xml</mtext></math></annotation-xml></semantics></math></p>
    2027
    2128</body>
  • trunk/LayoutTests/mathml/presentation/semantics-3.html

    r161430 r166065  
    33<head>
    44  <title>Semantics</title>
     5  <style type="text/css">
     6    .nospacing {
     7      border: 0 !important;
     8      padding: 0 !important;
     9      margin: 0 !important;
     10    }
     11  </style>
    512</head>
    613
     
    1219   -->
    1320
    14   <p>annotation 1: <math><semantics><csymbol>Content MathML</csymbol><annotation>annotation</annotation><annotation>error</annotation><annotation-xml encoding="application/mathml-presentation+xml"><mtext>error</mtext></annotation-xml></semantics></math></p>
    15   <p>annotation 2: <math><semantics><csymbol>Content MathML</csymbol><annotation encoding="application/x-tex">\sin x + 5</annotation><annotation>error</annotation><annotation-xml encoding="application/mathml-presentation+xml"><mtext>error</mtext></annotation-xml></semantics></math></p>
    16   <p>annotation 3: <math><semantics><csymbol>Content MathML</csymbol><annotation src="external-resource">error</annotation><annotation>annotation</annotation><annotation-xml encoding="application/mathml-presentation+xml"><mtext>error</mtext></annotation-xml></semantics></math></p>
     21  <p>annotation 1: <math><semantics><csymbol>Content MathML</csymbol><annotation>annotation</annotation><annotation>error</annotation><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>error</mtext></math></annotation-xml></semantics></math></p>
     22  <p>annotation 2: <math><semantics><csymbol>Content MathML</csymbol><annotation encoding="application/x-tex">\sin x + 5</annotation><annotation>error</annotation><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>error</mtext></math></annotation-xml></semantics></math></p>
     23  <p>annotation 3: <math><semantics><csymbol>Content MathML</csymbol><annotation src="external-resource">error</annotation><annotation>annotation</annotation><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>error</mtext></math></annotation-xml></semantics></math></p>
    1724
    18   <p>annotation-xml 1: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="application/mathml-presentation+xml"><mtext>application/mathml-presentation+xml</mtext></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><mtext>error</mtext></annotation-xml><annotation>error</annotation></semantics></math></p>
    19   <p>annotation-xml 2: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="MathML-Presentation"><mtext>MathML-Presentation</mtext></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><mtext>error</mtext></annotation-xml><annotation>error</annotation></semantics></math></p>
    20   <p>annotation-xml 3: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="image/svg+xml"><svg width="20px" height="20px"><rect width="20px" height="20px" fill="red" stroke="none"/></svg></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><mtext>error</mtext></annotation-xml><annotation>error</annotation></semantics></math></p>
    21   <p>annotation-xml 4: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="SVG1.1"><svg width="20px" height="20px"><rect width="20px" height="20px" fill="red" stroke="none"/></svg></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><mtext>error</mtext></annotation-xml><annotation>error</annotation></semantics></math></p>
    22   <p>annotation-xml 5: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="application/xhtml+xml"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>application/xhtml+xml</title></head><body><p>application/xhtml+xml</p></body></html></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><mtext>error</mtext></annotation-xml><annotation>error</annotation></math></p>
    23   <p>annotation-xml 6: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><html><head><title>text/html</title></head><body><p>text/html</p></body></html></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><mtext>error</mtext></annotation-xml><annotation>error</annotation></semantics></math></p>
    24   <p>annotation-xml 7: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="unknown"><mtext>error</mtext></annotation-xml><annotation-xml encoding="application/mathml+xml"><mtext>error</mtext></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><mtext>annotation-xml</mtext></annotation-xml><annotation>error</annotation></semantics></math></p>
     25  <p>annotation-xml 1: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>application/mathml-presentation+xml</mtext></math></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>error</mtext></math></annotation-xml><annotation>error</annotation></semantics></math></p>
     26  <p>annotation-xml 2: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="MathML-Presentation"><math class="nospacing"><mtext>MathML-Presentation</mtext></math></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>error</mtext></math></annotation-xml><annotation>error</annotation></semantics></math></p>
     27  <p>annotation-xml 3: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="image/svg+xml"><svg width="20px" height="20px"><rect width="20px" height="20px" fill="red" stroke="none"/></svg></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>error</mtext></math></annotation-xml><annotation>error</annotation></semantics></math></p>
     28  <p>annotation-xml 4: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="SVG1.1"><svg width="20px" height="20px"><rect width="20px" height="20px" fill="red" stroke="none"/></svg></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>error</mtext></math></annotation-xml><annotation>error</annotation></semantics></math></p>
     29  <p>annotation-xml 5: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="application/xhtml+xml"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>application/xhtml+xml</title></head><body><p>application/xhtml+xml</p></body></html></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>error</mtext></math></annotation-xml><annotation>error</annotation></math></p>
     30  <p>annotation-xml 6: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><html><head><title>text/html</title></head><body><p>text/html</p></body></html></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>error</mtext></math></annotation-xml><annotation>error</annotation></semantics></math></p>
     31  <p>annotation-xml 7: <math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="unknown"><math class="nospacing"><mtext>error</mtext></math></annotation-xml><annotation-xml encoding="application/mathml+xml"><math class="nospacing"><mtext>error</mtext></math></annotation-xml><annotation-xml encoding="application/mathml-presentation+xml"><math class="nospacing"><mtext>annotation-xml</mtext></math></annotation-xml><annotation>error</annotation></semantics></math></p>
    2532</body>
    2633</html>
  • trunk/LayoutTests/mathml/presentation/semantics-4.html

    r161430 r166065  
    33<head>
    44  <title>Semantics</title>
     5  <style type="text/css">
     6    .nospacing {
     7      border: 0 !important;
     8      padding: 0 !important;
     9      margin: 0 !important;
     10    }
     11  </style>
    512</head>
    613
     
    916  <!-- This test verifies that setting the encoding dynamically updates the selected annotation. This should render the same as the static reference. -->
    1017
    11   <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml id="a"><mtext>PASS</mtext></annotation-xml><annotation>FAIL</annotation></semantics></math></p>
     18  <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml id="a"><math class="nospacing"><mtext>PASS</mtext></math></annotation-xml><annotation>FAIL</annotation></semantics></math></p>
    1219
    1320</body>
  • trunk/Source/WebCore/ChangeLog

    r166063 r166065  
     12014-03-21  Frédéric Wang  <fred.wang@free.fr>
     2
     3        Bug 130345 - Refine childShouldCreateRenderer for MathML elements
     4        https://bugs.webkit.org/show_bug.cgi?id=130345
     5
     6        Reviewed by Chris Fleizach.
     7
     8        This is a follow-up of bug 124128. We add more restrictions on foreign
     9        content of MathML elements.
     10
     11        Tests: mathml/presentation/annotation-children.html
     12               mathml/presentation/foreign-element-in-token.html
     13
     14        * mathml/MathMLElement.cpp:
     15        (WebCore::MathMLElement::isPresentationMathML): fix line wrapping
     16        (WebCore::MathMLElement::isPhrasingContent):
     17        - move the function from MathMLSelectElement.cpp
     18        - add the constraint "is descendant of a map element" for area.
     19        (WebCore::MathMLElement::isFlowContent): new function to test flow content.
     20        (WebCore::MathMLElement::childShouldCreateRenderer):
     21        - remove annotation since it is now tested in MathMLTextElement
     22        - refine testing of annotation-xml
     23        - do not create renderer for text content in MathML. Such content is only allowed inside token elements.
     24        * mathml/MathMLElement.h: Declare isPhrasingContent and isFlowContent.
     25        * mathml/MathMLSelectElement.cpp: Add new function to test MathML/SVG/HTML encodings.
     26        (WebCore::MathMLSelectElement::isMathMLEncoding):
     27        (WebCore::MathMLSelectElement::isSVGEncoding):
     28        (WebCore::MathMLSelectElement::isHTMLEncoding):
     29        (WebCore::MathMLSelectElement::getSelectedSemanticsChild): use the new functions.
     30        * mathml/MathMLSelectElement.h: Declare the new public functions.
     31        * mathml/MathMLTextElement.cpp: remove the isPhrasingContent function.
     32        (WebCore::MathMLTextElement::childShouldCreateRenderer): Just in case, use the generic StyledElement::childShouldCreateRenderer.
     33
    1342014-03-21  Darin Adler  <darin@apple.com>
    235
  • trunk/Source/WebCore/mathml/MathMLElement.cpp

    r164856 r166065  
    3232#include "MathMLElement.h"
    3333
     34#include "ElementIterator.h"
     35#include "HTMLElement.h"
     36#include "HTMLMapElement.h"
     37#include "HTMLNames.h"
    3438#include "MathMLNames.h"
     39#include "MathMLSelectElement.h"
    3540#include "RenderTableCell.h"
     41#include "SVGElement.h"
     42#include "SVGNames.h"
    3643
    3744namespace WebCore {
     
    5158bool MathMLElement::isPresentationMathML() const
    5259{
    53     return hasTagName(MathMLNames::mtrTag) || hasTagName(MathMLNames::mtdTag) || hasTagName(MathMLNames::maligngroupTag) || hasTagName(MathMLNames::malignmarkTag) || hasTagName(MathMLNames::mencloseTag) || hasTagName(MathMLNames::mglyphTag) || hasTagName(MathMLNames::mlabeledtrTag) || hasTagName(MathMLNames::mlongdivTag) || hasTagName(MathMLNames::mpaddedTag) || hasTagName(MathMLNames::msTag) || hasTagName(MathMLNames::mscarriesTag) || hasTagName(MathMLNames::mscarryTag) || hasTagName(MathMLNames::msgroupTag) || hasTagName(MathMLNames::mslineTag) || hasTagName(MathMLNames::msrowTag) || hasTagName(MathMLNames::mstackTag);
     60    return hasTagName(MathMLNames::mtrTag)
     61        || hasTagName(MathMLNames::mtdTag)
     62        || hasTagName(MathMLNames::maligngroupTag)
     63        || hasTagName(MathMLNames::malignmarkTag)
     64        || hasTagName(MathMLNames::mencloseTag)
     65        || hasTagName(MathMLNames::mglyphTag)
     66        || hasTagName(MathMLNames::mlabeledtrTag)
     67        || hasTagName(MathMLNames::mlongdivTag)
     68        || hasTagName(MathMLNames::mpaddedTag)
     69        || hasTagName(MathMLNames::msTag)
     70        || hasTagName(MathMLNames::mscarriesTag)
     71        || hasTagName(MathMLNames::mscarryTag)
     72        || hasTagName(MathMLNames::msgroupTag)
     73        || hasTagName(MathMLNames::mslineTag)
     74        || hasTagName(MathMLNames::msrowTag)
     75        || hasTagName(MathMLNames::mstackTag);
     76}
     77
     78bool MathMLElement::isPhrasingContent(const Node& node) const
     79{
     80    // Phrasing content is described in the HTML 5 specification:
     81    // http://www.w3.org/TR/html5/dom.html#phrasing-content.
     82
     83    if (!node.isElementNode())
     84        return node.isTextNode();
     85
     86    if (node.isMathMLElement()) {
     87        auto& mathmlElement = toMathMLElement(node);
     88        return mathmlElement.hasTagName(MathMLNames::mathTag);
     89    }
     90
     91    if (node.isSVGElement()) {
     92        auto& svgElement = toSVGElement(node);
     93        return svgElement.hasTagName(SVGNames::svgTag);
     94    }
     95
     96    if (node.isHTMLElement()) {
     97        // FIXME: add the <data> and <time> tags when they are implemented.
     98        auto& htmlElement = toHTMLElement(node);
     99        return htmlElement.hasTagName(HTMLNames::aTag)
     100            || htmlElement.hasTagName(HTMLNames::abbrTag)
     101            || (htmlElement.hasTagName(HTMLNames::areaTag) && ancestorsOfType<HTMLMapElement>(htmlElement).first())
     102            || htmlElement.hasTagName(HTMLNames::audioTag)
     103            || htmlElement.hasTagName(HTMLNames::bTag)
     104            || htmlElement.hasTagName(HTMLNames::bdiTag)
     105            || htmlElement.hasTagName(HTMLNames::bdoTag)
     106            || htmlElement.hasTagName(HTMLNames::brTag)
     107            || htmlElement.hasTagName(HTMLNames::buttonTag)
     108            || htmlElement.hasTagName(HTMLNames::canvasTag)
     109            || htmlElement.hasTagName(HTMLNames::citeTag)
     110            || htmlElement.hasTagName(HTMLNames::codeTag)
     111            || htmlElement.hasTagName(HTMLNames::datalistTag)
     112            || htmlElement.hasTagName(HTMLNames::delTag)
     113            || htmlElement.hasTagName(HTMLNames::dfnTag)
     114            || htmlElement.hasTagName(HTMLNames::emTag)
     115            || htmlElement.hasTagName(HTMLNames::embedTag)
     116            || htmlElement.hasTagName(HTMLNames::iTag)
     117            || htmlElement.hasTagName(HTMLNames::iframeTag)
     118            || htmlElement.hasTagName(HTMLNames::imgTag)
     119            || htmlElement.hasTagName(HTMLNames::inputTag)
     120            || htmlElement.hasTagName(HTMLNames::insTag)
     121            || htmlElement.hasTagName(HTMLNames::kbdTag)
     122            || htmlElement.hasTagName(HTMLNames::keygenTag)
     123            || htmlElement.hasTagName(HTMLNames::labelTag)
     124            || htmlElement.hasTagName(HTMLNames::mapTag)
     125            || htmlElement.hasTagName(HTMLNames::markTag)
     126            || htmlElement.hasTagName(HTMLNames::meterTag)
     127            || htmlElement.hasTagName(HTMLNames::noscriptTag)
     128            || htmlElement.hasTagName(HTMLNames::objectTag)
     129            || htmlElement.hasTagName(HTMLNames::outputTag)
     130            || htmlElement.hasTagName(HTMLNames::progressTag)
     131            || htmlElement.hasTagName(HTMLNames::qTag)
     132            || htmlElement.hasTagName(HTMLNames::rubyTag)
     133            || htmlElement.hasTagName(HTMLNames::sTag)
     134            || htmlElement.hasTagName(HTMLNames::sampTag)
     135            || htmlElement.hasTagName(HTMLNames::scriptTag)
     136            || htmlElement.hasTagName(HTMLNames::selectTag)
     137            || htmlElement.hasTagName(HTMLNames::smallTag)
     138            || htmlElement.hasTagName(HTMLNames::spanTag)
     139            || htmlElement.hasTagName(HTMLNames::strongTag)
     140            || htmlElement.hasTagName(HTMLNames::subTag)
     141            || htmlElement.hasTagName(HTMLNames::supTag)
     142            || htmlElement.hasTagName(HTMLNames::templateTag)
     143            || htmlElement.hasTagName(HTMLNames::textareaTag)
     144            || htmlElement.hasTagName(HTMLNames::uTag)
     145            || htmlElement.hasTagName(HTMLNames::varTag)
     146            || htmlElement.hasTagName(HTMLNames::videoTag)
     147            || htmlElement.hasTagName(HTMLNames::wbrTag);
     148    }
     149
     150    return false;
     151}
     152
     153bool MathMLElement::isFlowContent(const Node& node) const
     154{
     155    // Flow content is described in the HTML 5 specification:
     156    // http://www.w3.org/TR/html5/dom.html#flow-content
     157
     158    if (isPhrasingContent(node))
     159        return true;
     160
     161    if (!node.isHTMLElement())
     162        return false;
     163
     164    auto& htmlElement = toHTMLElement(node);
     165    // FIXME add the <dialog> tag when it is implemented.
     166    return htmlElement.hasTagName(HTMLNames::addressTag)
     167        || htmlElement.hasTagName(HTMLNames::articleTag)
     168        || htmlElement.hasTagName(HTMLNames::asideTag)
     169        || htmlElement.hasTagName(HTMLNames::blockquoteTag)
     170        || htmlElement.hasTagName(HTMLNames::detailsTag)
     171        || htmlElement.hasTagName(HTMLNames::divTag)
     172        || htmlElement.hasTagName(HTMLNames::dlTag)
     173        || htmlElement.hasTagName(HTMLNames::fieldsetTag)
     174        || htmlElement.hasTagName(HTMLNames::figureTag)
     175        || htmlElement.hasTagName(HTMLNames::footerTag)
     176        || htmlElement.hasTagName(HTMLNames::formTag)
     177        || htmlElement.hasTagName(HTMLNames::h1Tag)
     178        || htmlElement.hasTagName(HTMLNames::h2Tag)
     179        || htmlElement.hasTagName(HTMLNames::h3Tag)
     180        || htmlElement.hasTagName(HTMLNames::h4Tag)
     181        || htmlElement.hasTagName(HTMLNames::h5Tag)
     182        || htmlElement.hasTagName(HTMLNames::h6Tag)
     183        || htmlElement.hasTagName(HTMLNames::headerTag)
     184        || htmlElement.hasTagName(HTMLNames::hrTag)
     185        || htmlElement.hasTagName(HTMLNames::mainTag)
     186        || htmlElement.hasTagName(HTMLNames::navTag)
     187        || htmlElement.hasTagName(HTMLNames::olTag)
     188        || htmlElement.hasTagName(HTMLNames::pTag)
     189        || htmlElement.hasTagName(HTMLNames::preTag)
     190        || htmlElement.hasTagName(HTMLNames::sectionTag)
     191        || (htmlElement.hasTagName(HTMLNames::styleTag) && htmlElement.hasAttribute("scoped"))
     192        || htmlElement.hasTagName(HTMLNames::tableTag)
     193        || htmlElement.hasTagName(HTMLNames::ulTag);
    54194}
    55195
     
    124264bool MathMLElement::childShouldCreateRenderer(const Node& child) const
    125265{
    126     if (hasTagName(annotationTag))
    127         return child.isTextNode();
    128     if (hasTagName(annotation_xmlTag))
    129         return StyledElement::childShouldCreateRenderer(child);
    130 
    131     // Only create renderers for MathML elements or text. MathML prohibits non-MathML markup inside a <math> element.
    132     return child.isTextNode() || child.isMathMLElement();
     266    if (hasTagName(annotation_xmlTag)) {
     267        const AtomicString& value = fastGetAttribute(MathMLNames::encodingAttr);
     268
     269        // See annotation-xml.model.mathml, annotation-xml.model.svg and annotation-xml.model.xhtml in the HTML5 RelaxNG schema.
     270
     271        if (child.isMathMLElement() && (MathMLSelectElement::isMathMLEncoding(value) || MathMLSelectElement::isHTMLEncoding(value))) {
     272            auto& mathmlElement = toMathMLElement(child);
     273            return mathmlElement.hasTagName(MathMLNames::mathTag);
     274        }
     275
     276        if (child.isSVGElement() && (MathMLSelectElement::isSVGEncoding(value) || MathMLSelectElement::isHTMLEncoding(value))) {
     277            auto& svgElement = toSVGElement(child);
     278            return svgElement.hasTagName(SVGNames::svgTag);
     279        }
     280
     281        if (child.isHTMLElement() && MathMLSelectElement::isHTMLEncoding(value)) {
     282            auto& htmlElement = toHTMLElement(child);
     283            return htmlElement.hasTagName(HTMLNames::htmlTag) || (isFlowContent(htmlElement) && StyledElement::childShouldCreateRenderer(child));
     284        }
     285
     286        return false;
     287    }
     288
     289    // In general, only MathML children are allowed. Text nodes are only visible in token MathML elements.
     290    return child.isMathMLElement();
    133291}
    134292
  • trunk/Source/WebCore/mathml/MathMLElement.h

    r165699 r166065  
    6767    virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override;
    6868
     69    bool isPhrasingContent(const Node&) const;
     70    bool isFlowContent(const Node&) const;
     71
    6972private:
    7073    virtual void updateSelectedChild() { }
  • trunk/Source/WebCore/mathml/MathMLSelectElement.cpp

    r165699 r166065  
    3030
    3131#include "Event.h"
     32#include "HTMLElement.h"
     33#include "HTMLNames.h"
    3234#include "MathMLNames.h"
    3335#include "RenderMathMLRow.h"
     36#include "SVGElement.h"
     37#include "SVGNames.h"
    3438
    3539namespace WebCore {
     
    5155{
    5256    return createRenderer<RenderMathMLRow>(*this, std::move(style));
     57}
     58
     59//  We recognize the following values for the encoding attribute of the <semantics> element:
     60//
     61// - "MathML-Presentation", which is mentioned in the MathML 3 recommendation.
     62// - "SVG1.1" which is mentioned in the W3C note.
     63//   http://www.w3.org/Math/Documents/Notes/graphics.xml
     64// - Other MIME Content-Types for MathML, SVG and HTML.
     65//
     66// We exclude "application/mathml+xml" which is ambiguous about whether it is Presentation or Content MathML. Authors must use a more explicit encoding value.
     67bool MathMLSelectElement::isMathMLEncoding(const AtomicString& value)
     68{
     69    return value == "application/mathml-presentation+xml" || value == "MathML-Presentation";
     70}
     71
     72bool MathMLSelectElement::isSVGEncoding(const AtomicString& value)
     73{
     74    return value == "image/svg+xml" || value == "SVG1.1";
     75}
     76
     77bool MathMLSelectElement::isHTMLEncoding(const AtomicString& value)
     78{
     79    return value == "application/xhtml+xml" || value == "text/html";
    5380}
    5481
     
    156183            if (child->hasAttribute(MathMLNames::srcAttr))
    157184                continue;
    158             // If the <annotation-xml> element has an encoding attribute describing presentation MathML, SVG or HTML we assume the content can be displayed and we stop here. We recognize the following encoding values:
    159             //
    160             // - "MathML-Presentation", which is mentioned in the MathML 3 recommendation.
    161             // - "SVG1.1" which is mentioned in the W3C note.
    162             //   http://www.w3.org/Math/Documents/Notes/graphics.xml
    163             // - Other MIME Content-Types for SVG and HTML.
    164             //
    165             // We exclude "application/mathml+xml" which is ambiguous about whether it is Presentation or Content MathML. Authors must use a more explicit encoding value.
     185            // If the <annotation-xml> element has an encoding attribute describing presentation MathML, SVG or HTML we assume the content can be displayed and we stop here.
    166186            const AtomicString& value = child->fastGetAttribute(MathMLNames::encodingAttr);
    167             if (value == "application/mathml-presentation+xml" || value == "MathML-Presentation" || value == "image/svg+xml" || value == "SVG1.1" || value == "application/xhtml+xml" || value == "text/html")
     187            if (isMathMLEncoding(value) || isSVGEncoding(value) || isHTMLEncoding(value))
    168188                return child;
    169189        }
  • trunk/Source/WebCore/mathml/MathMLSelectElement.h

    r164856 r166065  
    3535public:
    3636    static PassRefPtr<MathMLSelectElement> create(const QualifiedName& tagName, Document&);
     37    static bool isMathMLEncoding(const AtomicString& value);
     38    static bool isSVGEncoding(const AtomicString& value);
     39    static bool isHTMLEncoding(const AtomicString& value);
    3740
    3841private:
  • trunk/Source/WebCore/mathml/MathMLTextElement.cpp

    r165739 r166065  
    3131#include "MathMLTextElement.h"
    3232
    33 #include "HTMLElement.h"
    34 #include "HTMLNames.h"
    3533#include "MathMLNames.h"
    3634#include "RenderMathMLOperator.h"
    3735#include "RenderMathMLSpace.h"
    3836#include "RenderMathMLToken.h"
    39 #include "SVGElement.h"
    40 #include "SVGNames.h"
    4137
    4238namespace WebCore {
     
    8379}
    8480
    85 static bool isPhrasingContent(const Node& node)
    86 {
    87     // Phrasing content is described in the HTML 5 specification:
    88     // http://www.w3.org/TR/html5/dom.html#phrasing-content.
    89 
    90     if (!node.isElementNode())
    91         return node.isTextNode();
    92 
    93     auto& element = toElement(node);
    94 
    95     if (element.isMathMLElement()) {
    96         auto& mathmlElement = toMathMLElement(element);
    97         return mathmlElement.hasTagName(MathMLNames::mathTag);
    98     }
    99 
    100     if (element.isSVGElement()) {
    101         auto& svgElement = toSVGElement(element);
    102         return svgElement.hasTagName(SVGNames::svgTag);
    103     }
    104 
    105     if (element.isHTMLElement()) {
    106         // FIXME: add the <data> and <time> tags when they are implemented.
    107         auto& htmlElement = toHTMLElement(element);
    108         return htmlElement.hasTagName(HTMLNames::aTag)
    109             || htmlElement.hasTagName(HTMLNames::abbrTag)
    110             || htmlElement.hasTagName(HTMLNames::areaTag)
    111             || htmlElement.hasTagName(HTMLNames::audioTag)
    112             || htmlElement.hasTagName(HTMLNames::bTag)
    113             || htmlElement.hasTagName(HTMLNames::bdiTag)
    114             || htmlElement.hasTagName(HTMLNames::bdoTag)
    115             || htmlElement.hasTagName(HTMLNames::brTag)
    116             || htmlElement.hasTagName(HTMLNames::buttonTag)
    117             || htmlElement.hasTagName(HTMLNames::canvasTag)
    118             || htmlElement.hasTagName(HTMLNames::citeTag)
    119             || htmlElement.hasTagName(HTMLNames::codeTag)
    120             || htmlElement.hasTagName(HTMLNames::datalistTag)
    121             || htmlElement.hasTagName(HTMLNames::delTag)
    122             || htmlElement.hasTagName(HTMLNames::dfnTag)
    123             || htmlElement.hasTagName(HTMLNames::emTag)
    124             || htmlElement.hasTagName(HTMLNames::embedTag)
    125             || htmlElement.hasTagName(HTMLNames::iTag)
    126             || htmlElement.hasTagName(HTMLNames::iframeTag)
    127             || htmlElement.hasTagName(HTMLNames::imgTag)
    128             || htmlElement.hasTagName(HTMLNames::inputTag)
    129             || htmlElement.hasTagName(HTMLNames::insTag)
    130             || htmlElement.hasTagName(HTMLNames::kbdTag)
    131             || htmlElement.hasTagName(HTMLNames::keygenTag)
    132             || htmlElement.hasTagName(HTMLNames::labelTag)
    133             || htmlElement.hasTagName(HTMLNames::mapTag)
    134             || htmlElement.hasTagName(HTMLNames::markTag)
    135             || htmlElement.hasTagName(HTMLNames::meterTag)
    136             || htmlElement.hasTagName(HTMLNames::noscriptTag)
    137             || htmlElement.hasTagName(HTMLNames::objectTag)
    138             || htmlElement.hasTagName(HTMLNames::outputTag)
    139             || htmlElement.hasTagName(HTMLNames::progressTag)
    140             || htmlElement.hasTagName(HTMLNames::qTag)
    141             || htmlElement.hasTagName(HTMLNames::rubyTag)
    142             || htmlElement.hasTagName(HTMLNames::sTag)
    143             || htmlElement.hasTagName(HTMLNames::sampTag)
    144             || htmlElement.hasTagName(HTMLNames::scriptTag)
    145             || htmlElement.hasTagName(HTMLNames::selectTag)
    146             || htmlElement.hasTagName(HTMLNames::smallTag)
    147             || htmlElement.hasTagName(HTMLNames::spanTag)
    148             || htmlElement.hasTagName(HTMLNames::strongTag)
    149             || htmlElement.hasTagName(HTMLNames::subTag)
    150             || htmlElement.hasTagName(HTMLNames::supTag)
    151             || htmlElement.hasTagName(HTMLNames::templateTag)
    152             || htmlElement.hasTagName(HTMLNames::textareaTag)
    153             || htmlElement.hasTagName(HTMLNames::uTag)
    154             || htmlElement.hasTagName(HTMLNames::varTag)
    155             || htmlElement.hasTagName(HTMLNames::videoTag)
    156             || htmlElement.hasTagName(HTMLNames::wbrTag);
    157     }
    158 
    159     return false;
    160 }
    161 
    16281bool MathMLTextElement::childShouldCreateRenderer(const Node& child) const
    16382{
     
    17089
    17190    // The HTML specification defines <mi>, <mo>, <mn>, <ms> and <mtext> as insertion points.
    172     return isPhrasingContent(child);
     91    return isPhrasingContent(child) && StyledElement::childShouldCreateRenderer(child);
    17392}
    17493
Note: See TracChangeset for help on using the changeset viewer.