| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 String SVGNumber::valueAsString() const | 57 String SVGNumber::valueAsString() const |
| 58 { | 58 { |
| 59 return String::number(m_value); | 59 return String::number(m_value); |
| 60 } | 60 } |
| 61 | 61 |
| 62 template<typename CharType> | 62 template<typename CharType> |
| 63 bool SVGNumber::parse(const CharType*& ptr, const CharType* end) | 63 bool SVGNumber::parse(const CharType*& ptr, const CharType* end) |
| 64 { | 64 { |
| 65 if (!parseNumber(ptr, end, m_value, false)) { | 65 if (!parseNumber(ptr, end, m_value, AllowLeadingAndTrailingWhitespace)) { |
| 66 m_value = 0; | 66 m_value = 0; |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 | 69 |
| 70 if (ptr != end) { | 70 if (ptr != end) { |
| 71 m_value = 0; | 71 m_value = 0; |
| 72 return false; | 72 return false; |
| 73 } | 73 } |
| 74 | 74 |
| 75 return true; | 75 return true; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 return fabsf(m_value - toSVGNumber(other)->value()); | 120 return fabsf(m_value - toSVGNumber(other)->value()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 PassRefPtr<SVGNumber> SVGNumberAcceptPercentage::clone() const | 123 PassRefPtr<SVGNumber> SVGNumberAcceptPercentage::clone() const |
| 124 { | 124 { |
| 125 return create(m_value); | 125 return create(m_value); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void SVGNumberAcceptPercentage::setValueAsString(const String& string, Exception
State& exceptionState) | 128 void SVGNumberAcceptPercentage::setValueAsString(const String& string, Exception
State& exceptionState) |
| 129 { | 129 { |
| 130 if (string.isEmpty()) { | 130 bool valid = parseNumberOrPercentage(string, m_value); |
| 131 |
| 132 if (!valid) { |
| 133 exceptionState.throwDOMException(SyntaxError, "The value provided ('" +
string + "') is invalid."); |
| 131 m_value = 0; | 134 m_value = 0; |
| 132 return; | |
| 133 } | 135 } |
| 134 | |
| 135 if (string.endsWith('%')) { | |
| 136 SVGNumber::setValueAsString(string.left(string.length() - 1), exceptionS
tate); | |
| 137 if (exceptionState.hadException()) | |
| 138 return; | |
| 139 | |
| 140 m_value /= 100.0f; | |
| 141 return; | |
| 142 } | |
| 143 | |
| 144 SVGNumber::setValueAsString(string, exceptionState); | |
| 145 } | 136 } |
| 146 | 137 |
| 147 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value) | 138 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value) |
| 148 : SVGNumber(value) | 139 : SVGNumber(value) |
| 149 { | 140 { |
| 150 } | 141 } |
| 151 | 142 |
| 152 } | 143 } |
| OLD | NEW |