mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibWeb: Add CSS::Display enum and StyleProperties::display()
The display property is not interesting after we've built the layout tree, so we don't have to move it into LayoutStyle.
This commit is contained in:
parent
5d86305a72
commit
bc178ee743
Notes:
sideshowbarker
2024-07-19 05:24:28 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/bc178ee7430
8 changed files with 55 additions and 23 deletions
|
@ -244,4 +244,29 @@ CSS::TextAlign StyleProperties::text_align() const
|
|||
return CSS::TextAlign::Left;
|
||||
}
|
||||
|
||||
CSS::Display StyleProperties::display() const
|
||||
{
|
||||
auto display = string_or_fallback(CSS::PropertyID::Display, "inline");
|
||||
if (display == "none")
|
||||
return CSS::Display::None;
|
||||
if (display == "block")
|
||||
return CSS::Display::Block;
|
||||
if (display == "inline")
|
||||
return CSS::Display::Inline;
|
||||
if (display == "inline-block")
|
||||
return CSS::Display::InlineBlock;
|
||||
if (display == "list-item")
|
||||
return CSS::Display::ListItem;
|
||||
if (display == "table")
|
||||
return CSS::Display::Table;
|
||||
if (display == "table-row")
|
||||
return CSS::Display::TableRow;
|
||||
if (display == "table-cell")
|
||||
return CSS::Display::TableCell;
|
||||
if (display == "table-row-group")
|
||||
return CSS::Display::TableRowGroup;
|
||||
dbg() << "Unknown display type: _" << display << "_";
|
||||
return CSS::Display::Block;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
String string_or_fallback(CSS::PropertyID, const StringView& fallback) const;
|
||||
Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const;
|
||||
CSS::TextAlign text_align() const;
|
||||
CSS::Display display() const;
|
||||
|
||||
const Gfx::Font& font() const
|
||||
{
|
||||
|
|
|
@ -123,6 +123,18 @@ enum class TextAlign {
|
|||
VendorSpecificCenter,
|
||||
};
|
||||
|
||||
enum class Display {
|
||||
None,
|
||||
Block,
|
||||
Inline,
|
||||
InlineBlock,
|
||||
ListItem,
|
||||
Table,
|
||||
TableRow,
|
||||
TableCell,
|
||||
TableRowGroup,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class StyleValue : public RefCounted<StyleValue> {
|
||||
|
|
|
@ -111,36 +111,34 @@ RefPtr<LayoutNode> Element::create_layout_node(const StyleProperties* parent_sty
|
|||
{
|
||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||
const_cast<Element&>(*this).m_resolved_style = style;
|
||||
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
|
||||
auto display = style->display();
|
||||
|
||||
if (display == "none")
|
||||
if (display == CSS::Display::None)
|
||||
return nullptr;
|
||||
|
||||
if (tag_name() == "noscript" && document().is_scripting_enabled())
|
||||
return nullptr;
|
||||
|
||||
if (display == "block")
|
||||
if (display == CSS::Display::Block)
|
||||
return adopt(*new LayoutBlock(this, move(style)));
|
||||
if (display == "inline")
|
||||
if (display == CSS::Display::Inline)
|
||||
return adopt(*new LayoutInline(*this, move(style)));
|
||||
if (display == "list-item")
|
||||
if (display == CSS::Display::ListItem)
|
||||
return adopt(*new LayoutListItem(*this, move(style)));
|
||||
if (display == "table")
|
||||
if (display == CSS::Display::Table)
|
||||
return adopt(*new LayoutTable(*this, move(style)));
|
||||
if (display == "table-row")
|
||||
if (display == CSS::Display::TableRow)
|
||||
return adopt(*new LayoutTableRow(*this, move(style)));
|
||||
if (display == "table-cell")
|
||||
if (display == CSS::Display::TableCell)
|
||||
return adopt(*new LayoutTableCell(*this, move(style)));
|
||||
if (display == "table-row-group")
|
||||
if (display == CSS::Display::TableRowGroup)
|
||||
return adopt(*new LayoutTableRowGroup(*this, move(style)));
|
||||
if (display == "inline-block") {
|
||||
if (display == CSS::Display::InlineBlock) {
|
||||
auto inline_block = adopt(*new LayoutBlock(this, move(style)));
|
||||
inline_block->set_inline(true);
|
||||
return inline_block;
|
||||
}
|
||||
|
||||
dbg() << "Unknown display type: _" << display << "_";
|
||||
return adopt(*new LayoutBlock(this, move(style)));
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
void Element::parse_attribute(const FlyString& name, const String& value)
|
||||
|
@ -169,7 +167,7 @@ static StyleDifference compute_style_difference(const StyleProperties& old_style
|
|||
bool needs_repaint = false;
|
||||
bool needs_relayout = false;
|
||||
|
||||
if (new_style.string_or_fallback(CSS::PropertyID::Display, "block") != old_style.string_or_fallback(CSS::PropertyID::Color, "block"))
|
||||
if (new_style.display() != old_style.display())
|
||||
needs_relayout = true;
|
||||
|
||||
if (new_style.color_or_fallback(CSS::PropertyID::Color, document, Color::Black) != old_style.color_or_fallback(CSS::PropertyID::Color, document, Color::Black))
|
||||
|
@ -195,7 +193,7 @@ void Element::recompute_style()
|
|||
auto style = document().style_resolver().resolve_style(*this, &parent_layout_node->specified_style());
|
||||
m_resolved_style = style;
|
||||
if (!layout_node()) {
|
||||
if (style->string_or_fallback(CSS::PropertyID::Display, "inline") == "none")
|
||||
if (style->display() == CSS::Display::None)
|
||||
return;
|
||||
// We need a new layout tree here!
|
||||
LayoutTreeBuilder tree_builder;
|
||||
|
|
|
@ -58,8 +58,7 @@ unsigned HTMLCanvasElement::height() const
|
|||
RefPtr<LayoutNode> HTMLCanvasElement::create_layout_node(const StyleProperties* parent_style) const
|
||||
{
|
||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
|
||||
if (display == "none")
|
||||
if (style->display() == CSS::Display::None)
|
||||
return nullptr;
|
||||
return adopt(*new LayoutCanvas(*this, move(style)));
|
||||
}
|
||||
|
|
|
@ -71,8 +71,7 @@ void HTMLImageElement::parse_attribute(const FlyString& name, const String& valu
|
|||
RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleProperties* parent_style) const
|
||||
{
|
||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
|
||||
if (display == "none")
|
||||
if (style->display() == CSS::Display::None)
|
||||
return nullptr;
|
||||
return adopt(*new LayoutImage(*this, move(style), m_image_loader));
|
||||
}
|
||||
|
|
|
@ -56,8 +56,7 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties* p
|
|||
return nullptr;
|
||||
|
||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
|
||||
if (display == "none")
|
||||
if (style->display() == CSS::Display::None)
|
||||
return nullptr;
|
||||
|
||||
RefPtr<GUI::Widget> widget;
|
||||
|
|
|
@ -67,8 +67,7 @@ RefPtr<LayoutNode> HTMLObjectElement::create_layout_node(const StyleProperties*
|
|||
return HTMLElement::create_layout_node(parent_style);
|
||||
|
||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
|
||||
if (display == "none")
|
||||
if (style->display() == CSS::Display::None)
|
||||
return nullptr;
|
||||
if (m_image_loader.has_image())
|
||||
return adopt(*new LayoutImage(*this, move(style), m_image_loader));
|
||||
|
|
Loading…
Add table
Reference in a new issue