diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2022-03-12 19:31:32 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-12 21:51:38 +0100 |
commit | 0679eadd62c86a1a7de7227054e03398e3a257fa (patch) | |
tree | 6b02fa99aa3111a847d4145f3d473cafdeff8ffa /Userland/Libraries | |
parent | 7fe3f2d970304207bf22c7ea8db9bfe425281926 (diff) | |
download | serenity-0679eadd62c86a1a7de7227054e03398e3a257fa.zip |
LibWeb: Add support for the text-justify property
This commit adds the text-justify property as defined in:
https://drafts.csswg.org/css-text/#propdef-text-justify
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/ComputedValues.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Identifiers.json | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Properties.json | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleValue.h | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.cpp | 4 |
7 files changed, 50 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index c5cef946e8..40eb62c52e 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -21,6 +21,7 @@ public: static CSS::Cursor cursor() { return CSS::Cursor::Auto; } static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; } static CSS::TextAlign text_align() { return CSS::TextAlign::Left; } + static CSS::TextJustify text_justify() { return CSS::TextJustify::Auto; } static CSS::Position position() { return CSS::Position::Static; } static CSS::TextDecorationLine text_decoration_line() { return CSS::TextDecorationLine::None; } static CSS::Length text_decoration_thickness() { return Length::make_px(1); } @@ -111,6 +112,7 @@ public: CSS::Display display() const { return m_noninherited.display; } 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::TextDecorationLine text_decoration_line() const { return m_noninherited.text_decoration_line; } CSS::LengthPercentage text_decoration_thickness() const { return m_noninherited.text_decoration_thickness; } CSS::TextDecorationStyle text_decoration_style() const { return m_noninherited.text_decoration_style; } @@ -185,6 +187,7 @@ protected: CSS::ImageRendering image_rendering { InitialValues::image_rendering() }; CSS::PointerEvents pointer_events { InitialValues::pointer_events() }; CSS::TextAlign text_align { InitialValues::text_align() }; + CSS::TextJustify text_justify { InitialValues::text_justify() }; CSS::TextTransform text_transform { InitialValues::text_transform() }; CSS::WhiteSpace white_space { InitialValues::white_space() }; CSS::ListStyleType list_style_type { InitialValues::list_style_type() }; @@ -259,6 +262,7 @@ public: void set_clear(CSS::Clear value) { m_noninherited.clear = value; } void set_z_index(Optional<int> value) { m_noninherited.z_index = value; } void set_text_align(CSS::TextAlign text_align) { m_inherited.text_align = text_align; } + void set_text_justify(CSS::TextJustify text_justify) { m_inherited.text_justify = text_justify; } void set_text_decoration_line(CSS::TextDecorationLine value) { m_noninherited.text_decoration_line = value; } void set_text_decoration_thickness(CSS::LengthPercentage value) { m_noninherited.text_decoration_thickness = value; } void set_text_decoration_style(CSS::TextDecorationStyle value) { m_noninherited.text_decoration_style = value; } diff --git a/Userland/Libraries/LibWeb/CSS/Identifiers.json b/Userland/Libraries/LibWeb/CSS/Identifiers.json index 816333bb0d..a4588bae3f 100644 --- a/Userland/Libraries/LibWeb/CSS/Identifiers.json +++ b/Userland/Libraries/LibWeb/CSS/Identifiers.json @@ -97,6 +97,7 @@ "decimal-leading-zero", "default", "disc", + "distribute", "dotted", "double", "e-resize", @@ -129,6 +130,8 @@ "inset", "inside", "interlace", + "inter-character", + "inter-word", "invert", "italic", "justify", diff --git a/Userland/Libraries/LibWeb/CSS/Properties.json b/Userland/Libraries/LibWeb/CSS/Properties.json index 9e81881500..7188ed48c3 100644 --- a/Userland/Libraries/LibWeb/CSS/Properties.json +++ b/Userland/Libraries/LibWeb/CSS/Properties.json @@ -1287,6 +1287,17 @@ "unitless-length" ] }, + "text-justify": { + "inherited": true, + "initial": "auto", + "valid-identifiers": [ + "auto", + "none", + "inter-word", + "inter-character", + "distribute" + ] + }, "text-transform": { "inherited": true, "initial": "none", diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 584d775603..18e68eb399 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -438,6 +438,26 @@ Optional<CSS::TextAlign> StyleProperties::text_align() const } } +Optional<CSS::TextJustify> StyleProperties::text_justify() const +{ + auto value = property(CSS::PropertyID::TextJustify); + if (!value.has_value()) + return {}; + switch (value.value()->to_identifier()) { + case CSS::ValueID::Auto: + return CSS::TextJustify::Auto; + case CSS::ValueID::None: + return CSS::TextJustify::None; + case CSS::ValueID::InterWord: + return CSS::TextJustify::InterWord; + case CSS::ValueID::Distribute: + case CSS::ValueID::InterCharacter: + return CSS::TextJustify::InterCharacter; + default: + return {}; + } +} + Optional<CSS::PointerEvents> StyleProperties::pointer_events() const { auto value = property(CSS::PropertyID::PointerEvents); diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.h b/Userland/Libraries/LibWeb/CSS/StyleProperties.h index e3f701273f..4d63dc36cd 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.h @@ -47,6 +47,7 @@ public: LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const; Color color_or_fallback(CSS::PropertyID, Layout::NodeWithStyle const&, Color fallback) const; Optional<CSS::TextAlign> text_align() const; + Optional<CSS::TextJustify> text_justify() const; CSS::Display display() const; Optional<CSS::Float> float_() const; Optional<CSS::Clear> clear() const; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index 24d48ea986..c3a02435d1 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -274,6 +274,13 @@ enum class TextDecorationStyle { Wavy, }; +enum class TextJustify { + Auto, + None, + InterWord, + InterCharacter, +}; + enum class TextTransform { None, Capitalize, diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 5ca11a9aae..efc1a802ff 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -365,6 +365,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) if (text_align.has_value()) computed_values.set_text_align(text_align.value()); + auto text_justify = specified_style.text_justify(); + if (text_align.has_value()) + computed_values.set_text_justify(text_justify.value()); + auto white_space = specified_style.white_space(); if (white_space.has_value()) computed_values.set_white_space(white_space.value()); |