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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGEnumerationBase::cloneForAnimation(co
nst String& value) const | 53 PassRefPtrWillBeRawPtr<SVGPropertyBase> SVGEnumerationBase::cloneForAnimation(co
nst String& value) const |
54 { | 54 { |
55 RefPtrWillBeRawPtr<SVGEnumerationBase> svgEnumeration = clone(); | 55 RefPtrWillBeRawPtr<SVGEnumerationBase> svgEnumeration = clone(); |
56 svgEnumeration->setValueAsString(value, IGNORE_EXCEPTION); | 56 svgEnumeration->setValueAsString(value, IGNORE_EXCEPTION); |
57 return svgEnumeration.release(); | 57 return svgEnumeration.release(); |
58 } | 58 } |
59 | 59 |
60 String SVGEnumerationBase::valueAsString() const | 60 String SVGEnumerationBase::valueAsString() const |
61 { | 61 { |
62 StringEntries::const_iterator it = m_entries.begin(); | 62 for (const auto& entry : m_entries) { |
63 StringEntries::const_iterator itEnd = m_entries.end(); | 63 if (m_value == entry.first) |
64 for (; it != itEnd; ++it) { | 64 return entry.second; |
65 if (m_value == it->first) | |
66 return it->second; | |
67 } | 65 } |
68 | 66 |
69 ASSERT(m_value < maxInternalEnumValue()); | 67 ASSERT(m_value < maxInternalEnumValue()); |
70 return emptyString(); | 68 return emptyString(); |
71 } | 69 } |
72 | 70 |
73 void SVGEnumerationBase::setValue(unsigned short value, ExceptionState& exceptio
nState) | 71 void SVGEnumerationBase::setValue(unsigned short value, ExceptionState& exceptio
nState) |
74 { | 72 { |
75 if (!value) { | 73 if (!value) { |
76 exceptionState.throwTypeError("The enumeration value provided is 0, whic
h is not settable."); | 74 exceptionState.throwTypeError("The enumeration value provided is 0, whic
h is not settable."); |
77 return; | 75 return; |
78 } | 76 } |
79 | 77 |
80 if (value > maxExposedEnumValue()) { | 78 if (value > maxExposedEnumValue()) { |
81 exceptionState.throwTypeError("The enumeration value provided (" + Strin
g::number(value) + ") is larger than the largest allowed value (" + String::numb
er(maxExposedEnumValue()) + ")."); | 79 exceptionState.throwTypeError("The enumeration value provided (" + Strin
g::number(value) + ") is larger than the largest allowed value (" + String::numb
er(maxExposedEnumValue()) + ")."); |
82 return; | 80 return; |
83 } | 81 } |
84 | 82 |
85 m_value = value; | 83 m_value = value; |
86 notifyChange(); | 84 notifyChange(); |
87 } | 85 } |
88 | 86 |
89 void SVGEnumerationBase::setValueAsString(const String& string, ExceptionState&
exceptionState) | 87 void SVGEnumerationBase::setValueAsString(const String& string, ExceptionState&
exceptionState) |
90 { | 88 { |
91 StringEntries::const_iterator it = m_entries.begin(); | 89 for (const auto& entry : m_entries) { |
92 StringEntries::const_iterator itEnd = m_entries.end(); | 90 if (string == entry.second) { |
93 for (; it != itEnd; ++it) { | |
94 if (string == it->second) { | |
95 // 0 corresponds to _UNKNOWN enumeration values, and should not be s
ettable. | 91 // 0 corresponds to _UNKNOWN enumeration values, and should not be s
ettable. |
96 ASSERT(it->first); | 92 ASSERT(entry.first); |
97 m_value = it->first; | 93 m_value = entry.first; |
98 notifyChange(); | 94 notifyChange(); |
99 return; | 95 return; |
100 } | 96 } |
101 } | 97 } |
102 | 98 |
103 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + stri
ng + "') is invalid."); | 99 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + stri
ng + "') is invalid."); |
104 notifyChange(); | 100 notifyChange(); |
105 } | 101 } |
106 | 102 |
107 void SVGEnumerationBase::add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement
*) | 103 void SVGEnumerationBase::add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement
*) |
(...skipping 10 matching lines...) Expand all Loading... |
118 animationElement->animateDiscreteType<unsigned short>(percentage, fromEnumer
ation, toEnumeration, m_value); | 114 animationElement->animateDiscreteType<unsigned short>(percentage, fromEnumer
ation, toEnumeration, m_value); |
119 } | 115 } |
120 | 116 |
121 float SVGEnumerationBase::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBa
se>, SVGElement*) | 117 float SVGEnumerationBase::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBa
se>, SVGElement*) |
122 { | 118 { |
123 // No paced animations for boolean. | 119 // No paced animations for boolean. |
124 return -1; | 120 return -1; |
125 } | 121 } |
126 | 122 |
127 } | 123 } |
OLD | NEW |