add getSelection to Window, Document

This commit is contained in:
Muki Kiboigo
2026-01-14 00:36:42 -08:00
parent 0e6e4db08b
commit a6fc5aa345
2 changed files with 13 additions and 0 deletions

View File

@@ -36,6 +36,7 @@ const DOMTreeWalker = @import("DOMTreeWalker.zig");
const DOMNodeIterator = @import("DOMNodeIterator.zig"); const DOMNodeIterator = @import("DOMNodeIterator.zig");
const DOMImplementation = @import("DOMImplementation.zig"); const DOMImplementation = @import("DOMImplementation.zig");
const StyleSheetList = @import("css/StyleSheetList.zig"); const StyleSheetList = @import("css/StyleSheetList.zig");
const Selection = @import("Selection.zig");
pub const XMLDocument = @import("XMLDocument.zig"); pub const XMLDocument = @import("XMLDocument.zig");
pub const HTMLDocument = @import("HTMLDocument.zig"); pub const HTMLDocument = @import("HTMLDocument.zig");
@@ -55,6 +56,7 @@ _style_sheets: ?*StyleSheetList = null,
_write_insertion_point: ?*Node = null, _write_insertion_point: ?*Node = null,
_script_created_parser: ?Parser.Streaming = null, _script_created_parser: ?Parser.Streaming = null,
_adopted_style_sheets: ?js.Object.Global = null, _adopted_style_sheets: ?js.Object.Global = null,
_selection: Selection = .init,
pub const Type = union(enum) { pub const Type = union(enum) {
generic, generic,
@@ -276,6 +278,10 @@ pub fn getDocumentElement(self: *Document) ?*Element {
return null; return null;
} }
pub fn getSelection(self: *Document) *Selection {
return &self._selection;
}
pub fn querySelector(self: *Document, input: []const u8, page: *Page) !?*Element { pub fn querySelector(self: *Document, input: []const u8, page: *Page) !?*Element {
return Selector.querySelector(self.asNode(), input, page); return Selector.querySelector(self.asNode(), input, page);
} }
@@ -962,6 +968,7 @@ pub const JsApi = struct {
pub const querySelector = bridge.function(Document.querySelector, .{ .dom_exception = true }); pub const querySelector = bridge.function(Document.querySelector, .{ .dom_exception = true });
pub const querySelectorAll = bridge.function(Document.querySelectorAll, .{ .dom_exception = true }); pub const querySelectorAll = bridge.function(Document.querySelectorAll, .{ .dom_exception = true });
pub const getElementsByTagName = bridge.function(Document.getElementsByTagName, .{}); pub const getElementsByTagName = bridge.function(Document.getElementsByTagName, .{});
pub const getSelection = bridge.function(Document.getSelection, .{});
pub const getElementsByClassName = bridge.function(Document.getElementsByClassName, .{}); pub const getElementsByClassName = bridge.function(Document.getElementsByClassName, .{});
pub const getElementsByName = bridge.function(Document.getElementsByName, .{}); pub const getElementsByName = bridge.function(Document.getElementsByName, .{});
pub const adoptNode = bridge.function(Document.adoptNode, .{ .dom_exception = true }); pub const adoptNode = bridge.function(Document.adoptNode, .{ .dom_exception = true });

View File

@@ -42,6 +42,7 @@ const storage = @import("storage/storage.zig");
const Element = @import("Element.zig"); const Element = @import("Element.zig");
const CSSStyleProperties = @import("css/CSSStyleProperties.zig"); const CSSStyleProperties = @import("css/CSSStyleProperties.zig");
const CustomElementRegistry = @import("CustomElementRegistry.zig"); const CustomElementRegistry = @import("CustomElementRegistry.zig");
const Selection = @import("Selection.zig");
const Window = @This(); const Window = @This();
@@ -129,6 +130,10 @@ pub fn getLocation(self: *const Window) *Location {
return self._location; return self._location;
} }
pub fn getSelection(self: *const Window) *Selection {
return &self._document._selection;
}
pub fn setLocation(_: *const Window, url: [:0]const u8, page: *Page) !void { pub fn setLocation(_: *const Window, url: [:0]const u8, page: *Page) !void {
return page.scheduleNavigation(url, .{ .reason = .script, .kind = .{ .push = null } }, .script); return page.scheduleNavigation(url, .{ .reason = .script, .kind = .{ .push = null } }, .script);
} }
@@ -676,6 +681,7 @@ pub const JsApi = struct {
pub const atob = bridge.function(Window.atob, .{}); pub const atob = bridge.function(Window.atob, .{});
pub const reportError = bridge.function(Window.reportError, .{}); pub const reportError = bridge.function(Window.reportError, .{});
pub const getComputedStyle = bridge.function(Window.getComputedStyle, .{}); pub const getComputedStyle = bridge.function(Window.getComputedStyle, .{});
pub const getSelection = bridge.function(Window.getSelection, .{});
pub const isSecureContext = bridge.accessor(Window.getIsSecureContext, null, .{}); pub const isSecureContext = bridge.accessor(Window.getIsSecureContext, null, .{});
pub const frames = bridge.accessor(Window.getWindow, null, .{ .cache = "frames" }); pub const frames = bridge.accessor(Window.getWindow, null, .{ .cache = "frames" });
pub const index = bridge.indexed(Window.getFrame, .{ .null_as_undefined = true }); pub const index = bridge.indexed(Window.getFrame, .{ .null_as_undefined = true });