mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
Merge pull request #76 from Browsercore/domdoc-getter
dom document getters
This commit is contained in:
@@ -29,6 +29,48 @@ pub const Document = struct {
|
||||
// JS funcs
|
||||
// --------
|
||||
//
|
||||
pub fn get_documentElement(self: *parser.Document) ElementUnion {
|
||||
const e = parser.documentGetDocumentElement(self);
|
||||
return Element.toInterface(e);
|
||||
}
|
||||
|
||||
pub fn get_documentURI(self: *parser.Document) []const u8 {
|
||||
return parser.documentGetDocumentURI(self);
|
||||
}
|
||||
|
||||
// TODO should be get_URL but in this case, document.URL is indefined.
|
||||
pub fn get_url(self: *parser.Document) []const u8 {
|
||||
return get_documentURI(self);
|
||||
}
|
||||
|
||||
// TODO implement contentType
|
||||
pub fn get_contentType(self: *parser.Document) []const u8 {
|
||||
_ = self;
|
||||
return "text/html";
|
||||
}
|
||||
|
||||
// TODO implement compactMode
|
||||
pub fn get_compatMode(self: *parser.Document) []const u8 {
|
||||
_ = self;
|
||||
return "CSS1Compat";
|
||||
}
|
||||
|
||||
// TODO implement characterSet
|
||||
pub fn get_characterSet(self: *parser.Document) []const u8 {
|
||||
_ = self;
|
||||
return "UTF-8";
|
||||
}
|
||||
|
||||
// alias of get_characterSet
|
||||
pub fn get_charset(self: *parser.Document) []const u8 {
|
||||
return get_characterSet(self);
|
||||
}
|
||||
|
||||
// alias of get_characterSet
|
||||
pub fn get_inputEncoding(self: *parser.Document) []const u8 {
|
||||
return get_characterSet(self);
|
||||
}
|
||||
|
||||
pub fn get_doctype(self: *parser.Document) ?*parser.DocumentType {
|
||||
return parser.documentGetDoctype(self);
|
||||
}
|
||||
@@ -112,6 +154,36 @@ pub fn testExecFn(
|
||||
};
|
||||
try checkCases(js_env, &getElementsByClassName);
|
||||
|
||||
var getDocumentElement = [_]Case{
|
||||
.{ .src = "let e = document.documentElement", .ex = "undefined" },
|
||||
.{ .src = "e.localName", .ex = "html" },
|
||||
};
|
||||
try checkCases(js_env, &getDocumentElement);
|
||||
|
||||
var getCharacterSet = [_]Case{
|
||||
.{ .src = "document.characterSet", .ex = "UTF-8" },
|
||||
.{ .src = "document.charset", .ex = "UTF-8" },
|
||||
.{ .src = "document.inputEncoding", .ex = "UTF-8" },
|
||||
};
|
||||
try checkCases(js_env, &getCharacterSet);
|
||||
|
||||
var getCompatMode = [_]Case{
|
||||
.{ .src = "document.compatMode", .ex = "CSS1Compat" },
|
||||
};
|
||||
try checkCases(js_env, &getCompatMode);
|
||||
|
||||
var getContentType = [_]Case{
|
||||
.{ .src = "document.contentType", .ex = "text/html" },
|
||||
};
|
||||
try checkCases(js_env, &getContentType);
|
||||
|
||||
var getDocumentURI = [_]Case{
|
||||
.{ .src = "document.documentURI", .ex = "about:blank" },
|
||||
// TODO should be document.URL
|
||||
.{ .src = "document.url", .ex = "about:blank" },
|
||||
};
|
||||
try checkCases(js_env, &getDocumentURI);
|
||||
|
||||
const tags = comptime parser.Tag.all();
|
||||
comptime var createElements: [(tags.len) * 2]Case = undefined;
|
||||
inline for (tags, 0..) |tag, i| {
|
||||
|
||||
@@ -794,6 +794,12 @@ pub inline fn documentGetDocumentElement(doc: *Document) *Element {
|
||||
return elem.?;
|
||||
}
|
||||
|
||||
pub inline fn documentGetDocumentURI(doc: *Document) []const u8 {
|
||||
var s: ?*String = undefined;
|
||||
_ = documentVtable(doc).dom_document_get_uri.?(doc, &s);
|
||||
return stringToData(s.?);
|
||||
}
|
||||
|
||||
pub inline fn documentCreateElement(doc: *Document, tag_name: []const u8) *Element {
|
||||
var elem: ?*Element = undefined;
|
||||
_ = documentVtable(doc).dom_document_create_element.?(doc, stringFromData(tag_name), &elem);
|
||||
|
||||
Reference in New Issue
Block a user