LibWeb: Basic support for CSS text-indent: <length-percentage>
Note that this simple form of text-indent only affects the first line of formatted content in each block. Percentages are resolved against the width of the block.
This commit is contained in:
parent
9c2d496dbe
commit
5d4e9a0673
Notes:
sideshowbarker
2024-07-16 20:12:09 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5d4e9a0673 Pull-request: https://github.com/SerenityOS/serenity/pull/18855
6 changed files with 55 additions and 0 deletions
28
Tests/LibWeb/Layout/expected/text-indent.txt
Normal file
28
Tests/LibWeb/Layout/expected/text-indent.txt
Normal file
|
@ -0,0 +1,28 @@
|
|||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
BlockContainer <html> at (1,1) content-size 798x161.21875 [BFC] children: not-inline
|
||||
BlockContainer <body> at (10,10) content-size 780x143.21875 children: not-inline
|
||||
BlockContainer <div.px-indent> at (11,11) content-size 778x68.9375 children: not-inline
|
||||
BlockContainer <(anonymous)> at (11,11) content-size 778x17.46875 children: inline
|
||||
line 0 width: 142.390625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||
frag 0 from TextNode start: 0, length: 11, rect: [61,11 92.390625x17.46875]
|
||||
"50px indent"
|
||||
TextNode <#text>
|
||||
BlockContainer <p> at (12,45.46875) content-size 776x17.46875 children: inline
|
||||
line 0 width: 140.921875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||
frag 0 from TextNode start: 0, length: 12, rect: [62,45.46875 90.921875x17.46875]
|
||||
"is inherited"
|
||||
TextNode <#text>
|
||||
BlockContainer <div.pct-indent> at (11,81.9375) content-size 100x70.28125 children: inline
|
||||
line 0 width: 80.34375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||
frag 0 from TextNode start: 0, length: 3, rect: [61,81.9375 30.34375x17.46875]
|
||||
"50%"
|
||||
line 1 width: 88.15625, height: 17.9375, bottom: 35.40625, baseline: 13.53125
|
||||
frag 0 from TextNode start: 4, length: 11, rect: [11,98.9375 88.15625x17.46875]
|
||||
"indent snip"
|
||||
line 2 width: 78.703125, height: 18.40625, bottom: 53.34375, baseline: 13.53125
|
||||
frag 0 from TextNode start: 16, length: 9, rect: [11,115.9375 78.703125x17.46875]
|
||||
"snap snib"
|
||||
line 3 width: 37.765625, height: 17.875, bottom: 70.28125, baseline: 13.53125
|
||||
frag 0 from TextNode start: 26, length: 4, rect: [11,133.9375 37.765625x17.46875]
|
||||
"snab"
|
||||
TextNode <#text>
|
13
Tests/LibWeb/Layout/input/text-indent.html
Normal file
13
Tests/LibWeb/Layout/input/text-indent.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!doctype html><style>
|
||||
* {
|
||||
border: 1px solid black;
|
||||
font: 16px SerenitySans;
|
||||
}
|
||||
.px-indent {
|
||||
text-indent: 50px;
|
||||
}
|
||||
.pct-indent {
|
||||
text-indent: 50%;
|
||||
width: 100px;
|
||||
}
|
||||
</style><div class="px-indent">50px indent <p>is inherited</p></div><div class="pct-indent">50% indent snip snap snib snab</pct>
|
|
@ -39,6 +39,7 @@ public:
|
|||
static CSS::Length text_decoration_thickness() { return Length::make_auto(); }
|
||||
static CSS::TextDecorationStyle text_decoration_style() { return CSS::TextDecorationStyle::Solid; }
|
||||
static CSS::TextTransform text_transform() { return CSS::TextTransform::None; }
|
||||
static CSS::LengthPercentage text_indent() { return CSS::Length::make_px(0); }
|
||||
static CSS::Display display() { return CSS::Display { CSS::Display::Outside::Inline, CSS::Display::Inside::Flow }; }
|
||||
static Color color() { return Color::Black; }
|
||||
static Color stop_color() { return Color::Black; }
|
||||
|
@ -211,6 +212,7 @@ public:
|
|||
Optional<int> const& z_index() const { return m_noninherited.z_index; }
|
||||
CSS::TextAlign text_align() const { return m_inherited.text_align; }
|
||||
CSS::TextJustify text_justify() const { return m_inherited.text_justify; }
|
||||
CSS::LengthPercentage const& text_indent() const { return m_inherited.text_indent; }
|
||||
Vector<CSS::TextDecorationLine> const& text_decoration_line() const { return m_noninherited.text_decoration_line; }
|
||||
CSS::LengthPercentage const& text_decoration_thickness() const { return m_noninherited.text_decoration_thickness; }
|
||||
CSS::TextDecorationStyle text_decoration_style() const { return m_noninherited.text_decoration_style; }
|
||||
|
@ -310,6 +312,7 @@ protected:
|
|||
CSS::TextAlign text_align { InitialValues::text_align() };
|
||||
CSS::TextJustify text_justify { InitialValues::text_justify() };
|
||||
CSS::TextTransform text_transform { InitialValues::text_transform() };
|
||||
CSS::LengthPercentage text_indent { InitialValues::text_indent() };
|
||||
CSS::WhiteSpace white_space { InitialValues::white_space() };
|
||||
CSS::ListStyleType list_style_type { InitialValues::list_style_type() };
|
||||
CSS::Visibility visibility { InitialValues::visibility() };
|
||||
|
@ -413,6 +416,7 @@ public:
|
|||
void set_text_decoration_color(Color value) { m_noninherited.text_decoration_color = value; }
|
||||
void set_text_transform(CSS::TextTransform value) { m_inherited.text_transform = value; }
|
||||
void set_text_shadow(Vector<ShadowData>&& value) { m_noninherited.text_shadow = move(value); }
|
||||
void set_text_indent(CSS::LengthPercentage value) { m_inherited.text_indent = move(value); }
|
||||
void set_position(CSS::Position position) { m_noninherited.position = position; }
|
||||
void set_white_space(CSS::WhiteSpace value) { m_inherited.white_space = value; }
|
||||
void set_width(CSS::Size const& width) { m_noninherited.width = width; }
|
||||
|
|
|
@ -15,6 +15,7 @@ LineBuilder::LineBuilder(InlineFormattingContext& context, LayoutState& layout_s
|
|||
, m_layout_state(layout_state)
|
||||
, m_containing_block_state(layout_state.get_mutable(context.containing_block()))
|
||||
{
|
||||
m_text_indent = m_context.containing_block().computed_values().text_indent().to_px(m_context.containing_block(), m_containing_block_state.content_width());
|
||||
begin_new_line(false);
|
||||
}
|
||||
|
||||
|
@ -66,6 +67,11 @@ void LineBuilder::begin_new_line(bool increment_y, bool is_first_break_in_sequen
|
|||
recalculate_available_space();
|
||||
m_max_height_on_current_line = 0;
|
||||
m_last_line_needs_update = true;
|
||||
|
||||
// FIXME: Support text-indent with "each-line".
|
||||
if (m_containing_block_state.line_boxes.size() <= 1) {
|
||||
ensure_last_line_box().m_width += m_text_indent;
|
||||
}
|
||||
}
|
||||
|
||||
LineBox& LineBuilder::ensure_last_line_box()
|
||||
|
|
|
@ -57,6 +57,7 @@ private:
|
|||
CSSPixels m_available_width_for_current_line { 0 };
|
||||
CSSPixels m_current_y { 0 };
|
||||
CSSPixels m_max_height_on_current_line { 0 };
|
||||
CSSPixels m_text_indent { 0 };
|
||||
|
||||
bool m_last_line_needs_update { false };
|
||||
};
|
||||
|
|
|
@ -507,6 +507,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
|
|||
if (text_align.has_value())
|
||||
computed_values.set_text_justify(text_justify.value());
|
||||
|
||||
if (auto text_indent = computed_style.length_percentage(CSS::PropertyID::TextIndent); text_indent.has_value())
|
||||
computed_values.set_text_indent(text_indent.release_value());
|
||||
|
||||
auto white_space = computed_style.white_space();
|
||||
if (white_space.has_value())
|
||||
computed_values.set_white_space(white_space.value());
|
||||
|
|
Loading…
Add table
Reference in a new issue