Truly independent web browser
LibWeb: Represent Typed OM text-indent values as the parser does
Andreas Klingebb74f634e13
diff --git a/Libraries/LibWeb/CSS/StylePropertyMap.cpp b/Libraries/LibWeb/CSS/StylePropertyMap.cppindex efeb42525b8..153016c8c04 100644--- a/Libraries/LibWeb/CSS/StylePropertyMap.cpp+++ b/Libraries/LibWeb/CSS/StylePropertyMap.cpp@@ -66,7 +66,7 @@ static NonnullRefPtr<StyleValueList> style_value_list_for_property(StyleValueVecstatic WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> create_an_internal_representation(JS::VM& vm, PropertyNameAndID const& property, Variant<GC::Ref<CSSStyleValue>, Utf16String> const& value){// To create an internal representation, given a string property and a string or CSSStyleValue value:- return value.visit(+ auto internal_representation = TRY(value.visit([&property](GC::Ref<CSSStyleValue> const& css_style_value) {return css_style_value->create_an_internal_representation(property, CSSStyleValue::PerformTypeCheck::Yes);},@@ -78,7 +78,17 @@ static WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> create_an_internal_rauto result = TRY(CSSStyleValue::parse_a_css_style_value(vm, property.name(), css_text, CSSStyleValue::ParseMultiple::No));// AD-HOC: Result is a CSSStyleValue but we want an internal representation, so... convert it again I guess?return result.get<GC::Ref<CSSStyleValue>>()->create_an_internal_representation(property, CSSStyleValue::PerformTypeCheck::Yes);- });+ }));++ // AD-HOC: Our parser represents a text-indent that is just a length-percentage as a text-indent value, and style+ // computation expects that.+ if (property.id() == PropertyID::TextIndent+ && (internal_representation->is_length() || internal_representation->is_percentage() || internal_representation->is_calculated())) {+ return StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_create_text_indent(+ StyleValueFFI::rust_style_value_retain(internal_representation->rust_style_value_data()), false, false));+ }++ return internal_representation;}static WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> normalize_overflow_clip_margin_internal_representation(diff --git a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cppindex ebd4e76c298..aa32cf55426 100644--- a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp+++ b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp@@ -510,6 +510,11 @@ GC::Ref<CSSStyleValue> StyleValue::reify(Utf16FlyString const& associated_properreturn as_number().reify(associated_property);case Type::OpacityValue:return as_opacity_value().reify(associated_property);+ case Type::TextIndent:+ // NB: A text-indent without the `hanging` or `each-line` keywords is just its length-percentage.+ if (!m_value->text_indent.hanging && !m_value->text_indent.each_line)+ return wrap_rust_child(m_value->text_indent.length_percentage)->reify(associated_property);+ break;case Type::Unresolved:return as_unresolved().reify(associated_property);case Type::ValueList:diff --git a/Libraries/LibWeb/Rust/src/css/style_value.rs b/Libraries/LibWeb/Rust/src/css/style_value.rsindex 12d227aaceb..9d2786c2610 100644--- a/Libraries/LibWeb/Rust/src/css/style_value.rs+++ b/Libraries/LibWeb/Rust/src/css/style_value.rs@@ -3102,6 +3102,20 @@ pub unsafe extern "C" fn rust_style_value_create_ratio(}))}+/// Takes ownership of one strong reference to the length-percentage value.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn rust_style_value_create_text_indent(+ length_percentage: *const StyleValueData,+ hanging: bool,+ each_line: bool,+) -> *const StyleValueData {+ Arc::into_raw(Arc::new(StyleValueData::TextIndent {+ length_percentage: unsafe { RetainedStyleValueData::from_retained_pointer(length_percentage) },+ hanging,+ each_line,+ }))+}+#[unsafe(no_mangle)]pub extern "C" fn rust_style_value_create_guaranteed_invalid() -> *const StyleValueData {Arc::into_raw(Arc::new(StyleValueData::GuaranteedInvalid))diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/text-indent.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/text-indent.txtnew file mode 100644index 00000000000..c916d1493fb--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/text-indent.txt@@ -0,0 +1,39 @@+Harness status: OK++Found 34 tests++34 Pass+Pass Can set 'text-indent' to CSS-wide keywords: initial+Pass Can set 'text-indent' to CSS-wide keywords: inherit+Pass Can set 'text-indent' to CSS-wide keywords: unset+Pass Can set 'text-indent' to CSS-wide keywords: revert+Pass Can set 'text-indent' to var() references: var(--A)+Pass Can set 'text-indent' to a length: 0px+Pass Can set 'text-indent' to a length: -3.14em+Pass Can set 'text-indent' to a length: 3.14cm+Pass Can set 'text-indent' to a length: calc(0px + 0em)+Pass Can set 'text-indent' to a percent: 0%+Pass Can set 'text-indent' to a percent: -3.14%+Pass Can set 'text-indent' to a percent: 3.14%+Pass Can set 'text-indent' to a percent: calc(0% + 0%)+Pass Setting 'text-indent' to a time: 0s throws TypeError+Pass Setting 'text-indent' to a time: -3.14ms throws TypeError+Pass Setting 'text-indent' to a time: 3.14s throws TypeError+Pass Setting 'text-indent' to a time: calc(0s + 0ms) throws TypeError+Pass Setting 'text-indent' to an angle: 0deg throws TypeError+Pass Setting 'text-indent' to an angle: 3.14rad throws TypeError+Pass Setting 'text-indent' to an angle: -3.14deg throws TypeError+Pass Setting 'text-indent' to an angle: calc(0rad + 0deg) throws TypeError+Pass Setting 'text-indent' to a flexible length: 0fr throws TypeError+Pass Setting 'text-indent' to a flexible length: 1fr throws TypeError+Pass Setting 'text-indent' to a flexible length: -3.14fr throws TypeError+Pass Setting 'text-indent' to a number: 0 throws TypeError+Pass Setting 'text-indent' to a number: -3.14 throws TypeError+Pass Setting 'text-indent' to a number: 3.14 throws TypeError+Pass Setting 'text-indent' to a number: calc(2 + 3) throws TypeError+Pass Setting 'text-indent' to a transform: translate(50%, 50%) throws TypeError+Pass Setting 'text-indent' to a transform: perspective(10em) throws TypeError+Pass Setting 'text-indent' to a transform: translate3d(0px, 1px, 2px) translate(0px, 1px) rotate3d(1, 2, 3, 45deg) rotate(45deg) scale3d(1, 2, 3) scale(1, 2) skew(1deg, 1deg) skewX(1deg) skewY(45deg) perspective(1px) matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) matrix(1, 2, 3, 4, 5, 6) throws TypeError+Pass 'text-indent' does not support '5em each-line'+Pass 'text-indent' does not support '5em hanging'+Pass 'text-indent' does not support '5em hanging each-line'\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-typed-om/the-stylepropertymap/properties/text-indent.html b/Tests/LibWeb/Text/input/wpt-import/css/css-typed-om/the-stylepropertymap/properties/text-indent.htmlnew file mode 100644index 00000000000..f17d464c0e3--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-typed-om/the-stylepropertymap/properties/text-indent.html@@ -0,0 +1,25 @@+<!doctype html>+<meta charset="utf-8">+<title>'text-indent' property</title>+<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-get">+<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-set">+<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#property-stle-value-normalization">+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script src="../../resources/testhelper.js"></script>+<script src="resources/testsuite.js"></script>+<body>+<div id="log"></div>+<script>+'use strict';++runPropertyTests('text-indent', [+ { syntax: '<length>' },+ { syntax: '<percentage>' },+]);++runUnsupportedPropertyTests('text-indent', [+ '5em each-line', '5em hanging', '5em hanging each-line'+]);++</script>