mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
dom: add DocumentType
This commit is contained in:
24
src/dom/document_type.zig
Normal file
24
src/dom/document_type.zig
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
const parser = @import("../netsurf.zig");
|
||||||
|
|
||||||
|
const Node = @import("node.zig").Node;
|
||||||
|
|
||||||
|
// WEB IDL https://dom.spec.whatwg.org/#documenttype
|
||||||
|
pub const DocumentType = struct {
|
||||||
|
pub const Self = parser.DocumentType;
|
||||||
|
pub const prototype = *Node;
|
||||||
|
pub const mem_guarantied = true;
|
||||||
|
|
||||||
|
pub fn get_name(self: *parser.DocumentType) []const u8 {
|
||||||
|
return parser.documentTypeGetName(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_publicId(self: *parser.DocumentType) []const u8 {
|
||||||
|
return parser.documentTypeGetPublicId(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_systemId(self: *parser.DocumentType) []const u8 {
|
||||||
|
return parser.documentTypeGetSystemId(self);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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 DocumentType = @import("document_type.zig").DocumentType;
|
||||||
const HTMLCollection = @import("html_collection.zig").HTMLCollection;
|
const HTMLCollection = @import("html_collection.zig").HTMLCollection;
|
||||||
|
|
||||||
// HTML
|
// HTML
|
||||||
@@ -26,6 +27,7 @@ pub const Interfaces = generate.Tuple(.{
|
|||||||
CData.Interfaces,
|
CData.Interfaces,
|
||||||
Element,
|
Element,
|
||||||
Document,
|
Document,
|
||||||
|
DocumentType,
|
||||||
HTMLCollection,
|
HTMLCollection,
|
||||||
|
|
||||||
HTML.Interfaces,
|
HTML.Interfaces,
|
||||||
@@ -46,6 +48,7 @@ pub const Node = struct {
|
|||||||
.comment => .{ .Comment = @as(*parser.Comment, @ptrCast(node)) },
|
.comment => .{ .Comment = @as(*parser.Comment, @ptrCast(node)) },
|
||||||
.text => .{ .Text = @as(*parser.Text, @ptrCast(node)) },
|
.text => .{ .Text = @as(*parser.Text, @ptrCast(node)) },
|
||||||
.document => .{ .HTMLDocument = @as(*parser.DocumentHTML, @ptrCast(node)) },
|
.document => .{ .HTMLDocument = @as(*parser.DocumentHTML, @ptrCast(node)) },
|
||||||
|
.document_type => .{ .DocumentType = @as(*parser.DocumentType, @ptrCast(node)) },
|
||||||
else => @panic("node type not handled"), // TODO
|
else => @panic("node type not handled"), // TODO
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -720,6 +720,31 @@ pub const DocumentPosition = enum(u2) {
|
|||||||
implementation_specific = c.DOM_DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC,
|
implementation_specific = c.DOM_DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// DocumentType
|
||||||
|
pub const DocumentType = c.dom_document_type;
|
||||||
|
|
||||||
|
fn documentTypeVtable(dt: *DocumentType) c.dom_document_type_vtable {
|
||||||
|
return getVtable(c.dom_document_type_vtable, DocumentType, dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub inline fn documentTypeGetName(dt: *DocumentType) []const u8 {
|
||||||
|
var s: ?*String = undefined;
|
||||||
|
_ = documentTypeVtable(dt).dom_document_type_get_name.?(dt, &s);
|
||||||
|
return stringToData(s.?);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub inline fn documentTypeGetPublicId(dt: *DocumentType) []const u8 {
|
||||||
|
var s: ?*String = undefined;
|
||||||
|
_ = documentTypeVtable(dt).dom_document_type_get_public_id.?(dt, &s);
|
||||||
|
return stringToData(s.?);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub inline fn documentTypeGetSystemId(dt: *DocumentType) []const u8 {
|
||||||
|
var s: ?*String = undefined;
|
||||||
|
_ = documentTypeVtable(dt).dom_document_type_get_system_id.?(dt, &s);
|
||||||
|
return stringToData(s.?);
|
||||||
|
}
|
||||||
|
|
||||||
// Document
|
// Document
|
||||||
pub const Document = c.dom_document;
|
pub const Document = c.dom_document;
|
||||||
|
|
||||||
|
|||||||
17
tests/wpt/dom/nodes/DocumentType-literal.html
Normal file
17
tests/wpt/dom/nodes/DocumentType-literal.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "STAFF" "staffNS.dtd">
|
||||||
|
<title>DocumentType literals</title>
|
||||||
|
<link rel="help" href="https://dom.spec.whatwg.org/#dom-documenttype-name">
|
||||||
|
<link rel="help" href="https://dom.spec.whatwg.org/#dom-documenttype-publicid">
|
||||||
|
<link rel="help" href="https://dom.spec.whatwg.org/#dom-documenttype-systemid">
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<div id="log"></div>
|
||||||
|
<script>
|
||||||
|
test(function() {
|
||||||
|
var doctype = document.firstChild;
|
||||||
|
assert_true(doctype instanceof DocumentType)
|
||||||
|
assert_equals(doctype.name, "html")
|
||||||
|
assert_equals(doctype.publicId, 'STAFF')
|
||||||
|
assert_equals(doctype.systemId, 'staffNS.dtd')
|
||||||
|
})
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user