Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: Source/core/html/forms/RangeInputType.cpp

Issue 83413002: Derive the step base for an input element as (now) specified. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 bool RangeInputType::supportsRequired() const 118 bool RangeInputType::supportsRequired() const
119 { 119 {
120 return false; 120 return false;
121 } 121 }
122 122
123 StepRange RangeInputType::createStepRange(AnyStepHandling anyStepHandling) const 123 StepRange RangeInputType::createStepRange(AnyStepHandling anyStepHandling) const
124 { 124 {
125 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (rang eDefaultStep, rangeDefaultStepBase, rangeStepScaleFactor)); 125 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (rang eDefaultStep, rangeDefaultStepBase, rangeStepScaleFactor));
126 126
127 const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), r angeDefaultMinimum); 127 const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), S tring(), rangeDefaultMinimum);
128 const Decimal maximum = ensureMaximum(parseToNumber(element().fastGetAttribu te(maxAttr), rangeDefaultMaximum), minimum, rangeDefaultMaximum); 128 const Decimal maximum = ensureMaximum(parseToNumber(element().fastGetAttribu te(maxAttr), String(), rangeDefaultMaximum), minimum, rangeDefaultMaximum);
129 129
130 const AtomicString& precisionValue = element().fastGetAttribute(precisionAtt r); 130 const AtomicString& precisionValue = element().fastGetAttribute(precisionAtt r);
131 if (!precisionValue.isNull()) { 131 if (!precisionValue.isNull()) {
132 const Decimal step = equalIgnoringCase(precisionValue, "float") ? Decima l::nan() : 1; 132 const Decimal step = equalIgnoringCase(precisionValue, "float") ? Decima l::nan() : 1;
yosin_UTC9 2013/11/25 01:26:41 BTW, Can we stop supporting precsion="float"? If s
tkent 2013/11/25 01:36:33 We have UseCounter for precision attribute. We ca
133 return StepRange(minimum, minimum, maximum, step, stepDescription); 133 return StepRange(minimum, minimum, maximum, step, stepDescription);
134 } 134 }
135 135
136 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr)); 136 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr));
137 return StepRange(minimum, minimum, maximum, step, stepDescription); 137 return StepRange(minimum, minimum, maximum, step, stepDescription);
138 } 138 }
139 139
140 bool RangeInputType::isSteppable() const 140 bool RangeInputType::isSteppable() const
141 { 141 {
142 return true; 142 return true;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 RefPtr<HTMLElement> container = SliderContainerElement::create(document); 252 RefPtr<HTMLElement> container = SliderContainerElement::create(document);
253 container->appendChild(track.release()); 253 container->appendChild(track.release());
254 element().userAgentShadowRoot()->appendChild(container.release()); 254 element().userAgentShadowRoot()->appendChild(container.release());
255 } 255 }
256 256
257 RenderObject* RangeInputType::createRenderer(RenderStyle*) const 257 RenderObject* RangeInputType::createRenderer(RenderStyle*) const
258 { 258 {
259 return new RenderSlider(&element()); 259 return new RenderSlider(&element());
260 } 260 }
261 261
262 Decimal RangeInputType::parseToNumber(const String& src, const Decimal& defaultV alue) const 262 Decimal RangeInputType::parseToNumber(const String& src, const String& alternati ve, const Decimal& defaultValue) const
263 { 263 {
264 if (!alternative.isEmpty()) {
265 Decimal result = parseToDecimalForNumberType(src, Decimal::nan());
266 if (!result.isFinite())
267 result = parseToDecimalForNumberType(alternative, defaultValue);
268
269 return result;
270 }
264 return parseToDecimalForNumberType(src, defaultValue); 271 return parseToDecimalForNumberType(src, defaultValue);
265 } 272 }
266 273
267 String RangeInputType::serialize(const Decimal& value) const 274 String RangeInputType::serialize(const Decimal& value) const
268 { 275 {
269 if (!value.isFinite()) 276 if (!value.isFinite())
270 return String(); 277 return String();
271 return serializeForNumberType(value); 278 return serializeForNumberType(value);
272 } 279 }
273 280
(...skipping 24 matching lines...) Expand all
298 } 305 }
299 306
300 String RangeInputType::fallbackValue() const 307 String RangeInputType::fallbackValue() const
301 { 308 {
302 return serializeForNumberType(createStepRange(RejectAny).defaultValue()); 309 return serializeForNumberType(createStepRange(RejectAny).defaultValue());
303 } 310 }
304 311
305 String RangeInputType::sanitizeValue(const String& proposedValue) const 312 String RangeInputType::sanitizeValue(const String& proposedValue) const
306 { 313 {
307 StepRange stepRange(createStepRange(RejectAny)); 314 StepRange stepRange(createStepRange(RejectAny));
308 const Decimal proposedNumericValue = parseToNumber(proposedValue, stepRange. defaultValue()); 315 const Decimal proposedNumericValue = parseToNumber(proposedValue, String(), stepRange.defaultValue());
309 return serializeForNumberType(stepRange.clampValue(proposedNumericValue)); 316 return serializeForNumberType(stepRange.clampValue(proposedNumericValue));
310 } 317 }
311 318
312 bool RangeInputType::shouldRespectListAttribute() 319 bool RangeInputType::shouldRespectListAttribute()
313 { 320 {
314 return InputType::themeSupportsDataListUI(this); 321 return InputType::themeSupportsDataListUI(this);
315 } 322 }
316 323
317 inline SliderThumbElement* RangeInputType::sliderThumbElement() const 324 inline SliderThumbElement* RangeInputType::sliderThumbElement() const
318 { 325 {
(...skipping 28 matching lines...) Expand all
347 if (!dataList) 354 if (!dataList)
348 return; 355 return;
349 RefPtr<HTMLCollection> options = dataList->options(); 356 RefPtr<HTMLCollection> options = dataList->options();
350 m_tickMarkValues.reserveCapacity(options->length()); 357 m_tickMarkValues.reserveCapacity(options->length());
351 for (unsigned i = 0; i < options->length(); ++i) { 358 for (unsigned i = 0; i < options->length(); ++i) {
352 Node* node = options->item(i); 359 Node* node = options->item(i);
353 HTMLOptionElement* optionElement = toHTMLOptionElement(node); 360 HTMLOptionElement* optionElement = toHTMLOptionElement(node);
354 String optionValue = optionElement->value(); 361 String optionValue = optionElement->value();
355 if (!element().isValidValue(optionValue)) 362 if (!element().isValidValue(optionValue))
356 continue; 363 continue;
357 m_tickMarkValues.append(parseToNumber(optionValue, Decimal::nan())); 364 m_tickMarkValues.append(parseToNumber(optionValue, String(), Decimal::na n()));
358 } 365 }
359 m_tickMarkValues.shrinkToFit(); 366 m_tickMarkValues.shrinkToFit();
360 nonCopyingSort(m_tickMarkValues.begin(), m_tickMarkValues.end(), decimalComp are); 367 nonCopyingSort(m_tickMarkValues.begin(), m_tickMarkValues.end(), decimalComp are);
361 } 368 }
362 369
363 Decimal RangeInputType::findClosestTickMarkValue(const Decimal& value) 370 Decimal RangeInputType::findClosestTickMarkValue(const Decimal& value)
364 { 371 {
365 updateTickMarkValues(); 372 updateTickMarkValues();
366 if (!m_tickMarkValues.size()) 373 if (!m_tickMarkValues.size())
367 return Decimal::nan(); 374 return Decimal::nan();
(...skipping 19 matching lines...) Expand all
387 right = middle; 394 right = middle;
388 } 395 }
389 const Decimal closestLeft = middle ? m_tickMarkValues[middle - 1] : Decimal: :infinity(Decimal::Negative); 396 const Decimal closestLeft = middle ? m_tickMarkValues[middle - 1] : Decimal: :infinity(Decimal::Negative);
390 const Decimal closestRight = middle != m_tickMarkValues.size() ? m_tickMarkV alues[middle] : Decimal::infinity(Decimal::Positive); 397 const Decimal closestRight = middle != m_tickMarkValues.size() ? m_tickMarkV alues[middle] : Decimal::infinity(Decimal::Positive);
391 if (closestRight - value < value - closestLeft) 398 if (closestRight - value < value - closestLeft)
392 return closestRight; 399 return closestRight;
393 return closestLeft; 400 return closestLeft;
394 } 401 }
395 402
396 } // namespace WebCore 403 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698