From 4d67cfa34041f9fe10e7393e88a2b327606e988d Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Tue, 23 Dec 2025 17:14:34 +0100 Subject: [PATCH] backport frames access from Window --- src/browser/webapi/Window.zig | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/browser/webapi/Window.zig b/src/browser/webapi/Window.zig index 7cf26b6c..4b00c72e 100644 --- a/src/browser/webapi/Window.zig +++ b/src/browser/webapi/Window.zig @@ -343,8 +343,23 @@ pub fn atob(_: *const Window, input: []const u8, page: *Page) ![]const u8 { return decoded; } -pub fn getLength(_: *const Window) u32 { - return 0; +pub fn getFrame(_: *Window, _: usize) !?*Window { + // TODO return the iframe's window. + return null; +} + +pub fn getFramesLength(self: *const Window) u32 { + const TreeWalker = @import("TreeWalker.zig"); + var walker = TreeWalker.Full.init(self._document.asNode(), .{}); + + var ln: u32 = 0; + while (walker.next()) |node| { + const other_element = node.is(Element) orelse continue; + _ = other_element.is(Element.Html.IFrame) orelse continue; + ln += 1; + } + + return ln; } pub fn getInnerWidth(_: *const Window) u32 { @@ -562,9 +577,10 @@ pub const JsApi = struct { pub const btoa = bridge.function(Window.btoa, .{}); pub const atob = bridge.function(Window.atob, .{}); pub const reportError = bridge.function(Window.reportError, .{}); - pub const frames = bridge.accessor(Window.getWindow, null, .{ .cache = "frames" }); pub const getComputedStyle = bridge.function(Window.getComputedStyle, .{}); - pub const length = bridge.accessor(Window.getLength, null, .{ .cache = "length" }); + pub const frames = bridge.accessor(Window.getWindow, null, .{ .cache = "frames" }); + pub const index = bridge.indexed(Window.getFrame, .{ .null_as_undefined = true }); + pub const length = bridge.accessor(Window.getFramesLength, null, .{ .cache = "length" }); pub const innerWidth = bridge.accessor(Window.getInnerWidth, null, .{ .cache = "innerWidth" }); pub const innerHeight = bridge.accessor(Window.getInnerHeight, null, .{ .cache = "innerHeight" }); pub const scrollX = bridge.accessor(Window.getScrollX, null, .{ .cache = "scrollX" });