#include "config.h"
#if SVG_SUPPORT
#include "SVGLocatable.h"
#include "SVGElement.h"
#include "SVGMatrix.h"
#include "SVGRect.h"
#include "SVGSVGElement.h"
#include <kcanvas/RenderPath.h>
using namespace WebCore;
SVGLocatable::SVGLocatable()
{
}
SVGLocatable::~SVGLocatable()
{
}
SVGElement *SVGLocatable::nearestViewportElement(const SVGStyledElement *e)
{
Node *n = e->parentNode();
while (n && !n->isDocumentNode()) {
if (n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::symbolTag) ||
n->hasTagName(SVGNames::imageTag) || n->hasTagName(SVGNames::foreignObjectTag))
return static_cast<SVGElement *>(n);
n = n->parentNode();
}
return 0;
}
SVGElement *SVGLocatable::farthestViewportElement(const SVGStyledElement *e)
{
SVGElement *farthest = 0;
Node *n = e->parentNode();
while (n && !n->isDocumentNode()) {
if (n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::symbolTag) ||
n->hasTagName(SVGNames::imageTag) || n->hasTagName(SVGNames::foreignObjectTag))
farthest = static_cast<SVGElement *>(n);
n = n->parentNode();
}
return farthest;
}
FloatRect SVGLocatable::getBBox(const SVGStyledElement *e)
{
FloatRect bboxRect;
if (e && e->renderer()) {
bboxRect = e->renderer()->relativeBBox(false);
bboxRect.setSize(bboxRect.size() - FloatSize(1, 1)); }
return bboxRect;
}
SVGMatrix *SVGLocatable::getCTM(const SVGElement *element)
{
if(!element)
return 0;
SVGMatrix *ctm = SVGSVGElement::createSVGMatrix();
Node *parent = element->parentNode();
if (parent && parent->isElementNode()) {
SVGElement *parentElement = svg_dynamic_cast(parent);
if(parentElement && parentElement->isStyledLocatable())
{
RefPtr<SVGMatrix> parentCTM = static_cast<SVGStyledLocatableElement *>(parentElement)->getCTM();
ctm->multiply(parentCTM.get());
}
}
return ctm;
}
SVGMatrix *SVGLocatable::getScreenCTM(const SVGElement *element)
{
if(!element)
return 0;
SVGMatrix *ctm = SVGSVGElement::createSVGMatrix();
Node *parent = element->parentNode();
if(parent && parent->isElementNode())
{
SVGElement *parentElement = static_cast<SVGElement *>(parent);
if(parentElement->isStyledLocatable())
{
RefPtr<SVGMatrix> parentCTM = static_cast<SVGStyledLocatableElement *>(parentElement)->getScreenCTM();
ctm->multiply(parentCTM.get());
}
}
return ctm;
}
#endif // SVG_SUPPORT