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

Side by Side Diff: third_party/WebKit/Source/core/html/forms/InputType.cpp

Issue 2033323002: :in-range and :out-of-range CSS selectors should check 'have range limitations.' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) 7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
8 * Copyright (C) 2009, 2010, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2009, 2010, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2012 Samsung Electronics. All rights reserved. 9 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
10 * 10 *
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 return false; 285 return false;
286 286
287 // This function should return true if both of validity.rangeUnderflow and 287 // This function should return true if both of validity.rangeUnderflow and
288 // validity.rangeOverflow are false. 288 // validity.rangeOverflow are false.
289 // If the INPUT has no value, they are false. 289 // If the INPUT has no value, they are false.
290 const Decimal numericValue = parseToNumberOrNaN(value); 290 const Decimal numericValue = parseToNumberOrNaN(value);
291 if (!numericValue.isFinite()) 291 if (!numericValue.isFinite())
292 return true; 292 return true;
293 293
294 StepRange stepRange(createStepRange(RejectAny)); 294 StepRange stepRange(createStepRange(RejectAny));
295 return numericValue >= stepRange.minimum() && numericValue <= stepRange.maxi mum(); 295 return stepRange.hasRangeLimitations() && numericValue >= stepRange.minimum( ) && numericValue <= stepRange.maximum();
296 } 296 }
297 297
298 bool InputType::isOutOfRange(const String& value) const 298 bool InputType::isOutOfRange(const String& value) const
299 { 299 {
300 if (!isSteppable()) 300 if (!isSteppable())
301 return false; 301 return false;
302 302
303 // This function should return true if either validity.rangeUnderflow or 303 // This function should return true if either validity.rangeUnderflow or
304 // validity.rangeOverflow are true. 304 // validity.rangeOverflow are true.
305 // If the INPUT has no value, they are false. 305 // If the INPUT has no value, they are false.
306 const Decimal numericValue = parseToNumberOrNaN(value); 306 const Decimal numericValue = parseToNumberOrNaN(value);
307 if (!numericValue.isFinite()) 307 if (!numericValue.isFinite())
308 return false; 308 return false;
309 309
310 StepRange stepRange(createStepRange(RejectAny)); 310 StepRange stepRange(createStepRange(RejectAny));
311 return numericValue < stepRange.minimum() || numericValue > stepRange.maximu m(); 311 return stepRange.hasRangeLimitations() && (numericValue < stepRange.minimum( ) || numericValue > stepRange.maximum());
312 } 312 }
313 313
314 bool InputType::stepMismatch(const String& value) const 314 bool InputType::stepMismatch(const String& value) const
315 { 315 {
316 if (!isSteppable()) 316 if (!isSteppable())
317 return false; 317 return false;
318 318
319 const Decimal numericValue = parseToNumberOrNaN(value); 319 const Decimal numericValue = parseToNumberOrNaN(value);
320 if (!numericValue.isFinite()) 320 if (!numericValue.isFinite())
321 return false; 321 return false;
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 Decimal InputType::findStepBase(const Decimal& defaultValue) const 914 Decimal InputType::findStepBase(const Decimal& defaultValue) const
915 { 915 {
916 Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr), Decima l::nan()); 916 Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr), Decima l::nan());
917 if (!stepBase.isFinite()) 917 if (!stepBase.isFinite())
918 stepBase = parseToNumber(element().fastGetAttribute(valueAttr), defaultV alue); 918 stepBase = parseToNumber(element().fastGetAttribute(valueAttr), defaultV alue);
919 return stepBase; 919 return stepBase;
920 } 920 }
921 921
922 StepRange InputType::createStepRange(AnyStepHandling anyStepHandling, const Deci mal& stepBaseDefault, const Decimal& minimumDefault, const Decimal& maximumDefau lt, const StepRange::StepDescription& stepDescription) const 922 StepRange InputType::createStepRange(AnyStepHandling anyStepHandling, const Deci mal& stepBaseDefault, const Decimal& minimumDefault, const Decimal& maximumDefau lt, const StepRange::StepDescription& stepDescription) const
923 { 923 {
924 bool hasRangeLimitations = false;
924 const Decimal stepBase = findStepBase(stepBaseDefault); 925 const Decimal stepBase = findStepBase(stepBaseDefault);
925 const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), m inimumDefault); 926 Decimal minimum = parseToNumberOrNaN(element().fastGetAttribute(minAttr));
926 const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), m aximumDefault); 927 if (minimum.isFinite())
928 hasRangeLimitations = true;
929 else
930 minimum = minimumDefault;
931 Decimal maximum = parseToNumberOrNaN(element().fastGetAttribute(maxAttr));
932 if (maximum.isFinite())
933 hasRangeLimitations = true;
934 else
935 maximum = maximumDefault;
927 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr)); 936 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr));
928 return StepRange(stepBase, minimum, maximum, step, stepDescription); 937 return StepRange(stepBase, minimum, maximum, hasRangeLimitations, step, step Description);
929 } 938 }
930 939
931 void InputType::addWarningToConsole(const char* messageFormat, const String& val ue) const 940 void InputType::addWarningToConsole(const char* messageFormat, const String& val ue) const
932 { 941 {
933 element().document().addConsoleMessage(ConsoleMessage::create(RenderingMessa geSource, WarningMessageLevel, 942 element().document().addConsoleMessage(ConsoleMessage::create(RenderingMessa geSource, WarningMessageLevel,
934 String::format(messageFormat, JSONValue::quoteString(value).utf8().data( )))); 943 String::format(messageFormat, JSONValue::quoteString(value).utf8().data( ))));
935 } 944 }
936 945
937 } // namespace blink 946 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698