Commit 72779f46 authored by eseidel's avatar eseidel

Bug #: 5003

Submitted by: eseidel
Reviewed by: hyatt
        Added KDOM and KCanvas wrapper objects for the WebCore DOM
        and WebCore render tree.  This allows using SVG in any
        WebKit app, including Safari.
        Also added extensions to QPainter to return a
        KRenderingDeviceContext object to be passed into KCanvas.
        http://bugzilla.opendarwin.org/show_bug.cgi?id=5003

        * WebCore+SVG/dom_kdomdocumentwrapper.cpp: Added.
        (KDOMDocumentWrapperImpl::renderingDevice):
        (KDOMDocumentWrapperImpl::KDOMDocumentWrapperImpl):
        (KDOMDocumentWrapperImpl::~KDOMDocumentWrapperImpl):
        (DOM::KDOMDocumentWrapperImpl::createTokenizer):
        (KDOMDocumentWrapperImpl::svgView):
        * WebCore+SVG/dom_kdomdocumentwrapper.h: Added.
        * WebCore+SVG/dom_kdomnodetreewrapper.cpp: Added.
        (DOM::KDOMNodeTreeWrapperImpl::KDOMNodeTreeWrapperImpl):
        (KDOMNodeTreeWrapperImpl::~KDOMNodeTreeWrapperImpl):
        (KDOMNodeTreeWrapperImpl::attach):
        (KDOMNodeTreeWrapperImpl::createRenderer):
        * WebCore+SVG/dom_kdomnodetreewrapper.h: Added.
        * WebCore+SVG/render_kcanvaswrapper.cpp: Added.
        (RenderKCanvasWrapper::RenderKCanvasWrapper):
        (RenderKCanvasWrapper::~RenderKCanvasWrapper):
        (RenderKCanvasWrapper::layout):
        (RenderKCanvasWrapper::paint):
        (RenderKCanvasWrapper::intrinsicWidth):
        (RenderKCanvasWrapper::intrinsicHeight):
        * WebCore+SVG/render_kcanvaswrapper.h: Added.
        (khtml::RenderKCanvasWrapper::renderName):
        (khtml::RenderKCanvasWrapper::setCanvas):
        * WebCore+SVG/xml_kdomtokenizer.cpp: Added.
        (KDOMTokenizer::KDOMTokenizer):
        (KDOMTokenizer::~KDOMTokenizer):
        (KDOMTokenizer::documentWrapper):
        (KDOMTokenizer::write):
        (KDOMTokenizer::setOnHold):
        (KDOMTokenizer::finish):
        (KDOMTokenizer::isWaitingForScripts):
        (khtml::newKDOMTokenizer):
        * WebCore+SVG/xml_kdomtokenizer.h: Added.
        * WebCore.xcodeproj/project.pbxproj:
        * khtml/khtml_part.cpp:
        (KHTMLPart::begin):
        * khtml/xml/dom_docimpl.cpp:
        (DOMImplementationImpl::createKDOMDocument):
        * khtml/xml/dom_docimpl.h:
        * kwq/KWQPainter.h:
        * kwq/KWQPainter.mm:
        (QPainterPrivate::QPainterPrivate):
        (QPainterPrivate::~QPainterPrivate):
        (QPainter::renderingDeviceContext):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@10600 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0ab7b180
