[SVG] Accept HTML and MathML namespaces as valid requiredExtensions
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Jan 2014 12:03:10 +0000 (12:03 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Jan 2014 12:03:10 +0000 (12:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=88188

Patch by Frédéric Wang <fred.wang@free.fr> on 2014-01-10
Reviewed by Dirk Schulze.

Source/WebCore:

When HTML and MathML are used as foreign objects of an SVG image, it is
important for Web authors to be able to specify a fallback content for
SVG-only readers or browsers without MathML support. We rely on the
requiredExtensions for that purpose and we use the XHTML/MathML
namespaces as suggested in SVG Tiny 1.2 and implemented in Gecko.

Tests: svg/custom/conditional-processing-1.svg
       svg/custom/conditional-processing-2.html
       svg/dom/SVGTests.html

* svg/SVGSwitchElement.cpp: Remove an incorrect FIXME comment and replace it with a reference to bug 74749.
(WebCore::SVGSwitchElement::childShouldCreateRenderer):
* svg/SVGTests.cpp: Check if the list of required extensions contains only the XHTML/MathML namespaces.
(WebCore::SVGTests::hasExtension):
(WebCore::SVGTests::isValid):

LayoutTests:

conditional-processing-1 verifies that indeed a renderer object is only
created for the first "valid" SVG element of a <switch>, contrary to
what an incorrect FIXME comment said. conditional-processing-2 verifies
that the <switch> takes into account XHTML and MathML namespaces in the
requiredExtensions attribute to decide which SVG element is "valid".
SVGTests.html verifies the SVGTests interface of SVG DOM: three
SVGStringList attributes (already tested in svg/dom/SVGStringList.html)
and the hasExtension() function.

* svg/custom/conditional-processing-1-expected.txt: Added.
* svg/custom/conditional-processing-1.svg: Added.
* svg/custom/conditional-processing-2-expected.txt: Added.
* svg/custom/conditional-processing-2.html: Added.
* svg/dom/SVGTests-expected.txt: Added.
* svg/dom/SVGTests.html: Added.
* svg/dom/script-tests/SVGTests.js: Added.

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

LayoutTests/ChangeLog
LayoutTests/svg/custom/conditional-processing-1-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/conditional-processing-1.svg [new file with mode: 0644]
LayoutTests/svg/custom/conditional-processing-2-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/conditional-processing-2.html [new file with mode: 0644]
LayoutTests/svg/dom/SVGTests-expected.txt [new file with mode: 0644]
LayoutTests/svg/dom/SVGTests.html [new file with mode: 0644]
LayoutTests/svg/dom/script-tests/SVGTests.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/svg/SVGSwitchElement.cpp
Source/WebCore/svg/SVGTests.cpp

index 252a7a6..7b9229d 100644 (file)
@@ -1,3 +1,27 @@
+2014-01-10  Frédéric Wang  <fred.wang@free.fr>
+
+        [SVG] Accept HTML and MathML namespaces as valid requiredExtensions
+        https://bugs.webkit.org/show_bug.cgi?id=88188
+
+        Reviewed by Dirk Schulze.
+
+        conditional-processing-1 verifies that indeed a renderer object is only
+        created for the first "valid" SVG element of a <switch>, contrary to
+        what an incorrect FIXME comment said. conditional-processing-2 verifies
+        that the <switch> takes into account XHTML and MathML namespaces in the
+        requiredExtensions attribute to decide which SVG element is "valid".
+        SVGTests.html verifies the SVGTests interface of SVG DOM: three
+        SVGStringList attributes (already tested in svg/dom/SVGStringList.html)
+        and the hasExtension() function.
+
+        * svg/custom/conditional-processing-1-expected.txt: Added.
+        * svg/custom/conditional-processing-1.svg: Added.
+        * svg/custom/conditional-processing-2-expected.txt: Added.
+        * svg/custom/conditional-processing-2.html: Added.
+        * svg/dom/SVGTests-expected.txt: Added.
+        * svg/dom/SVGTests.html: Added.
+        * svg/dom/script-tests/SVGTests.js: Added.
+
 2014-01-10  Mihai Tica  <mitica@adobe.com>
 
         Add support for blendmode to Core Animation layer.
diff --git a/LayoutTests/svg/custom/conditional-processing-1-expected.txt b/LayoutTests/svg/custom/conditional-processing-1-expected.txt
new file mode 100644 (file)
index 0000000..9ff7d15
--- /dev/null
@@ -0,0 +1,6 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderSVGRoot {svg} at (0,0) size 100x100
+    RenderSVGContainer {switch} at (0,0) size 100x100
+      RenderSVGRect {rect} at (0,0) size 100x100 [fill={[type=SOLID] [color=#008000]}] [x=0.00] [y=0.00] [width=100.00] [height=100.00]
diff --git a/LayoutTests/svg/custom/conditional-processing-1.svg b/LayoutTests/svg/custom/conditional-processing-1.svg
new file mode 100644 (file)
index 0000000..63fdf6d
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
+  <switch>
+    <!-- This test passes if a renderer is only created for the first valid SVG child. -->
+    <span xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; width: 100px; height: 100px; background: red"/>
+    <mspace xmlns="http://www.w3.org/1998/Math/MathML" width="100px" height="100px" mathbackground="red"/>
+    <foreignObject requiredExtensions="unknownExtension" height="100" width="100">
+       <span xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; width: 100px; height: 100px; background: red"/>
+    </foreignObject>
+    <rect width="100" height="100" fill="green"/>
+    <rect width="100" height="100" fill="red"/>
+    <rect width="100" height="100" fill="red"/>
+    <rect width="100" height="100" fill="red"/>
+    <rect width="100" height="100" fill="red"/>
+  </switch>
+</svg>
diff --git a/LayoutTests/svg/custom/conditional-processing-2-expected.txt b/LayoutTests/svg/custom/conditional-processing-2-expected.txt
new file mode 100644 (file)
index 0000000..7bd51b0
--- /dev/null
@@ -0,0 +1,41 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x160
+  RenderBlock {HTML} at (0,0) size 800x160
+    RenderBody {BODY} at (8,16) size 784x136
+      RenderBlock {P} at (0,0) size 784x17
+        RenderText {#text} at (0,0) size 321x17
+          text run at (0,0) width 321: "This test passes if four green squares are displayed:"
+      RenderBlock (anonymous) at (0,33) size 784x103
+        RenderSVGRoot {svg} at (8,49) size 100x100
+          RenderSVGContainer {switch} at (8,49) size 100x100
+            RenderSVGForeignObject {foreignObject} at (0,0) size 100x100
+              RenderBlock {SPAN} at (0,0) size 100x100 [bgcolor=#008000]
+              RenderText {#text} at (0,0) size 0x0
+        RenderText {#text} at (100,86) size 4x17
+          text run at (100,86) width 4: " "
+        RenderText {#text} at (0,0) size 0x0
+        RenderSVGRoot {svg} at (112,49) size 100x100
+          RenderSVGContainer {switch} at (112,49) size 100x100
+            RenderSVGForeignObject {foreignObject} at (0,0) size 100x100
+              RenderMathMLMath {math} at (0,0) size 102x100 [padding: 0 1 0 1]
+                RenderMathMLSpace {mspace} at (1,0) size 100x100 [bgcolor=#008000]
+              RenderText {#text} at (0,0) size 0x0
+        RenderText {#text} at (204,86) size 4x17
+          text run at (204,86) width 4: " "
+        RenderText {#text} at (0,0) size 0x0
+        RenderSVGRoot {svg} at (216,49) size 100x100
+          RenderSVGContainer {switch} at (216,49) size 100x100
+            RenderSVGForeignObject {foreignObject} at (0,0) size 100x100
+              RenderBlock {SPAN} at (0,0) size 100x100
+                RenderMathMLMath {math} at (0,0) size 102x100 [padding: 0 1 0 1]
+                  RenderMathMLSpace {mspace} at (1,0) size 100x100 [bgcolor=#008000]
+                RenderText {#text} at (0,0) size 0x0
+              RenderText {#text} at (0,0) size 0x0
+        RenderText {#text} at (308,86) size 4x17
+          text run at (308,86) width 4: " "
+        RenderText {#text} at (0,0) size 0x0
+        RenderSVGRoot {svg} at (320,49) size 100x100
+          RenderSVGContainer {switch} at (320,49) size 100x100
+            RenderSVGRect {rect} at (320,49) size 100x100 [fill={[type=SOLID] [color=#008000]}] [x=0.00] [y=0.00] [width=100.00] [height=100.00]
+        RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/svg/custom/conditional-processing-2.html b/LayoutTests/svg/custom/conditional-processing-2.html
new file mode 100644 (file)
index 0000000..7021299
--- /dev/null
@@ -0,0 +1,60 @@
+<!doctype html>
+<html>
+  <head>
+    <title>requiredExtensions</title>
+    <meta charset="utf-8"/>
+  </head>
+  <body>
+
+    <!-- The following elements contain foreignObject with a list of required extensions. We should only display it when the list contains MathML or XHTML namespaces. -->
+
+    <p>This test passes if four green squares are displayed:</p>
+
+    <!-- This tests a required XHTML extension. -->
+    <svg width="100px" height="100px">
+      <switch>
+        <foreignObject requiredExtensions="http://www.w3.org/1999/xhtml" height="100" width="100">
+          <span style="display: inline-block; width: 100px; height: 100px; background: green"></span>
+        </foreignObject>
+        <rect width="100" height="100" fill="red"/>
+      </switch>
+    </svg>
+
+    <!-- This tests a required MathML extension. -->
+    <svg width="100px" height="100px">
+      <switch>
+        <foreignObject requiredExtensions="http://www.w3.org/1998/Math/MathML" height="100" width="100">
+          <math>
+            <mspace width="100px" height="100px" mathbackground="green"/>
+          </math>
+        </foreignObject>
+        <rect width="100" height="100" fill="red"/>
+      </switch>
+    </svg>
+
+    <!-- This tests required XHTML and MathML extensions. -->
+    <svg width="100px" height="100px">
+      <switch>
+        <foreignObject requiredExtensions="http://www.w3.org/1998/Math/MathML http://www.w3.org/1999/xhtml" height="100" width="100">
+          <span style="display: inline-block; width: 100px; height: 100px;">
+            <math>
+              <mspace width="100px" height="100px" mathbackground="green"/>
+            </math>
+          </span>
+        </foreignObject>
+        <rect width="100" height="100" fill="red"/>
+      </switch>
+    </svg>
+
+    <!-- This tests an unknown required extension. -->
+    <svg width="100px" height="100px">
+      <switch>
+        <foreignObject requiredExtensions="http://www.w3.org/1998/Math/MathML http://www.w3.org/1999/xhtml unknownExtension" height="100" width="100">
+          <span style="display: inline-block; width: 100px; height: 100px; background: red"></span>
+        </foreignObject>
+        <rect width="100" height="100" fill="green"/>
+      </switch>
+    </svg>
+
+  </body>
+</html>
diff --git a/LayoutTests/svg/dom/SVGTests-expected.txt b/LayoutTests/svg/dom/SVGTests-expected.txt
new file mode 100644 (file)
index 0000000..8fd148c
--- /dev/null
@@ -0,0 +1,22 @@
+This test checks the SVGTests API
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+Check the requiredFeatures, requiredExtensions and systemLanguage attributes
+PASS foreignObject.requiredFeatures instanceof SVGStringList is true
+PASS foreignObject.requiredExtensions instanceof SVGStringList is true
+PASS foreignObject.systemLanguage instanceof SVGStringList is true
+
+Check the hasExtension function
+PASS foreignObject.hasExtension('http://www.w3.org/1998/Math/MathML') is true
+PASS foreignObject.hasExtension('http://www.w3.org/1999/xhtml') is true
+PASS foreignObject.hasExtension('') is false
+PASS foreignObject.hasExtension('unknownExtension') is false
+PASS foreignObject.hasExtension('HTTP://WWW.W3.ORG/1999/XHTML') is false
+PASS foreignObject.hasExtension('http://www.w3.org/1998/Math/MathML http://www.w3.org/1999/xhtml') is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/svg/dom/SVGTests.html b/LayoutTests/svg/dom/SVGTests.html
new file mode 100644 (file)
index 0000000..0bcfb99
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/SVGTests.js"></script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/svg/dom/script-tests/SVGTests.js b/LayoutTests/svg/dom/script-tests/SVGTests.js
new file mode 100644 (file)
index 0000000..f2c893b
--- /dev/null
@@ -0,0 +1,21 @@
+description("This test checks the SVGTests API");
+
+var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
+var foreignObject = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
+
+debug("");
+debug("Check the requiredFeatures, requiredExtensions and systemLanguage attributes");
+shouldBeTrue("foreignObject.requiredFeatures instanceof SVGStringList");
+shouldBeTrue("foreignObject.requiredExtensions instanceof SVGStringList");
+shouldBeTrue("foreignObject.systemLanguage instanceof SVGStringList");
+
+debug("");
+debug("Check the hasExtension function");
+shouldBeTrue("foreignObject.hasExtension('http://www.w3.org/1998/Math/MathML')");
+shouldBeTrue("foreignObject.hasExtension('http://www.w3.org/1999/xhtml')");
+shouldBeFalse("foreignObject.hasExtension('')");
+shouldBeFalse("foreignObject.hasExtension('unknownExtension')");
+shouldBeFalse("foreignObject.hasExtension('HTTP://WWW.W3.ORG/1999/XHTML')");
+shouldBeFalse("foreignObject.hasExtension('http://www.w3.org/1998/Math/MathML http://www.w3.org/1999/xhtml')");
+
+successfullyParsed = true;
index 11bc5bc..fce3a86 100644 (file)
@@ -1,3 +1,26 @@
+2014-01-10  Frédéric Wang  <fred.wang@free.fr>
+
+        [SVG] Accept HTML and MathML namespaces as valid requiredExtensions
+        https://bugs.webkit.org/show_bug.cgi?id=88188
+
+        Reviewed by Dirk Schulze.
+
+        When HTML and MathML are used as foreign objects of an SVG image, it is
+        important for Web authors to be able to specify a fallback content for
+        SVG-only readers or browsers without MathML support. We rely on the
+        requiredExtensions for that purpose and we use the XHTML/MathML
+        namespaces as suggested in SVG Tiny 1.2 and implemented in Gecko.
+
+        Tests: svg/custom/conditional-processing-1.svg
+               svg/custom/conditional-processing-2.html
+               svg/dom/SVGTests.html
+
+        * svg/SVGSwitchElement.cpp: Remove an incorrect FIXME comment and replace it with a reference to bug 74749.
+        (WebCore::SVGSwitchElement::childShouldCreateRenderer):
+        * svg/SVGTests.cpp: Check if the list of required extensions contains only the XHTML/MathML namespaces.
+        (WebCore::SVGTests::hasExtension):
+        (WebCore::SVGTests::isValid):
+
 2014-01-10  Mihai Tica  <mitica@adobe.com>
 
         Add support for blendmode to Core Animation layer.
index 9d76b9f..0276bcd 100644 (file)
@@ -51,8 +51,8 @@ PassRefPtr<SVGSwitchElement> SVGSwitchElement::create(const QualifiedName& tagNa
 
 bool SVGSwitchElement::childShouldCreateRenderer(const Node& child) const
 {
-    // FIXME: This function does not do what the comment below implies it does.
-    // It will create a renderer for any valid SVG element children, not just the first one.
+    // We create a renderer for the first valid SVG element child.
+    // FIXME: The renderer must be updated after dynamic change of the requiredFeatures, requiredExtensions and systemLanguage attributes (http://wkb.ug/74749).
     for (auto& element : childrenOfType<SVGElement>(*this)) {
         if (!element.isValid())
             continue;
index 6ac8f7b..06a3824 100644 (file)
 
 #include "Attribute.h"
 #include "DOMImplementation.h"
+#include "HTMLNames.h"
 #include "Language.h"
+#if ENABLE(MATHML)
+#include "MathMLNames.h"
+#endif
 #include "SVGElement.h"
 #include "SVGNames.h"
 #include "SVGStringList.h"
@@ -95,10 +99,14 @@ SVGAttributeToPropertyMap& SVGTests::attributeToPropertyMap()
     return map;
 }
 
-bool SVGTests::hasExtension(const String&) const
+bool SVGTests::hasExtension(const String& extension) const
 {
-    // FIXME: Implement me!
-    return false;
+    // We recognize XHTML and MathML, as implemented in Gecko and suggested in the SVG Tiny recommendation (http://www.w3.org/TR/SVG11/struct.html#RequiredExtensionsAttribute).
+#if ENABLE(MATHML)
+    return extension == HTMLNames::xhtmlNamespaceURI || extension == MathMLNames::mathmlNamespaceURI;
+#else
+    return extension == HTMLNames::xhtmlNamespaceURI;
+#endif
 }
 
 bool SVGTests::isValid() const
@@ -117,8 +125,12 @@ bool SVGTests::isValid() const
             return false;
     }
 
-    if (!m_requiredExtensions.value.isEmpty())
-        return false;
+    unsigned extensionsSize = m_requiredExtensions.value.size();
+    for (unsigned i = 0; i < extensionsSize; ++i) {
+        String value = m_requiredExtensions.value.at(i);
+        if (!hasExtension(value))
+            return false;
+    }
 
     return true;
 }