mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 01:00:05 +00:00
LibWeb: Implement the HTMLInputElement.list
attribute
This returns the `HTMLDataListElement` pointed to by the `list` content attribute.
This commit is contained in:
parent
a37315da87
commit
6178557a07
Notes:
github-actions[bot]
2025-03-09 15:11:49 +00:00
Author: https://github.com/tcl3
Commit: 6178557a07
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3782
7 changed files with 164 additions and 1 deletions
|
@ -32,6 +32,7 @@
|
|||
#include <LibWeb/HTML/Dates.h>
|
||||
#include <LibWeb/HTML/DecodedImageData.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/HTML/HTMLDataListElement.h>
|
||||
#include <LibWeb/HTML/HTMLDivElement.h>
|
||||
#include <LibWeb/HTML/HTMLFormElement.h>
|
||||
#include <LibWeb/HTML/HTMLInputElement.h>
|
||||
|
@ -190,6 +191,39 @@ void HTMLInputElement::set_indeterminate(bool value)
|
|||
m_indeterminate = value;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#dom-input-list
|
||||
GC::Ptr<HTMLDataListElement const> HTMLInputElement::list() const
|
||||
{
|
||||
// The list IDL attribute must return the current suggestions source element, if any, or null otherwise.
|
||||
if (auto data_list_element = suggestions_source_element(); data_list_element.has_value())
|
||||
return *data_list_element;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#concept-input-list
|
||||
Optional<GC::Ref<HTMLDataListElement const>> HTMLInputElement::suggestions_source_element() const
|
||||
{
|
||||
// The suggestions source element is the first element in the tree in tree order to have an ID equal to the value of the list attribute,
|
||||
// if that element is a datalist element. If there is no list attribute, or if there is no element with that ID,
|
||||
// or if the first element with that ID is not a datalist element, then there is no suggestions source element.
|
||||
Optional<GC::Ref<HTMLDataListElement const>> result;
|
||||
if (auto list_attribute_value = get_attribute(HTML::AttributeNames::list); list_attribute_value.has_value()) {
|
||||
root().for_each_in_inclusive_subtree_of_type<DOM::Element>([&](auto& element) {
|
||||
if (element.id() == *list_attribute_value) {
|
||||
if (auto data_list_element = as_if<HTMLDataListElement>(element))
|
||||
result = *data_list_element;
|
||||
|
||||
return TraversalDecision::Break;
|
||||
}
|
||||
|
||||
return TraversalDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#compiled-pattern-regular-expression
|
||||
Optional<Regex<ECMA262>> HTMLInputElement::compiled_pattern_regular_expression() const
|
||||
{
|
||||
|
|
|
@ -106,6 +106,8 @@ public:
|
|||
bool indeterminate() const { return m_indeterminate; }
|
||||
void set_indeterminate(bool);
|
||||
|
||||
GC::Ptr<HTMLDataListElement const> list() const;
|
||||
|
||||
void did_pick_color(Optional<Color> picked_color, ColorPickerUpdateState state);
|
||||
|
||||
enum class MultipleHandling {
|
||||
|
@ -356,6 +358,8 @@ private:
|
|||
|
||||
Optional<Regex<ECMA262>> compiled_pattern_regular_expression() const;
|
||||
|
||||
Optional<GC::Ref<HTMLDataListElement const>> suggestions_source_element() const;
|
||||
|
||||
Optional<DOM::DocumentLoadEventDelayer> m_load_event_delayer;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#dom-input-indeterminate
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#import <HTML/HTMLDataListElement.idl>
|
||||
#import <HTML/HTMLElement.idl>
|
||||
#import <HTML/HTMLFormElement.idl>
|
||||
#import <HTML/PopoverInvokerElement.idl>
|
||||
|
@ -25,7 +26,7 @@ interface HTMLInputElement : HTMLElement {
|
|||
[CEReactions, Reflect=formtarget] attribute DOMString formTarget;
|
||||
[CEReactions] attribute unsigned long height;
|
||||
attribute boolean indeterminate;
|
||||
[FIXME] readonly attribute HTMLDataListElement? list;
|
||||
readonly attribute HTMLDataListElement? list;
|
||||
[CEReactions, Reflect] attribute DOMString max;
|
||||
[CEReactions] attribute long maxLength;
|
||||
[CEReactions, Reflect] attribute DOMString min;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue