diff --git a/Applications/Browser/InspectorWidget.cpp b/Applications/Browser/InspectorWidget.cpp index e3cad9c67a..946ac64f71 100644 --- a/Applications/Browser/InspectorWidget.cpp +++ b/Applications/Browser/InspectorWidget.cpp @@ -6,9 +6,8 @@ #include #include #include -#include -#include #include +#include InspectorWidget::InspectorWidget(GWidget* parent) : GWidget(parent) @@ -21,8 +20,10 @@ InspectorWidget::InspectorWidget(GWidget* parent) node->document().set_inspected_node(node); if (node->is_element()) { auto element = to(*node); - m_style_table_view->set_model(DOMElementStyleModel::create(element)); - m_computed_style_table_view->set_model(DOMComputedElementStyleModel::create(element)); + 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())); } else { m_style_table_view->set_model(nullptr); m_computed_style_table_view->set_model(nullptr); diff --git a/Libraries/LibHTML/DOMComputedElementStyleModel.cpp b/Libraries/LibHTML/DOMComputedElementStyleModel.cpp deleted file mode 100644 index 1c427730f1..0000000000 --- a/Libraries/LibHTML/DOMComputedElementStyleModel.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "DOMComputedElementStyleModel.h" -#include -#include -#include - -DOMComputedElementStyleModel::DOMComputedElementStyleModel(const Element& element) - : m_element(element) -{ - if (element.layout_node() != nullptr && element.layout_node()->has_style()) { - element.layout_node()->style().for_each_property([&](auto property_id, auto& property_value) { - Value value; - value.name = CSS::string_from_property_id(property_id); - value.value = property_value.to_string(); - m_values.append(value); - }); - } -} - -int DOMComputedElementStyleModel::row_count(const GModelIndex&) const -{ - return m_values.size(); -} - -String DOMComputedElementStyleModel::column_name(int column_index) const -{ - switch (column_index) { - case Column::PropertyName: - return "Name"; - case Column::PropertyValue: - return "Value"; - default: - ASSERT_NOT_REACHED(); - } -} -GVariant DOMComputedElementStyleModel::data(const GModelIndex& index, Role role) const -{ - auto& value = m_values[index.row()]; - if (role == Role::Display) { - if (index.column() == Column::PropertyName) - return value.name; - if (index.column() == Column::PropertyValue) - return value.value; - } - return {}; -} - -void DOMComputedElementStyleModel::update() -{ - did_update(); -} diff --git a/Libraries/LibHTML/DOMElementStyleModel.cpp b/Libraries/LibHTML/DOMElementStyleModel.cpp deleted file mode 100644 index e217c2bde2..0000000000 --- a/Libraries/LibHTML/DOMElementStyleModel.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "DOMElementStyleModel.h" -#include -#include -#include - -DOMElementStyleModel::DOMElementStyleModel(const Element& element) - : m_element(element) -{ - if (element.resolved_style()) { - element.resolved_style()->for_each_property([&](auto property_id, auto& property_value) { - Value value; - value.name = CSS::string_from_property_id(property_id); - value.value = property_value.to_string(); - m_values.append(value); - }); - } -} - -int DOMElementStyleModel::row_count(const GModelIndex&) const -{ - return m_values.size(); -} - -String DOMElementStyleModel::column_name(int column_index) const -{ - switch (column_index) { - case Column::PropertyName: - return "Name"; - case Column::PropertyValue: - return "Value"; - default: - ASSERT_NOT_REACHED(); - } -} -GVariant DOMElementStyleModel::data(const GModelIndex& index, Role role) const -{ - auto& value = m_values[index.row()]; - if (role == Role::Display) { - if (index.column() == Column::PropertyName) - return value.name; - if (index.column() == Column::PropertyValue) - return value.value; - } - return {}; -} - -void DOMElementStyleModel::update() -{ - did_update(); -} diff --git a/Libraries/LibHTML/DOMElementStyleModel.h b/Libraries/LibHTML/DOMElementStyleModel.h deleted file mode 100644 index 7d074eb9ef..0000000000 --- a/Libraries/LibHTML/DOMElementStyleModel.h +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include - -class Element; - -class DOMElementStyleModel final : public GModel { -public: - enum Column { - PropertyName, - PropertyValue, - __Count - }; - - static NonnullRefPtr create(const Element& element) { return adopt(*new DOMElementStyleModel(element)); } - - virtual int row_count(const GModelIndex& = GModelIndex()) const override; - virtual int column_count(const GModelIndex& = GModelIndex()) const override { return Column::__Count; } - virtual String column_name(int) const override; - virtual GVariant data(const GModelIndex&, Role = Role::Display) const override; - virtual void update() override; - -private: - explicit DOMElementStyleModel(const Element&); - const Element& element() const { return *m_element; } - - NonnullRefPtr m_element; - - struct Value { - String name; - String value; - }; - Vector m_values; -}; diff --git a/Libraries/LibHTML/Makefile b/Libraries/LibHTML/Makefile index 775fac466a..a23b602058 100644 --- a/Libraries/LibHTML/Makefile +++ b/Libraries/LibHTML/Makefile @@ -34,8 +34,7 @@ LIBHTML_OBJS = \ DOM/Node.o \ DOM/ParentNode.o \ DOM/Text.o \ - DOMElementStyleModel.o \ - DOMComputedElementStyleModel.o \ + StylePropertiesModel.o \ DOMTreeModel.o \ Dump.o \ FontCache.o \ diff --git a/Libraries/LibHTML/StylePropertiesModel.cpp b/Libraries/LibHTML/StylePropertiesModel.cpp new file mode 100644 index 0000000000..6fdda3c418 --- /dev/null +++ b/Libraries/LibHTML/StylePropertiesModel.cpp @@ -0,0 +1,48 @@ +#include "StylePropertiesModel.h" +#include +#include +#include + +StylePropertiesModel::StylePropertiesModel(const StyleProperties& properties) + : m_properties(properties) +{ + properties.for_each_property([&](auto property_id, auto& property_value) { + Value value; + value.name = CSS::string_from_property_id(property_id); + value.value = property_value.to_string(); + m_values.append(value); + }); +} + +int StylePropertiesModel::row_count(const GModelIndex&) const +{ + return m_values.size(); +} + +String StylePropertiesModel::column_name(int column_index) const +{ + switch (column_index) { + case Column::PropertyName: + return "Name"; + case Column::PropertyValue: + return "Value"; + default: + ASSERT_NOT_REACHED(); + } +} +GVariant StylePropertiesModel::data(const GModelIndex& index, Role role) const +{ + auto& value = m_values[index.row()]; + if (role == Role::Display) { + if (index.column() == Column::PropertyName) + return value.name; + if (index.column() == Column::PropertyValue) + return value.value; + } + return {}; +} + +void StylePropertiesModel::update() +{ + did_update(); +} diff --git a/Libraries/LibHTML/DOMComputedElementStyleModel.h b/Libraries/LibHTML/StylePropertiesModel.h similarity index 60% rename from Libraries/LibHTML/DOMComputedElementStyleModel.h rename to Libraries/LibHTML/StylePropertiesModel.h index b118c35254..2b98b8ede0 100644 --- a/Libraries/LibHTML/DOMComputedElementStyleModel.h +++ b/Libraries/LibHTML/StylePropertiesModel.h @@ -1,9 +1,9 @@ #include #include -class Element; +class StyleProperties; -class DOMComputedElementStyleModel final : public GModel { +class StylePropertiesModel final : public GModel { public: enum Column { PropertyName, @@ -11,7 +11,7 @@ public: __Count }; - static NonnullRefPtr create(const Element& element) { return adopt(*new DOMComputedElementStyleModel(element)); } + static NonnullRefPtr create(const StyleProperties& properties) { return adopt(*new StylePropertiesModel(properties)); } virtual int row_count(const GModelIndex& = GModelIndex()) const override; virtual int column_count(const GModelIndex& = GModelIndex()) const override { return Column::__Count; } @@ -20,10 +20,10 @@ public: virtual void update() override; private: - explicit DOMComputedElementStyleModel(const Element&); - const Element& element() const { return *m_element; } + explicit StylePropertiesModel(const StyleProperties& properties); + const StyleProperties& properties() const { return *m_properties; } - NonnullRefPtr m_element; + NonnullRefPtr m_properties; struct Value { String name;