click event dispastched from CDP should be trusted

This commit is contained in:
Karl Seguin
2026-03-16 17:33:12 +08:00
parent ddd34dc57b
commit 7b2895ef08
2 changed files with 14 additions and 3 deletions

View File

@@ -3255,7 +3255,7 @@ pub fn triggerMouseClick(self: *Page, x: f64, y: f64) !void {
.type = self._type, .type = self._type,
}); });
} }
const event = (try @import("webapi/event/MouseEvent.zig").init("click", .{ const event = (try @import("webapi/event/MouseEvent.zig").initTrusted(comptime .wrap("click"), .{
.bubbles = true, .bubbles = true,
.cancelable = true, .cancelable = true,
.composed = true, .composed = true,

View File

@@ -28,6 +28,8 @@ const EventTarget = @import("../EventTarget.zig");
const UIEvent = @import("UIEvent.zig"); const UIEvent = @import("UIEvent.zig");
const PointerEvent = @import("PointerEvent.zig"); const PointerEvent = @import("PointerEvent.zig");
const Allocator = std.mem.Allocator;
const MouseEvent = @This(); const MouseEvent = @This();
pub const MouseButton = enum(u8) { pub const MouseButton = enum(u8) {
@@ -83,12 +85,21 @@ pub fn init(typ: []const u8, _opts: ?Options, page: *Page) !*MouseEvent {
const arena = try page.getArena(.{ .debug = "MouseEvent" }); const arena = try page.getArena(.{ .debug = "MouseEvent" });
errdefer page.releaseArena(arena); errdefer page.releaseArena(arena);
const type_string = try String.init(arena, typ, .{}); const type_string = try String.init(arena, typ, .{});
return initWithTrusted(arena, type_string, _opts, false, page);
}
pub fn initTrusted(typ: String, _opts: ?Options, page: *Page) !*MouseEvent {
const arena = try page.getArena(.{ .debug = "MouseEvent.trusted" });
errdefer page.releaseArena(arena);
return initWithTrusted(arena, typ, _opts, true, page);
}
fn initWithTrusted(arena: Allocator, typ: String, _opts: ?Options, trusted: bool, page: *Page) !*MouseEvent {
const opts = _opts orelse Options{}; const opts = _opts orelse Options{};
const event = try page._factory.uiEvent( const event = try page._factory.uiEvent(
arena, arena,
type_string, typ,
MouseEvent{ MouseEvent{
._type = .generic, ._type = .generic,
._proto = undefined, ._proto = undefined,
@@ -106,7 +117,7 @@ pub fn init(typ: []const u8, _opts: ?Options, page: *Page) !*MouseEvent {
}, },
); );
Event.populatePrototypes(event, opts, false); Event.populatePrototypes(event, opts, trusted);
return event; return event;
} }