Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/browser/Scheduler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

const std = @import("std");
const log = @import("../log.zig");
const Allocator = std.mem.Allocator;

const Scheduler = @This();
Expand Down
2 changes: 1 addition & 1 deletion src/browser/ScriptManager.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
source = .{ .remote = .{} };
} else {
const inline_source = try parser.nodeTextContent(@ptrCast(element)) orelse return;
const inline_source = parser.nodeTextContent(@ptrCast(element)) orelse return;
source = .{ .@"inline" = inline_source };
}

Expand Down
1 change: 0 additions & 1 deletion src/browser/State.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const parser = @import("netsurf.zig");
const DataSet = @import("html/DataSet.zig");
const ShadowRoot = @import("dom/shadow_root.zig").ShadowRoot;
const StyleSheet = @import("cssom/StyleSheet.zig");
const CSSStyleSheet = @import("cssom/CSSStyleSheet.zig");
const CSSStyleDeclaration = @import("cssom/CSSStyleDeclaration.zig");

// for HTMLScript (but probably needs to be added to more)
Expand Down
1 change: 0 additions & 1 deletion src/browser/console/console.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const std = @import("std");
const builtin = @import("builtin");
const log = @import("../../log.zig");

const Allocator = std.mem.Allocator;
const Page = @import("../page.zig").Page;
const JsObject = @import("../env.zig").Env.JsObject;

Expand Down
26 changes: 11 additions & 15 deletions src/browser/css/css.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,27 @@ 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
// descendants of n and returns true. If none matches, it returns false.
pub fn matchFirst(s: *const Selector, node: anytype, m: anytype) !bool {
var c = try node.firstChild();
while (true) {
if (c == null) break;

if (try s.match(c.?)) {
try m.match(c.?);
var child = node.firstChild();
while (child) |c| {
if (try s.match(c)) {
try m.match(c);
return true;
}

if (try matchFirst(s, c.?, m)) return true;
c = try c.?.nextSibling();
if (try matchFirst(s, c, m)) return true;
child = c.nextSibling();
}
return false;
}

// matchAll call m.match with the all the nodes that matches the selector s, from the
// descendants of n.
pub fn matchAll(s: *const Selector, node: anytype, m: anytype) !void {
var c = try node.firstChild();
while (true) {
if (c == null) break;

if (try s.match(c.?)) try m.match(c.?);
try matchAll(s, c.?, m);
c = try c.?.nextSibling();
var child = node.firstChild();
while (child) |c| {
if (try s.match(c)) try m.match(c);
try matchAll(s, c, m);
child = c.nextSibling();
}
}

Expand Down
42 changes: 19 additions & 23 deletions src/browser/css/libdom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,79 +26,75 @@ const Allocator = std.mem.Allocator;
pub const Node = struct {
node: *parser.Node,

pub fn firstChild(n: Node) !?Node {
const c = try parser.nodeFirstChild(n.node);
pub fn firstChild(n: Node) ?Node {
const c = parser.nodeFirstChild(n.node);
if (c) |cc| return .{ .node = cc };

return null;
}

pub fn lastChild(n: Node) !?Node {
const c = try parser.nodeLastChild(n.node);
pub fn lastChild(n: Node) ?Node {
const c = parser.nodeLastChild(n.node);
if (c) |cc| return .{ .node = cc };

return null;
}

pub fn nextSibling(n: Node) !?Node {
const c = try parser.nodeNextSibling(n.node);
pub fn nextSibling(n: Node) ?Node {
const c = parser.nodeNextSibling(n.node);
if (c) |cc| return .{ .node = cc };

return null;
}

pub fn prevSibling(n: Node) !?Node {
const c = try parser.nodePreviousSibling(n.node);
pub fn prevSibling(n: Node) ?Node {
const c = parser.nodePreviousSibling(n.node);
if (c) |cc| return .{ .node = cc };

return null;
}

pub fn parent(n: Node) !?Node {
const c = try parser.nodeParentNode(n.node);
pub fn parent(n: Node) ?Node {
const c = parser.nodeParentNode(n.node);
if (c) |cc| return .{ .node = cc };

return null;
}

pub fn isElement(n: Node) bool {
const t = parser.nodeType(n.node) catch return false;
return t == .element;
return parser.nodeType(n.node) == .element;
}

pub fn isDocument(n: Node) bool {
const t = parser.nodeType(n.node) catch return false;
return t == .document;
return parser.nodeType(n.node) == .document;
}

pub fn isComment(n: Node) bool {
const t = parser.nodeType(n.node) catch return false;
return t == .comment;
return parser.nodeType(n.node) == .comment;
}

pub fn isText(n: Node) bool {
const t = parser.nodeType(n.node) catch return false;
return t == .text;
return parser.nodeType(n.node) == .text;
}

pub fn text(n: Node) !?[]const u8 {
const data = try parser.nodeTextContent(n.node);
pub fn text(n: Node) ?[]const u8 {
const data = parser.nodeTextContent(n.node);
if (data == null) return null;
if (data.?.len == 0) return null;

return std.mem.trim(u8, data.?, &std.ascii.whitespace);
}

pub fn isEmptyText(n: Node) !bool {
const data = try parser.nodeTextContent(n.node);
pub fn isEmptyText(n: Node) bool {
const data = parser.nodeTextContent(n.node);
if (data == null) return true;
if (data.?.len == 0) return true;

return std.mem.trim(u8, data.?, &std.ascii.whitespace).len == 0;
}

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 {
Expand Down
Loading