Truly independent web browser
LibWeb: Honor option styles in list boxes
sideshowbarkere850eb835a7a
diff --git a/Libraries/LibWeb/CSS/Default.css b/Libraries/LibWeb/CSS/Default.cssindex eceb4c8f9f8..3b00d128f21 100644--- a/Libraries/LibWeb/CSS/Default.css+++ b/Libraries/LibWeb/CSS/Default.css@@ -171,6 +171,36 @@ option, optgroup {display: block;}+select:is([multiple], [size]:not([size="0"], [size="1"])) {+ & option, & optgroup::before {+ min-block-size: 1.2em;+ line-height: 1.2em;+ padding-inline: 4px;+ user-select: none;+ }+ & optgroup::before {+ display: block;+ content: attr(label);+ font-weight: bold;+ }+ & optgroup optgroup {+ display: none !important;+ }+ & optgroup > option {+ padding-inline-start: 1.25em;+ }+ & option:disabled {+ color: GrayText;+ }+ & option:checked {+ background-color: color-mix(in srgb, currentcolor 22%, transparent);+ }+ &:focus option:checked {+ background-color: AccentColor !important;+ color: AccentColorText !important;+ }+}+/* Custom <input type="range"> styles */input[type=range] {display: inline-block;diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Libraries/LibWeb/HTML/HTMLOptionElement.cppindex 42933b98ec2..eb27ef90f78 100644--- a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp@@ -13,6 +13,7 @@#include <LibWeb/DOM/DocumentFragment.h>#include <LibWeb/DOM/ElementFactory.h>#include <LibWeb/DOM/Node.h>+#include <LibWeb/DOM/ShadowRoot.h>#include <LibWeb/DOM/Text.h>#include <LibWeb/HTML/HTMLDataListElement.h>#include <LibWeb/HTML/HTMLHRElement.h>@@ -60,6 +61,22 @@ void HTMLOptionElement::update_selection_label()update_label_sizer_text();}+void HTMLOptionElement::update_list_box_label()+{+ auto text = Infra::strip_and_collapse_whitespace(display_label());+ if (auto root = shadow_root()) {+ auto& label_text = as<DOM::Text>(*root->first_child());+ if (label_text.data() != text)+ label_text.set_data(text);+ return;+ }++ auto root = DOM::ShadowRoot::create(document(), *this, DOM::ShadowRootMode::Closed);+ root->set_user_agent_internal(true);+ set_shadow_root(root);+ MUST(root->append_child(document().create_text_node(move(text))));+}+void HTMLOptionElement::update_label_sizer_text(){GC::Ptr<DOM::Element> label_sizer;@@ -177,10 +194,7 @@ void HTMLOptionElement::set_selected_internal(bool selected)}}- bool const changed = m_selected != selected;m_selected = selected;- if (changed && m_cached_nearest_select_element)- m_cached_nearest_select_element->list_box_option_selectedness_did_change(*this);if (selected)m_selectedness_update_index = m_next_selectedness_update_index++;}@@ -359,6 +373,8 @@ void HTMLOptionElement::update_nearest_select_element()++new_select->m_number_of_selected_options;}m_cached_nearest_select_element = new_select;+ if (shadow_root() && (!new_select || !new_select->renders_as_list_box()))+ set_shadow_root(nullptr);update_label_sizer_text();if (old_select)old_select->list_box_options_did_change();diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.h b/Libraries/LibWeb/HTML/HTMLOptionElement.hindex 4f686d50b13..e012c195147 100644--- a/Libraries/LibWeb/HTML/HTMLOptionElement.h+++ b/Libraries/LibWeb/HTML/HTMLOptionElement.h@@ -72,6 +72,7 @@ private:void ask_for_a_reset();void update_selection_label();void update_label_sizer_text();+ void update_list_box_label();Utf16String display_label() const;// https://html.spec.whatwg.org/multipage/form-elements.html#update-an-option's-nearest-ancestor-selectdiff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Libraries/LibWeb/HTML/HTMLSelectElement.cppindex c473361d6ff..003c31225df 100644--- a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp@@ -29,6 +29,7 @@#include <LibWeb/HTML/HTMLOptionElement.h>#include <LibWeb/HTML/HTMLSelectElement.h>#include <LibWeb/HTML/HTMLSelectedContentElement.h>+#include <LibWeb/HTML/HTMLSlotElement.h>#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/HTML/Numbers.h>#include <LibWeb/HTML/Scripting/Environments.h>@@ -76,10 +77,8 @@ void HTMLSelectElement::visit_edges(Cell::Visitor& visitor)visitor.visit(m_cached_list_of_options);visitor.visit(m_select_item_option_elements);visitor.visit(m_list_box_element);- for (auto const& row : m_list_box_rows) {- visitor.visit(row.element);- visitor.visit(row.option);- }+ visitor.visit(m_list_box_slot);+ visitor.visit(m_list_box_options);}// https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-size@@ -683,7 +682,12 @@ void HTMLSelectElement::form_associated_element_attribute_changed(Utf16FlyStringm_chevron_icon_element = nullptr;m_chevron_icon_hidden = false;m_list_box_element = nullptr;- m_list_box_rows.clear();+ m_list_box_slot = nullptr;+ for (auto& option : list_of_options()) {+ if (option->shadow_root())+ option->set_shadow_root(nullptr);+ }+ m_list_box_options.clear();m_list_box_anchor_index = {};m_list_box_focus_index = {};create_shadow_tree_if_needed();@@ -1102,6 +1106,9 @@ void HTMLSelectElement::create_list_box_shadow_tree(DOM::ShadowRoot& shadow_root{m_list_box_element = MUST(DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML));MUST(shadow_root.append_child(*m_list_box_element));+ shadow_root.set_slot_assignment(DOM::SlotAssignmentMode::Manual);+ m_list_box_slot = as<HTMLSlotElement>(*MUST(DOM::create_element(document(), TagNames::slot, Namespace::HTML)));+ MUST(m_list_box_element->append_child(*m_list_box_slot));auto mousedown_function = JS::NativeFunction::create(HTML::relevant_realm(*this), GC::create_function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)>(GC::Heap::the(), GC::captures(*this), [](auto& self, JS::VM& vm) {@@ -1133,52 +1140,6 @@ void HTMLSelectElement::list_box_options_did_change()}));}-void HTMLSelectElement::update_list_box_row_styles()-{- for (auto const& row : m_list_box_rows)- update_list_box_row_style(row.element, row.option);-}--void HTMLSelectElement::did_receive_focus()-{- m_list_box_is_focused = true;- update_list_box_row_styles();-}--void HTMLSelectElement::did_lose_focus()-{- m_list_box_is_focused = false;- update_list_box_row_styles();-}--void HTMLSelectElement::list_box_option_selectedness_did_change(HTMLOptionElement const& option)-{- if (!m_list_box_element)- return;- for (auto const& row : m_list_box_rows) {- if (row.option.ptr() == &option) {- update_list_box_row_style(row.element, option);- return;- }- }-}--void HTMLSelectElement::update_list_box_row_style(DOM::Element& row, HTMLOptionElement const& option) const-{- StringBuilder style;- style.append("display: block; min-block-size: 1.2em; line-height: 1.2em; padding-inline: 4px; user-select: none;"sv);- if (as_if<HTMLOptGroupElement>(option.parent()))- style.append(" padding-inline-start: 1.25em;"sv);- // NB: The selection of a list box without focus is gray, so that it stands out less than one the keys move.- if (option.selected() && m_list_box_is_focused)- style.append(" background-color: AccentColor; color: AccentColorText;"sv);- else if (option.selected())- style.append(" background-color: color-mix(in srgb, currentcolor 22%, transparent);"sv);- else if (option.disabled())- style.append(" color: GrayText;"sv);- row.set_attribute_value(HTML::AttributeNames::style, Utf16String::from_utf8(style.string_view()));-}-void HTMLSelectElement::update_list_box(){VERIFY(m_list_box_element);@@ -1189,49 +1150,40 @@ void HTMLSelectElement::update_list_box()// NB: The rows are built again whenever the options change, so the anchor and focus of a range selection are kept// on the options they were on, as long as those still have a row.auto option_at = [&](Optional<size_t> index) -> GC::Ptr<HTMLOptionElement> {- if (!index.has_value() || *index >= m_list_box_rows.size())+ if (!index.has_value() || *index >= m_list_box_options.size())return nullptr;- return m_list_box_rows[*index].option;+ return m_list_box_options[*index];};auto anchor_option = option_at(m_list_box_anchor_index);auto focus_option = option_at(m_list_box_focus_index);- m_list_box_rows.clear();+ m_list_box_options.clear();m_list_box_anchor_index = {};m_list_box_focus_index = {};- m_list_box_element->replace_all(nullptr);-- auto append_option_row = [&](HTMLOptionElement& option) {- if (option.has_attribute(AttributeNames::hidden))- return;- auto row = MUST(DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML));- MUST(row->append_child(document().create_text_node(Infra::strip_and_collapse_whitespace(option.display_label()))));- update_list_box_row_style(row, option);- MUST(m_list_box_element->append_child(row));- m_list_box_rows.append({ row, option });+ GC::RootVector<HTMLSlotElement::SlottableHandle> assigned;+ auto append_option = [&](HTMLOptionElement& option) {+ option.update_list_box_label();+ m_list_box_options.append(option);};-- for (auto const& child : children_as_vector()) {+ for (auto& child : children_as_vector()) {if (auto* option = as_if<HTMLOptionElement>(*child)) {- append_option_row(*option);+ assigned.append(GC::Ref { static_cast<DOM::Element&>(*option) });+ append_option(*option);} else if (auto* group = as_if<HTMLOptGroupElement>(*child)) {- if (group->has_attribute(AttributeNames::hidden))- continue;- auto label_row = MUST(DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML));- label_row->set_attribute_value(HTML::AttributeNames::style, "display: block; min-block-size: 1.2em; line-height: 1.2em; padding-inline: 4px; font-weight: bold; user-select: none;"_utf16);- MUST(label_row->append_child(document().create_text_node(group->get_attribute(AttributeNames::label).value_or({}))));- MUST(m_list_box_element->append_child(label_row));- for (auto const& group_child : group->children_as_vector()) {- if (auto* group_option = as_if<HTMLOptionElement>(*group_child))- append_option_row(*group_option);- }+ assigned.append(GC::Ref { static_cast<DOM::Element&>(*group) });+ group->for_each_in_subtree_of_type<HTMLOptionElement>([&](auto& option) {+ if (option.nearest_select_element().ptr() == this)+ append_option(option);+ return TraversalDecision::SkipChildrenAndContinue;+ });}}+ m_list_box_slot->assign(move(assigned));auto index_of = [&](GC::Ptr<HTMLOptionElement> option) -> Optional<size_t> {if (!option)return {};- return m_list_box_rows.find_first_index_if([&](auto const& row) { return row.option == option; });+ return m_list_box_options.find_first_index_if([&](auto const& entry) { return entry == option; });};m_list_box_anchor_index = index_of(anchor_option);m_list_box_focus_index = index_of(focus_option);@@ -1242,21 +1194,16 @@ void HTMLSelectElement::handle_list_box_mousedown(UIEvents::MouseEvent& event)if (event.button() != 0 || !is_mutable())return;- // Find the row that was pressed, as the child of the list box that holds the event's target.auto* node = as_if<DOM::Node>(event.target().ptr());- while (node && node->parent() != m_list_box_element.ptr())+ while (node && node != this && !is<HTMLOptionElement>(*node))node = node->parent();- if (!node)+ if (!node || node == this || !m_list_box_element)return;+ if (m_list_box_update_queued)+ update_list_box();- Optional<size_t> index;- for (size_t i = 0; i < m_list_box_rows.size(); ++i) {- if (m_list_box_rows[i].element.ptr() == node) {- index = i;- break;- }- }- if (!index.has_value() || m_list_box_rows[*index].option->disabled())+ auto index = m_list_box_options.find_first_index_if([&](auto const& option) { return option.ptr() == node; });+ if (!index.has_value() || m_list_box_options[*index]->disabled())return;// NB: Pressing an option chooses it. In a multiple select, a press with Ctrl or Cmd held toggles the option, and a@@ -1268,7 +1215,7 @@ void HTMLSelectElement::handle_list_box_mousedown(UIEvents::MouseEvent& event)return;}- auto& option = m_list_box_rows[*index].option;+ auto& option = m_list_box_options[*index];option->set_selected(!option->selected());m_list_box_anchor_index = *index;m_list_box_focus_index = *index;@@ -1294,11 +1241,11 @@ void HTMLSelectElement::choose_list_box_row(size_t index, bool extend)auto first = min(*m_list_box_anchor_index, index);auto last = max(*m_list_box_anchor_index, index);for (size_t i = first; i <= last; ++i) {- if (!m_list_box_rows[i].option->disabled())- set_selectedness(*m_list_box_rows[i].option, true);+ if (!m_list_box_options[i]->disabled())+ set_selectedness(*m_list_box_options[i], true);}} else {- set_selectedness(*m_list_box_rows[index].option, true);+ set_selectedness(*m_list_box_options[index], true);m_list_box_anchor_index = index;}update_selectedness();@@ -1306,7 +1253,7 @@ void HTMLSelectElement::choose_list_box_row(size_t index, bool extend)Bindings::ScrollIntoViewOptions scroll_options;scroll_options.block = Bindings::ScrollLogicalPosition::Nearest;scroll_options.inline_ = Bindings::ScrollLogicalPosition::Nearest;- m_list_box_rows[index].element->scroll_into_view(scroll_options, nullptr);+ m_list_box_options[index]->scroll_into_view(scroll_options, nullptr);bool changed = false;for (size_t i = 0; i < m_cached_list_of_options.size(); ++i) {@@ -1319,7 +1266,7 @@ void HTMLSelectElement::choose_list_box_row(size_t index, bool extend)bool HTMLSelectElement::handle_list_box_key(UIEvents::KeyCode key, u32 modifiers){- if (m_list_box_rows.is_empty() || !is_mutable())+ if (m_list_box_options.is_empty() || !is_mutable())return false;if (modifiers != UIEvents::Mod_None && modifiers != UIEvents::Mod_Shift)return false;@@ -1327,19 +1274,22 @@ bool HTMLSelectElement::handle_list_box_key(UIEvents::KeyCode key, u32 modifiers// NB: The keys move from the option last chosen, or from the first selected option.Optional<size_t> current = m_list_box_focus_index;if (!current.has_value()) {- for (size_t i = 0; i < m_list_box_rows.size(); ++i) {- if (m_list_box_rows[i].option->selected()) {+ for (size_t i = 0; i < m_list_box_options.size(); ++i) {+ if (m_list_box_options[i]->selected()) {current = i;break;}}}- auto is_choosable = [&](size_t i) { return !m_list_box_rows[i].option->disabled(); };+ auto is_choosable = [&](size_t i) {+ auto const& option = *m_list_box_options[i];+ return !option.disabled() && !option.get_client_rects().is_empty();+ };Optional<size_t> target;switch (key) {case UIEvents::KeyCode::Key_Down:- for (size_t i = current.has_value() ? *current + 1 : 0; i < m_list_box_rows.size(); ++i) {+ for (size_t i = current.has_value() ? *current + 1 : 0; i < m_list_box_options.size(); ++i) {if (is_choosable(i)) {target = i;break;@@ -1348,7 +1298,7 @@ bool HTMLSelectElement::handle_list_box_key(UIEvents::KeyCode key, u32 modifiersbreak;case UIEvents::KeyCode::Key_Up:// NB: Without a current option, Up starts from the end of the list.- for (size_t i = current.value_or(m_list_box_rows.size()); i-- > 0;) {+ for (size_t i = current.value_or(m_list_box_options.size()); i-- > 0;) {if (is_choosable(i)) {target = i;break;@@ -1356,7 +1306,7 @@ bool HTMLSelectElement::handle_list_box_key(UIEvents::KeyCode key, u32 modifiers}break;case UIEvents::KeyCode::Key_Home:- for (size_t i = 0; i < m_list_box_rows.size(); ++i) {+ for (size_t i = 0; i < m_list_box_options.size(); ++i) {if (is_choosable(i)) {target = i;break;@@ -1364,7 +1314,7 @@ bool HTMLSelectElement::handle_list_box_key(UIEvents::KeyCode key, u32 modifiers}break;case UIEvents::KeyCode::Key_End:- for (size_t i = m_list_box_rows.size(); i-- > 0;) {+ for (size_t i = m_list_box_options.size(); i-- > 0;) {if (is_choosable(i)) {target = i;break;diff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Libraries/LibWeb/HTML/HTMLSelectElement.hindex 1c0dc7aa51f..3403cb4eb66 100644--- a/Libraries/LibWeb/HTML/HTMLSelectElement.h+++ b/Libraries/LibWeb/HTML/HTMLSelectElement.h@@ -126,7 +126,6 @@ public:// https://html.spec.whatwg.org/multipage/rendering.html#the-select-element-2bool renders_as_list_box() const;void list_box_options_did_change();- void list_box_option_selectedness_did_change(HTMLOptionElement const&);bool handle_list_box_key(UIEvents::KeyCode, u32 modifiers);bool can_skip_selectedness_update_for_inserted_option(HTMLOptionElement const&) const;@@ -188,20 +187,12 @@ private:void create_list_box_shadow_tree(DOM::ShadowRoot&);void update_list_box();- void update_list_box_row_style(DOM::Element& row, HTMLOptionElement const&) const;- void update_list_box_row_styles();- virtual void did_receive_focus() override;- virtual void did_lose_focus() override;- bool m_list_box_is_focused { false };void handle_list_box_mousedown(UIEvents::MouseEvent&);void choose_list_box_row(size_t index, bool extend);GC::Ptr<DOM::Element> m_list_box_element;- struct ListBoxRow {- GC::Ref<DOM::Element> element;- GC::Ref<HTMLOptionElement> option;- };- Vector<ListBoxRow> m_list_box_rows;+ GC::Ptr<HTMLSlotElement> m_list_box_slot;+ Vector<GC::Ref<HTMLOptionElement>> m_list_box_options;Optional<size_t> m_list_box_anchor_index;Optional<size_t> m_list_box_focus_index;bool m_list_box_update_queued { false };diff --git a/Libraries/LibWeb/Rust/src/css/parser/arbitrary_substitution.rs b/Libraries/LibWeb/Rust/src/css/parser/arbitrary_substitution.rsindex 937c9775175..e00104c182a 100644--- a/Libraries/LibWeb/Rust/src/css/parser/arbitrary_substitution.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/arbitrary_substitution.rs@@ -333,6 +333,15 @@ impl AttrNamesRead {}}+ pub(crate) fn include(&mut self, other: &Self) {+ let count = self.names.len();+ self.names.extend(other.names.iter().cloned());+ if self.names.len() != count || (other.any_name && !self.any_name) {+ self.generation += 1;+ }+ self.any_name |= other.any_name;+ }+/// The bytes the names hold on the heap.pub(crate) fn heap_size(&self) -> usize {crate::heap_size::set_bytes(&self.names)diff --git a/Libraries/LibWeb/Rust/src/css/style/host_atoms.rs b/Libraries/LibWeb/Rust/src/css/style/host_atoms.rsindex 8732de4249e..3b84bc5cce1 100644--- a/Libraries/LibWeb/Rust/src/css/style/host_atoms.rs+++ b/Libraries/LibWeb/Rust/src/css/style/host_atoms.rs@@ -432,9 +432,16 @@ pub(crate) fn note_attr_names_read_by_change(host: &DocumentHost, change: &Arenadeclarations: Some(declarations),..} => note_attr_names_read_by_block(host, declarations),+ Rule::AddUserAgentSheet { source_identity, .. } => {+ let rules = crate::render_state::process_style().user_agent_rules();+ host.engine_memo()+ .atoms+ .borrow_mut()+ .attr_names_read+ .include(rules.attr_names_read(*source_identity));+ }Rule::RuleDeclarations { declarations: None, .. }| Rule::AddSheet { .. }- | Rule::AddUserAgentSheet { .. }| Rule::BeginSheetRulesReplacement(_)| Rule::ReplaceSelectors { .. }| Rule::RemoveRules(_)diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/user_agent.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/user_agent.rsindex 14efcc77eed..9a14ededf99 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/user_agent.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/user_agent.rs@@ -12,6 +12,7 @@//! [`UserAgentVariant`], the key of the user agent index it decides with.use super::{RuleID, RuleStore, SheetID};+use crate::css::parser::arbitrary_substitution::AttrNamesRead;use crate::css::style::atoms::DocumentAtoms;use crate::css::style::selector_analysis::SelectorSummary;use crate::fork::ForkShared;@@ -44,6 +45,7 @@ struct UserAgentSheet {sheet: SheetID,/// What a document learns of the selectors of the sheet's rules as it attaches the sheet.selectors: Arc<SelectorSummary>,+ attr_names: Arc<AttrNamesRead>,/// The references that keep the names the sheet's rules declare interned._atoms: ForkShared<DocumentAtoms>,}@@ -64,11 +66,26 @@ impl UserAgentRules {selectors: SelectorSummary,atoms: ForkShared<DocumentAtoms>,) -> Self {+ let mut attr_names = AttrNamesRead::default();+ for rule in store.all_rules_in_sheet(sheet) {+ for value in store+ .written_values_of(rule)+ .iter()+ .chain(store.custom_written_values_of(rule))+ {+ if let Some(unresolved) =+ crate::css::style::custom_property_cascade::unresolved_reading_attributes(value.data())+ {+ attr_names.note(unresolved.components().as_ref());+ }+ }+ }let mut sheets = self.sheets.clone();sheets.push(UserAgentSheet {source_identity,sheet,selectors: Arc::new(selectors),+ attr_names: Arc::new(attr_names),_atoms: atoms,});Self { store, sheets }@@ -82,6 +99,15 @@ impl UserAgentRules {.map(|sheet| sheet.sheet)}+ pub(in crate::css::style) fn attr_names_read(&self, source_identity: u64) -> &AttrNamesRead {+ &self+ .sheets+ .iter()+ .find(|sheet| sheet.source_identity == source_identity)+ .expect("the process published the sheet")+ .attr_names+ }+/// What the selectors of the rules of `sheet` say to a document attaching it.pub(in crate::css::style) fn selector_summary(&self, sheet: SheetID) -> Arc<SelectorSummary> {let sheet = self.sheets.iter().find(|candidate| candidate.sheet == sheet);@@ -90,7 +116,18 @@ impl UserAgentRules {/// The bytes of the table, the first time `sizer` reaches each thing it holds.pub(in crate::css::style) fn heap_size(&self, sizer: &mut crate::heap_size::HeapSizer) -> usize {- self.store.heap_size(sizer) + self.sheets.len() * size_of::<UserAgentSheet>()+ let names = self+ .sheets+ .iter()+ .map(|sheet| {+ if sizer.first_sight(Arc::as_ptr(&sheet.attr_names)) {+ size_of::<AttrNamesRead>() + sheet.attr_names.heap_size()+ } else {+ 0+ }+ })+ .sum::<usize>();+ self.store.heap_size(sizer) + self.sheets.len() * size_of::<UserAgentSheet>() + names}/// The bytes of the declarations of the rules, the first time `sizer` reaches each.diff --git a/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txt b/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txtindex 40f7c507cc2..e202534679c 100644--- a/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txt+++ b/Tests/LibWeb/Layout/expected/select-list-box-optgroup-attribute-changes.txt@@ -4,22 +4,24 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenfrag 0 from BlockContainer start: 0, length: 0, rect: [9,10 69.84375x128] baseline: 129BlockContainer <select> at [9,10] inline-block [0+1+0 69.84375 0+1+0] [0+1+1 128 1+1+0] [BFC] children: not-inlineBlockContainer <div> at [9,10] [0+0+0 69.84375 0+0+0] [0+0+0 128 0+0+0] [BFC] children: not-inline- BlockContainer <div> at [13,10] [0+0+4 61.84375 4+0+0] [0+0+0 16 0+0+0] children: inline- frag 0 from TextNode start: 0, length: 9, rect: [13,11 61.84375x14] baseline: 11- "New label"- TextNode <#text> (not painted)- BlockContainer <div> at [25.65625,26] [0+0+16.65625 49.1875 4+0+0] [0+0+0 16 0+0+0] children: inline- frag 0 from TextNode start: 0, length: 1, rect: [25.65625,27 7.78125x14] baseline: 11- "B"- TextNode <#text> (not painted)- BlockContainer <div> at [13,42] [0+0+4 61.84375 4+0+0] [0+0+0 16 0+0+0] children: inline- frag 0 from TextNode start: 0, length: 8, rect: [13,43 53.875x14] baseline: 11- "Disabled"- TextNode <#text> (not painted)- BlockContainer <div> at [25.65625,58] [0+0+16.65625 49.1875 4+0+0] [0+0+0 16 0+0+0] children: inline- frag 0 from TextNode start: 0, length: 1, rect: [25.65625,59 8.59375x14] baseline: 11- "C"- TextNode <#text> (not painted)+ BlockContainer <optgroup#relabeled> at [9,10] [0+0+0 69.84375 0+0+0] [0+0+0 32 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [13,10] [0+0+4 61.84375 4+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from GeneratedTextNode start: 0, length: 9, rect: [13,11 61.84375x14] baseline: 11+ "New label"+ GeneratedTextNode <(anonymous)> (not painted)+ BlockContainer <option> at [25.65625,26] [0+0+16.65625 49.1875 4+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from TextNode start: 0, length: 1, rect: [25.65625,27 7.78125x14] baseline: 11+ "B"+ TextNode <#text> (not painted)+ BlockContainer <optgroup#disabled> at [9,42] [0+0+0 69.84375 0+0+0] [0+0+0 32 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [13,42] [0+0+4 61.84375 4+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from GeneratedTextNode start: 0, length: 8, rect: [13,43 53.875x14] baseline: 11+ "Disabled"+ GeneratedTextNode <(anonymous)> (not painted)+ BlockContainer <option> at [25.65625,58] [0+0+16.65625 49.1875 4+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from TextNode start: 0, length: 1, rect: [25.65625,59 8.59375x14] baseline: 11+ "C"+ TextNode <#text> (not painted)TextNode <#text> (not painted)SC for Viewport<#document> [0,0 800x600] (z-index: auto)diff --git a/Tests/LibWeb/Layout/expected/select-list-box-optgroups-replace-children.txt b/Tests/LibWeb/Layout/expected/select-list-box-optgroups-replace-children.txtindex 46148402640..931b537d11e 100644--- a/Tests/LibWeb/Layout/expected/select-list-box-optgroups-replace-children.txt+++ b/Tests/LibWeb/Layout/expected/select-list-box-optgroups-replace-children.txt@@ -4,14 +4,16 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenfrag 0 from BlockContainer start: 0, length: 0, rect: [9,10 55.8125x64] baseline: 65BlockContainer <select> at [9,10] inline-block [0+1+0 55.8125 0+1+0] [0+1+1 64 1+1+0] [BFC] children: not-inlineBlockContainer <div> at [9,10] [0+0+0 55.8125 0+0+0] [0+0+0 64 0+0+0] [BFC] children: not-inline- BlockContainer <div> at [13,10] [0+0+4 47.8125 4+0+0] [0+0+0 16 0+0+0] children: inline- frag 0 from TextNode start: 0, length: 5, rect: [13,11 35.109375x14] baseline: 11- "First"- TextNode <#text> (not painted)- BlockContainer <div> at [13,26] [0+0+4 47.8125 4+0+0] [0+0+0 16 0+0+0] children: inline- frag 0 from TextNode start: 0, length: 6, rect: [13,27 47.8125x14] baseline: 11- "Second"- TextNode <#text> (not painted)+ BlockContainer <optgroup> at [9,10] [0+0+0 55.8125 0+0+0] [0+0+0 16 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [13,10] [0+0+4 47.8125 4+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from GeneratedTextNode start: 0, length: 5, rect: [13,11 35.109375x14] baseline: 11+ "First"+ GeneratedTextNode <(anonymous)> (not painted)+ BlockContainer <optgroup> at [9,26] [0+0+0 55.8125 0+0+0] [0+0+0 16 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [13,26] [0+0+4 47.8125 4+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from GeneratedTextNode start: 0, length: 6, rect: [13,27 47.8125x14] baseline: 11+ "Second"+ GeneratedTextNode <(anonymous)> (not painted)TextNode <#text> (not painted)SC for Viewport<#document> [0,0 800x600] (z-index: auto)diff --git a/Tests/LibWeb/Ref/expected/select-list-box-author-option-style.html b/Tests/LibWeb/Ref/expected/select-list-box-author-option-style.htmlnew file mode 100644index 00000000000..ae6ba5b0128--- /dev/null+++ b/Tests/LibWeb/Ref/expected/select-list-box-author-option-style.html@@ -0,0 +1,2 @@+<!doctype html>+<select multiple><option>one</option><optgroup label="group"><option>two</option></optgroup></select>diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-display/select-4-option-optgroup-display-none-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-display/select-4-option-optgroup-display-none-ref.htmlnew file mode 100644index 00000000000..8fc87bdd269--- /dev/null+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-display/select-4-option-optgroup-display-none-ref.html@@ -0,0 +1,45 @@+<!DOCTYPE HTML>+<!--+ Any copyright is dedicated to the Public Domain.+ http://creativecommons.org/publicdomain/zero/1.0/+-->+<html><head>+ <meta charset="utf-8">+ <title>Reference: display:none on OPTION and OPTGROUP</title>+ <link rel="author" title="Mats Palmgren" href="mailto:[email protected]">+ <style>++.none { display:none; }+.contents { display:contents; }+.red { color: red; }+.green { color: green; }++select { -webkit-appearance: none; }++:root {+ will-change: transform;+}++ </style>+</head>+<body>++<pre>FAIL if there is any red color</pre>++<optgroup></optgroup>+<optgroup class="contents red"></optgroup>+<optgroup class="contents green" label="optgroup"></optgroup>++<br>++<select class="red" size="4"></select>+<select size="4" class="red"></select>+<select size="4" class="red"></select>+<select size="4" class="red"><optgroup></select>+<select size="4"></select>+<select size="4" class="red"></select>+<select size="4" class="red"></select>+<select size="4" class="red"></select>++</body>+</html>diff --git a/Tests/LibWeb/Ref/input/select-list-box-author-option-style.html b/Tests/LibWeb/Ref/input/select-list-box-author-option-style.htmlnew file mode 100644index 00000000000..b48fa96538b--- /dev/null+++ b/Tests/LibWeb/Ref/input/select-list-box-author-option-style.html@@ -0,0 +1,8 @@+<!doctype html>+<link rel="mismatch" href="../expected/select-list-box-author-option-style.html">+<style>.marked { color: blue; background: yellow; font: bold 20px monospace; }</style>+<select multiple><option>one</option><optgroup label="group"><option>two</option></optgroup></select>+<script>+ document.body.offsetWidth;+ document.querySelector("optgroup option").classList.add("marked");+</script>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-display/select-4-option-optgroup-display-none.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-display/select-4-option-optgroup-display-none.htmlnew file mode 100644index 00000000000..e4442508f39--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-display/select-4-option-optgroup-display-none.html@@ -0,0 +1,54 @@+<!DOCTYPE HTML>+<!--+ Any copyright is dedicated to the Public Domain.+ http://creativecommons.org/publicdomain/zero/1.0/+-->+<html><head>+ <meta charset="utf-8">+ <title>CSS Test: display:none on OPTION and OPTGROUP</title>+ <link rel="author" title="Mats Palmgren" href="mailto:[email protected]">+ <link rel="help" href="https://drafts.csswg.org/css-display-3/#valdef-display-none">+ <link rel="match" href="../../../../expected/wpt-import/css/css-display/select-4-option-optgroup-display-none-ref.html">+ <style>++.none { display:none; }+.contents { display:contents; }+.red { color: red; }+.green { color: green; }++select { -webkit-appearance: none; }++:root {+ /* Setting will-change:transform here and in the reference file fixes+ subpixel rendering differences of rounded corners. */+ will-change: transform;+}++ </style>+</head>+<body>++<pre>FAIL if there is any red color</pre>++<option class="none red">text</option>+<optgroup class="none red">text</optgroup>++<optgroup class="none red"><option>option</option></optgroup>+<optgroup><option class="none red">option</option></optgroup>+<optgroup class="contents red"><option class="none">option</option></optgroup>+<optgroup class="contents green" label="optgroup"><option class="none red">option</option></optgroup>+<optgroup class="none red" label="optgroup"><option class="red">option</option></optgroup>++<br>++<select class="red" size="4">select</select>+<select size="4" class="red"><optgroup class="none" label="optgroup"></select>+<select size="4" class="red"><option class="none">option</select>+<select size="4" class="red"><optgroup><option class="none">option</select>+<select size="4"><optgroup class="none"><option class="green">option</select>+<select size="4" class="red"><optgroup class="none green" label="optgroup"><option>option</select>+<select size="4" class="red"><optgroup class="none"><option class="none">option</select>+<select size="4" class="red"><optgroup class="none green" label="optgroup"><option class="none">option</select>++</body>+</html>diff --git a/Tests/LibWeb/Text/expected/select-list-box-author-hidden-options.txt b/Tests/LibWeb/Text/expected/select-list-box-author-hidden-options.txtnew file mode 100644index 00000000000..5fa145d4d09--- /dev/null+++ b/Tests/LibWeb/Text/expected/select-list-box-author-hidden-options.txt@@ -0,0 +1,7 @@+ArrowDown skips hidden and disabled options: E+ArrowUp reaches the newly visible option: C+Range includes hidden options but skips disabled options: A,B,C,E+Down reaches the displayed hidden option: B+Down reaches the option in the displayed hidden group: C+Clicked displayed option: B+Displayed option label: Displayed optiondiff --git a/Tests/LibWeb/Text/expected/select-list-box-remove-pressed-option.txt b/Tests/LibWeb/Text/expected/select-list-box-remove-pressed-option.txtnew file mode 100644index 00000000000..a85911b272c--- /dev/null+++ b/Tests/LibWeb/Text/expected/select-list-box-remove-pressed-option.txt@@ -0,0 +1,3 @@+Pressed option removed: true+Selected options: A+Removed option selected: falsediff --git a/Tests/LibWeb/Text/expected/select-list-box-wrapped-option.txt b/Tests/LibWeb/Text/expected/select-list-box-wrapped-option.txtnew file mode 100644index 00000000000..d344113857d--- /dev/null+++ b/Tests/LibWeb/Text/expected/select-list-box-wrapped-option.txt@@ -0,0 +1,5 @@+Nested group option has no row: true+A displayed nested group still has no option row: true+Down from A: B+Down from B: C+Clicked B: Bdiff --git a/Tests/LibWeb/Text/input/select-list-box-author-hidden-options.html b/Tests/LibWeb/Text/input/select-list-box-author-hidden-options.htmlnew file mode 100644index 00000000000..3d9779678fa--- /dev/null+++ b/Tests/LibWeb/Text/input/select-list-box-author-hidden-options.html@@ -0,0 +1,44 @@+<!doctype html>+<script src="include.js"></script>+<style>.skip { display: none; }</style>+<select id="list" size="6">+ <option selected>A</option>+ <option class="skip">B</option>+ <optgroup class="skip" label="Group"><option>C</option></optgroup>+ <option disabled>D</option>+ <option>E</option>+</select>+<script>+ promiseTest(async () => {+ const list = document.getElementById("list");+ list.focus();+ internals.sendKey(list, "Down");+ println("ArrowDown skips hidden and disabled options: " + list.value);+ list.querySelector("optgroup").classList.remove("skip");+ internals.sendKey(list, "Up");+ println("ArrowUp reaches the newly visible option: " + list.value);++ list.multiple = true;+ list.querySelector("optgroup").classList.add("skip");+ internals.sendKey(list, "Home");+ internals.sendKey(list, "End", internals.MOD_SHIFT);+ println("Range includes hidden options but skips disabled options: " + [...list.selectedOptions].map(option => option.label).join(","));+ list.options[1].label = "Displayed option";+ for (const hidden of [list.options[1], list.querySelector("optgroup")]) {+ hidden.classList.remove("skip");+ hidden.hidden = true;+ hidden.style.display = "block";+ }+ await new Promise(resolve => setTimeout(resolve, 0));+ internals.sendKey(list, "Home");+ internals.sendKey(list, "Down");+ println("Down reaches the displayed hidden option: " + list.value);+ internals.sendKey(list, "Down");+ println("Down reaches the option in the displayed hidden group: " + list.value);+ const option = list.options[1];+ const rect = option.getBoundingClientRect();+ internals.click(rect.x + rect.width / 2, rect.y + rect.height / 2);+ println("Clicked displayed option: " + list.value);+ println("Displayed option label: " + internals.getShadowRoot(option)?.textContent);+ });+</script>diff --git a/Tests/LibWeb/Text/input/select-list-box-remove-pressed-option.html b/Tests/LibWeb/Text/input/select-list-box-remove-pressed-option.htmlnew file mode 100644index 00000000000..7762f83277c--- /dev/null+++ b/Tests/LibWeb/Text/input/select-list-box-remove-pressed-option.html@@ -0,0 +1,15 @@+<!doctype html>+<script src="include.js"></script>+<select multiple size="4"><option selected>A</option><option>B</option><option>C</option></select>+<script>+ test(() => {+ const select = document.querySelector("select");+ const option = select.options[1];+ option.addEventListener("mousedown", () => option.remove(), { once: true });+ const rect = option.getBoundingClientRect();+ internals.mouseDown(rect.x + 4, rect.y + rect.height / 2, 1, 0, 0);+ println("Pressed option removed: " + !option.isConnected);+ println("Selected options: " + [...select.selectedOptions].map(item => item.text).join(","));+ println("Removed option selected: " + option.selected);+ });+</script>diff --git a/Tests/LibWeb/Text/input/select-list-box-wrapped-option.html b/Tests/LibWeb/Text/input/select-list-box-wrapped-option.htmlnew file mode 100644index 00000000000..ae296c07b7f--- /dev/null+++ b/Tests/LibWeb/Text/input/select-list-box-wrapped-option.html@@ -0,0 +1,34 @@+<!doctype html>+<script src="include.js"></script>+<select multiple size="8">+ <option selected>A</option>+ <optgroup label="Group"></optgroup>+ <option>C</option>+</select>+<script>+ asyncTest(async done => {+ const select = document.querySelector("select");+ const wrapper = document.createElement("div");+ const nestedGroup = document.createElement("optgroup");+ nestedGroup.append(new Option("Excluded"));+ const wrapped = new Option("B");+ wrapper.append(nestedGroup, wrapped);+ select.querySelector("optgroup").append(wrapper);+ await new Promise(resolve => setTimeout(resolve, 0));++ println("Nested group option has no row: " + (nestedGroup.firstElementChild.getClientRects().length === 0));+ nestedGroup.style.display = "block";+ println("A displayed nested group still has no option row: " + (nestedGroup.firstElementChild.getClientRects().length === 0));+ select.focus();+ internals.sendKey(select, "Home");+ internals.sendKey(select, "Down");+ println("Down from A: " + select.value);+ internals.sendKey(select, "Down");+ println("Down from B: " + select.value);++ const rect = wrapped.getBoundingClientRect();+ internals.click(rect.x + rect.width / 2, rect.y + rect.height / 2);+ println("Clicked B: " + select.value);+ done();+ });+</script>