summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-13 21:45:27 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-13 22:21:57 +0200
commitbf864199799099fc7954dc006c843715923b0b50 (patch)
tree73b7f4b6bfb7e92e328a29b24fdc8a1ec7a4e7a0
parent2e4b34b8c30dec858ff3862e0551b43f753401f1 (diff)
downloadserenity-bf864199799099fc7954dc006c843715923b0b50.zip
LibWeb: Use ComputedCSSStyleDeclaration to generate data for inspector
-rw-r--r--Userland/Libraries/LibWeb/DOM/Element.cpp33
1 files changed, 11 insertions, 22 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp
index 7929ecd183..7cc7b34d57 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Element.cpp
@@ -6,6 +6,7 @@
#include <AK/AnyOf.h>
#include <AK/StringBuilder.h>
+#include <LibWeb/CSS/ComputedCSSStyleDeclaration.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/StyleInvalidator.h>
@@ -229,29 +230,17 @@ void Element::recompute_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();
- 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,
- CSS::PropertyID::BorderTopWidth,
- CSS::PropertyID::BorderBottomWidth,
- CSS::PropertyID::BorderLeftWidth,
- CSS::PropertyID::BorderRightWidth,
- };
- for (CSS::PropertyID id : box_model_metrics) {
- auto prop = m_specified_css_values->property(id);
- if (prop.has_value())
- properties->set_property(id, prop.value());
- }
+ auto element_computed_style = CSS::ComputedCSSStyleDeclaration::create(*this);
+ auto properties = CSS::StyleProperties::create();
+
+ for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) {
+ auto property_id = (CSS::PropertyID)i;
+ auto maybe_value = element_computed_style->property(property_id);
+ if (!maybe_value.has_value())
+ continue;
+ properties->set_property(property_id, maybe_value.release_value().value);
}
+
return properties;
}