mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-19 10:28:10 +00:00
proper UIEvent
This commit is contained in:
@@ -576,6 +576,7 @@ pub const JsApis = flattenTypes(&.{
|
||||
@import("../webapi/event/NavigationCurrentEntryChangeEvent.zig"),
|
||||
@import("../webapi/event/PageTransitionEvent.zig"),
|
||||
@import("../webapi/event/PopStateEvent.zig"),
|
||||
@import("../webapi/event/UIEvent.zig"),
|
||||
@import("../webapi/MessageChannel.zig"),
|
||||
@import("../webapi/MessagePort.zig"),
|
||||
@import("../webapi/media/MediaError.zig"),
|
||||
|
||||
49
src/browser/tests/event/ui.html
Normal file
49
src/browser/tests/event/ui.html
Normal file
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../testing.js"></script>
|
||||
|
||||
<script id=uiEventConstructor>
|
||||
const evt = new UIEvent('click', {
|
||||
detail: 5,
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
});
|
||||
testing.expectEqual('click', evt.type);
|
||||
testing.expectEqual(5, evt.detail);
|
||||
testing.expectEqual(true, evt.bubbles);
|
||||
testing.expectEqual(true, evt.cancelable);
|
||||
testing.expectEqual(window, evt.view);
|
||||
</script>
|
||||
|
||||
<script id=uiEventWithView>
|
||||
const evt2 = new UIEvent('mousedown', {
|
||||
detail: 2,
|
||||
view: window
|
||||
});
|
||||
testing.expectEqual('mousedown', evt2.type);
|
||||
testing.expectEqual(2, evt2.detail);
|
||||
testing.expectEqual(window, evt2.view);
|
||||
</script>
|
||||
|
||||
<script id=uiEventDefaults>
|
||||
const evt3 = new UIEvent('focus');
|
||||
testing.expectEqual('focus', evt3.type);
|
||||
testing.expectEqual(0, evt3.detail);
|
||||
testing.expectEqual(false, evt3.bubbles);
|
||||
testing.expectEqual(false, evt3.cancelable);
|
||||
testing.expectEqual(window, evt3.view);
|
||||
</script>
|
||||
|
||||
<script id=uiEventInheritance>
|
||||
const evt4 = new UIEvent('blur', { detail: 1 });
|
||||
testing.expectEqual('blur', evt4.type);
|
||||
testing.expectEqual(Event.NONE, evt4.eventPhase);
|
||||
testing.expectEqual(false, evt4.defaultPrevented);
|
||||
testing.expectEqual(1, evt4.detail);
|
||||
</script>
|
||||
|
||||
<script id=uiEventDetailTypes>
|
||||
const evt5 = new UIEvent('custom', { detail: 0 });
|
||||
const evt6 = new UIEvent('custom', { detail: 100 });
|
||||
testing.expectEqual(0, evt5.detail);
|
||||
testing.expectEqual(100, evt6.detail);
|
||||
</script>
|
||||
@@ -60,6 +60,7 @@ pub const Type = union(enum) {
|
||||
navigation_current_entry_change_event: *@import("event/NavigationCurrentEntryChangeEvent.zig"),
|
||||
page_transition_event: *@import("event/PageTransitionEvent.zig"),
|
||||
pop_state_event: *@import("event/PopStateEvent.zig"),
|
||||
ui_event: *@import("event/UIEvent.zig"),
|
||||
};
|
||||
|
||||
const Options = struct {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023-2024 Lightpanda (Selecy SAS)
|
||||
// Copyright (C) 2023-2025 Lightpanda (Selecy SAS)
|
||||
//
|
||||
// Francis Bouvier <francis@lightpanda.io>
|
||||
// Pierre Tachoire <pierre@lightpanda.io>
|
||||
@@ -27,19 +27,30 @@ _proto: *Event,
|
||||
_detail: u32,
|
||||
_view: *Window,
|
||||
|
||||
pub const EventOptions = struct {
|
||||
pub const UIEventOptions = struct {
|
||||
detail: u32 = 0,
|
||||
view: ?*Window = null,
|
||||
};
|
||||
|
||||
pub fn init(typ: []const u8, _options: ?EventOptions, page: *Page) !*UIEvent {
|
||||
const options = _options orelse EventOptions{};
|
||||
const Options = Event.inheritOptions(
|
||||
UIEvent,
|
||||
UIEventOptions,
|
||||
);
|
||||
|
||||
return page._factory.event(typ, UIEvent{
|
||||
pub fn init(typ: []const u8, _opts: ?Options, page: *Page) !*UIEvent {
|
||||
const opts = _opts orelse Options{};
|
||||
|
||||
const event = try page._factory.event(
|
||||
typ,
|
||||
UIEvent{
|
||||
._proto = undefined,
|
||||
._detail = options.detail,
|
||||
._view = options.view,
|
||||
});
|
||||
._detail = opts.detail,
|
||||
._view = opts.view orelse page.window,
|
||||
},
|
||||
);
|
||||
|
||||
Event.populatePrototypes(event, opts);
|
||||
return event;
|
||||
}
|
||||
|
||||
pub fn asEvent(self: *UIEvent) *Event {
|
||||
@@ -56,6 +67,8 @@ pub fn getView(self: *UIEvent) *Window {
|
||||
return self._view;
|
||||
}
|
||||
|
||||
// deprecated `initUIEvent()` not implemented
|
||||
|
||||
pub const JsApi = struct {
|
||||
pub const bridge = js.Bridge(UIEvent);
|
||||
|
||||
@@ -69,3 +82,8 @@ pub const JsApi = struct {
|
||||
pub const detail = bridge.accessor(UIEvent.getDetail, null, .{});
|
||||
pub const view = bridge.accessor(UIEvent.getView, null, .{});
|
||||
};
|
||||
|
||||
const testing = @import("../../../testing.zig");
|
||||
test "WebApi: UIEvent" {
|
||||
try testing.htmlRunner("event/ui.html", .{});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user