| 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 = toSVGTextContentElement(cont
extElement()); |
| 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 | 67 |
| 57 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGTextContentElement) | 68 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGTextContentElement) |
| 58 REGISTER_LOCAL_ANIMATED_PROPERTY(textLength) | |
| 59 REGISTER_LOCAL_ANIMATED_PROPERTY(lengthAdjust) | 69 REGISTER_LOCAL_ANIMATED_PROPERTY(lengthAdjust) |
| 60 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) | 70 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) |
| 61 END_REGISTER_ANIMATED_PROPERTIES | 71 END_REGISTER_ANIMATED_PROPERTIES |
| 62 | 72 |
| 63 SVGTextContentElement::SVGTextContentElement(const QualifiedName& tagName, Docum
ent& document) | 73 SVGTextContentElement::SVGTextContentElement(const QualifiedName& tagName, Docum
ent& document) |
| 64 : SVGGraphicsElement(tagName, document) | 74 : SVGGraphicsElement(tagName, document) |
| 65 , m_textLength(LengthModeOther) | 75 , m_textLength(SVGAnimatedTextLength::create(this)) |
| 66 , m_specifiedTextLength(LengthModeOther) | 76 , m_textLengthIsSpecifiedByUser(false) |
| 67 , m_lengthAdjust(SVGLengthAdjustSpacing) | 77 , m_lengthAdjust(SVGLengthAdjustSpacing) |
| 68 { | 78 { |
| 69 ScriptWrappable::init(this); | 79 ScriptWrappable::init(this); |
| 80 |
| 81 addToPropertyMap(m_textLength); |
| 70 registerAnimatedPropertiesForSVGTextContentElement(); | 82 registerAnimatedPropertiesForSVGTextContentElement(); |
| 71 } | 83 } |
| 72 | 84 |
| 73 void SVGTextContentElement::synchronizeTextLength(SVGElement* contextElement) | |
| 74 { | |
| 75 ASSERT(contextElement); | |
| 76 SVGTextContentElement* ownerType = toSVGTextContentElement(contextElement); | |
| 77 if (!ownerType->m_textLength.shouldSynchronize) | |
| 78 return; | |
| 79 AtomicString value(SVGPropertyTraits<SVGLength>::toString(ownerType->m_speci
fiedTextLength)); | |
| 80 ownerType->m_textLength.synchronize(ownerType, textLengthPropertyInfo()->att
ributeName, value); | |
| 81 } | |
| 82 | |
| 83 PassRefPtr<SVGAnimatedProperty> SVGTextContentElement::lookupOrCreateTextLengthW
rapper(SVGElement* contextElement) | |
| 84 { | |
| 85 ASSERT(contextElement); | |
| 86 SVGTextContentElement* ownerType = toSVGTextContentElement(contextElement); | |
| 87 return SVGAnimatedProperty::lookupOrCreateWrapper<SVGTextContentElement, SVG
AnimatedLength, SVGLength> | |
| 88 (ownerType, textLengthPropertyInfo(), ownerType->m_textLength.value); | |
| 89 } | |
| 90 | |
| 91 PassRefPtr<SVGAnimatedLength> SVGTextContentElement::textLength() | |
| 92 { | |
| 93 DEFINE_STATIC_LOCAL(SVGLength, defaultTextLength, (LengthModeOther)); | |
| 94 if (m_specifiedTextLength == defaultTextLength) | |
| 95 m_textLength.value.newValueSpecifiedUnits(LengthTypeNumber, getComputedT
extLength(), ASSERT_NO_EXCEPTION); | |
| 96 | |
| 97 m_textLength.shouldSynchronize = true; | |
| 98 return static_pointer_cast<SVGAnimatedLength>(lookupOrCreateTextLengthWrappe
r(this)); | |
| 99 | |
| 100 } | |
| 101 | |
| 102 unsigned SVGTextContentElement::getNumberOfChars() | 85 unsigned SVGTextContentElement::getNumberOfChars() |
| 103 { | 86 { |
| 104 document().updateLayoutIgnorePendingStylesheets(); | 87 document().updateLayoutIgnorePendingStylesheets(); |
| 105 return SVGTextQuery(renderer()).numberOfCharacters(); | 88 return SVGTextQuery(renderer()).numberOfCharacters(); |
| 106 } | 89 } |
| 107 | 90 |
| 108 float SVGTextContentElement::getComputedTextLength() | 91 float SVGTextContentElement::getComputedTextLength() |
| 109 { | 92 { |
| 110 document().updateLayoutIgnorePendingStylesheets(); | 93 document().updateLayoutIgnorePendingStylesheets(); |
| 111 return SVGTextQuery(renderer()).textLength(); | 94 return SVGTextQuery(renderer()).textLength(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 { | 226 { |
| 244 SVGParsingError parseError = NoError; | 227 SVGParsingError parseError = NoError; |
| 245 | 228 |
| 246 if (!isSupportedAttribute(name)) | 229 if (!isSupportedAttribute(name)) |
| 247 SVGGraphicsElement::parseAttribute(name, value); | 230 SVGGraphicsElement::parseAttribute(name, value); |
| 248 else if (name == SVGNames::lengthAdjustAttr) { | 231 else if (name == SVGNames::lengthAdjustAttr) { |
| 249 SVGLengthAdjustType propertyValue = SVGPropertyTraits<SVGLengthAdjustTyp
e>::fromString(value); | 232 SVGLengthAdjustType propertyValue = SVGPropertyTraits<SVGLengthAdjustTyp
e>::fromString(value); |
| 250 if (propertyValue > 0) | 233 if (propertyValue > 0) |
| 251 setLengthAdjustBaseValue(propertyValue); | 234 setLengthAdjustBaseValue(propertyValue); |
| 252 } else if (name == SVGNames::textLengthAttr) { | 235 } else if (name == SVGNames::textLengthAttr) { |
| 253 m_textLength.value = SVGLength::construct(LengthModeOther, value, parseE
rror, ForbidNegativeLengths); | 236 m_textLength->setBaseValueAsString(value, ForbidNegativeLengths, parseEr
ror); |
| 254 } else if (name.matches(XMLNames::spaceAttr)) { | 237 } else if (name.matches(XMLNames::spaceAttr)) { |
| 255 } else | 238 } else |
| 256 ASSERT_NOT_REACHED(); | 239 ASSERT_NOT_REACHED(); |
| 257 | 240 |
| 258 reportAttributeParsingError(parseError, name, value); | 241 reportAttributeParsingError(parseError, name, value); |
| 259 } | 242 } |
| 260 | 243 |
| 261 void SVGTextContentElement::svgAttributeChanged(const QualifiedName& attrName) | 244 void SVGTextContentElement::svgAttributeChanged(const QualifiedName& attrName) |
| 262 { | 245 { |
| 263 if (!isSupportedAttribute(attrName)) { | 246 if (!isSupportedAttribute(attrName)) { |
| 264 SVGGraphicsElement::svgAttributeChanged(attrName); | 247 SVGGraphicsElement::svgAttributeChanged(attrName); |
| 265 return; | 248 return; |
| 266 } | 249 } |
| 267 | 250 |
| 251 if (attrName == SVGNames::textLengthAttr) |
| 252 m_textLengthIsSpecifiedByUser = true; |
| 253 |
| 268 SVGElementInstance::InvalidationGuard invalidationGuard(this); | 254 SVGElementInstance::InvalidationGuard invalidationGuard(this); |
| 269 | 255 |
| 270 if (attrName == SVGNames::textLengthAttr) | |
| 271 m_specifiedTextLength = m_textLength.value; | |
| 272 | |
| 273 if (RenderObject* renderer = this->renderer()) | 256 if (RenderObject* renderer = this->renderer()) |
| 274 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); | 257 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); |
| 275 } | 258 } |
| 276 | 259 |
| 277 bool SVGTextContentElement::selfHasRelativeLengths() const | 260 bool SVGTextContentElement::selfHasRelativeLengths() const |
| 278 { | 261 { |
| 279 // Any element of the <text> subtree is advertized as using relative lengths
. | 262 // Any element of the <text> subtree is advertized as using relative lengths
. |
| 280 // On any window size change, we have to relayout the text subtree, as the | 263 // On any window size change, we have to relayout the text subtree, as the |
| 281 // effective 'on-screen' font size may change. | 264 // effective 'on-screen' font size may change. |
| 282 return true; | 265 return true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 293 SVGElement* element = toSVGElement(renderer->node()); | 276 SVGElement* element = toSVGElement(renderer->node()); |
| 294 ASSERT(element); | 277 ASSERT(element); |
| 295 | 278 |
| 296 if (!element->isTextContent()) | 279 if (!element->isTextContent()) |
| 297 return 0; | 280 return 0; |
| 298 | 281 |
| 299 return toSVGTextContentElement(element); | 282 return toSVGTextContentElement(element); |
| 300 } | 283 } |
| 301 | 284 |
| 302 } | 285 } |
| OLD | NEW |