This source file includes following definitions.
- m_didTransformToRootUpdate
- hasValidPredecessor
- isChildAllowed
- calculateLocalTransform
#include "config.h"
#include "core/rendering/svg/RenderSVGTransformableContainer.h"
#include "SVGNames.h"
#include "core/rendering/svg/SVGRenderSupport.h"
#include "core/svg/SVGGraphicsElement.h"
#include "core/svg/SVGUseElement.h"
namespace WebCore {
RenderSVGTransformableContainer::RenderSVGTransformableContainer(SVGGraphicsElement* node)
: RenderSVGContainer(node)
, m_needsTransformUpdate(true)
, m_didTransformToRootUpdate(false)
{
}
static bool hasValidPredecessor(const Node* node)
{
ASSERT(node);
while ((node = node->previousSibling())) {
if (node->isSVGElement() && toSVGElement(node)->isValid())
return true;
}
return false;
}
bool RenderSVGTransformableContainer::isChildAllowed(RenderObject* child, RenderStyle* style) const
{
ASSERT(element());
if (isSVGSwitchElement(*element())) {
Node* node = child->node();
if (!node->isSVGElement() || !toSVGElement(node)->isValid())
return false;
if (hasValidPredecessor(node))
return false;
} else if (isSVGAElement(*element())) {
if (isSVGAElement(*child->node()))
return false;
if (parent() && parent()->isSVG())
return parent()->isChildAllowed(child, style);
}
return RenderSVGContainer::isChildAllowed(child, style);
}
bool RenderSVGTransformableContainer::calculateLocalTransform()
{
SVGGraphicsElement* element = toSVGGraphicsElement(this->element());
ASSERT(element);
SVGUseElement* useElement = 0;
if (isSVGUseElement(*element)) {
useElement = toSVGUseElement(element);
} else if (element->isInShadowTree() && isSVGGElement(*element)) {
SVGElement* correspondingElement = element->correspondingElement();
if (isSVGUseElement(correspondingElement))
useElement = toSVGUseElement(correspondingElement);
}
if (useElement) {
SVGLengthContext lengthContext(useElement);
FloatSize translation(
useElement->x()->currentValue()->value(lengthContext),
useElement->y()->currentValue()->value(lengthContext));
if (translation != m_lastTranslation)
m_needsTransformUpdate = true;
m_lastTranslation = translation;
}
m_didTransformToRootUpdate = m_needsTransformUpdate || SVGRenderSupport::transformToRootChanged(parent());
if (!m_needsTransformUpdate)
return false;
m_localTransform = element->animatedLocalTransform();
m_localTransform.translate(m_lastTranslation.width(), m_lastTranslation.height());
m_needsTransformUpdate = false;
return true;
}
}