diff --git a/toolkit/actors/PictureInPictureChild.jsm b/toolkit/actors/PictureInPictureChild.jsm index a8865646d2..0f60d995d4 100644 --- a/toolkit/actors/PictureInPictureChild.jsm +++ b/toolkit/actors/PictureInPictureChild.jsm @@ -8,9 +8,6 @@ var EXPORTED_SYMBOLS = ["PictureInPictureChild", "PictureInPictureToggleChild"]; const { ActorChild } = ChromeUtils.import( "resource://gre/modules/ActorChild.jsm" ); -const { XPCOMUtils } = ChromeUtils.import( - "resource://gre/modules/XPCOMUtils.jsm" -); ChromeUtils.defineModuleGetter( this, @@ -23,8 +20,6 @@ ChromeUtils.defineModuleGetter( "resource://gre/modules/Services.jsm" ); -XPCOMUtils.defineLazyGlobalGetters(this, ["InspectorUtils"]); - const TOGGLE_ENABLED_PREF = "media.videocontrols.picture-in-picture.video-toggle.enabled"; const TOGGLE_TESTING_PREF = @@ -149,6 +144,10 @@ class PictureInPictureToggleChild extends ActorChild { } break; } + case "mouseout": { + this.onMouseOut(event); + break; + } case "mousedown": case "pointerup": case "mouseup": @@ -280,6 +279,9 @@ class PictureInPictureToggleChild extends ActorChild { capture: true, }); this.content.windowRoot.addEventListener("click", this, { capture: true }); + this.content.windowRoot.addEventListener("mouseout", this, { + capture: true, + }); } removeMouseButtonListeners() { @@ -298,6 +300,9 @@ class PictureInPictureToggleChild extends ActorChild { this.content.windowRoot.removeEventListener("click", this, { capture: true, }); + this.content.windowRoot.removeEventListener("mouseout", this, { + capture: true, + }); } /** @@ -455,6 +460,28 @@ class PictureInPictureToggleChild extends ActorChild { } } + /** + * Called on mouseout events to determine whether or not the mouse has + * exited the window. + * + * @param {Event} event The mouseout event. + */ + onMouseOut(event) { + if (!event.relatedTarget) { + // For mouseout events, if there's no relatedTarget (which normally + // maps to the element that the mouse entered into) then this means that + // we left the window. + let state = this.docState; + + let video = state.weakOverVideo && state.weakOverVideo.get(); + if (!video) { + return; + } + + this.onMouseLeaveVideo(video); + } + } + /** * Called for each mousemove event when we're tracking those events to * determine if the cursor is hovering over a