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
14 changes: 10 additions & 4 deletions Source/HtmlRenderer/Core/CssData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void EnsureIndex()

/// <summary>
/// Walks a rule list in true document order, recursing into <c>@media</c> blocks, <c>@layer</c>
/// blocks and CSS-Nesting child rules (any nesting depth) in place, and buckets every style rule
/// blocks, <c>@supports</c> blocks whose condition is true and CSS-Nesting child rules (any nesting depth) in place, and buckets every style rule
/// found - assigning each an ever-increasing <see cref="IndexedRule.DocumentOrder"/> and recording
/// the chain of enclosing media conditions it's nested under, if any.
/// </summary>
Expand Down Expand Up @@ -327,9 +327,15 @@ private static void IndexRules(
// rule inside a layer would silently stop applying.
IndexRules(layerRule.Rules, isUserAgent, enclosingMedia, tagIndex, classIndex, idIndex, universal, keys, ref order);
}
// Everything else (@layer statements, @property, @font-palette-values, @supports,
// @container, ...) contributes no style rules to the cascade, so falling through is the
// correct handling rather than an oversight.
else if (rule is ISupportsRule supportsRule)
{
// css-conditional-3 #at-supports: the condition doesn't depend on the device, so it
// is decided once here instead of per box like @media.
if (supportsRule.Condition.Check())
IndexRules(supportsRule.Rules, isUserAgent, enclosingMedia, tagIndex, classIndex, idIndex, universal, keys, ref order);
}
// Everything else (@layer statements, @property, @font-palette-values, @container, ...)
// contributes no style rules to the cascade.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,16 @@
namespace HtmlRenderer.Test.Css.Selectors;

/// <summary>
/// Ported from PeachPDF.Tests/CSS/ConditionGroupingRuleIntegrationTests.cs. <c>@supports</c> and
/// <c>@container</c> parse and have working condition-evaluation code
/// (<see cref="TheArtOfDev.HtmlRenderer.Core.CssEngine.SupportsRule"/>,
/// <see cref="TheArtOfDev.HtmlRenderer.Core.CssEngine.ContainerRule"/>,
/// <see cref="TheArtOfDev.HtmlRenderer.Core.CssEngine.DeclarationCondition"/>), but
/// <c>TheArtOfDev.HtmlRenderer.Core.CssData.cs:330-332</c> explicitly documents that the real per-box
/// cascade NEVER applies their inner rules, regardless of whether the condition is true or false - this
/// is a deliberate, still-open scope gap (unlike PeachPDF, which genuinely evaluates and applies both).
///
/// Only the four cases that assert the inner rule DOES apply are ported, as <see cref="Ignore"/>d - they
/// would genuinely fail against the real engine today. The mirror-image "does NOT apply" cases (and the
/// AND/OR combination case, which also expects the block does not apply) are NOT ported: they'd pass,
/// but only vacuously (inner rules never apply here regardless of the condition), so they're not
/// meaningful regression coverage. <c>Supports_SvgOnlyProperty_AppliesToAnInlineSvgElement</c> is not
/// ported either - HTML-Renderer has no SVG rendering pipeline.
/// Ported from PeachPDF.Tests/CSS/ConditionGroupingRuleIntegrationTests.cs.
/// <c>Supports_SvgOnlyProperty_AppliesToAnInlineSvgElement</c> is not ported, HTML-Renderer has no SVG
/// rendering pipeline. The cascade doesn't apply <c>@container</c>'s inner rules yet.
/// </summary>
[TestClass]
public sealed class ConditionGroupingRuleIntegrationTests
{
private static readonly RColor Blue = RColor.FromArgb(0, 0, 255);

[TestMethod]
[Ignore("not yet spec compliant - CssData.cs:330-332 documents that the real per-box cascade never " +
"applies @supports'/@container's inner rules, regardless of the condition. See class doc comment.")]
public void Supports_InnerRules_Apply_WhenConditionIsSupported()
{
var html = Html(
Expand All @@ -39,8 +25,18 @@ public void Supports_InnerRules_Apply_WhenConditionIsSupported()
}

[TestMethod]
[Ignore("not yet spec compliant - CssData.cs:330-332 documents that the real per-box cascade never " +
"applies @supports'/@container's inner rules, regardless of the condition. See class doc comment.")]
public void SupportsNot_Applies_WhenDeclarationIsInvalid()
{
var html = Html(
"@supports not (display: no-such-value) { p { color: #0000ff; } }",
"<p>text</p>");
var box = FindBoxByTag(html, "p");
Assert.AreEqual(Blue, box.ActualColor);
}

[TestMethod]
[Ignore("not yet spec compliant - DeclarationCondition.Check() reports animation-name as supported, " +
"see SupportsTests.SupportsAnimationNameRule_NoLongerFalsePositive")]
public void SupportsNot_Fallback_Applies_WhenFeatureIsUnsupported()
{
var html = Html(
Expand All @@ -54,8 +50,6 @@ public void SupportsNot_Fallback_Applies_WhenFeatureIsUnsupported()
// block and its not-guarded fallback wrapping the same declaration, both present in one
// stylesheet. Real evaluation must let exactly one of them win, never both and never neither.
[TestMethod]
[Ignore("not yet spec compliant - CssData.cs:330-332 documents that the real per-box cascade never " +
"applies @supports'/@container's inner rules, regardless of the condition. See class doc comment.")]
public void SupportsEnhancedBlockAndNotGuardedFallback_ExactlyOneApplies()
{
var html = Html(
Expand All @@ -68,8 +62,41 @@ public void SupportsEnhancedBlockAndNotGuardedFallback_ExactlyOneApplies()
}

[TestMethod]
[Ignore("not yet spec compliant - CssData.cs:330-332 documents that the real per-box cascade never " +
"applies @supports'/@container's inner rules, regardless of the condition. See class doc comment.")]
public void Supports_InnerRules_DoNotApply_WhenConditionIsNotSupported()
{
var html = Html(
"p { color: #ff0000; } @supports (display: no-such-value) { p { color: #0000ff; } }",
"<p>text</p>");
var box = FindBoxByTag(html, "p");
Assert.AreEqual(RColor.FromArgb(255, 0, 0), box.ActualColor);
}

[TestMethod]
public void Supports_NestedWithMedia_AppliesOnlyWhenAllConditionsHold()
{
var html = Html(
"p { color: #ff0000; } " +
"@supports (display: block) { @media screen { @supports (display: block) { p { color: #0000ff; } } } } " +
"@media screen { @supports (display: no-such-value) { p { color: #00ff00; } } } " +
"@supports (display: block) { @media print { p { color: #00ff00; } } }",
"<p>text</p>");
var box = FindBoxByTag(html, "p");
Assert.AreEqual(Blue, box.ActualColor);
}

[TestMethod]
public void Supports_InsideLayer_AppliesOnlyWhenConditionIsSupported()
{
var html = Html(
"@layer base { @supports (display: block) { p { color: #0000ff; } } " +
"@supports (display: no-such-value) { p { color: #00ff00; } } }",
"<p>text</p>");
var box = FindBoxByTag(html, "p");
Assert.AreEqual(Blue, box.ActualColor);
}

[TestMethod]
[Ignore("not yet spec compliant - the cascade never applies @container's inner rules")]
public void Container_InnerRules_Apply_WhenAnEligibleAncestorContainerMatches()
{
var html = Html(
Expand Down
Loading