| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 float SVGNumber::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> other
, SVGElement*) | 99 float SVGNumber::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> other
, SVGElement*) |
| 100 { | 100 { |
| 101 return fabsf(m_value - toSVGNumber(other)->value()); | 101 return fabsf(m_value - toSVGNumber(other)->value()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 PassRefPtrWillBeRawPtr<SVGNumber> SVGNumberAcceptPercentage::clone() const | 104 PassRefPtrWillBeRawPtr<SVGNumber> SVGNumberAcceptPercentage::clone() const |
| 105 { | 105 { |
| 106 return create(m_value); | 106 return create(m_value); |
| 107 } | 107 } |
| 108 | 108 |
| 109 template<typename CharType> |
| 110 static SVGParsingError parseNumberOrPercentage(const CharType*& ptr, const CharT
ype* end, float& number) |
| 111 { |
| 112 const CharType* start = ptr; |
| 113 if (!parseNumber(ptr, end, number, AllowLeadingWhitespace)) |
| 114 return SVGParsingError(SVGParseStatus::ExpectedNumberOrPercentage, ptr -
start); |
| 115 if (ptr < end && *ptr == '%') { |
| 116 number /= 100; |
| 117 ptr++; |
| 118 } |
| 119 if (skipOptionalSVGSpaces(ptr, end)) |
| 120 return SVGParsingError(SVGParseStatus::TrailingGarbage, ptr - start); |
| 121 return SVGParseStatus::NoError; |
| 122 } |
| 123 |
| 109 SVGParsingError SVGNumberAcceptPercentage::setValueAsString(const String& string
) | 124 SVGParsingError SVGNumberAcceptPercentage::setValueAsString(const String& string
) |
| 110 { | 125 { |
| 111 if (parseNumberOrPercentage(string, m_value)) | 126 m_value = 0; |
| 112 return SVGParseStatus::NoError; | |
| 113 | 127 |
| 114 m_value = 0; | 128 if (string.isEmpty()) |
| 115 return SVGParseStatus::ParsingFailed; | 129 return SVGParseStatus::ExpectedNumberOrPercentage; |
| 130 |
| 131 float number = 0; |
| 132 SVGParsingError error; |
| 133 if (string.is8Bit()) { |
| 134 const LChar* ptr = string.characters8(); |
| 135 const LChar* end = ptr + string.length(); |
| 136 error = parseNumberOrPercentage(ptr, end, number); |
| 137 } else { |
| 138 const UChar* ptr = string.characters16(); |
| 139 const UChar* end = ptr + string.length(); |
| 140 error = parseNumberOrPercentage(ptr, end, number); |
| 141 } |
| 142 if (error == SVGParseStatus::NoError) |
| 143 m_value = number; |
| 144 return error; |
| 116 } | 145 } |
| 117 | 146 |
| 118 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value) | 147 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value) |
| 119 : SVGNumber(value) | 148 : SVGNumber(value) |
| 120 { | 149 { |
| 121 } | 150 } |
| 122 | 151 |
| 123 } // namespace blink | 152 } // namespace blink |
| OLD | NEW |