diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2022-03-12 19:32:03 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-12 21:51:38 +0100 |
commit | b801ddf73d605dd80b5033c3eae3125ec2ffc4bb (patch) | |
tree | 47670038920dc4c8311d14809be507f73e81cccf | |
parent | 0679eadd62c86a1a7de7227054e03398e3a257fa (diff) | |
download | serenity-b801ddf73d605dd80b5033c3eae3125ec2ffc4bb.zip |
LibWeb: Apply the current text-justify value when justifying
This implements at least some of the specification. inter-character is
not yet handled. However as our current algorithm only considers
whitespace as word breaks, inter-word could technically be considered to
be handled. :^)
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h | 2 |
2 files changed, 14 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index ef367604cc..d5fb0b1cbc 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -166,8 +166,18 @@ void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode l dump_tree(box); } -void InlineFormattingContext::apply_justification_to_fragments(FormattingState::NodeState const& containing_block_state, LineBox& line_box, bool is_last_line) +void InlineFormattingContext::apply_justification_to_fragments(FormattingState::NodeState const& containing_block_state, CSS::TextJustify text_justify, LineBox& line_box, bool is_last_line) { + switch (text_justify) { + case CSS::TextJustify::None: + return; + // FIXME: These two cases currently fall back to auto, handle them as well. + case CSS::TextJustify::InterCharacter: + case CSS::TextJustify::InterWord: + case CSS::TextJustify::Auto: + break; + } + float excess_horizontal_space = containing_block_state.content_width - line_box.width(); // Only justify the text if the excess horizontal space is less than or @@ -265,12 +275,13 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) auto const& containing_block = this->containing_block(); auto text_align = containing_block.computed_values().text_align(); + auto text_justify = containing_block.computed_values().text_justify(); if (text_align == CSS::TextAlign::Justify) { auto const& containing_block_state = m_state.get(containing_block); for (size_t i = 0; i < line_boxes.size(); i++) { auto& line_box = line_boxes[i]; auto is_last_line = i == line_boxes.size() - 1; - apply_justification_to_fragments(containing_block_state, line_box, is_last_line); + apply_justification_to_fragments(containing_block_state, text_justify, line_box, is_last_line); } } } diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h index 5d2c9b596e..8f36f7048c 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h @@ -36,7 +36,7 @@ public: private: void generate_line_boxes(LayoutMode); - void apply_justification_to_fragments(FormattingState::NodeState const& containing_block_state, LineBox&, bool is_last_line); + void apply_justification_to_fragments(FormattingState::NodeState const& containing_block_state, CSS::TextJustify, LineBox&, bool is_last_line); }; } |