|
| 1 | +using System.Linq; |
| 2 | +using HtmlRenderer.IntegrationTest.TestSupport; |
| 3 | + |
| 4 | +namespace HtmlRenderer.IntegrationTest.Painting; |
| 5 | + |
| 6 | +/// <summary> |
| 7 | +/// Ported from PeachPDF.Tests' Acid2FeatureVerificationTests.cs (the z-index/stacking-context section). |
| 8 | +/// CSS 2.1 §9.9/Appendix E: a positioned box's <c>z-index</c> establishes a stacking context, and boxes in a |
| 9 | +/// higher stacking context paint after (on top of) boxes in a lower one, regardless of document/source order - |
| 10 | +/// e.g. a <c>position:relative; z-index:2</c> box must paint over a <c>position:fixed</c> box declared later |
| 11 | +/// in the document. |
| 12 | +/// </summary> |
| 13 | +[DoNotParallelize] |
| 14 | +[TestClass] |
| 15 | +public sealed class StackingContextTests |
| 16 | +{ |
| 17 | + [Ignore("z-index/stacking-context paint order is not implemented on this fork: FragmentPainter.cs's own " + |
| 18 | + "class remarks explicitly document it as deferred (\"Stacking-context paint order and " + |
| 19 | + "box-decoration-break slicing are follow-on work\"), and CssBoxProperties has no ZIndex field at " + |
| 20 | + "all - the CSS-OM parses z-index (CssEngine/StyleProperties/Flow/ZIndexProperty.cs) but " + |
| 21 | + "CssUtils.SetPropertyValue never dispatches it onto a box, so it has zero effect on paint order. " + |
| 22 | + "This box tree currently paints in plain document order (normal flow, then absolute/fixed, per " + |
| 23 | + "FragmentPainter's child-iteration order) regardless of any z-index value - a position:relative " + |
| 24 | + "z-index:2 box painting over a LATER position:fixed sibling (this test's whole premise) is exactly " + |
| 25 | + "the case document order alone cannot produce, so this reliably fails rather than passing by " + |
| 26 | + "accident. Implementing real stacking-context ordering (a ZIndex box property, plus grouping/" + |
| 27 | + "sorting descendants by stacking context per CSS2.1 Appendix E) is a separate, larger feature port.")] |
| 28 | + [TestMethod] |
| 29 | + public void PositionedZIndex_PaintsOverFixedPositionedContent() |
| 30 | + { |
| 31 | + // A black position:fixed bar declared AFTER (later in the box tree than) a white |
| 32 | + // position:relative;z-index:2 box must still be painted BEFORE it (i.e. underneath). |
| 33 | + var html = LayoutHarness.Wrap( |
| 34 | + "<div id='fixedbar' style='position:fixed; top:0; left:0; width:50px; height:50px; background:rgb(0,0,0);'></div>" |
| 35 | + + "<div id='intro' style='position:relative; z-index:2; width:50px; height:50px; background:rgb(255,255,255);'></div>"); |
| 36 | + |
| 37 | + var (root, container) = PaintHarness.Layout(html); |
| 38 | + var recorder = PaintHarness.PaintPage(container); |
| 39 | + |
| 40 | + var fixedBar = PaintHarness.FindById(root, "fixedbar")!; |
| 41 | + var intro = PaintHarness.FindById(root, "intro")!; |
| 42 | + |
| 43 | + var drawRectCalls = recorder.Log.OfType<RecordingGraphics.DrawRectCall>().ToList(); |
| 44 | + var fixedBarPaintIndex = drawRectCalls.FindIndex(c => c.X == fixedBar.Location.X && c.Y == fixedBar.Location.Y); |
| 45 | + var introPaintIndex = drawRectCalls.FindIndex(c => c.X == intro.Location.X && c.Y == intro.Location.Y); |
| 46 | + |
| 47 | + Assert.IsTrue(fixedBarPaintIndex < introPaintIndex, |
| 48 | + "the z-index:2 box must paint after (on top of) the fixed bar, regardless of document order"); |
| 49 | + } |
| 50 | +} |
0 commit comments