diff options
author | Matrix89 <Matrix89@protonmail.ch> | 2020-01-04 03:09:22 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2020-01-05 17:13:22 +0100 |
commit | 2dd35916e5b5307d85c74d7341379b3c0050ffdd (patch) | |
tree | 541585a38349651ef033fa3ac69432e47e469810 /Libraries/LibHTML/DOM | |
parent | 2ced4c4ec745d1387be0e3a320596fd7b1597185 (diff) | |
download | serenity-2dd35916e5b5307d85c74d7341379b3c0050ffdd.zip |
Browser+LibHTML: Change the way computed styles are queried
Diffstat (limited to 'Libraries/LibHTML/DOM')
-rw-r--r-- | Libraries/LibHTML/DOM/Element.cpp | 25 | ||||
-rw-r--r-- | Libraries/LibHTML/DOM/Element.h | 1 |
2 files changed, 26 insertions, 0 deletions
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 <LibHTML/CSS/StyleResolver.h> +#include <LibHTML/CSS/PropertyID.h> +#include <LibHTML/CSS/Length.h> #include <LibHTML/DOM/Document.h> #include <LibHTML/DOM/Element.h> #include <LibHTML/Layout/LayoutBlock.h> @@ -160,3 +162,26 @@ void Element::recompute_style() layout_node()->set_needs_display(); } } + +RefPtr<StyleProperties> 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<StyleProperties> computed_style(); private: RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override; |