mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +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
8 changed files with 55 additions and 23 deletions
|
@ -244,4 +244,29 @@ CSS::TextAlign StyleProperties::text_align() const
|
||||||
return CSS::TextAlign::Left;
|
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;
|
String string_or_fallback(CSS::PropertyID, const StringView& fallback) const;
|
||||||
Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const;
|
Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const;
|
||||||
CSS::TextAlign text_align() const;
|
CSS::TextAlign text_align() const;
|
||||||
|
CSS::Display display() const;
|
||||||
|
|
||||||
const Gfx::Font& font() const
|
const Gfx::Font& font() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -123,6 +123,18 @@ enum class TextAlign {
|
||||||
VendorSpecificCenter,
|
VendorSpecificCenter,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class Display {
|
||||||
|
None,
|
||||||
|
Block,
|
||||||
|
Inline,
|
||||||
|
InlineBlock,
|
||||||
|
ListItem,
|
||||||
|
Table,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
TableRowGroup,
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class StyleValue : public RefCounted<StyleValue> {
|
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);
|
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||||
const_cast<Element&>(*this).m_resolved_style = 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;
|
return nullptr;
|
||||||
|
|
||||||
if (tag_name() == "noscript" && document().is_scripting_enabled())
|
if (tag_name() == "noscript" && document().is_scripting_enabled())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
if (display == "block")
|
if (display == CSS::Display::Block)
|
||||||
return adopt(*new LayoutBlock(this, move(style)));
|
return adopt(*new LayoutBlock(this, move(style)));
|
||||||
if (display == "inline")
|
if (display == CSS::Display::Inline)
|
||||||
return adopt(*new LayoutInline(*this, move(style)));
|
return adopt(*new LayoutInline(*this, move(style)));
|
||||||
if (display == "list-item")
|
if (display == CSS::Display::ListItem)
|
||||||
return adopt(*new LayoutListItem(*this, move(style)));
|
return adopt(*new LayoutListItem(*this, move(style)));
|
||||||
if (display == "table")
|
if (display == CSS::Display::Table)
|
||||||
return adopt(*new LayoutTable(*this, move(style)));
|
return adopt(*new LayoutTable(*this, move(style)));
|
||||||
if (display == "table-row")
|
if (display == CSS::Display::TableRow)
|
||||||
return adopt(*new LayoutTableRow(*this, move(style)));
|
return adopt(*new LayoutTableRow(*this, move(style)));
|
||||||
if (display == "table-cell")
|
if (display == CSS::Display::TableCell)
|
||||||
return adopt(*new LayoutTableCell(*this, move(style)));
|
return adopt(*new LayoutTableCell(*this, move(style)));
|
||||||
if (display == "table-row-group")
|
if (display == CSS::Display::TableRowGroup)
|
||||||
return adopt(*new LayoutTableRowGroup(*this, move(style)));
|
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)));
|
auto inline_block = adopt(*new LayoutBlock(this, move(style)));
|
||||||
inline_block->set_inline(true);
|
inline_block->set_inline(true);
|
||||||
return inline_block;
|
return inline_block;
|
||||||
}
|
}
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
dbg() << "Unknown display type: _" << display << "_";
|
|
||||||
return adopt(*new LayoutBlock(this, move(style)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Element::parse_attribute(const FlyString& name, const String& value)
|
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_repaint = false;
|
||||||
bool needs_relayout = 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;
|
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))
|
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());
|
auto style = document().style_resolver().resolve_style(*this, &parent_layout_node->specified_style());
|
||||||
m_resolved_style = style;
|
m_resolved_style = style;
|
||||||
if (!layout_node()) {
|
if (!layout_node()) {
|
||||||
if (style->string_or_fallback(CSS::PropertyID::Display, "inline") == "none")
|
if (style->display() == CSS::Display::None)
|
||||||
return;
|
return;
|
||||||
// We need a new layout tree here!
|
// We need a new layout tree here!
|
||||||
LayoutTreeBuilder tree_builder;
|
LayoutTreeBuilder tree_builder;
|
||||||
|
|
|
@ -58,8 +58,7 @@ unsigned HTMLCanvasElement::height() const
|
||||||
RefPtr<LayoutNode> HTMLCanvasElement::create_layout_node(const StyleProperties* parent_style) const
|
RefPtr<LayoutNode> HTMLCanvasElement::create_layout_node(const StyleProperties* parent_style) const
|
||||||
{
|
{
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||||
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
|
if (style->display() == CSS::Display::None)
|
||||||
if (display == "none")
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return adopt(*new LayoutCanvas(*this, move(style)));
|
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
|
RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleProperties* parent_style) const
|
||||||
{
|
{
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||||
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
|
if (style->display() == CSS::Display::None)
|
||||||
if (display == "none")
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return adopt(*new LayoutImage(*this, move(style), m_image_loader));
|
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;
|
return nullptr;
|
||||||
|
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||||
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
|
if (style->display() == CSS::Display::None)
|
||||||
if (display == "none")
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
RefPtr<GUI::Widget> widget;
|
RefPtr<GUI::Widget> widget;
|
||||||
|
|
|
@ -67,8 +67,7 @@ RefPtr<LayoutNode> HTMLObjectElement::create_layout_node(const StyleProperties*
|
||||||
return HTMLElement::create_layout_node(parent_style);
|
return HTMLElement::create_layout_node(parent_style);
|
||||||
|
|
||||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||||
auto display = style->string_or_fallback(CSS::PropertyID::Display, "inline");
|
if (style->display() == CSS::Display::None)
|
||||||
if (display == "none")
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (m_image_loader.has_image())
|
if (m_image_loader.has_image())
|
||||||
return adopt(*new LayoutImage(*this, move(style), m_image_loader));
|
return adopt(*new LayoutImage(*this, move(style), m_image_loader));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue