mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
dom: create elementToNode helper
This commit is contained in:
@@ -45,9 +45,9 @@ pub const Document = struct {
|
|||||||
// That's why we reimplemented getElementsByTagName by using an
|
// That's why we reimplemented getElementsByTagName by using an
|
||||||
// HTMLCollection in zig here.
|
// HTMLCollection in zig here.
|
||||||
pub fn _getElementsByTagName(self: *parser.Document, tag_name: []const u8) HTMLCollection {
|
pub fn _getElementsByTagName(self: *parser.Document, tag_name: []const u8) HTMLCollection {
|
||||||
const root = parser.documentGetDocumentNode(self);
|
const root = parser.documentGetDocumentElement(self);
|
||||||
return HTMLCollection{
|
return HTMLCollection{
|
||||||
.root = root,
|
.root = parser.elementToNode(root),
|
||||||
.match = tag_name,
|
.match = tag_name,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -621,6 +621,11 @@ pub fn elementGetAttribute(elem: *Element, name: []const u8) ?[]const u8 {
|
|||||||
return stringToData(s.?);
|
return stringToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// elementToNode is an helper to convert an element to a node.
|
||||||
|
pub inline fn elementToNode(e: *Element) *Node {
|
||||||
|
return @as(*Node, @ptrCast(e));
|
||||||
|
}
|
||||||
|
|
||||||
// ElementHTML
|
// ElementHTML
|
||||||
pub const ElementHTML = c.dom_html_element;
|
pub const ElementHTML = c.dom_html_element;
|
||||||
|
|
||||||
@@ -741,11 +746,6 @@ pub inline fn documentGetDocumentElement(doc: *Document) *Element {
|
|||||||
return elem.?;
|
return elem.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn documentGetDocumentNode(doc: *Document) *Node {
|
|
||||||
const res = documentGetDocumentElement(doc);
|
|
||||||
return @as(*Node, @ptrCast(res));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Element {
|
pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Element {
|
||||||
var elem: ?*Element = undefined;
|
var elem: ?*Element = undefined;
|
||||||
_ = documentVtable(doc).dom_document_create_element.?(doc, stringFromData(tag_name), &elem);
|
_ = documentVtable(doc).dom_document_create_element.?(doc, stringFromData(tag_name), &elem);
|
||||||
|
|||||||
Reference in New Issue
Block a user