| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return newValue; | 80 return newValue; |
| 81 | 81 |
| 82 return stepMismatch(currentValue) ? newValue : roundByStep(newValue, m_stepB
ase); | 82 return stepMismatch(currentValue) ? newValue : roundByStep(newValue, m_stepB
ase); |
| 83 } | 83 } |
| 84 | 84 |
| 85 Decimal StepRange::clampValue(const Decimal& value) const | 85 Decimal StepRange::clampValue(const Decimal& value) const |
| 86 { | 86 { |
| 87 const Decimal inRangeValue = max(m_minimum, min(value, m_maximum)); | 87 const Decimal inRangeValue = max(m_minimum, min(value, m_maximum)); |
| 88 if (!m_hasStep) | 88 if (!m_hasStep) |
| 89 return inRangeValue; | 89 return inRangeValue; |
| 90 // Rounds inRangeValue to minimum + N * step. | 90 // Rounds inRangeValue to stepBase + N * step. |
| 91 const Decimal roundedValue = roundByStep(inRangeValue, m_minimum); | 91 const Decimal roundedValue = roundByStep(inRangeValue, m_stepBase); |
| 92 const Decimal clampedValue = roundedValue > m_maximum ? roundedValue - m_ste
p : roundedValue; | 92 const Decimal clampedValue = roundedValue > m_maximum ? roundedValue - m_ste
p : (roundedValue < m_minimum ? roundedValue + m_step : roundedValue); |
| 93 ASSERT(clampedValue >= m_minimum); | 93 ASSERT(clampedValue >= m_minimum); |
| 94 ASSERT(clampedValue <= m_maximum); | 94 ASSERT(clampedValue <= m_maximum); |
| 95 return clampedValue; | 95 return clampedValue; |
| 96 } | 96 } |
| 97 | 97 |
| 98 Decimal StepRange::parseStep(AnyStepHandling anyStepHandling, const StepDescript
ion& stepDescription, const String& stepString) | 98 Decimal StepRange::parseStep(AnyStepHandling anyStepHandling, const StepDescript
ion& stepDescription, const String& stepString) |
| 99 { | 99 { |
| 100 if (stepString.isEmpty()) | 100 if (stepString.isEmpty()) |
| 101 return stepDescription.defaultValue(); | 101 return stepDescription.defaultValue(); |
| 102 | 102 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // ... that number subtracted from the step base is not an integral multiple | 161 // ... that number subtracted from the step base is not an integral multiple |
| 162 // of the allowed value step, the element is suffering from a step mismatch. | 162 // of the allowed value step, the element is suffering from a step mismatch. |
| 163 const Decimal remainder = (value - m_step * (value / m_step).round()).abs(); | 163 const Decimal remainder = (value - m_step * (value / m_step).round()).abs(); |
| 164 // Accepts erros in lower fractional part which IEEE 754 single-precision | 164 // Accepts erros in lower fractional part which IEEE 754 single-precision |
| 165 // can't represent. | 165 // can't represent. |
| 166 const Decimal computedAcceptableError = acceptableError(); | 166 const Decimal computedAcceptableError = acceptableError(); |
| 167 return computedAcceptableError < remainder && remainder < (m_step - computed
AcceptableError); | 167 return computedAcceptableError < remainder && remainder < (m_step - computed
AcceptableError); |
| 168 } | 168 } |
| 169 | 169 |
| 170 } // namespace WebCore | 170 } // namespace WebCore |
| OLD | NEW |