diff --git a/Applications/Browser/InspectorWidget.cpp b/Applications/Browser/InspectorWidget.cpp index 946ac64f71..d684f28d58 100644 --- a/Applications/Browser/InspectorWidget.cpp +++ b/Applications/Browser/InspectorWidget.cpp @@ -20,10 +20,10 @@ InspectorWidget::InspectorWidget(GWidget* parent) node->document().set_inspected_node(node); if (node->is_element()) { auto element = to(*node); - if (element.resolved_style()) - m_style_table_view->set_model(StylePropertiesModel::create(*element.resolved_style())); - if (element.layout_node() && element.layout_node()->has_style()) - m_computed_style_table_view->set_model(StylePropertiesModel::create(element.layout_node()->style())); + if (element.resolved_style()) { + m_style_table_view->set_model(StylePropertiesModel::create(*element.resolved_style())); + m_computed_style_table_view->set_model(StylePropertiesModel::create(*element.computed_style())); + } } else { m_style_table_view->set_model(nullptr); m_computed_style_table_view->set_model(nullptr); diff --git a/Libraries/LibHTML/CSS/StyleProperties.h b/Libraries/LibHTML/CSS/StyleProperties.h index 5475d0dce2..79ef18226f 100644 --- a/Libraries/LibHTML/CSS/StyleProperties.h +++ b/Libraries/LibHTML/CSS/StyleProperties.h @@ -10,6 +10,13 @@ class Color; class StyleProperties : public RefCounted { public: static NonnullRefPtr create() { return adopt(*new StyleProperties); } + static NonnullRefPtr create(const StyleProperties& properties) { + auto style_properties = new StyleProperties(); + properties.for_each_property([&](auto property_id, auto& property_value) { + style_properties->set_property(property_id, property_value); + }); + return adopt(*style_properties); + } template inline void for_each_property(Callback callback) const diff --git a/Libraries/LibHTML/DOM/Element.cpp b/Libraries/LibHTML/DOM/Element.cpp index 2f339d7bf8..d0e6d92d53 100644 --- a/Libraries/LibHTML/DOM/Element.cpp +++ b/Libraries/LibHTML/DOM/Element.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include #include #include @@ -160,3 +162,26 @@ void Element::recompute_style() layout_node()->set_needs_display(); } } + +RefPtr Element::computed_style() +{ + auto properties = StyleProperties::create(*m_resolved_style); + if (layout_node() && layout_node()->has_style()) { + CSS::PropertyID box_model_metrics[] = { + CSS::PropertyID::MarginTop, + CSS::PropertyID::MarginBottom, + CSS::PropertyID::MarginLeft, + CSS::PropertyID::MarginRight, + CSS::PropertyID::PaddingTop, + CSS::PropertyID::PaddingBottom, + CSS::PropertyID::PaddingLeft, + CSS::PropertyID::PaddingRight, + }; + for (CSS::PropertyID id : box_model_metrics) { + auto prop = layout_node()->style().property(id); + if (prop) + properties->set_property(id, prop.value()); + } + } + return properties.ptr(); +} diff --git a/Libraries/LibHTML/DOM/Element.h b/Libraries/LibHTML/DOM/Element.h index cf53f8221a..e163aa26bc 100644 --- a/Libraries/LibHTML/DOM/Element.h +++ b/Libraries/LibHTML/DOM/Element.h @@ -57,6 +57,7 @@ public: String name() const { return attribute("name"); } const StyleProperties* resolved_style() const { return m_resolved_style.ptr(); } + RefPtr computed_style(); private: RefPtr create_layout_node(const StyleProperties* parent_style) const override;