diff --git a/Libraries/LibWeb/CSS/StyleProperties.cpp b/Libraries/LibWeb/CSS/StyleProperties.cpp index 6683ecb12b..e23f91c601 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -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; +} + } diff --git a/Libraries/LibWeb/CSS/StyleProperties.h b/Libraries/LibWeb/CSS/StyleProperties.h index b48c098ec1..f55c076275 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Libraries/LibWeb/CSS/StyleProperties.h @@ -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 { diff --git a/Libraries/LibWeb/CSS/StyleValue.h b/Libraries/LibWeb/CSS/StyleValue.h index 4bcf689e4b..abce26d2d4 100644 --- a/Libraries/LibWeb/CSS/StyleValue.h +++ b/Libraries/LibWeb/CSS/StyleValue.h @@ -123,6 +123,18 @@ enum class TextAlign { VendorSpecificCenter, }; +enum class Display { + None, + Block, + Inline, + InlineBlock, + ListItem, + Table, + TableRow, + TableCell, + TableRowGroup, +}; + } class StyleValue : public RefCounted { diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 0911c7da5c..4b9fb4bbe0 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -111,36 +111,34 @@ RefPtr Element::create_layout_node(const StyleProperties* parent_sty { auto style = document().style_resolver().resolve_style(*this, parent_style); const_cast(*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; diff --git a/Libraries/LibWeb/DOM/HTMLCanvasElement.cpp b/Libraries/LibWeb/DOM/HTMLCanvasElement.cpp index 6052dd2b83..816a73145d 100644 --- a/Libraries/LibWeb/DOM/HTMLCanvasElement.cpp +++ b/Libraries/LibWeb/DOM/HTMLCanvasElement.cpp @@ -58,8 +58,7 @@ unsigned HTMLCanvasElement::height() const RefPtr 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))); } diff --git a/Libraries/LibWeb/DOM/HTMLImageElement.cpp b/Libraries/LibWeb/DOM/HTMLImageElement.cpp index 7c0e969f8d..33d632b6a9 100644 --- a/Libraries/LibWeb/DOM/HTMLImageElement.cpp +++ b/Libraries/LibWeb/DOM/HTMLImageElement.cpp @@ -71,8 +71,7 @@ void HTMLImageElement::parse_attribute(const FlyString& name, const String& valu RefPtr 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)); } diff --git a/Libraries/LibWeb/DOM/HTMLInputElement.cpp b/Libraries/LibWeb/DOM/HTMLInputElement.cpp index bf77944f57..766ab7a83b 100644 --- a/Libraries/LibWeb/DOM/HTMLInputElement.cpp +++ b/Libraries/LibWeb/DOM/HTMLInputElement.cpp @@ -56,8 +56,7 @@ RefPtr 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 widget; diff --git a/Libraries/LibWeb/DOM/HTMLObjectElement.cpp b/Libraries/LibWeb/DOM/HTMLObjectElement.cpp index 951c7ae012..d97e0e2e33 100644 --- a/Libraries/LibWeb/DOM/HTMLObjectElement.cpp +++ b/Libraries/LibWeb/DOM/HTMLObjectElement.cpp @@ -67,8 +67,7 @@ RefPtr 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));