mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 21:29:06 +00:00
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:
parent
94d72c174a
commit
4408581ee0
Notes:
sideshowbarker
2024-07-18 02:47:59 +09:00
Author: https://github.com/bplaat
Commit: 4408581ee0
Pull-request: https://github.com/SerenityOS/serenity/pull/23511
Reviewed-by: https://github.com/trflynn89
21 changed files with 243 additions and 152 deletions
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue