Changes between Version 8 and Version 9 of SVG properties


Ignore:
Timestamp:
Mar 8, 2019 9:43:37 PM (2 years ago)
Author:
Said Abou-Hallawa
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SVG properties

    v8 v9  
    44**What is an SVG property?**
    55
    6 It is a data type which can be primitive DOM type or SVG type. Example of primitive types are int, float, boolean. Examples for DOM type is DOMString. And examples for SVG types are SVGNumber, SVGNumberList, SVGLength, SVGLengthList, SVGAngle, SVGPoint, SVGPointList.
     6It is a storage for data type which can be primitive, DOM type or SVG type. Example of primitive types are int, float, boolean. Examples for DOM type is DOMString. And examples for SVG types are SVGNumber, SVGNumberList, SVGLength, SVGLengthList, SVGAngle, SVGPoint, SVGPointList.
    77
    88**What is so special about SVG property?**
    99
    10 1. It has its own DOM interface which is separate from getAttribute() and setAttribute() methods.
    11 2. It is a reflection of a DOM attribute. Two cases need to be handled
    12  a. When setAttribute called for the underlaying attribute, SVGElement::parseAttribute() will be called to update th SVG property and then SVGElement::svgAttributeChanged() is called to invalidate the renderer and the dependent SVG objects.
    13  b. When the SVG property is changed through the DOM interface. In this handed in two steps: (1) commit and (2) synchronize. The commit step is called immediately after changing the property. It will mark value of the underlaying attribute to be invalid and it call  SVGElement::svgAttributeChanged(). The synchronize. step happens later when the value of attribute is required. The valueAsString(0 of the SVG property is set as the attribute. value.
    14 3. Most of the properties are animated properties. The animated property has two members baseVal() and the animal(). Each of them are from the same SVG property type.  animal() differs from baseVal() only when animating. Otherwise they have to be the same value.
    15 4. The animal() of the animated property is read only; no changes from the DOM is allowed.
    16 5. The SVG property can be attached to an SVGElement or it can be detached.
     101. It has to provide a DOM interface. The interface can get or set its value similar to getAttribute() and setAttribute() methods.
     112. It has to be RefCounted because the DOM object will encapsulate the same SVG property and this DOM object can outlive the owner element.
     123. It is a reflection of a DOM attribute. Two cases have to be handled:
     13 a. When setAttribute() called for the underlaying attribute, SVGElement::parseAttribute() will be called to update the SVG property. Then SVGElement::svgAttributeChanged() is called to invalidate the renderer and the dependent SVG objects.
     14 b. When the SVG property is changed through the DOM interface. In this handled in two steps:
     15  * The commit step which is called immediately after changing the property's value. It will mark the value of the underlaying attribute to be invalid and it will call  SVGElement::svgAttributeChanged().
     16  *  The synchronize step which happens later when the value of attribute is required. The valueAsString() of the SVG property is set as the attribute value.
     174. Most of the properties are animated properties. The animated property has two members baseVal() and the animal(). Each of them are from the same SVG property type.  animal() differs from baseVal() only when animating. Otherwise they have to be the same value.
     185. The animal() of the animated property is read only; no changes from the DOM is allowed.
     196. The SVG property can be attached to an SVGElement or it can be detached.
     207. Some properties are SVG lists of SVG types, e.g. SVGNumberList and SVGPointList. In addition of having the list itself Refcounted, all the items of this list have to be RefCounted also. The items can outlive the owner list.
    1721
    18 **What things to consider for storing, modifying and animating the SVG property?**
    19 
    20 1. It has to be RefCounted because the DOM object will encapsulate the same SVG property and this DOM object can outlive the owner element.
    21 2. Some properties are SVG lists of SVG types, e.g. SVGNumberList and SVGPointList. In addition of having the list itself Refcounted, all the items of this list have to be RefCounted also. The items can outlive the owner list.
     22**Mechanic of the SVG property**
     231. Define the property registry of the element such that it associate the class with its all superclasses. And define a member of this type. For example the SVGRectElement has this definition and member declartion:
     24{{{
     25using PropertyRegistry = SVGPropertyOwnerRegistry<SVGRectElement, SVGGeometryElement, SVGExternalResourcesRequired>;
     26PropertyRegistry m_propertyRegistry { *this };
     27}}}
     282. Override the virtual method propertyRegistry() which will allow the base class SVGElement to perform operations on all the SVG properties of any superclass.
     29{{{
     30const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; }
     31}}}
     323. The property of defined in the header file of the SVG element exactly as it is defined in the IDL file. For example, SVGRectElement will have this member
     33{{{
     34Ref<SVGAnimatedLength> m_x { SVGAnimatedLength::create(this, LengthModeWidth) };
     35}}}
     364. The SVGAnimatedLength has two members named m_baseVal and m_animVal. Both of them are of type SVGLength.
     375. The property is registered only once in the constructor of the SVG element. This registration will associate the data member with the attribute name. For example the constructor of the SVGRectElement will have this statement:
     38{{{
     39PropertyRegistry::registerProperty<SVGNames::xAttr, &SVGRectElement::m_x>();
     40}}}
     416. This statement calls the override method of SVGPropertyOwnerRegistry
     42{{{
     43template<const LazyNeverDestroyed<const QualifiedName>& attributeName, Ref<SVGAnimatedLength> OwnerType::*property>
     44static void registerProperty()
     45{
     46    registerProperty(attributeName, SVGAnimatedLengthAccessor<OwnerType>::template singleton<property>());
     47}
     48}}}
     497. This registration associates a pointer to a member of SVGRectElement with the attributeName through the SVGAnimatedLengthAccessor.