LibWeb: Add support for select options disabled state
This commit is contained in:
parent
4408581ee0
commit
1475c1810f
Notes:
sideshowbarker
2024-07-17 03:45:48 +09:00
Author: https://github.com/bplaat Commit: https://github.com/SerenityOS/serenity/commit/1475c1810f Pull-request: https://github.com/SerenityOS/serenity/pull/23511 Reviewed-by: https://github.com/trflynn89
7 changed files with 10 additions and 8 deletions
|
@ -72,19 +72,16 @@
|
|||
<option value="8.01.1">Lecture 01: Powers of Ten
|
||||
<option value="8.01.2">Lecture 02: 1D Kinematics
|
||||
<option value="8.01.3">Lecture 03: Vectors
|
||||
<hr>
|
||||
<option value="8.01.4">Lecture 04: Random
|
||||
<optgroup label="8.02 Electricity and Magnetism">
|
||||
<optgroup label="8.02 Electricity and Magnetism (disabled)" disabled>
|
||||
<option value="8.02.1">Lecture 01: What holds our world together?
|
||||
<option value="8.02.2">Lecture 02: Electric Field
|
||||
<option value="8.02.3">Lecture 03: Electric Flux
|
||||
<hr>
|
||||
<option value="8.02.4">Lecture 04: Random
|
||||
<optgroup label="8.03 Physics III: Vibrations and Waves">
|
||||
<option value="8.03.1">Lecture 01: Periodic Phenomenon
|
||||
<option value="8.03.2">Lecture 02: Beats
|
||||
<option value="8.03.3">Lecture 03: Forced Oscillations with Damping
|
||||
<hr>
|
||||
<option value="8.03.4">Lecture 04: Random
|
||||
</select>
|
||||
Value: <span id="c-value">?</span>
|
||||
|
|
|
@ -714,7 +714,7 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
|
|||
auto add_menu_item = [self](Web::HTML::SelectItemOption const& item_option) {
|
||||
NSMenuItem* menuItem = [[NSMenuItem alloc]
|
||||
initWithTitle:Ladybird::string_to_ns_string(item_option.label)
|
||||
action:@selector(selectDropdownAction:)
|
||||
action:item_option.disabled ? nil : @selector(selectDropdownAction:)
|
||||
keyEquivalent:@""];
|
||||
menuItem.representedObject = [NSNumber numberWithUnsignedInt:item_option.id];
|
||||
menuItem.state = item_option.selected ? NSControlStateValueOn : NSControlStateValueOff;
|
||||
|
|
|
@ -336,6 +336,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
|
|||
QAction* action = new QAction(qstring_from_ak_string(item_option.label), this);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(item_option.selected);
|
||||
action->setDisabled(item_option.disabled);
|
||||
action->setData(QVariant(static_cast<uint>(item_option.id)));
|
||||
QObject::connect(action, &QAction::triggered, this, &Tab::select_dropdown_action);
|
||||
m_select_dropdown->addAction(action);
|
||||
|
|
|
@ -661,6 +661,7 @@ Tab::Tab(BrowserWindow& window)
|
|||
});
|
||||
action->set_checkable(true);
|
||||
action->set_checked(item_option.selected);
|
||||
action->set_enabled(!item_option.disabled);
|
||||
m_select_dropdown->add_action(action);
|
||||
};
|
||||
|
||||
|
|
|
@ -290,7 +290,7 @@ void HTMLSelectElement::activation_behavior(DOM::Event const&)
|
|||
for (auto const& child : opt_group_element.children_as_vector()) {
|
||||
if (is<HTMLOptionElement>(*child)) {
|
||||
auto& option_element = verify_cast<HTMLOptionElement>(*child);
|
||||
option_group_items.append(SelectItemOption { id_counter++, strip_newlines(option_element.text_content()), option_element.value(), option_element.selected(), option_element });
|
||||
option_group_items.append(SelectItemOption { id_counter++, strip_newlines(option_element.text_content()), option_element.value(), option_element.selected(), option_element.disabled(), option_element });
|
||||
}
|
||||
}
|
||||
m_select_items.append(SelectItemOptionGroup { opt_group_element.get_attribute(AttributeNames::label).value_or(String {}), option_group_items });
|
||||
|
@ -298,7 +298,7 @@ void HTMLSelectElement::activation_behavior(DOM::Event const&)
|
|||
|
||||
if (is<HTMLOptionElement>(*child)) {
|
||||
auto& option_element = verify_cast<HTMLOptionElement>(*child);
|
||||
m_select_items.append(SelectItemOption { id_counter++, strip_newlines(option_element.text_content()), option_element.value(), option_element.selected(), option_element });
|
||||
m_select_items.append(SelectItemOption { id_counter++, strip_newlines(option_element.text_content()), option_element.value(), option_element.selected(), option_element.disabled(), option_element });
|
||||
}
|
||||
|
||||
if (is<HTMLHRElement>(*child))
|
||||
|
|
|
@ -15,6 +15,7 @@ ErrorOr<void> IPC::encode(Encoder& encoder, Web::HTML::SelectItemOption const& i
|
|||
TRY(encoder.encode(item.label));
|
||||
TRY(encoder.encode(item.value));
|
||||
TRY(encoder.encode(item.selected));
|
||||
TRY(encoder.encode(item.disabled));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -25,7 +26,8 @@ ErrorOr<Web::HTML::SelectItemOption> IPC::decode(Decoder& decoder)
|
|||
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 };
|
||||
auto disabled = TRY(decoder.decode<bool>());
|
||||
return Web::HTML::SelectItemOption { id, move(label), move(value), selected, disabled };
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
|
@ -17,6 +17,7 @@ struct SelectItemOption {
|
|||
String label {};
|
||||
String value {};
|
||||
bool selected { false };
|
||||
bool disabled { false };
|
||||
JS::GCPtr<HTMLOptionElement> option_element {};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue