
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.
57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "SelectItem.h"
|
|
#include <LibIPC/Decoder.h>
|
|
#include <LibIPC/Encoder.h>
|
|
|
|
template<>
|
|
ErrorOr<void> IPC::encode(Encoder& encoder, Web::HTML::SelectItemOption const& item)
|
|
{
|
|
TRY(encoder.encode(item.id));
|
|
TRY(encoder.encode(item.label));
|
|
TRY(encoder.encode(item.value));
|
|
TRY(encoder.encode(item.selected));
|
|
return {};
|
|
}
|
|
|
|
template<>
|
|
ErrorOr<Web::HTML::SelectItemOption> IPC::decode(Decoder& decoder)
|
|
{
|
|
auto id = TRY(decoder.decode<u32>());
|
|
auto label = TRY(decoder.decode<String>());
|
|
auto value = TRY(decoder.decode<String>());
|
|
auto selected = TRY(decoder.decode<bool>());
|
|
return Web::HTML::SelectItemOption { id, move(label), move(value), selected };
|
|
}
|
|
|
|
template<>
|
|
ErrorOr<void> IPC::encode(Encoder& encoder, Web::HTML::SelectItemOptionGroup const& item)
|
|
{
|
|
TRY(encoder.encode(item.label));
|
|
TRY(encoder.encode(item.items));
|
|
return {};
|
|
}
|
|
|
|
template<>
|
|
ErrorOr<Web::HTML::SelectItemOptionGroup> IPC::decode(Decoder& decoder)
|
|
{
|
|
auto label = TRY(decoder.decode<String>());
|
|
auto items = TRY(decoder.decode<Vector<Web::HTML::SelectItemOption>>());
|
|
return Web::HTML::SelectItemOptionGroup { move(label), move(items) };
|
|
}
|
|
|
|
template<>
|
|
ErrorOr<void> IPC::encode(Encoder&, Web::HTML::SelectItemSeparator const&)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
template<>
|
|
ErrorOr<Web::HTML::SelectItemSeparator> IPC::decode(Decoder&)
|
|
{
|
|
return Web::HTML::SelectItemSeparator {};
|
|
}
|