diff options
author | Andreas Kling <kling@serenityos.org> | 2022-10-03 14:54:27 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-10-03 17:22:08 +0200 |
commit | 0455af4441d64ab0ec5e9f6cabaa94f5de8ac02e (patch) | |
tree | a260576c7c6580480619acd14d0eafd59e9d6fd5 /Userland/Libraries/LibWeb/HTML | |
parent | 9749eda09fde78c3cd54cecb90191cb2556eae8f (diff) | |
download | serenity-0455af4441d64ab0ec5e9f6cabaa94f5de8ac02e.zip |
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 :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp | 22 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLImageElement.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLImageElement.idl | 2 |
3 files changed, 27 insertions, 0 deletions
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; + }; |