mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
dom: add document.createElement and document.getElementById
This commit is contained in:
@@ -3,7 +3,9 @@ const std = @import("std");
|
||||
const parser = @import("../netsurf.zig");
|
||||
|
||||
const Node = @import("node.zig").Node;
|
||||
const NodeUnion = @import("node.zig").Union;
|
||||
const Element = @import("element.zig").Element;
|
||||
const HTMLBodyElement = @import("../html/elements.zig").HTMLBodyElement;
|
||||
|
||||
pub const Document = struct {
|
||||
pub const Self = parser.Document;
|
||||
@@ -15,20 +17,21 @@ pub const Document = struct {
|
||||
// return .{};
|
||||
// }
|
||||
|
||||
pub fn getElementById(self: *parser.Document, id: []const u8) ?*parser.Element {
|
||||
return parser.documentGetElementById(self, id);
|
||||
}
|
||||
|
||||
// JS funcs
|
||||
// --------
|
||||
|
||||
pub fn get_body(_: *parser.Document) ?*parser.Body {
|
||||
// TODO
|
||||
return null;
|
||||
pub fn get_body(self: *parser.Document) ?*HTMLBodyElement {
|
||||
const b = parser.documentBody(self) orelse null;
|
||||
return @as(*HTMLBodyElement, @ptrCast(b));
|
||||
}
|
||||
|
||||
pub fn _getElementById(_: *parser.Document, _: []u8) ?*parser.Element {
|
||||
// TODO
|
||||
return null;
|
||||
pub fn _getElementById(self: *parser.Document, id: []const u8) ?NodeUnion {
|
||||
const e = parser.documentGetElementById(self, id) orelse return null;
|
||||
return Element.toInterface(e);
|
||||
}
|
||||
|
||||
pub fn _createElement(self: *parser.Document, tag_name: []const u8) NodeUnion {
|
||||
const e = parser.documentCreateElement(self, tag_name);
|
||||
return Element.toInterface(e);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user