OLD | NEW |
---|---|
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, 2007, 2008 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007, 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, |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "bindings/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/v8/ExceptionStatePlaceholder.h" |
30 #include "core/editing/FrameSelection.h" | 30 #include "core/editing/FrameSelection.h" |
31 #include "core/frame/Frame.h" | 31 #include "core/frame/Frame.h" |
32 #include "core/rendering/RenderObject.h" | 32 #include "core/rendering/RenderObject.h" |
33 #include "core/rendering/svg/RenderSVGResource.h" | 33 #include "core/rendering/svg/RenderSVGResource.h" |
34 #include "core/rendering/svg/SVGTextQuery.h" | 34 #include "core/rendering/svg/SVGTextQuery.h" |
35 #include "core/svg/SVGElementInstance.h" | 35 #include "core/svg/SVGElementInstance.h" |
36 | 36 |
37 namespace WebCore { | 37 namespace WebCore { |
38 | 38 |
39 // Define custom animated property 'textLength'. | 39 // Animated property definitions |
40 const SVGPropertyInfo* SVGTextContentElement::textLengthPropertyInfo() | 40 |
41 { | 41 // SVGTextContentElement's 'textLength' attribute needs special handling. |
42 static const SVGPropertyInfo* s_propertyInfo = 0; | 42 // It should return getComputedTextLength() when textLength is not specified man ually. |
43 if (!s_propertyInfo) { | 43 class SVGAnimatedTextLength : public SVGAnimatedLength { |
44 s_propertyInfo = new SVGPropertyInfo(AnimatedLength, | 44 public: |
45 PropertyIsReadWrite, | 45 static PassRefPtr<SVGAnimatedTextLength> create(SVGTextContentElement* conte xtElement) |
46 SVGNames::textLengthAttr, | 46 { |
47 SVGNames::textLengthAttr.localName( ), | 47 return adoptRef(new SVGAnimatedTextLength(contextElement)); |
48 &SVGTextContentElement::synchronize TextLength, | |
49 &SVGTextContentElement::lookupOrCre ateTextLengthWrapper); | |
50 } | 48 } |
51 return s_propertyInfo; | |
52 } | |
53 | 49 |
54 // Animated property definitions | 50 virtual SVGLengthTearOff* baseVal() |
51 { | |
52 SVGTextContentElement* textContentElement = static_cast<SVGTextContentEl ement*>(contextElement()); | |
pdr.
2014/01/07 06:42:53
Please use toSVGTextContentElement instead of a st
kouhei (in TOK)
2014/01/08 08:12:07
Done.
| |
53 if (!textContentElement->textLengthIsSpecifiedByUser()) | |
54 baseValue()->newValueSpecifiedUnits(LengthTypeNumber, textContentEle ment->getComputedTextLength()); | |
55 | |
56 return SVGAnimatedLength::baseVal(); | |
57 } | |
58 | |
59 private: | |
60 SVGAnimatedTextLength(SVGTextContentElement* contextElement) | |
61 : SVGAnimatedLength(contextElement, SVGNames::textLengthAttr, SVGLength: :create(LengthModeOther)) | |
62 { | |
63 } | |
64 }; | |
65 | |
55 DEFINE_ANIMATED_ENUMERATION(SVGTextContentElement, SVGNames::lengthAdjustAttr, L engthAdjust, lengthAdjust, SVGLengthAdjustType) | 66 DEFINE_ANIMATED_ENUMERATION(SVGTextContentElement, SVGNames::lengthAdjustAttr, L engthAdjust, lengthAdjust, SVGLengthAdjustType) |
56 DEFINE_ANIMATED_BOOLEAN(SVGTextContentElement, SVGNames::externalResourcesRequir edAttr, ExternalResourcesRequired, externalResourcesRequired) | 67 DEFINE_ANIMATED_BOOLEAN(SVGTextContentElement, SVGNames::externalResourcesRequir edAttr, ExternalResourcesRequired, externalResourcesRequired) |
57 | 68 |
58 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGTextContentElement) | 69 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGTextContentElement) |
59 REGISTER_LOCAL_ANIMATED_PROPERTY(textLength) | |
60 REGISTER_LOCAL_ANIMATED_PROPERTY(lengthAdjust) | 70 REGISTER_LOCAL_ANIMATED_PROPERTY(lengthAdjust) |
61 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired) | 71 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired) |
62 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) | 72 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) |
63 END_REGISTER_ANIMATED_PROPERTIES | 73 END_REGISTER_ANIMATED_PROPERTIES |
64 | 74 |
65 SVGTextContentElement::SVGTextContentElement(const QualifiedName& tagName, Docum ent& document) | 75 SVGTextContentElement::SVGTextContentElement(const QualifiedName& tagName, Docum ent& document) |
66 : SVGGraphicsElement(tagName, document) | 76 : SVGGraphicsElement(tagName, document) |
67 , m_textLength(LengthModeOther) | 77 , m_textLength(SVGAnimatedTextLength::create(this)) |
68 , m_specifiedTextLength(LengthModeOther) | 78 , m_textLengthIsSpecifiedByUser(false) |
69 , m_lengthAdjust(SVGLengthAdjustSpacing) | 79 , m_lengthAdjust(SVGLengthAdjustSpacing) |
70 { | 80 { |
71 ScriptWrappable::init(this); | 81 ScriptWrappable::init(this); |
82 | |
83 addToPropertyMap(m_textLength); | |
72 registerAnimatedPropertiesForSVGTextContentElement(); | 84 registerAnimatedPropertiesForSVGTextContentElement(); |
73 } | 85 } |
74 | 86 |
75 void SVGTextContentElement::synchronizeTextLength(SVGElement* contextElement) | |
76 { | |
77 ASSERT(contextElement); | |
78 SVGTextContentElement* ownerType = toSVGTextContentElement(contextElement); | |
79 if (!ownerType->m_textLength.shouldSynchronize) | |
80 return; | |
81 AtomicString value(SVGPropertyTraits<SVGLength>::toString(ownerType->m_speci fiedTextLength)); | |
82 ownerType->m_textLength.synchronize(ownerType, textLengthPropertyInfo()->att ributeName, value); | |
83 } | |
84 | |
85 PassRefPtr<SVGAnimatedProperty> SVGTextContentElement::lookupOrCreateTextLengthW rapper(SVGElement* contextElement) | |
86 { | |
87 ASSERT(contextElement); | |
88 SVGTextContentElement* ownerType = toSVGTextContentElement(contextElement); | |
89 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGTextContentElement, SVG AnimatedLength, SVGLength> | |
90 (ownerType, textLengthPropertyInfo(), ownerType->m_textLength.value); | |
91 } | |
92 | |
93 PassRefPtr<SVGAnimatedLength> SVGTextContentElement::textLength() | |
94 { | |
95 DEFINE_STATIC_LOCAL(SVGLength, defaultTextLength, (LengthModeOther)); | |
96 if (m_specifiedTextLength == defaultTextLength) | |
97 m_textLength.value.newValueSpecifiedUnits(LengthTypeNumber, getComputedT extLength(), ASSERT_NO_EXCEPTION); | |
98 | |
99 m_textLength.shouldSynchronize = true; | |
100 return static_pointer_cast<SVGAnimatedLength>(lookupOrCreateTextLengthWrappe r(this)); | |
101 | |
102 } | |
103 | |
104 unsigned SVGTextContentElement::getNumberOfChars() | 87 unsigned SVGTextContentElement::getNumberOfChars() |
105 { | 88 { |
106 document().updateLayoutIgnorePendingStylesheets(); | 89 document().updateLayoutIgnorePendingStylesheets(); |
107 return SVGTextQuery(renderer()).numberOfCharacters(); | 90 return SVGTextQuery(renderer()).numberOfCharacters(); |
108 } | 91 } |
109 | 92 |
110 float SVGTextContentElement::getComputedTextLength() | 93 float SVGTextContentElement::getComputedTextLength() |
111 { | 94 { |
112 document().updateLayoutIgnorePendingStylesheets(); | 95 document().updateLayoutIgnorePendingStylesheets(); |
113 return SVGTextQuery(renderer()).textLength(); | 96 return SVGTextQuery(renderer()).textLength(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 { | 229 { |
247 SVGParsingError parseError = NoError; | 230 SVGParsingError parseError = NoError; |
248 | 231 |
249 if (!isSupportedAttribute(name)) | 232 if (!isSupportedAttribute(name)) |
250 SVGGraphicsElement::parseAttribute(name, value); | 233 SVGGraphicsElement::parseAttribute(name, value); |
251 else if (name == SVGNames::lengthAdjustAttr) { | 234 else if (name == SVGNames::lengthAdjustAttr) { |
252 SVGLengthAdjustType propertyValue = SVGPropertyTraits<SVGLengthAdjustTyp e>::fromString(value); | 235 SVGLengthAdjustType propertyValue = SVGPropertyTraits<SVGLengthAdjustTyp e>::fromString(value); |
253 if (propertyValue > 0) | 236 if (propertyValue > 0) |
254 setLengthAdjustBaseValue(propertyValue); | 237 setLengthAdjustBaseValue(propertyValue); |
255 } else if (name == SVGNames::textLengthAttr) { | 238 } else if (name == SVGNames::textLengthAttr) { |
256 m_textLength.value = SVGLength::construct(LengthModeOther, value, parseE rror, ForbidNegativeLengths); | 239 m_textLength->setBaseValueAsString(value, ForbidNegativeLengths, parseEr ror); |
240 if (parseError == NoError) | |
241 m_textLengthIsSpecifiedByUser = true; | |
257 } else if (SVGExternalResourcesRequired::parseAttribute(name, value)) { | 242 } else if (SVGExternalResourcesRequired::parseAttribute(name, value)) { |
258 } else if (name.matches(XMLNames::spaceAttr)) { | 243 } else if (name.matches(XMLNames::spaceAttr)) { |
259 } else | 244 } else |
260 ASSERT_NOT_REACHED(); | 245 ASSERT_NOT_REACHED(); |
261 | 246 |
262 reportAttributeParsingError(parseError, name, value); | 247 reportAttributeParsingError(parseError, name, value); |
263 } | 248 } |
264 | 249 |
265 void SVGTextContentElement::svgAttributeChanged(const QualifiedName& attrName) | 250 void SVGTextContentElement::svgAttributeChanged(const QualifiedName& attrName) |
266 { | 251 { |
267 if (!isSupportedAttribute(attrName)) { | 252 if (!isSupportedAttribute(attrName)) { |
268 SVGGraphicsElement::svgAttributeChanged(attrName); | 253 SVGGraphicsElement::svgAttributeChanged(attrName); |
269 return; | 254 return; |
270 } | 255 } |
271 | 256 |
257 if (attrName == SVGNames::textLengthAttr) | |
pdr.
2014/01/07 06:42:53
Isn't this handled in parseAttribute(...)?
kouhei (in TOK)
2014/01/08 08:12:07
Done. Removed flag flip in parseAttribute().
| |
258 m_textLengthIsSpecifiedByUser = true; | |
259 | |
272 SVGElementInstance::InvalidationGuard invalidationGuard(this); | 260 SVGElementInstance::InvalidationGuard invalidationGuard(this); |
273 | 261 |
274 if (attrName == SVGNames::textLengthAttr) | |
275 m_specifiedTextLength = m_textLength.value; | |
276 | |
277 if (RenderObject* renderer = this->renderer()) | 262 if (RenderObject* renderer = this->renderer()) |
278 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); | 263 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); |
279 } | 264 } |
280 | 265 |
281 bool SVGTextContentElement::selfHasRelativeLengths() const | 266 bool SVGTextContentElement::selfHasRelativeLengths() const |
282 { | 267 { |
283 // Any element of the <text> subtree is advertized as using relative lengths . | 268 // Any element of the <text> subtree is advertized as using relative lengths . |
284 // On any window size change, we have to relayout the text subtree, as the | 269 // On any window size change, we have to relayout the text subtree, as the |
285 // effective 'on-screen' font size may change. | 270 // effective 'on-screen' font size may change. |
286 return true; | 271 return true; |
(...skipping 10 matching lines...) Expand all Loading... | |
297 SVGElement* element = toSVGElement(renderer->node()); | 282 SVGElement* element = toSVGElement(renderer->node()); |
298 ASSERT(element); | 283 ASSERT(element); |
299 | 284 |
300 if (!element->isTextContent()) | 285 if (!element->isTextContent()) |
301 return 0; | 286 return 0; |
302 | 287 |
303 return toSVGTextContentElement(element); | 288 return toSVGTextContentElement(element); |
304 } | 289 } |
305 | 290 |
306 } | 291 } |
OLD | NEW |