Skip to content

Commit

Permalink
LibWeb: Add writing-mode CSS property, and its values
Browse files Browse the repository at this point in the history
Introduce the `writing-mode` property, as specified in
https://drafts.csswg.org/css-writing-modes/#block-flow

(cherry picked from commit c3f3e93b7e46e2f366fbc904852763af546d3913;
amended to fix conflict on `height:` in expectation)
  • Loading branch information
BenJilks authored and nico committed Nov 19, 2024
1 parent 17f9f8c commit 7e93c8d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ grid-row-start: auto
grid-template-areas: none
grid-template-columns: auto
grid-template-rows: auto
height: 2125px
height: 2142px
inline-size: auto
inset-block-end: auto
inset-block-start: auto
Expand Down
4 changes: 4 additions & 0 deletions Userland/Libraries/LibWeb/CSS/ComputedValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class InitialValues {
static CSS::TransformBox transform_box() { return CSS::TransformBox::ViewBox; }
static CSS::Direction direction() { return CSS::Direction::Ltr; }
static CSS::UnicodeBidi unicode_bidi() { return CSS::UnicodeBidi::Normal; }
static CSS::WritingMode writing_mode() { return CSS::WritingMode::HorizontalTb; }

// https://www.w3.org/TR/SVG/geometry.html
static LengthPercentage cx() { return CSS::Length::make_px(0); }
Expand Down Expand Up @@ -443,6 +444,7 @@ class ComputedValues {
CSS::ObjectPosition object_position() const { return m_noninherited.object_position; }
CSS::Direction direction() const { return m_inherited.direction; }
CSS::UnicodeBidi unicode_bidi() const { return m_noninherited.unicode_bidi; }
CSS::WritingMode writing_mode() const { return m_inherited.writing_mode; }

CSS::LengthBox const& inset() const { return m_noninherited.inset; }
const CSS::LengthBox& margin() const { return m_noninherited.margin; }
Expand Down Expand Up @@ -567,6 +569,7 @@ class ComputedValues {
CSS::Visibility visibility { InitialValues::visibility() };
CSS::QuotesData quotes { InitialValues::quotes() };
CSS::Direction direction { InitialValues::direction() };
CSS::WritingMode writing_mode { InitialValues::writing_mode() };

Optional<SVGPaint> fill;
CSS::FillRule fill_rule { InitialValues::fill_rule() };
Expand Down Expand Up @@ -813,6 +816,7 @@ class MutableComputedValues final : public ComputedValues {
void set_object_position(CSS::ObjectPosition value) { m_noninherited.object_position = value; }
void set_direction(CSS::Direction value) { m_inherited.direction = value; }
void set_unicode_bidi(CSS::UnicodeBidi value) { m_noninherited.unicode_bidi = value; }
void set_writing_mode(CSS::WritingMode value) { m_inherited.writing_mode = value; }

void set_fill(SVGPaint value) { m_inherited.fill = value; }
void set_stroke(SVGPaint value) { m_inherited.stroke = value; }
Expand Down
7 changes: 7 additions & 0 deletions Userland/Libraries/LibWeb/CSS/Enums.json
Original file line number Diff line number Diff line change
Expand Up @@ -508,5 +508,12 @@
"keep-all",
"break-all",
"break-word"
],
"writing-mode": [
"horizontal-tb",
"vertical-rl",
"vertical-lr",
"sideways-rl",
"sideways-lr"
]
}
5 changes: 5 additions & 0 deletions Userland/Libraries/LibWeb/CSS/Keywords.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
"high-quality",
"highlight",
"highlighttext",
"horizontal-tb",
"hover",
"inactiveborder",
"inactivecaption",
Expand Down Expand Up @@ -339,6 +340,8 @@
"semi-expanded",
"separate",
"serif",
"sideways-lr",
"sideways-rl",
"slider-horizontal",
"slow",
"small",
Expand Down Expand Up @@ -403,6 +406,8 @@
"upper-latin",
"upper-roman",
"uppercase",
"vertical-lr",
"vertical-rl",
"vertical-text",
"view-box",
"visible",
Expand Down
12 changes: 12 additions & 0 deletions Userland/Libraries/LibWeb/CSS/Properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -2795,6 +2795,18 @@
"normal"
]
},
"writing-mode": {
"animation-type": "none",
"inherited": true,
"initial": "horizontal-tb",
"valid-identifiers": [
"horizontal-tb",
"vertical-rl",
"vertical-lr",
"sideways-rl",
"sideways-lr"
]
},
"x": {
"__comment": "This is an SVG 2 geometry property, see: https://www.w3.org/TR/SVG/geometry.html#X.",
"animation-type": "by-computed-value",
Expand Down
6 changes: 6 additions & 0 deletions Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,12 @@ Optional<CSS::UnicodeBidi> StyleProperties::unicode_bidi() const
return keyword_to_unicode_bidi(value->to_keyword());
}

Optional<CSS::WritingMode> StyleProperties::writing_mode() const
{
auto value = property(CSS::PropertyID::WritingMode);
return keyword_to_writing_mode(value->to_keyword());
}

Optional<CSS::MaskType> StyleProperties::mask_type() const
{
auto value = property(CSS::PropertyID::MaskType);
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/CSS/StyleProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class StyleProperties : public RefCounted<StyleProperties> {
Optional<CSS::TableLayout> table_layout() const;
Optional<CSS::Direction> direction() const;
Optional<CSS::UnicodeBidi> unicode_bidi() const;
Optional<CSS::WritingMode> writing_mode() const;

static Vector<CSS::Transformation> transformations_for_style_value(CSSStyleValue const& value);
Vector<CSS::Transformation> transformations() const;
Expand Down
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/Layout/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
if (auto scrollbar_width = computed_style.scrollbar_width(); scrollbar_width.has_value())
computed_values.set_scrollbar_width(scrollbar_width.value());

if (auto writing_mode = computed_style.writing_mode(); writing_mode.has_value())
computed_values.set_writing_mode(writing_mode.value());

propagate_style_to_anonymous_wrappers();
}

Expand Down

0 comments on commit 7e93c8d

Please sign in to comment.