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

Side by Side 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 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, 2006, 2007, 2008 Nikolas Zimmermann 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann
3 * <zimmermann@kde.org> 3 * <zimmermann@kde.org>
4 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> 4 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org>
5 * Copyright (C) 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2008 Apple Inc. All rights reserved.
6 * Copyright (C) 2008 Alp Toker <alp@atoker.com> 6 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
7 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> 7 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 animatedProperty->animationEnded(); 305 animatedProperty->animationEnded();
306 }); 306 });
307 } 307 }
308 308
309 AffineTransform SVGElement::localCoordinateSpaceTransform(CTMScope) const { 309 AffineTransform SVGElement::localCoordinateSpaceTransform(CTMScope) const {
310 // To be overriden by SVGGraphicsElement (or as special case SVGTextElement 310 // To be overriden by SVGGraphicsElement (or as special case SVGTextElement
311 // and SVGPatternElement) 311 // and SVGPatternElement)
312 return AffineTransform(); 312 return AffineTransform();
313 } 313 }
314 314
315 bool SVGElement::hasTransform(ApplyMotionTransform applyMotionTransform) const {
316 return (layoutObject() && layoutObject()->styleRef().hasTransform()) ||
317 (applyMotionTransform == IncludeMotionTransform && hasSVGRareData());
318 }
319
320 AffineTransform SVGElement::calculateTransform(
321 ApplyMotionTransform applyMotionTransform) const {
322 const ComputedStyle* style =
323 layoutObject() ? layoutObject()->style() : nullptr;
324
325 // If CSS property was set, use that, otherwise fallback to attribute (if
326 // set).
327 AffineTransform matrix;
328 if (style && style->hasTransform()) {
329 TransformationMatrix transform;
330 float zoom = style->effectiveZoom();
331
332 // SVGTextElements need special handling for the text positioning code.
333 if (isSVGTextElement(this)) {
334 // Do not take into account SVG's zoom rules, transform-origin, or
335 // percentage values.
336 style->applyTransform(
337 transform, LayoutSize(0, 0), ComputedStyle::ExcludeTransformOrigin,
338 ComputedStyle::IncludeMotionPath,
339 ComputedStyle::IncludeIndependentTransformProperties);
340 } else {
341 // CSS transforms operate with pre-scaled lengths. To make this work with
342 // SVG (which applies the zoom factor globally, at the root level) we
343 //
344 // * pre-scale the bounding box (to bring it into the same space as the
345 // other CSS values)
346 // * invert the zoom factor (to effectively compute the CSS transform
347 // under a 1.0 zoom)
348 //
349 // Note: objectBoundingBox is an emptyRect for elements like pattern or
350 // clipPath. See the "Object bounding box units" section of
351 // http://dev.w3.org/csswg/css3-transforms/
352 if (zoom != 1) {
353 FloatRect scaledBBox = layoutObject()->objectBoundingBox();
354 scaledBBox.scale(zoom);
355 transform.scale(1 / zoom);
356 style->applyTransform(
357 transform, scaledBBox, ComputedStyle::IncludeTransformOrigin,
358 ComputedStyle::IncludeMotionPath,
359 ComputedStyle::IncludeIndependentTransformProperties);
360 transform.scale(zoom);
361 } else {
362 style->applyTransform(
363 transform, layoutObject()->objectBoundingBox(),
364 ComputedStyle::IncludeTransformOrigin,
365 ComputedStyle::IncludeMotionPath,
366 ComputedStyle::IncludeIndependentTransformProperties);
367 }
368 }
369 // Flatten any 3D transform.
370 matrix = transform.toAffineTransform();
371 }
372
373 // Apply any "motion transform" contribution if requested (and existing.)
374 if (applyMotionTransform == IncludeMotionTransform && hasSVGRareData())
375 matrix.preMultiply(*svgRareData()->animateMotionTransform());
376
377 return matrix;
378 }
379
315 Node::InsertionNotificationRequest SVGElement::insertedInto( 380 Node::InsertionNotificationRequest SVGElement::insertedInto(
316 ContainerNode* rootParent) { 381 ContainerNode* rootParent) {
317 Element::insertedInto(rootParent); 382 Element::insertedInto(rootParent);
318 updateRelativeLengthsInformation(); 383 updateRelativeLengthsInformation();
319 buildPendingResourcesIfNeeded(); 384 buildPendingResourcesIfNeeded();
320 return InsertionDone; 385 return InsertionDone;
321 } 386 }
322 387
323 void SVGElement::removedFrom(ContainerNode* rootParent) { 388 void SVGElement::removedFrom(ContainerNode* rootParent) {
324 bool wasInDocument = rootParent->isConnected(); 389 bool wasInDocument = rootParent->isConnected();
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 visitor->trace(m_className); 1309 visitor->trace(m_className);
1245 Element::trace(visitor); 1310 Element::trace(visitor);
1246 } 1311 }
1247 1312
1248 const AtomicString& SVGElement::eventParameterName() { 1313 const AtomicString& SVGElement::eventParameterName() {
1249 DEFINE_STATIC_LOCAL(const AtomicString, evtString, ("evt")); 1314 DEFINE_STATIC_LOCAL(const AtomicString, evtString, ("evt"));
1250 return evtString; 1315 return evtString;
1251 } 1316 }
1252 1317
1253 } // namespace blink 1318 } // namespace blink
OLDNEW
« 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