#include "config.h"
#if ENABLE(SVG)
#include "SVGLocatable.h"
#include "AffineTransform.h"
#include "RenderPath.h"
#include "SVGException.h"
#include "SVGSVGElement.h"
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)
#if ENABLE(SVG_EXPERIMENTAL_FEATURES)
|| n->hasTagName(SVGNames::foreignObjectTag)
#endif
)
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)
#if ENABLE(SVG_EXPERIMENTAL_FEATURES)
|| n->hasTagName(SVGNames::foreignObjectTag)
#endif
)
farthest = static_cast<SVGElement*>(n);
n = n->parentNode();
}
return farthest;
}
FloatRect SVGLocatable::getBBox(const SVGStyledElement* e)
{
FloatRect bboxRect;
if (e && e->renderer()) {
e->document()->updateLayoutIgnorePendingStylesheets();
bboxRect = e->renderer()->relativeBBox(false);
}
return bboxRect;
}
AffineTransform SVGLocatable::getCTM(const SVGElement* element)
{
if (!element)
return AffineTransform();
AffineTransform ctm;
Node* parent = element->parentNode();
if (parent && parent->isElementNode()) {
SVGElement* parentElement = svg_dynamic_cast(parent);
if (parentElement && parentElement->isStyledLocatable()) {
AffineTransform parentCTM = static_cast<SVGStyledLocatableElement*>(parentElement)->getCTM();
ctm = parentCTM * ctm;
}
}
return ctm;
}
AffineTransform SVGLocatable::getScreenCTM(const SVGElement* element)
{
if (!element)
return AffineTransform();
AffineTransform ctm;
Node* parent = element->parentNode();
if (parent && parent->isElementNode()) {
SVGElement* parentElement = svg_dynamic_cast(parent);
if (parentElement && parentElement->isStyledLocatable()) {
AffineTransform parentCTM = static_cast<SVGStyledLocatableElement*>(parentElement)->getScreenCTM();
ctm = parentCTM * ctm;
}
}
return ctm;
}
AffineTransform SVGLocatable::getTransformToElement(SVGElement* target, ExceptionCode& ec) const
{
AffineTransform ctm = getCTM();
SVGElement* targetElement = svg_dynamic_cast(target);
if (targetElement && targetElement->isStyledLocatable()) {
AffineTransform targetCTM = static_cast<SVGStyledLocatableElement*>(targetElement)->getCTM();
if (!targetCTM.isInvertible()) {
ec = SVG_MATRIX_NOT_INVERTABLE;
return ctm;
}
ctm *= targetCTM.inverse();
}
return ctm;
}
}
#endif // ENABLE(SVG)