mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
css: add isDocument, isText and isComment
This commit is contained in:
@@ -46,6 +46,21 @@ pub const Node = struct {
|
||||
return t == .element;
|
||||
}
|
||||
|
||||
pub fn isDocument(n: Node) bool {
|
||||
const t = parser.nodeType(n.node) catch return false;
|
||||
return t == .document;
|
||||
}
|
||||
|
||||
pub fn isComment(n: Node) bool {
|
||||
const t = parser.nodeType(n.node) catch return false;
|
||||
return t == .comment;
|
||||
}
|
||||
|
||||
pub fn isText(n: Node) bool {
|
||||
const t = parser.nodeType(n.node) catch return false;
|
||||
return t == .text;
|
||||
}
|
||||
|
||||
pub fn tag(n: Node) ![]const u8 {
|
||||
return try parser.nodeName(n.node);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,18 @@ pub const Node = struct {
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn isDocument(_: *const Node) bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn isComment(_: *const Node) bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn isText(_: *const Node) bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn tag(n: *const Node) ![]const u8 {
|
||||
return n.name;
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ pub const Selector = union(enum) {
|
||||
if (!try v.second.match(n)) return false;
|
||||
var c = try n.prevSibling();
|
||||
while (c != null) {
|
||||
if (!c.?.isElement()) { // TODO must check text node or comment node instead.
|
||||
if (c.?.isText() or c.?.isComment()) {
|
||||
c = try c.?.prevSibling();
|
||||
continue;
|
||||
}
|
||||
@@ -395,7 +395,7 @@ pub const Selector = union(enum) {
|
||||
if (!n.isElement()) return false;
|
||||
|
||||
const p = try n.parent();
|
||||
return p == null;
|
||||
return (p != null and p.?.isDocument());
|
||||
},
|
||||
.link => {
|
||||
const ntag = try n.tag();
|
||||
|
||||
Reference in New Issue
Block a user