mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Parse and propagate extended text-indent property values
CSS Text 3 gives `text-indent` a couple of optional keywords to control which lines are affected. This commit parses them, but doesn't yet do anything with them.
This commit is contained in:
parent
eea1d4e1d2
commit
c4b9e7eadf
Notes:
github-actions[bot]
2025-11-20 15:03:53 +00:00
Author: https://github.com/AtkinsSJ
Commit: c4b9e7eadf
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6855
Reviewed-by: https://github.com/gmta ✅
16 changed files with 199 additions and 9 deletions
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include <LibGfx/Font/Font.h>
|
||||
#include <LibGfx/Font/FontStyleMapping.h>
|
||||
#include <LibGfx/Font/FontWeight.h>
|
||||
#include <LibWeb/CSS/CSSStyleValue.h>
|
||||
#include <LibWeb/CSS/ComputedProperties.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
|
|
@ -68,6 +67,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
||||
#include <LibWeb/CSS/StyleValues/SuperellipseStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/TextIndentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/TextUnderlinePositionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ namespace Web::CSS {
|
|||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Shorthand, shorthand, ShorthandStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(String, string, StringStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Superellipse, superellipse, SuperellipseStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(TextIndent, text_indent, TextIndentStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(TextUnderlinePosition, text_underline_position, TextUnderlinePositionStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Time, time, TimeStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Transformation, transformation, TransformationStyleValue) \
|
||||
|
|
|
|||
54
Libraries/LibWeb/CSS/StyleValues/TextIndentStyleValue.cpp
Normal file
54
Libraries/LibWeb/CSS/StyleValues/TextIndentStyleValue.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "TextIndentStyleValue.h"
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
ValueComparingNonnullRefPtr<TextIndentStyleValue const> TextIndentStyleValue::create(NonnullRefPtr<StyleValue const> length_percentage, Hanging hanging, EachLine each_line)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) TextIndentStyleValue(move(length_percentage), hanging, each_line));
|
||||
}
|
||||
|
||||
TextIndentStyleValue::TextIndentStyleValue(NonnullRefPtr<StyleValue const> length_percentage, Hanging hanging, EachLine each_line)
|
||||
: StyleValueWithDefaultOperators(Type::TextIndent)
|
||||
, m_length_percentage(move(length_percentage))
|
||||
, m_hanging(hanging == Hanging::Yes)
|
||||
, m_each_line(each_line == EachLine::Yes)
|
||||
{
|
||||
}
|
||||
|
||||
TextIndentStyleValue::~TextIndentStyleValue() = default;
|
||||
|
||||
String TextIndentStyleValue::to_string(SerializationMode mode) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append(m_length_percentage->to_string(mode));
|
||||
if (m_each_line)
|
||||
builder.append(" each-line"sv);
|
||||
if (m_hanging)
|
||||
builder.append(" hanging"sv);
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue const> TextIndentStyleValue::absolutized(ComputationContext const& context) const
|
||||
{
|
||||
auto new_length_percentage = m_length_percentage->absolutized(context);
|
||||
if (new_length_percentage->equals(m_length_percentage))
|
||||
return *this;
|
||||
return create(move(new_length_percentage),
|
||||
m_hanging ? Hanging::Yes : Hanging::No,
|
||||
m_each_line ? EachLine::Yes : EachLine::No);
|
||||
}
|
||||
|
||||
bool TextIndentStyleValue::properties_equal(TextIndentStyleValue const& other) const
|
||||
{
|
||||
return m_length_percentage == other.m_length_percentage
|
||||
&& m_each_line == other.m_each_line
|
||||
&& m_hanging == other.m_hanging;
|
||||
}
|
||||
|
||||
}
|
||||
43
Libraries/LibWeb/CSS/StyleValues/TextIndentStyleValue.h
Normal file
43
Libraries/LibWeb/CSS/StyleValues/TextIndentStyleValue.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class TextIndentStyleValue : public StyleValueWithDefaultOperators<TextIndentStyleValue> {
|
||||
public:
|
||||
enum class Hanging : u8 {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
enum class EachLine : u8 {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
static ValueComparingNonnullRefPtr<TextIndentStyleValue const> create(NonnullRefPtr<StyleValue const> length_percentage, Hanging hanging, EachLine each_line);
|
||||
virtual ~TextIndentStyleValue() override;
|
||||
|
||||
StyleValue const& length_percentage() const { return m_length_percentage; }
|
||||
bool hanging() const { return m_hanging; }
|
||||
bool each_line() const { return m_each_line; }
|
||||
|
||||
virtual String to_string(SerializationMode) const override;
|
||||
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&) const override;
|
||||
bool properties_equal(TextIndentStyleValue const&) const;
|
||||
|
||||
private:
|
||||
TextIndentStyleValue(NonnullRefPtr<StyleValue const> length_percentage, Hanging hanging, EachLine each_line);
|
||||
|
||||
NonnullRefPtr<StyleValue const> m_length_percentage;
|
||||
bool m_hanging;
|
||||
bool m_each_line;
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue