mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:48:13 +00:00
LibHTML: Fetch the box edge values needed for block width computation.
This commit is contained in:
parent
af23b38418
commit
f88c5860df
4 changed files with 42 additions and 2 deletions
|
@ -29,6 +29,13 @@ public:
|
||||||
return String::format("%d [Length/Absolute]", m_value);
|
return String::format("%d [Length/Absolute]", m_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int to_px() const
|
||||||
|
{
|
||||||
|
if (is_auto())
|
||||||
|
return 0;
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type m_type { Type::Auto };
|
Type m_type { Type::Auto };
|
||||||
int m_value { 0 };
|
int m_value { 0 };
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/AKString.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
#include <AK/AKString.h>
|
#include <AK/Optional.h>
|
||||||
#include <LibHTML/TreeNode.h>
|
|
||||||
#include <LibHTML/CSS/StyleValue.h>
|
#include <LibHTML/CSS/StyleValue.h>
|
||||||
|
#include <LibHTML/TreeNode.h>
|
||||||
|
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
|
@ -50,6 +51,14 @@ public:
|
||||||
m_property_values.set(name, move(value));
|
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;
|
Display display() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <LibHTML/CSS/StyledNode.h>
|
||||||
#include <LibHTML/DOM/Element.h>
|
#include <LibHTML/DOM/Element.h>
|
||||||
#include <LibHTML/Layout/LayoutBlock.h>
|
#include <LibHTML/Layout/LayoutBlock.h>
|
||||||
|
|
||||||
|
@ -29,6 +30,26 @@ void LayoutBlock::layout()
|
||||||
|
|
||||||
void LayoutBlock::compute_width()
|
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()
|
void LayoutBlock::compute_height()
|
||||||
|
|
|
@ -49,6 +49,9 @@ public:
|
||||||
|
|
||||||
virtual LayoutNode& inline_wrapper() { return *this; }
|
virtual LayoutNode& inline_wrapper() { return *this; }
|
||||||
|
|
||||||
|
StyledNode* styled_node() { return m_styled_node; }
|
||||||
|
const StyledNode* styled_node() const { return m_styled_node; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit LayoutNode(const Node*, const StyledNode*);
|
explicit LayoutNode(const Node*, const StyledNode*);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue