mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 09:07:41 +00:00
LibWeb: LayoutMode line_break_policy => LayoutMode layout_mode
This commit is contained in:
parent
a8f0e4d56e
commit
35040dd2c4
11 changed files with 41 additions and 41 deletions
|
@ -53,27 +53,27 @@ LayoutNode& LayoutBlock::inline_wrapper()
|
||||||
return *last_child();
|
return *last_child();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutBlock::layout(LayoutMode line_break_policy)
|
void LayoutBlock::layout(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
compute_width();
|
compute_width();
|
||||||
|
|
||||||
if (!is_inline())
|
if (!is_inline())
|
||||||
compute_position();
|
compute_position();
|
||||||
|
|
||||||
layout_children(line_break_policy);
|
layout_children(layout_mode);
|
||||||
|
|
||||||
compute_height();
|
compute_height();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutBlock::layout_children(LayoutMode line_break_policy)
|
void LayoutBlock::layout_children(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
if (children_are_inline())
|
if (children_are_inline())
|
||||||
layout_inline_children(line_break_policy);
|
layout_inline_children(layout_mode);
|
||||||
else
|
else
|
||||||
layout_block_children(line_break_policy);
|
layout_block_children(layout_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutBlock::layout_block_children(LayoutMode line_break_policy)
|
void LayoutBlock::layout_block_children(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
ASSERT(!children_are_inline());
|
ASSERT(!children_are_inline());
|
||||||
float content_height = 0;
|
float content_height = 0;
|
||||||
|
@ -82,10 +82,10 @@ void LayoutBlock::layout_block_children(LayoutMode line_break_policy)
|
||||||
if (child.is_inline())
|
if (child.is_inline())
|
||||||
return;
|
return;
|
||||||
auto& child_block = static_cast<LayoutBlock&>(child);
|
auto& child_block = static_cast<LayoutBlock&>(child);
|
||||||
child_block.layout(line_break_policy);
|
child_block.layout(layout_mode);
|
||||||
content_height = child_block.rect().bottom() + child_block.box_model().full_margin().bottom - rect().top();
|
content_height = child_block.rect().bottom() + child_block.box_model().full_margin().bottom - rect().top();
|
||||||
});
|
});
|
||||||
if (line_break_policy != LayoutMode::Default) {
|
if (layout_mode != LayoutMode::Default) {
|
||||||
float max_width = 0;
|
float max_width = 0;
|
||||||
for_each_child([&](auto& child) {
|
for_each_child([&](auto& child) {
|
||||||
if (child.is_box())
|
if (child.is_box())
|
||||||
|
@ -96,13 +96,13 @@ void LayoutBlock::layout_block_children(LayoutMode line_break_policy)
|
||||||
rect().set_height(content_height);
|
rect().set_height(content_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutBlock::layout_inline_children(LayoutMode line_break_policy)
|
void LayoutBlock::layout_inline_children(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
ASSERT(children_are_inline());
|
ASSERT(children_are_inline());
|
||||||
m_line_boxes.clear();
|
m_line_boxes.clear();
|
||||||
for_each_child([&](auto& child) {
|
for_each_child([&](auto& child) {
|
||||||
ASSERT(child.is_inline());
|
ASSERT(child.is_inline());
|
||||||
child.split_into_lines(*this, line_break_policy);
|
child.split_into_lines(*this, layout_mode);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto& line_box : m_line_boxes) {
|
for (auto& line_box : m_line_boxes) {
|
||||||
|
@ -188,7 +188,7 @@ void LayoutBlock::layout_inline_children(LayoutMode line_break_policy)
|
||||||
if (fragment.layout_node().is_inline_block()) {
|
if (fragment.layout_node().is_inline_block()) {
|
||||||
auto& inline_block = const_cast<LayoutBlock&>(to<LayoutBlock>(fragment.layout_node()));
|
auto& inline_block = const_cast<LayoutBlock&>(to<LayoutBlock>(fragment.layout_node()));
|
||||||
inline_block.set_rect(fragment.rect());
|
inline_block.set_rect(fragment.rect());
|
||||||
inline_block.layout(line_break_policy);
|
inline_block.layout(layout_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
float final_line_box_width = 0;
|
float final_line_box_width = 0;
|
||||||
|
@ -202,7 +202,7 @@ void LayoutBlock::layout_inline_children(LayoutMode line_break_policy)
|
||||||
content_height += max_height;
|
content_height += max_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line_break_policy != LayoutMode::Default) {
|
if (layout_mode != LayoutMode::Default) {
|
||||||
rect().set_width(max_linebox_width);
|
rect().set_width(max_linebox_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,11 +501,11 @@ LineBox& LayoutBlock::add_line_box()
|
||||||
return m_line_boxes.last();
|
return m_line_boxes.last();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutBlock::split_into_lines(LayoutBlock& container, LayoutMode line_break_policy)
|
void LayoutBlock::split_into_lines(LayoutBlock& container, LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
ASSERT(is_inline());
|
ASSERT(is_inline());
|
||||||
|
|
||||||
layout(line_break_policy);
|
layout(layout_mode);
|
||||||
|
|
||||||
auto* line_box = &container.ensure_last_line_box();
|
auto* line_box = &container.ensure_last_line_box();
|
||||||
if (line_box->width() > 0 && line_box->width() + width() > container.width())
|
if (line_box->width() > 0 && line_box->width() + width() > container.width())
|
||||||
|
|
|
@ -40,11 +40,11 @@ LayoutCanvas::~LayoutCanvas()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutCanvas::layout(LayoutMode line_break_policy)
|
void LayoutCanvas::layout(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
rect().set_width(node().requested_width());
|
rect().set_width(node().requested_width());
|
||||||
rect().set_height(node().requested_height());
|
rect().set_height(node().requested_height());
|
||||||
LayoutReplaced::layout(line_break_policy);
|
LayoutReplaced::layout(layout_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutCanvas::render(RenderingContext& context)
|
void LayoutCanvas::render(RenderingContext& context)
|
||||||
|
|
|
@ -40,12 +40,12 @@ LayoutDocument::~LayoutDocument()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutDocument::layout(LayoutMode line_break_policy)
|
void LayoutDocument::layout(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
ASSERT(document().frame());
|
ASSERT(document().frame());
|
||||||
rect().set_width(document().frame()->size().width());
|
rect().set_width(document().frame()->size().width());
|
||||||
|
|
||||||
LayoutNode::layout(line_break_policy);
|
LayoutNode::layout(layout_mode);
|
||||||
|
|
||||||
ASSERT(!children_are_inline());
|
ASSERT(!children_are_inline());
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ LayoutImage::~LayoutImage()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutImage::layout(LayoutMode line_break_policy)
|
void LayoutImage::layout(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
if (node().preferred_width() && node().preferred_height()) {
|
if (node().preferred_width() && node().preferred_height()) {
|
||||||
rect().set_width(node().preferred_width());
|
rect().set_width(node().preferred_width());
|
||||||
|
@ -57,7 +57,7 @@ void LayoutImage::layout(LayoutMode line_break_policy)
|
||||||
rect().set_height(16);
|
rect().set_height(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutReplaced::layout(line_break_policy);
|
LayoutReplaced::layout(layout_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutImage::render(RenderingContext& context)
|
void LayoutImage::render(RenderingContext& context)
|
||||||
|
|
|
@ -38,14 +38,14 @@ LayoutListItem::~LayoutListItem()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutListItem::layout(LayoutMode line_break_policy)
|
void LayoutListItem::layout(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
if (m_marker) {
|
if (m_marker) {
|
||||||
remove_child(*m_marker);
|
remove_child(*m_marker);
|
||||||
m_marker = nullptr;
|
m_marker = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutBlock::layout(line_break_policy);
|
LayoutBlock::layout(layout_mode);
|
||||||
|
|
||||||
if (!m_marker) {
|
if (!m_marker) {
|
||||||
m_marker = adopt(*new LayoutListItemMarker);
|
m_marker = adopt(*new LayoutListItemMarker);
|
||||||
|
|
|
@ -46,10 +46,10 @@ LayoutNode::~LayoutNode()
|
||||||
m_node->set_layout_node({}, nullptr);
|
m_node->set_layout_node({}, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutNode::layout(LayoutMode line_break_policy)
|
void LayoutNode::layout(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
for_each_child([&](auto& child) {
|
for_each_child([&](auto& child) {
|
||||||
child.layout(line_break_policy);
|
child.layout(layout_mode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,11 +111,11 @@ LayoutDocument& LayoutNode::root()
|
||||||
return *document().layout_node();
|
return *document().layout_node();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutNode::split_into_lines(LayoutBlock& container, LayoutMode line_break_policy)
|
void LayoutNode::split_into_lines(LayoutBlock& container, LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
for_each_child([&](auto& child) {
|
for_each_child([&](auto& child) {
|
||||||
if (child.is_inline()) {
|
if (child.is_inline()) {
|
||||||
child.split_into_lines(container, line_break_policy);
|
child.split_into_lines(container, layout_mode);
|
||||||
} else {
|
} else {
|
||||||
// FIXME: Support block children of inlines.
|
// FIXME: Support block children of inlines.
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,9 @@ LayoutReplaced::~LayoutReplaced()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutReplaced::split_into_lines(LayoutBlock& container, LayoutMode line_break_policy)
|
void LayoutReplaced::split_into_lines(LayoutBlock& container, LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
layout(line_break_policy);
|
layout(layout_mode);
|
||||||
|
|
||||||
auto* line_box = &container.ensure_last_line_box();
|
auto* line_box = &container.ensure_last_line_box();
|
||||||
if (line_box->width() > 0 && line_box->width() + width() > container.width())
|
if (line_box->width() > 0 && line_box->width() + width() > container.width())
|
||||||
|
|
|
@ -39,9 +39,9 @@ LayoutTable::~LayoutTable()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutTable::layout(LayoutMode line_break_policy)
|
void LayoutTable::layout(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
LayoutBlock::layout(line_break_policy);
|
LayoutBlock::layout(layout_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutTableRow* LayoutTable::first_row()
|
LayoutTableRow* LayoutTable::first_row()
|
||||||
|
|
|
@ -39,9 +39,9 @@ LayoutTableRow::~LayoutTableRow()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutTableRow::layout(LayoutMode line_break_policy)
|
void LayoutTableRow::layout(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
LayoutBox::layout(line_break_policy);
|
LayoutBox::layout(layout_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutTableCell* LayoutTableRow::first_cell()
|
LayoutTableCell* LayoutTableRow::first_cell()
|
||||||
|
|
|
@ -95,7 +95,7 @@ void LayoutText::render_fragment(RenderingContext& context, const LineBoxFragmen
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void LayoutText::for_each_chunk(Callback callback, LayoutMode line_break_policy, bool do_wrap_lines, bool do_wrap_breaks) const
|
void LayoutText::for_each_chunk(Callback callback, LayoutMode layout_mode, bool do_wrap_lines, bool do_wrap_breaks) const
|
||||||
{
|
{
|
||||||
Utf8View view(m_text_for_rendering);
|
Utf8View view(m_text_for_rendering);
|
||||||
if (view.is_empty())
|
if (view.is_empty())
|
||||||
|
@ -104,7 +104,7 @@ void LayoutText::for_each_chunk(Callback callback, LayoutMode line_break_policy,
|
||||||
auto start_of_chunk = view.begin();
|
auto start_of_chunk = view.begin();
|
||||||
|
|
||||||
auto commit_chunk = [&](auto it, bool has_breaking_newline, bool must_commit = false) {
|
auto commit_chunk = [&](auto it, bool has_breaking_newline, bool must_commit = false) {
|
||||||
if (line_break_policy == LayoutMode::OnlyRequiredLineBreaks && !must_commit)
|
if (layout_mode == LayoutMode::OnlyRequiredLineBreaks && !must_commit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int start = view.byte_offset_of(start_of_chunk);
|
int start = view.byte_offset_of(start_of_chunk);
|
||||||
|
@ -120,7 +120,7 @@ void LayoutText::for_each_chunk(Callback callback, LayoutMode line_break_policy,
|
||||||
bool last_was_space = isspace(*view.begin());
|
bool last_was_space = isspace(*view.begin());
|
||||||
bool last_was_newline = false;
|
bool last_was_newline = false;
|
||||||
for (auto it = view.begin(); it != view.end();) {
|
for (auto it = view.begin(); it != view.end();) {
|
||||||
if (line_break_policy == LayoutMode::AllPossibleLineBreaks) {
|
if (layout_mode == LayoutMode::AllPossibleLineBreaks) {
|
||||||
commit_chunk(it, false);
|
commit_chunk(it, false);
|
||||||
}
|
}
|
||||||
if (last_was_newline) {
|
if (last_was_newline) {
|
||||||
|
@ -146,7 +146,7 @@ void LayoutText::for_each_chunk(Callback callback, LayoutMode line_break_policy,
|
||||||
commit_chunk(view.end(), false, true);
|
commit_chunk(view.end(), false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutText::split_into_lines_by_rules(LayoutBlock& container, LayoutMode line_break_policy, bool do_collapse, bool do_wrap_lines, bool do_wrap_breaks)
|
void LayoutText::split_into_lines_by_rules(LayoutBlock& container, LayoutMode layout_mode, bool do_collapse, bool do_wrap_lines, bool do_wrap_breaks)
|
||||||
{
|
{
|
||||||
auto& font = style().font();
|
auto& font = style().font();
|
||||||
float space_width = font.glyph_width(' ') + font.glyph_spacing();
|
float space_width = font.glyph_width(' ') + font.glyph_spacing();
|
||||||
|
@ -192,7 +192,7 @@ void LayoutText::split_into_lines_by_rules(LayoutBlock& container, LayoutMode li
|
||||||
[&](const Utf8View& view, int start, int length, bool is_break) {
|
[&](const Utf8View& view, int start, int length, bool is_break) {
|
||||||
chunks.append({ Utf8View(view), start, length, is_break });
|
chunks.append({ Utf8View(view), start, length, is_break });
|
||||||
},
|
},
|
||||||
line_break_policy, do_wrap_lines, do_wrap_breaks);
|
layout_mode, do_wrap_lines, do_wrap_breaks);
|
||||||
|
|
||||||
for (size_t i = 0; i < chunks.size(); ++i) {
|
for (size_t i = 0; i < chunks.size(); ++i) {
|
||||||
auto& chunk = chunks[i];
|
auto& chunk = chunks[i];
|
||||||
|
@ -236,7 +236,7 @@ void LayoutText::split_into_lines_by_rules(LayoutBlock& container, LayoutMode li
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutText::split_into_lines(LayoutBlock& container, LayoutMode line_break_policy)
|
void LayoutText::split_into_lines(LayoutBlock& container, LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
bool do_collapse = true;
|
bool do_collapse = true;
|
||||||
bool do_wrap_lines = true;
|
bool do_wrap_lines = true;
|
||||||
|
@ -261,7 +261,7 @@ void LayoutText::split_into_lines(LayoutBlock& container, LayoutMode line_break_
|
||||||
do_wrap_breaks = true;
|
do_wrap_breaks = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
split_into_lines_by_rules(container, line_break_policy, do_collapse, do_wrap_lines, do_wrap_breaks);
|
split_into_lines_by_rules(container, layout_mode, do_collapse, do_wrap_lines, do_wrap_breaks);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,10 +43,10 @@ LayoutWidget::~LayoutWidget()
|
||||||
widget().remove_from_parent();
|
widget().remove_from_parent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutWidget::layout(LayoutMode line_break_policy)
|
void LayoutWidget::layout(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
rect().set_size(widget().width(), widget().height());
|
rect().set_size(widget().width(), widget().height());
|
||||||
LayoutReplaced::layout(line_break_policy);
|
LayoutReplaced::layout(layout_mode);
|
||||||
widget().move_to(rect().x(), rect().y());
|
widget().move_to(rect().x(), rect().y());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue