Title: [195315] trunk/Source/WebCore
Revision
195315
Author
[email protected]
Date
2016-01-19 14:01:55 -0800 (Tue, 19 Jan 2016)

Log Message

SVG 2 requires a mechanism for restricting enum values exposed through the DOM
https://bugs.webkit.org/show_bug.cgi?id=152814

Patch by Nikos Andronikos <[email protected]> on 2016-01-19
Reviewed by Darin Adler.

No new tests (No change in functionality, blocked bugs add new tests).

This patch adds a mechanism to restrict the values returned through the
SVGAnimatedEnumeration interface.
This is required for SVG 2, which does not expose new enumeration
values through the IDL.
See http://www.w3.org/TR/SVG2/types.html#InterfaceSVGAnimatedEnumeration
Getters:
SVG 2 does not add numeric type values for new options, new options
should return UNKNOWN.
E.g. See the table defining numeric type values for orient at
http://www.w3.org/TR/SVG2/painting.html#InterfaceSVGMarkerElement
Setters:
On setting baseVal, the following steps are run:
1. ...
2. If value is 0 or is not the numeric type value for any value of the reflected attribute, then set the reflected attribute to the empty string.

* svg/properties/SVGAnimatedEnumerationPropertyTearOff.h:
Override baseVal() and animVal() to perform range checks against
the highest exposed enum value.
* svg/properties/SVGAnimatedStaticPropertyTearOff.h:
(WebCore::SVGAnimatedStaticPropertyTearOff::baseVal): Mark function as virtual as it's over-ridden for enumerations.
(WebCore::SVGAnimatedStaticPropertyTearOff::animVal): Mark function as virtual as it's over-ridden for enumerations.
* svg/properties/SVGPropertyTraits.h:
Add SVGIDLEnumLimits struct that contains function for querying the
highest exposed enum value.
(WebCore::SVGIDLEnumLimits::highestExposedEnumValue): New function that returns the highest enum value that should
be exposed through the DOM. This function should be specialized for enum types that need to restrict the exposed
values.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (195314 => 195315)


--- trunk/Source/WebCore/ChangeLog	2016-01-19 21:49:12 UTC (rev 195314)
+++ trunk/Source/WebCore/ChangeLog	2016-01-19 22:01:55 UTC (rev 195315)
@@ -1,3 +1,40 @@
+2016-01-19  Nikos Andronikos  <[email protected]>
+
+        SVG 2 requires a mechanism for restricting enum values exposed through the DOM
+        https://bugs.webkit.org/show_bug.cgi?id=152814
+
+        Reviewed by Darin Adler.
+
+        No new tests (No change in functionality, blocked bugs add new tests).
+ 
+        This patch adds a mechanism to restrict the values returned through the
+        SVGAnimatedEnumeration interface.
+        This is required for SVG 2, which does not expose new enumeration
+        values through the IDL.
+        See http://www.w3.org/TR/SVG2/types.html#InterfaceSVGAnimatedEnumeration
+        Getters:
+        SVG 2 does not add numeric type values for new options, new options
+        should return UNKNOWN.
+        E.g. See the table defining numeric type values for orient at
+        http://www.w3.org/TR/SVG2/painting.html#InterfaceSVGMarkerElement
+        Setters:
+        On setting baseVal, the following steps are run:
+        1. ...
+        2. If value is 0 or is not the numeric type value for any value of the reflected attribute, then set the reflected attribute to the empty string.
+
+        * svg/properties/SVGAnimatedEnumerationPropertyTearOff.h:
+        Override baseVal() and animVal() to perform range checks against
+        the highest exposed enum value.
+        * svg/properties/SVGAnimatedStaticPropertyTearOff.h:
+        (WebCore::SVGAnimatedStaticPropertyTearOff::baseVal): Mark function as virtual as it's over-ridden for enumerations.
+        (WebCore::SVGAnimatedStaticPropertyTearOff::animVal): Mark function as virtual as it's over-ridden for enumerations.
+        * svg/properties/SVGPropertyTraits.h:
+        Add SVGIDLEnumLimits struct that contains function for querying the
+        highest exposed enum value.
+        (WebCore::SVGIDLEnumLimits::highestExposedEnumValue): New function that returns the highest enum value that should
+        be exposed through the DOM. This function should be specialized for enum types that need to restrict the exposed
+        values.
+
 2016-01-19  Konstantin Tokarev  <[email protected]>
 
         Fixed compilation of AXObjectCache in case of !HAVE(ACCESSIBILITY).

