mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:58:12 +00:00
LibHTML: Add some convenient geometry getters on LayoutNode
Add x(), y(), size() and position() and use them around the codebase.
This commit is contained in:
parent
aefc7f9b22
commit
3309bdf722
7 changed files with 26 additions and 22 deletions
|
@ -61,17 +61,17 @@ void dump_tree(const LayoutNode& layout_node)
|
|||
dbgprintf("%s {%s} at (%d,%d) size %dx%d",
|
||||
layout_node.class_name(),
|
||||
tag_name.characters(),
|
||||
layout_node.rect().x(),
|
||||
layout_node.rect().y(),
|
||||
layout_node.rect().width(),
|
||||
layout_node.rect().height());
|
||||
layout_node.x(),
|
||||
layout_node.y(),
|
||||
layout_node.width(),
|
||||
layout_node.height());
|
||||
|
||||
// Dump the horizontal box properties
|
||||
dbgprintf(" [%d+%d+%d %d %d+%d+%d]",
|
||||
layout_node.box_model().margin().left.to_px(),
|
||||
layout_node.box_model().border().left.to_px(),
|
||||
layout_node.box_model().padding().left.to_px(),
|
||||
layout_node.rect().width(),
|
||||
layout_node.width(),
|
||||
layout_node.box_model().padding().right.to_px(),
|
||||
layout_node.box_model().border().right.to_px(),
|
||||
layout_node.box_model().margin().right.to_px());
|
||||
|
@ -81,7 +81,7 @@ void dump_tree(const LayoutNode& layout_node)
|
|||
layout_node.box_model().margin().top.to_px(),
|
||||
layout_node.box_model().border().top.to_px(),
|
||||
layout_node.box_model().padding().top.to_px(),
|
||||
layout_node.rect().height(),
|
||||
layout_node.height(),
|
||||
layout_node.box_model().padding().bottom.to_px(),
|
||||
layout_node.box_model().border().bottom.to_px(),
|
||||
layout_node.box_model().margin().bottom.to_px());
|
||||
|
|
|
@ -76,14 +76,14 @@ void HtmlView::layout_and_sync_size()
|
|||
|
||||
main_frame().set_size(available_size());
|
||||
document()->layout();
|
||||
set_content_size(layout_root()->rect().size());
|
||||
set_content_size(layout_root()->size());
|
||||
|
||||
// NOTE: If layout caused us to gain or lose scrollbars, we have to lay out again
|
||||
// since the scrollbars now take up some of the available space.
|
||||
if (had_vertical_scrollbar != vertical_scrollbar().is_visible() || had_horizontal_scrollbar != horizontal_scrollbar().is_visible()) {
|
||||
main_frame().set_size(available_size());
|
||||
document()->layout();
|
||||
set_content_size(layout_root()->rect().size());
|
||||
set_content_size(layout_root()->size());
|
||||
}
|
||||
|
||||
#ifdef HTML_DEBUG
|
||||
|
|
|
@ -66,8 +66,8 @@ void LayoutBlock::layout_inline_children()
|
|||
for (auto& fragment : line_box.fragments()) {
|
||||
// Vertically align everyone's bottom to the line.
|
||||
// FIXME: Support other kinds of vertical alignment.
|
||||
fragment.rect().set_x(rect().x() + fragment.rect().x());
|
||||
fragment.rect().set_y(rect().y() + content_height + (max_height - fragment.rect().height()));
|
||||
fragment.rect().set_x(x() + fragment.rect().x());
|
||||
fragment.rect().set_y(y() + content_height + (max_height - fragment.rect().height()));
|
||||
|
||||
if (fragment.layout_node().is_replaced())
|
||||
const_cast<LayoutNode&>(fragment.layout_node()).set_rect(fragment.rect());
|
||||
|
@ -109,7 +109,7 @@ void LayoutBlock::compute_width()
|
|||
|
||||
// 10.3.3 Block-level, non-replaced elements in normal flow
|
||||
// If 'width' is not 'auto' and 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' (plus any of 'margin-left' or 'margin-right' that are not 'auto') is larger than the width of the containing block, then any 'auto' values for 'margin-left' or 'margin-right' are, for the following rules, treated as zero.
|
||||
if (width.is_auto() && total_px > containing_block()->rect().width()) {
|
||||
if (width.is_auto() && total_px > containing_block()->width()) {
|
||||
if (margin_left.is_auto())
|
||||
margin_left = zero_value;
|
||||
if (margin_right.is_auto())
|
||||
|
@ -117,7 +117,7 @@ void LayoutBlock::compute_width()
|
|||
}
|
||||
|
||||
// 10.3.3 cont'd.
|
||||
auto underflow_px = containing_block()->rect().width() - total_px;
|
||||
auto underflow_px = containing_block()->width() - total_px;
|
||||
|
||||
if (width.is_auto()) {
|
||||
if (margin_left.is_auto())
|
||||
|
@ -168,7 +168,7 @@ void LayoutBlock::compute_position()
|
|||
box_model().border().bottom = style.length_or_fallback(CSS::PropertyID::BorderBottomWidth, zero_value);
|
||||
box_model().padding().top = style.length_or_fallback(CSS::PropertyID::PaddingTop, zero_value);
|
||||
box_model().padding().bottom = style.length_or_fallback(CSS::PropertyID::PaddingBottom, zero_value);
|
||||
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());
|
||||
rect().set_x(containing_block()->x() + box_model().margin().left.to_px() + box_model().border().left.to_px() + box_model().padding().left.to_px());
|
||||
|
||||
int top_border = -1;
|
||||
if (previous_sibling() != nullptr) {
|
||||
|
@ -177,7 +177,7 @@ void LayoutBlock::compute_position()
|
|||
top_border = previous_sibling_rect.y() + previous_sibling_rect.height();
|
||||
top_border += previous_sibling_style.full_margin().bottom;
|
||||
} else {
|
||||
top_border = containing_block()->rect().y();
|
||||
top_border = containing_block()->y();
|
||||
}
|
||||
rect().set_y(top_border + box_model().full_margin().top);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@ void LayoutListItem::layout()
|
|||
append_child(*m_marker);
|
||||
}
|
||||
|
||||
Rect marker_rect { rect().x() - 8, rect().y(), 4, rect().height() };
|
||||
Rect marker_rect { x() - 8, y(), 4, height() };
|
||||
m_marker->set_rect(marker_rect);
|
||||
}
|
||||
|
|
|
@ -51,10 +51,10 @@ void LayoutNode::render(RenderingContext& context)
|
|||
#endif
|
||||
|
||||
Rect padded_rect;
|
||||
padded_rect.set_x(rect().x() - box_model().padding().left.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() - box_model().padding().top.to_px());
|
||||
padded_rect.set_height(rect().height() + box_model().padding().top.to_px() + box_model().padding().bottom.to_px());
|
||||
padded_rect.set_x(x() - box_model().padding().left.to_px());
|
||||
padded_rect.set_width(width() + box_model().padding().left.to_px() + box_model().padding().right.to_px());
|
||||
padded_rect.set_y(y() - box_model().padding().top.to_px());
|
||||
padded_rect.set_height(height() + box_model().padding().top.to_px() + box_model().padding().bottom.to_px());
|
||||
|
||||
auto bgcolor = style().property(CSS::PropertyID::BackgroundColor);
|
||||
if (bgcolor.has_value() && bgcolor.value()->is_color()) {
|
||||
|
|
|
@ -28,8 +28,12 @@ public:
|
|||
Rect& rect() { return m_rect; }
|
||||
void set_rect(const Rect& rect) { m_rect = rect; }
|
||||
|
||||
int x() const { return rect().x(); }
|
||||
int y() const { return rect().y(); }
|
||||
int width() const { return rect().width(); }
|
||||
int height() const { return rect().height(); }
|
||||
Size size() const { return rect().size(); }
|
||||
Point position() const { return rect().location(); }
|
||||
|
||||
BoxModelMetrics& box_model() { return m_box_metrics; }
|
||||
const BoxModelMetrics& box_model() const { return m_box_metrics; }
|
||||
|
|
|
@ -128,7 +128,7 @@ void LayoutText::split_into_lines(LayoutBlock& container)
|
|||
auto& line_boxes = container.line_boxes();
|
||||
if (line_boxes.is_empty())
|
||||
line_boxes.append(LineBox());
|
||||
int available_width = container.rect().width() - line_boxes.last().width();
|
||||
int available_width = container.width() - line_boxes.last().width();
|
||||
|
||||
bool is_preformatted = style().string_or_fallback(CSS::PropertyID::WhiteSpace, "normal") == "pre";
|
||||
if (is_preformatted) {
|
||||
|
@ -179,7 +179,7 @@ void LayoutText::split_into_lines(LayoutBlock& container)
|
|||
|
||||
if (word_width > available_width) {
|
||||
line_boxes.append(LineBox());
|
||||
available_width = container.rect().width();
|
||||
available_width = container.width();
|
||||
}
|
||||
|
||||
if (is_whitespace && line_boxes.last().fragments().is_empty())
|
||||
|
@ -190,7 +190,7 @@ void LayoutText::split_into_lines(LayoutBlock& container)
|
|||
|
||||
if (available_width < 0) {
|
||||
line_boxes.append(LineBox());
|
||||
available_width = container.rect().width();
|
||||
available_width = container.width();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue