|
| 1 | +// Copyright (C) 2023-2025 Lightpanda (Selecy SAS) |
| 2 | +// |
| 3 | +// Francis Bouvier <francis@lightpanda.io> |
| 4 | +// Pierre Tachoire <pierre@lightpanda.io> |
| 5 | +// |
| 6 | +// This program is free software: you can redistribute it and/or modify |
| 7 | +// it under the terms of the GNU Affero General Public License as |
| 8 | +// published by the Free Software Foundation, either version 3 of the |
| 9 | +// License, or (at your option) any later version. |
| 10 | +// |
| 11 | +// This program is distributed in the hope that it will be useful, |
| 12 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +// GNU Affero General Public License for more details. |
| 15 | +// |
| 16 | +// You should have received a copy of the GNU Affero General Public License |
| 17 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +const std = @import("std"); |
| 20 | + |
| 21 | +const parser = @import("../netsurf.zig"); |
| 22 | + |
| 23 | +// https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent |
| 24 | +pub const CompositionEvent = struct { |
| 25 | + data: []const u8, |
| 26 | + proto: parser.Event, |
| 27 | + |
| 28 | + pub const union_make_copy = true; |
| 29 | + pub const prototype = *parser.Event; |
| 30 | + |
| 31 | + pub const ConstructorOptions = struct { |
| 32 | + data: []const u8 = "", |
| 33 | + }; |
| 34 | + |
| 35 | + pub fn constructor(event_type: []const u8, options_: ?ConstructorOptions) !CompositionEvent { |
| 36 | + const options: ConstructorOptions = options_ orelse .{}; |
| 37 | + |
| 38 | + const event = try parser.eventCreate(); |
| 39 | + defer parser.eventDestroy(event); |
| 40 | + try parser.eventInit(event, event_type, .{}); |
| 41 | + parser.eventSetInternalType(event, .composition_event); |
| 42 | + |
| 43 | + return .{ |
| 44 | + .proto = event.*, |
| 45 | + .data = options.data, |
| 46 | + }; |
| 47 | + } |
| 48 | + |
| 49 | + pub fn get_data(self: *const CompositionEvent) []const u8 { |
| 50 | + return self.data; |
| 51 | + } |
| 52 | +}; |
| 53 | + |
| 54 | +const testing = @import("../../testing.zig"); |
| 55 | +test "Browser: Events.Composition" { |
| 56 | + try testing.htmlRunner("events/composition.html"); |
| 57 | +} |
0 commit comments