diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index 440b92f8e2..5b654c1fc2 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -138,4 +138,28 @@ void HTMLImageElement::set_height(unsigned height) set_attribute(HTML::AttributeNames::height, String::number(height)); } +// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth +unsigned HTMLImageElement::natural_width() const +{ + // Return the density-corrected intrinsic width of the image, in CSS pixels, + // if the image has intrinsic dimensions and is available. + if (m_image_loader.has_image()) + return m_image_loader.width(); + + // ...or else 0. + return 0; +} + +// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalheight +unsigned HTMLImageElement::natural_height() const +{ + // Return the density-corrected intrinsic height of the image, in CSS pixels, + // if the image has intrinsic dimensions and is available. + if (m_image_loader.has_image()) + return m_image_loader.height(); + + // ...or else 0. + return 0; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h index c7b46db958..046a29fd64 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h @@ -39,6 +39,9 @@ public: unsigned height() const; void set_height(unsigned); + unsigned natural_width() const; + unsigned natural_height() const; + private: virtual void apply_presentational_hints(CSS::StyleProperties&) const override; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.idl index f805d45036..5b759c9509 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.idl @@ -15,5 +15,7 @@ interface HTMLImageElement : HTMLElement { [CEReactions] attribute unsigned long width; [CEReactions] attribute unsigned long height; + readonly attribute unsigned long naturalWidth; + readonly attribute unsigned long naturalHeight; };