Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Unified Diff: third_party/WebKit/Source/core/svg/SVGElement.cpp

Issue 2478233002: Make 'transform' a presentation attribute on SVG elements (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 ae818a9ff5cad2d1d8c0851628b4030732c9737d..962c5b6f935bd953b76ce4fdc5d4e21a2e85c270 100644
--- a/third_party/WebKit/Source/core/svg/SVGElement.cpp
+++ b/third_party/WebKit/Source/core/svg/SVGElement.cpp
@@ -312,6 +312,71 @@ AffineTransform SVGElement::localCoordinateSpaceTransform(CTMScope) const {
return AffineTransform();
}
+bool SVGElement::hasTransform(ApplyMotionTransform applyMotionTransform) const {
+ return (layoutObject() && layoutObject()->styleRef().hasTransform()) ||
+ (applyMotionTransform == IncludeMotionTransform && hasSVGRareData());
+}
+
+AffineTransform SVGElement::calculateTransform(
+ ApplyMotionTransform applyMotionTransform) const {
+ const ComputedStyle* style =
+ layoutObject() ? layoutObject()->style() : nullptr;
+
+ // If CSS property was set, use that, otherwise fallback to attribute (if
+ // set).
+ AffineTransform matrix;
+ if (style && style->hasTransform()) {
+ 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,
+ ComputedStyle::IncludeIndependentTransformProperties);
+ }
+ }
+ // Flatten any 3D transform.
+ matrix = transform.toAffineTransform();
+ }
+
+ // Apply any "motion transform" contribution if requested (and existing.)
+ if (applyMotionTransform == IncludeMotionTransform && hasSVGRareData())
+ matrix.preMultiply(*svgRareData()->animateMotionTransform());
+
+ return matrix;
+}
+
Node::InsertionNotificationRequest SVGElement::insertedInto(
ContainerNode* rootParent) {
Element::insertedInto(rootParent);
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGElement.h ('k') | third_party/WebKit/Source/core/svg/SVGGeometryElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698