Bug 130345 - Refine childShouldCreateRenderer for MathML elements
authorfred.wang@free.fr <fred.wang@free.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Mar 2014 16:19:36 +0000 (16:19 +0000)
committerfred.wang@free.fr <fred.wang@free.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Mar 2014 16:19:36 +0000 (16:19 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166065 268f45cc-cd09-0410-ab3c-d52691b4dbfc

25 files changed:
LayoutTests/ChangeLog
LayoutTests/mathml/msub-anonymous-child-render-crash-expected.txt
LayoutTests/mathml/presentation/annotation-children-expected.html [new file with mode: 0644]
LayoutTests/mathml/presentation/annotation-children.html [new file with mode: 0644]
LayoutTests/mathml/presentation/foreign-element-in-annotation-xml-expected.txt [new file with mode: 0644]
LayoutTests/mathml/presentation/foreign-element-in-annotation-xml.html [new file with mode: 0644]
LayoutTests/mathml/presentation/foreign-element-in-token-expected.txt [new file with mode: 0644]
LayoutTests/mathml/presentation/foreign-element-in-token.html [new file with mode: 0644]
LayoutTests/mathml/presentation/foreign-mi-expected-mismatch.html [deleted file]
LayoutTests/mathml/presentation/foreign-mi.html [deleted file]
LayoutTests/mathml/presentation/foreign-mn-expected-mismatch.html [deleted file]
LayoutTests/mathml/presentation/foreign-mn.html [deleted file]
LayoutTests/mathml/presentation/foreign-mtext-expected-mismatch.html [deleted file]
LayoutTests/mathml/presentation/foreign-mtext-rejected-expected.html [deleted file]
LayoutTests/mathml/presentation/foreign-mtext-rejected.html [deleted file]
LayoutTests/mathml/presentation/foreign-mtext.html [deleted file]
LayoutTests/mathml/presentation/semantics-2.html
LayoutTests/mathml/presentation/semantics-3.html
LayoutTests/mathml/presentation/semantics-4.html
Source/WebCore/ChangeLog
Source/WebCore/mathml/MathMLElement.cpp
Source/WebCore/mathml/MathMLElement.h
Source/WebCore/mathml/MathMLSelectElement.cpp
Source/WebCore/mathml/MathMLSelectElement.h
Source/WebCore/mathml/MathMLTextElement.cpp

index 3e8ee09..4247d64 100644 (file)
@@ -1,3 +1,34 @@
+2014-03-21  Frédéric Wang  <fred.wang@free.fr>
+
+        Bug 130345 - Refine childShouldCreateRenderer for MathML elements
+        https://bugs.webkit.org/show_bug.cgi?id=130345
+
+        Reviewed by Chris Fleizach.
+
+        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.
+
 2014-03-21  Mark Lam  <mark.lam@apple.com>
 
         StackLayoutPhase should find the union'ed calleeVariable before accessing its machineLocal.
diff --git a/LayoutTests/mathml/presentation/annotation-children-expected.html b/LayoutTests/mathml/presentation/annotation-children-expected.html
new file mode 100644 (file)
index 0000000..644f3c7
--- /dev/null
@@ -0,0 +1,12 @@
+<!doctype html>
+<html>
+  <head>
+    <title>annotation children</title>
+    <meta charset="utf-8"/>
+  </head>
+  <body>
+
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation>PASS</annotation></semantics></math></p>
+
+  </body>
+</html>
diff --git a/LayoutTests/mathml/presentation/annotation-children.html b/LayoutTests/mathml/presentation/annotation-children.html
new file mode 100644 (file)
index 0000000..291b12d
--- /dev/null
@@ -0,0 +1,14 @@
+<!doctype html>
+<html>
+  <head>
+    <title>annotation children</title>
+    <meta charset="utf-8"/>
+  </head>
+  <body>
+
+    <!-- This verifies that the annotation element can only contain text content -->
+
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation>PA<mtext>ERROR</mtext>SS</annotation></semantics></math></p>
+
+  </body>
+</html>
diff --git a/LayoutTests/mathml/presentation/foreign-element-in-annotation-xml-expected.txt b/LayoutTests/mathml/presentation/foreign-element-in-annotation-xml-expected.txt
new file mode 100644 (file)
index 0000000..85da463
--- /dev/null
@@ -0,0 +1,43 @@
+x
+y
+
+x
+y
+
+x
+y
+
+span
+
+svg
+
+mathml
+
+div
+
+h1
+
+
+h2
+
+
+h3
+
+
+h4
+
+
+h5
+
+
+h6
+
+
+blockquote
+
+
+svg
+
+mathml
+
+
diff --git a/LayoutTests/mathml/presentation/foreign-element-in-annotation-xml.html b/LayoutTests/mathml/presentation/foreign-element-in-annotation-xml.html
new file mode 100644 (file)
index 0000000..32d5092
--- /dev/null
@@ -0,0 +1,38 @@
+<!doctype html>
+<html>
+  <head>
+    <title>Foreign content in semantics</title>
+    <script type="text/javascript">
+      if (window.testRunner)
+        testRunner.dumpAsText();
+    </script>
+  </head>
+  <body>
+  
+    <!-- Text is generally not accepted inside MathML elements. -->
+    <p><math>ERROR</math></p>
+    <p><math><mfrac><mi>x</mi>ERROR<mi>y</mi></mfrac></math></p>
+    <p><math><munder><mi>x</mi>ERROR<mi>y</mi></munder></math></p>
+    <p><math><msup><mi>x</mi>ERROR<mi>y</mi></msup></math></p>
+
+    <!-- annotation-xml with HTML encoding accepts flow content. -->
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><span>span</span></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><svg><text>svg</text></svg></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><math><mtext>mathml</mtext></math></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><div>div</div></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><h1>h1</h1></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><h2>h2</h2></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><h3>h3</h3></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><h4>h4</h4></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><h5>h5</h5></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><h6>h6</h6></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="text/html"><blockquote>blockquote</blockquote></annotation-xml></semantics></math></p>
+
+    <!-- annotation-xml with SVG/MathML encoding only accepts the specified type. -->
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="image/svg+xml"><math><mtext>ERROR</mtext></math></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="image/svg+xml"><svg><text>svg</text></svg></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="application/mathml-presentation+xml"><math><mtext>mathml</mtext></math></annotation-xml></semantics></math></p>
+    <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml encoding="application/mathml-presentation+xml"><svg><text>ERROR</text></svg></annotation-xml></semantics></math></p>
+
+  </body>
+</html>
diff --git a/LayoutTests/mathml/presentation/foreign-element-in-token-expected.txt b/LayoutTests/mathml/presentation/foreign-element-in-token-expected.txt
new file mode 100644 (file)
index 0000000..f0e571c
--- /dev/null
@@ -0,0 +1,344 @@
+Foreign phrasing content should create renderers:
+
+a: 
+mi
+
+abbr: 
+mi
+
+b: 
+mi
+
+bdi: 
+mi
+
+bdo: 
+mi
+
+button: 
+mi
+
+cite: 
+mi
+
+code: 
+mi
+
+datalist: 
+mi
+
+del: 
+mi
+
+dfn: 
+mi
+
+em: 
+mi
+
+embed: 
+mi
+
+i: 
+mi
+
+img: 
+mi
+
+input: 
+mi
+
+ins: 
+mi
+
+kbd: 
+mi
+
+keygen: 
+mi
+
+label: 
+mi
+
+mark: 
+mi
+
+math: 
+mi
+
+object: 
+mi
+
+output: 
+mi
+
+q: 
+mi
+
+ruby: 
+mi
+
+s: 
+mi
+
+samp: 
+mi
+
+small: 
+mi
+
+span: 
+mi
+
+strong: 
+mi
+
+sub: 
+mi
+
+sup: 
+mi
+
+svg: 
+mi
+
+u: 
+mi
+
+var: 
+mi
+
+a: 
+mn
+
+abbr: 
+mn
+
+b: 
+mn
+
+bdi: 
+mn
+
+bdo: 
+mn
+
+button: 
+mn
+
+cite: 
+mn
+
+code: 
+mn
+
+datalist: 
+mn
+
+del: 
+mn
+
+dfn: 
+mn
+
+em: 
+mn
+
+embed: 
+mn
+
+i: 
+mn
+
+img: 
+mn
+
+input: 
+mn
+
+ins: 
+mn
+
+kbd: 
+mn
+
+keygen: 
+mn
+
+label: 
+mn
+
+mark: 
+mn
+
+math: 
+mn
+
+object: 
+mn
+
+output: 
+mn
+
+q: 
+mn
+
+ruby: 
+mn
+
+s: 
+mn
+
+samp: 
+mn
+
+small: 
+mn
+
+span: 
+mn
+
+strong: 
+mn
+
+sub: 
+mn
+
+sup: 
+mn
+
+svg: 
+mn
+
+u: 
+mn
+
+var: 
+mn
+
+a: 
+mtext
+
+abbr: 
+mtext
+
+b: 
+mtext
+
+bdi: 
+mtext
+
+bdo: 
+mtext
+
+button: 
+mtext
+
+cite: 
+mtext
+
+code: 
+mtext
+
+datalist: 
+mtext
+
+del: 
+mtext
+
+dfn: 
+mtext
+
+em: 
+mtext
+
+embed: 
+mtext
+
+i: 
+mtext
+
+img: 
+mtext
+
+input: 
+mtext
+
+ins: 
+mtext
+
+kbd: 
+mtext
+
+keygen: 
+mtext
+
+label: 
+mtext
+
+mark: 
+mtext
+
+math: 
+mtext
+
+object: 
+mtext
+
+output: 
+mtext
+
+q: 
+mtext
+
+ruby: 
+mtext
+
+s: 
+mtext
+
+samp: 
+mtext
+
+small: 
+mtext
+
+span: 
+mtext
+
+strong: 
+mtext
+
+sub: 
+mtext
+
+sup: 
+mtext
+
+svg: 
+mtext
+
+u: 
+mtext
+
+var: 
+mtext
+
+Foreign non-phrasing content should not create renderers:
+
+p: 
+
+div: 
+
+h1: 
+
+h2: 
+
+h3: 
+
+h4: 
+
+h6: 
+
+blockquote: 
+
diff --git a/LayoutTests/mathml/presentation/foreign-element-in-token.html b/LayoutTests/mathml/presentation/foreign-element-in-token.html
new file mode 100644 (file)
index 0000000..2ab594e
--- /dev/null
@@ -0,0 +1,141 @@
+<!doctype html>
+<html>
+  <head>
+    <title>Foreign content</title>
+    <script type="text/javascript">
+      if (window.testRunner)
+        testRunner.dumpAsText();
+    </script>
+  </head>
+  <body>
+  
+    <p>Foreign phrasing content should create renderers:</p>
+
+    <!-- The following elements are not covered by this test: wbr, audio, data,
+         time, canvas, iframe, map, video, textarea, meter, noscript, progress,
+         script, select, template, br, area. -->
+
+    <p>a: <math><mi><a>mi</a></mi></math></p>
+    <p>abbr: <math><mi><abbr>mi</abbr></mi></math></p>
+    <p>b: <math><mi><b>mi</b></mi></math></p>
+    <p>bdi: <math><mi><bdi>mi</bdi></mi></math></p>
+    <p>bdo: <math><mi><bdo>mi</bdo></mi></math></p>
+    <p>button: <math><mi><button>mi</button></mi></math></p>
+    <p>cite: <math><mi><cite>mi</cite></mi></math></p>
+    <p>code: <math><mi><code>mi</code></mi></math></p>
+    <p>datalist: <math><mi><datalist>mi</datalist></mi></math></p>
+    <p>del: <math><mi><del>mi</del></mi></math></p>
+    <p>dfn: <math><mi><dfn>mi</dfn></mi></math></p>
+    <p>em: <math><mi><em>mi</em></mi></math></p>
+    <p>embed: <math><mi><embed>mi</embed></mi></math></p>
+    <p>i: <math><mi><i>mi</i></mi></math></p>
+    <p>img: <math><mi><img>mi</img></mi></math></p>
+    <p>input: <math><mi><input>mi</input></mi></math></p>
+    <p>ins: <math><mi><ins>mi</ins></mi></math></p>
+    <p>kbd: <math><mi><kbd>mi</kbd></mi></math></p>
+    <p>keygen: <math><mi><keygen>mi</keygen></mi></math></p>
+    <p>label: <math><mi><label>mi</label></mi></math></p>
+    <p>mark: <math><mi><mark>mi</mark></mi></math></p>
+    <p>math: <math><mi><math><mtext>mi</mtext></math></mi></math></p>
+    <p>object: <math><mi><object>mi</object></mi></math></p>
+    <p>output: <math><mi><output>mi</output></mi></math></p>
+    <p>q: <math><mi><q>mi</q></mi></math></p>
+    <p>ruby: <math><mi><ruby>mi</ruby></mi></math></p>
+    <p>s: <math><mi><s>mi</s></mi></math></p>
+    <p>samp: <math><mi><samp>mi</samp></mi></math></p>
+    <p>small: <math><mi><small>mi</small></mi></math></p>
+    <p>span: <math><mi><span>mi</span></mi></math></p>
+    <p>strong: <math><mi><strong>mi</strong></mi></math></p>
+    <p>sub: <math><mi><sub>mi</sub></mi></math></p>
+    <p>sup: <math><mi><sup>mi</sup></mi></math></p>
+    <p>svg: <math><mi><svg><text>mi</text></svg></mi></math></p>
+    <p>u: <math><mi><u>mi</u></mi></math></p>
+    <p>var: <math><mi><var>mi</var></mi></math></p>
+
+    <p>a: <math><mn><a>mn</a></mn></math></p>
+    <p>abbr: <math><mn><abbr>mn</abbr></mn></mth></p>
+    <p>b: <math><mn><b>mn</b></mn></math></p>
+    <p>bdi: <math><mn><bdi>mn</bdi></mn></math></p>
+    <p>bdo: <math><mn><bdo>mn</bdo></mn></math></p>
+    <p>button: <math><mn><button>mn</button></mn></math></p>
+    <p>cite: <math><mn><cite>mn</cite></mn></math></p>
+    <p>code: <math><mn><code>mn</code></mn></math></p>
+    <p>datalist: <math><mn><datalist>mn</datalist></mn></math></p>
+    <p>del: <math><mn><del>mn</del></mn></math></p>
+    <p>dfn: <math><mn><dfn>mn</dfn></mn></math></p>
+    <p>em: <math><mn><em>mn</em></mn></math></p>
+    <p>embed: <math><mn><embed>mn</embed></mn></math></p>
+    <p>i: <math><mn><i>mn</i></mn></math></p>
+    <p>img: <math><mn><img>mn</img></mn></math></p>
+    <p>input: <math><mn><input>mn</input></mn></math></p>
+    <p>ins: <math><mn><ins>mn</ins></mn></math></p>
+    <p>kbd: <math><mn><kbd>mn</kbd></mn></math></p>
+    <p>keygen: <math><mn><keygen>mn</keygen></mn></math></p>
+    <p>label: <math><mn><label>mn</label></mn></math></p>
+    <p>mark: <math><mn><mark>mn</mark></mn></math></p>
+    <p>math: <math><mn><math><mtext>mn</mtext></math></mn></math></p>
+    <p>object: <math><mn><object>mn</object></mn></math></p>
+    <p>output: <math><mn><output>mn</output></mn></math></p>
+    <p>q: <math><mn><q>mn</q></mn></math></p>
+    <p>ruby: <math><mn><ruby>mn</ruby></mn></math></p>
+    <p>s: <math><mn><s>mn</s></mn></math></p>
+    <p>samp: <math><mn><samp>mn</samp></mn></math></p>
+    <p>small: <math><mn><small>mn</small></mn></math></p>
+    <p>span: <math><mn><span>mn</span></mn></math></p>
+    <p>strong: <math><mn><strong>mn</strong></mn></math></p>
+    <p>sub: <math><mn><sub>mn</sub></mn></math></p>
+    <p>sup: <math><mn><sup>mn</sup></mn></math></p>
+    <p>svg: <math><mn><svg><text>mn</text></svg></mn></math></p>
+    <p>u: <math><mn><u>mn</u></mn></math></p>
+    <p>var: <math><mn><var>mn</var></mn></math></p>
+
+    <p>a: <math><mtext><a>mtext</a></mtext></math></p>
+    <p>abbr: <math><mtext><abbr>mtext</abbr></mtext></mth></p>
+    <p>b: <math><mtext><b>mtext</b></mtext></math></p>
+    <p>bdi: <math><mtext><bdi>mtext</bdi></mtext></math></p>
+    <p>bdo: <math><mtext><bdo>mtext</bdo></mtext></math></p>
+    <p>button: <math><mtext><button>mtext</button></mtext></math></p>
+    <p>cite: <math><mtext><cite>mtext</cite></mtext></math></p>
+    <p>code: <math><mtext><code>mtext</code></mtext></math></p>
+    <p>datalist: <math><mtext><datalist>mtext</datalist></mtext></math></p>
+    <p>del: <math><mtext><del>mtext</del></mtext></math></p>
+    <p>dfn: <math><mtext><dfn>mtext</dfn></mtext></math></p>
+    <p>em: <math><mtext><em>mtext</em></mtext></math></p>
+    <p>embed: <math><mtext><embed>mtext</embed></mtext></math></p>
+    <p>i: <math><mtext><i>mtext</i></mtext></math></p>
+    <p>img: <math><mtext><img>mtext</img></mtext></math></p>
+    <p>input: <math><mtext><input>mtext</input></mtext></math></p>
+    <p>ins: <math><mtext><ins>mtext</ins></mtext></math></p>
+    <p>kbd: <math><mtext><kbd>mtext</kbd></mtext></math></p>
+    <p>keygen: <math><mtext><keygen>mtext</keygen></mtext></math></p>
+    <p>label: <math><mtext><label>mtext</label></mtext></math></p>
+    <p>mark: <math><mtext><mark>mtext</mark></mtext></math></p>
+    <p>math: <math><mtext><math><mtext>mtext</mtext></math></mtext></math></p>
+    <p>object: <math><mtext><object>mtext</object></mtext></math></p>
+    <p>output: <math><mtext><output>mtext</output></mtext></math></p>
+    <p>q: <math><mtext><q>mtext</q></mtext></math></p>
+    <p>ruby: <math><mtext><ruby>mtext</ruby></mtext></math></p>
+    <p>s: <math><mtext><s>mtext</s></mtext></math></p>
+    <p>samp: <math><mtext><samp>mtext</samp></mtext></math></p>
+    <p>small: <math><mtext><small>mtext</small></mtext></math></p>
+    <p>span: <math><mtext><span>mtext</span></mtext></math></p>
+    <p>strong: <math><mtext><strong>mtext</strong></mtext></math></p>
+    <p>sub: <math><mtext><sub>mtext</sub></mtext></math></p>
+    <p>sup: <math><mtext><sup>mtext</sup></mtext></math></p>
+    <p>svg: <math><mtext><svg><text>mtext</text></svg></mtext></math></p>
+    <p>u: <math><mtext><u>mtext</u></mtext></math></p>
+    <p>var: <math><mtext><var>mtext</var></mtext></math></p>
+
+    <p>Foreign non-phrasing content should not create renderers:</p>
+
+    <p>p: <math><mi><p>mi</p></mi><mtext><p>mi</p></mtext><mn><p>mn</p></mn></math></p>
+    <p>div: <math><mi><div>mi</div></mi><mtext><div>mi</div></mtext><mn><div>mn</div></mn></math></p>
+    <p>h1: <math><mi><h1>mi</h1></mi><mtext><h1>mi</h1></mtext><mn><h1>mn</h1></mn></math></p>
+    <p>h2: <math><mi><h2>mi</h2></mi><mtext><h2>mi</h2></mtext><mn><h2>mn</h2></mn></math></p>
+    <p>h3: <math><mi><h3>mi</h3></mi><mtext><h3>mi</h3></mtext><mn><h3>mn</h3></mn></math></p>
+    <p>h4: <math><mi><h4>mi</h4></mi><mtext><h4>mi</h4></mtext><mn><h4>mn</h4></mn></math></p>
+    <p>h6: <math><mi><h6>mi</h6></mi><mtext><h6>mi</h6></mtext><mn><h6>mn</h6></mn></math></p>
+    <p>blockquote: <math><mi><blockquote>mi</blockquote></mi><mtext><blockquote>mi</blockquote></mtext><mn><blockquote>mn</blockquote></mn></math></p>
+
+  </body>
+</html>
diff --git a/LayoutTests/mathml/presentation/foreign-mi-expected-mismatch.html b/LayoutTests/mathml/presentation/foreign-mi-expected-mismatch.html
deleted file mode 100644 (file)
index 62c24cb..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<!doctype html>
-<html>
-  <head>
-    <title>Foreign content in mi</title>
-  </head>
-  <body>
-
-    <math><mi></mi></math>
-
-  </body>
-</html>
diff --git a/LayoutTests/mathml/presentation/foreign-mi.html b/LayoutTests/mathml/presentation/foreign-mi.html
deleted file mode 100644 (file)
index 6672322..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<!doctype html>
-<html>
-  <head>
-    <title>Foreign content in mi</title>
-  </head>
-  <body>
-
-    <!-- The HTML-in-MathML span should be visible. -->
-
-    <math><mi><span>HTML-in-MathML</span></mi></math>
-
-  </body>
-</html>
diff --git a/LayoutTests/mathml/presentation/foreign-mn-expected-mismatch.html b/LayoutTests/mathml/presentation/foreign-mn-expected-mismatch.html
deleted file mode 100644 (file)
index d63c66f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<!doctype html>
-<html>
-  <head>
-    <title>Foreign content in mn</title>
-  </head>
-  <body>
-
-    <math><mn></mn></math>
-
-  </body>
-</html>
diff --git a/LayoutTests/mathml/presentation/foreign-mn.html b/LayoutTests/mathml/presentation/foreign-mn.html
deleted file mode 100644 (file)
index 425d358..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<!doctype html>
-<html>
-  <head>
-    <title>Foreign content in mn</title>
-  </head>
-  <body>
-
-    <!-- The HTML-in-MathML span should be visible. -->
-
-    <math><mn><span>HTML-in-MathML</span></mn></math>
-
-  </body>
-</html>
diff --git a/LayoutTests/mathml/presentation/foreign-mtext-expected-mismatch.html b/LayoutTests/mathml/presentation/foreign-mtext-expected-mismatch.html
deleted file mode 100644 (file)
index 6f1cd86..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<!doctype html>
-<html>
-  <head>
-    <title>Foreign content in mtext</title>
-  </head>
-  <body>
-
-    <math><mtext></mtext></math>
-
-  </body>
-</html>
diff --git a/LayoutTests/mathml/presentation/foreign-mtext-rejected-expected.html b/LayoutTests/mathml/presentation/foreign-mtext-rejected-expected.html
deleted file mode 100644 (file)
index 880a449..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<!doctype html>
-<html>
-  <head>
-    <title>Foreign content in mtext</title>
-  </head>
-  <body>
-
-    _<math><mtext></mtext></math>_
-
-    _<math><mtext></mtext></math>_
-
-    _<math><mtext></mtext></math>_
-
-  </body>
-</html>
diff --git a/LayoutTests/mathml/presentation/foreign-mtext-rejected.html b/LayoutTests/mathml/presentation/foreign-mtext-rejected.html
deleted file mode 100644 (file)
index c9bde96..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<!doctype html>
-<html>
-  <head>
-    <title>Foreign content in mtext</title>
-  </head>
-  <body>
-
-    <!-- These HTML-in-MathML elements are not phrasing content and should be rejected. -->
-
-    _<math><mtext><p>HTML-in-MathML</p></mtext></math>_
-
-    _<math><mtext><div>HTML-in-MathML</div></mtext></math>_
-
-    _<math><mtext><blockquote>HTML-in-MathML</blockquote></mtext></math>_
-
-  </body>
-</html>
diff --git a/LayoutTests/mathml/presentation/foreign-mtext.html b/LayoutTests/mathml/presentation/foreign-mtext.html
deleted file mode 100644 (file)
index a2acd65..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<!doctype html>
-<html>
-  <head>
-    <title>Foreign content in mtext</title>
-  </head>
-  <body>
-
-    <!-- The HTML-in-MathML span should be visible. -->
-
-    <math><mtext><span>HTML-in-MathML</span></mtext></math>
-
-  </body>
-</html>
index 23fe423..eba6f3f 100644 (file)
@@ -2,6 +2,13 @@
 <html>
 <head>
   <title>Semantics</title>
+  <style type="text/css">
+    .nospacing {
+      border: 0 !important;
+      padding: 0 !important;
+      margin: 0 !important;
+    }
+  </style>
 </head>
 
 <body>
 
   <!-- Presentation MathML: the child is displayed -->
   <p>presentation MathML ; annotation: <math><semantics><mtext>presentation MathML</mtext><annotation>annotation</annotation></semantics></math></p>
-  <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>
+  <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>
 
   <!-- Content MathML: the annotation is displayed -->
   <p>content MathML ; annotation: <math><semantics><csymbol>content MathML</csymbol><annotation>annotation</annotation></semantics></math></p>
-  <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>
+  <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>
 
 </body>
 </html>
index 573a465..cc4b0f9 100644 (file)
@@ -2,6 +2,13 @@
 <html>
 <head>
   <title>Semantics</title>
+  <style type="text/css">
+    .nospacing {
+      border: 0 !important;
+      padding: 0 !important;
+      margin: 0 !important;
+    }
+  </style>
 </head>
 
 <body>
    - An <annotation-xml> element without src attribute and with one of the encoding among "application/mathml-presentation+xml", "MathML-Presentation", "image/svg+xml", "SVG1.1", "application/xhtml+xml" and "text/html".
    -->
 
-  <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>
-  <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>
-  <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>
+  <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>
+  <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>
+  <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>
 
-  <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>
-  <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>
-  <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>
-  <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>
-  <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>
-  <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>
-  <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>
+  <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>
+  <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>
+  <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>
+  <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>
+  <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>
+  <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>
+  <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>
 </body>
 </html>
index ddd80b7..59978a4 100644 (file)
@@ -2,13 +2,20 @@
 <html>
 <head>
   <title>Semantics</title>
+  <style type="text/css">
+    .nospacing {
+      border: 0 !important;
+      padding: 0 !important;
+      margin: 0 !important;
+    }
+  </style>
 </head>
 
 <body onload="document.getElementById('a').setAttribute('encoding', 'MathML-Presentation')">
 
   <!-- This test verifies that setting the encoding dynamically updates the selected annotation. This should render the same as the static reference. -->
 
-  <p><math><semantics><csymbol>Content MathML</csymbol><annotation-xml id="a"><mtext>PASS</mtext></annotation-xml><annotation>FAIL</annotation></semantics></math></p>
+  <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>
 
 </body>
 </html>
index 8d921e6..5d65308 100644 (file)
@@ -1,3 +1,36 @@
+2014-03-21  Frédéric Wang  <fred.wang@free.fr>
+
+        Bug 130345 - Refine childShouldCreateRenderer for MathML elements
+        https://bugs.webkit.org/show_bug.cgi?id=130345
+
+        Reviewed by Chris Fleizach.
+
+        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.
+
 2014-03-21  Darin Adler  <darin@apple.com>
 
         Stop using deprecatedCharacters in WebCore/platform/win
index 42fe25d..1830994 100644 (file)
 
 #include "MathMLElement.h"
 
+#include "ElementIterator.h"
+#include "HTMLElement.h"
+#include "HTMLMapElement.h"
+#include "HTMLNames.h"
 #include "MathMLNames.h"
+#include "MathMLSelectElement.h"
 #include "RenderTableCell.h"
+#include "SVGElement.h"
+#include "SVGNames.h"
 
 namespace WebCore {
     
@@ -50,7 +57,140 @@ PassRefPtr<MathMLElement> MathMLElement::create(const QualifiedName& tagName, Do
 
 bool MathMLElement::isPresentationMathML() const
 {
-    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);
+    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);
+}
+
+bool MathMLElement::isPhrasingContent(const Node& node) const
+{
+    // Phrasing content is described in the HTML 5 specification:
+    // http://www.w3.org/TR/html5/dom.html#phrasing-content.
+
+    if (!node.isElementNode())
+        return node.isTextNode();
+
+    if (node.isMathMLElement()) {
+        auto& mathmlElement = toMathMLElement(node);
+        return mathmlElement.hasTagName(MathMLNames::mathTag);
+    }
+
+    if (node.isSVGElement()) {
+        auto& svgElement = toSVGElement(node);
+        return svgElement.hasTagName(SVGNames::svgTag);
+    }
+
+    if (node.isHTMLElement()) {
+        // FIXME: add the <data> and <time> tags when they are implemented.
+        auto& htmlElement = toHTMLElement(node);
+        return htmlElement.hasTagName(HTMLNames::aTag)
+            || htmlElement.hasTagName(HTMLNames::abbrTag)
+            || (htmlElement.hasTagName(HTMLNames::areaTag) && ancestorsOfType<HTMLMapElement>(htmlElement).first())
+            || htmlElement.hasTagName(HTMLNames::audioTag)
+            || htmlElement.hasTagName(HTMLNames::bTag)
+            || htmlElement.hasTagName(HTMLNames::bdiTag)
+            || htmlElement.hasTagName(HTMLNames::bdoTag)
+            || htmlElement.hasTagName(HTMLNames::brTag)
+            || htmlElement.hasTagName(HTMLNames::buttonTag)
+            || htmlElement.hasTagName(HTMLNames::canvasTag)
+            || htmlElement.hasTagName(HTMLNames::citeTag)
+            || htmlElement.hasTagName(HTMLNames::codeTag)
+            || htmlElement.hasTagName(HTMLNames::datalistTag)
+            || htmlElement.hasTagName(HTMLNames::delTag)
+            || htmlElement.hasTagName(HTMLNames::dfnTag)
+            || htmlElement.hasTagName(HTMLNames::emTag)
+            || htmlElement.hasTagName(HTMLNames::embedTag)
+            || htmlElement.hasTagName(HTMLNames::iTag)
+            || htmlElement.hasTagName(HTMLNames::iframeTag)
+            || htmlElement.hasTagName(HTMLNames::imgTag)
+            || htmlElement.hasTagName(HTMLNames::inputTag)
+            || htmlElement.hasTagName(HTMLNames::insTag)
+            || htmlElement.hasTagName(HTMLNames::kbdTag)
+            || htmlElement.hasTagName(HTMLNames::keygenTag)
+            || htmlElement.hasTagName(HTMLNames::labelTag)
+            || htmlElement.hasTagName(HTMLNames::mapTag)
+            || htmlElement.hasTagName(HTMLNames::markTag)
+            || htmlElement.hasTagName(HTMLNames::meterTag)
+            || htmlElement.hasTagName(HTMLNames::noscriptTag)
+            || htmlElement.hasTagName(HTMLNames::objectTag)
+            || htmlElement.hasTagName(HTMLNames::outputTag)
+            || htmlElement.hasTagName(HTMLNames::progressTag)
+            || htmlElement.hasTagName(HTMLNames::qTag)
+            || htmlElement.hasTagName(HTMLNames::rubyTag)
+            || htmlElement.hasTagName(HTMLNames::sTag)
+            || htmlElement.hasTagName(HTMLNames::sampTag)
+            || htmlElement.hasTagName(HTMLNames::scriptTag)
+            || htmlElement.hasTagName(HTMLNames::selectTag)
+            || htmlElement.hasTagName(HTMLNames::smallTag)
+            || htmlElement.hasTagName(HTMLNames::spanTag)
+            || htmlElement.hasTagName(HTMLNames::strongTag)
+            || htmlElement.hasTagName(HTMLNames::subTag)
+            || htmlElement.hasTagName(HTMLNames::supTag)
+            || htmlElement.hasTagName(HTMLNames::templateTag)
+            || htmlElement.hasTagName(HTMLNames::textareaTag)
+            || htmlElement.hasTagName(HTMLNames::uTag)
+            || htmlElement.hasTagName(HTMLNames::varTag)
+            || htmlElement.hasTagName(HTMLNames::videoTag)
+            || htmlElement.hasTagName(HTMLNames::wbrTag);
+    }
+
+    return false;
+}
+
+bool MathMLElement::isFlowContent(const Node& node) const
+{
+    // Flow content is described in the HTML 5 specification:
+    // http://www.w3.org/TR/html5/dom.html#flow-content
+
+    if (isPhrasingContent(node))
+        return true;
+
+    if (!node.isHTMLElement())
+        return false;
+
+    auto& htmlElement = toHTMLElement(node);
+    // FIXME add the <dialog> tag when it is implemented.
+    return htmlElement.hasTagName(HTMLNames::addressTag)
+        || htmlElement.hasTagName(HTMLNames::articleTag)
+        || htmlElement.hasTagName(HTMLNames::asideTag)
+        || htmlElement.hasTagName(HTMLNames::blockquoteTag)
+        || htmlElement.hasTagName(HTMLNames::detailsTag)
+        || htmlElement.hasTagName(HTMLNames::divTag)
+        || htmlElement.hasTagName(HTMLNames::dlTag)
+        || htmlElement.hasTagName(HTMLNames::fieldsetTag)
+        || htmlElement.hasTagName(HTMLNames::figureTag)
+        || htmlElement.hasTagName(HTMLNames::footerTag)
+        || htmlElement.hasTagName(HTMLNames::formTag)
+        || htmlElement.hasTagName(HTMLNames::h1Tag)
+        || htmlElement.hasTagName(HTMLNames::h2Tag)
+        || htmlElement.hasTagName(HTMLNames::h3Tag)
+        || htmlElement.hasTagName(HTMLNames::h4Tag)
+        || htmlElement.hasTagName(HTMLNames::h5Tag)
+        || htmlElement.hasTagName(HTMLNames::h6Tag)
+        || htmlElement.hasTagName(HTMLNames::headerTag)
+        || htmlElement.hasTagName(HTMLNames::hrTag)
+        || htmlElement.hasTagName(HTMLNames::mainTag)
+        || htmlElement.hasTagName(HTMLNames::navTag)
+        || htmlElement.hasTagName(HTMLNames::olTag)
+        || htmlElement.hasTagName(HTMLNames::pTag)
+        || htmlElement.hasTagName(HTMLNames::preTag)
+        || htmlElement.hasTagName(HTMLNames::sectionTag)
+        || (htmlElement.hasTagName(HTMLNames::styleTag) && htmlElement.hasAttribute("scoped"))
+        || htmlElement.hasTagName(HTMLNames::tableTag)
+        || htmlElement.hasTagName(HTMLNames::ulTag);
 }
 
 int MathMLElement::colSpan() const
@@ -123,13 +263,31 @@ void MathMLElement::collectStyleForPresentationAttribute(const QualifiedName& na
 
 bool MathMLElement::childShouldCreateRenderer(const Node& child) const
 {
-    if (hasTagName(annotationTag))
-        return child.isTextNode();
-    if (hasTagName(annotation_xmlTag))
-        return StyledElement::childShouldCreateRenderer(child);
+    if (hasTagName(annotation_xmlTag)) {
+        const AtomicString& value = fastGetAttribute(MathMLNames::encodingAttr);
+
+        // See annotation-xml.model.mathml, annotation-xml.model.svg and annotation-xml.model.xhtml in the HTML5 RelaxNG schema.
+
+        if (child.isMathMLElement() && (MathMLSelectElement::isMathMLEncoding(value) || MathMLSelectElement::isHTMLEncoding(value))) {
+            auto& mathmlElement = toMathMLElement(child);
+            return mathmlElement.hasTagName(MathMLNames::mathTag);
+        }
+
+        if (child.isSVGElement() && (MathMLSelectElement::isSVGEncoding(value) || MathMLSelectElement::isHTMLEncoding(value))) {
+            auto& svgElement = toSVGElement(child);
+            return svgElement.hasTagName(SVGNames::svgTag);
+        }
+
+        if (child.isHTMLElement() && MathMLSelectElement::isHTMLEncoding(value)) {
+            auto& htmlElement = toHTMLElement(child);
+            return htmlElement.hasTagName(HTMLNames::htmlTag) || (isFlowContent(htmlElement) && StyledElement::childShouldCreateRenderer(child));
+        }
+
+        return false;
+    }
 
-    // Only create renderers for MathML elements or text. MathML prohibits non-MathML markup inside a <math> element.
-    return child.isTextNode() || child.isMathMLElement();
+    // In general, only MathML children are allowed. Text nodes are only visible in token MathML elements.
+    return child.isMathMLElement();
 }
 
 void MathMLElement::attributeChanged(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason reason)
index 98e0449..68c81bd 100644 (file)
@@ -66,6 +66,9 @@ protected:
     virtual bool isPresentationAttribute(const QualifiedName&) const override;
     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override;
 
+    bool isPhrasingContent(const Node&) const;
+    bool isFlowContent(const Node&) const;
+
 private:
     virtual void updateSelectedChild() { }
 };
index 1e1cd62..326ea12 100644 (file)
 #if ENABLE(MATHML)
 
 #include "Event.h"
+#include "HTMLElement.h"
+#include "HTMLNames.h"
 #include "MathMLNames.h"
 #include "RenderMathMLRow.h"
+#include "SVGElement.h"
+#include "SVGNames.h"
 
 namespace WebCore {
 
@@ -52,6 +56,29 @@ RenderPtr<RenderElement> MathMLSelectElement::createElementRenderer(PassRef<Rend
     return createRenderer<RenderMathMLRow>(*this, std::move(style));
 }
 
+//  We recognize the following values for the encoding attribute of the <semantics> element:
+//
+// - "MathML-Presentation", which is mentioned in the MathML 3 recommendation.
+// - "SVG1.1" which is mentioned in the W3C note.
+//   http://www.w3.org/Math/Documents/Notes/graphics.xml
+// - Other MIME Content-Types for MathML, SVG and HTML.
+//
+// We exclude "application/mathml+xml" which is ambiguous about whether it is Presentation or Content MathML. Authors must use a more explicit encoding value.
+bool MathMLSelectElement::isMathMLEncoding(const AtomicString& value)
+{
+    return value == "application/mathml-presentation+xml" || value == "MathML-Presentation";
+}
+
+bool MathMLSelectElement::isSVGEncoding(const AtomicString& value)
+{
+    return value == "image/svg+xml" || value == "SVG1.1";
+}
+
+bool MathMLSelectElement::isHTMLEncoding(const AtomicString& value)
+{
+    return value == "application/xhtml+xml" || value == "text/html";
+}
+
 bool MathMLSelectElement::childShouldCreateRenderer(const Node& child) const
 {
     return MathMLElement::childShouldCreateRenderer(child) && m_selectedChild == &child;
@@ -155,16 +182,9 @@ Element* MathMLSelectElement::getSelectedSemanticsChild()
             // If the <annotation-xml> element has an src attribute then it is a reference to arbitrary binary data and it is not clear whether we can display it. Hence we just ignore the annotation.
             if (child->hasAttribute(MathMLNames::srcAttr))
                 continue;
-            // 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:
-            //
-            // - "MathML-Presentation", which is mentioned in the MathML 3 recommendation.
-            // - "SVG1.1" which is mentioned in the W3C note.
-            //   http://www.w3.org/Math/Documents/Notes/graphics.xml
-            // - Other MIME Content-Types for SVG and HTML.
-            //
-            // We exclude "application/mathml+xml" which is ambiguous about whether it is Presentation or Content MathML. Authors must use a more explicit encoding value.
+            // 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.
             const AtomicString& value = child->fastGetAttribute(MathMLNames::encodingAttr);
-            if (value == "application/mathml-presentation+xml" || value == "MathML-Presentation" || value == "image/svg+xml" || value == "SVG1.1" || value == "application/xhtml+xml" || value == "text/html")
+            if (isMathMLEncoding(value) || isSVGEncoding(value) || isHTMLEncoding(value))
                 return child;
         }
     }
index 9c1b2ff..03a8534 100644 (file)
@@ -34,6 +34,9 @@ namespace WebCore {
 class MathMLSelectElement final : public MathMLInlineContainerElement {
 public:
     static PassRefPtr<MathMLSelectElement> create(const QualifiedName& tagName, Document&);
+    static bool isMathMLEncoding(const AtomicString& value);
+    static bool isSVGEncoding(const AtomicString& value);
+    static bool isHTMLEncoding(const AtomicString& value);
 
 private:
     MathMLSelectElement(const QualifiedName& tagName, Document&);
index 3f9e5b0..10e3087 100644 (file)
 
 #include "MathMLTextElement.h"
 
-#include "HTMLElement.h"
-#include "HTMLNames.h"
 #include "MathMLNames.h"
 #include "RenderMathMLOperator.h"
 #include "RenderMathMLSpace.h"
 #include "RenderMathMLToken.h"
-#include "SVGElement.h"
-#include "SVGNames.h"
 
 namespace WebCore {
     
@@ -82,83 +78,6 @@ RenderPtr<RenderElement> MathMLTextElement::createElementRenderer(PassRef<Render
     return createRenderer<RenderMathMLToken>(*this, std::move(style));
 }
 
-static bool isPhrasingContent(const Node& node)
-{
-    // Phrasing content is described in the HTML 5 specification:
-    // http://www.w3.org/TR/html5/dom.html#phrasing-content.
-
-    if (!node.isElementNode())
-        return node.isTextNode();
-
-    auto& element = toElement(node);
-
-    if (element.isMathMLElement()) {
-        auto& mathmlElement = toMathMLElement(element);
-        return mathmlElement.hasTagName(MathMLNames::mathTag);
-    }
-
-    if (element.isSVGElement()) {
-        auto& svgElement = toSVGElement(element);
-        return svgElement.hasTagName(SVGNames::svgTag);
-    }
-
-    if (element.isHTMLElement()) {
-        // FIXME: add the <data> and <time> tags when they are implemented.
-        auto& htmlElement = toHTMLElement(element);
-        return htmlElement.hasTagName(HTMLNames::aTag)
-            || htmlElement.hasTagName(HTMLNames::abbrTag)
-            || htmlElement.hasTagName(HTMLNames::areaTag)
-            || htmlElement.hasTagName(HTMLNames::audioTag)
-            || htmlElement.hasTagName(HTMLNames::bTag)
-            || htmlElement.hasTagName(HTMLNames::bdiTag)
-            || htmlElement.hasTagName(HTMLNames::bdoTag)
-            || htmlElement.hasTagName(HTMLNames::brTag)
-            || htmlElement.hasTagName(HTMLNames::buttonTag)
-            || htmlElement.hasTagName(HTMLNames::canvasTag)
-            || htmlElement.hasTagName(HTMLNames::citeTag)
-            || htmlElement.hasTagName(HTMLNames::codeTag)
-            || htmlElement.hasTagName(HTMLNames::datalistTag)
-            || htmlElement.hasTagName(HTMLNames::delTag)
-            || htmlElement.hasTagName(HTMLNames::dfnTag)
-            || htmlElement.hasTagName(HTMLNames::emTag)
-            || htmlElement.hasTagName(HTMLNames::embedTag)
-            || htmlElement.hasTagName(HTMLNames::iTag)
-            || htmlElement.hasTagName(HTMLNames::iframeTag)
-            || htmlElement.hasTagName(HTMLNames::imgTag)
-            || htmlElement.hasTagName(HTMLNames::inputTag)
-            || htmlElement.hasTagName(HTMLNames::insTag)
-            || htmlElement.hasTagName(HTMLNames::kbdTag)
-            || htmlElement.hasTagName(HTMLNames::keygenTag)
-            || htmlElement.hasTagName(HTMLNames::labelTag)
-            || htmlElement.hasTagName(HTMLNames::mapTag)
-            || htmlElement.hasTagName(HTMLNames::markTag)
-            || htmlElement.hasTagName(HTMLNames::meterTag)
-            || htmlElement.hasTagName(HTMLNames::noscriptTag)
-            || htmlElement.hasTagName(HTMLNames::objectTag)
-            || htmlElement.hasTagName(HTMLNames::outputTag)
-            || htmlElement.hasTagName(HTMLNames::progressTag)
-            || htmlElement.hasTagName(HTMLNames::qTag)
-            || htmlElement.hasTagName(HTMLNames::rubyTag)
-            || htmlElement.hasTagName(HTMLNames::sTag)
-            || htmlElement.hasTagName(HTMLNames::sampTag)
-            || htmlElement.hasTagName(HTMLNames::scriptTag)
-            || htmlElement.hasTagName(HTMLNames::selectTag)
-            || htmlElement.hasTagName(HTMLNames::smallTag)
-            || htmlElement.hasTagName(HTMLNames::spanTag)
-            || htmlElement.hasTagName(HTMLNames::strongTag)
-            || htmlElement.hasTagName(HTMLNames::subTag)
-            || htmlElement.hasTagName(HTMLNames::supTag)
-            || htmlElement.hasTagName(HTMLNames::templateTag)
-            || htmlElement.hasTagName(HTMLNames::textareaTag)
-            || htmlElement.hasTagName(HTMLNames::uTag)
-            || htmlElement.hasTagName(HTMLNames::varTag)
-            || htmlElement.hasTagName(HTMLNames::videoTag)
-            || htmlElement.hasTagName(HTMLNames::wbrTag);
-    }
-
-    return false;
-}
-
 bool MathMLTextElement::childShouldCreateRenderer(const Node& child) const
 {
     if (hasTagName(MathMLNames::mspaceTag))
@@ -169,7 +88,7 @@ bool MathMLTextElement::childShouldCreateRenderer(const Node& child) const
         return child.isTextNode();
 
     // The HTML specification defines <mi>, <mo>, <mn>, <ms> and <mtext> as insertion points.
-    return isPhrasingContent(child);
+    return isPhrasingContent(child) && StyledElement::childShouldCreateRenderer(child);
 }
 
 }