mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 00:08:59 +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 parser = @import("../netsurf.zig");
|
||||||
|
|
||||||
const Node = @import("node.zig").Node;
|
const Node = @import("node.zig").Node;
|
||||||
|
const NodeUnion = @import("node.zig").Union;
|
||||||
const Element = @import("element.zig").Element;
|
const Element = @import("element.zig").Element;
|
||||||
|
const HTMLBodyElement = @import("../html/elements.zig").HTMLBodyElement;
|
||||||
|
|
||||||
pub const Document = struct {
|
pub const Document = struct {
|
||||||
pub const Self = parser.Document;
|
pub const Self = parser.Document;
|
||||||
@@ -15,20 +17,21 @@ pub const Document = struct {
|
|||||||
// return .{};
|
// return .{};
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pub fn getElementById(self: *parser.Document, id: []const u8) ?*parser.Element {
|
|
||||||
return parser.documentGetElementById(self, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// JS funcs
|
// JS funcs
|
||||||
// --------
|
// --------
|
||||||
|
|
||||||
pub fn get_body(_: *parser.Document) ?*parser.Body {
|
pub fn get_body(self: *parser.Document) ?*HTMLBodyElement {
|
||||||
// TODO
|
const b = parser.documentBody(self) orelse null;
|
||||||
return null;
|
return @as(*HTMLBodyElement, @ptrCast(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _getElementById(_: *parser.Document, _: []u8) ?*parser.Element {
|
pub fn _getElementById(self: *parser.Document, id: []const u8) ?NodeUnion {
|
||||||
// TODO
|
const e = parser.documentGetElementById(self, id) orelse return null;
|
||||||
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 parser = @import("../netsurf.zig");
|
||||||
|
|
||||||
const Node = @import("node.zig").Node;
|
const Node = @import("node.zig").Node;
|
||||||
|
const Union = @import("node.zig").Union;
|
||||||
|
|
||||||
pub const Element = struct {
|
pub const Element = struct {
|
||||||
pub const Self = parser.Element;
|
pub const Self = parser.Element;
|
||||||
pub const prototype = *Node;
|
pub const prototype = *Node;
|
||||||
pub const mem_guarantied = true;
|
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
|
// JS funcs
|
||||||
// --------
|
// --------
|
||||||
|
|
||||||
|
|||||||
@@ -671,6 +671,16 @@ pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Eleme
|
|||||||
return elem.?;
|
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
|
// DocumentHTML
|
||||||
pub const DocumentHTML = c.dom_html_document;
|
pub const DocumentHTML = c.dom_html_document;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user