mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +00:00
LibWeb: Use the specified CSS values from element in more places
Instead of using the specified style stored on Layout::Node, use the specified CSS values kept by the DOM::Element in more places.
This commit is contained in:
parent
63046d82f4
commit
981758a8b1
2 changed files with 14 additions and 13 deletions
|
@ -198,14 +198,12 @@ void Element::recompute_style()
|
||||||
{
|
{
|
||||||
set_needs_style_update(false);
|
set_needs_style_update(false);
|
||||||
ASSERT(parent());
|
ASSERT(parent());
|
||||||
auto* parent_layout_node = parent()->layout_node();
|
auto old_specified_css_values = m_specified_css_values;
|
||||||
if (!parent_layout_node)
|
auto* parent_specified_css_values = parent()->is_element() ? downcast<Element>(*parent()).specified_css_values() : nullptr;
|
||||||
return;
|
auto new_specified_css_values = document().style_resolver().resolve_style(*this, parent_specified_css_values);
|
||||||
ASSERT(parent_layout_node);
|
m_specified_css_values = new_specified_css_values;
|
||||||
auto style = document().style_resolver().resolve_style(*this, &parent_layout_node->specified_style());
|
|
||||||
m_specified_css_values = style;
|
|
||||||
if (!layout_node()) {
|
if (!layout_node()) {
|
||||||
if (style->display() == CSS::Display::None)
|
if (new_specified_css_values->display() == CSS::Display::None)
|
||||||
return;
|
return;
|
||||||
// We need a new layout tree here!
|
// We need a new layout tree here!
|
||||||
Layout::TreeBuilder tree_builder;
|
Layout::TreeBuilder tree_builder;
|
||||||
|
@ -217,11 +215,13 @@ void Element::recompute_style()
|
||||||
if (is<Layout::WidgetBox>(layout_node()))
|
if (is<Layout::WidgetBox>(layout_node()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto diff = compute_style_difference(layout_node()->specified_style(), *style, document());
|
auto diff = StyleDifference::NeedsRelayout;
|
||||||
|
if (old_specified_css_values)
|
||||||
|
diff = compute_style_difference(*old_specified_css_values, *new_specified_css_values, document());
|
||||||
if (diff == StyleDifference::None)
|
if (diff == StyleDifference::None)
|
||||||
return;
|
return;
|
||||||
layout_node()->set_specified_style(*style);
|
layout_node()->set_specified_style(*new_specified_css_values);
|
||||||
layout_node()->apply_style(*style);
|
layout_node()->apply_style(*new_specified_css_values);
|
||||||
if (diff == StyleDifference::NeedsRelayout) {
|
if (diff == StyleDifference::NeedsRelayout) {
|
||||||
document().force_layout();
|
document().force_layout();
|
||||||
return;
|
return;
|
||||||
|
@ -233,6 +233,7 @@ void Element::recompute_style()
|
||||||
|
|
||||||
NonnullRefPtr<CSS::StyleProperties> Element::computed_style()
|
NonnullRefPtr<CSS::StyleProperties> Element::computed_style()
|
||||||
{
|
{
|
||||||
|
// FIXME: This implementation is not doing anything it's supposed to.
|
||||||
auto properties = m_specified_css_values->clone();
|
auto properties = m_specified_css_values->clone();
|
||||||
if (layout_node() && layout_node()->has_style()) {
|
if (layout_node() && layout_node()->has_style()) {
|
||||||
CSS::PropertyID box_model_metrics[] = {
|
CSS::PropertyID box_model_metrics[] = {
|
||||||
|
@ -250,7 +251,7 @@ NonnullRefPtr<CSS::StyleProperties> Element::computed_style()
|
||||||
CSS::PropertyID::BorderRightWidth,
|
CSS::PropertyID::BorderRightWidth,
|
||||||
};
|
};
|
||||||
for (CSS::PropertyID id : box_model_metrics) {
|
for (CSS::PropertyID id : box_model_metrics) {
|
||||||
auto prop = layout_node()->specified_style().property(id);
|
auto prop = m_specified_css_values->property(id);
|
||||||
if (prop.has_value())
|
if (prop.has_value())
|
||||||
properties->set_property(id, prop.value());
|
properties->set_property(id, prop.value());
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,13 +242,13 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_specified_style) {
|
if (show_specified_style && layout_node.dom_node() && layout_node.dom_node()->is_element() && downcast<DOM::Element>(layout_node.dom_node())->specified_css_values()) {
|
||||||
struct NameAndValue {
|
struct NameAndValue {
|
||||||
String name;
|
String name;
|
||||||
String value;
|
String value;
|
||||||
};
|
};
|
||||||
Vector<NameAndValue> properties;
|
Vector<NameAndValue> properties;
|
||||||
layout_node.specified_style().for_each_property([&](auto property_id, auto& value) {
|
downcast<DOM::Element>(*layout_node.dom_node()).specified_css_values()->for_each_property([&](auto property_id, auto& value) {
|
||||||
properties.append({ CSS::string_from_property_id(property_id), value.to_string() });
|
properties.append({ CSS::string_from_property_id(property_id), value.to_string() });
|
||||||
});
|
});
|
||||||
quick_sort(properties, [](auto& a, auto& b) { return a.name < b.name; });
|
quick_sort(properties, [](auto& a, auto& b) { return a.name < b.name; });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue