LibWeb: Fix ::-webkit-progress-bar/value pseudo elements

Recent changes to layout and display broke these pseudo elements
leading to crashes on a few websites such as https://rpcs3.net/.
This commit is contained in:
MacDue 2022-10-08 22:15:32 +01:00 committed by Andreas Kling
parent 72605e854f
commit 0265041d44
Notes: sideshowbarker 2024-07-17 06:09:59 +09:00
2 changed files with 14 additions and 7 deletions

View file

@ -25,9 +25,8 @@ HTMLProgressElement::~HTMLProgressElement() = default;
RefPtr<Layout::Node> HTMLProgressElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style) RefPtr<Layout::Node> HTMLProgressElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
{ {
if (style->appearance().value_or(CSS::Appearance::Auto) == CSS::Appearance::None) { if (style->appearance().value_or(CSS::Appearance::Auto) == CSS::Appearance::None)
return adopt_ref(*new Layout::BlockContainer(document(), this, move(style))); return HTMLElement::create_layout_node(style);
}
return adopt_ref(*new Layout::Progress(document(), *this, move(style))); return adopt_ref(*new Layout::Progress(document(), *this, move(style)));
} }

View file

@ -265,13 +265,21 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context&
auto& progress = static_cast<HTML::HTMLProgressElement&>(dom_node); auto& progress = static_cast<HTML::HTMLProgressElement&>(dom_node);
if (!progress.using_system_appearance()) { if (!progress.using_system_appearance()) {
auto bar_style = style_computer.compute_style(progress, CSS::Selector::PseudoElement::ProgressBar); auto bar_style = style_computer.compute_style(progress, CSS::Selector::PseudoElement::ProgressBar);
bar_style->set_property(CSS::PropertyID::Display, CSS::IdentifierStyleValue::create(CSS::ValueID::InlineBlock));
auto value_style = style_computer.compute_style(progress, CSS::Selector::PseudoElement::ProgressValue); auto value_style = style_computer.compute_style(progress, CSS::Selector::PseudoElement::ProgressValue);
value_style->set_property(CSS::PropertyID::Display, CSS::IdentifierStyleValue::create(CSS::ValueID::Block));
auto position = progress.position(); auto position = progress.position();
value_style->set_property(CSS::PropertyID::Width, CSS::PercentageStyleValue::create(CSS::Percentage(position >= 0 ? round_to<int>(100 * position) : 0))); value_style->set_property(CSS::PropertyID::Width, CSS::PercentageStyleValue::create(CSS::Percentage(position >= 0 ? round_to<int>(100 * position) : 0)));
auto progress_bar = adopt_ref(*new Layout::BlockContainer(document, nullptr, bar_style)); auto bar_display = bar_style->display();
auto progress_value = adopt_ref(*new Layout::BlockContainer(document, nullptr, value_style)); auto value_display = value_style->display();
progress_bar->append_child(*progress_value); auto progress_bar = DOM::Element::create_layout_node_for_display_type(document, bar_display, bar_style, nullptr);
layout_node->append_child(*progress_bar); auto progress_value = DOM::Element::create_layout_node_for_display_type(document, value_display, value_style, nullptr);
push_parent(verify_cast<NodeWithStyle>(*layout_node));
push_parent(verify_cast<NodeWithStyle>(*progress_bar));
insert_node_into_inline_or_block_ancestor(*progress_value, value_display, AppendOrPrepend::Append);
pop_parent();
insert_node_into_inline_or_block_ancestor(*progress_bar, bar_display, AppendOrPrepend::Append);
pop_parent();
progress.set_pseudo_element_node({}, CSS::Selector::PseudoElement::ProgressBar, progress_bar); progress.set_pseudo_element_node({}, CSS::Selector::PseudoElement::ProgressBar, progress_bar);
progress.set_pseudo_element_node({}, CSS::Selector::PseudoElement::ProgressValue, progress_value); progress.set_pseudo_element_node({}, CSS::Selector::PseudoElement::ProgressValue, progress_value);
} }