Truly independent web browser
LibWeb: Preserve specified step easing keywords in Typed OM
Andreas Klingdd8a2069bb2f
diff --git a/Libraries/LibWeb/CSS/StylePropertyMap.cpp b/Libraries/LibWeb/CSS/StylePropertyMap.cppindex 3f796e56bae..0ebec80c949 100644--- a/Libraries/LibWeb/CSS/StylePropertyMap.cpp+++ b/Libraries/LibWeb/CSS/StylePropertyMap.cpp@@ -90,6 +90,15 @@ static WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> create_an_internal_rreturn WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Numeric value does not match the property's grammar"_utf16 };}+ // NB: Step easing keywords are custom identifiers outside the property parser. Store the parsed iteration so+ // multi-value set() and append() use the easing representation expected by style computation.+ if (internal_representation->is_custom_ident()+ && first_is_one_of(property.id(), PropertyID::AnimationTimingFunction, PropertyID::TransitionTimingFunction)) {+ if (auto parsed_value = parse_css_value(Parser::ParsingParams {}, internal_representation->to_utf16_string(SerializationMode::Normal), property.id());+ parsed_value && parsed_value->is_value_list() && parsed_value->as_value_list().size() == 1)+ return parsed_value->as_value_list().value_at(0, false);+ }+// 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::TextIndentdiff --git a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cppindex 148d4720eed..763c04dc63e 100644--- a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp+++ b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp@@ -501,6 +501,11 @@ GC::Ref<CSSStyleValue> StyleValue::reify(Utf16FlyString const& associated_properreturn as_custom_ident().reify(associated_property);case Type::Display:return as_display().reify(associated_property);+ case Type::Easing:+ // NB: Preserve authored step keywords until computation canonicalizes them to steps().+ if (m_value->easing.is_keyword)+ return CSSKeywordValue::create(m_value->easing.step_position == to_underlying(StepPosition::Start) ? "step-start"_utf16_fly_string : "step-end"_utf16_fly_string);+ break;case Type::Integer:return as_integer().reify(associated_property);case Type::Keyword:diff --git a/Libraries/LibWeb/Rust/src/css/absolutize.rs b/Libraries/LibWeb/Rust/src/css/absolutize.rsindex 9616503007f..c831880355c 100644--- a/Libraries/LibWeb/Rust/src/css/absolutize.rs+++ b/Libraries/LibWeb/Rust/src/css/absolutize.rs@@ -1369,11 +1369,12 @@ fn absolutize_easing(y2,number_of_intervals,step_position,+ is_keyword,} = valueelse {return None;};- let mut changed = false;+ let mut changed = *is_keyword;let mut stops = Vec::with_capacity(linear_stops.as_slice().len());for stop in linear_stops.as_slice() {let [output, input] = stop.values();@@ -1405,6 +1406,7 @@ fn absolutize_easing(y2,number_of_intervals,step_position: *step_position,+ is_keyword: false,})))}diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rsindex 4275797e973..6ed6bbfa285 100644--- a/Libraries/LibWeb/Rust/src/css/animation.rs+++ b/Libraries/LibWeb/Rust/src/css/animation.rs@@ -201,6 +201,7 @@ pub(crate) unsafe fn style_value_from_easing(descriptor: &FfiEasingDescriptor) -y2,number_of_intervals,step_position: descriptor.step_position,+ is_keyword: false,}))}diff --git a/Libraries/LibWeb/Rust/src/css/parser/transforms_effects_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/transforms_effects_parser.rsindex 36d8dbe7e90..1778d3a60b1 100644--- a/Libraries/LibWeb/Rust/src/css/parser/transforms_effects_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/transforms_effects_parser.rs@@ -360,6 +360,7 @@ fn easing(coordinates: [Option<StyleValueData>; 4],number_of_intervals: Option<StyleValueData>,step_position: u8,+ is_keyword: bool,) -> StyleValueData {let [x1, y1, x2, y2] = coordinates.map(|value| value.map_or_else(RetainedStyleValueData::none, retained));StyleValueData::Easing {@@ -371,6 +372,7 @@ fn easing(y2,number_of_intervals: number_of_intervals.map_or_else(RetainedStyleValueData::none, retained),step_position,+ is_keyword,}}@@ -449,7 +451,7 @@ fn parse_linear_easing(context: &ParseContext, property: u16, values: &[Componen}}}- (!stops.is_empty()).then(|| easing(0, stops, [None, None, None, None], None, 0))+ (!stops.is_empty()).then(|| easing(0, stops, [None, None, None, None], None, 0, false))}fn parse_cubic_bezier_easing(@@ -491,6 +493,7 @@ fn parse_cubic_bezier_easing(],None,0,+ false,))}@@ -526,6 +529,7 @@ fn parse_steps_easing(context: &ParseContext, property: u16, values: &[Component[None, None, None, None],Some(intervals),position,+ false,))}@@ -553,6 +557,7 @@ fn parse_easing_value(context: &ParseContext, property: u16, values: &[Component[None, None, None, None],Some(StyleValueData::Integer { value: 1 }),position,+ true,));}let (name, arguments) = value[0].function()?;diff --git a/Libraries/LibWeb/Rust/src/css/serialize.rs b/Libraries/LibWeb/Rust/src/css/serialize.rsindex 202cba79844..b7c52015cdc 100644--- a/Libraries/LibWeb/Rust/src/css/serialize.rs+++ b/Libraries/LibWeb/Rust/src/css/serialize.rs@@ -1393,6 +1393,7 @@ pub(crate) fn serialize_style_value(sink: &mut TextSink, value: &StyleValueData,y2,number_of_intervals,step_position,+ ..} => {use crate::css::css_enums::step_position as step_position_enum;match kind {diff --git a/Libraries/LibWeb/Rust/src/css/style_value.rs b/Libraries/LibWeb/Rust/src/css/style_value.rsindex 81a8582c6c4..300166ac5ed 100644--- a/Libraries/LibWeb/Rust/src/css/style_value.rs+++ b/Libraries/LibWeb/Rust/src/css/style_value.rs@@ -2045,6 +2045,7 @@ pub enum StyleValueData {Easing {kind: u8,step_position: u8,+ is_keyword: bool,linear_stops: RetainedLinearEasingStopList,x1: RetainedStyleValueData,y1: RetainedStyleValueData,@@ -2802,8 +2803,10 @@ impl StyleValueData {y2,number_of_intervals,step_position,+ is_keyword,} => {hasher.write_u8(*kind);+ write_bool(hasher, *is_keyword);hasher.write_usize(linear_stops.as_slice().len());for stop in linear_stops.as_slice() {write_value(hasher, &stop.output);diff --git a/Tests/LibWeb/Text/expected/css/typed-om-step-easing-list.txt b/Tests/LibWeb/Text/expected/css/typed-om-step-easing-list.txtnew file mode 100644index 00000000000..4306f723034--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/typed-om-step-easing-list.txt@@ -0,0 +1,12 @@+set step-start: linear, step-start+width halfway: 20px+animation step-start: linear, steps(1, start)+set step-end: linear, step-end+width halfway: 10px+animation step-end: linear, steps(1)+append step-start: linear, step-start+width halfway: 20px+animation step-start: linear, steps(1, start)+append step-end: linear, step-end+width halfway: 10px+animation step-end: linear, steps(1)diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/animation-timing-function.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/animation-timing-function.txtindex b8bbb36d922..691d3010c5d 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/animation-timing-function.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/animation-timing-function.txt@@ -2,8 +2,7 @@ Harness status: OKFound 40 tests-38 Pass-2 Fail+40 PassPass Can set 'animation-timing-function' to CSS-wide keywords: initialPass Can set 'animation-timing-function' to CSS-wide keywords: inheritPass Can set 'animation-timing-function' to CSS-wide keywords: unset@@ -14,8 +13,8 @@ Pass Can set 'animation-timing-function' to the 'ease' keyword: easePass Can set 'animation-timing-function' to the 'ease-in' keyword: ease-inPass Can set 'animation-timing-function' to the 'ease-out' keyword: ease-outPass Can set 'animation-timing-function' to the 'ease-in-out' keyword: ease-in-out-Fail Can set 'animation-timing-function' to the 'step-start' keyword: step-start-Fail Can set 'animation-timing-function' to the 'step-end' keyword: step-end+Pass Can set 'animation-timing-function' to the 'step-start' keyword: step-start+Pass Can set 'animation-timing-function' to the 'step-end' keyword: step-endPass Setting 'animation-timing-function' to a length: 0px throws TypeErrorPass Setting 'animation-timing-function' to a length: -3.14em throws TypeErrorPass Setting 'animation-timing-function' to a length: 3.14cm throws TypeErrordiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/transition-timing-function.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/transition-timing-function.txtindex 10e25a807b4..85bb4eae925 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/transition-timing-function.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/transition-timing-function.txt@@ -2,8 +2,7 @@ Harness status: OKFound 40 tests-38 Pass-2 Fail+40 PassPass Can set 'transition-timing-function' to CSS-wide keywords: initialPass Can set 'transition-timing-function' to CSS-wide keywords: inheritPass Can set 'transition-timing-function' to CSS-wide keywords: unset@@ -14,8 +13,8 @@ Pass Can set 'transition-timing-function' to the 'ease' keyword: easePass Can set 'transition-timing-function' to the 'ease-in' keyword: ease-inPass Can set 'transition-timing-function' to the 'ease-out' keyword: ease-outPass Can set 'transition-timing-function' to the 'ease-in-out' keyword: ease-in-out-Fail Can set 'transition-timing-function' to the 'step-start' keyword: step-start-Fail Can set 'transition-timing-function' to the 'step-end' keyword: step-end+Pass Can set 'transition-timing-function' to the 'step-start' keyword: step-start+Pass Can set 'transition-timing-function' to the 'step-end' keyword: step-endPass Setting 'transition-timing-function' to a length: 0px throws TypeErrorPass Setting 'transition-timing-function' to a length: -3.14em throws TypeErrorPass Setting 'transition-timing-function' to a length: 3.14cm throws TypeErrordiff --git a/Tests/LibWeb/Text/input/css/typed-om-step-easing-list.html b/Tests/LibWeb/Text/input/css/typed-om-step-easing-list.htmlnew file mode 100644index 00000000000..04747643b85--- /dev/null+++ b/Tests/LibWeb/Text/input/css/typed-om-step-easing-list.html@@ -0,0 +1,57 @@+<!doctype html>+<script src="../include.js"></script>+<script>+ test(() => {+ for (const method of ["set", "append"]) {+ for (const keyword of ["step-start", "step-end"]) {+ const target = document.createElement("div");+ target.style.cssText =+ "opacity: 0; width: 10px; transition-property: opacity, width; transition-duration: 1s";+ document.body.append(target);+ const map = target.attributeStyleMap;+ if (method === "set") {+ map.set("transition-timing-function", new CSSKeywordValue("linear"), new CSSKeywordValue(keyword));+ } else {+ map.set("transition-timing-function", new CSSKeywordValue("linear"));+ map.append("transition-timing-function", new CSSKeywordValue(keyword));+ }+ println(+ `${method} ${keyword}: ${map+ .getAll("transition-timing-function")+ .map(value => value.toString())+ .join(", ")}`+ );+ internals.updateStyle();+ target.style.width = "20px";+ internals.updateStyle();+ const transition = target.getAnimations().find(animation => animation.transitionProperty === "width");+ transition.pause();+ transition.currentTime = 500;+ println(`width halfway: ${getComputedStyle(target).width}`);+ transition.cancel();+ target.remove();++ const animation = document.createElement("div");+ document.body.append(animation);+ if (method === "set") {+ animation.attributeStyleMap.set(+ "animation-timing-function",+ new CSSKeywordValue("linear"),+ new CSSKeywordValue(keyword)+ );+ } else {+ animation.attributeStyleMap.set("animation-timing-function", new CSSKeywordValue("linear"));+ animation.attributeStyleMap.append("animation-timing-function", new CSSKeywordValue(keyword));+ }+ println(+ `animation ${keyword}: ${animation+ .computedStyleMap()+ .getAll("animation-timing-function")+ .map(value => value.toString())+ .join(", ")}`+ );+ animation.remove();+ }+ }+ });+</script>