Changeset 116540 in webkit
- Timestamp:
- May 9, 2012 10:06:19 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r116539 r116540 1 2012-05-09 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> 2 3 Simplify CSSParser::parseSimpleLengthValue() 4 https://bugs.webkit.org/show_bug.cgi?id=85910 5 6 Reviewed by Alexis Menard. 7 8 Various small improvements to this function, mainly: 9 - Move the check if the property ID accepts a simple length as early as possible; 10 - Remove the check for the characters{8,16} pointers since they'll be valid (we ASSERT that); 11 - Use a template to avoid duplicate code for 8 and 16 bit characters. 12 13 * css/CSSParser.cpp: 14 (WebCore): 15 (WebCore::parseSimpleLength): 16 (WebCore::parseSimpleLengthValue): 17 1 18 2012-05-09 Ami Fischman <fischman@chromium.org> 2 19 -
trunk/Source/WebCore/css/CSSParser.cpp
r116263 r116540 440 440 } 441 441 442 template <typename CharType> 443 static inline bool parseSimpleLength(const CharType* characters, unsigned& length, CSSPrimitiveValue::UnitTypes& unit, double& number) 444 { 445 if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') { 446 length -= 2; 447 unit = CSSPrimitiveValue::CSS_PX; 448 } else if (length > 1 && characters[length - 1] == '%') { 449 length -= 1; 450 unit = CSSPrimitiveValue::CSS_PERCENTAGE; 451 } 452 453 // We rely on charactersToDouble for validation as well. The function 454 // will set "ok" to "false" if the entire passed-in character range does 455 // not represent a double. 456 bool ok; 457 number = charactersToDouble(characters, length, &ok); 458 return ok; 459 } 460 442 461 static bool parseSimpleLengthValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode) 443 462 { 444 463 ASSERT(!string.isEmpty()); 445 464 bool acceptsNegativeNumbers; 446 bool strict = isStrictParserMode(cssParserMode); 465 if (!isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers)) 466 return false; 467 447 468 unsigned length = string.length(); 448 449 469 double number; 450 bool ok;451 470 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER; 452 471 453 472 if (string.is8Bit()) { 454 const LChar* characters8 = string.characters8(); 455 if (!characters8) 456 return false; 457 458 if (!isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers)) 459 return false; 460 461 if (length > 2 && (characters8[length - 2] | 0x20) == 'p' && (characters8[length - 1] | 0x20) == 'x') { 462 length -= 2; 463 unit = CSSPrimitiveValue::CSS_PX; 464 } else if (length > 1 && characters8[length - 1] == '%') { 465 length -= 1; 466 unit = CSSPrimitiveValue::CSS_PERCENTAGE; 467 } 468 469 // We rely on charactersToDouble for validation as well. The function 470 // will set "ok" to "false" if the entire passed-in character range does 471 // not represent a double. 472 number = charactersToDouble(characters8, length, &ok); 473 if (!parseSimpleLength(string.characters8(), length, unit, number)) 474 return false; 473 475 } else { 474 const UChar* characters16 = string.characters16(); 475 if (!characters16) 476 return false; 477 478 if (!isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers)) 479 return false; 480 481 if (length > 2 && (characters16[length - 2] | 0x20) == 'p' && (characters16[length - 1] | 0x20) == 'x') { 482 length -= 2; 483 unit = CSSPrimitiveValue::CSS_PX; 484 } else if (length > 1 && characters16[length - 1] == '%') { 485 length -= 1; 486 unit = CSSPrimitiveValue::CSS_PERCENTAGE; 487 } 488 489 // We rely on charactersToDouble for validation as well. The function 490 // will set "ok" to "false" if the entire passed-in character range does 491 // not represent a double. 492 number = charactersToDouble(characters16, length, &ok); 493 } 494 495 if (!ok) 496 return false; 476 if (!parseSimpleLength(string.characters16(), length, unit, number)) 477 return false; 478 } 479 497 480 if (unit == CSSPrimitiveValue::CSS_NUMBER) { 498 if (number && strict)481 if (number && isStrictParserMode(cssParserMode)) 499 482 return false; 500 483 unit = CSSPrimitiveValue::CSS_PX;
Note: See TracChangeset
for help on using the changeset viewer.