mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
address review: conditional event dispatch and explicit options
- play event only fires when transitioning from paused to playing - pause event only fires when transitioning from playing to paused - playing event always fires on play() per spec - explicitly set bubbles: false, cancelable: false on events - updated tests to verify no duplicate events on repeated calls
This commit is contained in:
@@ -60,14 +60,25 @@
|
||||
audio.addEventListener('pause', () => events.push('pause'));
|
||||
audio.addEventListener('emptied', () => events.push('emptied'));
|
||||
|
||||
// First play: paused -> playing, fires play + playing
|
||||
audio.play();
|
||||
testing.expectEqual('play,playing', events.join(','));
|
||||
|
||||
audio.pause();
|
||||
testing.expectEqual('play,playing,pause', events.join(','));
|
||||
// Second play: already playing, fires only playing (not play)
|
||||
audio.play();
|
||||
testing.expectEqual('play,playing,playing', events.join(','));
|
||||
|
||||
// Pause: playing -> paused, fires pause
|
||||
audio.pause();
|
||||
testing.expectEqual('play,playing,playing,pause', events.join(','));
|
||||
|
||||
// Second pause: already paused, no event
|
||||
audio.pause();
|
||||
testing.expectEqual('play,playing,playing,pause', events.join(','));
|
||||
|
||||
// Load: fires emptied
|
||||
audio.load();
|
||||
testing.expectEqual('play,playing,pause,emptied', events.join(','));
|
||||
testing.expectEqual('play,playing,playing,pause,emptied', events.join(','));
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -138,17 +138,22 @@ fn isMaybeSupported(mime_type: []const u8) bool {
|
||||
}
|
||||
|
||||
pub fn play(self: *Media, page: *Page) !void {
|
||||
const was_paused = self._paused;
|
||||
self._paused = false;
|
||||
self._ready_state = .HAVE_ENOUGH_DATA;
|
||||
self._network_state = .NETWORK_IDLE;
|
||||
if (was_paused) {
|
||||
try self.dispatchEvent("play", page);
|
||||
}
|
||||
try self.dispatchEvent("playing", page);
|
||||
}
|
||||
|
||||
pub fn pause(self: *Media, page: *Page) !void {
|
||||
if (!self._paused) {
|
||||
self._paused = true;
|
||||
try self.dispatchEvent("pause", page);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load(self: *Media, page: *Page) !void {
|
||||
self._paused = true;
|
||||
@@ -160,7 +165,7 @@ pub fn load(self: *Media, page: *Page) !void {
|
||||
}
|
||||
|
||||
fn dispatchEvent(self: *Media, name: []const u8, page: *Page) !void {
|
||||
const event = try Event.init(name, null, page);
|
||||
const event = try Event.init(name, .{ .bubbles = false, .cancelable = false }, page);
|
||||
defer if (!event._v8_handoff) event.deinit(false);
|
||||
try page._event_manager.dispatch(self.asElement().asEventTarget(), event);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user