Index: third_party/WebKit/Source/core/svg/SVGElement.cpp |
diff --git a/third_party/WebKit/Source/core/svg/SVGElement.cpp b/third_party/WebKit/Source/core/svg/SVGElement.cpp |
index 8a440b8d22faf05b063f0b0d7fa342a015b30cbe..0c4006def10c235c98ce2c56a20aeebb3f4d8bd4 100644 |
--- a/third_party/WebKit/Source/core/svg/SVGElement.cpp |
+++ b/third_party/WebKit/Source/core/svg/SVGElement.cpp |
@@ -312,6 +312,63 @@ AffineTransform SVGElement::localCoordinateSpaceTransform(CTMScope) const { |
return AffineTransform(); |
} |
+bool SVGElement::hasTransform() const { |
+ return layoutObject() && layoutObject()->styleRef().hasTransform(); |
+} |
+ |
+AffineTransform SVGElement::calculateTransform() const { |
+ const ComputedStyle* style = |
+ layoutObject() ? layoutObject()->style() : nullptr; |
+ |
+ // If CSS property was set, use that, otherwise fallback to attribute (if |
+ // set). |
+ if (!style || !style->hasTransform()) |
+ return AffineTransform(); |
+ |
+ TransformationMatrix transform; |
+ float zoom = style->effectiveZoom(); |
+ |
+ // SVGTextElements need special handling for the text positioning code. |
+ if (isSVGTextElement(this)) { |
+ // Do not take into account SVG's zoom rules, transform-origin, or |
+ // percentage values. |
+ style->applyTransform(transform, LayoutSize(0, 0), |
+ ComputedStyle::ExcludeTransformOrigin, |
+ ComputedStyle::IncludeMotionPath, |
+ ComputedStyle::IncludeIndependentTransformProperties); |
+ } else { |
+ // CSS transforms operate with pre-scaled lengths. To make this work with |
+ // SVG (which applies the zoom factor globally, at the root level) we |
+ // |
+ // * pre-scale the bounding box (to bring it into the same space as the |
+ // other CSS values) |
+ // * invert the zoom factor (to effectively compute the CSS transform |
+ // under a 1.0 zoom) |
+ // |
+ // Note: objectBoundingBox is an emptyRect for elements like pattern or |
+ // clipPath. See the "Object bounding box units" section of |
+ // http://dev.w3.org/csswg/css3-transforms/ |
+ if (zoom != 1) { |
+ FloatRect scaledBBox = layoutObject()->objectBoundingBox(); |
+ scaledBBox.scale(zoom); |
+ transform.scale(1 / zoom); |
+ style->applyTransform( |
+ transform, scaledBBox, ComputedStyle::IncludeTransformOrigin, |
+ ComputedStyle::IncludeMotionPath, |
+ ComputedStyle::IncludeIndependentTransformProperties); |
+ transform.scale(zoom); |
+ } else { |
+ style->applyTransform( |
+ transform, layoutObject()->objectBoundingBox(), |
+ ComputedStyle::IncludeTransformOrigin, |
+ ComputedStyle::IncludeMotionPath, |
pdr.
2016/11/22 04:02:48
Does this include motion path but exclude animate
fs
2016/11/22 13:54:07
Yes, correct. (SVGGraphicsElement::calculateAnimat
|
+ ComputedStyle::IncludeIndependentTransformProperties); |
+ } |
+ } |
+ // Flatten any 3D transform. |
+ return transform.toAffineTransform(); |
+} |
+ |
Node::InsertionNotificationRequest SVGElement::insertedInto( |
ContainerNode* rootParent) { |
Element::insertedInto(rootParent); |