| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 bool NumberInputType::typeMismatch() const | 159 bool NumberInputType::typeMismatch() const |
| 160 { | 160 { |
| 161 ASSERT(!typeMismatchFor(element().value())); | 161 ASSERT(!typeMismatchFor(element().value())); |
| 162 return false; | 162 return false; |
| 163 } | 163 } |
| 164 | 164 |
| 165 StepRange NumberInputType::createStepRange(AnyStepHandling anyStepHandling) cons
t | 165 StepRange NumberInputType::createStepRange(AnyStepHandling anyStepHandling) cons
t |
| 166 { | 166 { |
| 167 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (numb
erDefaultStep, numberDefaultStepBase, numberStepScaleFactor)); | 167 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (numb
erDefaultStep, numberDefaultStepBase, numberStepScaleFactor)); |
| 168 const Decimal stepBase = parseToDecimalForNumberType(element().fastGetAttrib
ute(minAttr), numberDefaultStepBase); | 168 |
| 169 const Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr),
element().fastGetAttribute(valueAttr), numberDefaultStepBase); |
| 169 // FIXME: We should use numeric_limits<double>::max for number input type. | 170 // FIXME: We should use numeric_limits<double>::max for number input type. |
| 170 const Decimal floatMax = Decimal::fromDouble(numeric_limits<float>::max()); | 171 const Decimal floatMax = Decimal::fromDouble(numeric_limits<float>::max()); |
| 171 const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), -
floatMax); | 172 const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), S
tring(), -floatMax); |
| 172 const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), f
loatMax); | 173 const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), S
tring(), floatMax); |
| 173 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription,
element().fastGetAttribute(stepAttr)); | 174 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription,
element().fastGetAttribute(stepAttr)); |
| 174 return StepRange(stepBase, minimum, maximum, step, stepDescription); | 175 return StepRange(stepBase, minimum, maximum, step, stepDescription); |
| 175 } | 176 } |
| 176 | 177 |
| 177 bool NumberInputType::sizeShouldIncludeDecoration(int defaultSize, int& preferre
dSize) const | 178 bool NumberInputType::sizeShouldIncludeDecoration(int defaultSize, int& preferre
dSize) const |
| 178 { | 179 { |
| 179 preferredSize = defaultSize; | 180 preferredSize = defaultSize; |
| 180 | 181 |
| 181 const String stepString = element().fastGetAttribute(stepAttr); | 182 const String stepString = element().fastGetAttribute(stepAttr); |
| 182 if (equalIgnoringCase(stepString, "any")) | 183 if (equalIgnoringCase(stepString, "any")) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 205 return true; | 206 return true; |
| 206 } | 207 } |
| 207 | 208 |
| 208 void NumberInputType::handleKeydownEvent(KeyboardEvent* event) | 209 void NumberInputType::handleKeydownEvent(KeyboardEvent* event) |
| 209 { | 210 { |
| 210 handleKeydownEventForSpinButton(event); | 211 handleKeydownEventForSpinButton(event); |
| 211 if (!event->defaultHandled()) | 212 if (!event->defaultHandled()) |
| 212 TextFieldInputType::handleKeydownEvent(event); | 213 TextFieldInputType::handleKeydownEvent(event); |
| 213 } | 214 } |
| 214 | 215 |
| 215 Decimal NumberInputType::parseToNumber(const String& src, const Decimal& default
Value) const | 216 Decimal NumberInputType::parseToNumber(const String& src, const String& alternat
ive, const Decimal& defaultValue) const |
| 216 { | 217 { |
| 218 if (!alternative.isEmpty()) { |
| 219 Decimal result = parseToDecimalForNumberType(src, Decimal::nan()); |
| 220 if (!result.isFinite()) |
| 221 result = parseToDecimalForNumberType(alternative, defaultValue); |
| 222 |
| 223 return result; |
| 224 } |
| 217 return parseToDecimalForNumberType(src, defaultValue); | 225 return parseToDecimalForNumberType(src, defaultValue); |
| 218 } | 226 } |
| 219 | 227 |
| 220 String NumberInputType::serialize(const Decimal& value) const | 228 String NumberInputType::serialize(const Decimal& value) const |
| 221 { | 229 { |
| 222 if (!value.isFinite()) | 230 if (!value.isFinite()) |
| 223 return String(); | 231 return String(); |
| 224 return serializeForNumberType(value); | 232 return serializeForNumberType(value); |
| 225 } | 233 } |
| 226 | 234 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 315 |
| 308 void NumberInputType::stepAttributeChanged() | 316 void NumberInputType::stepAttributeChanged() |
| 309 { | 317 { |
| 310 InputType::stepAttributeChanged(); | 318 InputType::stepAttributeChanged(); |
| 311 | 319 |
| 312 if (element().renderer()) | 320 if (element().renderer()) |
| 313 element().renderer()->setNeedsLayoutAndPrefWidthsRecalc(); | 321 element().renderer()->setNeedsLayoutAndPrefWidthsRecalc(); |
| 314 } | 322 } |
| 315 | 323 |
| 316 } // namespace WebCore | 324 } // namespace WebCore |
| OLD | NEW |