Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ namespace TheArtOfDev.HtmlRenderer.Core.CssEngine

internal sealed class TransitionProperty : ShorthandProperty
{
internal static readonly IValueConverter ListConverter = new TimeBasedShorthandConverter(
1, // duration index
3, // delay index
AnimatableConverter.Option().For(PropertyNames.TransitionProperty), // 0
TimeConverter.Option().For(PropertyNames.TransitionDuration), // 1
TransitionConverter.Option().For(PropertyNames.TransitionTimingFunction), // 2
TimeConverter.Option().For(PropertyNames.TransitionDelay) // 3
).FromList().OrDefault();
// css-transitions-1 §2.5: none is only valid when the list has a single item
internal static readonly IValueConverter ListConverter = SingleTransition(AnimatableConverter).FromList()
.Or(SingleTransition(AnimatableConverter.OrNone()))
.OrDefault();

internal TransitionProperty()
: base(PropertyNames.Transition)
{
}

internal override IValueConverter Converter => ListConverter;

private static IValueConverter SingleTransition(IValueConverter propertyConverter)
{
return new TimeBasedShorthandConverter(
1, // duration index
3, // delay index
propertyConverter.Option().For(PropertyNames.TransitionProperty), // 0
TimeConverter.Option().For(PropertyNames.TransitionDuration), // 1
TransitionConverter.Option().For(PropertyNames.TransitionTimingFunction), // 2
TimeConverter.Option().For(PropertyNames.TransitionDelay) // 3
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public IPropertyValue Convert(IEnumerable<Token> value)

if (targetIndex == i)
{
// This is the right slot for this time value - actually consume it
TryMatchTime(list, out timeValue);
options[i] = timeValue;
// This is the right slot for this time value - actually consume it,
// through the slot's converter so the value only extracts for its longhand
options[i] = _converters[i].VaryStart(list);
matched[i] = true;
timeValuesFound++;
foundMatch = true;
Expand Down
45 changes: 45 additions & 0 deletions Source/Test/HtmlRenderer.Test/Css/AnimationPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,49 @@ public void AnimationMultipleLegal()
Assert.IsTrue(concrete.HasValue);
Assert.AreEqual("0s ease 10 my-animation, linear 5 other-animation, 0s step-start 1s 10 yet-another", concrete.Value);
}

[TestMethod]
public void AnimationShorthandSetsEveryLonghand()
{
var style = CssConstructionFunctions.ParseDeclarations("animation: slide 1s ease-in 2s infinite alternate both paused");

Assert.AreEqual("slide", style.GetPropertyValue("animation-name"));
Assert.AreEqual("1s", style.GetPropertyValue("animation-duration"));
Assert.AreEqual("ease-in", style.GetPropertyValue("animation-timing-function"));
Assert.AreEqual("2s", style.GetPropertyValue("animation-delay"));
Assert.AreEqual("infinite", style.GetPropertyValue("animation-iteration-count"));
Assert.AreEqual("alternate", style.GetPropertyValue("animation-direction"));
Assert.AreEqual("both", style.GetPropertyValue("animation-fill-mode"));
Assert.AreEqual("paused", style.GetPropertyValue("animation-play-state"));
}

[TestMethod]
public void AnimationShorthandWithOneTimeSetsOnlyTheDuration()
{
var style = CssConstructionFunctions.ParseDeclarations("animation: slide 1s");

Assert.AreEqual("slide", style.GetPropertyValue("animation-name"));
Assert.AreEqual("1s", style.GetPropertyValue("animation-duration"));
Assert.AreEqual("initial", style.GetPropertyValue("animation-delay"));
}

[TestMethod]
public void AnimationShorthandGivesKeywordsToTheOtherLonghandsFirst()
{
var style = CssConstructionFunctions.ParseDeclarations("animation: 3s none backwards");

Assert.AreEqual("3s", style.GetPropertyValue("animation-duration"));
Assert.AreEqual("none", style.GetPropertyValue("animation-fill-mode"));
Assert.AreEqual("backwards", style.GetPropertyValue("animation-name"));
}

[TestMethod]
public void AnimationShorthandListSetsTheLonghandsPerItem()
{
var style = CssConstructionFunctions.ParseDeclarations("animation: a 1s 2s, b 3s 4s");

Assert.AreEqual("a, b", style.GetPropertyValue("animation-name"));
Assert.AreEqual("1s, 3s", style.GetPropertyValue("animation-duration"));
Assert.AreEqual("2s, 4s", style.GetPropertyValue("animation-delay"));
}
}
35 changes: 35 additions & 0 deletions Source/Test/HtmlRenderer.Test/Css/TransitionPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,39 @@ public void CssTransitionSecondsEaseAllHeightMsStepsWidthCubicBezierLegal()
Assert.IsTrue(concrete.HasValue);
Assert.AreEqual("all 1s ease, height 50ms step-start, width, cubic-bezier(0.2, 0.5, 1, 1)", concrete.Value);
}

[TestMethod]
public void CssTransitionShorthandWithOneTimeSetsOnlyTheDuration()
{
var style = CssConstructionFunctions.ParseDeclarations("transition: color 1s");

Assert.AreEqual("color", style.GetPropertyValue("transition-property"));
Assert.AreEqual("1s", style.GetPropertyValue("transition-duration"));
Assert.AreEqual("initial", style.GetPropertyValue("transition-delay"));
}

[TestMethod]
public void CssTransitionShorthandAssignsTheSecondTimeToTheDelay()
{
var style = CssConstructionFunctions.ParseDeclarations("transition: 1s 2s");

Assert.AreEqual("1s", style.GetPropertyValue("transition-duration"));
Assert.AreEqual("2s", style.GetPropertyValue("transition-delay"));
}

[TestMethod]
public void CssTransitionShorthandNoneSetsThePropertyToNone()
{
var style = CssConstructionFunctions.ParseDeclarations("transition: none");

Assert.AreEqual("none", style.GetPropertyValue("transition-property"));
}

[TestMethod]
public void CssTransitionShorthandWithNoneInAListIsInvalid()
{
var style = CssConstructionFunctions.ParseDeclarations("transition: none, color 1s");

Assert.AreEqual(string.Empty, style.GetPropertyValue("transition"));
}
}
Loading