mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 16:05:07 +00:00
LibWeb: Rename Layout::Node::style() => computed_values()
This commit is contained in:
parent
e187a5365a
commit
e5490ae1d1
6 changed files with 22 additions and 22 deletions
|
@ -35,7 +35,7 @@ namespace Web::Layout {
|
||||||
|
|
||||||
void LineBox::add_fragment(Node& layout_node, int start, int length, float width, float height, LineBoxFragment::Type fragment_type)
|
void LineBox::add_fragment(Node& layout_node, int start, int length, float width, float height, LineBoxFragment::Type fragment_type)
|
||||||
{
|
{
|
||||||
bool text_align_is_justify = layout_node.style().text_align() == CSS::TextAlign::Justify;
|
bool text_align_is_justify = layout_node.computed_values().text_align() == CSS::TextAlign::Justify;
|
||||||
if (!text_align_is_justify && !m_fragments.is_empty() && &m_fragments.last().layout_node() == &layout_node) {
|
if (!text_align_is_justify && !m_fragments.is_empty() && &m_fragments.last().layout_node() == &layout_node) {
|
||||||
// The fragment we're adding is from the last Layout::Node on the line.
|
// The fragment we're adding is from the last Layout::Node on the line.
|
||||||
// Expand the last fragment instead of adding a new one with the same Layout::Node.
|
// Expand the last fragment instead of adding a new one with the same Layout::Node.
|
||||||
|
|
|
@ -57,7 +57,7 @@ Node::~Node()
|
||||||
|
|
||||||
bool Node::can_contain_boxes_with_position_absolute() const
|
bool Node::can_contain_boxes_with_position_absolute() const
|
||||||
{
|
{
|
||||||
return style().position() != CSS::Position::Static || is<InitialContainingBlockBox>(*this);
|
return computed_values().position() != CSS::Position::Static || is<InitialContainingBlockBox>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const BlockBox* Node::containing_block() const
|
const BlockBox* Node::containing_block() const
|
||||||
|
@ -72,7 +72,7 @@ const BlockBox* Node::containing_block() const
|
||||||
if (is<TextNode>(*this))
|
if (is<TextNode>(*this))
|
||||||
return nearest_block_ancestor();
|
return nearest_block_ancestor();
|
||||||
|
|
||||||
auto position = style().position();
|
auto position = computed_values().position();
|
||||||
|
|
||||||
if (position == CSS::Position::Absolute) {
|
if (position == CSS::Position::Absolute) {
|
||||||
auto* ancestor = parent();
|
auto* ancestor = parent();
|
||||||
|
@ -186,19 +186,19 @@ bool Node::is_floating() const
|
||||||
{
|
{
|
||||||
if (!has_style())
|
if (!has_style())
|
||||||
return false;
|
return false;
|
||||||
return style().float_() != CSS::Float::None;
|
return computed_values().float_() != CSS::Float::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::is_positioned() const
|
bool Node::is_positioned() const
|
||||||
{
|
{
|
||||||
return has_style() && style().position() != CSS::Position::Static;
|
return has_style() && computed_values().position() != CSS::Position::Static;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::is_absolutely_positioned() const
|
bool Node::is_absolutely_positioned() const
|
||||||
{
|
{
|
||||||
if (!has_style())
|
if (!has_style())
|
||||||
return false;
|
return false;
|
||||||
auto position = style().position();
|
auto position = computed_values().position();
|
||||||
return position == CSS::Position::Absolute || position == CSS::Position::Fixed;
|
return position == CSS::Position::Absolute || position == CSS::Position::Fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ bool Node::is_fixed_position() const
|
||||||
{
|
{
|
||||||
if (!has_style())
|
if (!has_style())
|
||||||
return false;
|
return false;
|
||||||
auto position = style().position();
|
auto position = computed_values().position();
|
||||||
return position == CSS::Position::Fixed;
|
return position == CSS::Position::Fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ public:
|
||||||
|
|
||||||
const Gfx::Font& font() const;
|
const Gfx::Font& font() const;
|
||||||
const CSS::StyleProperties& specified_style() const;
|
const CSS::StyleProperties& specified_style() const;
|
||||||
const CSS::ImmutableComputedValues& style() const;
|
const CSS::ImmutableComputedValues& computed_values() const;
|
||||||
|
|
||||||
NodeWithStyle* parent();
|
NodeWithStyle* parent();
|
||||||
const NodeWithStyle* parent() const;
|
const NodeWithStyle* parent() const;
|
||||||
|
@ -247,7 +247,7 @@ inline const CSS::StyleProperties& Node::specified_style() const
|
||||||
return parent()->specified_style();
|
return parent()->specified_style();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const CSS::ImmutableComputedValues& Node::style() const
|
inline const CSS::ImmutableComputedValues& Node::computed_values() const
|
||||||
{
|
{
|
||||||
if (m_has_style)
|
if (m_has_style)
|
||||||
return static_cast<const NodeWithStyle*>(this)->computed_values();
|
return static_cast<const NodeWithStyle*>(this)->computed_values();
|
||||||
|
|
|
@ -84,7 +84,7 @@ void TableFormattingContext::calculate_column_widths(Box& row, Vector<float>& co
|
||||||
{
|
{
|
||||||
size_t column_index = 0;
|
size_t column_index = 0;
|
||||||
auto* table = row.first_ancestor_of_type<TableBox>();
|
auto* table = row.first_ancestor_of_type<TableBox>();
|
||||||
bool use_auto_layout = !table || table->style().width().is_undefined_or_auto();
|
bool use_auto_layout = !table || table->computed_values().width().is_undefined_or_auto();
|
||||||
row.for_each_child_of_type<TableCellBox>([&](auto& cell) {
|
row.for_each_child_of_type<TableCellBox>([&](auto& cell) {
|
||||||
compute_width(cell);
|
compute_width(cell);
|
||||||
if (use_auto_layout) {
|
if (use_auto_layout) {
|
||||||
|
@ -103,7 +103,7 @@ void TableFormattingContext::layout_row(Box& row, Vector<float>& column_widths)
|
||||||
float tallest_cell_height = 0;
|
float tallest_cell_height = 0;
|
||||||
float content_width = 0;
|
float content_width = 0;
|
||||||
auto* table = row.first_ancestor_of_type<TableBox>();
|
auto* table = row.first_ancestor_of_type<TableBox>();
|
||||||
bool use_auto_layout = !table || table->style().width().is_undefined_or_auto();
|
bool use_auto_layout = !table || table->computed_values().width().is_undefined_or_auto();
|
||||||
|
|
||||||
row.for_each_child_of_type<TableCellBox>([&](auto& cell) {
|
row.for_each_child_of_type<TableCellBox>([&](auto& cell) {
|
||||||
cell.set_offset(row.effective_offset().translated(content_width, 0));
|
cell.set_offset(row.effective_offset().translated(content_width, 0));
|
||||||
|
|
|
@ -77,7 +77,7 @@ void TextNode::paint_fragment(PaintContext& context, const LineBoxFragment& frag
|
||||||
auto& painter = context.painter();
|
auto& painter = context.painter();
|
||||||
|
|
||||||
if (phase == PaintPhase::Background) {
|
if (phase == PaintPhase::Background) {
|
||||||
painter.fill_rect(enclosing_int_rect(fragment.absolute_rect()), style().background_color());
|
painter.fill_rect(enclosing_int_rect(fragment.absolute_rect()), computed_values().background_color());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phase == PaintPhase::Foreground) {
|
if (phase == PaintPhase::Foreground) {
|
||||||
|
@ -86,18 +86,18 @@ void TextNode::paint_fragment(PaintContext& context, const LineBoxFragment& frag
|
||||||
if (document().inspected_node() == &dom_node())
|
if (document().inspected_node() == &dom_node())
|
||||||
context.painter().draw_rect(enclosing_int_rect(fragment.absolute_rect()), Color::Magenta);
|
context.painter().draw_rect(enclosing_int_rect(fragment.absolute_rect()), Color::Magenta);
|
||||||
|
|
||||||
if (style().text_decoration_line() == CSS::TextDecorationLine::Underline)
|
if (computed_values().text_decoration_line() == CSS::TextDecorationLine::Underline)
|
||||||
painter.draw_line(enclosing_int_rect(fragment.absolute_rect()).bottom_left().translated(0, 1), enclosing_int_rect(fragment.absolute_rect()).bottom_right().translated(0, 1), style().color());
|
painter.draw_line(enclosing_int_rect(fragment.absolute_rect()).bottom_left().translated(0, 1), enclosing_int_rect(fragment.absolute_rect()).bottom_right().translated(0, 1), computed_values().color());
|
||||||
|
|
||||||
// FIXME: text-transform should be done already in layout, since uppercase glyphs may be wider than lowercase, etc.
|
// FIXME: text-transform should be done already in layout, since uppercase glyphs may be wider than lowercase, etc.
|
||||||
auto text = m_text_for_rendering;
|
auto text = m_text_for_rendering;
|
||||||
auto text_transform = style().text_transform();
|
auto text_transform = computed_values().text_transform();
|
||||||
if (text_transform == CSS::TextTransform::Uppercase)
|
if (text_transform == CSS::TextTransform::Uppercase)
|
||||||
text = m_text_for_rendering.to_uppercase();
|
text = m_text_for_rendering.to_uppercase();
|
||||||
if (text_transform == CSS::TextTransform::Lowercase)
|
if (text_transform == CSS::TextTransform::Lowercase)
|
||||||
text = m_text_for_rendering.to_lowercase();
|
text = m_text_for_rendering.to_lowercase();
|
||||||
|
|
||||||
painter.draw_text(enclosing_int_rect(fragment.absolute_rect()), text.substring_view(fragment.start(), fragment.length()), Gfx::TextAlignment::CenterLeft, style().color());
|
painter.draw_text(enclosing_int_rect(fragment.absolute_rect()), text.substring_view(fragment.start(), fragment.length()), Gfx::TextAlignment::CenterLeft, computed_values().color());
|
||||||
|
|
||||||
auto selection_rect = fragment.selection_rect(font());
|
auto selection_rect = fragment.selection_rect(font());
|
||||||
if (!selection_rect.is_empty()) {
|
if (!selection_rect.is_empty()) {
|
||||||
|
@ -135,7 +135,7 @@ void TextNode::paint_cursor_if_needed(PaintContext& context, const LineBoxFragme
|
||||||
float cursor_height = fragment_rect.height();
|
float cursor_height = fragment_rect.height();
|
||||||
Gfx::IntRect cursor_rect(cursor_x, cursor_top, 1, cursor_height);
|
Gfx::IntRect cursor_rect(cursor_x, cursor_top, 1, cursor_height);
|
||||||
|
|
||||||
context.painter().draw_rect(cursor_rect, style().color());
|
context.painter().draw_rect(cursor_rect, computed_values().color());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
|
@ -302,19 +302,19 @@ void TextNode::split_into_lines(InlineFormattingContext& context, LayoutMode lay
|
||||||
bool do_wrap_lines = true;
|
bool do_wrap_lines = true;
|
||||||
bool do_wrap_breaks = false;
|
bool do_wrap_breaks = false;
|
||||||
|
|
||||||
if (style().white_space() == CSS::WhiteSpace::Nowrap) {
|
if (computed_values().white_space() == CSS::WhiteSpace::Nowrap) {
|
||||||
do_collapse = true;
|
do_collapse = true;
|
||||||
do_wrap_lines = false;
|
do_wrap_lines = false;
|
||||||
do_wrap_breaks = false;
|
do_wrap_breaks = false;
|
||||||
} else if (style().white_space() == CSS::WhiteSpace::Pre) {
|
} else if (computed_values().white_space() == CSS::WhiteSpace::Pre) {
|
||||||
do_collapse = false;
|
do_collapse = false;
|
||||||
do_wrap_lines = false;
|
do_wrap_lines = false;
|
||||||
do_wrap_breaks = true;
|
do_wrap_breaks = true;
|
||||||
} else if (style().white_space() == CSS::WhiteSpace::PreLine) {
|
} else if (computed_values().white_space() == CSS::WhiteSpace::PreLine) {
|
||||||
do_collapse = true;
|
do_collapse = true;
|
||||||
do_wrap_lines = true;
|
do_wrap_lines = true;
|
||||||
do_wrap_breaks = true;
|
do_wrap_breaks = true;
|
||||||
} else if (style().white_space() == CSS::WhiteSpace::PreWrap) {
|
} else if (computed_values().white_space() == CSS::WhiteSpace::PreWrap) {
|
||||||
do_collapse = false;
|
do_collapse = false;
|
||||||
do_wrap_lines = true;
|
do_wrap_lines = true;
|
||||||
do_wrap_breaks = true;
|
do_wrap_breaks = true;
|
||||||
|
|
|
@ -43,7 +43,7 @@ StackingContext::StackingContext(Box& box, StackingContext* parent)
|
||||||
|
|
||||||
// FIXME: Don't sort on every append..
|
// FIXME: Don't sort on every append..
|
||||||
quick_sort(m_parent->m_children, [](auto& a, auto& b) {
|
quick_sort(m_parent->m_children, [](auto& a, auto& b) {
|
||||||
return a->m_box.style().z_index().value_or(0) < b->m_box.style().z_index().value_or(0);
|
return a->m_box.computed_values().z_index().value_or(0) < b->m_box.computed_values().z_index().value_or(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue