OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 28 matching lines...) Expand all Loading... |
39 public: | 39 public: |
40 typedef std::pair<unsigned short, String> StringEntry; | 40 typedef std::pair<unsigned short, String> StringEntry; |
41 typedef Vector<StringEntry> StringEntries; | 41 typedef Vector<StringEntry> StringEntries; |
42 | 42 |
43 // SVGEnumeration does not have a tear-off type. | 43 // SVGEnumeration does not have a tear-off type. |
44 typedef void TearOffType; | 44 typedef void TearOffType; |
45 typedef unsigned short PrimitiveType; | 45 typedef unsigned short PrimitiveType; |
46 | 46 |
47 virtual ~SVGEnumerationBase(); | 47 virtual ~SVGEnumerationBase(); |
48 | 48 |
49 unsigned short value() const { return m_value; } | 49 unsigned short value() const { return m_value <= maxExposedEnumValue() ? m_v
alue : 0; } |
50 void setValue(unsigned short, ExceptionState&); | 50 void setValue(unsigned short, ExceptionState&); |
51 | 51 |
52 // This assumes that |m_entries| are sorted. | |
53 unsigned short maxEnumValue() const { return m_entries.last().first; } | |
54 | |
55 // SVGPropertyBase: | 52 // SVGPropertyBase: |
56 virtual PassRefPtr<SVGEnumerationBase> clone() const = 0; | 53 virtual PassRefPtr<SVGEnumerationBase> clone() const = 0; |
57 virtual PassRefPtr<SVGPropertyBase> cloneForAnimation(const String&) const O
VERRIDE; | 54 virtual PassRefPtr<SVGPropertyBase> cloneForAnimation(const String&) const O
VERRIDE; |
58 | 55 |
59 virtual String valueAsString() const OVERRIDE; | 56 virtual String valueAsString() const OVERRIDE; |
60 void setValueAsString(const String&, ExceptionState&); | 57 void setValueAsString(const String&, ExceptionState&); |
61 | 58 |
62 virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) OVERR
IDE; | 59 virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) OVERR
IDE; |
63 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage,
unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBa
se> to, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement*) OVERRID
E; | 60 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage,
unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBa
se> to, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement*) OVERRID
E; |
64 virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement*)
OVERRIDE; | 61 virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement*)
OVERRIDE; |
65 | 62 |
66 static AnimatedPropertyType classType() { return AnimatedEnumeration; } | 63 static AnimatedPropertyType classType() { return AnimatedEnumeration; } |
67 | 64 |
68 // Ensure that |SVGAnimatedEnumerationBase::setBaseVal| is used instead of |
SVGAnimatedProperty<SVGEnumerationBase>::setBaseVal|. | 65 // Ensure that |SVGAnimatedEnumerationBase::setBaseVal| is used instead of |
SVGAnimatedProperty<SVGEnumerationBase>::setBaseVal|. |
69 void setValue(unsigned short) { ASSERT_NOT_REACHED(); } | 66 void setValue(unsigned short) { ASSERT_NOT_REACHED(); } |
70 | 67 |
| 68 static unsigned short valueOfLastEnum(const StringEntries& entries) { return
entries.last().first; } |
| 69 |
71 protected: | 70 protected: |
72 SVGEnumerationBase(unsigned short value, const StringEntries& entries) | 71 SVGEnumerationBase(unsigned short value, const StringEntries& entries, unsig
ned short maxExposed) |
73 : SVGPropertyBase(classType()) | 72 : SVGPropertyBase(classType()) |
74 , m_value(value) | 73 , m_value(value) |
| 74 , m_maxExposed(maxExposed) |
75 , m_entries(entries) | 75 , m_entries(entries) |
76 { | 76 { |
77 } | 77 } |
78 | 78 |
| 79 // This is the maximum value of all the internal enumeration values. |
| 80 // This assumes that |m_entries| are sorted. |
| 81 unsigned short maxInternalEnumValue() const { return valueOfLastEnum(m_entri
es); } |
| 82 |
| 83 // This is the maximum value that is exposed as an IDL constant on the relev
ant interface. |
| 84 unsigned short maxExposedEnumValue() const { return m_maxExposed; } |
| 85 |
79 // Used by SVGMarkerOrientEnumeration. | 86 // Used by SVGMarkerOrientEnumeration. |
80 virtual void notifyChange() { } | 87 virtual void notifyChange() { } |
81 | 88 |
82 unsigned short m_value; | 89 unsigned short m_value; |
| 90 const unsigned short m_maxExposed; |
83 const StringEntries& m_entries; | 91 const StringEntries& m_entries; |
84 }; | 92 }; |
85 typedef SVGEnumerationBase::StringEntries SVGEnumerationStringEntries; | 93 typedef SVGEnumerationBase::StringEntries SVGEnumerationStringEntries; |
86 | 94 |
87 template<typename Enum> const SVGEnumerationStringEntries& getStaticStringEntrie
s(); | 95 template<typename Enum> const SVGEnumerationStringEntries& getStaticStringEntrie
s(); |
| 96 template<typename Enum> unsigned short getMaxExposedEnumValue() |
| 97 { |
| 98 return SVGEnumerationBase::valueOfLastEnum(getStaticStringEntries<Enum>()); |
| 99 } |
88 | 100 |
89 template<typename Enum> | 101 template<typename Enum> |
90 class SVGEnumeration : public SVGEnumerationBase { | 102 class SVGEnumeration : public SVGEnumerationBase { |
91 public: | 103 public: |
92 static PassRefPtr<SVGEnumeration<Enum> > create(Enum newValue) | 104 static PassRefPtr<SVGEnumeration<Enum> > create(Enum newValue) |
93 { | 105 { |
94 return adoptRef(new SVGEnumeration<Enum>(newValue)); | 106 return adoptRef(new SVGEnumeration<Enum>(newValue)); |
95 } | 107 } |
96 | 108 |
97 virtual ~SVGEnumeration() | 109 virtual ~SVGEnumeration() |
98 { | 110 { |
99 } | 111 } |
100 | 112 |
101 virtual PassRefPtr<SVGEnumerationBase> clone() const OVERRIDE | 113 virtual PassRefPtr<SVGEnumerationBase> clone() const OVERRIDE |
102 { | 114 { |
103 return create(enumValue()); | 115 return create(enumValue()); |
104 } | 116 } |
105 | 117 |
106 Enum enumValue() const | 118 Enum enumValue() const |
107 { | 119 { |
108 ASSERT(m_value <= maxEnumValue()); | 120 ASSERT(m_value <= maxInternalEnumValue()); |
109 return static_cast<Enum>(m_value); | 121 return static_cast<Enum>(m_value); |
110 } | 122 } |
111 | 123 |
112 void setEnumValue(Enum value) | 124 void setEnumValue(Enum value) |
113 { | 125 { |
114 m_value = value; | 126 m_value = value; |
115 notifyChange(); | 127 notifyChange(); |
116 } | 128 } |
117 | 129 |
118 protected: | 130 protected: |
119 explicit SVGEnumeration(Enum newValue) | 131 explicit SVGEnumeration(Enum newValue) |
120 : SVGEnumerationBase(newValue, getStaticStringEntries<Enum>()) | 132 : SVGEnumerationBase(newValue, getStaticStringEntries<Enum>(), getMaxExp
osedEnumValue<Enum>()) |
121 { | 133 { |
122 } | 134 } |
123 }; | 135 }; |
124 | 136 |
125 } // namespace blink | 137 } // namespace blink |
126 | 138 |
127 #endif // SVGEnumeration_h | 139 #endif // SVGEnumeration_h |
OLD | NEW |