Bug 1274146 part 2 - Redirect fullscreenchange event to video controls via a custom event. r?gijs
Handler for fullscreenchange event attached normally may affect or be
affected by other event handlers from the content. More specifically,
a handler listening on "fullscreenchange" event on a target would stop
any handler on the same target listening on "mozfullscreenchange" from
being invoked.
The main idea of this patch is to use a system event listener to avoid
affecting event handling in content.
MozReview-Commit-ID: FWVuREsDK9a
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -1474,8 +1474,31 @@ let OfflineApps = {
}
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]),
};
addEventListener("MozApplicationManifest", OfflineApps, false);
addMessageListener("OfflineApps:StartFetching", OfflineApps);
+
+var FullscreenListener = {
+ init: function() {
+ this._fullscreenElement = null;
+ // Register a system event listener so that it would not affect
+ // the event handling in the content.
+ Services.els.addSystemEventListener(global, "fullscreenchange", this, true);
+ },
+ handleEvent: function(evt) {
+ let targetFullscreenElement = evt.target.fullscreenElement;
+ let elem = targetFullscreenElement || this._fullscreenElement;
+ if (elem && elem instanceof content.HTMLVideoElement && elem.controls) {
+ this._fullscreenElement = targetFullscreenElement;
+ let nodes = Cc["@mozilla.org/inspector/dom-utils;1"]
+ .getService(Ci.inIDOMUtils).getChildrenForNode(elem, true);
+ // Dispatch a fullscreen change notice to the controls.
+ Array.prototype.find.call(nodes, node => {
+ return node.tagName == "videocontrols";
+ }).dispatchEvent(new content.CustomEvent("mediafullscreenchange"));
+ }
+ }
+};
+FullscreenListener.init();
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -1520,17 +1520,17 @@
addListener(this.playButton, "command", this.togglePause);
addListener(this.fullscreenButton, "command", this.toggleFullscreen);
addListener(this.clickToPlay, "click", this.clickToPlayClickHandler);
addListener(this.controlsSpacer, "click", this.clickToPlayClickHandler);
addListener(this.controlsSpacer, "dblclick", this.toggleFullscreen);
addListener(this.videocontrols, "resizevideocontrols", this.adjustControlSize);
addListener(this.videocontrols, "transitionend", this.onTransitionEnd);
- addListener(this.video.ownerDocument, "mozfullscreenchange", this.onFullscreenChange);
+ addListener(this.videocontrols, "mediafullscreenchange", this.onFullscreenChange);
addListener(this.video, "keypress", this.keyHandler);
addListener(this.videocontrols, "dragstart", function(event) {
event.preventDefault(); //prevent dragging of controls image (bug 517114)
});
this.log("--- videocontrols initialized ---");
}