Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1587362 - Make sure PiP toggle mouse button listeners are attache…
Browse files Browse the repository at this point in the history
…d to the right WindowRoot after tab tear out / in. r=jaws

Differential Revision: https://phabricator.services.mozilla.com/D48885
  • Loading branch information
mikeconley committed Oct 11, 2019
1 parent 39c511f commit 59a03d7
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions toolkit/actors/PictureInPictureChild.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ class PictureInPictureToggleChild extends ActorChild {
// This is a DeferredTask to hide the toggle after a period of mouse
// inactivity.
hideToggleDeferredTask: null,
// If we reach a point where we're tracking videos for mouse movements,
// then this will be true. If there are no videos worth tracking, then
// this is false.
isTrackingVideos: false,
};
this.weakDocStates.set(this.content.document, state);
}
Expand Down Expand Up @@ -164,6 +168,14 @@ class PictureInPictureToggleChild extends ActorChild {
this.onMouseMove(event);
break;
}
case "pageshow": {
this.onPageShow(event);
break;
}
case "pagehide": {
this.onPageHide(event);
break;
}
}
}

Expand Down Expand Up @@ -330,7 +342,14 @@ class PictureInPictureToggleChild extends ActorChild {
mozSystemGroup: true,
capture: true,
});
this.content.addEventListener("pageshow", this, {
mozSystemGroup: true,
});
this.content.addEventListener("pagehide", this, {
mozSystemGroup: true,
});
this.addMouseButtonListeners();
state.isTrackingVideos = true;
}

/**
Expand All @@ -345,11 +364,50 @@ class PictureInPictureToggleChild extends ActorChild {
mozSystemGroup: true,
capture: true,
});
this.content.removeEventListener("pageshow", this, {
mozSystemGroup: true,
});
this.content.removeEventListener("pagehide", this, {
mozSystemGroup: true,
});
this.removeMouseButtonListeners();
let oldOverVideo = state.weakOverVideo && state.weakOverVideo.get();
if (oldOverVideo) {
this.onMouseLeaveVideo(oldOverVideo);
}
state.isTrackingVideos = false;
}

/**
* This pageshow event handler will get called if and when we complete a tab
* tear out or in. If we happened to be tracking videos before the tear
* occurred, we re-add the mouse event listeners so that they're attached to
* the right WindowRoot.
*
* @param {Event} event The pageshow event fired when completing a tab tear
* out or in.
*/
onPageShow(event) {
let state = this.docState;
if (state.isTrackingVideos) {
this.addMouseButtonListeners();
}
}

/**
* This pagehide event handler will get called if and when we start a tab
* tear out or in. If we happened to be tracking videos before the tear
* occurred, we remove the mouse event listeners. We'll re-add them when the
* pageshow event fires.
*
* @param {Event} event The pagehide event fired when starting a tab tear
* out or in.
*/
onPageHide(event) {
let state = this.docState;
if (state.isTrackingVideos) {
this.removeMouseButtonListeners();
}
}

/**
Expand Down

0 comments on commit 59a03d7

Please sign in to comment.