mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
Merge pull request #1376 from lightpanda-io/nikneym/attribute-ns
Add simplified `setAttributeNS` and `getAttributeNS`
This commit is contained in:
@@ -467,6 +467,22 @@ pub fn getAttribute(self: *const Element, name: []const u8, page: *Page) !?[]con
|
|||||||
return attributes.get(name, page);
|
return attributes.get(name, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// For simplicity, the namespace is currently ignored and only the local name is used.
|
||||||
|
pub fn getAttributeNS(
|
||||||
|
self: *const Element,
|
||||||
|
maybe_namespace: ?[]const u8,
|
||||||
|
local_name: []const u8,
|
||||||
|
page: *Page,
|
||||||
|
) !?[]const u8 {
|
||||||
|
if (maybe_namespace) |namespace| {
|
||||||
|
if (!std.mem.eql(u8, namespace, "http://www.w3.org/1999/xhtml")) {
|
||||||
|
log.warn(.not_implemented, "Element.getAttributeNS", .{ .namespace = namespace });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.getAttribute(local_name, page);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn getAttributeSafe(self: *const Element, name: []const u8) ?[]const u8 {
|
pub fn getAttributeSafe(self: *const Element, name: []const u8) ?[]const u8 {
|
||||||
const attributes = self._attributes orelse return null;
|
const attributes = self._attributes orelse return null;
|
||||||
return attributes.getSafe(name);
|
return attributes.getSafe(name);
|
||||||
@@ -499,6 +515,26 @@ pub fn setAttribute(self: *Element, name: []const u8, value: []const u8, page: *
|
|||||||
_ = try attributes.put(name, value, self, page);
|
_ = try attributes.put(name, value, self, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setAttributeNS(
|
||||||
|
self: *Element,
|
||||||
|
maybe_namespace: ?[]const u8,
|
||||||
|
qualified_name: []const u8,
|
||||||
|
value: []const u8,
|
||||||
|
page: *Page,
|
||||||
|
) !void {
|
||||||
|
if (maybe_namespace) |namespace| {
|
||||||
|
if (!std.mem.eql(u8, namespace, "http://www.w3.org/1999/xhtml")) {
|
||||||
|
log.warn(.not_implemented, "Element.setAttributeNS", .{ .namespace = namespace });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const local_name = if (std.mem.indexOfScalarPos(u8, qualified_name, 0, ':')) |idx|
|
||||||
|
qualified_name[idx + 1 ..]
|
||||||
|
else
|
||||||
|
qualified_name;
|
||||||
|
return self.setAttribute(local_name, value, page);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setAttributeSafe(self: *Element, name: []const u8, value: []const u8, page: *Page) !void {
|
pub fn setAttributeSafe(self: *Element, name: []const u8, value: []const u8, page: *Page) !void {
|
||||||
const attributes = try self.getOrCreateAttributeList(page);
|
const attributes = try self.getOrCreateAttributeList(page);
|
||||||
_ = try attributes.putSafe(name, value, self, page);
|
_ = try attributes.putSafe(name, value, self, page);
|
||||||
@@ -1380,8 +1416,10 @@ pub const JsApi = struct {
|
|||||||
pub const hasAttribute = bridge.function(Element.hasAttribute, .{});
|
pub const hasAttribute = bridge.function(Element.hasAttribute, .{});
|
||||||
pub const hasAttributes = bridge.function(Element.hasAttributes, .{});
|
pub const hasAttributes = bridge.function(Element.hasAttributes, .{});
|
||||||
pub const getAttribute = bridge.function(Element.getAttribute, .{});
|
pub const getAttribute = bridge.function(Element.getAttribute, .{});
|
||||||
|
pub const getAttributeNS = bridge.function(Element.getAttributeNS, .{});
|
||||||
pub const getAttributeNode = bridge.function(Element.getAttributeNode, .{});
|
pub const getAttributeNode = bridge.function(Element.getAttributeNode, .{});
|
||||||
pub const setAttribute = bridge.function(Element.setAttribute, .{ .dom_exception = true });
|
pub const setAttribute = bridge.function(Element.setAttribute, .{ .dom_exception = true });
|
||||||
|
pub const setAttributeNS = bridge.function(Element.setAttributeNS, .{ .dom_exception = true });
|
||||||
pub const setAttributeNode = bridge.function(Element.setAttributeNode, .{});
|
pub const setAttributeNode = bridge.function(Element.setAttributeNode, .{});
|
||||||
pub const removeAttribute = bridge.function(Element.removeAttribute, .{});
|
pub const removeAttribute = bridge.function(Element.removeAttribute, .{});
|
||||||
pub const toggleAttribute = bridge.function(Element.toggleAttribute, .{ .dom_exception = true });
|
pub const toggleAttribute = bridge.function(Element.toggleAttribute, .{ .dom_exception = true });
|
||||||
|
|||||||
Reference in New Issue
Block a user