From a3feb46ad7f2bc249f350bb671e51ba108ae9d20 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 22 Jul 2020 01:16:27 +0200 Subject: [PATCH] LibWeb: Parse "width" and "height" presentation attributes on These are HTML lengths that map to CSS width and height respectively. --- Libraries/LibWeb/DOM/HTMLImageElement.cpp | 16 ++++++++++++++++ Libraries/LibWeb/DOM/HTMLImageElement.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/Libraries/LibWeb/DOM/HTMLImageElement.cpp b/Libraries/LibWeb/DOM/HTMLImageElement.cpp index 124b00b734..7c1d7e7e57 100644 --- a/Libraries/LibWeb/DOM/HTMLImageElement.cpp +++ b/Libraries/LibWeb/DOM/HTMLImageElement.cpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace Web { @@ -60,6 +61,21 @@ HTMLImageElement::~HTMLImageElement() { } +void HTMLImageElement::apply_presentational_hints(StyleProperties& style) const +{ + for_each_attribute([&](auto& name, auto& value) { + if (name == HTML::AttributeNames::width) { + if (auto parsed_value = parse_html_length(document(), value)) { + style.set_property(CSS::PropertyID::Width, parsed_value.release_nonnull()); + } + } else if (name == HTML::AttributeNames::height) { + if (auto parsed_value = parse_html_length(document(), value)) { + style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull()); + } + } + }); +} + void HTMLImageElement::parse_attribute(const FlyString& name, const String& value) { HTMLElement::parse_attribute(name, value); diff --git a/Libraries/LibWeb/DOM/HTMLImageElement.h b/Libraries/LibWeb/DOM/HTMLImageElement.h index b4a3c4b4d2..fff36b0359 100644 --- a/Libraries/LibWeb/DOM/HTMLImageElement.h +++ b/Libraries/LibWeb/DOM/HTMLImageElement.h @@ -51,6 +51,8 @@ public: const Gfx::Bitmap* bitmap() const; private: + virtual void apply_presentational_hints(StyleProperties&) const override; + void animate(); virtual RefPtr create_layout_node(const StyleProperties* parent_style) override;