2006-09-26 Eric Seidel <eric@eseidel.com>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Sep 2006 12:56:30 +0000 (12:56 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Sep 2006 12:56:30 +0000 (12:56 +0000)
        Reviewed by Tim H.

        SVGDocument::createElement does not create elements in the SVG namespace
        http://bugzilla.opendarwin.org/show_bug.cgi?id=10932

        Test: svg/custom/createelement.svg

        * ksvg2/svg/SVGDocument.cpp:
        (WebCore::SVGDocument::createElement):
        * ksvg2/svg/SVGDocument.h:

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

LayoutTests/ChangeLog
LayoutTests/svg/custom/createelement-expected.checksum [new file with mode: 0644]
LayoutTests/svg/custom/createelement-expected.png [new file with mode: 0644]
LayoutTests/svg/custom/createelement-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/createelement.svg [new file with mode: 0644]
WebCore/ChangeLog
WebCore/ksvg2/svg/SVGDocument.cpp
WebCore/ksvg2/svg/SVGDocument.h

index 6b5c0f1d5eb66432990fd2b70e593beef718685f..95e6d1ca90818a9a30c306de79a7e5e7c20e025c 100644 (file)
@@ -1,3 +1,15 @@
+2006-09-26  Eric Seidel  <eric@eseidel.com>
+
+        Reviewed by Tim H.
+
+        SVGDocument::createElement does not create elements in the SVG namespace
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=10932
+
+        * svg/custom/createelement-expected.checksum: Added.
+        * svg/custom/createelement-expected.png: Added.
+        * svg/custom/createelement-expected.txt: Added.
+        * svg/custom/createelement.svg: Added.
+
 2006-09-26  Eric Seidel  <eric@eseidel.com>
 
         Reviewed by Tim H.
diff --git a/LayoutTests/svg/custom/createelement-expected.checksum b/LayoutTests/svg/custom/createelement-expected.checksum
new file mode 100644 (file)
index 0000000..4c8be32
--- /dev/null
@@ -0,0 +1 @@
+8d142988c8c534f3ac6bb5b2a0e1555a
\ No newline at end of file
diff --git a/LayoutTests/svg/custom/createelement-expected.png b/LayoutTests/svg/custom/createelement-expected.png
new file mode 100644 (file)
index 0000000..10e13c7
Binary files /dev/null and b/LayoutTests/svg/custom/createelement-expected.png differ
diff --git a/LayoutTests/svg/custom/createelement-expected.txt b/LayoutTests/svg/custom/createelement-expected.txt
new file mode 100644 (file)
index 0000000..00f2f8b
--- /dev/null
@@ -0,0 +1,8 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+    KCanvasContainer {svg} at (0,0) size 100x100
+      KCanvasItem {rect} at (0,0) size 100x100 [fill={[type=SOLID] [color=#FF0000]}] [data="M0.00,0.00L100.00,0.00L100.00,100.00L0.00,100.00"]
+      RenderSVGText {text} at (0,0) size 800x18
+        RenderText {#text} at (0,0) size 353x18
+          text run at (0,0) width 353: "namespace of created rect: http://www.w3.org/2000/svg"
+      KCanvasItem {rect} at (0,0) size 100x100 [fill={[type=SOLID] [color=#008000]}] [data="M0.00,0.00L100.00,0.00L100.00,100.00L0.00,100.00"]
diff --git a/LayoutTests/svg/custom/createelement.svg b/LayoutTests/svg/custom/createelement.svg
new file mode 100644 (file)
index 0000000..4aace36
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg">
+  <rect id="red" width="100" height="100" fill="red" />
+  <text id="text" x="10" y="120"></text>
+  <script type="text/javascript">
+  <![CDATA[
+    var red = document.getElementById('red');
+    // Note the use of createElement instead of createElementNS
+    var green = document.createElement("rect");
+    // DOM 3 core says the namespaceURI must be null:
+    // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/DOM3-Core.html#core-ID-2141741547
+    // but setting it to http://www.w3.org/2000/svg (like html does) is more in line with what web authors will expect.
+    green.setAttribute("width", "100");
+    green.setAttribute("height", "100");
+    green.setAttribute("fill", "green");
+    red.ownerDocument.rootElement.appendChild(green);
+    document.getElementById('text').textContent = "namespace of created rect: " + green.namespaceURI;
+  ]]>
+  </script>
+</svg>
index 1c56f236e1b4413e8d642f38ad5ccb845cdd2dbd..7da223fbf63fe91843e987fe0dd3639303b35f32 100644 (file)
@@ -1,3 +1,16 @@
+2006-09-26  Eric Seidel  <eric@eseidel.com>
+
+        Reviewed by Tim H.
+
+        SVGDocument::createElement does not create elements in the SVG namespace
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=10932
+        
+        Test: svg/custom/createelement.svg
+
+        * ksvg2/svg/SVGDocument.cpp:
+        (WebCore::SVGDocument::createElement):
+        * ksvg2/svg/SVGDocument.h:
+
 2006-09-26  Eric Seidel  <eric@eseidel.com>
 
         Reviewed by Tim H.
index 7d3a16d12820442e4c20c565ff2ed5ba03da04f2..43d707e0c1a3e493c829e7ba35d069bb1b7f0924 100644 (file)
 #include "EventNames.h"
 #include "ExceptionCode.h"
 #include "SVGElement.h"
+#include "SVGNames.h"
 #include "SVGSVGElement.h"
 #include "SVGZoomEvent.h"
 
 namespace WebCore {
 
-SVGDocument::SVGDocument(DOMImplementation *i, FrameView *view) : Document(i, view)
+SVGDocument::SVGDocument(DOMImplementation* i, FrameView* view)
+    : Document(i, view)
 {
 }
 
@@ -40,33 +42,36 @@ SVGDocument::~SVGDocument()
 {
 }
 
-SVGSVGElement *SVGDocument::rootElement() const
+SVGSVGElementSVGDocument::rootElement() const
 {
-    Element *elem = documentElement();
-    if(elem && elem->hasTagName(SVGNames::svgTag))
-        return static_cast<SVGSVGElement *>(elem);
+    Elementelem = documentElement();
+    if (elem && elem->hasTagName(SVGNames::svgTag))
+        return static_cast<SVGSVGElement*>(elem);
 
     return 0;
 }
 
+PassRefPtr<Element> SVGDocument::createElement(const String& tagName, ExceptionCode& ec)
+{
+    return createElementNS(SVGNames::svgNamespaceURI, tagName, ec);
+}
+
 void SVGDocument::dispatchZoomEvent(float prevScale, float newScale)
 {
-    // dispatch zoom event
     ExceptionCode ec = 0;
     RefPtr<SVGZoomEvent> event = static_pointer_cast<SVGZoomEvent>(createEvent("SVGZoomEvents", ec));
     event->initEvent(EventNames::zoomEvent, true, false);
     event->setPreviousScale(prevScale);
     event->setNewScale(newScale);
-    rootElement()->dispatchEvent(event.get(), ec);
+    rootElement()->dispatchEvent(event.release(), ec);
 }
 
 void SVGDocument::dispatchScrollEvent()
 {
-    // dispatch zoom event
     ExceptionCode ec = 0;
     RefPtr<Event> event = createEvent("SVGEvents", ec);
     event->initEvent(EventNames::scrollEvent, true, false);
-    rootElement()->dispatchEvent(event.get(), ec);
+    rootElement()->dispatchEvent(event.release(), ec);
 }
 
 }
index c7cc2ed5ccbc7b23aa1a4456e97f1c1f6edaf7da..5dccee0c921596d217728be8b3822f10930be064 100644 (file)
@@ -20,8 +20,8 @@
     Boston, MA 02111-1307, USA.
 */
 
-#ifndef KSVG_SVGDocumentImpl_H
-#define KSVG_SVGDocumentImpl_H
+#ifndef SVGDocument_H
+#define SVGDocument_H
 #ifdef SVG_SUPPORT
 
 #include "Document.h"
@@ -39,7 +39,9 @@ namespace WebCore {
         
         virtual bool isSVGDocument() const { return true; }
 
-        SVGSVGElement *rootElement() const;
+        SVGSVGElement* rootElement() const;
+        
+        virtual PassRefPtr<Element> SVGDocument::createElement(const String& tagName, ExceptionCode&);
         
         void dispatchZoomEvent(float prevScale, float newScale);
         void dispatchScrollEvent();
@@ -48,6 +50,6 @@ namespace WebCore {
 } // namespace WebCore
 
 #endif // SVG_SUPPORT
-#endif // KSVG_SVGDocumentImpl_H
+#endif // SVGDocument_H
 
 // vim:ts=4:noet