diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-24 07:34:07 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-24 07:34:07 +0200 |
commit | f88c5860df7ac20f8583c6b1be991842d850f808 (patch) | |
tree | c6d368aa97a10e9a58abbceb69e5265586ab4b89 | |
parent | af23b3841868d1b8314aa1472b32812fd550ab3e (diff) | |
download | serenity-f88c5860df7ac20f8583c6b1be991842d850f808.zip |
LibHTML: Fetch the box edge values needed for block width computation.
-rw-r--r-- | Libraries/LibHTML/CSS/Length.h | 7 | ||||
-rw-r--r-- | Libraries/LibHTML/CSS/StyledNode.h | 13 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutBlock.cpp | 21 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutNode.h | 3 |
4 files changed, 42 insertions, 2 deletions
diff --git a/Libraries/LibHTML/CSS/Length.h b/Libraries/LibHTML/CSS/Length.h index 0dc8c5a54a..c0dcefb628 100644 --- a/Libraries/LibHTML/CSS/Length.h +++ b/Libraries/LibHTML/CSS/Length.h @@ -29,6 +29,13 @@ public: return String::format("%d [Length/Absolute]", m_value); } + int to_px() const + { + if (is_auto()) + return 0; + return m_value; + } + private: Type m_type { Type::Auto }; int m_value { 0 }; diff --git a/Libraries/LibHTML/CSS/StyledNode.h b/Libraries/LibHTML/CSS/StyledNode.h index 0cef5f3f26..3f5e74a295 100644 --- a/Libraries/LibHTML/CSS/StyledNode.h +++ b/Libraries/LibHTML/CSS/StyledNode.h @@ -1,10 +1,11 @@ #pragma once +#include <AK/AKString.h> #include <AK/HashMap.h> #include <AK/NonnullRefPtr.h> -#include <AK/AKString.h> -#include <LibHTML/TreeNode.h> +#include <AK/Optional.h> #include <LibHTML/CSS/StyleValue.h> +#include <LibHTML/TreeNode.h> class Node; @@ -50,6 +51,14 @@ public: m_property_values.set(name, move(value)); } + Optional<NonnullRefPtr<StyleValue>> property(const String& name) const + { + auto it = m_property_values.find(name); + if (it == m_property_values.end()) + return {}; + return it->value; + } + Display display() const; protected: diff --git a/Libraries/LibHTML/Layout/LayoutBlock.cpp b/Libraries/LibHTML/Layout/LayoutBlock.cpp index 7e76b7d91f..be97a2597f 100644 --- a/Libraries/LibHTML/Layout/LayoutBlock.cpp +++ b/Libraries/LibHTML/Layout/LayoutBlock.cpp @@ -1,3 +1,4 @@ +#include <LibHTML/CSS/StyledNode.h> #include <LibHTML/DOM/Element.h> #include <LibHTML/Layout/LayoutBlock.h> @@ -29,6 +30,26 @@ void LayoutBlock::layout() void LayoutBlock::compute_width() { + if (!styled_node()) { + // I guess the size is "auto" in this case. + return; + } + + auto auto_value= LengthStyleValue::create({}); + auto& styled_node = *this->styled_node(); + auto width = styled_node.property("width").value_or(auto_value); + + auto zero_value = LengthStyleValue::create(Length(0, Length::Type::Absolute)); + + auto margin_left = styled_node.property("margin-left").value_or(zero_value); + auto margin_right = styled_node.property("margin-right").value_or(zero_value); + auto border_left = styled_node.property("border-left").value_or(zero_value); + auto border_right = styled_node.property("border-right").value_or(zero_value); + auto padding_left = styled_node.property("padding-left").value_or(zero_value); + auto padding_right = styled_node.property("padding-right").value_or(zero_value); + + dbg() << " Left: " << margin_left->to_string() << "+" << border_left->to_string() << "+" << padding_left->to_string(); + dbg() << "Right: " << margin_right->to_string() << "+" << border_right->to_string() << "+" << padding_right->to_string(); } void LayoutBlock::compute_height() diff --git a/Libraries/LibHTML/Layout/LayoutNode.h b/Libraries/LibHTML/Layout/LayoutNode.h index a48e11d422..938fd6cd7b 100644 --- a/Libraries/LibHTML/Layout/LayoutNode.h +++ b/Libraries/LibHTML/Layout/LayoutNode.h @@ -49,6 +49,9 @@ public: virtual LayoutNode& inline_wrapper() { return *this; } + StyledNode* styled_node() { return m_styled_node; } + const StyledNode* styled_node() const { return m_styled_node; } + protected: explicit LayoutNode(const Node*, const StyledNode*); |