mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 03:08:13 +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();
|
||||
}
|
||||
|
||||
void LayoutBlock::layout(LayoutMode line_break_policy)
|
||||
void LayoutBlock::layout(LayoutMode layout_mode)
|
||||
{
|
||||
compute_width();
|
||||
|
||||
if (!is_inline())
|
||||
compute_position();
|
||||
|
||||
layout_children(line_break_policy);
|
||||
layout_children(layout_mode);
|
||||
|
||||
compute_height();
|
||||
}
|
||||
|
||||
void LayoutBlock::layout_children(LayoutMode line_break_policy)
|
||||
void LayoutBlock::layout_children(LayoutMode layout_mode)
|
||||
{
|
||||
if (children_are_inline())
|
||||
layout_inline_children(line_break_policy);
|
||||
layout_inline_children(layout_mode);
|
||||
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());
|
||||
float content_height = 0;
|
||||
|
@ -82,10 +82,10 @@ void LayoutBlock::layout_block_children(LayoutMode line_break_policy)
|
|||
if (child.is_inline())
|
||||
return;
|
||||
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();
|
||||
});
|
||||
if (line_break_policy != LayoutMode::Default) {
|
||||
if (layout_mode != LayoutMode::Default) {
|
||||
float max_width = 0;
|
||||
for_each_child([&](auto& child) {
|
||||
if (child.is_box())
|
||||
|
@ -96,13 +96,13 @@ void LayoutBlock::layout_block_children(LayoutMode line_break_policy)
|
|||
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());
|
||||
m_line_boxes.clear();
|
||||
for_each_child([&](auto& child) {
|
||||
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) {
|
||||
|
@ -188,7 +188,7 @@ void LayoutBlock::layout_inline_children(LayoutMode line_break_policy)
|
|||
if (fragment.layout_node().is_inline_block()) {
|
||||
auto& inline_block = const_cast<LayoutBlock&>(to<LayoutBlock>(fragment.layout_node()));
|
||||
inline_block.set_rect(fragment.rect());
|
||||
inline_block.layout(line_break_policy);
|
||||
inline_block.layout(layout_mode);
|
||||
}
|
||||
|
||||
float final_line_box_width = 0;
|
||||
|
@ -202,7 +202,7 @@ void LayoutBlock::layout_inline_children(LayoutMode line_break_policy)
|
|||
content_height += max_height;
|
||||
}
|
||||
|
||||
if (line_break_policy != LayoutMode::Default) {
|
||||
if (layout_mode != LayoutMode::Default) {
|
||||
rect().set_width(max_linebox_width);
|
||||
}
|
||||
|
||||
|
@ -501,11 +501,11 @@ LineBox& LayoutBlock::add_line_box()
|
|||
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());
|
||||
|
||||
layout(line_break_policy);
|
||||
layout(layout_mode);
|
||||
|
||||
auto* line_box = &container.ensure_last_line_box();
|
||||
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_height(node().requested_height());
|
||||
LayoutReplaced::layout(line_break_policy);
|
||||
LayoutReplaced::layout(layout_mode);
|
||||
}
|
||||
|
||||
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());
|
||||
rect().set_width(document().frame()->size().width());
|
||||
|
||||
LayoutNode::layout(line_break_policy);
|
||||
LayoutNode::layout(layout_mode);
|
||||
|
||||
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()) {
|
||||
rect().set_width(node().preferred_width());
|
||||
|
@ -57,7 +57,7 @@ void LayoutImage::layout(LayoutMode line_break_policy)
|
|||
rect().set_height(16);
|
||||
}
|
||||
|
||||
LayoutReplaced::layout(line_break_policy);
|
||||
LayoutReplaced::layout(layout_mode);
|
||||
}
|
||||
|
||||
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) {
|
||||
remove_child(*m_marker);
|
||||
m_marker = nullptr;
|
||||
}
|
||||
|
||||
LayoutBlock::layout(line_break_policy);
|
||||
LayoutBlock::layout(layout_mode);
|
||||
|
||||
if (!m_marker) {
|
||||
m_marker = adopt(*new LayoutListItemMarker);
|
||||
|
|
|
@ -46,10 +46,10 @@ LayoutNode::~LayoutNode()
|
|||
m_node->set_layout_node({}, nullptr);
|
||||
}
|
||||
|
||||
void LayoutNode::layout(LayoutMode line_break_policy)
|
||||
void LayoutNode::layout(LayoutMode layout_mode)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
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) {
|
||||
if (child.is_inline()) {
|
||||
child.split_into_lines(container, line_break_policy);
|
||||
child.split_into_lines(container, layout_mode);
|
||||
} else {
|
||||
// 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();
|
||||
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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -95,7 +95,7 @@ void LayoutText::render_fragment(RenderingContext& context, const LineBoxFragmen
|
|||
}
|
||||
|
||||
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);
|
||||
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 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;
|
||||
|
||||
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_newline = false;
|
||||
for (auto it = view.begin(); it != view.end();) {
|
||||
if (line_break_policy == LayoutMode::AllPossibleLineBreaks) {
|
||||
if (layout_mode == LayoutMode::AllPossibleLineBreaks) {
|
||||
commit_chunk(it, false);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
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) {
|
||||
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) {
|
||||
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_wrap_lines = true;
|
||||
|
@ -261,7 +261,7 @@ void LayoutText::split_into_lines(LayoutBlock& container, LayoutMode line_break_
|
|||
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();
|
||||
}
|
||||
|
||||
void LayoutWidget::layout(LayoutMode line_break_policy)
|
||||
void LayoutWidget::layout(LayoutMode layout_mode)
|
||||
{
|
||||
rect().set_size(widget().width(), widget().height());
|
||||
LayoutReplaced::layout(line_break_policy);
|
||||
LayoutReplaced::layout(layout_mode);
|
||||
widget().move_to(rect().x(), rect().y());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue