Changeset 278689 in webkit
- Timestamp:
- Jun 9, 2021, 8:17:05 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/html/HTMLElement.cpp (modified) (1 diff)
-
Source/WebCore/html/parser/HTMLParserIdioms.cpp (modified) (2 diffs)
-
Source/WebCore/html/parser/HTMLParserIdioms.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r278665 r278689 1 2021-06-09 Cathie Chen <cathiechen@igalia.com> 2 3 Aspect ratio from width and height attribute is not compatible to string with invalid ends 4 https://bugs.webkit.org/show_bug.cgi?id=226469 5 6 Reviewed by Antti Koivisto. 7 8 * web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt: 9 1 10 2021-06-09 Alex Christensen <achristensen@webkit.org> 2 11 -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/rendering/replaced-elements/attributes-for-embedded-content-and-images/img-aspect-ratio-expected.txt
r278299 r278689 5 5 PASS Create, append and test immediately: <img> with attributes width=0.8, height=0.2 6 6 PASS Create, append and test immediately: <img> with attributes width=50% height=25% 7 FAIL Create, append and test immediately: <img> with invalid trailing attributes width=50pp height=25xx assert_approx_equals: expected 2 +/- 0.001 but got Infinity 7 PASS Create, append and test immediately: <img> with invalid trailing attributes width=50pp height=25xx 8 8 PASS Computed style test: img with {"width":"10","height":"20"} 9 9 PASS Computed style test: input with {"type":"image","width":"10","height":"20"} -
trunk/Source/WebCore/ChangeLog
r278683 r278689 1 2021-06-09 Cathie Chen <cathiechen@igalia.com> 2 3 Aspect ratio from width and height attribute is not compatible to string with invalid ends 4 https://bugs.webkit.org/show_bug.cgi?id=226469 5 6 Reviewed by Antti Koivisto. 7 8 The patch follows the steps defined in [1] to parse the dimension values from the attribute values. 9 It adds HTMLDimension to present the dimension value which has two types, Percentage and Pixel. 10 And parseHTMLDimension() follows the specification steps to check validation and parse the dimension 11 value. Currently, it is only used by parsing aspect-ratio from width and height attributes. It will 12 apply to other attributes length parse in the future patch. 13 14 [1] https://html.spec.whatwg.org/#rules-for-parsing-dimension-values 15 16 * html/HTMLElement.cpp: 17 (WebCore::HTMLElement::applyAspectRatioFromWidthAndHeightAttributesToStyle): Call parseHTMLDimension to get the length values. 18 * html/parser/HTMLParserIdioms.cpp: 19 (WebCore::parseHTMLDimensionNumber): 20 (WebCore::parseHTMLDimension): 21 * html/parser/HTMLParserIdioms.h: 22 1 23 2021-06-09 Andres Gonzalez <andresg_22@apple.com> 2 24 -
trunk/Source/WebCore/html/HTMLElement.cpp
r278575 r278689 631 631 return; 632 632 633 double width = parseValidHTMLFloatingPointNumber(attributeWithoutSynchronization(widthAttr)).value_or(-1);634 if ( width < 0)633 auto dimensionWidth = parseHTMLDimension(attributeWithoutSynchronization(widthAttr)); 634 if (!dimensionWidth || dimensionWidth->type != HTMLDimension::Type::Pixel) 635 635 return; 636 double height = parseValidHTMLFloatingPointNumber(attributeWithoutSynchronization(heightAttr)).value_or(-1);637 if ( height < 0)636 auto dimensionHeight = parseHTMLDimension(attributeWithoutSynchronization(heightAttr)); 637 if (!dimensionHeight || dimensionHeight->type != HTMLDimension::Type::Pixel) 638 638 return; 639 639 640 640 auto ratioList = CSSValueList::createSlashSeparated(); 641 ratioList->append(CSSValuePool::singleton().createValue( width, CSSUnitType::CSS_NUMBER));642 ratioList->append(CSSValuePool::singleton().createValue( height, CSSUnitType::CSS_NUMBER));641 ratioList->append(CSSValuePool::singleton().createValue(dimensionWidth->number, CSSUnitType::CSS_NUMBER)); 642 ratioList->append(CSSValuePool::singleton().createValue(dimensionHeight->number, CSSUnitType::CSS_NUMBER)); 643 643 auto list = CSSValueList::createSpaceSeparated(); 644 644 list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueAuto)); -
trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp
r278340 r278689 27 27 28 28 #include "Decimal.h" 29 #include "ParsingUtilities.h" 29 30 #include "QualifiedName.h" 30 31 #include <limits> … … 476 477 } 477 478 478 } 479 struct HTMLDimensionParsingResult { 480 double number; 481 unsigned parsedLength; 482 }; 483 484 template <typename CharacterType> 485 static std::optional<HTMLDimensionParsingResult> parseHTMLDimensionNumber(const CharacterType* position, unsigned length) 486 { 487 if (!length || !position) 488 return std::nullopt; 489 490 const auto* begin = position; 491 const auto* end = position + length; 492 skipWhile<isHTMLSpace>(position, end); 493 if (position == end) 494 return std::nullopt; 495 496 auto* start = position; 497 skipWhile<isASCIIDigit>(position, end); 498 if (start == position) 499 return std::nullopt; 500 501 if (skipExactly(position, end, '.')) 502 skipWhile<isASCIIDigit>(position, end); 503 504 size_t parsedLength = 0; 505 double number = parseDouble(start, position - start, parsedLength); 506 if (!(parsedLength && std::isfinite(number))) 507 return std::nullopt; 508 509 HTMLDimensionParsingResult result; 510 result.number = number; 511 result.parsedLength = position - begin; 512 return result; 513 } 514 515 std::optional<HTMLDimension> parseHTMLDimension(StringView dimensionString) 516 { 517 std::optional<HTMLDimensionParsingResult> result; 518 auto length = dimensionString.length(); 519 if (dimensionString.is8Bit()) 520 result = parseHTMLDimensionNumber(dimensionString.characters8(), length); 521 else 522 result = parseHTMLDimensionNumber(dimensionString.characters16(), length); 523 if (!result) 524 return std::nullopt; 525 526 HTMLDimension dimension; 527 dimension.number = result->number; 528 dimension.type = HTMLDimension::Type::Pixel; 529 if (result->parsedLength < dimensionString.length() && dimensionString[result->parsedLength] == '%') 530 dimension.type = HTMLDimension::Type::Percentage; 531 return dimension; 532 } 533 534 } -
trunk/Source/WebCore/html/parser/HTMLParserIdioms.h
r278253 r278689 87 87 AtomString parseHTMLHashNameReference(StringView); 88 88 89 // https://html.spec.whatwg.org/#rules-for-parsing-dimension-values 90 struct HTMLDimension { 91 enum class Type : bool { Percentage, Pixel }; 92 double number; 93 Type type; 94 }; 95 std::optional<HTMLDimension> parseHTMLDimension(StringView); 96 89 97 // Inline implementations of some of the functions declared above. 90 98
Note:
See TracChangeset
for help on using the changeset viewer.