 Chromium Code Reviews
 Chromium Code Reviews Issue 423093014:
  [SVG2] Make transform, gradientTransform and patternTransform presentation attributes.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 423093014:
  [SVG2] Make transform, gradientTransform and patternTransform presentation attributes.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| Index: Source/core/svg/SVGPatternElement.cpp | 
| diff --git a/Source/core/svg/SVGPatternElement.cpp b/Source/core/svg/SVGPatternElement.cpp | 
| index f8cb010227b0fdbc4c012a0a1567ca7d7941c935..f93f9238aa65e513d0dbee85674d0265dd032d5d 100644 | 
| --- a/Source/core/svg/SVGPatternElement.cpp | 
| +++ b/Source/core/svg/SVGPatternElement.cpp | 
| @@ -57,6 +57,22 @@ inline SVGPatternElement::SVGPatternElement(Document& document) | 
| DEFINE_NODE_FACTORY(SVGPatternElement) | 
| +bool SVGPatternElement::isPresentationAttribute(const QualifiedName& name) const | 
| +{ | 
| + if (name == SVGNames::patternTransformAttr) | 
| + return true; | 
| + return SVGElement::isPresentationAttribute(name); | 
| +} | 
| + | 
| +void SVGPatternElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style) | 
| +{ | 
| + // Don't add invalid (empty) values to the style | 
| 
pdr.
2014/08/01 22:43:10
I don't understand this comment.
 
Erik Dahlström (inactive)
2014/08/04 13:57:57
It was a misunderstanding of the spec (this avoide
 | 
| + if (name == SVGNames::patternTransformAttr) | 
| + addPropertyToPresentationAttributeStyle(style, CSSPropertyTransform, value); | 
| + else | 
| + SVGElement::collectStyleForPresentationAttribute(name, value, style); | 
| +} | 
| + | 
| bool SVGPatternElement::isSupportedAttribute(const QualifiedName& attrName) | 
| { | 
| DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); | 
| @@ -167,10 +183,41 @@ static void setPatternAttributes(const SVGPatternElement* element, PatternAttrib | 
| if (!attributes.hasPatternContentUnits() && element->patternContentUnits()->isSpecified()) | 
| attributes.setPatternContentUnits(element->patternContentUnits()->currentValue()->enumValue()); | 
| - if (!attributes.hasPatternTransform() && element->patternTransform()->isSpecified()) { | 
| + if (!attributes.hasPatternTransform()) { | 
| AffineTransform transform; | 
| - element->patternTransform()->currentValue()->concatenate(transform); | 
| - attributes.setPatternTransform(transform); | 
| + RenderStyle* style = element->renderer() ? element->renderer()->style() : 0; | 
| + | 
| + // If CSS property was set, use that, otherwise fallback to attribute (if set). | 
| + if (style && style->hasTransform()) { | 
| + TransformationMatrix matrix; | 
| + float zoom = style->effectiveZoom(); | 
| + | 
| + // 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 = element->renderer()->objectBoundingBox(); | 
| + scaledBBox.scale(zoom); | 
| + transform.scale(1 / zoom); | 
| + style->applyTransform(matrix, scaledBBox); | 
| + matrix.scale(zoom); | 
| + } else { | 
| + style->applyTransform(matrix, element->renderer()->objectBoundingBox()); | 
| + } | 
| + | 
| + // Flatten any 3D transform. | 
| + transform = matrix.toAffineTransform(); | 
| + } else if (element->patternTransform()->isSpecified()) { | 
| + element->patternTransform()->currentValue()->concatenate(transform); | 
| + } | 
| + | 
| + if (!transform.isIdentity()) | 
| + attributes.setPatternTransform(transform); | 
| } | 
| if (!attributes.hasPatternContentElement() && ElementTraversal::firstWithin(*element)) |