diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index 1ca65c3b3d..945c8d925a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -179,4 +179,26 @@ unsigned HTMLImageElement::natural_height() const return 0; } +// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-complete +bool HTMLImageElement::complete() const +{ + // The IDL attribute complete must return true if any of the following conditions is true: + + // - Both the src attribute and the srcset attribute are omitted. + if (!has_attribute(HTML::AttributeNames::src) && !has_attribute(HTML::AttributeNames::srcset)) + return true; + + // - The srcset attribute is omitted and the src attribute's value is the empty string. + if (!has_attribute(HTML::AttributeNames::srcset) && attribute(HTML::AttributeNames::src) == ""sv) + return true; + + // - The img element's current request's state is completely available and its pending request is null. + // - The img element's current request's state is broken and its pending request is null. + // FIXME: This is ad-hoc and should be updated once we are loading images via the Fetch mechanism. + if (m_image_loader.has_loaded_or_failed()) + return true; + + return false; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h index 91384226f9..803ee9f339 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h @@ -40,6 +40,9 @@ public: unsigned natural_width() const; unsigned natural_height() const; + // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-complete + bool complete() const; + private: HTMLImageElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.idl index 5b759c9509..339c90fb13 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.idl @@ -18,4 +18,6 @@ interface HTMLImageElement : HTMLElement { readonly attribute unsigned long naturalWidth; readonly attribute unsigned long naturalHeight; + readonly attribute boolean complete; + };