mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 08:18:59 +00:00
dom: add HTMLCollection
This commit is contained in:
28
src/dom/html_collection.zig
Normal file
28
src/dom/html_collection.zig
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
const parser = @import("../netsurf.zig");
|
||||||
|
|
||||||
|
const jsruntime = @import("jsruntime");
|
||||||
|
|
||||||
|
const Element = @import("element.zig").Element;
|
||||||
|
|
||||||
|
// WEB IDL https://dom.spec.whatwg.org/#htmlcollection
|
||||||
|
pub const HTMLCollection = struct {
|
||||||
|
pub const Self = parser.HTMLCollection;
|
||||||
|
pub const mem_guarantied = true;
|
||||||
|
|
||||||
|
// JS funcs
|
||||||
|
// --------
|
||||||
|
|
||||||
|
pub fn _get_length(self: *parser.HTMLCollection) u32 {
|
||||||
|
return parser.HTMLCollectionLength(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn _item(self: *parser.HTMLCollection, index: u32) ?*parser.Element {
|
||||||
|
return parser.HTMLCollectionItem(self, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn _namedItem(self: *parser.HTMLCollection, name: []const u8) ?*parser.Element {
|
||||||
|
return parser.HTMLCollectionNamedItem(self, name);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -14,6 +14,7 @@ const EventTarget = @import("event_target.zig").EventTarget;
|
|||||||
const CData = @import("character_data.zig");
|
const CData = @import("character_data.zig");
|
||||||
const Element = @import("element.zig").Element;
|
const Element = @import("element.zig").Element;
|
||||||
const Document = @import("document.zig").Document;
|
const Document = @import("document.zig").Document;
|
||||||
|
const HTMLCollection = @import("html_collection.zig").HTMLCollection;
|
||||||
|
|
||||||
// HTML
|
// HTML
|
||||||
const HTML = @import("../html/html.zig");
|
const HTML = @import("../html/html.zig");
|
||||||
@@ -25,6 +26,7 @@ pub const Interfaces = generate.Tuple(.{
|
|||||||
CData.Interfaces,
|
CData.Interfaces,
|
||||||
Element,
|
Element,
|
||||||
Document,
|
Document,
|
||||||
|
HTMLCollection,
|
||||||
|
|
||||||
HTML.Interfaces,
|
HTML.Interfaces,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -618,6 +618,40 @@ pub fn elementGetAttribute(elem: *Element, name: []const u8) ?[]const u8 {
|
|||||||
return stringToData(s.?);
|
return stringToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTMLCollection
|
||||||
|
|
||||||
|
pub const HTMLCollection = c.dom_html_collection;
|
||||||
|
|
||||||
|
pub fn HTMLCollectionLength(collection: *HTMLCollection) u32 {
|
||||||
|
var ln: u32 = undefined;
|
||||||
|
_ = c.dom_html_collection_get_length(collection, &ln);
|
||||||
|
return ln;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn HTMLCollectionItem(collection: *HTMLCollection, index: u32) ?*Element {
|
||||||
|
var n: [*c]c.dom_node = undefined;
|
||||||
|
_ = c.dom_html_collection_item(collection, index, &n);
|
||||||
|
|
||||||
|
if (n == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cast [*c]c.dom_node into *Element
|
||||||
|
return @as(*Element, @ptrCast(n));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn HTMLCollectionNamedItem(collection: *HTMLCollection, name: []const u8) ?*Element {
|
||||||
|
var n: [*c]c.dom_node = undefined;
|
||||||
|
_ = c.dom_html_collection_named_item(collection, stringFromData(name), &n);
|
||||||
|
|
||||||
|
if (n == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cast [*c]c.dom_node into *Element
|
||||||
|
return @as(*Element, @ptrCast(n));
|
||||||
|
}
|
||||||
|
|
||||||
// ElementHTML
|
// ElementHTML
|
||||||
pub const ElementHTML = c.dom_html_element;
|
pub const ElementHTML = c.dom_html_element;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user