diff --git a/src/browser/webapi/Document.zig b/src/browser/webapi/Document.zig index 57db61fd..8c4e030b 100644 --- a/src/browser/webapi/Document.zig +++ b/src/browser/webapi/Document.zig @@ -36,6 +36,7 @@ const DOMTreeWalker = @import("DOMTreeWalker.zig"); const DOMNodeIterator = @import("DOMNodeIterator.zig"); const DOMImplementation = @import("DOMImplementation.zig"); const StyleSheetList = @import("css/StyleSheetList.zig"); +const Selection = @import("Selection.zig"); pub const XMLDocument = @import("XMLDocument.zig"); pub const HTMLDocument = @import("HTMLDocument.zig"); @@ -55,6 +56,7 @@ _style_sheets: ?*StyleSheetList = null, _write_insertion_point: ?*Node = null, _script_created_parser: ?Parser.Streaming = null, _adopted_style_sheets: ?js.Object.Global = null, +_selection: Selection = .init, pub const Type = union(enum) { generic, @@ -276,6 +278,10 @@ pub fn getDocumentElement(self: *Document) ?*Element { return null; } +pub fn getSelection(self: *Document) *Selection { + return &self._selection; +} + pub fn querySelector(self: *Document, input: []const u8, page: *Page) !?*Element { 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 querySelectorAll = bridge.function(Document.querySelectorAll, .{ .dom_exception = true }); pub const getElementsByTagName = bridge.function(Document.getElementsByTagName, .{}); + pub const getSelection = bridge.function(Document.getSelection, .{}); pub const getElementsByClassName = bridge.function(Document.getElementsByClassName, .{}); pub const getElementsByName = bridge.function(Document.getElementsByName, .{}); pub const adoptNode = bridge.function(Document.adoptNode, .{ .dom_exception = true }); diff --git a/src/browser/webapi/Window.zig b/src/browser/webapi/Window.zig index 7b6938e8..251f0220 100644 --- a/src/browser/webapi/Window.zig +++ b/src/browser/webapi/Window.zig @@ -42,6 +42,7 @@ const storage = @import("storage/storage.zig"); const Element = @import("Element.zig"); const CSSStyleProperties = @import("css/CSSStyleProperties.zig"); const CustomElementRegistry = @import("CustomElementRegistry.zig"); +const Selection = @import("Selection.zig"); const Window = @This(); @@ -129,6 +130,10 @@ pub fn getLocation(self: *const Window) *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 { 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 reportError = bridge.function(Window.reportError, .{}); pub const getComputedStyle = bridge.function(Window.getComputedStyle, .{}); + pub const getSelection = bridge.function(Window.getSelection, .{}); pub const isSecureContext = bridge.accessor(Window.getIsSecureContext, null, .{}); pub const frames = bridge.accessor(Window.getWindow, null, .{ .cache = "frames" }); pub const index = bridge.indexed(Window.getFrame, .{ .null_as_undefined = true });