LibWeb: Refactor SelectItem to allow selecting options without value

Currently the `<select>` dropdown IPC uses the option value attr to
find which option is selected. This won't work when options don't
have values or when multiple options have the same value. Also the
`SelectItem` contained so weird recursive structures that are
impossible to create with HTML. So I refactored `SelectItem` as a
variant, and gave the options a unique id. The id is send back to
`HTMLSelectElement` so it can find out exactly which option element
is selected.
This commit is contained in:
Bastiaan van der Plaat 2024-04-03 19:19:08 +02:00 committed by Tim Flynn
commit 4408581ee0
Notes: sideshowbarker 2024-07-18 02:47:59 +09:00
21 changed files with 243 additions and 152 deletions

View file

@ -12,6 +12,7 @@
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/HTML/HTMLOptionsCollection.h>
#include <LibWeb/HTML/SelectItem.h>
namespace Web::HTML {
@ -78,7 +79,7 @@ public:
virtual void form_associated_element_was_inserted() override;
virtual void form_associated_element_was_removed(DOM::Node*) override;
void did_select_value(Optional<String> value);
void did_select_item(Optional<u32> const& id);
private:
HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
@ -93,9 +94,11 @@ private:
void create_shadow_tree_if_needed();
void update_inner_text_element();
void queue_input_and_change_events();
JS::GCPtr<HTMLOptionsCollection> m_options;
bool m_is_open { false };
Vector<SelectItem> m_select_items;
JS::GCPtr<DOM::Element> m_inner_text_element;
JS::GCPtr<DOM::Element> m_chevron_icon_element;
};