mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-24 13:43:15 +00:00
Merge pull request #1056 from lightpanda-io/DOM_NO_ERR
Convert more DOM_NO_ERR cases to assertions
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const log = @import("../log.zig");
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
|
||||||
const Scheduler = @This();
|
const Scheduler = @This();
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element) !void {
|
|||||||
remote_url = try URL.stitch(page.arena, src, page.url.raw, .{ .null_terminated = true });
|
remote_url = try URL.stitch(page.arena, src, page.url.raw, .{ .null_terminated = true });
|
||||||
source = .{ .remote = .{} };
|
source = .{ .remote = .{} };
|
||||||
} else {
|
} else {
|
||||||
const inline_source = try parser.nodeTextContent(@ptrCast(element)) orelse return;
|
const inline_source = parser.nodeTextContent(@ptrCast(element)) orelse return;
|
||||||
source = .{ .@"inline" = inline_source };
|
source = .{ .@"inline" = inline_source };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ const parser = @import("netsurf.zig");
|
|||||||
const DataSet = @import("html/DataSet.zig");
|
const DataSet = @import("html/DataSet.zig");
|
||||||
const ShadowRoot = @import("dom/shadow_root.zig").ShadowRoot;
|
const ShadowRoot = @import("dom/shadow_root.zig").ShadowRoot;
|
||||||
const StyleSheet = @import("cssom/StyleSheet.zig");
|
const StyleSheet = @import("cssom/StyleSheet.zig");
|
||||||
const CSSStyleSheet = @import("cssom/CSSStyleSheet.zig");
|
|
||||||
const CSSStyleDeclaration = @import("cssom/CSSStyleDeclaration.zig");
|
const CSSStyleDeclaration = @import("cssom/CSSStyleDeclaration.zig");
|
||||||
|
|
||||||
// for HTMLScript (but probably needs to be added to more)
|
// for HTMLScript (but probably needs to be added to more)
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ const std = @import("std");
|
|||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const log = @import("../../log.zig");
|
const log = @import("../../log.zig");
|
||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
|
||||||
const Page = @import("../page.zig").Page;
|
const Page = @import("../page.zig").Page;
|
||||||
const JsObject = @import("../env.zig").Env.JsObject;
|
const JsObject = @import("../env.zig").Env.JsObject;
|
||||||
|
|
||||||
|
|||||||
@@ -46,17 +46,15 @@ pub fn parse(alloc: std.mem.Allocator, s: []const u8, opts: parser.ParseOptions)
|
|||||||
// matchFirst call m.match with the first node that matches the selector s, from the
|
// matchFirst call m.match with the first node that matches the selector s, from the
|
||||||
// descendants of n and returns true. If none matches, it returns false.
|
// descendants of n and returns true. If none matches, it returns false.
|
||||||
pub fn matchFirst(s: *const Selector, node: anytype, m: anytype) !bool {
|
pub fn matchFirst(s: *const Selector, node: anytype, m: anytype) !bool {
|
||||||
var c = try node.firstChild();
|
var child = node.firstChild();
|
||||||
while (true) {
|
while (child) |c| {
|
||||||
if (c == null) break;
|
if (try s.match(c)) {
|
||||||
|
try m.match(c);
|
||||||
if (try s.match(c.?)) {
|
|
||||||
try m.match(c.?);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (try matchFirst(s, c.?, m)) return true;
|
if (try matchFirst(s, c, m)) return true;
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -64,13 +62,11 @@ pub fn matchFirst(s: *const Selector, node: anytype, m: anytype) !bool {
|
|||||||
// matchAll call m.match with the all the nodes that matches the selector s, from the
|
// matchAll call m.match with the all the nodes that matches the selector s, from the
|
||||||
// descendants of n.
|
// descendants of n.
|
||||||
pub fn matchAll(s: *const Selector, node: anytype, m: anytype) !void {
|
pub fn matchAll(s: *const Selector, node: anytype, m: anytype) !void {
|
||||||
var c = try node.firstChild();
|
var child = node.firstChild();
|
||||||
while (true) {
|
while (child) |c| {
|
||||||
if (c == null) break;
|
if (try s.match(c)) try m.match(c);
|
||||||
|
try matchAll(s, c, m);
|
||||||
if (try s.match(c.?)) try m.match(c.?);
|
child = c.nextSibling();
|
||||||
try matchAll(s, c.?, m);
|
|
||||||
c = try c.?.nextSibling();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,71 +26,67 @@ const Allocator = std.mem.Allocator;
|
|||||||
pub const Node = struct {
|
pub const Node = struct {
|
||||||
node: *parser.Node,
|
node: *parser.Node,
|
||||||
|
|
||||||
pub fn firstChild(n: Node) !?Node {
|
pub fn firstChild(n: Node) ?Node {
|
||||||
const c = try parser.nodeFirstChild(n.node);
|
const c = parser.nodeFirstChild(n.node);
|
||||||
if (c) |cc| return .{ .node = cc };
|
if (c) |cc| return .{ .node = cc };
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lastChild(n: Node) !?Node {
|
pub fn lastChild(n: Node) ?Node {
|
||||||
const c = try parser.nodeLastChild(n.node);
|
const c = parser.nodeLastChild(n.node);
|
||||||
if (c) |cc| return .{ .node = cc };
|
if (c) |cc| return .{ .node = cc };
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nextSibling(n: Node) !?Node {
|
pub fn nextSibling(n: Node) ?Node {
|
||||||
const c = try parser.nodeNextSibling(n.node);
|
const c = parser.nodeNextSibling(n.node);
|
||||||
if (c) |cc| return .{ .node = cc };
|
if (c) |cc| return .{ .node = cc };
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prevSibling(n: Node) !?Node {
|
pub fn prevSibling(n: Node) ?Node {
|
||||||
const c = try parser.nodePreviousSibling(n.node);
|
const c = parser.nodePreviousSibling(n.node);
|
||||||
if (c) |cc| return .{ .node = cc };
|
if (c) |cc| return .{ .node = cc };
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parent(n: Node) !?Node {
|
pub fn parent(n: Node) ?Node {
|
||||||
const c = try parser.nodeParentNode(n.node);
|
const c = parser.nodeParentNode(n.node);
|
||||||
if (c) |cc| return .{ .node = cc };
|
if (c) |cc| return .{ .node = cc };
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isElement(n: Node) bool {
|
pub fn isElement(n: Node) bool {
|
||||||
const t = parser.nodeType(n.node) catch return false;
|
return parser.nodeType(n.node) == .element;
|
||||||
return t == .element;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isDocument(n: Node) bool {
|
pub fn isDocument(n: Node) bool {
|
||||||
const t = parser.nodeType(n.node) catch return false;
|
return parser.nodeType(n.node) == .document;
|
||||||
return t == .document;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isComment(n: Node) bool {
|
pub fn isComment(n: Node) bool {
|
||||||
const t = parser.nodeType(n.node) catch return false;
|
return parser.nodeType(n.node) == .comment;
|
||||||
return t == .comment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isText(n: Node) bool {
|
pub fn isText(n: Node) bool {
|
||||||
const t = parser.nodeType(n.node) catch return false;
|
return parser.nodeType(n.node) == .text;
|
||||||
return t == .text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text(n: Node) !?[]const u8 {
|
pub fn text(n: Node) ?[]const u8 {
|
||||||
const data = try parser.nodeTextContent(n.node);
|
const data = parser.nodeTextContent(n.node);
|
||||||
if (data == null) return null;
|
if (data == null) return null;
|
||||||
if (data.?.len == 0) return null;
|
if (data.?.len == 0) return null;
|
||||||
|
|
||||||
return std.mem.trim(u8, data.?, &std.ascii.whitespace);
|
return std.mem.trim(u8, data.?, &std.ascii.whitespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isEmptyText(n: Node) !bool {
|
pub fn isEmptyText(n: Node) bool {
|
||||||
const data = try parser.nodeTextContent(n.node);
|
const data = parser.nodeTextContent(n.node);
|
||||||
if (data == null) return true;
|
if (data == null) return true;
|
||||||
if (data.?.len == 0) return true;
|
if (data.?.len == 0) return true;
|
||||||
|
|
||||||
@@ -98,7 +94,7 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn tag(n: Node) ![]const u8 {
|
pub fn tag(n: Node) ![]const u8 {
|
||||||
return try parser.nodeName(n.node);
|
return parser.nodeName(n.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn attr(n: Node, key: []const u8) !?[]const u8 {
|
pub fn attr(n: Node, key: []const u8) !?[]const u8 {
|
||||||
|
|||||||
@@ -334,41 +334,39 @@ pub const Selector = union(enum) {
|
|||||||
if (!try v.second.match(n)) return false;
|
if (!try v.second.match(n)) return false;
|
||||||
|
|
||||||
// The first must match a ascendent.
|
// The first must match a ascendent.
|
||||||
var p = try n.parent();
|
var parent = n.parent();
|
||||||
while (p != null) {
|
while (parent) |p| {
|
||||||
if (try v.first.match(p.?)) {
|
if (try v.first.match(p)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
p = try p.?.parent();
|
parent = p.parent();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
.child => {
|
.child => {
|
||||||
const p = try n.parent();
|
const p = n.parent() orelse return false;
|
||||||
if (p == null) return false;
|
return try v.second.match(n) and try v.first.match(p);
|
||||||
|
|
||||||
return try v.second.match(n) and try v.first.match(p.?);
|
|
||||||
},
|
},
|
||||||
.next_sibling => {
|
.next_sibling => {
|
||||||
if (!try v.second.match(n)) return false;
|
if (!try v.second.match(n)) return false;
|
||||||
var c = try n.prevSibling();
|
var child = n.prevSibling();
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
if (c.?.isText() or c.?.isComment()) {
|
if (c.isText() or c.isComment()) {
|
||||||
c = try c.?.prevSibling();
|
child = c.prevSibling();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return try v.first.match(c.?);
|
return try v.first.match(c);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
.subsequent_sibling => {
|
.subsequent_sibling => {
|
||||||
if (!try v.second.match(n)) return false;
|
if (!try v.second.match(n)) return false;
|
||||||
|
|
||||||
var c = try n.prevSibling();
|
var child = n.prevSibling();
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
if (try v.first.match(c.?)) return true;
|
if (try v.first.match(c)) return true;
|
||||||
c = try c.?.prevSibling();
|
child = c.prevSibling();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
@@ -438,10 +436,10 @@ pub const Selector = union(enum) {
|
|||||||
// Only containsOwn is implemented.
|
// Only containsOwn is implemented.
|
||||||
if (v.own == false) return Error.UnsupportedContainsPseudoClass;
|
if (v.own == false) return Error.UnsupportedContainsPseudoClass;
|
||||||
|
|
||||||
var c = try n.firstChild();
|
var child = n.firstChild();
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
if (c.?.isText()) {
|
if (c.isText()) {
|
||||||
const text = try c.?.text();
|
const text = c.text();
|
||||||
if (text) |_text| {
|
if (text) |_text| {
|
||||||
if (contains(_text, v.val, false)) { // we are case sensitive. Is this correct behavior?
|
if (contains(_text, v.val, false)) { // we are case sensitive. Is this correct behavior?
|
||||||
return true;
|
return true;
|
||||||
@@ -449,7 +447,7 @@ pub const Selector = union(enum) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
@@ -477,16 +475,16 @@ pub const Selector = union(enum) {
|
|||||||
.empty => {
|
.empty => {
|
||||||
if (!n.isElement()) return false;
|
if (!n.isElement()) return false;
|
||||||
|
|
||||||
var c = try n.firstChild();
|
var child = n.firstChild();
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
if (c.?.isElement()) return false;
|
if (c.isElement()) return false;
|
||||||
|
|
||||||
if (c.?.isText()) {
|
if (c.isText()) {
|
||||||
if (try c.?.isEmptyText()) continue;
|
if (c.isEmptyText()) continue;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -494,7 +492,7 @@ pub const Selector = union(enum) {
|
|||||||
.root => {
|
.root => {
|
||||||
if (!n.isElement()) return false;
|
if (!n.isElement()) return false;
|
||||||
|
|
||||||
const p = try n.parent();
|
const p = n.parent();
|
||||||
return (p != null and p.?.isDocument());
|
return (p != null and p.?.isDocument());
|
||||||
},
|
},
|
||||||
.link => {
|
.link => {
|
||||||
@@ -609,24 +607,23 @@ pub const Selector = union(enum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn hasLegendInPreviousSiblings(n: anytype) anyerror!bool {
|
fn hasLegendInPreviousSiblings(n: anytype) anyerror!bool {
|
||||||
var c = try n.prevSibling();
|
var child = n.prevSibling();
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
const ctag = try c.?.tag();
|
const ctag = try c.tag();
|
||||||
if (std.ascii.eqlIgnoreCase("legend", ctag)) return true;
|
if (std.ascii.eqlIgnoreCase("legend", ctag)) return true;
|
||||||
c = try c.?.prevSibling();
|
child = c.prevSibling();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inDisabledFieldset(n: anytype) anyerror!bool {
|
fn inDisabledFieldset(n: anytype) anyerror!bool {
|
||||||
const p = try n.parent();
|
const p = n.parent() orelse return false;
|
||||||
if (p == null) return false;
|
|
||||||
|
|
||||||
const ntag = try n.tag();
|
const ntag = try n.tag();
|
||||||
const ptag = try p.?.tag();
|
const ptag = try p.tag();
|
||||||
|
|
||||||
if (std.ascii.eqlIgnoreCase("fieldset", ptag) and
|
if (std.ascii.eqlIgnoreCase("fieldset", ptag) and
|
||||||
try p.?.attr("disabled") != null and
|
try p.attr("disabled") != null and
|
||||||
(!std.ascii.eqlIgnoreCase("legend", ntag) or try hasLegendInPreviousSiblings(n)))
|
(!std.ascii.eqlIgnoreCase("legend", ntag) or try hasLegendInPreviousSiblings(n)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -642,7 +639,7 @@ pub const Selector = union(enum) {
|
|||||||
// ```
|
// ```
|
||||||
// https://github.com/andybalholm/cascadia/blob/master/pseudo_classes.go#L434
|
// https://github.com/andybalholm/cascadia/blob/master/pseudo_classes.go#L434
|
||||||
|
|
||||||
return try inDisabledFieldset(p.?);
|
return try inDisabledFieldset(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn langMatch(lang: []const u8, n: anytype) anyerror!bool {
|
fn langMatch(lang: []const u8, n: anytype) anyerror!bool {
|
||||||
@@ -656,10 +653,8 @@ pub const Selector = union(enum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the tag doesn't match, try the parent.
|
// if the tag doesn't match, try the parent.
|
||||||
const p = try n.parent();
|
const p = n.parent() orelse return false;
|
||||||
if (p == null) return false;
|
return langMatch(lang, p);
|
||||||
|
|
||||||
return langMatch(lang, p.?);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// onlyChildMatch implements :only-child
|
// onlyChildMatch implements :only-child
|
||||||
@@ -667,25 +662,24 @@ pub const Selector = union(enum) {
|
|||||||
fn onlyChildMatch(of_type: bool, n: anytype) anyerror!bool {
|
fn onlyChildMatch(of_type: bool, n: anytype) anyerror!bool {
|
||||||
if (!n.isElement()) return false;
|
if (!n.isElement()) return false;
|
||||||
|
|
||||||
const p = try n.parent();
|
const p = n.parent() orelse return false;
|
||||||
if (p == null) return false;
|
|
||||||
|
|
||||||
const ntag = try n.tag();
|
const ntag = try n.tag();
|
||||||
|
|
||||||
var count: usize = 0;
|
var count: usize = 0;
|
||||||
var c = try p.?.firstChild();
|
var child = p.firstChild();
|
||||||
// loop hover all n siblings.
|
// loop hover all n siblings.
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
// ignore non elements or others tags if of-type is true.
|
// ignore non elements or others tags if of-type is true.
|
||||||
if (!c.?.isElement() or (of_type and !std.mem.eql(u8, ntag, try c.?.tag()))) {
|
if (!c.isElement() or (of_type and !std.mem.eql(u8, ntag, try c.tag()))) {
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
if (count > 1) return false;
|
if (count > 1) return false;
|
||||||
|
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
}
|
}
|
||||||
|
|
||||||
return count == 1;
|
return count == 1;
|
||||||
@@ -696,27 +690,25 @@ pub const Selector = union(enum) {
|
|||||||
fn simpleNthLastChildMatch(b: isize, of_type: bool, n: anytype) anyerror!bool {
|
fn simpleNthLastChildMatch(b: isize, of_type: bool, n: anytype) anyerror!bool {
|
||||||
if (!n.isElement()) return false;
|
if (!n.isElement()) return false;
|
||||||
|
|
||||||
const p = try n.parent();
|
const p = n.parent() orelse return false;
|
||||||
if (p == null) return false;
|
|
||||||
|
|
||||||
const ntag = try n.tag();
|
const ntag = try n.tag();
|
||||||
|
|
||||||
var count: isize = 0;
|
var count: isize = 0;
|
||||||
var c = try p.?.lastChild();
|
var child = p.lastChild();
|
||||||
// loop hover all n siblings.
|
// loop hover all n siblings.
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
// ignore non elements or others tags if of-type is true.
|
// ignore non elements or others tags if of-type is true.
|
||||||
if (!c.?.isElement() or (of_type and !std.mem.eql(u8, ntag, try c.?.tag()))) {
|
if (!c.isElement() or (of_type and !std.mem.eql(u8, ntag, try c.tag()))) {
|
||||||
c = try c.?.prevSibling();
|
child = c.prevSibling();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
||||||
if (n.eql(c.?)) return count == b;
|
if (n.eql(c)) return count == b;
|
||||||
if (count >= b) return false;
|
if (count >= b) return false;
|
||||||
|
|
||||||
c = try c.?.prevSibling();
|
child = c.prevSibling();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -727,27 +719,25 @@ pub const Selector = union(enum) {
|
|||||||
fn simpleNthChildMatch(b: isize, of_type: bool, n: anytype) anyerror!bool {
|
fn simpleNthChildMatch(b: isize, of_type: bool, n: anytype) anyerror!bool {
|
||||||
if (!n.isElement()) return false;
|
if (!n.isElement()) return false;
|
||||||
|
|
||||||
const p = try n.parent();
|
const p = n.parent() orelse return false;
|
||||||
if (p == null) return false;
|
|
||||||
|
|
||||||
const ntag = try n.tag();
|
const ntag = try n.tag();
|
||||||
|
|
||||||
var count: isize = 0;
|
var count: isize = 0;
|
||||||
var c = try p.?.firstChild();
|
var child = p.firstChild();
|
||||||
// loop hover all n siblings.
|
// loop hover all n siblings.
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
// ignore non elements or others tags if of-type is true.
|
// ignore non elements or others tags if of-type is true.
|
||||||
if (!c.?.isElement() or (of_type and !std.mem.eql(u8, ntag, try c.?.tag()))) {
|
if (!c.isElement() or (of_type and !std.mem.eql(u8, ntag, try c.tag()))) {
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
||||||
if (n.eql(c.?)) return count == b;
|
if (n.eql(c)) return count == b;
|
||||||
if (count >= b) return false;
|
if (count >= b) return false;
|
||||||
|
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -759,29 +749,27 @@ pub const Selector = union(enum) {
|
|||||||
fn nthChildMatch(a: isize, b: isize, last: bool, of_type: bool, n: anytype) anyerror!bool {
|
fn nthChildMatch(a: isize, b: isize, last: bool, of_type: bool, n: anytype) anyerror!bool {
|
||||||
if (!n.isElement()) return false;
|
if (!n.isElement()) return false;
|
||||||
|
|
||||||
const p = try n.parent();
|
const p = n.parent() orelse return false;
|
||||||
if (p == null) return false;
|
|
||||||
|
|
||||||
const ntag = try n.tag();
|
const ntag = try n.tag();
|
||||||
|
|
||||||
var i: isize = -1;
|
var i: isize = -1;
|
||||||
var count: isize = 0;
|
var count: isize = 0;
|
||||||
var c = try p.?.firstChild();
|
var child = p.firstChild();
|
||||||
// loop hover all n siblings.
|
// loop hover all n siblings.
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
// ignore non elements or others tags if of-type is true.
|
// ignore non elements or others tags if of-type is true.
|
||||||
if (!c.?.isElement() or (of_type and !std.mem.eql(u8, ntag, try c.?.tag()))) {
|
if (!c.isElement() or (of_type and !std.mem.eql(u8, ntag, try c.tag()))) {
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
||||||
if (n.eql(c.?)) {
|
if (n.eql(c)) {
|
||||||
i = count;
|
i = count;
|
||||||
if (!last) break;
|
if (!last) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == -1) return false;
|
if (i == -1) return false;
|
||||||
@@ -794,21 +782,21 @@ pub const Selector = union(enum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn hasDescendantMatch(s: *const Selector, n: anytype) anyerror!bool {
|
fn hasDescendantMatch(s: *const Selector, n: anytype) anyerror!bool {
|
||||||
var c = try n.firstChild();
|
var child = n.firstChild();
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
if (try s.match(c.?)) return true;
|
if (try s.match(c)) return true;
|
||||||
if (c.?.isElement() and try hasDescendantMatch(s, c.?)) return true;
|
if (c.isElement() and try hasDescendantMatch(s, c)) return true;
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hasChildMatch(s: *const Selector, n: anytype) anyerror!bool {
|
fn hasChildMatch(s: *const Selector, n: anytype) anyerror!bool {
|
||||||
var c = try n.firstChild();
|
var child = n.firstChild();
|
||||||
while (c != null) {
|
while (child) |c| {
|
||||||
if (try s.match(c.?)) return true;
|
if (try s.match(c)) return true;
|
||||||
c = try c.?.nextSibling();
|
child = c.nextSibling();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -859,23 +847,23 @@ pub const NodeTest = struct {
|
|||||||
name: []const u8 = "",
|
name: []const u8 = "",
|
||||||
att: ?[]const u8 = null,
|
att: ?[]const u8 = null,
|
||||||
|
|
||||||
pub fn firstChild(n: *const NodeTest) !?*const NodeTest {
|
pub fn firstChild(n: *const NodeTest) ?*const NodeTest {
|
||||||
return n.child;
|
return n.child;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lastChild(n: *const NodeTest) !?*const NodeTest {
|
pub fn lastChild(n: *const NodeTest) ?*const NodeTest {
|
||||||
return n.last;
|
return n.last;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nextSibling(n: *const NodeTest) !?*const NodeTest {
|
pub fn nextSibling(n: *const NodeTest) ?*const NodeTest {
|
||||||
return n.sibling;
|
return n.sibling;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prevSibling(n: *const NodeTest) !?*const NodeTest {
|
pub fn prevSibling(n: *const NodeTest) ?*const NodeTest {
|
||||||
return n.prev;
|
return n.prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parent(n: *const NodeTest) !?*const NodeTest {
|
pub fn parent(n: *const NodeTest) ?*const NodeTest {
|
||||||
return n.par;
|
return n.par;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -891,7 +879,7 @@ pub const NodeTest = struct {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text(_: *const NodeTest) !?[]const u8 {
|
pub fn text(_: *const NodeTest) ?[]const u8 {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -899,7 +887,7 @@ pub const NodeTest = struct {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isEmptyText(_: *const NodeTest) !bool {
|
pub fn isEmptyText(_: *const NodeTest) bool {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const CSSRule = @import("CSSRule.zig");
|
const CSSRule = @import("CSSRule.zig");
|
||||||
const StyleSheet = @import("StyleSheet.zig").StyleSheet;
|
|
||||||
|
|
||||||
const CSSImportRule = CSSRule.CSSImportRule;
|
const CSSImportRule = CSSRule.CSSImportRule;
|
||||||
|
|
||||||
|
|||||||
@@ -25,24 +25,24 @@ pub const Attr = struct {
|
|||||||
pub const prototype = *Node;
|
pub const prototype = *Node;
|
||||||
pub const subtype = .node;
|
pub const subtype = .node;
|
||||||
|
|
||||||
pub fn get_namespaceURI(self: *parser.Attribute) !?[]const u8 {
|
pub fn get_namespaceURI(self: *parser.Attribute) ?[]const u8 {
|
||||||
return try parser.nodeGetNamespace(parser.attributeToNode(self));
|
return parser.nodeGetNamespace(parser.attributeToNode(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_prefix(self: *parser.Attribute) !?[]const u8 {
|
pub fn get_prefix(self: *parser.Attribute) ?[]const u8 {
|
||||||
return try parser.nodeGetPrefix(parser.attributeToNode(self));
|
return parser.nodeGetPrefix(parser.attributeToNode(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_localName(self: *parser.Attribute) ![]const u8 {
|
pub fn get_localName(self: *parser.Attribute) ![]const u8 {
|
||||||
return try parser.nodeLocalName(parser.attributeToNode(self));
|
return parser.nodeLocalName(parser.attributeToNode(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_name(self: *parser.Attribute) ![]const u8 {
|
pub fn get_name(self: *parser.Attribute) ![]const u8 {
|
||||||
return try parser.attributeGetName(self);
|
return parser.attributeGetName(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_value(self: *parser.Attribute) !?[]const u8 {
|
pub fn get_value(self: *parser.Attribute) !?[]const u8 {
|
||||||
return try parser.attributeGetValue(self);
|
return parser.attributeGetValue(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_value(self: *parser.Attribute, v: []const u8) !?[]const u8 {
|
pub fn set_value(self: *parser.Attribute, v: []const u8) !?[]const u8 {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ pub const CharacterData = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_nextElementSibling(self: *parser.CharacterData) !?ElementUnion {
|
pub fn get_nextElementSibling(self: *parser.CharacterData) !?ElementUnion {
|
||||||
const res = try parser.nodeNextElementSibling(parser.characterDataToNode(self));
|
const res = parser.nodeNextElementSibling(parser.characterDataToNode(self));
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ pub const CharacterData = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_previousElementSibling(self: *parser.CharacterData) !?ElementUnion {
|
pub fn get_previousElementSibling(self: *parser.CharacterData) !?ElementUnion {
|
||||||
const res = try parser.nodePreviousElementSibling(parser.characterDataToNode(self));
|
const res = parser.nodePreviousElementSibling(parser.characterDataToNode(self));
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -68,8 +68,8 @@ pub const CharacterData = struct {
|
|||||||
|
|
||||||
// Read/Write attributes
|
// Read/Write attributes
|
||||||
|
|
||||||
pub fn get_data(self: *parser.CharacterData) ![]const u8 {
|
pub fn get_data(self: *parser.CharacterData) []const u8 {
|
||||||
return try parser.characterDataData(self);
|
return parser.characterDataData(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_data(self: *parser.CharacterData, data: []const u8) !void {
|
pub fn set_data(self: *parser.CharacterData, data: []const u8) !void {
|
||||||
@@ -96,18 +96,18 @@ pub const CharacterData = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn _substringData(self: *parser.CharacterData, offset: u32, count: u32) ![]const u8 {
|
pub fn _substringData(self: *parser.CharacterData, offset: u32, count: u32) ![]const u8 {
|
||||||
return try parser.characterDataSubstringData(self, offset, count);
|
return parser.characterDataSubstringData(self, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// netsurf's CharacterData (text, comment) doesn't implement the
|
// netsurf's CharacterData (text, comment) doesn't implement the
|
||||||
// dom_node_get_attributes and thus will crash if we try to call nodeIsEqualNode.
|
// dom_node_get_attributes and thus will crash if we try to call nodeIsEqualNode.
|
||||||
pub fn _isEqualNode(self: *parser.CharacterData, other_node: *parser.Node) !bool {
|
pub fn _isEqualNode(self: *parser.CharacterData, other_node: *parser.Node) bool {
|
||||||
if (try parser.nodeType(@ptrCast(@alignCast(self))) != try parser.nodeType(other_node)) {
|
if (parser.nodeType(@ptrCast(@alignCast(self))) != parser.nodeType(other_node)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const other: *parser.CharacterData = @ptrCast(other_node);
|
const other: *parser.CharacterData = @ptrCast(other_node);
|
||||||
if (std.mem.eql(u8, try get_data(self), try get_data(other)) == false) {
|
if (std.mem.eql(u8, get_data(self), get_data(other)) == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const log = @import("../../log.zig");
|
|
||||||
const parser = @import("../netsurf.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
const Page = @import("../page.zig").Page;
|
const Page = @import("../page.zig").Page;
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ pub const DocumentFragment = struct {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _isEqualNode(self: *parser.DocumentFragment, other_node: *parser.Node) !bool {
|
pub fn _isEqualNode(self: *parser.DocumentFragment, other_node: *parser.Node) bool {
|
||||||
const other_type = try parser.nodeType(other_node);
|
const other_type = parser.nodeType(other_node);
|
||||||
if (other_type != .document_fragment) {
|
if (other_type != .document_fragment) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,21 +29,21 @@ pub const DocumentType = struct {
|
|||||||
pub const subtype = .node;
|
pub const subtype = .node;
|
||||||
|
|
||||||
pub fn get_name(self: *parser.DocumentType) ![]const u8 {
|
pub fn get_name(self: *parser.DocumentType) ![]const u8 {
|
||||||
return try parser.documentTypeGetName(self);
|
return parser.documentTypeGetName(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_publicId(self: *parser.DocumentType) ![]const u8 {
|
pub fn get_publicId(self: *parser.DocumentType) []const u8 {
|
||||||
return try parser.documentTypeGetPublicId(self);
|
return parser.documentTypeGetPublicId(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_systemId(self: *parser.DocumentType) ![]const u8 {
|
pub fn get_systemId(self: *parser.DocumentType) []const u8 {
|
||||||
return try parser.documentTypeGetSystemId(self);
|
return parser.documentTypeGetSystemId(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
// netsurf's DocumentType doesn't implement the dom_node_get_attributes
|
// netsurf's DocumentType doesn't implement the dom_node_get_attributes
|
||||||
// and thus will crash if we try to call nodeIsEqualNode.
|
// and thus will crash if we try to call nodeIsEqualNode.
|
||||||
pub fn _isEqualNode(self: *parser.DocumentType, other_node: *parser.Node) !bool {
|
pub fn _isEqualNode(self: *parser.DocumentType, other_node: *parser.Node) !bool {
|
||||||
if (try parser.nodeType(other_node) != .document_type) {
|
if (parser.nodeType(other_node) != .document_type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,10 +51,10 @@ pub const DocumentType = struct {
|
|||||||
if (std.mem.eql(u8, try get_name(self), try get_name(other)) == false) {
|
if (std.mem.eql(u8, try get_name(self), try get_name(other)) == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (std.mem.eql(u8, try get_publicId(self), try get_publicId(other)) == false) {
|
if (std.mem.eql(u8, get_publicId(self), get_publicId(other)) == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (std.mem.eql(u8, try get_systemId(self), try get_systemId(other)) == false) {
|
if (std.mem.eql(u8, get_systemId(self), get_systemId(other)) == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ pub const Element = struct {
|
|||||||
pub fn toInterfaceT(comptime T: type, e: *parser.Element) !T {
|
pub fn toInterfaceT(comptime T: type, e: *parser.Element) !T {
|
||||||
const tagname = try parser.elementGetTagName(e) orelse {
|
const tagname = try parser.elementGetTagName(e) orelse {
|
||||||
// If the owner's document is HTML, assume we have an HTMLElement.
|
// If the owner's document is HTML, assume we have an HTMLElement.
|
||||||
const doc = try parser.nodeOwnerDocument(parser.elementToNode(e));
|
const doc = parser.nodeOwnerDocument(parser.elementToNode(e));
|
||||||
if (doc != null and !doc.?.is_html) {
|
if (doc != null and !doc.?.is_html) {
|
||||||
return .{ .HTMLElement = @as(*parser.ElementHTML, @ptrCast(e)) };
|
return .{ .HTMLElement = @as(*parser.ElementHTML, @ptrCast(e)) };
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ pub const Element = struct {
|
|||||||
|
|
||||||
const tag = parser.Tag.fromString(tagname) catch {
|
const tag = parser.Tag.fromString(tagname) catch {
|
||||||
// If the owner's document is HTML, assume we have an HTMLElement.
|
// If the owner's document is HTML, assume we have an HTMLElement.
|
||||||
const doc = try parser.nodeOwnerDocument(parser.elementToNode(e));
|
const doc = parser.nodeOwnerDocument(parser.elementToNode(e));
|
||||||
if (doc != null and doc.?.is_html) {
|
if (doc != null and doc.?.is_html) {
|
||||||
return .{ .HTMLElement = @as(*parser.ElementHTML, @ptrCast(e)) };
|
return .{ .HTMLElement = @as(*parser.ElementHTML, @ptrCast(e)) };
|
||||||
}
|
}
|
||||||
@@ -87,12 +87,12 @@ pub const Element = struct {
|
|||||||
// JS funcs
|
// JS funcs
|
||||||
// --------
|
// --------
|
||||||
|
|
||||||
pub fn get_namespaceURI(self: *parser.Element) !?[]const u8 {
|
pub fn get_namespaceURI(self: *parser.Element) ?[]const u8 {
|
||||||
return try parser.nodeGetNamespace(parser.elementToNode(self));
|
return parser.nodeGetNamespace(parser.elementToNode(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_prefix(self: *parser.Element) !?[]const u8 {
|
pub fn get_prefix(self: *parser.Element) ?[]const u8 {
|
||||||
return try parser.nodeGetPrefix(parser.elementToNode(self));
|
return parser.nodeGetPrefix(parser.elementToNode(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_localName(self: *parser.Element) ![]const u8 {
|
pub fn get_localName(self: *parser.Element) ![]const u8 {
|
||||||
@@ -150,7 +150,7 @@ pub const Element = struct {
|
|||||||
|
|
||||||
pub fn set_innerHTML(self: *parser.Element, str: []const u8, page: *Page) !void {
|
pub fn set_innerHTML(self: *parser.Element, str: []const u8, page: *Page) !void {
|
||||||
const node = parser.elementToNode(self);
|
const node = parser.elementToNode(self);
|
||||||
const doc = try parser.nodeOwnerDocument(node) orelse return parser.DOMError.WrongDocument;
|
const doc = parser.nodeOwnerDocument(node) orelse return parser.DOMError.WrongDocument;
|
||||||
// parse the fragment
|
// parse the fragment
|
||||||
const fragment = try parser.documentParseFragmentFromStr(doc, str);
|
const fragment = try parser.documentParseFragmentFromStr(doc, str);
|
||||||
|
|
||||||
@@ -168,9 +168,9 @@ pub const Element = struct {
|
|||||||
// or an actual document. In a blank page, something like:
|
// or an actual document. In a blank page, something like:
|
||||||
// x.innerHTML = '<script></script>';
|
// x.innerHTML = '<script></script>';
|
||||||
// does _not_ create an empty script, but in a real page, it does. Weird.
|
// does _not_ create an empty script, but in a real page, it does. Weird.
|
||||||
const html = try parser.nodeFirstChild(fragment_node) orelse return;
|
const html = parser.nodeFirstChild(fragment_node) orelse return;
|
||||||
const head = try parser.nodeFirstChild(html) orelse return;
|
const head = parser.nodeFirstChild(html) orelse return;
|
||||||
const body = try parser.nodeNextSibling(head) orelse return;
|
const body = parser.nodeNextSibling(head) orelse return;
|
||||||
|
|
||||||
if (try parser.elementTag(self) == .template) {
|
if (try parser.elementTag(self) == .template) {
|
||||||
// HTMLElementTemplate is special. We don't append these as children
|
// HTMLElementTemplate is special. We don't append these as children
|
||||||
@@ -179,11 +179,11 @@ pub const Element = struct {
|
|||||||
// a new fragment
|
// a new fragment
|
||||||
const clean = try parser.documentCreateDocumentFragment(doc);
|
const clean = try parser.documentCreateDocumentFragment(doc);
|
||||||
const children = try parser.nodeGetChildNodes(body);
|
const children = try parser.nodeGetChildNodes(body);
|
||||||
const ln = try parser.nodeListLength(children);
|
const ln = parser.nodeListLength(children);
|
||||||
for (0..ln) |_| {
|
for (0..ln) |_| {
|
||||||
// always index 0, because nodeAppendChild moves the node out of
|
// always index 0, because nodeAppendChild moves the node out of
|
||||||
// the nodeList and into the new tree
|
// the nodeList and into the new tree
|
||||||
const child = try parser.nodeListItem(children, 0) orelse continue;
|
const child = parser.nodeListItem(children, 0) orelse continue;
|
||||||
_ = try parser.nodeAppendChild(@ptrCast(@alignCast(clean)), child);
|
_ = try parser.nodeAppendChild(@ptrCast(@alignCast(clean)), child);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,22 +197,22 @@ pub const Element = struct {
|
|||||||
{
|
{
|
||||||
// First, copy some of the head element
|
// First, copy some of the head element
|
||||||
const children = try parser.nodeGetChildNodes(head);
|
const children = try parser.nodeGetChildNodes(head);
|
||||||
const ln = try parser.nodeListLength(children);
|
const ln = parser.nodeListLength(children);
|
||||||
for (0..ln) |_| {
|
for (0..ln) |_| {
|
||||||
// always index 0, because nodeAppendChild moves the node out of
|
// always index 0, because nodeAppendChild moves the node out of
|
||||||
// the nodeList and into the new tree
|
// the nodeList and into the new tree
|
||||||
const child = try parser.nodeListItem(children, 0) orelse continue;
|
const child = parser.nodeListItem(children, 0) orelse continue;
|
||||||
_ = try parser.nodeAppendChild(node, child);
|
_ = try parser.nodeAppendChild(node, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const children = try parser.nodeGetChildNodes(body);
|
const children = try parser.nodeGetChildNodes(body);
|
||||||
const ln = try parser.nodeListLength(children);
|
const ln = parser.nodeListLength(children);
|
||||||
for (0..ln) |_| {
|
for (0..ln) |_| {
|
||||||
// always index 0, because nodeAppendChild moves the node out of
|
// always index 0, because nodeAppendChild moves the node out of
|
||||||
// the nodeList and into the new tree
|
// the nodeList and into the new tree
|
||||||
const child = try parser.nodeListItem(children, 0) orelse continue;
|
const child = parser.nodeListItem(children, 0) orelse continue;
|
||||||
_ = try parser.nodeAppendChild(node, child);
|
_ = try parser.nodeAppendChild(node, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ pub const Element = struct {
|
|||||||
}
|
}
|
||||||
return parser.nodeToElement(current.node);
|
return parser.nodeToElement(current.node);
|
||||||
}
|
}
|
||||||
current = try current.parent() orelse return null;
|
current = current.parent() orelse return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,13 +407,13 @@ pub const Element = struct {
|
|||||||
// NonDocumentTypeChildNode
|
// NonDocumentTypeChildNode
|
||||||
// https://dom.spec.whatwg.org/#interface-nondocumenttypechildnode
|
// https://dom.spec.whatwg.org/#interface-nondocumenttypechildnode
|
||||||
pub fn get_previousElementSibling(self: *parser.Element) !?Union {
|
pub fn get_previousElementSibling(self: *parser.Element) !?Union {
|
||||||
const res = try parser.nodePreviousElementSibling(parser.elementToNode(self));
|
const res = parser.nodePreviousElementSibling(parser.elementToNode(self));
|
||||||
if (res == null) return null;
|
if (res == null) return null;
|
||||||
return try toInterface(res.?);
|
return try toInterface(res.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_nextElementSibling(self: *parser.Element) !?Union {
|
pub fn get_nextElementSibling(self: *parser.Element) !?Union {
|
||||||
const res = try parser.nodeNextElementSibling(parser.elementToNode(self));
|
const res = parser.nodeNextElementSibling(parser.elementToNode(self));
|
||||||
if (res == null) return null;
|
if (res == null) return null;
|
||||||
return try toInterface(res.?);
|
return try toInterface(res.?);
|
||||||
}
|
}
|
||||||
@@ -426,7 +426,7 @@ pub const Element = struct {
|
|||||||
while (true) {
|
while (true) {
|
||||||
next = try walker.get_next(root, next) orelse return null;
|
next = try walker.get_next(root, next) orelse return null;
|
||||||
// ignore non-element nodes.
|
// ignore non-element nodes.
|
||||||
if (try parser.nodeType(next.?) != .element) {
|
if (parser.nodeType(next.?) != .element) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const e = parser.nodeToElement(next.?);
|
const e = parser.nodeToElement(next.?);
|
||||||
@@ -474,7 +474,7 @@ pub const Element = struct {
|
|||||||
// Returns a 0 DOMRect object if the element is eventually detached from the main window
|
// Returns a 0 DOMRect object if the element is eventually detached from the main window
|
||||||
pub fn _getBoundingClientRect(self: *parser.Element, page: *Page) !DOMRect {
|
pub fn _getBoundingClientRect(self: *parser.Element, page: *Page) !DOMRect {
|
||||||
// Since we are lazy rendering we need to do this check. We could store the renderer in a viewport such that it could cache these, but it would require tracking changes.
|
// Since we are lazy rendering we need to do this check. We could store the renderer in a viewport such that it could cache these, but it would require tracking changes.
|
||||||
if (!try page.isNodeAttached(parser.elementToNode(self))) {
|
if (!page.isNodeAttached(parser.elementToNode(self))) {
|
||||||
return DOMRect{
|
return DOMRect{
|
||||||
.x = 0,
|
.x = 0,
|
||||||
.y = 0,
|
.y = 0,
|
||||||
@@ -493,7 +493,7 @@ pub const Element = struct {
|
|||||||
// We do not render so it only always return the element's bounding rect.
|
// We do not render so it only always return the element's bounding rect.
|
||||||
// Returns an empty array if the element is eventually detached from the main window
|
// Returns an empty array if the element is eventually detached from the main window
|
||||||
pub fn _getClientRects(self: *parser.Element, page: *Page) ![]DOMRect {
|
pub fn _getClientRects(self: *parser.Element, page: *Page) ![]DOMRect {
|
||||||
if (!try page.isNodeAttached(parser.elementToNode(self))) {
|
if (!page.isNodeAttached(parser.elementToNode(self))) {
|
||||||
return &.{};
|
return &.{};
|
||||||
}
|
}
|
||||||
const heap_ptr = try page.call_arena.create(DOMRect);
|
const heap_ptr = try page.call_arena.create(DOMRect);
|
||||||
@@ -549,7 +549,7 @@ pub const Element = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Not sure what to do if there is no owner document
|
// Not sure what to do if there is no owner document
|
||||||
const doc = try parser.nodeOwnerDocument(@ptrCast(self)) orelse return error.InvalidArgument;
|
const doc = parser.nodeOwnerDocument(@ptrCast(self)) orelse return error.InvalidArgument;
|
||||||
const fragment = try parser.documentCreateDocumentFragment(doc);
|
const fragment = try parser.documentCreateDocumentFragment(doc);
|
||||||
const sr = try page.arena.create(ShadowRoot);
|
const sr = try page.arena.create(ShadowRoot);
|
||||||
sr.* = .{
|
sr.* = .{
|
||||||
@@ -595,7 +595,7 @@ pub const Element = struct {
|
|||||||
// for related elements JIT by walking the tree, but there could be
|
// for related elements JIT by walking the tree, but there could be
|
||||||
// cases in libdom or the Zig WebAPI where this reference is kept
|
// cases in libdom or the Zig WebAPI where this reference is kept
|
||||||
const as_node: *parser.Node = @ptrCast(self);
|
const as_node: *parser.Node = @ptrCast(self);
|
||||||
const parent = try parser.nodeParentNode(as_node) orelse return;
|
const parent = parser.nodeParentNode(as_node) orelse return;
|
||||||
_ = try Node._removeChild(parent, as_node);
|
_ = try Node._removeChild(parent, as_node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Env = @import("../env.zig").Env;
|
|
||||||
const parser = @import("../netsurf.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
const Page = @import("../page.zig").Page;
|
const Page = @import("../page.zig").Page;
|
||||||
|
|
||||||
@@ -48,7 +47,7 @@ pub const EventTarget = struct {
|
|||||||
pub fn toInterface(et: *parser.EventTarget, page: *Page) !Union {
|
pub fn toInterface(et: *parser.EventTarget, page: *Page) !Union {
|
||||||
// libdom assumes that all event targets are libdom nodes. They are not.
|
// libdom assumes that all event targets are libdom nodes. They are not.
|
||||||
|
|
||||||
switch (try parser.eventTargetInternalType(et)) {
|
switch (parser.eventTargetInternalType(et)) {
|
||||||
.libdom_node => {
|
.libdom_node => {
|
||||||
return .{ .node = try nod.Node.toInterface(@as(*parser.Node, @ptrCast(et))) };
|
return .{ .node = try nod.Node.toInterface(@as(*parser.Node, @ptrCast(et))) };
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ pub const HTMLCollection = struct {
|
|||||||
var node = try self.start() orelse return 0;
|
var node = try self.start() orelse return 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (try parser.nodeType(node) == .element) {
|
if (parser.nodeType(node) == .element) {
|
||||||
if (try self.matcher.match(node)) {
|
if (try self.matcher.match(node)) {
|
||||||
len += 1;
|
len += 1;
|
||||||
}
|
}
|
||||||
@@ -371,7 +371,7 @@ pub const HTMLCollection = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (try parser.nodeType(node) == .element) {
|
if (parser.nodeType(node) == .element) {
|
||||||
if (try self.matcher.match(node)) {
|
if (try self.matcher.match(node)) {
|
||||||
// check if we found the searched element.
|
// check if we found the searched element.
|
||||||
if (i == index) {
|
if (i == index) {
|
||||||
@@ -405,7 +405,7 @@ pub const HTMLCollection = struct {
|
|||||||
var node = try self.start() orelse return null;
|
var node = try self.start() orelse return null;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (try parser.nodeType(node) == .element) {
|
if (parser.nodeType(node) == .element) {
|
||||||
if (try self.matcher.match(node)) {
|
if (try self.matcher.match(node)) {
|
||||||
const elem = @as(*parser.Element, @ptrCast(node));
|
const elem = @as(*parser.Element, @ptrCast(node));
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ pub const IntersectionObserverEntry = struct {
|
|||||||
return self.page.renderer.boundingRect();
|
return self.page.renderer.boundingRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
const root_type = try parser.nodeType(root);
|
const root_type = parser.nodeType(root);
|
||||||
|
|
||||||
var element: *parser.Element = undefined;
|
var element: *parser.Element = undefined;
|
||||||
switch (root_type) {
|
switch (root_type) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
|
||||||
|
|
||||||
const log = @import("../../log.zig");
|
const log = @import("../../log.zig");
|
||||||
const parser = @import("../netsurf.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
@@ -284,7 +283,7 @@ const Observer = struct {
|
|||||||
|
|
||||||
const mutation_event = parser.eventToMutationEvent(event);
|
const mutation_event = parser.eventToMutationEvent(event);
|
||||||
const event_type = blk: {
|
const event_type = blk: {
|
||||||
const t = try parser.eventType(event);
|
const t = parser.eventType(event);
|
||||||
break :blk std.meta.stringToEnum(MutationEventType, t) orelse return;
|
break :blk std.meta.stringToEnum(MutationEventType, t) orelse return;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -302,12 +301,12 @@ const Observer = struct {
|
|||||||
.DOMAttrModified => {
|
.DOMAttrModified => {
|
||||||
record.attribute_name = parser.mutationEventAttributeName(mutation_event) catch null;
|
record.attribute_name = parser.mutationEventAttributeName(mutation_event) catch null;
|
||||||
if (self.options.attributeOldValue) {
|
if (self.options.attributeOldValue) {
|
||||||
record.old_value = parser.mutationEventPrevValue(mutation_event) catch null;
|
record.old_value = parser.mutationEventPrevValue(mutation_event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.DOMCharacterDataModified => {
|
.DOMCharacterDataModified => {
|
||||||
if (self.options.characterDataOldValue) {
|
if (self.options.characterDataOldValue) {
|
||||||
record.old_value = parser.mutationEventPrevValue(mutation_event) catch null;
|
record.old_value = parser.mutationEventPrevValue(mutation_event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.DOMNodeInserted => {
|
.DOMNodeInserted => {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ pub const Node = struct {
|
|||||||
pub const subtype = .node;
|
pub const subtype = .node;
|
||||||
|
|
||||||
pub fn toInterface(node: *parser.Node) !Union {
|
pub fn toInterface(node: *parser.Node) !Union {
|
||||||
return switch (try parser.nodeType(node)) {
|
return switch (parser.nodeType(node)) {
|
||||||
.element => try Element.toInterfaceT(
|
.element => try Element.toInterfaceT(
|
||||||
Union,
|
Union,
|
||||||
@as(*parser.Element, @ptrCast(node)),
|
@as(*parser.Element, @ptrCast(node)),
|
||||||
@@ -124,7 +124,7 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_firstChild(self: *parser.Node) !?Union {
|
pub fn get_firstChild(self: *parser.Node) !?Union {
|
||||||
const res = try parser.nodeFirstChild(self);
|
const res = parser.nodeFirstChild(self);
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_lastChild(self: *parser.Node) !?Union {
|
pub fn get_lastChild(self: *parser.Node) !?Union {
|
||||||
const res = try parser.nodeLastChild(self);
|
const res = parser.nodeLastChild(self);
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_nextSibling(self: *parser.Node) !?Union {
|
pub fn get_nextSibling(self: *parser.Node) !?Union {
|
||||||
const res = try parser.nodeNextSibling(self);
|
const res = parser.nodeNextSibling(self);
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_previousSibling(self: *parser.Node) !?Union {
|
pub fn get_previousSibling(self: *parser.Node) !?Union {
|
||||||
const res = try parser.nodePreviousSibling(self);
|
const res = parser.nodePreviousSibling(self);
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -156,7 +156,7 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_parentNode(self: *parser.Node) !?Union {
|
pub fn get_parentNode(self: *parser.Node) !?Union {
|
||||||
const res = try parser.nodeParentNode(self);
|
const res = parser.nodeParentNode(self);
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_parentElement(self: *parser.Node) !?ElementUnion {
|
pub fn get_parentElement(self: *parser.Node) !?ElementUnion {
|
||||||
const res = try parser.nodeParentElement(self);
|
const res = parser.nodeParentElement(self);
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -176,11 +176,11 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_nodeType(self: *parser.Node) !u8 {
|
pub fn get_nodeType(self: *parser.Node) !u8 {
|
||||||
return @intFromEnum(try parser.nodeType(self));
|
return @intFromEnum(parser.nodeType(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_ownerDocument(self: *parser.Node) !?*parser.DocumentHTML {
|
pub fn get_ownerDocument(self: *parser.Node) !?*parser.DocumentHTML {
|
||||||
const res = try parser.nodeOwnerDocument(self);
|
const res = parser.nodeOwnerDocument(self);
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -190,12 +190,12 @@ pub const Node = struct {
|
|||||||
pub fn get_isConnected(self: *parser.Node) !bool {
|
pub fn get_isConnected(self: *parser.Node) !bool {
|
||||||
var node = self;
|
var node = self;
|
||||||
while (true) {
|
while (true) {
|
||||||
const node_type = try parser.nodeType(node);
|
const node_type = parser.nodeType(node);
|
||||||
if (node_type == .document) {
|
if (node_type == .document) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (try parser.nodeParentNode(node)) |parent| {
|
if (parser.nodeParentNode(node)) |parent| {
|
||||||
// didn't find a document, but node has a parent, let's see
|
// didn't find a document, but node has a parent, let's see
|
||||||
// if it's connected;
|
// if it's connected;
|
||||||
node = parent;
|
node = parent;
|
||||||
@@ -222,15 +222,15 @@ pub const Node = struct {
|
|||||||
// Read/Write attributes
|
// Read/Write attributes
|
||||||
|
|
||||||
pub fn get_nodeValue(self: *parser.Node) !?[]const u8 {
|
pub fn get_nodeValue(self: *parser.Node) !?[]const u8 {
|
||||||
return try parser.nodeValue(self);
|
return parser.nodeValue(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_nodeValue(self: *parser.Node, data: []u8) !void {
|
pub fn set_nodeValue(self: *parser.Node, data: []u8) !void {
|
||||||
try parser.nodeSetValue(self, data);
|
try parser.nodeSetValue(self, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_textContent(self: *parser.Node) !?[]const u8 {
|
pub fn get_textContent(self: *parser.Node) ?[]const u8 {
|
||||||
return try parser.nodeTextContent(self);
|
return parser.nodeTextContent(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_textContent(self: *parser.Node, data: []u8) !void {
|
pub fn set_textContent(self: *parser.Node, data: []u8) !void {
|
||||||
@@ -240,8 +240,8 @@ pub const Node = struct {
|
|||||||
// Methods
|
// Methods
|
||||||
|
|
||||||
pub fn _appendChild(self: *parser.Node, child: *parser.Node) !Union {
|
pub fn _appendChild(self: *parser.Node, child: *parser.Node) !Union {
|
||||||
const self_owner = try parser.nodeOwnerDocument(self);
|
const self_owner = parser.nodeOwnerDocument(self);
|
||||||
const child_owner = try parser.nodeOwnerDocument(child);
|
const child_owner = parser.nodeOwnerDocument(child);
|
||||||
|
|
||||||
// If the node to be inserted has a different ownerDocument than the parent node,
|
// If the node to be inserted has a different ownerDocument than the parent node,
|
||||||
// modern browsers automatically adopt the node and its descendants into
|
// modern browsers automatically adopt the node and its descendants into
|
||||||
@@ -272,14 +272,14 @@ pub const Node = struct {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const docself = try parser.nodeOwnerDocument(self) orelse blk: {
|
const docself = parser.nodeOwnerDocument(self) orelse blk: {
|
||||||
if (try parser.nodeType(self) == .document) {
|
if (parser.nodeType(self) == .document) {
|
||||||
break :blk @as(*parser.Document, @ptrCast(self));
|
break :blk @as(*parser.Document, @ptrCast(self));
|
||||||
}
|
}
|
||||||
break :blk null;
|
break :blk null;
|
||||||
};
|
};
|
||||||
const docother = try parser.nodeOwnerDocument(other) orelse blk: {
|
const docother = parser.nodeOwnerDocument(other) orelse blk: {
|
||||||
if (try parser.nodeType(other) == .document) {
|
if (parser.nodeType(other) == .document) {
|
||||||
break :blk @as(*parser.Document, @ptrCast(other));
|
break :blk @as(*parser.Document, @ptrCast(other));
|
||||||
}
|
}
|
||||||
break :blk null;
|
break :blk null;
|
||||||
@@ -299,8 +299,8 @@ pub const Node = struct {
|
|||||||
@intFromEnum(parser.DocumentPosition.contained_by);
|
@intFromEnum(parser.DocumentPosition.contained_by);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootself = try parser.nodeGetRootNode(self);
|
const rootself = parser.nodeGetRootNode(self);
|
||||||
const rootother = try parser.nodeGetRootNode(other);
|
const rootother = parser.nodeGetRootNode(other);
|
||||||
if (rootself != rootother) {
|
if (rootself != rootother) {
|
||||||
return @intFromEnum(parser.DocumentPosition.disconnected) +
|
return @intFromEnum(parser.DocumentPosition.disconnected) +
|
||||||
@intFromEnum(parser.DocumentPosition.implementation_specific) +
|
@intFromEnum(parser.DocumentPosition.implementation_specific) +
|
||||||
@@ -347,8 +347,8 @@ pub const Node = struct {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _contains(self: *parser.Node, other: *parser.Node) !bool {
|
pub fn _contains(self: *parser.Node, other: *parser.Node) bool {
|
||||||
return try parser.nodeContains(self, other);
|
return parser.nodeContains(self, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns itself or ancestor object inheriting from Node.
|
// Returns itself or ancestor object inheriting from Node.
|
||||||
@@ -364,7 +364,7 @@ pub const Node = struct {
|
|||||||
log.warn(.web_api, "not implemented", .{ .feature = "getRootNode composed" });
|
log.warn(.web_api, "not implemented", .{ .feature = "getRootNode composed" });
|
||||||
};
|
};
|
||||||
|
|
||||||
const root = try parser.nodeGetRootNode(self);
|
const root = parser.nodeGetRootNode(self);
|
||||||
if (page.getNodeState(root)) |state| {
|
if (page.getNodeState(root)) |state| {
|
||||||
if (state.shadow_root) |sr| {
|
if (state.shadow_root) |sr| {
|
||||||
return .{ .shadow_root = sr };
|
return .{ .shadow_root = sr };
|
||||||
@@ -374,18 +374,18 @@ pub const Node = struct {
|
|||||||
return .{ .node = try Node.toInterface(root) };
|
return .{ .node = try Node.toInterface(root) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _hasChildNodes(self: *parser.Node) !bool {
|
pub fn _hasChildNodes(self: *parser.Node) bool {
|
||||||
return try parser.nodeHasChildNodes(self);
|
return parser.nodeHasChildNodes(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_childNodes(self: *parser.Node, page: *Page) !NodeList {
|
pub fn get_childNodes(self: *parser.Node, page: *Page) !NodeList {
|
||||||
const allocator = page.arena;
|
const allocator = page.arena;
|
||||||
var list: NodeList = .{};
|
var list: NodeList = .{};
|
||||||
|
|
||||||
var n = try parser.nodeFirstChild(self) orelse return list;
|
var n = parser.nodeFirstChild(self) orelse return list;
|
||||||
while (true) {
|
while (true) {
|
||||||
try list.append(allocator, n);
|
try list.append(allocator, n);
|
||||||
n = try parser.nodeNextSibling(n) orelse return list;
|
n = parser.nodeNextSibling(n) orelse return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,8 +394,8 @@ pub const Node = struct {
|
|||||||
return _appendChild(self, new_node);
|
return _appendChild(self, new_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
const self_owner = try parser.nodeOwnerDocument(self);
|
const self_owner = parser.nodeOwnerDocument(self);
|
||||||
const new_node_owner = try parser.nodeOwnerDocument(new_node);
|
const new_node_owner = parser.nodeOwnerDocument(new_node);
|
||||||
|
|
||||||
// If the node to be inserted has a different ownerDocument than the parent node,
|
// If the node to be inserted has a different ownerDocument than the parent node,
|
||||||
// modern browsers automatically adopt the node and its descendants into
|
// modern browsers automatically adopt the node and its descendants into
|
||||||
@@ -415,7 +415,7 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn _isDefaultNamespace(self: *parser.Node, namespace: ?[]const u8) !bool {
|
pub fn _isDefaultNamespace(self: *parser.Node, namespace: ?[]const u8) !bool {
|
||||||
return try parser.nodeIsDefaultNamespace(self, namespace);
|
return parser.nodeIsDefaultNamespace(self, namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _isEqualNode(self: *parser.Node, other: *parser.Node) !bool {
|
pub fn _isEqualNode(self: *parser.Node, other: *parser.Node) !bool {
|
||||||
@@ -423,10 +423,10 @@ pub const Node = struct {
|
|||||||
return try parser.nodeIsEqualNode(self, other);
|
return try parser.nodeIsEqualNode(self, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _isSameNode(self: *parser.Node, other: *parser.Node) !bool {
|
pub fn _isSameNode(self: *parser.Node, other: *parser.Node) bool {
|
||||||
// TODO: other is not an optional parameter, but can be null.
|
// TODO: other is not an optional parameter, but can be null.
|
||||||
// NOTE: there is no need to use isSameNode(); instead use the === strict equality operator
|
// NOTE: there is no need to use isSameNode(); instead use the === strict equality operator
|
||||||
return try parser.nodeIsSameNode(self, other);
|
return parser.nodeIsSameNode(self, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _lookupPrefix(self: *parser.Node, namespace: ?[]const u8) !?[]const u8 {
|
pub fn _lookupPrefix(self: *parser.Node, namespace: ?[]const u8) !?[]const u8 {
|
||||||
@@ -482,9 +482,9 @@ pub const Node = struct {
|
|||||||
return parser.DOMError.HierarchyRequest;
|
return parser.DOMError.HierarchyRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
const doc = (try parser.nodeOwnerDocument(self)) orelse return;
|
const doc = (parser.nodeOwnerDocument(self)) orelse return;
|
||||||
|
|
||||||
if (try parser.nodeFirstChild(self)) |first| {
|
if (parser.nodeFirstChild(self)) |first| {
|
||||||
for (nodes) |node| {
|
for (nodes) |node| {
|
||||||
_ = try parser.nodeInsertBefore(self, try node.toNode(doc), first);
|
_ = try parser.nodeInsertBefore(self, try node.toNode(doc), first);
|
||||||
}
|
}
|
||||||
@@ -506,7 +506,7 @@ pub const Node = struct {
|
|||||||
return parser.DOMError.HierarchyRequest;
|
return parser.DOMError.HierarchyRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
const doc = (try parser.nodeOwnerDocument(self)) orelse return;
|
const doc = (parser.nodeOwnerDocument(self)) orelse return;
|
||||||
for (nodes) |node| {
|
for (nodes) |node| {
|
||||||
_ = try parser.nodeAppendChild(self, try node.toNode(doc));
|
_ = try parser.nodeAppendChild(self, try node.toNode(doc));
|
||||||
}
|
}
|
||||||
@@ -525,7 +525,7 @@ pub const Node = struct {
|
|||||||
// remove existing children
|
// remove existing children
|
||||||
try removeChildren(self);
|
try removeChildren(self);
|
||||||
|
|
||||||
const doc = (try parser.nodeOwnerDocument(self)) orelse return;
|
const doc = (parser.nodeOwnerDocument(self)) orelse return;
|
||||||
// add new children
|
// add new children
|
||||||
for (nodes) |node| {
|
for (nodes) |node| {
|
||||||
_ = try parser.nodeAppendChild(self, try node.toNode(doc));
|
_ = try parser.nodeAppendChild(self, try node.toNode(doc));
|
||||||
@@ -533,30 +533,30 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn removeChildren(self: *parser.Node) !void {
|
pub fn removeChildren(self: *parser.Node) !void {
|
||||||
if (!try parser.nodeHasChildNodes(self)) return;
|
if (!parser.nodeHasChildNodes(self)) return;
|
||||||
|
|
||||||
const children = try parser.nodeGetChildNodes(self);
|
const children = try parser.nodeGetChildNodes(self);
|
||||||
const ln = try parser.nodeListLength(children);
|
const ln = parser.nodeListLength(children);
|
||||||
var i: u32 = 0;
|
var i: u32 = 0;
|
||||||
while (i < ln) {
|
while (i < ln) {
|
||||||
defer i += 1;
|
defer i += 1;
|
||||||
// we always retrieve the 0 index child on purpose: libdom nodelist
|
// we always retrieve the 0 index child on purpose: libdom nodelist
|
||||||
// are dynamic. So the next child to remove is always as pos 0.
|
// are dynamic. So the next child to remove is always as pos 0.
|
||||||
const child = try parser.nodeListItem(children, 0) orelse continue;
|
const child = parser.nodeListItem(children, 0) orelse continue;
|
||||||
_ = try parser.nodeRemoveChild(self, child);
|
_ = try parser.nodeRemoveChild(self, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn before(self: *parser.Node, nodes: []const NodeOrText) !void {
|
pub fn before(self: *parser.Node, nodes: []const NodeOrText) !void {
|
||||||
const parent = try parser.nodeParentNode(self) orelse return;
|
const parent = parser.nodeParentNode(self) orelse return;
|
||||||
const doc = (try parser.nodeOwnerDocument(parent)) orelse return;
|
const doc = (parser.nodeOwnerDocument(parent)) orelse return;
|
||||||
|
|
||||||
var sibling: ?*parser.Node = self;
|
var sibling: ?*parser.Node = self;
|
||||||
// have to find the first sibling that isn't in nodes
|
// have to find the first sibling that isn't in nodes
|
||||||
CHECK: while (sibling) |s| {
|
CHECK: while (sibling) |s| {
|
||||||
for (nodes) |n| {
|
for (nodes) |n| {
|
||||||
if (n.is(s)) {
|
if (n.is(s)) {
|
||||||
sibling = try parser.nodePreviousSibling(s);
|
sibling = parser.nodePreviousSibling(s);
|
||||||
continue :CHECK;
|
continue :CHECK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -564,7 +564,7 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sibling == null) {
|
if (sibling == null) {
|
||||||
sibling = try parser.nodeFirstChild(parent);
|
sibling = parser.nodeFirstChild(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sibling) |ref_node| {
|
if (sibling) |ref_node| {
|
||||||
@@ -578,15 +578,15 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn after(self: *parser.Node, nodes: []const NodeOrText) !void {
|
pub fn after(self: *parser.Node, nodes: []const NodeOrText) !void {
|
||||||
const parent = try parser.nodeParentNode(self) orelse return;
|
const parent = parser.nodeParentNode(self) orelse return;
|
||||||
const doc = (try parser.nodeOwnerDocument(parent)) orelse return;
|
const doc = (parser.nodeOwnerDocument(parent)) orelse return;
|
||||||
|
|
||||||
// have to find the first sibling that isn't in nodes
|
// have to find the first sibling that isn't in nodes
|
||||||
var sibling = try parser.nodeNextSibling(self);
|
var sibling = parser.nodeNextSibling(self);
|
||||||
CHECK: while (sibling) |s| {
|
CHECK: while (sibling) |s| {
|
||||||
for (nodes) |n| {
|
for (nodes) |n| {
|
||||||
if (n.is(s)) {
|
if (n.is(s)) {
|
||||||
sibling = try parser.nodeNextSibling(s);
|
sibling = parser.nodeNextSibling(s);
|
||||||
continue :CHECK;
|
continue :CHECK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ pub const NodeFilter = struct {
|
|||||||
const VerifyResult = enum { accept, skip, reject };
|
const VerifyResult = enum { accept, skip, reject };
|
||||||
|
|
||||||
pub fn verify(what_to_show: u32, filter: ?Env.Function, node: *parser.Node) !VerifyResult {
|
pub fn verify(what_to_show: u32, filter: ?Env.Function, node: *parser.Node) !VerifyResult {
|
||||||
const node_type = try parser.nodeType(node);
|
const node_type = parser.nodeType(node);
|
||||||
|
|
||||||
// Verify that we can show this node type.
|
// Verify that we can show this node type.
|
||||||
if (!switch (node_type) {
|
if (!switch (node_type) {
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ pub const NodeIterator = struct {
|
|||||||
return try Node.toInterface(sibling);
|
return try Node.toInterface(sibling);
|
||||||
}
|
}
|
||||||
|
|
||||||
current = (try parser.nodeParentNode(current)) orelse break;
|
current = (parser.nodeParentNode(current)) orelse break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -147,7 +147,7 @@ pub const NodeIterator = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var current = self.reference_node;
|
var current = self.reference_node;
|
||||||
while (try parser.nodePreviousSibling(current)) |previous| {
|
while (parser.nodePreviousSibling(current)) |previous| {
|
||||||
current = previous;
|
current = previous;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
||||||
@@ -189,11 +189,11 @@ pub const NodeIterator = struct {
|
|||||||
|
|
||||||
fn firstChild(self: *const NodeIterator, node: *parser.Node) !?*parser.Node {
|
fn firstChild(self: *const NodeIterator, node: *parser.Node) !?*parser.Node {
|
||||||
const children = try parser.nodeGetChildNodes(node);
|
const children = try parser.nodeGetChildNodes(node);
|
||||||
const child_count = try parser.nodeListLength(children);
|
const child_count = parser.nodeListLength(children);
|
||||||
|
|
||||||
for (0..child_count) |i| {
|
for (0..child_count) |i| {
|
||||||
const index: u32 = @intCast(i);
|
const index: u32 = @intCast(i);
|
||||||
const child = (try parser.nodeListItem(children, index)) orelse return null;
|
const child = (parser.nodeListItem(children, index)) orelse return null;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, child)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, child)) {
|
||||||
.accept => return child, // NOTE: Skip and reject are equivalent for NodeIterator, this is different from TreeWalker
|
.accept => return child, // NOTE: Skip and reject are equivalent for NodeIterator, this is different from TreeWalker
|
||||||
@@ -206,12 +206,12 @@ pub const NodeIterator = struct {
|
|||||||
|
|
||||||
fn lastChild(self: *const NodeIterator, node: *parser.Node) !?*parser.Node {
|
fn lastChild(self: *const NodeIterator, node: *parser.Node) !?*parser.Node {
|
||||||
const children = try parser.nodeGetChildNodes(node);
|
const children = try parser.nodeGetChildNodes(node);
|
||||||
const child_count = try parser.nodeListLength(children);
|
const child_count = parser.nodeListLength(children);
|
||||||
|
|
||||||
var index: u32 = child_count;
|
var index: u32 = child_count;
|
||||||
while (index > 0) {
|
while (index > 0) {
|
||||||
index -= 1;
|
index -= 1;
|
||||||
const child = (try parser.nodeListItem(children, index)) orelse return null;
|
const child = (parser.nodeListItem(children, index)) orelse return null;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, child)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, child)) {
|
||||||
.accept => return child, // NOTE: Skip and reject are equivalent for NodeIterator, this is different from TreeWalker
|
.accept => return child, // NOTE: Skip and reject are equivalent for NodeIterator, this is different from TreeWalker
|
||||||
@@ -229,7 +229,7 @@ pub const NodeIterator = struct {
|
|||||||
var current = node;
|
var current = node;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (current == self.root) return null;
|
if (current == self.root) return null;
|
||||||
current = (try parser.nodeParentNode(current)) orelse return null;
|
current = (parser.nodeParentNode(current)) orelse return null;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
||||||
.accept => return current,
|
.accept => return current,
|
||||||
@@ -243,7 +243,7 @@ pub const NodeIterator = struct {
|
|||||||
var current = node;
|
var current = node;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
current = (try parser.nodeNextSibling(current)) orelse return null;
|
current = (parser.nodeNextSibling(current)) orelse return null;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
||||||
.accept => return current,
|
.accept => return current,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ pub const ProcessingInstruction = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_data(self: *parser.ProcessingInstruction) !?[]const u8 {
|
pub fn get_data(self: *parser.ProcessingInstruction) !?[]const u8 {
|
||||||
return try parser.nodeValue(parser.processingInstructionToNode(self));
|
return parser.nodeValue(parser.processingInstructionToNode(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_data(self: *parser.ProcessingInstruction, data: []u8) !void {
|
pub fn set_data(self: *parser.ProcessingInstruction, data: []u8) !void {
|
||||||
@@ -58,7 +58,7 @@ pub const ProcessingInstruction = struct {
|
|||||||
// netsurf's ProcessInstruction doesn't implement the dom_node_get_attributes
|
// netsurf's ProcessInstruction doesn't implement the dom_node_get_attributes
|
||||||
// and thus will crash if we try to call nodeIsEqualNode.
|
// and thus will crash if we try to call nodeIsEqualNode.
|
||||||
pub fn _isEqualNode(self: *parser.ProcessingInstruction, other_node: *parser.Node) !bool {
|
pub fn _isEqualNode(self: *parser.ProcessingInstruction, other_node: *parser.Node) !bool {
|
||||||
if (try parser.nodeType(other_node) != .processing_instruction) {
|
if (parser.nodeType(other_node) != .processing_instruction) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -176,10 +176,10 @@ pub const Range = struct {
|
|||||||
self.proto.end_node = node;
|
self.proto.end_node = node;
|
||||||
|
|
||||||
// Set end_offset
|
// Set end_offset
|
||||||
switch (try parser.nodeType(node)) {
|
switch (parser.nodeType(node)) {
|
||||||
.text, .cdata_section, .comment, .processing_instruction => {
|
.text, .cdata_section, .comment, .processing_instruction => {
|
||||||
// For text-like nodes, end_offset should be the length of the text data
|
// For text-like nodes, end_offset should be the length of the text data
|
||||||
if (try parser.nodeValue(node)) |text_data| {
|
if (parser.nodeValue(node)) |text_data| {
|
||||||
self.proto.end_offset = @intCast(text_data.len);
|
self.proto.end_offset = @intCast(text_data.len);
|
||||||
} else {
|
} else {
|
||||||
self.proto.end_offset = 0;
|
self.proto.end_offset = 0;
|
||||||
@@ -188,7 +188,7 @@ pub const Range = struct {
|
|||||||
else => {
|
else => {
|
||||||
// For element and other nodes, end_offset is the number of children
|
// For element and other nodes, end_offset is the number of children
|
||||||
const child_nodes = try parser.nodeGetChildNodes(node);
|
const child_nodes = try parser.nodeGetChildNodes(node);
|
||||||
const child_count = try parser.nodeListLength(child_nodes);
|
const child_count = parser.nodeListLength(child_nodes);
|
||||||
self.proto.end_offset = @intCast(child_count);
|
self.proto.end_offset = @intCast(child_count);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -211,7 +211,7 @@ pub const Range = struct {
|
|||||||
|
|
||||||
pub fn _comparePoint(self: *const Range, node: *parser.Node, offset_: i32) !i32 {
|
pub fn _comparePoint(self: *const Range, node: *parser.Node, offset_: i32) !i32 {
|
||||||
const start = self.proto.start_node;
|
const start = self.proto.start_node;
|
||||||
if (try parser.nodeGetRootNode(start) != try parser.nodeGetRootNode(node)) {
|
if (parser.nodeGetRootNode(start) != parser.nodeGetRootNode(node)) {
|
||||||
// WPT really wants this error to be first. Later, when we check
|
// WPT really wants this error to be first. Later, when we check
|
||||||
// if the relative position is 'disconnected', it'll also catch this
|
// if the relative position is 'disconnected', it'll also catch this
|
||||||
// case, but WPT will complain because it sometimes also sends
|
// case, but WPT will complain because it sometimes also sends
|
||||||
@@ -219,7 +219,7 @@ pub const Range = struct {
|
|||||||
return error.WrongDocument;
|
return error.WrongDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (try parser.nodeType(node) == .document_type) {
|
if (parser.nodeType(node) == .document_type) {
|
||||||
return error.InvalidNodeType;
|
return error.InvalidNodeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,8 +245,8 @@ pub const Range = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn _intersectsNode(self: *const Range, node: *parser.Node) !bool {
|
pub fn _intersectsNode(self: *const Range, node: *parser.Node) !bool {
|
||||||
const start_root = try parser.nodeGetRootNode(self.proto.start_node);
|
const start_root = parser.nodeGetRootNode(self.proto.start_node);
|
||||||
const node_root = try parser.nodeGetRootNode(node);
|
const node_root = parser.nodeGetRootNode(node);
|
||||||
if (start_root != node_root) {
|
if (start_root != node_root) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -299,29 +299,29 @@ fn ensureValidOffset(node: *parser.Node, offset: i32) !void {
|
|||||||
|
|
||||||
fn nodeLength(node: *parser.Node) !usize {
|
fn nodeLength(node: *parser.Node) !usize {
|
||||||
switch (try isTextual(node)) {
|
switch (try isTextual(node)) {
|
||||||
true => return ((try parser.nodeTextContent(node)) orelse "").len,
|
true => return ((parser.nodeTextContent(node)) orelse "").len,
|
||||||
false => {
|
false => {
|
||||||
const children = try parser.nodeGetChildNodes(node);
|
const children = try parser.nodeGetChildNodes(node);
|
||||||
return @intCast(try parser.nodeListLength(children));
|
return @intCast(parser.nodeListLength(children));
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn isTextual(node: *parser.Node) !bool {
|
fn isTextual(node: *parser.Node) !bool {
|
||||||
return switch (try parser.nodeType(node)) {
|
return switch (parser.nodeType(node)) {
|
||||||
.text, .comment, .cdata_section => true,
|
.text, .comment, .cdata_section => true,
|
||||||
else => false,
|
else => false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getParentAndIndex(child: *parser.Node) !struct { *parser.Node, u32 } {
|
fn getParentAndIndex(child: *parser.Node) !struct { *parser.Node, u32 } {
|
||||||
const parent = (try parser.nodeParentNode(child)) orelse return error.InvalidNodeType;
|
const parent = (parser.nodeParentNode(child)) orelse return error.InvalidNodeType;
|
||||||
const children = try parser.nodeGetChildNodes(parent);
|
const children = try parser.nodeGetChildNodes(parent);
|
||||||
const ln = try parser.nodeListLength(children);
|
const ln = parser.nodeListLength(children);
|
||||||
var i: u32 = 0;
|
var i: u32 = 0;
|
||||||
while (i < ln) {
|
while (i < ln) {
|
||||||
defer i += 1;
|
defer i += 1;
|
||||||
const c = try parser.nodeListItem(children, i) orelse continue;
|
const c = parser.nodeListItem(children, i) orelse continue;
|
||||||
if (c == child) {
|
if (c == child) {
|
||||||
return .{ parent, i };
|
return .{ parent, i };
|
||||||
}
|
}
|
||||||
@@ -363,7 +363,7 @@ fn compare(node_a: *parser.Node, offset_a: u32, node_b: *parser.Node, offset_b:
|
|||||||
if (position & @intFromEnum(parser.DocumentPosition.contains) == @intFromEnum(parser.DocumentPosition.contains)) {
|
if (position & @intFromEnum(parser.DocumentPosition.contains) == @intFromEnum(parser.DocumentPosition.contains)) {
|
||||||
// node_a contains node_b
|
// node_a contains node_b
|
||||||
var child = node_b;
|
var child = node_b;
|
||||||
while (try parser.nodeParentNode(child)) |parent| {
|
while (parser.nodeParentNode(child)) |parent| {
|
||||||
if (parent == node_a) {
|
if (parent == node_a) {
|
||||||
// child.parentNode == node_a
|
// child.parentNode == node_a
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ pub const ShadowRoot = struct {
|
|||||||
|
|
||||||
pub fn set_innerHTML(self: *ShadowRoot, str_: ?[]const u8) !void {
|
pub fn set_innerHTML(self: *ShadowRoot, str_: ?[]const u8) !void {
|
||||||
const sr_doc = parser.documentFragmentToNode(self.proto);
|
const sr_doc = parser.documentFragmentToNode(self.proto);
|
||||||
const doc = try parser.nodeOwnerDocument(sr_doc) orelse return parser.DOMError.WrongDocument;
|
const doc = parser.nodeOwnerDocument(sr_doc) orelse return parser.DOMError.WrongDocument;
|
||||||
try Node.removeChildren(sr_doc);
|
try Node.removeChildren(sr_doc);
|
||||||
const str = str_ orelse return;
|
const str = str_ orelse return;
|
||||||
|
|
||||||
@@ -80,16 +80,16 @@ pub const ShadowRoot = struct {
|
|||||||
// element.
|
// element.
|
||||||
// For ShadowRoot, it appears the only the children within the body should
|
// For ShadowRoot, it appears the only the children within the body should
|
||||||
// be set.
|
// be set.
|
||||||
const html = try parser.nodeFirstChild(fragment_node) orelse return;
|
const html = parser.nodeFirstChild(fragment_node) orelse return;
|
||||||
const head = try parser.nodeFirstChild(html) orelse return;
|
const head = parser.nodeFirstChild(html) orelse return;
|
||||||
const body = try parser.nodeNextSibling(head) orelse return;
|
const body = parser.nodeNextSibling(head) orelse return;
|
||||||
|
|
||||||
const children = try parser.nodeGetChildNodes(body);
|
const children = try parser.nodeGetChildNodes(body);
|
||||||
const ln = try parser.nodeListLength(children);
|
const ln = parser.nodeListLength(children);
|
||||||
for (0..ln) |_| {
|
for (0..ln) |_| {
|
||||||
// always index 0, because nodeAppendChild moves the node out of
|
// always index 0, because nodeAppendChild moves the node out of
|
||||||
// the nodeList and into the new tree
|
// the nodeList and into the new tree
|
||||||
const child = try parser.nodeListItem(children, 0) orelse continue;
|
const child = parser.nodeListItem(children, 0) orelse continue;
|
||||||
_ = try parser.nodeAppendChild(sr_doc, child);
|
_ = try parser.nodeAppendChild(sr_doc, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ const parser = @import("../netsurf.zig");
|
|||||||
|
|
||||||
const NodeFilter = @import("node_filter.zig");
|
const NodeFilter = @import("node_filter.zig");
|
||||||
const Env = @import("../env.zig").Env;
|
const Env = @import("../env.zig").Env;
|
||||||
const Page = @import("../page.zig").Page;
|
|
||||||
const Node = @import("node.zig").Node;
|
const Node = @import("node.zig").Node;
|
||||||
const NodeUnion = @import("node.zig").Union;
|
const NodeUnion = @import("node.zig").Union;
|
||||||
|
|
||||||
@@ -95,11 +94,11 @@ pub const TreeWalker = struct {
|
|||||||
|
|
||||||
fn firstChild(self: *const TreeWalker, node: *parser.Node) !?*parser.Node {
|
fn firstChild(self: *const TreeWalker, node: *parser.Node) !?*parser.Node {
|
||||||
const children = try parser.nodeGetChildNodes(node);
|
const children = try parser.nodeGetChildNodes(node);
|
||||||
const child_count = try parser.nodeListLength(children);
|
const child_count = parser.nodeListLength(children);
|
||||||
|
|
||||||
for (0..child_count) |i| {
|
for (0..child_count) |i| {
|
||||||
const index: u32 = @intCast(i);
|
const index: u32 = @intCast(i);
|
||||||
const child = (try parser.nodeListItem(children, index)) orelse return null;
|
const child = (parser.nodeListItem(children, index)) orelse return null;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, child)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, child)) {
|
||||||
.accept => return child,
|
.accept => return child,
|
||||||
@@ -113,12 +112,12 @@ pub const TreeWalker = struct {
|
|||||||
|
|
||||||
fn lastChild(self: *const TreeWalker, node: *parser.Node) !?*parser.Node {
|
fn lastChild(self: *const TreeWalker, node: *parser.Node) !?*parser.Node {
|
||||||
const children = try parser.nodeGetChildNodes(node);
|
const children = try parser.nodeGetChildNodes(node);
|
||||||
const child_count = try parser.nodeListLength(children);
|
const child_count = parser.nodeListLength(children);
|
||||||
|
|
||||||
var index: u32 = child_count;
|
var index: u32 = child_count;
|
||||||
while (index > 0) {
|
while (index > 0) {
|
||||||
index -= 1;
|
index -= 1;
|
||||||
const child = (try parser.nodeListItem(children, index)) orelse return null;
|
const child = (parser.nodeListItem(children, index)) orelse return null;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, child)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, child)) {
|
||||||
.accept => return child,
|
.accept => return child,
|
||||||
@@ -134,7 +133,7 @@ pub const TreeWalker = struct {
|
|||||||
var current = node;
|
var current = node;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
current = (try parser.nodeNextSibling(current)) orelse return null;
|
current = (parser.nodeNextSibling(current)) orelse return null;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
||||||
.accept => return current,
|
.accept => return current,
|
||||||
@@ -149,7 +148,7 @@ pub const TreeWalker = struct {
|
|||||||
var current = node;
|
var current = node;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
current = (try parser.nodePreviousSibling(current)) orelse return null;
|
current = (parser.nodePreviousSibling(current)) orelse return null;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
||||||
.accept => return current,
|
.accept => return current,
|
||||||
@@ -166,7 +165,7 @@ pub const TreeWalker = struct {
|
|||||||
var current = node;
|
var current = node;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (current == self.root) return null;
|
if (current == self.root) return null;
|
||||||
current = (try parser.nodeParentNode(current)) orelse return null;
|
current = (parser.nodeParentNode(current)) orelse return null;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
||||||
.accept => return current,
|
.accept => return current,
|
||||||
@@ -206,7 +205,7 @@ pub const TreeWalker = struct {
|
|||||||
return try Node.toInterface(sibling);
|
return try Node.toInterface(sibling);
|
||||||
}
|
}
|
||||||
|
|
||||||
current = (try parser.nodeParentNode(current)) orelse break;
|
current = (parser.nodeParentNode(current)) orelse break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -234,7 +233,7 @@ pub const TreeWalker = struct {
|
|||||||
if (self.current_node == self.root) return null;
|
if (self.current_node == self.root) return null;
|
||||||
|
|
||||||
var current = self.current_node;
|
var current = self.current_node;
|
||||||
while (try parser.nodePreviousSibling(current)) |previous| {
|
while (parser.nodePreviousSibling(current)) |previous| {
|
||||||
current = previous;
|
current = previous;
|
||||||
|
|
||||||
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
switch (try NodeFilter.verify(self.what_to_show, self.filter_func, current)) {
|
||||||
|
|||||||
@@ -44,39 +44,39 @@ pub const WalkerDepthFirst = struct {
|
|||||||
var n = cur orelse root;
|
var n = cur orelse root;
|
||||||
|
|
||||||
// TODO deinit next
|
// TODO deinit next
|
||||||
if (try parser.nodeFirstChild(n)) |next| {
|
if (parser.nodeFirstChild(n)) |next| {
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO deinit next
|
// TODO deinit next
|
||||||
if (try parser.nodeNextSibling(n)) |next| {
|
if (parser.nodeNextSibling(n)) |next| {
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO deinit parent
|
// TODO deinit parent
|
||||||
// Back to the parent of cur.
|
// Back to the parent of cur.
|
||||||
// If cur has no parent, then the iteration is over.
|
// If cur has no parent, then the iteration is over.
|
||||||
var parent = try parser.nodeParentNode(n) orelse return null;
|
var parent = parser.nodeParentNode(n) orelse return null;
|
||||||
|
|
||||||
// TODO deinit lastchild
|
// TODO deinit lastchild
|
||||||
var lastchild = try parser.nodeLastChild(parent);
|
var lastchild = parser.nodeLastChild(parent);
|
||||||
while (n != root and n == lastchild) {
|
while (n != root and n == lastchild) {
|
||||||
n = parent;
|
n = parent;
|
||||||
|
|
||||||
// TODO deinit parent
|
// TODO deinit parent
|
||||||
// Back to the prev's parent.
|
// Back to the prev's parent.
|
||||||
// If prev has no parent, then the loop must stop.
|
// If prev has no parent, then the loop must stop.
|
||||||
parent = try parser.nodeParentNode(n) orelse break;
|
parent = parser.nodeParentNode(n) orelse break;
|
||||||
|
|
||||||
// TODO deinit lastchild
|
// TODO deinit lastchild
|
||||||
lastchild = try parser.nodeLastChild(parent);
|
lastchild = parser.nodeLastChild(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == root) {
|
if (n == root) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return try parser.nodeNextSibling(n);
|
return parser.nodeNextSibling(n);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -84,14 +84,14 @@ pub const WalkerDepthFirst = struct {
|
|||||||
pub const WalkerChildren = struct {
|
pub const WalkerChildren = struct {
|
||||||
pub fn get_next(_: WalkerChildren, root: *parser.Node, cur: ?*parser.Node) !?*parser.Node {
|
pub fn get_next(_: WalkerChildren, root: *parser.Node, cur: ?*parser.Node) !?*parser.Node {
|
||||||
// On walk start, we return the first root's child.
|
// On walk start, we return the first root's child.
|
||||||
if (cur == null) return try parser.nodeFirstChild(root);
|
if (cur == null) return parser.nodeFirstChild(root);
|
||||||
|
|
||||||
// If cur is root, then return null.
|
// If cur is root, then return null.
|
||||||
// This is a special case, if the root is included in the walk, we
|
// This is a special case, if the root is included in the walk, we
|
||||||
// don't want to go further to find children.
|
// don't want to go further to find children.
|
||||||
if (root == cur.?) return null;
|
if (root == cur.?) return null;
|
||||||
|
|
||||||
return try parser.nodeNextSibling(cur.?);
|
return parser.nodeNextSibling(cur.?);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ pub fn writeDocType(doc_type: *parser.DocumentType, writer: *std.Io.Writer) !voi
|
|||||||
try writer.writeAll("<!DOCTYPE ");
|
try writer.writeAll("<!DOCTYPE ");
|
||||||
try writer.writeAll(try parser.documentTypeGetName(doc_type));
|
try writer.writeAll(try parser.documentTypeGetName(doc_type));
|
||||||
|
|
||||||
const public_id = try parser.documentTypeGetPublicId(doc_type);
|
const public_id = parser.documentTypeGetPublicId(doc_type);
|
||||||
const system_id = try parser.documentTypeGetSystemId(doc_type);
|
const system_id = parser.documentTypeGetSystemId(doc_type);
|
||||||
if (public_id.len != 0 and system_id.len != 0) {
|
if (public_id.len != 0 and system_id.len != 0) {
|
||||||
try writer.writeAll(" PUBLIC \"");
|
try writer.writeAll(" PUBLIC \"");
|
||||||
try writeEscapedAttributeValue(writer, public_id);
|
try writeEscapedAttributeValue(writer, public_id);
|
||||||
@@ -63,7 +63,7 @@ pub fn writeDocType(doc_type: *parser.DocumentType, writer: *std.Io.Writer) !voi
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn writeNode(node: *parser.Node, opts: Opts, writer: *std.Io.Writer) anyerror!void {
|
pub fn writeNode(node: *parser.Node, opts: Opts, writer: *std.Io.Writer) anyerror!void {
|
||||||
switch (try parser.nodeType(node)) {
|
switch (parser.nodeType(node)) {
|
||||||
.element => {
|
.element => {
|
||||||
// open the tag
|
// open the tag
|
||||||
const tag_type = try parser.nodeHTMLGetTagType(node) orelse .undef;
|
const tag_type = try parser.nodeHTMLGetTagType(node) orelse .undef;
|
||||||
@@ -104,7 +104,7 @@ pub fn writeNode(node: *parser.Node, opts: Opts, writer: *std.Io.Writer) anyerro
|
|||||||
if (try isVoid(parser.nodeToElement(node))) return;
|
if (try isVoid(parser.nodeToElement(node))) return;
|
||||||
|
|
||||||
if (tag_type == .script) {
|
if (tag_type == .script) {
|
||||||
try writer.writeAll(try parser.nodeTextContent(node) orelse "");
|
try writer.writeAll(parser.nodeTextContent(node) orelse "");
|
||||||
} else {
|
} else {
|
||||||
// write the children
|
// write the children
|
||||||
// TODO avoid recursion
|
// TODO avoid recursion
|
||||||
@@ -117,17 +117,17 @@ pub fn writeNode(node: *parser.Node, opts: Opts, writer: *std.Io.Writer) anyerro
|
|||||||
try writer.writeAll(">");
|
try writer.writeAll(">");
|
||||||
},
|
},
|
||||||
.text => {
|
.text => {
|
||||||
const v = try parser.nodeValue(node) orelse return;
|
const v = parser.nodeValue(node) orelse return;
|
||||||
try writeEscapedTextNode(writer, v);
|
try writeEscapedTextNode(writer, v);
|
||||||
},
|
},
|
||||||
.cdata_section => {
|
.cdata_section => {
|
||||||
const v = try parser.nodeValue(node) orelse return;
|
const v = parser.nodeValue(node) orelse return;
|
||||||
try writer.writeAll("<![CDATA[");
|
try writer.writeAll("<![CDATA[");
|
||||||
try writer.writeAll(v);
|
try writer.writeAll(v);
|
||||||
try writer.writeAll("]]>");
|
try writer.writeAll("]]>");
|
||||||
},
|
},
|
||||||
.comment => {
|
.comment => {
|
||||||
const v = try parser.nodeValue(node) orelse return;
|
const v = parser.nodeValue(node) orelse return;
|
||||||
try writer.writeAll("<!--");
|
try writer.writeAll("<!--");
|
||||||
try writer.writeAll(v);
|
try writer.writeAll(v);
|
||||||
try writer.writeAll("-->");
|
try writer.writeAll("-->");
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const log = @import("../../log.zig");
|
const log = @import("../../log.zig");
|
||||||
|
|
||||||
const Env = @import("../env.zig").Env;
|
|
||||||
const Page = @import("../page.zig").Page;
|
const Page = @import("../page.zig").Page;
|
||||||
|
|
||||||
// https://encoding.spec.whatwg.org/#interface-textdecoder
|
// https://encoding.spec.whatwg.org/#interface-textdecoder
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ pub const Event = struct {
|
|||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
pub fn get_type(self: *parser.Event) ![]const u8 {
|
pub fn get_type(self: *parser.Event) []const u8 {
|
||||||
return try parser.eventType(self);
|
return parser.eventType(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_target(self: *parser.Event, page: *Page) !?EventTargetUnion {
|
pub fn get_target(self: *parser.Event, page: *Page) !?EventTargetUnion {
|
||||||
@@ -158,7 +158,7 @@ pub const Event = struct {
|
|||||||
const et_ = parser.eventTarget(self);
|
const et_ = parser.eventTarget(self);
|
||||||
const et = et_ orelse return &.{};
|
const et = et_ orelse return &.{};
|
||||||
|
|
||||||
var node: ?*parser.Node = switch (try parser.eventTargetInternalType(et)) {
|
var node: ?*parser.Node = switch (parser.eventTargetInternalType(et)) {
|
||||||
.libdom_node => @as(*parser.Node, @ptrCast(et)),
|
.libdom_node => @as(*parser.Node, @ptrCast(et)),
|
||||||
.plain => parser.eventTargetToNode(et),
|
.plain => parser.eventTargetToNode(et),
|
||||||
else => {
|
else => {
|
||||||
@@ -174,8 +174,8 @@ pub const Event = struct {
|
|||||||
.node = try Node.toInterface(n),
|
.node = try Node.toInterface(n),
|
||||||
});
|
});
|
||||||
|
|
||||||
node = try parser.nodeParentNode(n);
|
node = parser.nodeParentNode(n);
|
||||||
if (node == null and try parser.nodeType(n) == .document_fragment) {
|
if (node == null and parser.nodeType(n) == .document_fragment) {
|
||||||
// we have a non-continuous hook from a shadowroot to its host (
|
// we have a non-continuous hook from a shadowroot to its host (
|
||||||
// it's parent element). libdom doesn't really support ShdowRoots
|
// it's parent element). libdom doesn't really support ShdowRoots
|
||||||
// and, for the most part, that works out well since it naturally
|
// and, for the most part, that works out well since it naturally
|
||||||
@@ -339,7 +339,7 @@ pub const EventHandler = struct {
|
|||||||
|
|
||||||
if (self.once) {
|
if (self.once) {
|
||||||
const target = parser.eventTarget(event).?;
|
const target = parser.eventTarget(event).?;
|
||||||
const typ = parser.eventType(event) catch return;
|
const typ = parser.eventType(event);
|
||||||
parser.eventTargetRemoveEventListener(
|
parser.eventTargetRemoveEventListener(
|
||||||
target,
|
target,
|
||||||
typ,
|
typ,
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ const builtin = @import("builtin");
|
|||||||
|
|
||||||
const parser = @import("../netsurf.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
const Event = @import("event.zig").Event;
|
const Event = @import("event.zig").Event;
|
||||||
const JsObject = @import("../env.zig").JsObject;
|
|
||||||
|
|
||||||
// TODO: We currently don't have a UIEvent interface so we skip it in the prototype chain.
|
// TODO: We currently don't have a UIEvent interface so we skip it in the prototype chain.
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/UIEvent
|
// https://developer.mozilla.org/en-US/docs/Web/API/UIEvent
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ const log = @import("../../log.zig");
|
|||||||
|
|
||||||
const parser = @import("../netsurf.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
const Event = @import("event.zig").Event;
|
const Event = @import("event.zig").Event;
|
||||||
const JsObject = @import("../env.zig").JsObject;
|
|
||||||
|
|
||||||
// TODO: We currently don't have a UIEvent interface so we skip it in the prototype chain.
|
// TODO: We currently don't have a UIEvent interface so we skip it in the prototype chain.
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/UIEvent
|
// https://developer.mozilla.org/en-US/docs/Web/API/UIEvent
|
||||||
|
|||||||
@@ -133,14 +133,14 @@ pub const HTMLElement = struct {
|
|||||||
|
|
||||||
pub fn get_innerText(e: *parser.ElementHTML) ![]const u8 {
|
pub fn get_innerText(e: *parser.ElementHTML) ![]const u8 {
|
||||||
const n = @as(*parser.Node, @ptrCast(e));
|
const n = @as(*parser.Node, @ptrCast(e));
|
||||||
return try parser.nodeTextContent(n) orelse "";
|
return parser.nodeTextContent(n) orelse "";
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_innerText(e: *parser.ElementHTML, s: []const u8) !void {
|
pub fn set_innerText(e: *parser.ElementHTML, s: []const u8) !void {
|
||||||
const n = @as(*parser.Node, @ptrCast(e));
|
const n = @as(*parser.Node, @ptrCast(e));
|
||||||
|
|
||||||
// create text node.
|
// create text node.
|
||||||
const doc = try parser.nodeOwnerDocument(n) orelse return error.NoDocument;
|
const doc = parser.nodeOwnerDocument(n) orelse return error.NoDocument;
|
||||||
const t = try parser.documentCreateTextNode(doc, s);
|
const t = try parser.documentCreateTextNode(doc, s);
|
||||||
|
|
||||||
// remove existing children.
|
// remove existing children.
|
||||||
@@ -167,12 +167,12 @@ pub const HTMLElement = struct {
|
|||||||
focusVisible: bool,
|
focusVisible: bool,
|
||||||
};
|
};
|
||||||
pub fn _focus(e: *parser.ElementHTML, _: ?FocusOpts, page: *Page) !void {
|
pub fn _focus(e: *parser.ElementHTML, _: ?FocusOpts, page: *Page) !void {
|
||||||
if (!try page.isNodeAttached(@ptrCast(e))) {
|
if (!page.isNodeAttached(@ptrCast(e))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Document = @import("../dom/document.zig").Document;
|
const Document = @import("../dom/document.zig").Document;
|
||||||
const root_node = try parser.nodeGetRootNode(@ptrCast(e));
|
const root_node = parser.nodeGetRootNode(@ptrCast(e));
|
||||||
try Document.setFocus(@ptrCast(root_node), e, page);
|
try Document.setFocus(@ptrCast(root_node), e, page);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -251,7 +251,7 @@ pub const HTMLAnchorElement = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_text(self: *parser.Anchor) !?[]const u8 {
|
pub fn get_text(self: *parser.Anchor) !?[]const u8 {
|
||||||
return try parser.nodeTextContent(parser.anchorToNode(self));
|
return parser.nodeTextContent(parser.anchorToNode(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_text(self: *parser.Anchor, v: []const u8) !void {
|
pub fn set_text(self: *parser.Anchor, v: []const u8) !void {
|
||||||
@@ -1064,7 +1064,7 @@ pub const HTMLSlotElement = struct {
|
|||||||
// First we look for any explicitly assigned nodes (via the slot attribute)
|
// First we look for any explicitly assigned nodes (via the slot attribute)
|
||||||
{
|
{
|
||||||
const slot_name = try parser.elementGetAttribute(@ptrCast(@alignCast(self)), "name");
|
const slot_name = try parser.elementGetAttribute(@ptrCast(@alignCast(self)), "name");
|
||||||
var root = try parser.nodeGetRootNode(node);
|
var root = parser.nodeGetRootNode(node);
|
||||||
if (page.getNodeState(root)) |state| {
|
if (page.getNodeState(root)) |state| {
|
||||||
if (state.shadow_root) |sr| {
|
if (state.shadow_root) |sr| {
|
||||||
root = @ptrCast(@alignCast(sr.host));
|
root = @ptrCast(@alignCast(sr.host));
|
||||||
@@ -1076,7 +1076,7 @@ pub const HTMLSlotElement = struct {
|
|||||||
var next: ?*parser.Node = null;
|
var next: ?*parser.Node = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
next = try w.get_next(root, next) orelse break;
|
next = try w.get_next(root, next) orelse break;
|
||||||
if (try parser.nodeType(next.?) != .element) {
|
if (parser.nodeType(next.?) != .element) {
|
||||||
if (slot_name == null and !element_only) {
|
if (slot_name == null and !element_only) {
|
||||||
// default slot (with no name), takes everything
|
// default slot (with no name), takes everything
|
||||||
try arr.append(page.call_arena, try Node.toInterface(next.?));
|
try arr.append(page.call_arena, try Node.toInterface(next.?));
|
||||||
@@ -1105,7 +1105,7 @@ pub const HTMLSlotElement = struct {
|
|||||||
// we'll collect the children of the slot - the defaults.
|
// we'll collect the children of the slot - the defaults.
|
||||||
{
|
{
|
||||||
const nl = try parser.nodeGetChildNodes(node);
|
const nl = try parser.nodeGetChildNodes(node);
|
||||||
const len = try parser.nodeListLength(nl);
|
const len = parser.nodeListLength(nl);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
return &.{};
|
return &.{};
|
||||||
}
|
}
|
||||||
@@ -1113,8 +1113,8 @@ pub const HTMLSlotElement = struct {
|
|||||||
var assigned = try page.call_arena.alloc(NodeUnion, len);
|
var assigned = try page.call_arena.alloc(NodeUnion, len);
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
while (true) : (i += 1) {
|
while (true) : (i += 1) {
|
||||||
const child = try parser.nodeListItem(nl, @intCast(i)) orelse break;
|
const child = parser.nodeListItem(nl, @intCast(i)) orelse break;
|
||||||
if (!element_only or try parser.nodeType(child) == .element) {
|
if (!element_only or parser.nodeType(child) == .element) {
|
||||||
assigned[i] = try Node.toInterface(child);
|
assigned[i] = try Node.toInterface(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ const Allocator = std.mem.Allocator;
|
|||||||
const parser = @import("../netsurf.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
const Page = @import("../page.zig").Page;
|
const Page = @import("../page.zig").Page;
|
||||||
const HTMLElement = @import("elements.zig").HTMLElement;
|
const HTMLElement = @import("elements.zig").HTMLElement;
|
||||||
const FormData = @import("../xhr/form_data.zig").FormData;
|
|
||||||
|
|
||||||
pub const HTMLFormElement = struct {
|
pub const HTMLFormElement = struct {
|
||||||
pub const Self = parser.Form;
|
pub const Self = parser.Form;
|
||||||
|
|||||||
@@ -16,10 +16,8 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
|
||||||
|
|
||||||
const parser = @import("../netsurf.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
const Page = @import("../page.zig").Page;
|
|
||||||
const HTMLElement = @import("elements.zig").HTMLElement;
|
const HTMLElement = @import("elements.zig").HTMLElement;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#htmliframeelement
|
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#htmliframeelement
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ const domcss = @import("../dom/css.zig");
|
|||||||
const Css = @import("../css/css.zig").Css;
|
const Css = @import("../css/css.zig").Css;
|
||||||
|
|
||||||
const Function = Env.Function;
|
const Function = Env.Function;
|
||||||
const JsObject = Env.JsObject;
|
|
||||||
|
|
||||||
const v8 = @import("v8");
|
const v8 = @import("v8");
|
||||||
const Request = @import("../fetch/Request.zig");
|
const Request = @import("../fetch/Request.zig");
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
|
||||||
|
|
||||||
pub const Mime = struct {
|
pub const Mime = struct {
|
||||||
content_type: ContentType,
|
content_type: ContentType,
|
||||||
|
|||||||
@@ -445,13 +445,15 @@ pub fn eventInit(evt: *Event, typ: []const u8, opts: EventInit) !void {
|
|||||||
try DOMErr(err);
|
try DOMErr(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eventType(evt: *Event) ![]const u8 {
|
pub fn eventType(evt: *Event) []const u8 {
|
||||||
var s: ?*String = null;
|
var s: ?*String = null;
|
||||||
const err = c._dom_event_get_type(evt, &s);
|
const err = c._dom_event_get_type(evt, &s);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
|
|
||||||
// if the event type is null, return a empty string.
|
// if the event type is null, return a empty string.
|
||||||
if (s == null) return "";
|
if (s == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
@@ -571,10 +573,10 @@ pub fn mutationEventAttributeName(evt: *MutationEvent) ![]const u8 {
|
|||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mutationEventPrevValue(evt: *MutationEvent) !?[]const u8 {
|
pub fn mutationEventPrevValue(evt: *MutationEvent) ?[]const u8 {
|
||||||
var s: ?*String = null;
|
var s: ?*String = null;
|
||||||
const err = c._dom_mutation_event_get_prev_value(evt, &s);
|
const err = c._dom_mutation_event_get_prev_value(evt, &s);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
if (s == null) return null;
|
if (s == null) return null;
|
||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
@@ -582,7 +584,7 @@ pub fn mutationEventPrevValue(evt: *MutationEvent) !?[]const u8 {
|
|||||||
pub fn mutationEventRelatedNode(evt: *MutationEvent) !?*Node {
|
pub fn mutationEventRelatedNode(evt: *MutationEvent) !?*Node {
|
||||||
var n: NodeExternal = undefined;
|
var n: NodeExternal = undefined;
|
||||||
const err = c._dom_mutation_event_get_related_node(evt, &n);
|
const err = c._dom_mutation_event_get_related_node(evt, &n);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
if (n == null) return null;
|
if (n == null) return null;
|
||||||
return @as(*Node, @ptrCast(@alignCast(n)));
|
return @as(*Node, @ptrCast(@alignCast(n)));
|
||||||
}
|
}
|
||||||
@@ -779,10 +781,10 @@ pub fn eventTargetDispatchEvent(et: *EventTarget, event: *Event) !bool {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eventTargetInternalType(et: *EventTarget) !EventTargetTBase.InternalType {
|
pub fn eventTargetInternalType(et: *EventTarget) EventTargetTBase.InternalType {
|
||||||
var res: u32 = undefined;
|
var res: u32 = undefined;
|
||||||
const err = eventTargetVtable(et).internal_type.?(et, &res);
|
const err = eventTargetVtable(et).internal_type.?(et, &res);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return @enumFromInt(res);
|
return @enumFromInt(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -850,10 +852,8 @@ pub const EventTargetTBase = extern struct {
|
|||||||
pub fn dispatch_event(et: [*c]c.dom_event_target, evt: ?*c.struct_dom_event, res: [*c]bool) callconv(.c) c.dom_exception {
|
pub fn dispatch_event(et: [*c]c.dom_event_target, evt: ?*c.struct_dom_event, res: [*c]bool) callconv(.c) c.dom_exception {
|
||||||
const self = @as(*Self, @ptrCast(et));
|
const self = @as(*Self, @ptrCast(et));
|
||||||
// Set the event target to the target dispatched.
|
// Set the event target to the target dispatched.
|
||||||
const e = c._dom_event_set_target(evt, et);
|
const err = c._dom_event_set_target(evt, et);
|
||||||
if (e != c.DOM_NO_ERR) {
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return e;
|
|
||||||
}
|
|
||||||
return c._dom_event_target_dispatch(et, &self.eti, evt, c.DOM_AT_TARGET, res);
|
return c._dom_event_target_dispatch(et, &self.eti, evt, c.DOM_AT_TARGET, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1046,17 +1046,17 @@ pub const NodeType = enum(u4) {
|
|||||||
// NodeList
|
// NodeList
|
||||||
pub const NodeList = c.dom_nodelist;
|
pub const NodeList = c.dom_nodelist;
|
||||||
|
|
||||||
pub fn nodeListLength(nodeList: *NodeList) !u32 {
|
pub fn nodeListLength(nodeList: *NodeList) u32 {
|
||||||
var ln: u32 = undefined;
|
var ln: u32 = undefined;
|
||||||
const err = c.dom_nodelist_get_length(nodeList, &ln);
|
const err = c.dom_nodelist_get_length(nodeList, &ln);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return ln;
|
return ln;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeListItem(nodeList: *NodeList, index: u32) !?*Node {
|
pub fn nodeListItem(nodeList: *NodeList, index: u32) ?*Node {
|
||||||
var n: NodeExternal = undefined;
|
var n: NodeExternal = undefined;
|
||||||
const err = c._dom_nodelist_item(nodeList, index, &n);
|
const err = c._dom_nodelist_item(nodeList, index, &n);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
if (n == null) return null;
|
if (n == null) return null;
|
||||||
return @as(*Node, @ptrCast(@alignCast(n)));
|
return @as(*Node, @ptrCast(@alignCast(n)));
|
||||||
}
|
}
|
||||||
@@ -1173,88 +1173,86 @@ fn nodeVtable(node: *Node) c.dom_node_vtable {
|
|||||||
pub fn nodeLocalName(node: *Node) ![]const u8 {
|
pub fn nodeLocalName(node: *Node) ![]const u8 {
|
||||||
var s: ?*String = null;
|
var s: ?*String = null;
|
||||||
const err = nodeVtable(node).dom_node_get_local_name.?(node, &s);
|
const err = nodeVtable(node).dom_node_get_local_name.?(node, &s);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
if (s == null) return "";
|
if (s == null) return "";
|
||||||
|
|
||||||
var s_lower: ?*String = null;
|
var s_lower: ?*String = null;
|
||||||
const errStr = c.dom_string_tolower(s, true, &s_lower);
|
const errStr = c.dom_string_tolower(s, true, &s_lower);
|
||||||
try DOMErr(errStr);
|
try DOMErr(errStr);
|
||||||
return strToData(s_lower.?);
|
return strToData(s_lower.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeType(node: *Node) !NodeType {
|
pub fn nodeType(node: *Node) NodeType {
|
||||||
var node_type: c.dom_node_type = undefined;
|
var node_type: c.dom_node_type = undefined;
|
||||||
const err = nodeVtable(node).dom_node_get_node_type.?(node, &node_type);
|
const err = nodeVtable(node).dom_node_get_node_type.?(node, &node_type);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return @as(NodeType, @enumFromInt(node_type));
|
return @as(NodeType, @enumFromInt(node_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeFirstChild(node: *Node) !?*Node {
|
pub fn nodeFirstChild(node: *Node) ?*Node {
|
||||||
var res: ?*Node = null;
|
var res: ?*Node = null;
|
||||||
const err = nodeVtable(node).dom_node_get_first_child.?(node, &res);
|
const err = nodeVtable(node).dom_node_get_first_child.?(node, &res);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeLastChild(node: *Node) !?*Node {
|
pub fn nodeLastChild(node: *Node) ?*Node {
|
||||||
var res: ?*Node = null;
|
var res: ?*Node = null;
|
||||||
const err = nodeVtable(node).dom_node_get_last_child.?(node, &res);
|
const err = nodeVtable(node).dom_node_get_last_child.?(node, &res);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeNextSibling(node: *Node) !?*Node {
|
pub fn nodeNextSibling(node: *Node) ?*Node {
|
||||||
var res: ?*Node = null;
|
var res: ?*Node = null;
|
||||||
const err = nodeVtable(node).dom_node_get_next_sibling.?(node, &res);
|
const err = nodeVtable(node).dom_node_get_next_sibling.?(node, &res);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeNextElementSibling(node: *Node) !?*Element {
|
pub fn nodeNextElementSibling(node: *Node) ?*Element {
|
||||||
var n = node;
|
var n = node;
|
||||||
while (true) {
|
while (true) {
|
||||||
const res = try nodeNextSibling(n);
|
const res = nodeNextSibling(n) orelse return null;
|
||||||
if (res == null) return null;
|
|
||||||
|
|
||||||
if (try nodeType(res.?) == .element) {
|
if (nodeType(res) == .element) {
|
||||||
return @as(*Element, @ptrCast(res.?));
|
return @as(*Element, @ptrCast(res));
|
||||||
}
|
}
|
||||||
n = res.?;
|
n = res;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodePreviousSibling(node: *Node) !?*Node {
|
pub fn nodePreviousSibling(node: *Node) ?*Node {
|
||||||
var res: ?*Node = null;
|
var res: ?*Node = null;
|
||||||
const err = nodeVtable(node).dom_node_get_previous_sibling.?(node, &res);
|
const err = nodeVtable(node).dom_node_get_previous_sibling.?(node, &res);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodePreviousElementSibling(node: *Node) !?*Element {
|
pub fn nodePreviousElementSibling(node: *Node) ?*Element {
|
||||||
var n = node;
|
var n = node;
|
||||||
while (true) {
|
while (true) {
|
||||||
const res = try nodePreviousSibling(n);
|
const res = nodePreviousSibling(n) orelse return null;
|
||||||
if (res == null) return null;
|
if (nodeType(res) == .element) {
|
||||||
|
return @as(*Element, @ptrCast(res));
|
||||||
if (try nodeType(res.?) == .element) {
|
|
||||||
return @as(*Element, @ptrCast(res.?));
|
|
||||||
}
|
}
|
||||||
n = res.?;
|
n = res;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeParentNode(node: *Node) !?*Node {
|
pub fn nodeParentNode(node: *Node) ?*Node {
|
||||||
var res: ?*Node = null;
|
var res: ?*Node = null;
|
||||||
const err = nodeVtable(node).dom_node_get_parent_node.?(node, &res);
|
const err = nodeVtable(node).dom_node_get_parent_node.?(node, &res);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeParentElement(node: *Node) !?*Element {
|
pub fn nodeParentElement(node: *Node) ?*Element {
|
||||||
const res = try nodeParentNode(node);
|
const res = nodeParentNode(node);
|
||||||
if (res) |value| {
|
if (res) |value| {
|
||||||
if (try nodeType(value) == .element) {
|
if (nodeType(value) == .element) {
|
||||||
return @as(*Element, @ptrCast(value));
|
return @as(*Element, @ptrCast(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1269,17 +1267,17 @@ pub fn nodeName(node: *Node) ![]const u8 {
|
|||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeOwnerDocument(node: *Node) !?*Document {
|
pub fn nodeOwnerDocument(node: *Node) ?*Document {
|
||||||
var doc: ?*Document = null;
|
var doc: ?*Document = null;
|
||||||
const err = nodeVtable(node).dom_node_get_owner_document.?(node, &doc);
|
const err = nodeVtable(node).dom_node_get_owner_document.?(node, &doc);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeValue(node: *Node) !?[]const u8 {
|
pub fn nodeValue(node: *Node) ?[]const u8 {
|
||||||
var s: ?*String = null;
|
var s: ?*String = null;
|
||||||
const err = nodeVtable(node).dom_node_get_node_value.?(node, &s);
|
const err = nodeVtable(node).dom_node_get_node_value.?(node, &s);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
if (s == null) return null;
|
if (s == null) return null;
|
||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
@@ -1290,14 +1288,14 @@ pub fn nodeSetValue(node: *Node, value: []const u8) !void {
|
|||||||
try DOMErr(err);
|
try DOMErr(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeTextContent(node: *Node) !?[]const u8 {
|
pub fn nodeTextContent(node: *Node) ?[]const u8 {
|
||||||
var s: ?*String = null;
|
var s: ?*String = null;
|
||||||
const err = nodeVtable(node).dom_node_get_text_content.?(node, &s);
|
const err = nodeVtable(node).dom_node_get_text_content.?(node, &s);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
// NOTE: it seems that there is a bug in netsurf implem
|
// NOTE: it seems that there is a bug in netsurf implem
|
||||||
// an empty Element should return an empty string and not null
|
// an empty Element should return an empty string and not null
|
||||||
if (try nodeType(node) == .element) {
|
if (nodeType(node) == .element) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -1318,10 +1316,10 @@ pub fn nodeGetChildNodes(node: *Node) !*NodeList {
|
|||||||
return nlist.?;
|
return nlist.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeGetRootNode(node: *Node) !*Node {
|
pub fn nodeGetRootNode(node: *Node) *Node {
|
||||||
var root = node;
|
var root = node;
|
||||||
while (true) {
|
while (true) {
|
||||||
const parent = try nodeParentNode(root);
|
const parent = nodeParentNode(root);
|
||||||
if (parent) |parent_| {
|
if (parent) |parent_| {
|
||||||
root = parent_;
|
root = parent_;
|
||||||
} else break;
|
} else break;
|
||||||
@@ -1343,17 +1341,17 @@ pub fn nodeCloneNode(node: *Node, is_deep: bool) !*Node {
|
|||||||
return res.?;
|
return res.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeContains(node: *Node, other: *Node) !bool {
|
pub fn nodeContains(node: *Node, other: *Node) bool {
|
||||||
var res: bool = undefined;
|
var res: bool = undefined;
|
||||||
const err = c._dom_node_contains(node, other, &res);
|
const err = c._dom_node_contains(node, other, &res);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeHasChildNodes(node: *Node) !bool {
|
pub fn nodeHasChildNodes(node: *Node) bool {
|
||||||
var res: bool = undefined;
|
var res: bool = undefined;
|
||||||
const err = nodeVtable(node).dom_node_has_child_nodes.?(node, &res);
|
const err = nodeVtable(node).dom_node_has_child_nodes.?(node, &res);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1368,7 +1366,7 @@ pub fn nodeIsDefaultNamespace(node: *Node, namespace_: ?[]const u8) !bool {
|
|||||||
const s = if (namespace_) |n| try strFromData(n) else null;
|
const s = if (namespace_) |n| try strFromData(n) else null;
|
||||||
var res: bool = undefined;
|
var res: bool = undefined;
|
||||||
const err = nodeVtable(node).dom_node_is_default_namespace.?(node, s, &res);
|
const err = nodeVtable(node).dom_node_is_default_namespace.?(node, s, &res);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1379,10 +1377,10 @@ pub fn nodeIsEqualNode(node: *Node, other: *Node) !bool {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeIsSameNode(node: *Node, other: *Node) !bool {
|
pub fn nodeIsSameNode(node: *Node, other: *Node) bool {
|
||||||
var res: bool = undefined;
|
var res: bool = undefined;
|
||||||
const err = nodeVtable(node).dom_node_is_same.?(node, other, &res);
|
const err = nodeVtable(node).dom_node_is_same.?(node, other, &res);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1422,13 +1420,6 @@ pub fn nodeReplaceChild(node: *Node, new_child: *Node, old_child: *Node) !*Node
|
|||||||
return res.?;
|
return res.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeHasAttributes(node: *Node) !bool {
|
|
||||||
var res: bool = undefined;
|
|
||||||
const err = nodeVtable(node).dom_node_has_attributes.?(node, &res);
|
|
||||||
try DOMErr(err);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn nodeGetAttributes(node: *Node) !?*NamedNodeMap {
|
pub fn nodeGetAttributes(node: *Node) !?*NamedNodeMap {
|
||||||
var res: ?*NamedNodeMap = null;
|
var res: ?*NamedNodeMap = null;
|
||||||
const err = nodeVtable(node).dom_node_get_attributes.?(node, &res);
|
const err = nodeVtable(node).dom_node_get_attributes.?(node, &res);
|
||||||
@@ -1436,18 +1427,18 @@ pub fn nodeGetAttributes(node: *Node) !?*NamedNodeMap {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeGetNamespace(node: *Node) !?[]const u8 {
|
pub fn nodeGetNamespace(node: *Node) ?[]const u8 {
|
||||||
var s: ?*String = null;
|
var s: ?*String = null;
|
||||||
const err = nodeVtable(node).dom_node_get_namespace.?(node, &s);
|
const err = nodeVtable(node).dom_node_get_namespace.?(node, &s);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
if (s == null) return null;
|
if (s == null) return null;
|
||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodeGetPrefix(node: *Node) !?[]const u8 {
|
pub fn nodeGetPrefix(node: *Node) ?[]const u8 {
|
||||||
var s: ?*String = null;
|
var s: ?*String = null;
|
||||||
const err = nodeVtable(node).dom_node_get_prefix.?(node, &s);
|
const err = nodeVtable(node).dom_node_get_prefix.?(node, &s);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
if (s == null) return null;
|
if (s == null) return null;
|
||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
@@ -1463,7 +1454,8 @@ pub fn nodeSetEmbedderData(node: *Node, data: *anyopaque) void {
|
|||||||
pub fn nodeGetElementById(node: *Node, id: []const u8) !?*Element {
|
pub fn nodeGetElementById(node: *Node, id: []const u8) !?*Element {
|
||||||
var el: ?*Element = null;
|
var el: ?*Element = null;
|
||||||
const str_id = try strFromData(id);
|
const str_id = try strFromData(id);
|
||||||
try DOMErr(c._dom_find_element_by_id(node, str_id, &el));
|
const err = c._dom_find_element_by_id(node, str_id, &el);
|
||||||
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1479,7 +1471,7 @@ pub inline fn nodeToDocument(node: *Node) *Document {
|
|||||||
|
|
||||||
// Combination of nodeToElement + elementTag
|
// Combination of nodeToElement + elementTag
|
||||||
pub fn nodeHTMLGetTagType(node: *Node) !?Tag {
|
pub fn nodeHTMLGetTagType(node: *Node) !?Tag {
|
||||||
if (try nodeType(node) != .element) {
|
if (nodeType(node) != .element) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1497,10 +1489,10 @@ pub inline fn characterDataToNode(cdata: *CharacterData) *Node {
|
|||||||
return @as(*Node, @ptrCast(@alignCast(cdata)));
|
return @as(*Node, @ptrCast(@alignCast(cdata)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn characterDataData(cdata: *CharacterData) ![]const u8 {
|
pub fn characterDataData(cdata: *CharacterData) []const u8 {
|
||||||
var s: ?*String = null;
|
var s: ?*String = null;
|
||||||
const err = characterDataVtable(cdata).dom_characterdata_get_data.?(cdata, &s);
|
const err = characterDataVtable(cdata).dom_characterdata_get_data.?(cdata, &s);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1513,7 +1505,7 @@ pub fn characterDataSetData(cdata: *CharacterData, data: []const u8) !void {
|
|||||||
pub fn characterDataLength(cdata: *CharacterData) !u32 {
|
pub fn characterDataLength(cdata: *CharacterData) !u32 {
|
||||||
var n: u32 = undefined;
|
var n: u32 = undefined;
|
||||||
const err = characterDataVtable(cdata).dom_characterdata_get_length.?(cdata, &n);
|
const err = characterDataVtable(cdata).dom_characterdata_get_length.?(cdata, &n);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2070,17 +2062,17 @@ pub inline fn documentTypeGetName(dt: *DocumentType) ![]const u8 {
|
|||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn documentTypeGetPublicId(dt: *DocumentType) ![]const u8 {
|
pub inline fn documentTypeGetPublicId(dt: *DocumentType) []const u8 {
|
||||||
var s: ?*String = null;
|
var s: ?*String = null;
|
||||||
const err = documentTypeVtable(dt).dom_document_type_get_public_id.?(dt, &s);
|
const err = documentTypeVtable(dt).dom_document_type_get_public_id.?(dt, &s);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn documentTypeGetSystemId(dt: *DocumentType) ![]const u8 {
|
pub inline fn documentTypeGetSystemId(dt: *DocumentType) []const u8 {
|
||||||
var s: ?*String = null;
|
var s: ?*String = null;
|
||||||
const err = documentTypeVtable(dt).dom_document_type_get_system_id.?(dt, &s);
|
const err = documentTypeVtable(dt).dom_document_type_get_system_id.?(dt, &s);
|
||||||
try DOMErr(err);
|
std.debug.assert(err == c.DOM_NO_ERR);
|
||||||
return strToData(s.?);
|
return strToData(s.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -198,12 +198,12 @@ pub const Page = struct {
|
|||||||
// returns the <pre> element from the HTML
|
// returns the <pre> element from the HTML
|
||||||
const doc = parser.documentHTMLToDocument(self.window.document);
|
const doc = parser.documentHTMLToDocument(self.window.document);
|
||||||
const list = try parser.documentGetElementsByTagName(doc, "pre");
|
const list = try parser.documentGetElementsByTagName(doc, "pre");
|
||||||
const pre = try parser.nodeListItem(list, 0) orelse return error.InvalidHTML;
|
const pre = parser.nodeListItem(list, 0) orelse return error.InvalidHTML;
|
||||||
const walker = Walker{};
|
const walker = Walker{};
|
||||||
var next: ?*parser.Node = null;
|
var next: ?*parser.Node = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
next = try walker.get_next(pre, next) orelse break;
|
next = try walker.get_next(pre, next) orelse break;
|
||||||
const v = try parser.nodeTextContent(next.?) orelse return;
|
const v = parser.nodeTextContent(next.?) orelse return;
|
||||||
try out.writeAll(v);
|
try out.writeAll(v);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -241,7 +241,7 @@ pub const Page = struct {
|
|||||||
|
|
||||||
// find <head> tag
|
// find <head> tag
|
||||||
const list = try parser.documentGetElementsByTagName(doc, "head");
|
const list = try parser.documentGetElementsByTagName(doc, "head");
|
||||||
const head = try parser.nodeListItem(list, 0) orelse return;
|
const head = parser.nodeListItem(list, 0) orelse return;
|
||||||
|
|
||||||
const base = try parser.documentCreateElement(doc, "base");
|
const base = try parser.documentCreateElement(doc, "base");
|
||||||
try parser.elementSetAttribute(base, "href", self.url.raw);
|
try parser.elementSetAttribute(base, "href", self.url.raw);
|
||||||
@@ -1076,9 +1076,9 @@ pub const Page = struct {
|
|||||||
try self.navigateFromWebAPI(action, opts);
|
try self.navigateFromWebAPI(action, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isNodeAttached(self: *const Page, node: *parser.Node) !bool {
|
pub fn isNodeAttached(self: *const Page, node: *parser.Node) bool {
|
||||||
const root = parser.documentToNode(parser.documentHTMLToDocument(self.window.document));
|
const root = parser.documentToNode(parser.documentHTMLToDocument(self.window.document));
|
||||||
return root == try parser.nodeGetRootNode(node);
|
return root == parser.nodeGetRootNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn elementSubmitForm(self: *Page, element: *parser.Element) !void {
|
fn elementSubmitForm(self: *Page, element: *parser.Element) !void {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ const Allocator = std.mem.Allocator;
|
|||||||
|
|
||||||
const Env = @import("env.zig").Env;
|
const Env = @import("env.zig").Env;
|
||||||
const Page = @import("page.zig").Page;
|
const Page = @import("page.zig").Page;
|
||||||
const URL = @import("../url.zig").URL;
|
|
||||||
const Browser = @import("browser.zig").Browser;
|
const Browser = @import("browser.zig").Browser;
|
||||||
const NavigateOpts = @import("page.zig").NavigateOpts;
|
const NavigateOpts = @import("page.zig").NavigateOpts;
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const DOMError = @import("../netsurf.zig").DOMError;
|
|
||||||
|
|
||||||
pub const cookie = @import("cookie.zig");
|
pub const cookie = @import("cookie.zig");
|
||||||
pub const Cookie = cookie.Cookie;
|
pub const Cookie = cookie.Cookie;
|
||||||
pub const CookieJar = cookie.Jar;
|
pub const CookieJar = cookie.Jar;
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ const parser = @import("../netsurf.zig");
|
|||||||
const Env = @import("../env.zig").Env;
|
const Env = @import("../env.zig").Env;
|
||||||
const Page = @import("../page.zig").Page;
|
const Page = @import("../page.zig").Page;
|
||||||
const FormData = @import("../xhr/form_data.zig").FormData;
|
const FormData = @import("../xhr/form_data.zig").FormData;
|
||||||
const HTMLElement = @import("../html/elements.zig").HTMLElement;
|
|
||||||
|
|
||||||
const kv = @import("../key_value.zig");
|
const kv = @import("../key_value.zig");
|
||||||
const iterator = @import("../iterator/iterator.zig");
|
const iterator = @import("../iterator/iterator.zig");
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ const Mime = @import("../mime.zig").Mime;
|
|||||||
const parser = @import("../netsurf.zig");
|
const parser = @import("../netsurf.zig");
|
||||||
const Page = @import("../page.zig").Page;
|
const Page = @import("../page.zig").Page;
|
||||||
const Http = @import("../../http/Http.zig");
|
const Http = @import("../../http/Http.zig");
|
||||||
const CookieJar = @import("../storage/storage.zig").CookieJar;
|
|
||||||
|
|
||||||
// XHR interfaces
|
// XHR interfaces
|
||||||
// https://xhr.spec.whatwg.org/#interface-xmlhttprequest
|
// https://xhr.spec.whatwg.org/#interface-xmlhttprequest
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub const XMLSerializer = struct {
|
|||||||
|
|
||||||
pub fn _serializeToString(_: *const XMLSerializer, root: *parser.Node, page: *Page) ![]const u8 {
|
pub fn _serializeToString(_: *const XMLSerializer, root: *parser.Node, page: *Page) ![]const u8 {
|
||||||
var aw = std.Io.Writer.Allocating.init(page.call_arena);
|
var aw = std.Io.Writer.Allocating.init(page.call_arena);
|
||||||
switch (try parser.nodeType(root)) {
|
switch (parser.nodeType(root)) {
|
||||||
.document => try dump.writeHTML(@as(*parser.Document, @ptrCast(root)), .{}, &aw.writer),
|
.document => try dump.writeHTML(@as(*parser.Document, @ptrCast(root)), .{}, &aw.writer),
|
||||||
.document_type => try dump.writeDocType(@as(*parser.DocumentType, @ptrCast(root)), &aw.writer),
|
.document_type => try dump.writeDocType(@as(*parser.DocumentType, @ptrCast(root)), &aw.writer),
|
||||||
else => try dump.writeNode(root, .{}, &aw.writer),
|
else => try dump.writeNode(root, .{}, &aw.writer),
|
||||||
|
|||||||
@@ -243,13 +243,13 @@ pub const Writer = struct {
|
|||||||
fn writeChildren(self: *const Writer, node: *const Node, depth: usize, w: anytype) anyerror!usize {
|
fn writeChildren(self: *const Writer, node: *const Node, depth: usize, w: anytype) anyerror!usize {
|
||||||
var registry = self.registry;
|
var registry = self.registry;
|
||||||
const child_nodes = try parser.nodeGetChildNodes(node._node);
|
const child_nodes = try parser.nodeGetChildNodes(node._node);
|
||||||
const child_count = try parser.nodeListLength(child_nodes);
|
const child_count = parser.nodeListLength(child_nodes);
|
||||||
const full_child = self.depth < 0 or self.depth < depth;
|
const full_child = self.depth < 0 or self.depth < depth;
|
||||||
|
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
try w.beginArray();
|
try w.beginArray();
|
||||||
for (0..child_count) |_| {
|
for (0..child_count) |_| {
|
||||||
const child = (try parser.nodeListItem(child_nodes, @intCast(i))) orelse break;
|
const child = (parser.nodeListItem(child_nodes, @intCast(i))) orelse break;
|
||||||
const child_node = try registry.register(child);
|
const child_node = try registry.register(child);
|
||||||
if (full_child) {
|
if (full_child) {
|
||||||
try self.toJSON(child_node, depth + 1, w);
|
try self.toJSON(child_node, depth + 1, w);
|
||||||
@@ -275,7 +275,7 @@ pub const Writer = struct {
|
|||||||
|
|
||||||
const n = node._node;
|
const n = node._node;
|
||||||
|
|
||||||
if (try parser.nodeParentNode(n)) |p| {
|
if (parser.nodeParentNode(n)) |p| {
|
||||||
const parent_node = try self.registry.register(p);
|
const parent_node = try self.registry.register(p);
|
||||||
try w.objectField("parentId");
|
try w.objectField("parentId");
|
||||||
try w.write(parent_node.id);
|
try w.write(parent_node.id);
|
||||||
@@ -295,7 +295,7 @@ pub const Writer = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try w.objectField("nodeType");
|
try w.objectField("nodeType");
|
||||||
try w.write(@intFromEnum(try parser.nodeType(n)));
|
try w.write(@intFromEnum(parser.nodeType(n)));
|
||||||
|
|
||||||
try w.objectField("nodeName");
|
try w.objectField("nodeName");
|
||||||
try w.write(try parser.nodeName(n));
|
try w.write(try parser.nodeName(n));
|
||||||
@@ -304,12 +304,12 @@ pub const Writer = struct {
|
|||||||
try w.write(try parser.nodeLocalName(n));
|
try w.write(try parser.nodeLocalName(n));
|
||||||
|
|
||||||
try w.objectField("nodeValue");
|
try w.objectField("nodeValue");
|
||||||
try w.write((try parser.nodeValue(n)) orelse "");
|
try w.write((parser.nodeValue(n)) orelse "");
|
||||||
|
|
||||||
if (include_child_count) {
|
if (include_child_count) {
|
||||||
try w.objectField("childNodeCount");
|
try w.objectField("childNodeCount");
|
||||||
const child_nodes = try parser.nodeGetChildNodes(n);
|
const child_nodes = try parser.nodeGetChildNodes(n);
|
||||||
try w.write(try parser.nodeListLength(child_nodes));
|
try w.write(parser.nodeListLength(child_nodes));
|
||||||
}
|
}
|
||||||
|
|
||||||
try w.objectField("documentURL");
|
try w.objectField("documentURL");
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ const Page = @import("../browser/page.zig").Page;
|
|||||||
const Inspector = @import("../browser/env.zig").Env.Inspector;
|
const Inspector = @import("../browser/env.zig").Env.Inspector;
|
||||||
const Incrementing = @import("../id.zig").Incrementing;
|
const Incrementing = @import("../id.zig").Incrementing;
|
||||||
const Notification = @import("../notification.zig").Notification;
|
const Notification = @import("../notification.zig").Notification;
|
||||||
const NetworkState = @import("domains/network.zig").NetworkState;
|
|
||||||
const InterceptState = @import("domains/fetch.zig").InterceptState;
|
const InterceptState = @import("domains/fetch.zig").InterceptState;
|
||||||
|
|
||||||
const polyfill = @import("../browser/polyfill/polyfill.zig");
|
const polyfill = @import("../browser/polyfill/polyfill.zig");
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
|
|||||||
for (nodes) |_n| {
|
for (nodes) |_n| {
|
||||||
var n = _n;
|
var n = _n;
|
||||||
while (true) {
|
while (true) {
|
||||||
const p = try parser.nodeParentNode(n) orelse break;
|
const p = parser.nodeParentNode(n) orelse break;
|
||||||
|
|
||||||
// Register the node.
|
// Register the node.
|
||||||
const node = try bc.node_registry.register(p);
|
const node = try bc.node_registry.register(p);
|
||||||
@@ -151,7 +151,7 @@ fn dispatchSetChildNodes(cmd: anytype, nodes: []*parser.Node) !void {
|
|||||||
// If the node has no parent, it's the root node.
|
// If the node has no parent, it's the root node.
|
||||||
// We don't dispatch event for it because we assume the root node is
|
// We don't dispatch event for it because we assume the root node is
|
||||||
// dispatched via the DOM.getDocument command.
|
// dispatched via the DOM.getDocument command.
|
||||||
const p = try parser.nodeParentNode(node._node) orelse {
|
const p = parser.nodeParentNode(node._node) orelse {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -368,7 +368,7 @@ fn scrollIntoViewIfNeeded(cmd: anytype) !void {
|
|||||||
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
||||||
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
|
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
|
||||||
|
|
||||||
const node_type = parser.nodeType(node._node) catch return error.InvalidNode;
|
const node_type = parser.nodeType(node._node);
|
||||||
switch (node_type) {
|
switch (node_type) {
|
||||||
.element => {},
|
.element => {},
|
||||||
.document => {},
|
.document => {},
|
||||||
@@ -410,7 +410,7 @@ fn getContentQuads(cmd: anytype) !void {
|
|||||||
// visibility: hidden
|
// visibility: hidden
|
||||||
// display: none
|
// display: none
|
||||||
|
|
||||||
if (try parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
|
if (parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
|
||||||
// TODO implement for document or text
|
// TODO implement for document or text
|
||||||
// Most likely document would require some hierachgy in the renderer. It is left unimplemented till we have a good example.
|
// Most likely document would require some hierachgy in the renderer. It is left unimplemented till we have a good example.
|
||||||
// Text may be tricky, multiple quads in case of multiple lines? empty quads of text = ""?
|
// Text may be tricky, multiple quads in case of multiple lines? empty quads of text = ""?
|
||||||
@@ -436,7 +436,7 @@ fn getBoxModel(cmd: anytype) !void {
|
|||||||
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
|
const node = try getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);
|
||||||
|
|
||||||
// TODO implement for document or text
|
// TODO implement for document or text
|
||||||
if (try parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
|
if (parser.nodeType(node._node) != .element) return error.NodeIsNotAnElement;
|
||||||
const element = parser.nodeToElement(node._node);
|
const element = parser.nodeToElement(node._node);
|
||||||
|
|
||||||
const rect = try Element._getBoundingClientRect(element, page);
|
const rect = try Element._getBoundingClientRect(element, page);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
|
||||||
const log = @import("../../log.zig");
|
|
||||||
const CdpStorage = @import("storage.zig");
|
const CdpStorage = @import("storage.zig");
|
||||||
const Transfer = @import("../../http/Client.zig").Transfer;
|
const Transfer = @import("../../http/Client.zig").Transfer;
|
||||||
const Notification = @import("../../notification.zig").Notification;
|
const Notification = @import("../../notification.zig").Notification;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const URL = @import("../../url.zig").URL;
|
|
||||||
const Page = @import("../../browser/page.zig").Page;
|
const Page = @import("../../browser/page.zig").Page;
|
||||||
const Notification = @import("../../notification.zig").Notification;
|
const Notification = @import("../../notification.zig").Notification;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
|
||||||
|
|
||||||
const log = @import("../../log.zig");
|
const log = @import("../../log.zig");
|
||||||
const Cookie = @import("../../browser/storage/storage.zig").Cookie;
|
const Cookie = @import("../../browser/storage/storage.zig").Cookie;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ const ArenaAllocator = std.heap.ArenaAllocator;
|
|||||||
const Testing = @This();
|
const Testing = @This();
|
||||||
|
|
||||||
const main = @import("cdp.zig");
|
const main = @import("cdp.zig");
|
||||||
const App = @import("../app.zig").App;
|
|
||||||
const parser = @import("../browser/netsurf.zig");
|
const parser = @import("../browser/netsurf.zig");
|
||||||
|
|
||||||
const base = @import("../testing.zig");
|
const base = @import("../testing.zig");
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ const std = @import("std");
|
|||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
const Thread = std.Thread;
|
const Thread = std.Thread;
|
||||||
const Allocator = std.mem.Allocator;
|
|
||||||
|
|
||||||
const is_debug = builtin.mode == .Debug;
|
const is_debug = builtin.mode == .Debug;
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,10 @@ const Allocator = std.mem.Allocator;
|
|||||||
|
|
||||||
const log = @import("log.zig");
|
const log = @import("log.zig");
|
||||||
const App = @import("app.zig").App;
|
const App = @import("app.zig").App;
|
||||||
const Http = @import("http/Http.zig");
|
|
||||||
const Server = @import("server.zig").Server;
|
const Server = @import("server.zig").Server;
|
||||||
const Browser = @import("browser/browser.zig").Browser;
|
const Browser = @import("browser/browser.zig").Browser;
|
||||||
|
|
||||||
const build_config = @import("build_config");
|
const build_config = @import("build_config");
|
||||||
const parser = @import("browser/netsurf.zig");
|
|
||||||
|
|
||||||
var _app: ?*App = null;
|
var _app: ?*App = null;
|
||||||
var _server: ?Server = null;
|
var _server: ?Server = null;
|
||||||
|
|||||||
@@ -27,9 +27,6 @@ const Env = @import("browser/env.zig").Env;
|
|||||||
const Browser = @import("browser/browser.zig").Browser;
|
const Browser = @import("browser/browser.zig").Browser;
|
||||||
const TestHTTPServer = @import("TestHTTPServer.zig");
|
const TestHTTPServer = @import("TestHTTPServer.zig");
|
||||||
|
|
||||||
const parser = @import("browser/netsurf.zig");
|
|
||||||
const polyfill = @import("browser/polyfill/polyfill.zig");
|
|
||||||
|
|
||||||
const WPT_DIR = "tests/wpt";
|
const WPT_DIR = "tests/wpt";
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const log = @import("log.zig");
|
const log = @import("log.zig");
|
||||||
const URL = @import("url.zig").URL;
|
|
||||||
const page = @import("browser/page.zig");
|
const page = @import("browser/page.zig");
|
||||||
const Http = @import("http/Http.zig");
|
|
||||||
const Transfer = @import("http/Client.zig").Transfer;
|
const Transfer = @import("http/Client.zig").Transfer;
|
||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
|||||||
@@ -2954,7 +2954,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
|||||||
}
|
}
|
||||||
return v8.initNull(isolate).toValue();
|
return v8.initNull(isolate).toValue();
|
||||||
},
|
},
|
||||||
.error_union => return zigValueToJs(templates, isolate, v8_context, value catch |err| return err),
|
.error_union => return zigValueToJs(templates, isolate, v8_context, try value),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ const log = @import("log.zig");
|
|||||||
const App = @import("app.zig").App;
|
const App = @import("app.zig").App;
|
||||||
const CDP = @import("cdp/cdp.zig").CDP;
|
const CDP = @import("cdp/cdp.zig").CDP;
|
||||||
|
|
||||||
const TimeoutCheck = std.time.ns_per_ms * 100;
|
|
||||||
|
|
||||||
const MAX_HTTP_REQUEST_SIZE = 4096;
|
const MAX_HTTP_REQUEST_SIZE = 4096;
|
||||||
|
|
||||||
// max message size
|
// max message size
|
||||||
|
|||||||
@@ -19,8 +19,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
|
||||||
const Platform = @import("runtime/js.zig").Platform;
|
|
||||||
|
|
||||||
pub const allocator = std.testing.allocator;
|
pub const allocator = std.testing.allocator;
|
||||||
pub const expectError = std.testing.expectError;
|
pub const expectError = std.testing.expectError;
|
||||||
pub const expect = std.testing.expect;
|
pub const expect = std.testing.expect;
|
||||||
|
|||||||
Reference in New Issue
Block a user