Files
ladybird/Userland/Libraries/LibWeb/HTML/SelectItem.h
Bastiaan van der Plaat 4408581ee0 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.
2024-04-08 17:24:48 -04:00

55 lines
1.1 KiB
C++

/*
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <LibIPC/Forward.h>
#include <LibWeb/HTML/HTMLOptionElement.h>
namespace Web::HTML {
struct SelectItemOption {
u32 id { 0 };
String label {};
String value {};
bool selected { false };
JS::GCPtr<HTMLOptionElement> option_element {};
};
struct SelectItemOptionGroup {
String label = {};
Vector<SelectItemOption> items = {};
};
struct SelectItemSeparator { };
using SelectItem = Variant<SelectItemOption, SelectItemOptionGroup, SelectItemSeparator>;
}
namespace IPC {
template<>
ErrorOr<void> encode(Encoder&, Web::HTML::SelectItemOption const&);
template<>
ErrorOr<Web::HTML::SelectItemOption> decode(Decoder&);
template<>
ErrorOr<void> encode(Encoder&, Web::HTML::SelectItemOptionGroup const&);
template<>
ErrorOr<Web::HTML::SelectItemOptionGroup> decode(Decoder&);
template<>
ErrorOr<void> encode(Encoder&, Web::HTML::SelectItemSeparator const&);
template<>
ErrorOr<Web::HTML::SelectItemSeparator> decode(Decoder&);
}