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

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGGraphicsElement.cpp

Issue 2478233002: Make 'transform' a presentation attribute on SVG elements (Closed)
Patch Set: Updated expectations 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 * Copyright (C) 2014 Google, Inc. 4 * Copyright (C) 2014 Google, Inc.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #include "core/svg/SVGGraphicsElement.h" 22 #include "core/svg/SVGGraphicsElement.h"
23 23
24 #include "core/SVGNames.h" 24 #include "core/SVGNames.h"
25 #include "core/layout/svg/LayoutSVGPath.h" 25 #include "core/dom/StyleChangeReason.h"
26 #include "core/layout/LayoutObject.h"
26 #include "core/svg/SVGElementRareData.h" 27 #include "core/svg/SVGElementRareData.h"
27 #include "core/svg/SVGMatrixTearOff.h" 28 #include "core/svg/SVGMatrixTearOff.h"
28 #include "core/svg/SVGRectTearOff.h" 29 #include "core/svg/SVGRectTearOff.h"
29 #include "platform/transforms/AffineTransform.h" 30 #include "platform/transforms/AffineTransform.h"
30 31
31 namespace blink { 32 namespace blink {
32 33
33 SVGGraphicsElement::SVGGraphicsElement(const QualifiedName& tagName, 34 SVGGraphicsElement::SVGGraphicsElement(const QualifiedName& tagName,
34 Document& document, 35 Document& document,
35 ConstructionType constructionType) 36 ConstructionType constructionType)
36 : SVGElement(tagName, document, constructionType), 37 : SVGElement(tagName, document, constructionType),
37 SVGTests(this), 38 SVGTests(this),
38 m_transform( 39 m_transform(SVGAnimatedTransformList::create(this,
39 SVGAnimatedTransformList::create(this, SVGNames::transformAttr)) { 40 SVGNames::transformAttr,
41 CSSPropertyTransform)) {
40 addToPropertyMap(m_transform); 42 addToPropertyMap(m_transform);
41 } 43 }
42 44
43 SVGGraphicsElement::~SVGGraphicsElement() {} 45 SVGGraphicsElement::~SVGGraphicsElement() {}
44 46
45 DEFINE_TRACE(SVGGraphicsElement) { 47 DEFINE_TRACE(SVGGraphicsElement) {
46 visitor->trace(m_transform); 48 visitor->trace(m_transform);
47 SVGElement::trace(visitor); 49 SVGElement::trace(visitor);
48 SVGTests::trace(visitor); 50 SVGTests::trace(visitor);
49 } 51 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 103 }
102 104
103 SVGMatrixTearOff* SVGGraphicsElement::getCTMFromJavascript() { 105 SVGMatrixTearOff* SVGGraphicsElement::getCTMFromJavascript() {
104 return SVGMatrixTearOff::create(getCTM()); 106 return SVGMatrixTearOff::create(getCTM());
105 } 107 }
106 108
107 SVGMatrixTearOff* SVGGraphicsElement::getScreenCTMFromJavascript() { 109 SVGMatrixTearOff* SVGGraphicsElement::getScreenCTMFromJavascript() {
108 return SVGMatrixTearOff::create(getScreenCTM()); 110 return SVGMatrixTearOff::create(getScreenCTM());
109 } 111 }
110 112
113 void SVGGraphicsElement::collectStyleForPresentationAttribute(
114 const QualifiedName& name,
115 const AtomicString& value,
116 MutableStylePropertySet* style) {
117 if (name == SVGNames::transformAttr) {
118 addPropertyToPresentationAttributeStyle(
119 style, CSSPropertyTransform, m_transform->currentValue()->cssValue());
120 return;
121 }
122 SVGElement::collectStyleForPresentationAttribute(name, value, style);
123 }
124
111 bool SVGGraphicsElement::hasAnimatedLocalTransform() const { 125 bool SVGGraphicsElement::hasAnimatedLocalTransform() const {
112 const ComputedStyle* style =
113 layoutObject() ? layoutObject()->style() : nullptr;
114
115 // Each of these is used in 126 // Each of these is used in
116 // SVGGraphicsElement::calculateAnimatedLocalTransform to create an animated 127 // SVGGraphicsElement::calculateAnimatedLocalTransform to create an animated
117 // local transform. 128 // local transform.
118 return (style && style->hasTransform()) || 129 return hasTransform() || hasSVGRareData();
119 !m_transform->currentValue()->isEmpty() || hasSVGRareData();
120 } 130 }
121 131
122 AffineTransform SVGGraphicsElement::calculateAnimatedLocalTransform() const { 132 AffineTransform SVGGraphicsElement::calculateAnimatedLocalTransform() const {
123 AffineTransform matrix; 133 AffineTransform matrix = calculateTransform();
124 const ComputedStyle* style =
125 layoutObject() ? layoutObject()->style() : nullptr;
126
127 // If CSS property was set, use that, otherwise fallback to attribute (if
128 // set).
129 if (style && style->hasTransform()) {
130 TransformationMatrix transform;
131 float zoom = style->effectiveZoom();
132
133 // SVGTextElements need special handling for the text positioning code.
134 if (isSVGTextElement(this)) {
135 // Do not take into account SVG's zoom rules, transform-origin, or
136 // percentage values.
137 style->applyTransform(
138 transform, LayoutSize(0, 0), ComputedStyle::ExcludeTransformOrigin,
139 ComputedStyle::IncludeMotionPath,
140 ComputedStyle::IncludeIndependentTransformProperties);
141 } else {
142 // CSS transforms operate with pre-scaled lengths. To make this work with
143 // SVG (which applies the zoom factor globally, at the root level) we
144 //
145 // * pre-scale the bounding box (to bring it into the same space as the
146 // other CSS values)
147 // * invert the zoom factor (to effectively compute the CSS transform
148 // under a 1.0 zoom)
149 //
150 // Note: objectBoundingBox is an emptyRect for elements like pattern or
151 // clipPath. See the "Object bounding box units" section of
152 // http://dev.w3.org/csswg/css3-transforms/
153 if (zoom != 1) {
154 FloatRect scaledBBox = layoutObject()->objectBoundingBox();
155 scaledBBox.scale(zoom);
156 transform.scale(1 / zoom);
157 style->applyTransform(
158 transform, scaledBBox, ComputedStyle::IncludeTransformOrigin,
159 ComputedStyle::IncludeMotionPath,
160 ComputedStyle::IncludeIndependentTransformProperties);
161 transform.scale(zoom);
162 } else {
163 style->applyTransform(
164 transform, layoutObject()->objectBoundingBox(),
165 ComputedStyle::IncludeTransformOrigin,
166 ComputedStyle::IncludeMotionPath,
167 ComputedStyle::IncludeIndependentTransformProperties);
168 }
169 }
170
171 // Flatten any 3D transform.
172 matrix = transform.toAffineTransform();
173 } else {
174 m_transform->currentValue()->concatenate(matrix);
175 }
176
177 if (hasSVGRareData()) 134 if (hasSVGRareData())
178 return *svgRareData()->animateMotionTransform() * matrix; 135 matrix.preMultiply(*svgRareData()->animateMotionTransform());
179 return matrix; 136 return matrix;
180 } 137 }
181 138
182 AffineTransform* SVGGraphicsElement::animateMotionTransform() { 139 AffineTransform* SVGGraphicsElement::animateMotionTransform() {
183 return ensureSVGRareData()->animateMotionTransform(); 140 return ensureSVGRareData()->animateMotionTransform();
184 } 141 }
185 142
186 void SVGGraphicsElement::svgAttributeChanged(const QualifiedName& attrName) { 143 void SVGGraphicsElement::svgAttributeChanged(const QualifiedName& attrName) {
187 // Reattach so the isValid() check will be run again during layoutObject 144 // Reattach so the isValid() check will be run again during layoutObject
188 // creation. 145 // creation.
189 if (SVGTests::isKnownAttribute(attrName)) { 146 if (SVGTests::isKnownAttribute(attrName)) {
190 SVGElement::InvalidationGuard invalidationGuard(this); 147 SVGElement::InvalidationGuard invalidationGuard(this);
191 lazyReattachIfAttached(); 148 lazyReattachIfAttached();
192 return; 149 return;
193 } 150 }
194 151
195 if (attrName == SVGNames::transformAttr) { 152 if (attrName == SVGNames::transformAttr) {
196 LayoutObject* object = layoutObject(); 153 LayoutObject* object = layoutObject();
197 if (!object) 154 if (!object)
198 return; 155 return;
199 156
157 invalidateSVGPresentationAttributeStyle();
158
200 SVGElement::InvalidationGuard invalidationGuard(this); 159 SVGElement::InvalidationGuard invalidationGuard(this);
201 object->setNeedsTransformUpdate(); 160 // TODO(fs): The InvalidationGuard will make sure all instances are
161 // invalidated, but the style recalc will propagate to instances too. So
162 // there is some redundant operations being performed here. Could we get
163 // away with removing the InvalidationGuard?
164 setNeedsStyleRecalc(LocalStyleChange,
165 StyleChangeReasonForTracing::fromAttribute(attrName));
202 markForLayoutAndParentResourceInvalidation(object); 166 markForLayoutAndParentResourceInvalidation(object);
203 return; 167 return;
204 } 168 }
205 169
206 SVGElement::svgAttributeChanged(attrName); 170 SVGElement::svgAttributeChanged(attrName);
207 } 171 }
208 172
209 SVGElement* SVGGraphicsElement::nearestViewportElement() const { 173 SVGElement* SVGGraphicsElement::nearestViewportElement() const {
210 for (Element* current = parentOrShadowHostElement(); current; 174 for (Element* current = parentOrShadowHostElement(); current;
211 current = current->parentOrShadowHostElement()) { 175 current = current->parentOrShadowHostElement()) {
(...skipping 23 matching lines...) Expand all
235 199
236 return layoutObject()->objectBoundingBox(); 200 return layoutObject()->objectBoundingBox();
237 } 201 }
238 202
239 SVGRectTearOff* SVGGraphicsElement::getBBoxFromJavascript() { 203 SVGRectTearOff* SVGGraphicsElement::getBBoxFromJavascript() {
240 return SVGRectTearOff::create(SVGRect::create(getBBox()), 0, 204 return SVGRectTearOff::create(SVGRect::create(getBBox()), 0,
241 PropertyIsNotAnimVal); 205 PropertyIsNotAnimVal);
242 } 206 }
243 207
244 } // namespace blink 208 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698