HTMLDataElement

This commit is contained in:
Karl Seguin
2025-12-02 11:08:47 +08:00
parent fd39168106
commit 6a46a9ba47
5 changed files with 70 additions and 0 deletions

View File

@@ -1094,6 +1094,12 @@ pub fn createElement(self: *Page, ns_: ?[]const u8, name: []const u8, attribute_
attribute_iterator, attribute_iterator,
.{ ._proto = undefined, ._tag_name = String.init(undefined, "main", .{}) catch unreachable, ._tag = .main }, .{ ._proto = undefined, ._tag_name = String.init(undefined, "main", .{}) catch unreachable, ._tag = .main },
), ),
asUint("data") => return self.createHtmlElementT(
Element.Html.Data,
namespace,
attribute_iterator,
.{ ._proto = undefined },
),
else => {}, else => {},
}, },
5 => switch (@as(u40, @bitCast(name[0..5].*))) { 5 => switch (@as(u40, @bitCast(name[0..5].*))) {

View File

@@ -528,6 +528,7 @@ pub const JsApis = flattenTypes(&.{
@import("../webapi/element/html/BR.zig"), @import("../webapi/element/html/BR.zig"),
@import("../webapi/element/html/Button.zig"), @import("../webapi/element/html/Button.zig"),
@import("../webapi/element/html/Custom.zig"), @import("../webapi/element/html/Custom.zig"),
@import("../webapi/element/html/Data.zig"),
@import("../webapi/element/html/Dialog.zig"), @import("../webapi/element/html/Dialog.zig"),
@import("../webapi/element/html/Div.zig"), @import("../webapi/element/html/Div.zig"),
@import("../webapi/element/html/Form.zig"), @import("../webapi/element/html/Form.zig"),

View File

@@ -129,6 +129,7 @@ pub fn getTagNameLower(self: *const Element) []const u8 {
.br => "br", .br => "br",
.button => "button", .button => "button",
.custom => |e| e._tag_name.str(), .custom => |e| e._tag_name.str(),
.data => "data",
.dialog => "dialog", .dialog => "dialog",
.div => "div", .div => "div",
.form => "form", .form => "form",
@@ -174,6 +175,7 @@ pub fn getTagNameSpec(self: *const Element, buf: []u8) []const u8 {
.br => "BR", .br => "BR",
.button => "BUTTON", .button => "BUTTON",
.custom => |e| upperTagName(&e._tag_name, buf), .custom => |e| upperTagName(&e._tag_name, buf),
.data => "DATA",
.dialog => "DIALOG", .dialog => "DIALOG",
.div => "DIV", .div => "DIV",
.form => "FORM", .form => "FORM",
@@ -793,6 +795,7 @@ pub fn getTag(self: *const Element) Tag {
.form => .form, .form => .form,
.p => .p, .p => .p,
.custom => .custom, .custom => .custom,
.data => .data,
.dialog => .dialog, .dialog => .dialog,
.iframe => .iframe, .iframe => .iframe,
.img => .img, .img => .img,
@@ -835,6 +838,7 @@ pub const Tag = enum {
button, button,
circle, circle,
custom, custom,
data,
dialog, dialog,
div, div,
ellipse, ellipse,

View File

@@ -42,6 +42,7 @@ pub const Custom = @import("html/Custom.zig");
pub const Script = @import("html/Script.zig"); pub const Script = @import("html/Script.zig");
pub const Anchor = @import("html/Anchor.zig"); pub const Anchor = @import("html/Anchor.zig");
pub const Button = @import("html/Button.zig"); pub const Button = @import("html/Button.zig");
pub const Data = @import("html/Data.zig");
pub const Dialog = @import("html/Dialog.zig"); pub const Dialog = @import("html/Dialog.zig");
pub const Form = @import("html/Form.zig"); pub const Form = @import("html/Form.zig");
pub const Heading = @import("html/Heading.zig"); pub const Heading = @import("html/Heading.zig");
@@ -72,6 +73,7 @@ pub const Type = union(enum) {
br: *BR, br: *BR,
button: *Button, button: *Button,
custom: *Custom, custom: *Custom,
data: *Data,
dialog: *Dialog, dialog: *Dialog,
div: *Div, div: *Div,
form: *Form, form: *Form,
@@ -121,6 +123,7 @@ pub fn className(self: *const HtmlElement) []const u8 {
.form => "[object HTMLFormElement]", .form => "[object HTMLFormElement]",
.p => "[object HtmlParagraphElement]", .p => "[object HtmlParagraphElement]",
.custom => "[object CUSTOM-TODO]", .custom => "[object CUSTOM-TODO]",
.data => "[object HTMLDataElement]",
.dialog => "[object HTMLDialogElement]", .dialog => "[object HTMLDialogElement]",
.img => "[object HTMLImageElement]", .img => "[object HTMLImageElement]",
.iframe => "[object HTMLIFrameElement]", .iframe => "[object HTMLIFrameElement]",

View File

@@ -0,0 +1,56 @@
// Copyright (C) 2023-2025 Lightpanda (Selecy SAS)
//
// Francis Bouvier <francis@lightpanda.io>
// Pierre Tachoire <pierre@lightpanda.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// 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/>.
const js = @import("../../../js/js.zig");
const Page = @import("../../../Page.zig");
const Node = @import("../../Node.zig");
const Element = @import("../../Element.zig");
const HtmlElement = @import("../Html.zig");
const Data = @This();
_proto: *HtmlElement,
pub fn asElement(self: *Data) *Element {
return self._proto._proto;
}
pub fn asNode(self: *Data) *Node {
return self.asElement().asNode();
}
pub fn getValue(self: *Data) []const u8 {
return self.asElement().getAttributeSafe("value") orelse "";
}
pub fn setValue(self: *Data, value: []const u8, page: *Page) !void {
try self.asElement().setAttributeSafe("value", value, page);
}
pub const JsApi = struct {
pub const bridge = js.Bridge(Data);
pub const Meta = struct {
pub const name = "HTMLDataElement";
pub const prototype_chain = bridge.prototypeChain();
pub var class_id: bridge.ClassId = undefined;
};
pub const value = bridge.accessor(Data.getValue, Data.setValue, .{});
};