PerformRequestAsync(Request request, CancellationToken cancel)
+ {
+ var (status, type, content) = request.Address.Path switch
+ {
+ "missing.png" => (HttpStatusCode.NotFound, "image/png", YellowPixel),
+ "page.png" => (HttpStatusCode.OK, "text/html; charset=utf-8", "FAIL"u8.ToArray()),
+ _ => (HttpStatusCode.OK, "image/png", YellowPixel),
+ };
+ var response = new DefaultResponse
+ {
+ Address = request.Address,
+ StatusCode = status,
+ Content = new MemoryStream(content),
+ };
+ response.Headers[HeaderNames.ContentType] = type;
+ return Task.FromResult(response);
+ }
+ }
+}
diff --git a/src/AngleSharp.Renderer.Tests/cases/test15-acid1.html b/src/AngleSharp.Renderer.Tests/cases/test15-acid1.html
new file mode 100644
index 0000000..3fffecd
--- /dev/null
+++ b/src/AngleSharp.Renderer.Tests/cases/test15-acid1.html
@@ -0,0 +1,177 @@
+
+
+
+
+ display/box/float/clear test
+
+
+
+
+
+ -
+ toggle
+
+ -
+
+ -
+ the way
+
+ -
+
+ the world ends
+
+
+
+ -
+ i grow old
+
+ -
+ pluot?
+
+
+
+
+ bar maids,
+
+
+
+ sing to me, erbarme dich
+
+
+
+
+ This is a nonsensical document, but syntactically valid HTML 4.0. All 100%-conformant CSS1 agents should be able to render the document elements above this paragraph indistinguishably (to the pixel) from this
+ reference rendering,
+ (except font rasterization and form widgets). All discrepancies should be traceable to CSS1 implementation shortcomings. Once you have finished evaluating this test, you can return to the parent page.
+
+
+
diff --git a/src/AngleSharp.Renderer.Tests/verification-assets/acid1.linux.png b/src/AngleSharp.Renderer.Tests/verification-assets/acid1.linux.png
new file mode 100644
index 0000000..6ee19e4
Binary files /dev/null and b/src/AngleSharp.Renderer.Tests/verification-assets/acid1.linux.png differ
diff --git a/src/AngleSharp.Renderer.Tests/verification-assets/acid1.macos.png b/src/AngleSharp.Renderer.Tests/verification-assets/acid1.macos.png
new file mode 100644
index 0000000..2a6694b
Binary files /dev/null and b/src/AngleSharp.Renderer.Tests/verification-assets/acid1.macos.png differ
diff --git a/src/AngleSharp.Renderer.Tests/verification-assets/acid1.windows.png b/src/AngleSharp.Renderer.Tests/verification-assets/acid1.windows.png
new file mode 100644
index 0000000..69d338c
Binary files /dev/null and b/src/AngleSharp.Renderer.Tests/verification-assets/acid1.windows.png differ
diff --git a/src/AngleSharp.Renderer/HtmlRenderer.Frames.cs b/src/AngleSharp.Renderer/HtmlRenderer.Frames.cs
index 781df15..7c84609 100644
--- a/src/AngleSharp.Renderer/HtmlRenderer.Frames.cs
+++ b/src/AngleSharp.Renderer/HtmlRenderer.Frames.cs
@@ -39,22 +39,28 @@ internal sealed class SubframeEntry
///
private static void PaintSubframe(DisplayList displayList, IElement element, LayoutContext context, float x, float y, float width, float height)
{
- if (s_trialDepth > 0 || width <= 0f || height <= 0f)
+ if (s_trialDepth > 0)
{
return;
}
- var viewport = new RenderRect(x, y, width, height);
- var command = new DrawSubframeCommand(viewport);
- displayList.Add(command);
+ var viewport = new RenderRect(x, y, Math.Max(0f, width), Math.Max(0f, height));
if (!context.Subframes.TryGetValue(element, out var entry))
{
context.Subframes[element] = entry = new SubframeEntry();
}
- entry.Commands.Add(command);
entry.Viewport = viewport;
+
+ // an empty iframe shows nothing, but its document still has that viewport (e.g. for
+ // its media queries)
+ if (width > 0f && height > 0f)
+ {
+ var command = new DrawSubframeCommand(viewport);
+ displayList.Add(command);
+ entry.Commands.Add(command);
+ }
}
private static void ResolveSubframes(IDocument document, LayoutContext context)
@@ -83,7 +89,11 @@ private static void ResolveSubframes(IDocument document, LayoutContext context)
{
parent?.AttachSubframe(state);
state.SetViewport((int)Math.Round(entry.Viewport.Width), (int)Math.Round(entry.Viewport.Height));
- entry.Frame = state.PrepareFrame();
+
+ if (entry.Commands.Count > 0)
+ {
+ entry.Frame = state.PrepareFrame();
+ }
}
foreach (var command in entry.Commands)
diff --git a/src/AngleSharp.Renderer/HtmlRenderer.cs b/src/AngleSharp.Renderer/HtmlRenderer.cs
index b24da4a..e198070 100644
--- a/src/AngleSharp.Renderer/HtmlRenderer.cs
+++ b/src/AngleSharp.Renderer/HtmlRenderer.cs
@@ -9699,10 +9699,48 @@ element is not IPseudoElement &&
private static bool TryGetObjectImage(IElement element, out CachedImageResource? imageResource)
{
imageResource = null;
+ // an error (e.g. a 404 with an image) shows the fallback (HTML 4.8.6)
return element is not ILoadableElement { CurrentDownload.Task.IsCompleted: false } &&
+ (GetObjectResponse(element) is not { } response || IsSuccessful(response)) &&
TryGetOrLoadImageResource(element, element.GetAttribute("data"), out imageResource) && imageResource is not null;
}
+ ///
+ /// An object showing a document (e.g. a page of HTML) rather than an image, which
+ /// hides its fallback like an iframe. The document itself isn't shown (Acid3 has a
+ /// transparent one), so the object is an empty box of the size of an iframe.
+ ///
+ private static bool ShowsObjectDocument(IElement element)
+ {
+ if (element is IPseudoElement || !string.Equals(element.LocalName, "object", StringComparison.OrdinalIgnoreCase) ||
+ GetObjectResponse(element) is not { } response || !IsSuccessful(response))
+ {
+ return false;
+ }
+
+ return ObjectDocumentService.IsDocument(response);
+ }
+
+ // the completed response of the data of an object, if any (one a request failed for is none)
+ private static IResponse? GetObjectResponse(IElement element)
+ {
+ if (element is not ILoadableElement { CurrentDownload.Task: { IsCompleted: true } task })
+ {
+ return null;
+ }
+
+ try
+ {
+ return task.Status == TaskStatus.RanToCompletion ? task.Result : null;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ private static bool IsSuccessful(IResponse response) => (int)response.StatusCode is >= 200 and < 300;
+
private static bool HasLoadableImageSource(IElement element) =>
TryGetOrLoadImageResource(element, element.GetAttribute("src"), out var imageResource) && imageResource is not null;
@@ -10699,7 +10737,7 @@ private static FormControlKind ResolveFormControlKind(ElementRenderNode node)
return FormControlKind.Progress;
}
- if (string.Equals(tagName, "iframe", StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(tagName, "iframe", StringComparison.OrdinalIgnoreCase) || ShowsObjectDocument(element))
{
return FormControlKind.Frame;
}
@@ -11557,7 +11595,7 @@ private static void PaintFormControl(
PaintListBox(displayList, element, textStyle, context, contentX, contentY, contentWidth, contentHeight);
break;
- case FormControlKind.Frame:
+ case FormControlKind.Frame when string.Equals(element.LocalName, "iframe", StringComparison.OrdinalIgnoreCase):
PaintSubframe(displayList, element, context, contentX, contentY, contentWidth, contentHeight);
break;
diff --git a/src/AngleSharp.Renderer/InteractiveHtmlRendererStateExtensions.cs b/src/AngleSharp.Renderer/InteractiveHtmlRendererStateExtensions.cs
index be87b75..1d18963 100644
--- a/src/AngleSharp.Renderer/InteractiveHtmlRendererStateExtensions.cs
+++ b/src/AngleSharp.Renderer/InteractiveHtmlRendererStateExtensions.cs
@@ -30,13 +30,16 @@ public static IDomHarness GetDomHarness(this IBrowsingContext context)
throw new InvalidOperationException("No IRenderDevice service is registered in the browsing context. Register a render device service in IConfiguration before creating the context.");
}
- // the document of an iframe has a viewport of its own
- if (browsingContext.Parent is not null)
+ // the document of an iframe has a viewport of its own, which is the device of its
+ // context if the host registered one per context (so its media queries see it too)
+ if (browsingContext.Parent is { } parentContext &&
+ (renderDevice is not DefaultRenderDevice || ReferenceEquals(renderDevice, parentContext.GetServices().FirstOrDefault())))
{
renderDevice = new DefaultRenderDevice
{
Category = renderDevice.Category,
ColorBits = renderDevice.ColorBits,
+ MonochromeBits = renderDevice.MonochromeBits,
Frequency = renderDevice.Frequency,
IsInterlaced = renderDevice.IsInterlaced,
IsScripting = renderDevice.IsScripting,
diff --git a/src/AngleSharp.Renderer/Rendering/ObjectDocumentService.cs b/src/AngleSharp.Renderer/Rendering/ObjectDocumentService.cs
new file mode 100644
index 0000000..06a7714
--- /dev/null
+++ b/src/AngleSharp.Renderer/Rendering/ObjectDocumentService.cs
@@ -0,0 +1,47 @@
+namespace AngleSharp.Renderer.Rendering;
+
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Threading.Tasks;
+using AngleSharp.Dom;
+using AngleSharp.Io;
+using AngleSharp.Media;
+
+///
+/// Notes the responses of object data that are documents (e.g. a page of HTML), which
+/// an object shows instead of its fallback. AngleSharp clears the headers of a response once
+/// it has been processed, so the type has to be noted while it is.
+///
+internal sealed class ObjectDocumentService : IResourceService
+{
+ private static readonly ConditionalWeakTable s_documents = new();
+ private static readonly object s_marker = new();
+
+ public static ObjectDocumentService Instance { get; } = new();
+
+ private ObjectDocumentService()
+ {
+ }
+
+ public bool SupportsType(string mimeType) => IsDocumentType(mimeType);
+
+ public Task CreateAsync(IResponse response, CancellationToken cancel)
+ {
+ s_documents.AddOrUpdate(response, s_marker);
+ return Task.FromResult(new ObjectInfo { Source = response.Address });
+ }
+
+ public static bool IsDocument(IResponse response) => s_documents.TryGetValue(response, out _);
+
+ private static bool IsDocumentType(string? mimeType) =>
+ mimeType?.Split(';')[0].Trim().ToLowerInvariant() is "text/html" or "application/xhtml+xml" or "text/plain" or "text/xml" or "application/xml";
+
+ private sealed class ObjectInfo : IObjectInfo
+ {
+ public required Url Source { get; set; }
+
+ public int Width => 0;
+
+ public int Height => 0;
+ }
+}
diff --git a/src/AngleSharp.Renderer/Rendering/RenderingConfigurationExtensions.cs b/src/AngleSharp.Renderer/Rendering/RenderingConfigurationExtensions.cs
index 2e235a7..444ca5e 100644
--- a/src/AngleSharp.Renderer/Rendering/RenderingConfigurationExtensions.cs
+++ b/src/AngleSharp.Renderer/Rendering/RenderingConfigurationExtensions.cs
@@ -28,8 +28,13 @@ public static IConfiguration WithRendering(this IConfiguration configuration, Fu
ArgumentNullException.ThrowIfNull(factory);
configuration = configuration.WithOnly(factory);
- return configuration.Services.OfType().Any()
+ configuration = configuration.Services.OfType().Any()
? configuration
: configuration.With(ImageResourceService.Instance);
+
+ // an object showing a document hides its fallback
+ return configuration.Services.OfType().Any()
+ ? configuration
+ : configuration.With(ObjectDocumentService.Instance);
}
}