Chromium Code Reviews| Index: Source/core/svg/SVGTextContentElement.cpp |
| diff --git a/Source/core/svg/SVGTextContentElement.cpp b/Source/core/svg/SVGTextContentElement.cpp |
| index 1c298456cae236d12d37961e6fe143ed4a0bec49..50cc7a988f36746f505b4dcd8b8c173d12961954 100644 |
| --- a/Source/core/svg/SVGTextContentElement.cpp |
| +++ b/Source/core/svg/SVGTextContentElement.cpp |
| @@ -36,27 +36,37 @@ |
| namespace WebCore { |
| -// Define custom animated property 'textLength'. |
| -const SVGPropertyInfo* SVGTextContentElement::textLengthPropertyInfo() |
| -{ |
| - static const SVGPropertyInfo* s_propertyInfo = 0; |
| - if (!s_propertyInfo) { |
| - s_propertyInfo = new SVGPropertyInfo(AnimatedLength, |
| - PropertyIsReadWrite, |
| - SVGNames::textLengthAttr, |
| - SVGNames::textLengthAttr.localName(), |
| - &SVGTextContentElement::synchronizeTextLength, |
| - &SVGTextContentElement::lookupOrCreateTextLengthWrapper); |
| +// Animated property definitions |
| + |
| +// SVGTextContentElement's 'textLength' attribute needs special handling. |
| +// It should return getComputedTextLength() when textLength is not specified manually. |
| +class SVGAnimatedTextLength : public SVGAnimatedLength { |
| +public: |
| + static PassRefPtr<SVGAnimatedTextLength> create(SVGTextContentElement* contextElement) |
| + { |
| + return adoptRef(new SVGAnimatedTextLength(contextElement)); |
| } |
| - return s_propertyInfo; |
| -} |
| -// Animated property definitions |
| + virtual SVGLengthTearOff* baseVal() |
| + { |
| + SVGTextContentElement* textContentElement = static_cast<SVGTextContentElement*>(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.
|
| + if (!textContentElement->textLengthIsSpecifiedByUser()) |
| + baseValue()->newValueSpecifiedUnits(LengthTypeNumber, textContentElement->getComputedTextLength()); |
| + |
| + return SVGAnimatedLength::baseVal(); |
| + } |
| + |
| +private: |
| + SVGAnimatedTextLength(SVGTextContentElement* contextElement) |
| + : SVGAnimatedLength(contextElement, SVGNames::textLengthAttr, SVGLength::create(LengthModeOther)) |
| + { |
| + } |
| +}; |
| + |
| DEFINE_ANIMATED_ENUMERATION(SVGTextContentElement, SVGNames::lengthAdjustAttr, LengthAdjust, lengthAdjust, SVGLengthAdjustType) |
| DEFINE_ANIMATED_BOOLEAN(SVGTextContentElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) |
| BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGTextContentElement) |
| - REGISTER_LOCAL_ANIMATED_PROPERTY(textLength) |
| REGISTER_LOCAL_ANIMATED_PROPERTY(lengthAdjust) |
| REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired) |
| REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) |
| @@ -64,41 +74,14 @@ END_REGISTER_ANIMATED_PROPERTIES |
| SVGTextContentElement::SVGTextContentElement(const QualifiedName& tagName, Document& document) |
| : SVGGraphicsElement(tagName, document) |
| - , m_textLength(LengthModeOther) |
| - , m_specifiedTextLength(LengthModeOther) |
| + , m_textLength(SVGAnimatedTextLength::create(this)) |
| + , m_textLengthIsSpecifiedByUser(false) |
| , m_lengthAdjust(SVGLengthAdjustSpacing) |
| { |
| ScriptWrappable::init(this); |
| - registerAnimatedPropertiesForSVGTextContentElement(); |
| -} |
| - |
| -void SVGTextContentElement::synchronizeTextLength(SVGElement* contextElement) |
| -{ |
| - ASSERT(contextElement); |
| - SVGTextContentElement* ownerType = toSVGTextContentElement(contextElement); |
| - if (!ownerType->m_textLength.shouldSynchronize) |
| - return; |
| - AtomicString value(SVGPropertyTraits<SVGLength>::toString(ownerType->m_specifiedTextLength)); |
| - ownerType->m_textLength.synchronize(ownerType, textLengthPropertyInfo()->attributeName, value); |
| -} |
| - |
| -PassRefPtr<SVGAnimatedProperty> SVGTextContentElement::lookupOrCreateTextLengthWrapper(SVGElement* contextElement) |
| -{ |
| - ASSERT(contextElement); |
| - SVGTextContentElement* ownerType = toSVGTextContentElement(contextElement); |
| - return SVGAnimatedProperty::lookupOrCreateWrapper<SVGTextContentElement, SVGAnimatedLength, SVGLength> |
| - (ownerType, textLengthPropertyInfo(), ownerType->m_textLength.value); |
| -} |
| - |
| -PassRefPtr<SVGAnimatedLength> SVGTextContentElement::textLength() |
| -{ |
| - DEFINE_STATIC_LOCAL(SVGLength, defaultTextLength, (LengthModeOther)); |
| - if (m_specifiedTextLength == defaultTextLength) |
| - m_textLength.value.newValueSpecifiedUnits(LengthTypeNumber, getComputedTextLength(), ASSERT_NO_EXCEPTION); |
| - |
| - m_textLength.shouldSynchronize = true; |
| - return static_pointer_cast<SVGAnimatedLength>(lookupOrCreateTextLengthWrapper(this)); |
| + addToPropertyMap(m_textLength); |
| + registerAnimatedPropertiesForSVGTextContentElement(); |
| } |
| unsigned SVGTextContentElement::getNumberOfChars() |
| @@ -253,7 +236,9 @@ void SVGTextContentElement::parseAttribute(const QualifiedName& name, const Atom |
| if (propertyValue > 0) |
| setLengthAdjustBaseValue(propertyValue); |
| } else if (name == SVGNames::textLengthAttr) { |
| - m_textLength.value = SVGLength::construct(LengthModeOther, value, parseError, ForbidNegativeLengths); |
| + m_textLength->setBaseValueAsString(value, ForbidNegativeLengths, parseError); |
| + if (parseError == NoError) |
| + m_textLengthIsSpecifiedByUser = true; |
| } else if (SVGExternalResourcesRequired::parseAttribute(name, value)) { |
| } else if (name.matches(XMLNames::spaceAttr)) { |
| } else |
| @@ -269,10 +254,10 @@ void SVGTextContentElement::svgAttributeChanged(const QualifiedName& attrName) |
| return; |
| } |
| - SVGElementInstance::InvalidationGuard invalidationGuard(this); |
| - |
| 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().
|
| - m_specifiedTextLength = m_textLength.value; |
| + m_textLengthIsSpecifiedByUser = true; |
| + |
| + SVGElementInstance::InvalidationGuard invalidationGuard(this); |
| if (RenderObject* renderer = this->renderer()) |
| RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); |