Skip to content

Commit dc3ca42

Browse files
committed
LibWeb: Expose applicable effect timing values as CSSNumberish
1 parent dd92d84 commit dc3ca42

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

Libraries/LibWeb/Animations/AnimationEffect.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ OptionalEffectTiming EffectTiming::to_optional_effect_timing() const
6666
.fill = fill,
6767
.iteration_start = iteration_start,
6868
.iterations = iterations,
69-
.duration = duration,
69+
.duration = duration.visit(
70+
[](double const& value) -> Variant<double, String> { return value; },
71+
[](String const& value) -> Variant<double, String> { return value; },
72+
// NB: We check that this isn't the case in the caller
73+
[](GC::Root<CSS::CSSNumericValue> const&) -> Variant<double, String> { VERIFY_NOT_REACHED(); }),
7074
.direction = direction,
7175
.easing = easing,
7276
};
@@ -104,7 +108,7 @@ ComputedEffectTiming AnimationEffect::get_computed_timing() const
104108
// If duration is the string auto, this attribute will return the current calculated value of the intrinsic
105109
// iteration duration, which may be a expressed as a double representing the duration in milliseconds or a
106110
// percentage when the effect is associated with a progress-based timeline.
107-
auto duration = m_iteration_duration.as_milliseconds();
111+
auto duration = m_iteration_duration.as_css_numberish();
108112

109113
// - fill: likewise, while getTiming() may return the string auto, getComputedTiming() must return the specific
110114
// FillMode used for timing calculations as defined in the description of the fill member of the EffectTiming
@@ -125,9 +129,9 @@ ComputedEffectTiming AnimationEffect::get_computed_timing() const
125129
.easing = m_timing_function.to_string(),
126130
},
127131

128-
end_time().as_milliseconds(),
129-
active_duration().as_milliseconds(),
130-
local_time().map([](auto const& time) { return time.as_milliseconds(); }),
132+
end_time().as_css_numberish(),
133+
active_duration().as_css_numberish(),
134+
NullableCSSNumberish::from_optional_css_numberish_time(local_time()),
131135
transformed_progress(),
132136
current_iteration(),
133137
};

Libraries/LibWeb/Animations/AnimationEffect.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,26 @@ struct OptionalEffectTiming {
3131
};
3232

3333
// https://www.w3.org/TR/web-animations-1/#the-effecttiming-dictionaries
34+
// https://drafts.csswg.org/web-animations-2/#the-effecttiming-dictionaries
3435
struct EffectTiming {
3536
double delay { 0 };
3637
double end_delay { 0 };
3738
Bindings::FillMode fill { Bindings::FillMode::Auto };
3839
double iteration_start { 0.0 };
3940
double iterations { 1.0 };
40-
Variant<double, String> duration { "auto"_string };
41+
FlattenVariant<CSS::CSSNumberish, Variant<String>> duration { "auto"_string };
4142
Bindings::PlaybackDirection direction { Bindings::PlaybackDirection::Normal };
4243
String easing { "linear"_string };
4344

4445
OptionalEffectTiming to_optional_effect_timing() const;
4546
};
4647

4748
// https://www.w3.org/TR/web-animations-1/#the-computedeffecttiming-dictionary
49+
// https://drafts.csswg.org/web-animations-2/#the-computedeffecttiming-dictionary
4850
struct ComputedEffectTiming : public EffectTiming {
49-
double end_time;
50-
double active_duration;
51-
Optional<double> local_time;
51+
CSS::CSSNumberish end_time;
52+
CSS::CSSNumberish active_duration;
53+
NullableCSSNumberish local_time;
5254
Optional<double> progress;
5355
Optional<double> current_iteration;
5456
};

Libraries/LibWeb/Animations/AnimationEffect.idl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1+
#import <CSS/CSSNumericValue.idl>
2+
13
// https://www.w3.org/TR/web-animations-1/#the-effecttiming-dictionaries
4+
// https://drafts.csswg.org/web-animations-2/#the-effecttiming-dictionaries
25
dictionary EffectTiming {
36
double delay = 0;
47
double endDelay = 0;
58
FillMode fill = "auto";
69
double iterationStart = 0.0;
710
unrestricted double iterations = 1.0;
8-
(unrestricted double or DOMString) duration = "auto";
11+
// FIXME: Support playbackRate
12+
(unrestricted double or CSSNumericValue or DOMString) duration = "auto";
913
PlaybackDirection direction = "normal";
1014
DOMString easing = "linear";
1115
};
1216

1317
// https://www.w3.org/TR/web-animations-1/#dictdef-optionaleffecttiming
18+
// https://drafts.csswg.org/web-animations-2/#ref-for-dictdef-optionaleffecttiming
1419
dictionary OptionalEffectTiming {
1520
double delay;
1621
double endDelay;
1722
FillMode fill;
1823
double iterationStart;
1924
unrestricted double iterations;
25+
// FIXME: Support playbackRate
2026
(unrestricted double or DOMString) duration;
2127
PlaybackDirection direction;
2228
DOMString easing;
@@ -30,9 +36,9 @@ enum PlaybackDirection { "normal", "reverse", "alternate", "alternate-reverse" }
3036

3137
// https://www.w3.org/TR/web-animations-1/#the-computedeffecttiming-dictionary
3238
dictionary ComputedEffectTiming : EffectTiming {
33-
[GenerateAsRequired] unrestricted double endTime;
34-
[GenerateAsRequired] unrestricted double activeDuration;
35-
double? localTime;
39+
[GenerateAsRequired] CSSNumberish endTime;
40+
[GenerateAsRequired] CSSNumberish activeDuration;
41+
CSSNumberish? localTime;
3642
double? progress;
3743
unrestricted double? currentIteration;
3844
};

Libraries/LibWeb/Animations/KeyframeEffect.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,14 @@ WebIDL::ExceptionOr<GC::Ref<KeyframeEffect>> KeyframeEffect::construct_impl(
705705
timing_input.duration = options.get<double>();
706706
}
707707

708+
// https://drafts.csswg.org/web-animations-2/#the-effecttiming-dictionaries
709+
// Note: In this version of the spec, duration is not settable as a CSSNumericValue; however, duration may be
710+
// returned as a CSSNumericValue when resolving the duration in getComputedTiming(). Future versions of
711+
// the spec may enable setting the duration as a CSSNumeric value, where the unit is a valid time unit or
712+
// percent.
713+
if (timing_input.duration.has<GC::Root<CSS::CSSNumericValue>>())
714+
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Setting duration as a CSSNumericValue is not supported"sv };
715+
708716
// 5. Call the procedure to update the timing properties of an animation effect of effect from timing input.
709717
// If that procedure causes an exception to be thrown, propagate the exception and abort this procedure.
710718
TRY(effect->update_timing(timing_input.to_optional_effect_timing()));

0 commit comments

Comments
 (0)