diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-22 01:13:18 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-22 01:13:18 +0200 |
commit | 5a7e57457ebb22af7f5df4e69186bc4778974240 (patch) | |
tree | 2800133946d354bc25180c41b1b05dae0c3a7575 /Libraries | |
parent | 9fc00d5d126a0b5ec1e155675e7a6f309c19b5dc (diff) | |
download | serenity-5a7e57457ebb22af7f5df4e69186bc4778974240.zip |
LibWeb: Add a dedicated function for parsing HTML length values
Presentation attribute lengths (width, height, etc.) can always be
unit-less (e.g "400") so going via the normal CSS parsing path only
works when the document is in quirks mode.
Add a separate parse_html_length() that always allows unit-less values.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/DOM/HTMLTableCellElement.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/DOM/HTMLTableElement.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Parser/CSSParser.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibWeb/Parser/CSSParser.h | 2 |
4 files changed, 12 insertions, 2 deletions
diff --git a/Libraries/LibWeb/DOM/HTMLTableCellElement.cpp b/Libraries/LibWeb/DOM/HTMLTableCellElement.cpp index 7a7a5fa994..3154acc55f 100644 --- a/Libraries/LibWeb/DOM/HTMLTableCellElement.cpp +++ b/Libraries/LibWeb/DOM/HTMLTableCellElement.cpp @@ -55,7 +55,7 @@ void HTMLTableCellElement::apply_presentational_hints(StyleProperties& style) co return; } if (name == HTML::AttributeNames::width) { - if (auto parsed_value = parse_css_value(CSS::ParsingContext(document()), value)) + if (auto parsed_value = parse_html_length(document(), value)) style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull()); return; } diff --git a/Libraries/LibWeb/DOM/HTMLTableElement.cpp b/Libraries/LibWeb/DOM/HTMLTableElement.cpp index 363001b7db..e337f3eda5 100644 --- a/Libraries/LibWeb/DOM/HTMLTableElement.cpp +++ b/Libraries/LibWeb/DOM/HTMLTableElement.cpp @@ -42,7 +42,7 @@ void HTMLTableElement::apply_presentational_hints(StyleProperties& style) const { for_each_attribute([&](auto& name, auto& value) { if (name == HTML::AttributeNames::width) { - if (auto parsed_value = parse_css_value(CSS::ParsingContext(document()), value)) + if (auto parsed_value = parse_html_length(document(), value)) style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull()); return; } diff --git a/Libraries/LibWeb/Parser/CSSParser.cpp b/Libraries/LibWeb/Parser/CSSParser.cpp index 9bc89980b0..3138190b70 100644 --- a/Libraries/LibWeb/Parser/CSSParser.cpp +++ b/Libraries/LibWeb/Parser/CSSParser.cpp @@ -928,4 +928,12 @@ RefPtr<StyleDeclaration> parse_css_declaration(const CSS::ParsingContext& contex return parser.parse_standalone_declaration(); } +RefPtr<StyleValue> parse_html_length(const Document& document, const StringView& string) +{ + auto integer = string.to_int(); + if (integer.has_value()) + return LengthStyleValue::create(Length::make_px(integer.value())); + return parse_css_value(CSS::ParsingContext(document), string); +} + } diff --git a/Libraries/LibWeb/Parser/CSSParser.h b/Libraries/LibWeb/Parser/CSSParser.h index dc38bb7c74..1426f72306 100644 --- a/Libraries/LibWeb/Parser/CSSParser.h +++ b/Libraries/LibWeb/Parser/CSSParser.h @@ -53,4 +53,6 @@ RefPtr<LengthStyleValue> parse_line_width(const CSS::ParsingContext&, const Stri RefPtr<ColorStyleValue> parse_color(const CSS::ParsingContext&, const StringView&); RefPtr<StringStyleValue> parse_line_style(const CSS::ParsingContext&, const StringView&); +RefPtr<StyleValue> parse_html_length(const Document&, const StringView&); + } |