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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 SVGPropertyBase::trace(visitor); | 45 SVGPropertyBase::trace(visitor); |
46 } | 46 } |
47 | 47 |
48 SVGIntegerOptionalInteger* SVGIntegerOptionalInteger::clone() const { | 48 SVGIntegerOptionalInteger* SVGIntegerOptionalInteger::clone() const { |
49 return SVGIntegerOptionalInteger::create(m_firstInteger->clone(), | 49 return SVGIntegerOptionalInteger::create(m_firstInteger->clone(), |
50 m_secondInteger->clone()); | 50 m_secondInteger->clone()); |
51 } | 51 } |
52 | 52 |
53 SVGPropertyBase* SVGIntegerOptionalInteger::cloneForAnimation( | 53 SVGPropertyBase* SVGIntegerOptionalInteger::cloneForAnimation( |
54 const String& value) const { | 54 const String& value) const { |
55 float floatX, floatY; | 55 SVGIntegerOptionalInteger* clone = |
56 if (!parseNumberOptionalNumber(value, floatX, floatY)) { | 56 create(SVGInteger::create(0), SVGInteger::create(0)); |
57 return SVGIntegerOptionalInteger::create(SVGInteger::create(0), | 57 clone->setValueAsString(value); |
58 SVGInteger::create(0)); | 58 return clone; |
59 } | |
60 | |
61 int x = static_cast<int>(roundf(floatX)); | |
62 int y = static_cast<int>(roundf(floatY)); | |
63 | |
64 return SVGIntegerOptionalInteger::create(SVGInteger::create(x), | |
65 SVGInteger::create(y)); | |
66 } | 59 } |
67 | 60 |
68 String SVGIntegerOptionalInteger::valueAsString() const { | 61 String SVGIntegerOptionalInteger::valueAsString() const { |
69 if (m_firstInteger->value() == m_secondInteger->value()) { | 62 if (m_firstInteger->value() == m_secondInteger->value()) { |
70 return String::number(m_firstInteger->value()); | 63 return String::number(m_firstInteger->value()); |
71 } | 64 } |
72 | 65 |
73 return String::number(m_firstInteger->value()) + " " + | 66 return String::number(m_firstInteger->value()) + " " + |
74 String::number(m_secondInteger->value()); | 67 String::number(m_secondInteger->value()); |
75 } | 68 } |
76 | 69 |
77 SVGParsingError SVGIntegerOptionalInteger::setValueAsString( | 70 SVGParsingError SVGIntegerOptionalInteger::setValueAsString( |
78 const String& value) { | 71 const String& value) { |
79 float x, y; | 72 float x, y; |
80 SVGParsingError parseStatus; | 73 SVGParsingError parseStatus; |
81 if (!parseNumberOptionalNumber(value, x, y)) { | 74 if (!parseNumberOptionalNumber(value, x, y)) { |
82 parseStatus = SVGParseStatus::ExpectedInteger; | 75 parseStatus = SVGParseStatus::ExpectedInteger; |
83 x = y = 0; | 76 x = y = 0; |
84 } | 77 } |
85 | 78 |
86 m_firstInteger->setValue(x); | 79 m_firstInteger->setValue(clampTo<int>(x)); |
87 m_secondInteger->setValue(y); | 80 m_secondInteger->setValue(clampTo<int>(y)); |
88 return parseStatus; | 81 return parseStatus; |
89 } | 82 } |
90 | 83 |
91 void SVGIntegerOptionalInteger::add(SVGPropertyBase* other, SVGElement*) { | 84 void SVGIntegerOptionalInteger::add(SVGPropertyBase* other, SVGElement*) { |
92 SVGIntegerOptionalInteger* otherIntegerOptionalInteger = | 85 SVGIntegerOptionalInteger* otherIntegerOptionalInteger = |
93 toSVGIntegerOptionalInteger(other); | 86 toSVGIntegerOptionalInteger(other); |
94 | 87 |
95 m_firstInteger->setValue( | 88 m_firstInteger->setValue( |
96 m_firstInteger->value() + | 89 m_firstInteger->value() + |
97 otherIntegerOptionalInteger->m_firstInteger->value()); | 90 otherIntegerOptionalInteger->m_firstInteger->value()); |
(...skipping 20 matching lines...) Expand all Loading... |
118 float x = m_firstInteger->value(); | 111 float x = m_firstInteger->value(); |
119 float y = m_secondInteger->value(); | 112 float y = m_secondInteger->value(); |
120 animationElement->animateAdditiveNumber( | 113 animationElement->animateAdditiveNumber( |
121 percentage, repeatCount, fromInteger->firstInteger()->value(), | 114 percentage, repeatCount, fromInteger->firstInteger()->value(), |
122 toInteger->firstInteger()->value(), | 115 toInteger->firstInteger()->value(), |
123 toAtEndOfDurationInteger->firstInteger()->value(), x); | 116 toAtEndOfDurationInteger->firstInteger()->value(), x); |
124 animationElement->animateAdditiveNumber( | 117 animationElement->animateAdditiveNumber( |
125 percentage, repeatCount, fromInteger->secondInteger()->value(), | 118 percentage, repeatCount, fromInteger->secondInteger()->value(), |
126 toInteger->secondInteger()->value(), | 119 toInteger->secondInteger()->value(), |
127 toAtEndOfDurationInteger->secondInteger()->value(), y); | 120 toAtEndOfDurationInteger->secondInteger()->value(), y); |
128 m_firstInteger->setValue(static_cast<int>(roundf(x))); | 121 m_firstInteger->setValue(clampTo<int>(roundf(x))); |
129 m_secondInteger->setValue(static_cast<int>(roundf(y))); | 122 m_secondInteger->setValue(clampTo<int>(roundf(y))); |
130 } | 123 } |
131 | 124 |
132 float SVGIntegerOptionalInteger::calculateDistance(SVGPropertyBase* other, | 125 float SVGIntegerOptionalInteger::calculateDistance(SVGPropertyBase* other, |
133 SVGElement*) { | 126 SVGElement*) { |
134 // FIXME: Distance calculation is not possible for SVGIntegerOptionalInteger | 127 // FIXME: Distance calculation is not possible for SVGIntegerOptionalInteger |
135 // right now. We need the distance for every single value. | 128 // right now. We need the distance for every single value. |
136 return -1; | 129 return -1; |
137 } | 130 } |
138 | 131 |
139 } // namespace blink | 132 } // namespace blink |
OLD | NEW |