mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53: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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,12 +3,18 @@ const std = @import("std");
|
||||
const parser = @import("../netsurf.zig");
|
||||
|
||||
const Node = @import("node.zig").Node;
|
||||
const Union = @import("node.zig").Union;
|
||||
|
||||
pub const Element = struct {
|
||||
pub const Self = parser.Element;
|
||||
pub const prototype = *Node;
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
pub fn toInterface(e: *parser.Element) Union {
|
||||
const n = @as(*parser.Node, @ptrCast(e));
|
||||
return Node.toInterface(n);
|
||||
}
|
||||
|
||||
// JS funcs
|
||||
// --------
|
||||
|
||||
|
||||
@@ -671,6 +671,16 @@ pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Eleme
|
||||
return elem.?;
|
||||
}
|
||||
|
||||
pub inline fn documentBody(doc: *Document) ?*Body {
|
||||
const dochtml = @as(*DocumentHTML, @ptrCast(doc));
|
||||
var body: ?*ElementHTML = undefined;
|
||||
_ = documentHTMLVtable(dochtml).get_body.?(dochtml, &body);
|
||||
if (body == null) {
|
||||
return null;
|
||||
}
|
||||
return @as(*Body, @ptrCast(body.?));
|
||||
}
|
||||
|
||||
// DocumentHTML
|
||||
pub const DocumentHTML = c.dom_html_document;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user