darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 1 | /* |
zimmermann@webkit.org | 711245f | 2010-08-03 19:39:01 +0000 | [diff] [blame] | 2 | * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 | * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | */ |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 20 | |
| 21 | #include "config.h" |
weinig | 5fc44ff | 2006-10-24 21:57:42 +0000 | [diff] [blame] | 22 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 23 | #if ENABLE(SVG) |
weinig | 5fc44ff | 2006-10-24 21:57:42 +0000 | [diff] [blame] | 24 | #include "SVGStyledTransformableElement.h" |
| 25 | |
krit@webkit.org | 2b95a9a | 2010-02-08 20:30:42 +0000 | [diff] [blame] | 26 | #include "AffineTransform.h" |
eseidel | 40eb1b9 | 2006-03-25 22:20:36 +0000 | [diff] [blame] | 27 | #include "Attr.h" |
andreas.kling@nokia.com | ecf4956 | 2010-10-07 07:33:33 +0000 | [diff] [blame^] | 28 | #include "RenderSVGPath.h" |
weinig | 5fc44ff | 2006-10-24 21:57:42 +0000 | [diff] [blame] | 29 | #include "SVGDocument.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 30 | #include "SVGStyledElement.h" |
eseidel | a7f7626 | 2006-09-06 03:36:10 +0000 | [diff] [blame] | 31 | #include "SVGTransformList.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 32 | |
rwlbuis | dde95e2 | 2006-12-03 12:02:26 +0000 | [diff] [blame] | 33 | namespace WebCore { |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 34 | |
darin@apple.com | c8b8f87 | 2010-08-30 18:44:06 +0000 | [diff] [blame] | 35 | SVGStyledTransformableElement::SVGStyledTransformableElement(const QualifiedName& tagName, Document* document) |
| 36 | : SVGStyledLocatableElement(tagName, document) |
zimmermann@webkit.org | 8fc4539 | 2010-01-27 01:51:39 +0000 | [diff] [blame] | 37 | , m_transform(SVGTransformList::create(SVGNames::transformAttr)) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
simon.fraser@apple.com | 64487f9 | 2010-08-19 17:19:40 +0000 | [diff] [blame] | 41 | AffineTransform SVGStyledTransformableElement::getCTM(StyleUpdateStrategy styleUpdateStrategy) const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 42 | { |
simon.fraser@apple.com | 64487f9 | 2010-08-19 17:19:40 +0000 | [diff] [blame] | 43 | return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope, styleUpdateStrategy); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 44 | } |
| 45 | |
simon.fraser@apple.com | 64487f9 | 2010-08-19 17:19:40 +0000 | [diff] [blame] | 46 | AffineTransform SVGStyledTransformableElement::getScreenCTM(StyleUpdateStrategy styleUpdateStrategy) const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 47 | { |
simon.fraser@apple.com | 64487f9 | 2010-08-19 17:19:40 +0000 | [diff] [blame] | 48 | return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope, styleUpdateStrategy); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 49 | } |
| 50 | |
krit@webkit.org | 2b95a9a | 2010-02-08 20:30:42 +0000 | [diff] [blame] | 51 | AffineTransform SVGStyledTransformableElement::animatedLocalTransform() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 52 | { |
antti@apple.com | af57927 | 2008-04-18 07:40:17 +0000 | [diff] [blame] | 53 | return m_supplementalTransform ? transform()->concatenate().matrix() * *m_supplementalTransform : transform()->concatenate().matrix(); |
| 54 | } |
| 55 | |
krit@webkit.org | 2b95a9a | 2010-02-08 20:30:42 +0000 | [diff] [blame] | 56 | AffineTransform* SVGStyledTransformableElement::supplementalTransform() |
antti@apple.com | af57927 | 2008-04-18 07:40:17 +0000 | [diff] [blame] | 57 | { |
| 58 | if (!m_supplementalTransform) |
krit@webkit.org | 2b95a9a | 2010-02-08 20:30:42 +0000 | [diff] [blame] | 59 | m_supplementalTransform.set(new AffineTransform()); |
antti@apple.com | af57927 | 2008-04-18 07:40:17 +0000 | [diff] [blame] | 60 | return m_supplementalTransform.get(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 61 | } |
| 62 | |
weinig@apple.com | c360893 | 2010-05-19 17:48:06 +0000 | [diff] [blame] | 63 | void SVGStyledTransformableElement::parseMappedAttribute(Attribute* attr) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 64 | { |
zimmermann@webkit.org | be274bd | 2010-01-08 00:36:10 +0000 | [diff] [blame] | 65 | if (SVGTransformable::isKnownAttribute(attr->name())) { |
rwlbuis | dde95e2 | 2006-12-03 12:02:26 +0000 | [diff] [blame] | 66 | SVGTransformList* localTransforms = transformBaseValue(); |
zimmermann@webkit.org | be274bd | 2010-01-08 00:36:10 +0000 | [diff] [blame] | 67 | if (!SVGTransformable::parseTransformAttribute(localTransforms, attr->value())) { |
| 68 | ExceptionCode ec = 0; |
rwlbuis | c8a141e | 2006-12-08 08:02:35 +0000 | [diff] [blame] | 69 | localTransforms->clear(ec); |
zimmermann@webkit.org | be274bd | 2010-01-08 00:36:10 +0000 | [diff] [blame] | 70 | } |
| 71 | } else |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 72 | SVGStyledLocatableElement::parseMappedAttribute(attr); |
| 73 | } |
| 74 | |
zimmermann@webkit.org | 8fc4539 | 2010-01-27 01:51:39 +0000 | [diff] [blame] | 75 | void SVGStyledTransformableElement::synchronizeProperty(const QualifiedName& attrName) |
| 76 | { |
| 77 | SVGStyledLocatableElement::synchronizeProperty(attrName); |
| 78 | |
| 79 | if (attrName == anyQName() || SVGTransformable::isKnownAttribute(attrName)) |
| 80 | synchronizeTransform(); |
| 81 | } |
| 82 | |
zimmermann@webkit.org | 52b39ec | 2008-02-03 23:18:53 +0000 | [diff] [blame] | 83 | bool SVGStyledTransformableElement::isKnownAttribute(const QualifiedName& attrName) |
| 84 | { |
| 85 | return SVGTransformable::isKnownAttribute(attrName) || |
| 86 | SVGStyledLocatableElement::isKnownAttribute(attrName); |
| 87 | } |
| 88 | |
rwlbuis | dde95e2 | 2006-12-03 12:02:26 +0000 | [diff] [blame] | 89 | SVGElement* SVGStyledTransformableElement::nearestViewportElement() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 90 | { |
| 91 | return SVGTransformable::nearestViewportElement(this); |
| 92 | } |
| 93 | |
rwlbuis | dde95e2 | 2006-12-03 12:02:26 +0000 | [diff] [blame] | 94 | SVGElement* SVGStyledTransformableElement::farthestViewportElement() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 95 | { |
| 96 | return SVGTransformable::farthestViewportElement(this); |
| 97 | } |
| 98 | |
simon.fraser@apple.com | 64487f9 | 2010-08-19 17:19:40 +0000 | [diff] [blame] | 99 | FloatRect SVGStyledTransformableElement::getBBox(StyleUpdateStrategy styleUpdateStrategy) const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 100 | { |
simon.fraser@apple.com | 64487f9 | 2010-08-19 17:19:40 +0000 | [diff] [blame] | 101 | return SVGTransformable::getBBox(this, styleUpdateStrategy); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 102 | } |
| 103 | |
darin@apple.com | faced26 | 2009-01-12 07:44:27 +0000 | [diff] [blame] | 104 | RenderObject* SVGStyledTransformableElement::createRenderer(RenderArena* arena, RenderStyle*) |
oliver | 09e98ea | 2007-10-12 15:38:34 +0000 | [diff] [blame] | 105 | { |
| 106 | // By default, any subclass is expected to do path-based drawing |
andreas.kling@nokia.com | ecf4956 | 2010-10-07 07:33:33 +0000 | [diff] [blame^] | 107 | return new (arena) RenderSVGPath(this); |
oliver | 09e98ea | 2007-10-12 15:38:34 +0000 | [diff] [blame] | 108 | } |
| 109 | |
rwlbuis@webkit.org | 8f675dd | 2008-09-16 11:12:52 +0000 | [diff] [blame] | 110 | Path SVGStyledTransformableElement::toClipPath() const |
| 111 | { |
| 112 | Path pathData = toPathData(); |
| 113 | // FIXME: How do we know the element has done a layout? |
| 114 | pathData.transform(animatedLocalTransform()); |
| 115 | return pathData; |
| 116 | } |
| 117 | |
oliver | 666a58d | 2007-10-12 12:28:28 +0000 | [diff] [blame] | 118 | } |
| 119 | |
mjs | d2948ef | 2007-02-26 19:29:04 +0000 | [diff] [blame] | 120 | #endif // ENABLE(SVG) |