summaryrefslogtreecommitdiff
path: root/Source/WebCore/svg/SVGLocatable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/svg/SVGLocatable.cpp')
-rw-r--r--Source/WebCore/svg/SVGLocatable.cpp36
1 files changed, 16 insertions, 20 deletions
diff --git a/Source/WebCore/svg/SVGLocatable.cpp b/Source/WebCore/svg/SVGLocatable.cpp
index cad52c884..b7fab2d32 100644
--- a/Source/WebCore/svg/SVGLocatable.cpp
+++ b/Source/WebCore/svg/SVGLocatable.cpp
@@ -21,14 +21,13 @@
*/
#include "config.h"
-
-#if ENABLE(SVG)
#include "SVGLocatable.h"
#include "RenderElement.h"
#include "SVGException.h"
#include "SVGGraphicsElement.h"
#include "SVGImageElement.h"
+#include "SVGMatrix.h"
#include "SVGNames.h"
namespace WebCore {
@@ -38,7 +37,7 @@ static bool isViewportElement(Node* node)
return (node->hasTagName(SVGNames::svgTag)
|| node->hasTagName(SVGNames::symbolTag)
|| node->hasTagName(SVGNames::foreignObjectTag)
- || isSVGImageElement(node));
+ || is<SVGImageElement>(*node));
}
SVGElement* SVGLocatable::nearestViewportElement(const SVGElement* element)
@@ -46,19 +45,19 @@ SVGElement* SVGLocatable::nearestViewportElement(const SVGElement* element)
ASSERT(element);
for (Element* current = element->parentOrShadowHostElement(); current; current = current->parentOrShadowHostElement()) {
if (isViewportElement(current))
- return toSVGElement(current);
+ return downcast<SVGElement>(current);
}
- return 0;
+ return nullptr;
}
SVGElement* SVGLocatable::farthestViewportElement(const SVGElement* element)
{
ASSERT(element);
- SVGElement* farthest = 0;
+ SVGElement* farthest = nullptr;
for (Element* current = element->parentOrShadowHostElement(); current; current = current->parentOrShadowHostElement()) {
if (isViewportElement(current))
- farthest = toSVGElement(current);
+ farthest = downcast<SVGElement>(current);
}
return farthest;
}
@@ -84,12 +83,12 @@ AffineTransform SVGLocatable::computeCTM(SVGElement* element, CTMScope mode, Sty
AffineTransform ctm;
- SVGElement* stopAtElement = mode == NearestViewportScope ? nearestViewportElement(element) : 0;
+ SVGElement* stopAtElement = mode == NearestViewportScope ? nearestViewportElement(element) : nullptr;
for (Element* currentElement = element; currentElement; currentElement = currentElement->parentOrShadowHostElement()) {
if (!currentElement->isSVGElement())
break;
- ctm = toSVGElement(currentElement)->localCoordinateSpaceTransform(mode).multiply(ctm);
+ ctm = downcast<SVGElement>(*currentElement).localCoordinateSpaceTransform(mode).multiply(ctm);
// For getCTM() computation, stop at the nearest viewport element
if (currentElement == stopAtElement)
@@ -99,22 +98,19 @@ AffineTransform SVGLocatable::computeCTM(SVGElement* element, CTMScope mode, Sty
return ctm;
}
-AffineTransform SVGLocatable::getTransformToElement(SVGElement* target, ExceptionCode& ec, StyleUpdateStrategy styleUpdateStrategy)
+ExceptionOr<Ref<SVGMatrix>> SVGLocatable::getTransformToElement(SVGElement* target, StyleUpdateStrategy styleUpdateStrategy)
{
AffineTransform ctm = getCTM(styleUpdateStrategy);
- if (target && target->isSVGGraphicsElement()) {
- AffineTransform targetCTM = toSVGGraphicsElement(target)->getCTM(styleUpdateStrategy);
- if (!targetCTM.isInvertible()) {
- ec = SVGException::SVG_MATRIX_NOT_INVERTABLE;
- return ctm;
- }
- ctm = targetCTM.inverse() * ctm;
+ if (is<SVGGraphicsElement>(target)) {
+ AffineTransform targetCTM = downcast<SVGGraphicsElement>(*target).getCTM(styleUpdateStrategy);
+ if (auto inverse = targetCTM.inverse())
+ ctm = inverse.value() * ctm;
+ else
+ return Exception { SVGException::SVG_MATRIX_NOT_INVERTABLE };
}
- return ctm;
+ return SVGMatrix::create(ctm);
}
}
-
-#endif // ENABLE(SVG)