From 950182986a2ba5f720d3ee1f9053e68561279e0e Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Wed, 27 Aug 2025 09:04:21 +0800 Subject: [PATCH] Start working on HTMLSlotElement --- src/browser/dom/element.zig | 11 +++ src/browser/dom/node.zig | 17 ++++- src/browser/html/elements.zig | 102 ++++++++++++++++++++++++++ src/browser/netsurf.zig | 2 + src/tests/html/html_slot_element.html | 66 +++++++++++++++++ vendor/netsurf/libdom | 2 +- 6 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 src/tests/html/html_slot_element.html diff --git a/src/browser/dom/element.zig b/src/browser/dom/element.zig index 5043c4cb..5482dc65 100644 --- a/src/browser/dom/element.zig +++ b/src/browser/dom/element.zig @@ -560,6 +560,17 @@ pub const Element = struct { state.shadow_root = sr; parser.documentFragmentSetHost(sr.proto, @ptrCast(@alignCast(self))); + // Storing the ShadowRoot on the element makes sense, it's the ShadowRoot's + // parent. When we render, we go top-down, so we'll have the element, get + // its shadowroot, and go on. that's what the above code does. + // But we sometimes need to go bottom-up, e.g when we have a slot element + // and want to find the containing parent. Unforatunately , we don't have + // that link, so we need to create it. In the DOM, the ShadowRoot is + // represented by this DocumentFragment (it's the ShadowRoot's base prototype) + // So we can also store the ShadowRoot in the DocumentFragment's state. + const fragment_state = try page.getOrCreateNodeState(@ptrCast(@alignCast(fragment))); + fragment_state.shadow_root = sr; + return sr; } diff --git a/src/browser/dom/node.zig b/src/browser/dom/node.zig index aa3933d0..5dc171b4 100644 --- a/src/browser/dom/node.zig +++ b/src/browser/dom/node.zig @@ -37,6 +37,7 @@ const DocumentFragment = @import("document_fragment.zig").DocumentFragment; const HTMLCollection = @import("html_collection.zig").HTMLCollection; const HTMLAllCollection = @import("html_collection.zig").HTMLAllCollection; const HTMLCollectionIterator = @import("html_collection.zig").HTMLCollectionIterator; +const ShadowRoot = @import("shadow_root.zig").ShadowRoot; const Walker = @import("walker.zig").WalkerDepthFirst; // HTML @@ -354,11 +355,23 @@ pub const Node = struct { // - An Element inside a standard web page will return an HTMLDocument object representing the entire page (or