mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
support CustomEvent in createEvent
This commit is contained in:
@@ -36,6 +36,8 @@ const CSSStyleSheet = @import("../cssom/CSSStyleSheet.zig");
|
|||||||
const NodeIterator = @import("node_iterator.zig").NodeIterator;
|
const NodeIterator = @import("node_iterator.zig").NodeIterator;
|
||||||
const Range = @import("range.zig").Range;
|
const Range = @import("range.zig").Range;
|
||||||
|
|
||||||
|
const CustomEvent = @import("../events/custom_event.zig").CustomEvent;
|
||||||
|
|
||||||
const Env = @import("../env.zig").Env;
|
const Env = @import("../env.zig").Env;
|
||||||
|
|
||||||
const DOMImplementation = @import("implementation.zig").DOMImplementation;
|
const DOMImplementation = @import("implementation.zig").DOMImplementation;
|
||||||
@@ -110,13 +112,21 @@ pub const Document = struct {
|
|||||||
return try parser.documentGetDoctype(self);
|
return try parser.documentGetDoctype(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _createEvent(_: *parser.Document, eventCstr: []const u8) !*parser.Event {
|
pub fn _createEvent(_: *parser.Document, eventCstr: []const u8) !union(enum) {
|
||||||
// TODO: for now only "Event" constructor is supported
|
base: *parser.Event,
|
||||||
// see table on https://dom.spec.whatwg.org/#dom-document-createevent $2
|
custom: CustomEvent,
|
||||||
|
} {
|
||||||
if (std.ascii.eqlIgnoreCase(eventCstr, "Event") or std.ascii.eqlIgnoreCase(eventCstr, "Events")) {
|
if (std.ascii.eqlIgnoreCase(eventCstr, "Event") or std.ascii.eqlIgnoreCase(eventCstr, "Events")) {
|
||||||
return try parser.eventCreate();
|
return .{ .base = try parser.eventCreate() };
|
||||||
}
|
}
|
||||||
return parser.DOMError.NotSupported;
|
|
||||||
|
// Not documented in MDN but supported in Chrome.
|
||||||
|
// This is actually both instance of `Event` and `CustomEvent`.
|
||||||
|
if (std.ascii.eqlIgnoreCase(eventCstr, "CustomEvent")) {
|
||||||
|
return .{ .custom = try CustomEvent.constructor(eventCstr, null) };
|
||||||
|
}
|
||||||
|
|
||||||
|
return error.NotSupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _getElementById(self: *parser.Document, id: []const u8) !?ElementUnion {
|
pub fn _getElementById(self: *parser.Document, id: []const u8) !?ElementUnion {
|
||||||
|
|||||||
Reference in New Issue
Block a user