Modified: trunk/Source/WebCore/svg/properties/SVGAnimatedEnumerationPropertyTearOff.h (195314 => 195315)


--- trunk/Source/WebCore/svg/properties/SVGAnimatedEnumerationPropertyTearOff.h	2016-01-19 21:49:12 UTC (rev 195314)
+++ trunk/Source/WebCore/svg/properties/SVGAnimatedEnumerationPropertyTearOff.h	2016-01-19 22:01:55 UTC (rev 195315)
@@ -27,12 +27,32 @@
 namespace WebCore {
 
 template<typename EnumType>
-class SVGAnimatedEnumerationPropertyTearOff : public SVGAnimatedStaticPropertyTearOff<unsigned> {
+class SVGAnimatedEnumerationPropertyTearOff final : public SVGAnimatedStaticPropertyTearOff<unsigned> {
 public:
+    virtual unsigned& baseVal() override
+    {
+        unsigned& baseVal = SVGAnimatedStaticPropertyTearOff::baseVal();
+
+        if (baseVal > SVGIDLEnumLimits<EnumType>::highestExposedEnumValue())
+            return m_outOfRangeEnumValue;
+
+        return baseVal;
+    }
+
+    virtual unsigned& animVal() override
+    {
+        unsigned& animVal = SVGAnimatedStaticPropertyTearOff::animVal();
+
+        if (animVal > SVGIDLEnumLimits<EnumType>::highestExposedEnumValue())
+            return m_outOfRangeEnumValue;
+
+        return animVal;
+    }
+
     virtual void setBaseVal(const unsigned& property, ExceptionCode& ec) override
     {
         // All SVG enumeration values, that are allowed to be set via SVG DOM start with 1, 0 corresponds to unknown and is not settable through SVG DOM.
-        if (!property || property > SVGPropertyTraits<EnumType>::highestEnumValue()) {
+        if (!property || property > SVGIDLEnumLimits<EnumType>::highestExposedEnumValue()) {
             ec = SVGException::SVG_INVALID_VALUE_ERR;
             return;
         }
@@ -57,8 +77,14 @@
         : SVGAnimatedStaticPropertyTearOff<unsigned>(contextElement, attributeName, animatedPropertyType, property)
     {
     }
+
+    static unsigned m_outOfRangeEnumValue;
 };
 
+// By convention, all enum values that represent UNKNOWN in SVG are equal to zero.
+template<typename EnumType>
+unsigned SVGAnimatedEnumerationPropertyTearOff<EnumType>::m_outOfRangeEnumValue = 0;
+
 }
 
 #endif // SVGAnimatedEnumerationPropertyTearOff_h

Modified: trunk/Source/WebCore/svg/properties/SVGAnimatedStaticPropertyTearOff.h (195314 => 195315)


--- trunk/Source/WebCore/svg/properties/SVGAnimatedStaticPropertyTearOff.h	2016-01-19 21:49:12 UTC (rev 195314)
+++ trunk/Source/WebCore/svg/properties/SVGAnimatedStaticPropertyTearOff.h	2016-01-19 22:01:55 UTC (rev 195315)
@@ -30,12 +30,12 @@
 public:
     typedef PropertyType ContentType;
 
-    PropertyType& baseVal()
+    virtual PropertyType& baseVal()
     {
         return m_property;
     }
 
-    PropertyType& animVal()
+    virtual PropertyType& animVal()
     {
         if (m_animatedProperty)
             return *m_animatedProperty;

Modified: trunk/Source/WebCore/svg/properties/SVGPropertyTraits.h (195314 => 195315)


--- trunk/Source/WebCore/svg/properties/SVGPropertyTraits.h	2016-01-19 21:49:12 UTC (rev 195314)
+++ trunk/Source/WebCore/svg/properties/SVGPropertyTraits.h	2016-01-19 22:01:55 UTC (rev 195315)
@@ -58,6 +58,12 @@
     static String toString(const String& type) { return type; }
 };
 
+template<typename EnumType>
+struct SVGIDLEnumLimits {
+    // Specialize this function for a particular enumeration to limit the values that are exposed through the DOM.
+    static unsigned highestExposedEnumValue() { return SVGPropertyTraits<EnumType>::highestEnumValue(); }
+};
+
 }
 
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to