[webkit-changes] cvs commit: WebCore/ksvg2/svg
SVGStyledElementImpl.cpp SVGStyledElementImpl.h
Eric
eseidel at opensource.apple.com
Sun Dec 11 03:42:05 PST 2005
eseidel 05/12/11 03:42:04
Modified: . ChangeLog
khtml/xml xml_tokenizer.cpp
ksvg2/svg SVGStyledElementImpl.cpp SVGStyledElementImpl.h
Log:
Bug #: 5875
Submitted by: eseidel
Reviewed by: darin & mjs
Fixes SVG to load external scripts and report parse errors.
http://bugzilla.opendarwin.org/show_bug.cgi?id=5875
Added 7 layout tests to exercise parse error code.
* khtml/xml/xml_tokenizer.cpp:
(khtml::createXHTMLParserErrorHeader):
(khtml::XMLTokenizer::insertErrorMessageBlock):
(khtml::XMLTokenizer::executeScripts):
* ksvg2/svg/SVGStyledElementImpl.h: removed broken code
* ksvg2/svg/SVGStyledElementImpl.cpp: removed broken attach()
Revision Changes Path
1.510 +16 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.509
retrieving revision 1.510
diff -u -r1.509 -r1.510
--- ChangeLog 11 Dec 2005 09:25:53 -0000 1.509
+++ ChangeLog 11 Dec 2005 11:41:58 -0000 1.510
@@ -1,5 +1,21 @@
2005-12-11 Eric Seidel <eseidel at apple.com>
+ Reviewed by darin & mjs.
+
+ Fixes SVG to load external scripts and report parse errors.
+ http://bugzilla.opendarwin.org/show_bug.cgi?id=5875
+
+ Added 7 layout tests to exercise parse error code.
+
+ * khtml/xml/xml_tokenizer.cpp:
+ (khtml::createXHTMLParserErrorHeader):
+ (khtml::XMLTokenizer::insertErrorMessageBlock):
+ (khtml::XMLTokenizer::executeScripts):
+ * ksvg2/svg/SVGStyledElementImpl.h: removed broken code
+ * ksvg2/svg/SVGStyledElementImpl.cpp: removed broken attach()
+
+2005-12-11 Eric Seidel <eseidel at apple.com>
+
Reviewed by hyatt.
Small fixes made during SVG code review.
1.56 +57 -35 WebCore/khtml/xml/xml_tokenizer.cpp
Index: xml_tokenizer.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/xml_tokenizer.cpp,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- xml_tokenizer.cpp 8 Dec 2005 09:17:05 -0000 1.55
+++ xml_tokenizer.cpp 11 Dec 2005 11:42:03 -0000 1.56
@@ -42,6 +42,7 @@
#if SVG_SUPPORT
#include "SVGNames.h"
+#include "XLinkNames.h"
#endif
#include <qptrstack.h>
@@ -660,6 +661,28 @@
emit finishedParsing();
}
+static inline RefPtr<ElementImpl> createXHTMLParserErrorHeader(DocumentImpl* doc, const DOMString& errorMessages)
+{
+ int exceptioncode = 0;
+ RefPtr<ElementImpl> reportElement = doc->createElementNS(xhtmlNamespaceURI, "parsererror", exceptioncode);
+ reportElement->setAttribute(styleAttr, "white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black");
+
+ RefPtr<ElementImpl> h3 = doc->createElementNS(xhtmlNamespaceURI, "h3", exceptioncode);
+ reportElement->appendChild(h3.get(), exceptioncode);
+ h3->appendChild(doc->createTextNode("This page contains the following errors:"), exceptioncode);
+
+ RefPtr<ElementImpl> fixed = doc->createElementNS(xhtmlNamespaceURI, "div", exceptioncode);
+ reportElement->appendChild(fixed.get(), exceptioncode);
+ fixed->setAttribute(styleAttr, "font-family:monospace;font-size:12px");
+ fixed->appendChild(doc->createTextNode(errorMessages), exceptioncode);
+
+ h3 = doc->createElementNS(xhtmlNamespaceURI, "h3", exceptioncode);
+ reportElement->appendChild(h3.get(), exceptioncode);
+ h3->appendChild(doc->createTextNode("Below is a rendering of the page up to the first error."), exceptioncode);
+
+ return reportElement;
+}
+
void XMLTokenizer::insertErrorMessageBlock()
{
// One or more errors occurred during parsing of the code. Display an error block to the user above
@@ -669,29 +692,30 @@
// Create elements for display
int exceptioncode = 0;
DocumentImpl *doc = m_doc;
- NodeImpl* root = doc->documentElement();
- if (!root) {
- root = doc->createElementNS(xhtmlNamespaceURI, "html", exceptioncode);
+ NodeImpl* documentElement = doc->documentElement();
+ if (!documentElement) {
+ NodeImpl *rootElement = doc->createElementNS(xhtmlNamespaceURI, "html", exceptioncode);
+ doc->appendChild(rootElement, exceptioncode);
NodeImpl* body = doc->createElementNS(xhtmlNamespaceURI, "body", exceptioncode);
- root->appendChild(body, exceptioncode);
- doc->appendChild(root, exceptioncode);
- root = body;
+ rootElement->appendChild(body, exceptioncode);
+ documentElement = body;
}
+#if SVG_SUPPORT
+ else if (documentElement->namespaceURI() == KSVG::SVGNames::svgNamespaceURI) {
+ // Until our SVG implementation has text support, it is best if we
+ // wrap the erroneous SVG document in an xhtml document and render
+ // the combined document with error messages.
+ RefPtr<NodeImpl> rootElement = doc->createElementNS(xhtmlNamespaceURI, "html", exceptioncode);
+ NodeImpl* body = doc->createElementNS(xhtmlNamespaceURI, "body", exceptioncode);
+ rootElement->appendChild(body, exceptioncode);
+ body->appendChild(documentElement, exceptioncode);
+ doc->appendChild(rootElement.get(), exceptioncode);
+ documentElement = body;
+ }
+#endif
- ElementImpl* reportElement = doc->createElementNS(xhtmlNamespaceURI, "parsererror", exceptioncode);
- reportElement->setAttribute(styleAttr, "white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black");
- ElementImpl* h3 = doc->createElementNS(xhtmlNamespaceURI, "h3", exceptioncode);
- h3->appendChild(doc->createTextNode("This page contains the following errors:"), exceptioncode);
- reportElement->appendChild(h3, exceptioncode);
- ElementImpl* fixed = doc->createElementNS(xhtmlNamespaceURI, "div", exceptioncode);
- fixed->setAttribute(styleAttr, "font-family:monospace;font-size:12px");
- NodeImpl* textNode = doc->createTextNode(m_errorMessages);
- fixed->appendChild(textNode, exceptioncode);
- reportElement->appendChild(fixed, exceptioncode);
- h3 = doc->createElementNS(xhtmlNamespaceURI, "h3", exceptioncode);
- reportElement->appendChild(h3, exceptioncode);
-
- h3->appendChild(doc->createTextNode("Below is a rendering of the page up to the first error."), exceptioncode);
+ RefPtr<ElementImpl> reportElement = createXHTMLParserErrorHeader(doc, m_errorMessages);
+ documentElement->insertBefore(reportElement.get(), documentElement->firstChild(), exceptioncode);
#ifdef KHTML_XSLT
if (doc->transformSourceDocument()) {
ElementImpl* par = doc->createElementNS(xhtmlNamespaceURI, "p", exceptioncode);
@@ -700,8 +724,6 @@
par->appendChild(doc->createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result."), exceptioncode);
}
#endif
- root->insertBefore(reportElement, root->firstChild(), exceptioncode);
-
doc->updateRendering();
}
@@ -727,35 +749,35 @@
// start loading the script and return (executeScripts() will be called again once the script is loaded
// and continue where it left off). For scripts that don't have a src attribute, execute the code
// inside the tag
- while (m_scriptsIt->current()) {
- DOMString scriptSrc = m_scriptsIt->current()->getAttribute(srcAttr);
- QString charset = m_scriptsIt->current()->getAttribute(charsetAttr).qstring();
+ while (ElementImpl *scriptElement = m_scriptsIt->current()) {
+ ++(*m_scriptsIt);
+ DOMString scriptHref = scriptElement->getAttribute(srcAttr);
+#if SVG_SUPPORT
+ if (scriptElement->hasTagName(KSVG::SVGNames::scriptTag))
+ scriptHref = scriptElement->getAttribute(XLinkNames::hrefAttr);
+#endif
+ QString charset = scriptElement->getAttribute(charsetAttr).qstring();
// don't load external scripts for standalone documents (for now)
- if (scriptSrc != "" && m_doc->part()) {
+ if (!scriptHref.isEmpty() && m_doc->part()) {
// we have a src attribute
- m_cachedScript = m_doc->docLoader()->requestScript(scriptSrc, charset);
- ++(*m_scriptsIt);
+ m_cachedScript = m_doc->docLoader()->requestScript(scriptHref, charset);
m_cachedScript->ref(this); // will call executeScripts() again if already cached
return;
}
else {
// no src attribute - execute from contents of tag
QString scriptCode = "";
- NodeImpl *child;
- for (child = m_scriptsIt->current()->firstChild(); child; child = child->nextSibling()) {
- if (child->nodeType() == Node::TEXT_NODE || child->nodeType() == Node::CDATA_SECTION_NODE) {
+ for (NodeImpl *child = scriptElement->firstChild(); child; child = child->nextSibling()) {
+ if (child->nodeType() == Node::TEXT_NODE || child->nodeType() == Node::CDATA_SECTION_NODE)
scriptCode += static_cast<TextImpl*>(child)->data().qstring();
- }
}
// the script cannot do document.write until we support incremental parsing
// ### handle the case where the script deletes the node or redirects to
// another page, etc. (also in notifyFinished())
// ### the script may add another script node after this one which should be executed
- if (m_view) {
+ if (m_view)
m_view->part()->executeScript(scriptCode);
- }
- ++(*m_scriptsIt);
}
}
1.17 +0 -22 WebCore/ksvg2/svg/SVGStyledElementImpl.cpp
Index: SVGStyledElementImpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/ksvg2/svg/SVGStyledElementImpl.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- SVGStyledElementImpl.cpp 6 Dec 2005 01:53:16 -0000 1.16
+++ SVGStyledElementImpl.cpp 11 Dec 2005 11:42:04 -0000 1.17
@@ -113,28 +113,6 @@
notifyAttributeChange();
}
-void SVGStyledElementImpl::finalizeStyle(KCanvasRenderingStyle *style, bool needFillStrokeUpdate)
-{
- if(needFillStrokeUpdate && renderer()->isRenderPath()) {
- RenderPath *renderPath = static_cast<RenderPath *>(renderer());
- style->updateFill(renderPath);
- style->updateStroke(renderPath);
- }
-}
-
-void SVGStyledElementImpl::attach()
-{
- createRendererIfNeeded();
- if (m_render && m_render->isRenderPath())
- {
- RenderPath *renderPath = static_cast<RenderPath *>(m_render);
- KCanvasRenderingStyle *renderingStyle = static_cast<KCanvasRenderingStyle *>(renderPath->canvasStyle());
- finalizeStyle(renderingStyle);
- }
-
- KDOM::NodeImpl::attach();
-}
-
khtml::RenderCanvas *SVGStyledElementImpl::canvas() const
{
return static_cast<khtml::RenderCanvas *>(getDocument()->renderer());
1.14 +0 -4 WebCore/ksvg2/svg/SVGStyledElementImpl.h
Index: SVGStyledElementImpl.h
===================================================================
RCS file: /cvs/root/WebCore/ksvg2/svg/SVGStyledElementImpl.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- SVGStyledElementImpl.h 6 Dec 2005 01:23:25 -0000 1.13
+++ SVGStyledElementImpl.h 11 Dec 2005 11:42:04 -0000 1.14
@@ -53,8 +53,6 @@
// 'SVGStylable' functions
virtual SVGAnimatedStringImpl *className() const;
- virtual void attach();
-
// These need to be implemented.
virtual bool rendererIsNeeded(khtml::RenderStyle *) { return false; }
virtual KCanvasPath* toPathData() const { return 0; }
@@ -74,8 +72,6 @@
virtual const SVGStyledElementImpl *pushAttributeContext(const SVGStyledElementImpl *context);
protected:
- virtual void finalizeStyle(KCanvasRenderingStyle *style, bool needFillStrokeUpdate = true);
-
void updateCanvasItem(); // Handles "path data" object changes... (not for style/transform!)
private:
More information about the webkit-changes
mailing list