mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:38:11 +00:00
LibHTML: Rename ComputedStyle to BoxModelMetrics
There was nothing left in ComputedStyle except the box model metrics, so this patch gives it a more representative name. Note that style information is fetched directly from StyleProperties, which is basically the CSS property name/value pairs that apply to an element.
This commit is contained in:
parent
7bc9310170
commit
9c0e9a1a20
7 changed files with 44 additions and 44 deletions
|
@ -62,23 +62,23 @@ void dump_tree(const LayoutNode& layout_node)
|
||||||
|
|
||||||
// Dump the horizontal box properties
|
// Dump the horizontal box properties
|
||||||
dbgprintf(" [%d+%d+%d %d %d+%d+%d]",
|
dbgprintf(" [%d+%d+%d %d %d+%d+%d]",
|
||||||
layout_node.style().margin().left.to_px(),
|
layout_node.box_model().margin().left.to_px(),
|
||||||
layout_node.style().border().left.to_px(),
|
layout_node.box_model().border().left.to_px(),
|
||||||
layout_node.style().padding().left.to_px(),
|
layout_node.box_model().padding().left.to_px(),
|
||||||
layout_node.rect().width(),
|
layout_node.rect().width(),
|
||||||
layout_node.style().padding().right.to_px(),
|
layout_node.box_model().padding().right.to_px(),
|
||||||
layout_node.style().border().right.to_px(),
|
layout_node.box_model().border().right.to_px(),
|
||||||
layout_node.style().margin().right.to_px());
|
layout_node.box_model().margin().right.to_px());
|
||||||
|
|
||||||
// And the vertical box properties
|
// And the vertical box properties
|
||||||
dbgprintf(" [%d+%d+%d %d %d+%d+%d]",
|
dbgprintf(" [%d+%d+%d %d %d+%d+%d]",
|
||||||
layout_node.style().margin().top.to_px(),
|
layout_node.box_model().margin().top.to_px(),
|
||||||
layout_node.style().border().top.to_px(),
|
layout_node.box_model().border().top.to_px(),
|
||||||
layout_node.style().padding().top.to_px(),
|
layout_node.box_model().padding().top.to_px(),
|
||||||
layout_node.rect().height(),
|
layout_node.rect().height(),
|
||||||
layout_node.style().padding().bottom.to_px(),
|
layout_node.box_model().padding().bottom.to_px(),
|
||||||
layout_node.style().border().bottom.to_px(),
|
layout_node.box_model().border().bottom.to_px(),
|
||||||
layout_node.style().margin().bottom.to_px());
|
layout_node.box_model().margin().bottom.to_px());
|
||||||
|
|
||||||
dbgprintf("\n");
|
dbgprintf("\n");
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#include <LibHTML/Layout/ComputedStyle.h>
|
#include <LibHTML/Layout/BoxModelMetrics.h>
|
||||||
|
|
||||||
ComputedStyle::ComputedStyle()
|
BoxModelMetrics::BoxModelMetrics()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputedStyle::~ComputedStyle()
|
BoxModelMetrics::~BoxModelMetrics()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputedStyle::PixelBox ComputedStyle::full_margin() const
|
BoxModelMetrics::PixelBox BoxModelMetrics::full_margin() const
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
m_margin.top.to_px() + m_border.top.to_px() + m_padding.top.to_px(),
|
m_margin.top.to_px() + m_border.top.to_px() + m_padding.top.to_px(),
|
|
@ -3,10 +3,10 @@
|
||||||
#include <LibDraw/Size.h>
|
#include <LibDraw/Size.h>
|
||||||
#include <LibHTML/CSS/LengthBox.h>
|
#include <LibHTML/CSS/LengthBox.h>
|
||||||
|
|
||||||
class ComputedStyle {
|
class BoxModelMetrics {
|
||||||
public:
|
public:
|
||||||
ComputedStyle();
|
BoxModelMetrics();
|
||||||
~ComputedStyle();
|
~BoxModelMetrics();
|
||||||
|
|
||||||
LengthBox& margin() { return m_margin; }
|
LengthBox& margin() { return m_margin; }
|
||||||
LengthBox& padding() { return m_padding; }
|
LengthBox& padding() { return m_padding; }
|
|
@ -39,7 +39,7 @@ void LayoutBlock::layout_block_children()
|
||||||
int content_height = 0;
|
int content_height = 0;
|
||||||
for_each_child([&](auto& child) {
|
for_each_child([&](auto& child) {
|
||||||
child.layout();
|
child.layout();
|
||||||
content_height = child.rect().bottom() + child.style().full_margin().bottom - rect().top();
|
content_height = child.rect().bottom() + child.box_model().full_margin().bottom - rect().top();
|
||||||
});
|
});
|
||||||
rect().set_height(content_height);
|
rect().set_height(content_height);
|
||||||
}
|
}
|
||||||
|
@ -139,12 +139,12 @@ void LayoutBlock::compute_width()
|
||||||
}
|
}
|
||||||
|
|
||||||
rect().set_width(width.to_px());
|
rect().set_width(width.to_px());
|
||||||
style().margin().left = margin_left;
|
box_model().margin().left = margin_left;
|
||||||
style().margin().right = margin_right;
|
box_model().margin().right = margin_right;
|
||||||
style().border().left = border_left;
|
box_model().border().left = border_left;
|
||||||
style().border().right = border_right;
|
box_model().border().right = border_right;
|
||||||
style().padding().left = padding_left;
|
box_model().padding().left = padding_left;
|
||||||
style().padding().right = padding_right;
|
box_model().padding().right = padding_right;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutBlock::compute_position()
|
void LayoutBlock::compute_position()
|
||||||
|
@ -156,24 +156,24 @@ void LayoutBlock::compute_position()
|
||||||
|
|
||||||
auto width = style_properties.length_or_fallback("width", auto_value);
|
auto width = style_properties.length_or_fallback("width", auto_value);
|
||||||
|
|
||||||
style().margin().top = style_properties.length_or_fallback("margin-top", zero_value);
|
box_model().margin().top = style_properties.length_or_fallback("margin-top", zero_value);
|
||||||
style().margin().bottom = style_properties.length_or_fallback("margin-bottom", zero_value);
|
box_model().margin().bottom = style_properties.length_or_fallback("margin-bottom", zero_value);
|
||||||
style().border().top = style_properties.length_or_fallback("border-top", zero_value);
|
box_model().border().top = style_properties.length_or_fallback("border-top", zero_value);
|
||||||
style().border().bottom = style_properties.length_or_fallback("border-bottom", zero_value);
|
box_model().border().bottom = style_properties.length_or_fallback("border-bottom", zero_value);
|
||||||
style().padding().top = style_properties.length_or_fallback("padding-top", zero_value);
|
box_model().padding().top = style_properties.length_or_fallback("padding-top", zero_value);
|
||||||
style().padding().bottom = style_properties.length_or_fallback("padding-bottom", zero_value);
|
box_model().padding().bottom = style_properties.length_or_fallback("padding-bottom", zero_value);
|
||||||
rect().set_x(containing_block()->rect().x() + style().margin().left.to_px() + style().border().left.to_px() + style().padding().left.to_px());
|
rect().set_x(containing_block()->rect().x() + box_model().margin().left.to_px() + box_model().border().left.to_px() + box_model().padding().left.to_px());
|
||||||
|
|
||||||
int top_border = -1;
|
int top_border = -1;
|
||||||
if (previous_sibling() != nullptr) {
|
if (previous_sibling() != nullptr) {
|
||||||
auto& previous_sibling_rect = previous_sibling()->rect();
|
auto& previous_sibling_rect = previous_sibling()->rect();
|
||||||
auto& previous_sibling_style = previous_sibling()->style();
|
auto& previous_sibling_style = previous_sibling()->box_model();
|
||||||
top_border = previous_sibling_rect.y() + previous_sibling_rect.height();
|
top_border = previous_sibling_rect.y() + previous_sibling_rect.height();
|
||||||
top_border += previous_sibling_style.full_margin().bottom;
|
top_border += previous_sibling_style.full_margin().bottom;
|
||||||
} else {
|
} else {
|
||||||
top_border = containing_block()->rect().y();
|
top_border = containing_block()->rect().y();
|
||||||
}
|
}
|
||||||
rect().set_y(top_border + style().full_margin().top);
|
rect().set_y(top_border + box_model().full_margin().top);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutBlock::compute_height()
|
void LayoutBlock::compute_height()
|
||||||
|
|
|
@ -44,10 +44,10 @@ void LayoutNode::render(RenderingContext& context)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Rect padded_rect;
|
Rect padded_rect;
|
||||||
padded_rect.set_x(rect().x() - style().padding().left.to_px());
|
padded_rect.set_x(rect().x() - box_model().padding().left.to_px());
|
||||||
padded_rect.set_width(rect().width() + style().padding().left.to_px() + style().padding().right.to_px());
|
padded_rect.set_width(rect().width() + box_model().padding().left.to_px() + box_model().padding().right.to_px());
|
||||||
padded_rect.set_y(rect().y() - style().padding().top.to_px());
|
padded_rect.set_y(rect().y() - box_model().padding().top.to_px());
|
||||||
padded_rect.set_height(rect().height() + style().padding().top.to_px() + style().padding().bottom.to_px());
|
padded_rect.set_height(rect().height() + box_model().padding().top.to_px() + box_model().padding().bottom.to_px());
|
||||||
|
|
||||||
auto bgcolor = style_properties().property("background-color");
|
auto bgcolor = style_properties().property("background-color");
|
||||||
if (bgcolor.has_value() && bgcolor.value()->is_color()) {
|
if (bgcolor.has_value() && bgcolor.value()->is_color()) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibDraw/Rect.h>
|
#include <LibDraw/Rect.h>
|
||||||
#include <LibHTML/CSS/StyleProperties.h>
|
#include <LibHTML/CSS/StyleProperties.h>
|
||||||
#include <LibHTML/Layout/ComputedStyle.h>
|
#include <LibHTML/Layout/BoxModelMetrics.h>
|
||||||
#include <LibHTML/RenderingContext.h>
|
#include <LibHTML/RenderingContext.h>
|
||||||
#include <LibHTML/TreeNode.h>
|
#include <LibHTML/TreeNode.h>
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ public:
|
||||||
Rect& rect() { return m_rect; }
|
Rect& rect() { return m_rect; }
|
||||||
void set_rect(const Rect& rect) { m_rect = rect; }
|
void set_rect(const Rect& rect) { m_rect = rect; }
|
||||||
|
|
||||||
ComputedStyle& style() { return m_style; }
|
BoxModelMetrics& box_model() { return m_style; }
|
||||||
const ComputedStyle& style() const { return m_style; }
|
const BoxModelMetrics& box_model() const { return m_style; }
|
||||||
|
|
||||||
virtual HitTestResult hit_test(const Point&) const;
|
virtual HitTestResult hit_test(const Point&) const;
|
||||||
|
|
||||||
|
@ -79,6 +79,6 @@ private:
|
||||||
const Node* m_node { nullptr };
|
const Node* m_node { nullptr };
|
||||||
|
|
||||||
RefPtr<StyleProperties> m_style_properties;
|
RefPtr<StyleProperties> m_style_properties;
|
||||||
ComputedStyle m_style;
|
BoxModelMetrics m_style;
|
||||||
Rect m_rect;
|
Rect m_rect;
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,7 +27,7 @@ LIBHTML_OBJS = \
|
||||||
Layout/LayoutBlock.o \
|
Layout/LayoutBlock.o \
|
||||||
Layout/LayoutInline.o \
|
Layout/LayoutInline.o \
|
||||||
Layout/LayoutDocument.o \
|
Layout/LayoutDocument.o \
|
||||||
Layout/ComputedStyle.o \
|
Layout/BoxModelMetrics.o \
|
||||||
Layout/LineBox.o \
|
Layout/LineBox.o \
|
||||||
Layout/LineBoxFragment.o \
|
Layout/LineBoxFragment.o \
|
||||||
HtmlView.o \
|
HtmlView.o \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue