diff --git a/src/browser/dom/tree_walker.zig b/src/browser/dom/tree_walker.zig index f8143e22..89acfb42 100644 --- a/src/browser/dom/tree_walker.zig +++ b/src/browser/dom/tree_walker.zig @@ -227,7 +227,6 @@ pub const TreeWalker = struct { continue; }; - if (!result.should_descend) { // This is an .accept node - return it self.current_node = result.node; diff --git a/src/browser/events/composition_event.zig b/src/browser/events/composition_event.zig new file mode 100644 index 00000000..7e9d9845 --- /dev/null +++ b/src/browser/events/composition_event.zig @@ -0,0 +1,57 @@ +// Copyright (C) 2023-2025 Lightpanda (Selecy SAS) +// +// Francis Bouvier +// Pierre Tachoire +// +// 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 . + +const std = @import("std"); + +const parser = @import("../netsurf.zig"); + +// https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent +pub const CompositionEvent = struct { + data: []const u8, + proto: parser.Event, + + pub const union_make_copy = true; + pub const prototype = *parser.Event; + + pub const ConstructorOptions = struct { + data: []const u8 = "", + }; + + pub fn constructor(event_type: []const u8, options_: ?ConstructorOptions) !CompositionEvent { + const options: ConstructorOptions = options_ orelse .{}; + + const event = try parser.eventCreate(); + defer parser.eventDestroy(event); + try parser.eventInit(event, event_type, .{}); + parser.eventSetInternalType(event, .composition_event); + + return .{ + .proto = event.*, + .data = options.data, + }; + } + + pub fn get_data(self: *const CompositionEvent) []const u8 { + return self.data; + } +}; + +const testing = @import("../../testing.zig"); +test "Browser: Events.Composition" { + try testing.htmlRunner("events/composition.html"); +} diff --git a/src/browser/events/event.zig b/src/browser/events/event.zig index 17d192ff..a7a242bc 100644 --- a/src/browser/events/event.zig +++ b/src/browser/events/event.zig @@ -37,6 +37,7 @@ const KeyboardEvent = @import("keyboard_event.zig").KeyboardEvent; const ErrorEvent = @import("../html/error_event.zig").ErrorEvent; const MessageEvent = @import("../dom/MessageChannel.zig").MessageEvent; const PopStateEvent = @import("../html/History.zig").PopStateEvent; +const CompositionEvent = @import("composition_event.zig").CompositionEvent; // Event interfaces pub const Interfaces = .{ @@ -48,6 +49,7 @@ pub const Interfaces = .{ ErrorEvent, MessageEvent, PopStateEvent, + CompositionEvent, }; pub const Union = generate.Union(Interfaces); @@ -76,6 +78,7 @@ pub const Event = struct { .message_event => .{ .MessageEvent = @as(*MessageEvent, @ptrCast(evt)).* }, .keyboard_event => .{ .KeyboardEvent = @as(*parser.KeyboardEvent, @ptrCast(evt)) }, .pop_state => .{ .PopStateEvent = @as(*PopStateEvent, @ptrCast(evt)).* }, + .composition_event => .{ .CompositionEvent = (@as(*CompositionEvent, @fieldParentPtr("proto", evt))).* }, }; } diff --git a/src/browser/netsurf.zig b/src/browser/netsurf.zig index ffa81006..38f13dd6 100644 --- a/src/browser/netsurf.zig +++ b/src/browser/netsurf.zig @@ -559,6 +559,7 @@ pub const EventType = enum(u8) { message_event = 7, keyboard_event = 8, pop_state = 9, + composition_event = 10, }; pub const MutationEvent = c.dom_mutation_event; diff --git a/src/tests/events/composition.html b/src/tests/events/composition.html new file mode 100644 index 00000000..b5a6a710 --- /dev/null +++ b/src/tests/events/composition.html @@ -0,0 +1,36 @@ + + + + + + + + +