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

Side by Side Diff: Source/core/svg/SVGTextElement.cpp

Issue 18503004: Have SVGTextContentElement inherit SVGGraphicsElement (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Really remove SVGLocatable IDL interface Created 7 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/svg/SVGTextElement.h ('k') | Source/core/svg/SVGTextElement.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 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 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, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 22
23 #include "core/svg/SVGTextElement.h" 23 #include "core/svg/SVGTextElement.h"
24 24
25 #include "SVGNames.h" 25 #include "SVGNames.h"
26 #include "core/dom/NodeRenderingContext.h" 26 #include "core/dom/NodeRenderingContext.h"
27 #include "core/platform/graphics/FloatRect.h"
28 #include "core/platform/graphics/transforms/AffineTransform.h"
29 #include "core/rendering/svg/RenderSVGResource.h" 27 #include "core/rendering/svg/RenderSVGResource.h"
30 #include "core/rendering/svg/RenderSVGText.h" 28 #include "core/rendering/svg/RenderSVGText.h"
31 #include "core/svg/SVGElementInstance.h" 29 #include "core/svg/SVGElementInstance.h"
32 30
33 namespace WebCore { 31 namespace WebCore {
34 32
35 // Animated property definitions
36 DEFINE_ANIMATED_TRANSFORM_LIST(SVGTextElement, SVGNames::transformAttr, Transfor m, transform)
37
38 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGTextElement)
39 REGISTER_LOCAL_ANIMATED_PROPERTY(transform)
40 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTextPositioningElement)
41 END_REGISTER_ANIMATED_PROPERTIES
42
43 inline SVGTextElement::SVGTextElement(const QualifiedName& tagName, Document* do c) 33 inline SVGTextElement::SVGTextElement(const QualifiedName& tagName, Document* do c)
44 : SVGTextPositioningElement(tagName, doc) 34 : SVGTextPositioningElement(tagName, doc)
45 { 35 {
46 ASSERT(hasTagName(SVGNames::textTag)); 36 ASSERT(hasTagName(SVGNames::textTag));
47 ScriptWrappable::init(this); 37 ScriptWrappable::init(this);
48 registerAnimatedPropertiesForSVGTextElement();
49 } 38 }
50 39
51 PassRefPtr<SVGTextElement> SVGTextElement::create(const QualifiedName& tagName, Document* document) 40 PassRefPtr<SVGTextElement> SVGTextElement::create(const QualifiedName& tagName, Document* document)
52 { 41 {
53 return adoptRef(new SVGTextElement(tagName, document)); 42 return adoptRef(new SVGTextElement(tagName, document));
54 } 43 }
55 44
56 bool SVGTextElement::isSupportedAttribute(const QualifiedName& attrName) 45 // We override SVGGraphics::animatedLocalTransform() so that the transform-origi n
57 { 46 // is not taken into account.
58 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
59 if (supportedAttributes.isEmpty())
60 supportedAttributes.add(SVGNames::transformAttr);
61 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
62 }
63
64 void SVGTextElement::parseAttribute(const QualifiedName& name, const AtomicStrin g& value)
65 {
66 if (!isSupportedAttribute(name)) {
67 SVGTextPositioningElement::parseAttribute(name, value);
68 return;
69 }
70
71 if (name == SVGNames::transformAttr) {
72 SVGTransformList newList;
73 newList.parse(value);
74 detachAnimatedTransformListWrappers(newList.size());
75 setTransformBaseValue(newList);
76 return;
77 }
78
79 ASSERT_NOT_REACHED();
80 }
81
82 SVGElement* SVGTextElement::nearestViewportElement() const
83 {
84 return SVGTransformable::nearestViewportElement(this);
85 }
86
87 SVGElement* SVGTextElement::farthestViewportElement() const
88 {
89 return SVGTransformable::farthestViewportElement(this);
90 }
91
92 FloatRect SVGTextElement::getBBox(StyleUpdateStrategy styleUpdateStrategy)
93 {
94 return SVGTransformable::getBBox(this, styleUpdateStrategy);
95 }
96
97 AffineTransform SVGTextElement::getCTM(StyleUpdateStrategy styleUpdateStrategy)
98 {
99 return SVGLocatable::computeCTM(this, SVGLocatable::NearestViewportScope, st yleUpdateStrategy);
100 }
101
102 AffineTransform SVGTextElement::getScreenCTM(StyleUpdateStrategy styleUpdateStra tegy)
103 {
104 return SVGLocatable::computeCTM(this, SVGLocatable::ScreenScope, styleUpdate Strategy);
105 }
106
107 AffineTransform SVGTextElement::animatedLocalTransform() const 47 AffineTransform SVGTextElement::animatedLocalTransform() const
108 { 48 {
109 AffineTransform matrix; 49 AffineTransform matrix;
110 RenderStyle* style = renderer() ? renderer()->style() : 0; 50 RenderStyle* style = renderer() ? renderer()->style() : 0;
111 51
112 // if CSS property was set, use that, otherwise fallback to attribute (if se t) 52 // if CSS property was set, use that, otherwise fallback to attribute (if se t)
113 if (style && style->hasTransform()) { 53 if (style && style->hasTransform()) {
114 TransformationMatrix t; 54 TransformationMatrix t;
115 // For now, the transform-origin is not taken into account 55 // For now, the transform-origin is not taken into account
116 // Also, any percentage values will not be taken into account 56 // Also, any percentage values will not be taken into account
117 style->applyTransform(t, IntSize(0, 0), RenderStyle::ExcludeTransformOri gin); 57 style->applyTransform(t, IntSize(0, 0), RenderStyle::ExcludeTransformOri gin);
118 // Flatten any 3D transform 58 // Flatten any 3D transform
119 matrix = t.toAffineTransform(); 59 matrix = t.toAffineTransform();
120 } else 60 } else
121 transform().concatenate(matrix); 61 transform().concatenate(matrix);
122 62
123 if (m_supplementalTransform) 63 const AffineTransform* transform = const_cast<SVGTextElement*>(this)->supple mentalTransform();
124 return *m_supplementalTransform * matrix; 64 if (transform)
65 return *transform * matrix;
125 return matrix; 66 return matrix;
126 } 67 }
127 68
128 AffineTransform* SVGTextElement::supplementalTransform()
129 {
130 if (!m_supplementalTransform)
131 m_supplementalTransform = adoptPtr(new AffineTransform);
132 return m_supplementalTransform.get();
133 }
134
135 RenderObject* SVGTextElement::createRenderer(RenderStyle*) 69 RenderObject* SVGTextElement::createRenderer(RenderStyle*)
136 { 70 {
137 return new (document()->renderArena()) RenderSVGText(this); 71 return new (document()->renderArena()) RenderSVGText(this);
138 } 72 }
139 73
140 bool SVGTextElement::childShouldCreateRenderer(const NodeRenderingContext& child Context) const 74 bool SVGTextElement::childShouldCreateRenderer(const NodeRenderingContext& child Context) const
141 { 75 {
142 if (childContext.node()->isTextNode() 76 if (childContext.node()->isTextNode()
143 || childContext.node()->hasTagName(SVGNames::aTag) 77 || childContext.node()->hasTagName(SVGNames::aTag)
144 #if ENABLE(SVG_FONTS) 78 #if ENABLE(SVG_FONTS)
145 || childContext.node()->hasTagName(SVGNames::altGlyphTag) 79 || childContext.node()->hasTagName(SVGNames::altGlyphTag)
146 #endif 80 #endif
147 || childContext.node()->hasTagName(SVGNames::textPathTag) 81 || childContext.node()->hasTagName(SVGNames::textPathTag)
148 || childContext.node()->hasTagName(SVGNames::trefTag) 82 || childContext.node()->hasTagName(SVGNames::trefTag)
149 || childContext.node()->hasTagName(SVGNames::tspanTag)) 83 || childContext.node()->hasTagName(SVGNames::tspanTag))
150 return true; 84 return true;
151 85
152 return false; 86 return false;
153 } 87 }
154 88
155 void SVGTextElement::svgAttributeChanged(const QualifiedName& attrName)
156 {
157 if (!isSupportedAttribute(attrName)) {
158 SVGTextPositioningElement::svgAttributeChanged(attrName);
159 return;
160 }
161
162 SVGElementInstance::InvalidationGuard invalidationGuard(this);
163
164 RenderObject* renderer = this->renderer();
165 if (!renderer)
166 return;
167
168 if (attrName == SVGNames::transformAttr) {
169 renderer->setNeedsTransformUpdate();
170 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
171 return;
172 }
173
174 ASSERT_NOT_REACHED();
175 } 89 }
176
177 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGTextElement.h ('k') | Source/core/svg/SVGTextElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698