فهرست منبع

LibWeb/CSS: Add support for `unicode-bidi` property

Khaled Lakehal 9 ماه پیش
والد
کامیت
77761e123d

+ 1 - 0
Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt

@@ -187,6 +187,7 @@ transition-delay: 0s
 transition-duration: 0s
 transition-property: all
 transition-timing-function: ease
+unicode-bidi: normal
 user-select: auto
 vertical-align: baseline
 width: 784px

+ 10 - 0
Tests/LibWeb/Text/expected/css/unicode-bidi-computed-values.txt

@@ -0,0 +1,10 @@
+normal
+embed
+isolate
+bidi-override
+isolate-override
+plaintext
+normal
+normal
+normal
+normal

+ 29 - 0
Tests/LibWeb/Text/input/css/unicode-bidi-computed-values.html

@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+
+<script>
+    test(() => {
+        const propertyName = "unicode-bidi";
+        const propertyValues = [
+            "normal",
+            "embed",
+            "isolate",
+            "bidi-override",
+            "isolate-override",
+            "plaintext",
+            "bad-value",
+            "bidi-override isolate-override",
+            "normal bad-value",
+            "bad-value normal",
+        ];
+
+        for (const propertyValue of propertyValues) {
+            const element = document.createElement("span");
+            element.style.setProperty(propertyName, propertyValue);
+            document.body.appendChild(element);
+            const computedValue = getComputedStyle(element).getPropertyValue(propertyName);
+            println(computedValue);
+            element.remove();
+        }
+    });
+</script>

+ 4 - 0
Userland/Libraries/LibWeb/CSS/ComputedValues.h

@@ -183,6 +183,7 @@ public:
     static QuotesData quotes() { return QuotesData { .type = QuotesData::Type::Auto }; }
     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; }
 
     // https://www.w3.org/TR/SVG/geometry.html
     static LengthPercentage cx() { return CSS::Length::make_px(0); }
@@ -431,6 +432,7 @@ public:
     CSS::ObjectFit object_fit() const { return m_noninherited.object_fit; }
     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::LengthBox const& inset() const { return m_noninherited.inset; }
     const CSS::LengthBox& margin() const { return m_noninherited.margin; }
@@ -647,6 +649,7 @@ protected:
         CSS::TableLayout table_layout { InitialValues::table_layout() };
         CSS::ObjectFit object_fit { InitialValues::object_fit() };
         CSS::ObjectPosition object_position { InitialValues::object_position() };
+        CSS::UnicodeBidi unicode_bidi { InitialValues::unicode_bidi() };
 
         Optional<MaskReference> mask;
         CSS::MaskType mask_type { InitialValues::mask_type() };
@@ -782,6 +785,7 @@ public:
     void set_object_fit(CSS::ObjectFit value) { m_noninherited.object_fit = value; }
     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_fill(SVGPaint value) { m_inherited.fill = value; }
     void set_stroke(SVGPaint value) { m_inherited.stroke = value; }

+ 8 - 0
Userland/Libraries/LibWeb/CSS/Enums.json

@@ -463,6 +463,14 @@
     "stroke-box",
     "view-box "
   ],
+  "unicode-bidi": [
+    "bidi-override",
+    "embed",
+    "isolate",
+    "isolate-override",
+    "normal",
+    "plaintext"
+  ],
   "vertical-align": [
     "baseline",
     "bottom",

+ 5 - 0
Userland/Libraries/LibWeb/CSS/Keywords.json

@@ -79,6 +79,7 @@
   "background",
   "backwards",
   "baseline",
+  "bidi-override",
   "blink",
   "block",
   "bold",
@@ -142,6 +143,7 @@
   "ease-in-out",
   "ease-out",
   "ellipsis",
+  "embed",
   "enabled",
   "end",
   "evenodd",
@@ -204,6 +206,8 @@
   "interlace",
   "invert",
   "inverted",
+  "isolate",
+  "isolate-override",
   "italic",
   "jump-both",
   "jump-end",
@@ -280,6 +284,7 @@
   "paged",
   "paused",
   "pixelated",
+  "plaintext",
   "pointer",
   "portrait",
   "pre",

+ 8 - 0
Userland/Libraries/LibWeb/CSS/Properties.json

@@ -2678,6 +2678,14 @@
       "easing-function"
     ]
   },
+  "unicode-bidi": {
+    "animation-type": "none",
+    "inherited": false,
+    "initial": "normal",
+    "valid-types": [
+      "unicode-bidi"
+    ]
+  },
   "user-select": {
     "affects-layout": false,
     "animation-type": "discrete",

+ 6 - 0
Userland/Libraries/LibWeb/CSS/StyleProperties.cpp

@@ -1189,6 +1189,12 @@ Optional<CSS::Direction> StyleProperties::direction() const
     return keyword_to_direction(value->to_keyword());
 }
 
+Optional<CSS::UnicodeBidi> StyleProperties::unicode_bidi() const
+{
+    auto value = property(CSS::PropertyID::UnicodeBidi);
+    return keyword_to_unicode_bidi(value->to_keyword());
+}
+
 Optional<CSS::MaskType> StyleProperties::mask_type() const
 {
     auto value = property(CSS::PropertyID::MaskType);

+ 1 - 0
Userland/Libraries/LibWeb/CSS/StyleProperties.h

@@ -166,6 +166,7 @@ public:
     CSS::ObjectPosition object_position() const;
     Optional<CSS::TableLayout> table_layout() const;
     Optional<CSS::Direction> direction() const;
+    Optional<CSS::UnicodeBidi> unicode_bidi() const;
 
     static Vector<CSS::Transformation> transformations_for_style_value(CSSStyleValue const& value);
     Vector<CSS::Transformation> transformations() const;

+ 3 - 0
Userland/Libraries/LibWeb/Layout/Node.cpp

@@ -896,6 +896,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
     if (auto direction = computed_style.direction(); direction.has_value())
         computed_values.set_direction(direction.value());
 
+    if (auto unicode_bidi = computed_style.unicode_bidi(); unicode_bidi.has_value())
+        computed_values.set_unicode_bidi(unicode_bidi.value());
+
     if (auto scrollbar_width = computed_style.scrollbar_width(); scrollbar_width.has_value())
         computed_values.set_scrollbar_width(scrollbar_width.value());