diff --git a/Libraries/LibWeb/CSS/StyleProperties.cpp b/Libraries/LibWeb/CSS/StyleProperties.cpp index 990392b052..b0e184171b 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -229,19 +229,19 @@ bool StyleProperties::operator==(const StyleProperties& other) const return true; } -CSS::ValueID StyleProperties::text_align() const +CSS::TextAlign StyleProperties::text_align() const { auto string = string_or_fallback(CSS::PropertyID::TextAlign, "left"); if (string == "center") - return CSS::ValueID::Center; + return CSS::TextAlign::Center; if (string == "right") - return CSS::ValueID::Right; + return CSS::TextAlign::Right; if (string == "justify") - return CSS::ValueID::Justify; + return CSS::TextAlign::Justify; if (string == "-libweb-center") - return CSS::ValueID::VendorSpecificCenter; + return CSS::TextAlign::VendorSpecificCenter; // Otherwise, just assume "left".. - return CSS::ValueID::Left; + return CSS::TextAlign::Left; } } diff --git a/Libraries/LibWeb/CSS/StyleProperties.h b/Libraries/LibWeb/CSS/StyleProperties.h index 7838123ac2..b48c098ec1 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Libraries/LibWeb/CSS/StyleProperties.h @@ -59,7 +59,7 @@ public: Length length_or_fallback(CSS::PropertyID, const Length& fallback, float reference_for_percentages) const; String string_or_fallback(CSS::PropertyID, const StringView& fallback) const; Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const; - CSS::ValueID text_align() const; + CSS::TextAlign text_align() const; const Gfx::Font& font() const { diff --git a/Libraries/LibWeb/CSS/StyleValue.h b/Libraries/LibWeb/CSS/StyleValue.h index 577620e031..d68d1680d5 100644 --- a/Libraries/LibWeb/CSS/StyleValue.h +++ b/Libraries/LibWeb/CSS/StyleValue.h @@ -114,6 +114,15 @@ enum class Position { Fixed, Sticky, }; + +enum class TextAlign { + Left, + Center, + Right, + Justify, + VendorSpecificCenter, +}; + } class StyleValue : public RefCounted { diff --git a/Libraries/LibWeb/Layout/LayoutBlock.cpp b/Libraries/LibWeb/Layout/LayoutBlock.cpp index 8f11b6b3fa..6fef0b9bb3 100644 --- a/Libraries/LibWeb/Layout/LayoutBlock.cpp +++ b/Libraries/LibWeb/Layout/LayoutBlock.cpp @@ -187,7 +187,7 @@ void LayoutBlock::layout_inline_children(LayoutMode layout_mode) line_box.trim_trailing_whitespace(); } - auto text_align = style().text_align(); + auto text_align = this->text_align(); float min_line_height = style().line_height(*this); float line_spacing = min_line_height - style().font().glyph_height(); float content_height = 0; @@ -203,22 +203,22 @@ void LayoutBlock::layout_inline_children(LayoutMode layout_mode) float excess_horizontal_space = (float)width() - line_box.width(); switch (text_align) { - case CSS::ValueID::Center: - case CSS::ValueID::VendorSpecificCenter: + case CSS::TextAlign::Center: + case CSS::TextAlign::VendorSpecificCenter: x_offset += excess_horizontal_space / 2; break; - case CSS::ValueID::Right: + case CSS::TextAlign::Right: x_offset += excess_horizontal_space; break; - case CSS::ValueID::Left: - case CSS::ValueID::Justify: + case CSS::TextAlign::Left: + case CSS::TextAlign::Justify: default: break; } float excess_horizontal_space_including_whitespace = excess_horizontal_space; int whitespace_count = 0; - if (text_align == CSS::ValueID::Justify) { + if (text_align == CSS::TextAlign::Justify) { for (auto& fragment : line_box.fragments()) { if (fragment.is_justifiable_whitespace()) { ++whitespace_count; @@ -236,7 +236,7 @@ void LayoutBlock::layout_inline_children(LayoutMode layout_mode) // FIXME: Support other kinds of vertical alignment. fragment.set_offset({ roundf(x_offset + fragment.offset().x()), content_height + (max_height - fragment.height()) - (line_spacing / 2) }); - if (text_align == CSS::ValueID::Justify) { + if (text_align == CSS::TextAlign::Justify) { if (fragment.is_justifiable_whitespace()) { if (fragment.width() != justified_space_width) { float diff = justified_space_width - fragment.width(); @@ -633,7 +633,7 @@ void LayoutBlock::place_block_level_non_replaced_element_in_normal_flow(LayoutBl + box.padding().left.to_px(*this) + box.offset().left.to_px(*this); - if (this->style().text_align() == CSS::ValueID::VendorSpecificCenter) { + if (text_align() == CSS::TextAlign::VendorSpecificCenter) { x = (containing_block.width() / 2) - block.width() / 2; } diff --git a/Libraries/LibWeb/Layout/LayoutNode.cpp b/Libraries/LibWeb/Layout/LayoutNode.cpp index fd7d24f7d2..236bc0840d 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.cpp +++ b/Libraries/LibWeb/Layout/LayoutNode.cpp @@ -217,6 +217,7 @@ LayoutNodeWithStyle::LayoutNodeWithStyle(const Node* node, NonnullRefPtrposition(); + m_text_align = m_style->text_align(); } } diff --git a/Libraries/LibWeb/Layout/LayoutNode.h b/Libraries/LibWeb/Layout/LayoutNode.h index fa0b2a7882..2dcca0b67a 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.h +++ b/Libraries/LibWeb/Layout/LayoutNode.h @@ -259,6 +259,7 @@ public: void set_style(const StyleProperties& style) { m_style = style; } CSS::Position position() const { return m_position; } + CSS::TextAlign text_align() const { return m_text_align; } protected: explicit LayoutNodeWithStyle(const Node*, NonnullRefPtr); @@ -266,6 +267,7 @@ protected: private: NonnullRefPtr m_style; CSS::Position m_position; + CSS::TextAlign m_text_align; }; class LayoutNodeWithStyleAndBoxModelMetrics : public LayoutNodeWithStyle {