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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 TextFieldInputType::setValue(sanitizedValue, valueChanged, eventBehavior); | 116 TextFieldInputType::setValue(sanitizedValue, valueChanged, eventBehavior); |
117 } | 117 } |
118 | 118 |
119 double NumberInputType::valueAsDouble() const | 119 double NumberInputType::valueAsDouble() const |
120 { | 120 { |
121 return parseToDoubleForNumberType(element().value()); | 121 return parseToDoubleForNumberType(element().value()); |
122 } | 122 } |
123 | 123 |
124 void NumberInputType::setValueAsDouble(double newValue, TextFieldEventBehavior e
ventBehavior, ExceptionState& exceptionState) const | 124 void NumberInputType::setValueAsDouble(double newValue, TextFieldEventBehavior e
ventBehavior, ExceptionState& exceptionState) const |
125 { | 125 { |
126 // FIXME: We should use numeric_limits<double>::max for number input type. | |
127 // (NOTE: the range check will not be true for NaN.) | |
128 const double floatMax = numeric_limits<float>::max(); | |
129 if (newValue < -floatMax || newValue > floatMax) { | |
130 exceptionState.throwDOMException(InvalidStateError, "The value provided
(" + String::number(newValue) + ") is outside the range (" + String::number(-flo
atMax) + ", " + String::number(floatMax) + ")."); | |
131 return; | |
132 } | |
133 element().setValue(serializeForNumberType(newValue), eventBehavior); | 126 element().setValue(serializeForNumberType(newValue), eventBehavior); |
134 } | 127 } |
135 | 128 |
136 void NumberInputType::setValueAsDecimal(const Decimal& newValue, TextFieldEventB
ehavior eventBehavior, ExceptionState& exceptionState) const | 129 void NumberInputType::setValueAsDecimal(const Decimal& newValue, TextFieldEventB
ehavior eventBehavior, ExceptionState& exceptionState) const |
137 { | 130 { |
138 // FIXME: We should use numeric_limits<double>::max for number input type. | |
139 const Decimal floatMax = Decimal::fromDouble(numeric_limits<float>::max()); | |
140 if (newValue < -floatMax || newValue > floatMax) { | |
141 exceptionState.throwDOMException(InvalidStateError, "The value provided
(" + newValue.toString() + ") is outside the range (-" + floatMax.toString() + "
, " + floatMax.toString() + ")."); | |
142 return; | |
143 } | |
144 element().setValue(serializeForNumberType(newValue), eventBehavior); | 131 element().setValue(serializeForNumberType(newValue), eventBehavior); |
145 } | 132 } |
146 | 133 |
147 bool NumberInputType::typeMismatchFor(const String& value) const | 134 bool NumberInputType::typeMismatchFor(const String& value) const |
148 { | 135 { |
149 return !value.isEmpty() && !std::isfinite(parseToDoubleForNumberType(value))
; | 136 return !value.isEmpty() && !std::isfinite(parseToDoubleForNumberType(value))
; |
150 } | 137 } |
151 | 138 |
152 bool NumberInputType::typeMismatch() const | 139 bool NumberInputType::typeMismatch() const |
153 { | 140 { |
154 ASSERT(!typeMismatchFor(element().value())); | 141 ASSERT(!typeMismatchFor(element().value())); |
155 return false; | 142 return false; |
156 } | 143 } |
157 | 144 |
158 StepRange NumberInputType::createStepRange(AnyStepHandling anyStepHandling) cons
t | 145 StepRange NumberInputType::createStepRange(AnyStepHandling anyStepHandling) cons
t |
159 { | 146 { |
160 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (numb
erDefaultStep, numberDefaultStepBase, numberStepScaleFactor)); | 147 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (numb
erDefaultStep, numberDefaultStepBase, numberStepScaleFactor)); |
161 | 148 const Decimal doubleMax = Decimal::fromDouble(numeric_limits<double>::max())
; |
162 // FIXME: We should use numeric_limits<double>::max for number input type. | 149 return InputType::createStepRange(anyStepHandling, numberDefaultStepBase, -d
oubleMax, doubleMax, stepDescription); |
163 const Decimal floatMax = Decimal::fromDouble(numeric_limits<float>::max()); | |
164 return InputType::createStepRange(anyStepHandling, numberDefaultStepBase, -f
loatMax, floatMax, stepDescription); | |
165 } | 150 } |
166 | 151 |
167 bool NumberInputType::sizeShouldIncludeDecoration(int defaultSize, int& preferre
dSize) const | 152 bool NumberInputType::sizeShouldIncludeDecoration(int defaultSize, int& preferre
dSize) const |
168 { | 153 { |
169 preferredSize = defaultSize; | 154 preferredSize = defaultSize; |
170 | 155 |
171 const String stepString = element().fastGetAttribute(stepAttr); | 156 const String stepString = element().fastGetAttribute(stepAttr); |
172 if (equalIgnoringCase(stepString, "any")) | 157 if (equalIgnoringCase(stepString, "any")) |
173 return false; | 158 return false; |
174 | 159 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 if (element().renderer()) | 287 if (element().renderer()) |
303 element().renderer()->setNeedsLayoutAndPrefWidthsRecalc(); | 288 element().renderer()->setNeedsLayoutAndPrefWidthsRecalc(); |
304 } | 289 } |
305 | 290 |
306 bool NumberInputType::supportsSelectionAPI() const | 291 bool NumberInputType::supportsSelectionAPI() const |
307 { | 292 { |
308 return false; | 293 return false; |
309 } | 294 } |
310 | 295 |
311 } // namespace WebCore | 296 } // namespace WebCore |
OLD | NEW |