2005-09-22 Eric Seidel <eseidel@apple.com>
Reviewed by hyatt.
Added KDOM and KCanvas wrapper objects for the WebCore DOM
and WebCore render tree. This allows using SVG in any
WebKit app, including Safari.
Also added extensions to QPainter to return a
KRenderingDeviceContext object to be passed into KCanvas.
http://bugzilla.opendarwin.org/show_bug.cgi?id=5003
* WebCore+SVG/dom_kdomdocumentwrapper.cpp: Added.
(KDOMDocumentWrapperImpl::renderingDevice):
(KDOMDocumentWrapperImpl::KDOMDocumentWrapperImpl):
(KDOMDocumentWrapperImpl::~KDOMDocumentWrapperImpl):
(DOM::KDOMDocumentWrapperImpl::createTokenizer):
(KDOMDocumentWrapperImpl::svgView):
* WebCore+SVG/dom_kdomdocumentwrapper.h: Added.
* WebCore+SVG/dom_kdomnodetreewrapper.cpp: Added.
(DOM::KDOMNodeTreeWrapperImpl::KDOMNodeTreeWrapperImpl):
(KDOMNodeTreeWrapperImpl::~KDOMNodeTreeWrapperImpl):
(KDOMNodeTreeWrapperImpl::attach):
(KDOMNodeTreeWrapperImpl::createRenderer):
* WebCore+SVG/dom_kdomnodetreewrapper.h: Added.
* WebCore+SVG/render_kcanvaswrapper.cpp: Added.
(RenderKCanvasWrapper::RenderKCanvasWrapper):
(RenderKCanvasWrapper::~RenderKCanvasWrapper):
(RenderKCanvasWrapper::layout):
(RenderKCanvasWrapper::paint):
(RenderKCanvasWrapper::intrinsicWidth):
(RenderKCanvasWrapper::intrinsicHeight):
* WebCore+SVG/render_kcanvaswrapper.h: Added.
(khtml::RenderKCanvasWrapper::renderName):
(khtml::RenderKCanvasWrapper::setCanvas):
* WebCore+SVG/xml_kdomtokenizer.cpp: Added.
(KDOMTokenizer::KDOMTokenizer):
(KDOMTokenizer::~KDOMTokenizer):
(KDOMTokenizer::documentWrapper):
(KDOMTokenizer::write):
(KDOMTokenizer::setOnHold):
(KDOMTokenizer::finish):
(KDOMTokenizer::isWaitingForScripts):
(khtml::newKDOMTokenizer):
* WebCore+SVG/xml_kdomtokenizer.h: Added.
* WebCore.xcodeproj/project.pbxproj:
* khtml/khtml_part.cpp:
(KHTMLPart::begin):
* khtml/xml/dom_docimpl.cpp:
(DOMImplementationImpl::createKDOMDocument):
* khtml/xml/dom_docimpl.h:
* kwq/KWQPainter.h:
* kwq/KWQPainter.mm:
(QPainterPrivate::QPainterPrivate):
(QPainterPrivate::~QPainterPrivate):
(QPainter::renderingDeviceContext):
2005-09-22 Darin Adler <darin@apple.com>
Reviewed by Geoff.
......
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "dom_kdomdocumentwrapper.h"
#include "xml_kdomtokenizer.h"
#include "KWQKSVGView.h"
#include "KWQKSVGPart.h"
#include "kcanvas/KCanvas.h"
#include "kcanvas/device/quartz/KRenderingDeviceQuartz.h"
using namespace khtml;
using namespace DOM;
KRenderingDeviceQuartz *KDOMDocumentWrapperImpl::renderingDevice()
{
static KRenderingDeviceQuartz *__quartzRenderingDevice = nil;
if (!__quartzRenderingDevice)
__quartzRenderingDevice = new KRenderingDeviceQuartz();
return __quartzRenderingDevice;
}
KDOMDocumentWrapperImpl::KDOMDocumentWrapperImpl(DOMImplementationImpl *i, KHTMLView *v) : DocumentImpl(i,v)
{
m_svgPart = new KSVG::KSVGPart();
m_canvas = new KCanvas(KDOMDocumentWrapperImpl::renderingDevice());
svgView()->canvasView()->init(m_canvas, NULL);
m_canvas->addView(svgView()->canvasView());
}
KDOMDocumentWrapperImpl::~KDOMDocumentWrapperImpl()
{
delete m_svgPart;
delete m_canvas;
}
Tokenizer *DOM::KDOMDocumentWrapperImpl::createTokenizer()
{
return newKDOMTokenizer(docPtr(), m_view);
}
KSVG::KSVGView *KDOMDocumentWrapperImpl::svgView()
{
return m_svgPart ? static_cast<KSVG::KSVGView *>(m_svgPart->view()) : NULL;
}
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _DOM_KDOMDocumentWrapperImpl_h
#define _DOM_KDOMDocumentWrapperImpl_h
#include "khtml/xml/dom_docimpl.h"
class KCanvas;
class KRenderingDeviceQuartz;
namespace KSVG {
class KSVGPart;
class KSVGView;
}
namespace DOM {
class KDOMDocumentWrapperImpl : public DocumentImpl
{
public:
KDOMDocumentWrapperImpl(DOMImplementationImpl *i, KHTMLView *v);
virtual ~KDOMDocumentWrapperImpl();
virtual khtml::Tokenizer *createTokenizer();
KSVG::KSVGView *svgView();
private:
static KRenderingDeviceQuartz *renderingDevice();
KSVG::KSVGPart *m_svgPart;
KCanvas *m_canvas;
};
}; // namespace
#endif
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "dom_kdomnodetreewrapper.h"
#include "dom_elementimpl.h"
#include "render_object.h"
#include "render_kcanvaswrapper.h"
#include "kdom/core/DocumentImpl.h"
#include "ksvg2/svg/SVGDocumentImpl.h"
using namespace khtml;
using namespace DOM;
using namespace KSVG;
DOM::KDOMNodeTreeWrapperImpl::KDOMNodeTreeWrapperImpl(DOM::DocumentPtr *doc, KDOM::DocumentImpl *wrapped) :
DOM::ElementImpl(QualifiedName("svg", "svg", "http://www.w3.org/2000/svg"), doc), m_wrappedDoc(wrapped)
{
if (m_wrappedDoc)
m_wrappedDoc->ref();
}
KDOMNodeTreeWrapperImpl::~KDOMNodeTreeWrapperImpl()
{
if (m_wrappedDoc)
m_wrappedDoc->deref();
}
void KDOMNodeTreeWrapperImpl::attach()
{
ElementImpl::attach();
if (renderer()) {
RenderKCanvasWrapper *canvasWrapper = static_cast<RenderKCanvasWrapper*>(renderer());
SVGDocumentImpl *svgDoc = static_cast<KSVG::SVGDocumentImpl *>(m_wrappedDoc);
canvasWrapper->setCanvas(svgDoc->canvas());
}
}
RenderObject *KDOMNodeTreeWrapperImpl::createRenderer(RenderArena *arena, RenderStyle *style)
{
return new (arena) RenderKCanvasWrapper(this);
}
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _DOM_KDOMNodeTreeWrapperImpl_h
#define _DOM_KDOMNodeTreeWrapperImpl_h
#include "dom_elementimpl.h"
class RenderArena;
namespace khtml {
class RenderObject;
class RenderStyle;
}
namespace KDOM {
class DocumentImpl;
};
namespace DOM {
class KDOMNodeTreeWrapperImpl : public ElementImpl
{
public:
KDOMNodeTreeWrapperImpl(DocumentPtr *doc, KDOM::DocumentImpl *wrapped);
virtual ~KDOMNodeTreeWrapperImpl();
virtual khtml::RenderObject *createRenderer(RenderArena *arena, khtml::RenderStyle *style);
virtual void attach();
private:
KDOM::DocumentImpl *m_wrappedDoc;
};
}; // namespace
#endif
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "render_kcanvaswrapper.h"
#include "kcanvas/KCanvas.h"
#include "kcanvas/KCanvasContainer.h"
#include "kcanvas/device/KRenderingDevice.h"
using namespace khtml;
RenderKCanvasWrapper::RenderKCanvasWrapper(DOM::KDOMNodeTreeWrapperImpl *node) : RenderReplaced(node), m_canvas(0)
{
}
RenderKCanvasWrapper::~RenderKCanvasWrapper()
{
}
void RenderKCanvasWrapper::layout()
{
QSize canvasSize = m_canvas->canvasSize();
// this should go somewhere in ksvg2
if ((canvasSize == QSize(-1,-1)) && m_canvas->rootContainer()) {
QRect canvasBounds = m_canvas->rootContainer()->bbox();
canvasSize = QSize(abs(canvasBounds.x()) + canvasBounds.width(), abs(canvasBounds.y()) + canvasBounds.height());
m_canvas->setCanvasSize(canvasSize);
}
setWidth(canvasSize.width());
setHeight(canvasSize.height());
setNeedsLayout(false);
}
void RenderKCanvasWrapper::paint(PaintInfo &paintInfo, int parentX, int parentY)
{
if (paintInfo.p->paintingDisabled())
return;
if (paintInfo.phase == PaintActionBlockBackground) {
paintRootBoxDecorations(paintInfo, parentX, parentY);
return;
}
if (!RenderReplaced::shouldPaint(paintInfo, parentX, parentY) || (paintInfo.phase != PaintActionForeground))
return;
if (!m_canvas || !m_canvas->rootContainer() || !m_canvas->renderingDevice())
return;
KRenderingDevice *renderingDevice = m_canvas->renderingDevice();
renderingDevice->pushContext(paintInfo.p->renderingDeviceContext());
paintInfo.p->save();
QRect dirtyRect = paintInfo.r; //QRect([drawView mapViewRectToCanvas:dirtyViewRect]);
m_canvas->rootContainer()->draw(dirtyRect);
// restore drawing state
paintInfo.p->restore();
renderingDevice->popContext();
}
int RenderKCanvasWrapper::intrinsicWidth() const
{
return 150;
}
int RenderKCanvasWrapper::intrinsicHeight() const
{
return 150;
}
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef RENDER_KCANVASWRAPPER_H
#define RENDER_KCANVASWRAPPER_H
#include "khtml/misc/loader.h"
#include "khtml/rendering/render_replaced.h"
#include "dom_kdomnodetreewrapper.h"
class KCanvas;
namespace khtml {
class RenderKCanvasWrapper : public RenderReplaced
{
public:
RenderKCanvasWrapper(DOM::KDOMNodeTreeWrapperImpl *node);
virtual ~RenderKCanvasWrapper();
virtual const char *renderName() const { return "RenderKCanvasWrapper"; }
virtual void layout();
virtual void paint(PaintInfo &i, int _tx, int _ty);
void setCanvas(KCanvas *canvas) { m_canvas = canvas; }
int RenderKCanvasWrapper::intrinsicWidth() const;
int RenderKCanvasWrapper::intrinsicHeight() const;
private:
KCanvas *m_canvas;
};
}; // namespace
#endif
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <qstring.h>
#include "loader_client.h"
#include "khtmlview.h"
#include "dom_kdomdocumentwrapper.h"
#include "dom_kdomnodetreewrapper.h"
#include "dom_nodeimpl.h"
#include "xml_tokenizer.h"
#include "xml_kdomtokenizer.h"
#include "kdom/core/DOMConfigurationImpl.h"
#include "kdom/backends/libxml/LibXMLParser.h"
#include "kdom/core/DocumentImpl.h"
#include "ksvg2/svg/SVGDocumentImpl.h"
#include "ksvg2/misc/KSVGDocumentBuilder.h"
namespace DOM {
class KDOMDocumentWrapperImpl;
};
namespace khtml {
class TokenizerString;
class KDOMTokenizer : public Tokenizer, public CachedObjectClient
{
public:
KDOMTokenizer(DOM::DocumentPtr *, KHTMLView * = 0);
~KDOMTokenizer();
// from Tokenizer
virtual void write(const TokenizerString &str, bool);
virtual void finish();
virtual void setOnHold(bool onHold);
virtual bool isWaitingForScripts() const;
private:
DOM::KDOMDocumentWrapperImpl *documentWrapper();
DOM::DocumentPtr *m_doc;
KHTMLView *m_view;
QString m_xmlCode;
};
}; // namespace
using namespace khtml;
using namespace KSVG;
using namespace DOM;
// --------------------------------
KDOMTokenizer::KDOMTokenizer(DOM::DocumentPtr *_doc, KHTMLView *_view)
: m_doc(_doc), m_view(_view)
{
if (m_doc)
m_doc->ref();
//FIXME: KDOMTokenizer should use this in a fashion similiar to how
//HTMLTokenizer uses loadStopped, in the future.
loadStopped = false;
}
KDOMTokenizer::~KDOMTokenizer()
{
if (m_doc)
m_doc->deref();
}
KDOMDocumentWrapperImpl *KDOMTokenizer::documentWrapper()
{
return m_doc ? static_cast<KDOMDocumentWrapperImpl *>(m_doc->document()) : NULL;
}
void KDOMTokenizer::write(const TokenizerString &s, bool /*appendData*/ )
{
m_xmlCode += s.toString();
}
void KDOMTokenizer::setOnHold(bool onHold)
{
// Will we need to implement this when we do incremental XML parsing?
}
void KDOMTokenizer::finish()
{
KSVG::DocumentBuilder *builder = new KSVG::DocumentBuilder(documentWrapper()->svgView());
KDOM::LibXMLParser *parser = new KDOM::LibXMLParser(KURL());
parser->setDocumentBuilder(builder);
parser->domConfig()->setParameter(KDOM::ENTITIES.handle(), false);
parser->domConfig()->setParameter(KDOM::ELEMENT_CONTENT_WHITESPACE.handle(), false);
// Feed the parser the whole document (hack)
parser->doOneShotParse(m_xmlCode.utf8(), m_xmlCode.length());
SVGDocumentImpl *svgDoc = static_cast<SVGDocumentImpl *>(parser->document());
NodeImpl *wrappedDoc = new KDOMNodeTreeWrapperImpl(m_doc, svgDoc);
delete parser; // builder is owned (deleted) by parser
if (documentWrapper()->addChild(wrappedDoc)) {
KCanvasView *primaryView = documentWrapper()->svgView()->canvasView();
svgDoc->setCanvasView(primaryView);
if (m_view && !wrappedDoc->attached())
wrappedDoc->attach();
}
else
delete wrappedDoc;
emit finishedParsing();
}
bool KDOMTokenizer::isWaitingForScripts() const
{
return false;
}
namespace khtml {
Tokenizer *newKDOMTokenizer(DOM::DocumentPtr *d, KHTMLView *v)
{
return new KDOMTokenizer(d, v);
}
};
/*
* Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions