mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:48:12 +00:00
LibWeb: Move border width and color into LayoutStyle
To make this possible, I also had to give each LayoutNode a Document& so it can resolve document-specific colors correctly. There's probably ways to avoid having this extra member by resolving colors later, but this works for now.
This commit is contained in:
parent
4b2ac34725
commit
440b4ece22
57 changed files with 173 additions and 190 deletions
|
@ -35,8 +35,9 @@
|
|||
|
||||
namespace Web {
|
||||
|
||||
LayoutNode::LayoutNode(const Node* node)
|
||||
: m_node(node)
|
||||
LayoutNode::LayoutNode(Document& document, const Node* node)
|
||||
: m_document(document)
|
||||
, m_node(node)
|
||||
{
|
||||
if (m_node)
|
||||
m_node->set_layout_node({}, this);
|
||||
|
@ -124,21 +125,6 @@ Frame& LayoutNode::frame()
|
|||
return *document().frame();
|
||||
}
|
||||
|
||||
const Document& LayoutNode::document() const
|
||||
{
|
||||
if (is_anonymous())
|
||||
return parent()->document();
|
||||
return node()->document();
|
||||
}
|
||||
|
||||
Document& LayoutNode::document()
|
||||
{
|
||||
if (is_anonymous())
|
||||
return parent()->document();
|
||||
// FIXME: Remove this const_cast once we give up on the idea of a const link from layout tree to DOM tree.
|
||||
return const_cast<Node*>(node())->document();
|
||||
}
|
||||
|
||||
const LayoutDocument& LayoutNode::root() const
|
||||
{
|
||||
ASSERT(document().layout_node());
|
||||
|
@ -211,12 +197,12 @@ bool LayoutNode::is_fixed_position() const
|
|||
return position == CSS::Position::Fixed;
|
||||
}
|
||||
|
||||
LayoutNodeWithStyle::LayoutNodeWithStyle(const Node* node, NonnullRefPtr<StyleProperties> style)
|
||||
: LayoutNode(node)
|
||||
, m_specified_style(move(style))
|
||||
LayoutNodeWithStyle::LayoutNodeWithStyle(Document& document, const Node* node, NonnullRefPtr<StyleProperties> specified_style)
|
||||
: LayoutNode(document, node)
|
||||
, m_specified_style(move(specified_style))
|
||||
{
|
||||
m_has_style = true;
|
||||
apply_style(this->specified_style());
|
||||
apply_style(*m_specified_style);
|
||||
}
|
||||
|
||||
void LayoutNodeWithStyle::apply_style(const StyleProperties& specified_style)
|
||||
|
@ -241,6 +227,16 @@ void LayoutNodeWithStyle::apply_style(const StyleProperties& specified_style)
|
|||
style.set_offset(specified_style.length_box(CSS::PropertyID::Left, CSS::PropertyID::Top, CSS::PropertyID::Right, CSS::PropertyID::Bottom));
|
||||
style.set_margin(specified_style.length_box(CSS::PropertyID::MarginLeft, CSS::PropertyID::MarginTop, CSS::PropertyID::MarginRight, CSS::PropertyID::MarginBottom));
|
||||
style.set_padding(specified_style.length_box(CSS::PropertyID::PaddingLeft, CSS::PropertyID::PaddingTop, CSS::PropertyID::PaddingRight, CSS::PropertyID::PaddingBottom));
|
||||
|
||||
style.border_left().width = specified_style.length_or_fallback(CSS::PropertyID::BorderLeftWidth, {}).resolved_or_zero(*this, 0).to_px(*this);
|
||||
style.border_top().width = specified_style.length_or_fallback(CSS::PropertyID::BorderTopWidth, {}).resolved_or_zero(*this, 0).to_px(*this);
|
||||
style.border_right().width = specified_style.length_or_fallback(CSS::PropertyID::BorderRightWidth, {}).resolved_or_zero(*this, 0).to_px(*this);
|
||||
style.border_bottom().width = specified_style.length_or_fallback(CSS::PropertyID::BorderBottomWidth, {}).resolved_or_zero(*this, 0).to_px(*this);
|
||||
|
||||
style.border_left().color = specified_style.color_or_fallback(CSS::PropertyID::BorderLeftColor, document(), Color::Transparent);
|
||||
style.border_top().color = specified_style.color_or_fallback(CSS::PropertyID::BorderTopColor, document(), Color::Transparent);
|
||||
style.border_right().color = specified_style.color_or_fallback(CSS::PropertyID::BorderRightColor, document(), Color::Transparent);
|
||||
style.border_bottom().color = specified_style.color_or_fallback(CSS::PropertyID::BorderBottomColor, document(), Color::Transparent);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue