From 0455af4441d64ab0ec5e9f6cabaa94f5de8ac02e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 3 Oct 2022 14:54:27 +0200 Subject: LibWeb: Implement HTMLImageElement.complete This was fairly straightforward, although a small part had to be ad-hoc since we don't yet load images through Fetch. With this, we can now see annotation labels on deskto.ps :^) --- .../Libraries/LibWeb/HTML/HTMLImageElement.cpp | 22 ++++++++++++++++++++++ Userland/Libraries/LibWeb/HTML/HTMLImageElement.h | 3 +++ .../Libraries/LibWeb/HTML/HTMLImageElement.idl | 2 ++ 3 files changed, 27 insertions(+) (limited to 'Userland/Libraries/LibWeb/HTML') 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; + }; -- cgit v1.2.3