| OLD | NEW |
| 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 Loading... |
| 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 |
| 111 bool SVGGraphicsElement::hasAnimatedLocalTransform() const { | 113 void SVGGraphicsElement::collectStyleForPresentationAttribute( |
| 112 const ComputedStyle* style = | 114 const QualifiedName& name, |
| 113 layoutObject() ? layoutObject()->style() : nullptr; | 115 const AtomicString& value, |
| 114 | 116 MutableStylePropertySet* style) { |
| 115 // Each of these is used in | 117 if (name == SVGNames::transformAttr) { |
| 116 // SVGGraphicsElement::calculateAnimatedLocalTransform to create an animated | 118 addPropertyToPresentationAttributeStyle( |
| 117 // local transform. | 119 style, CSSPropertyTransform, m_transform->currentValue()->cssValue()); |
| 118 return (style && style->hasTransform()) || | 120 return; |
| 119 !m_transform->currentValue()->isEmpty() || hasSVGRareData(); | |
| 120 } | |
| 121 | |
| 122 AffineTransform SVGGraphicsElement::calculateAnimatedLocalTransform() const { | |
| 123 AffineTransform matrix; | |
| 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 } | 121 } |
| 176 | 122 SVGElement::collectStyleForPresentationAttribute(name, value, style); |
| 177 if (hasSVGRareData()) | |
| 178 return *svgRareData()->animateMotionTransform() * matrix; | |
| 179 return matrix; | |
| 180 } | 123 } |
| 181 | 124 |
| 182 AffineTransform* SVGGraphicsElement::animateMotionTransform() { | 125 AffineTransform* SVGGraphicsElement::animateMotionTransform() { |
| 183 return ensureSVGRareData()->animateMotionTransform(); | 126 return ensureSVGRareData()->animateMotionTransform(); |
| 184 } | 127 } |
| 185 | 128 |
| 186 void SVGGraphicsElement::svgAttributeChanged(const QualifiedName& attrName) { | 129 void SVGGraphicsElement::svgAttributeChanged(const QualifiedName& attrName) { |
| 187 // Reattach so the isValid() check will be run again during layoutObject | 130 // Reattach so the isValid() check will be run again during layoutObject |
| 188 // creation. | 131 // creation. |
| 189 if (SVGTests::isKnownAttribute(attrName)) { | 132 if (SVGTests::isKnownAttribute(attrName)) { |
| 190 SVGElement::InvalidationGuard invalidationGuard(this); | 133 SVGElement::InvalidationGuard invalidationGuard(this); |
| 191 lazyReattachIfAttached(); | 134 lazyReattachIfAttached(); |
| 192 return; | 135 return; |
| 193 } | 136 } |
| 194 | 137 |
| 195 if (attrName == SVGNames::transformAttr) { | 138 if (attrName == SVGNames::transformAttr) { |
| 196 LayoutObject* object = layoutObject(); | 139 LayoutObject* object = layoutObject(); |
| 197 if (!object) | 140 if (!object) |
| 198 return; | 141 return; |
| 199 | 142 |
| 143 invalidateSVGPresentationAttributeStyle(); |
| 144 |
| 200 SVGElement::InvalidationGuard invalidationGuard(this); | 145 SVGElement::InvalidationGuard invalidationGuard(this); |
| 201 object->setNeedsTransformUpdate(); | 146 // TODO(fs): The InvalidationGuard will make sure all instances are |
| 147 // invalidated, but the style recalc will propagate to instances too. So |
| 148 // there is some redundant operations being performed here. Could we get |
| 149 // away with removing the InvalidationGuard? |
| 150 setNeedsStyleRecalc(LocalStyleChange, |
| 151 StyleChangeReasonForTracing::fromAttribute(attrName)); |
| 202 markForLayoutAndParentResourceInvalidation(object); | 152 markForLayoutAndParentResourceInvalidation(object); |
| 203 return; | 153 return; |
| 204 } | 154 } |
| 205 | 155 |
| 206 SVGElement::svgAttributeChanged(attrName); | 156 SVGElement::svgAttributeChanged(attrName); |
| 207 } | 157 } |
| 208 | 158 |
| 209 SVGElement* SVGGraphicsElement::nearestViewportElement() const { | 159 SVGElement* SVGGraphicsElement::nearestViewportElement() const { |
| 210 for (Element* current = parentOrShadowHostElement(); current; | 160 for (Element* current = parentOrShadowHostElement(); current; |
| 211 current = current->parentOrShadowHostElement()) { | 161 current = current->parentOrShadowHostElement()) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 235 | 185 |
| 236 return layoutObject()->objectBoundingBox(); | 186 return layoutObject()->objectBoundingBox(); |
| 237 } | 187 } |
| 238 | 188 |
| 239 SVGRectTearOff* SVGGraphicsElement::getBBoxFromJavascript() { | 189 SVGRectTearOff* SVGGraphicsElement::getBBoxFromJavascript() { |
| 240 return SVGRectTearOff::create(SVGRect::create(getBBox()), 0, | 190 return SVGRectTearOff::create(SVGRect::create(getBBox()), 0, |
| 241 PropertyIsNotAnimVal); | 191 PropertyIsNotAnimVal); |
| 242 } | 192 } |
| 243 | 193 |
| 244 } // namespace blink | 194 } // namespace blink |
| OLD | NEW |