Bug 1274146 part 2 - Dispatch an independent event to video control for entering fullscreen. r?smaug,gijs
MozReview-Commit-ID: JpDhzvxHfLj
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -12171,16 +12171,33 @@ nsDocument::ApplyFullscreen(const Fullsc
}
// Dispatch "fullscreenchange" events. Note this loop is in reverse
// order so that the events for the root document arrives before the leaf
// document, as required by the spec.
for (uint32_t i = 0; i < changed.Length(); ++i) {
DispatchFullScreenChange(changed[changed.Length() - i - 1]);
}
+
+ // If the element entering fullscreen is a video with controls,
+ // dispatch an independent event to the controls so that it won't
+ // need to listen on our normal fullscreenchange event.
+ if (elem->IsHTMLElement(nsGkAtoms::video) &&
+ elem->GetBoolAttr(nsGkAtoms::controls)) {
+ nsCOMPtr<nsINodeList> kids = elem->GetChildren(nsIContent::eAllChildren);
+ for (auto i : MakeRange(kids->Length())) {
+ nsIContent* item = kids->Item(i);
+ if (item->IsXULElement(nsGkAtoms::videocontrols)) {
+ DispatchCustomEventWithFlush(
+ item, NS_LITERAL_STRING("MediaEnteredFullscreen"),
+ /* Bubbles */ false, /* OnlyChrome */ false);
+ break;
+ }
+ }
+ }
return true;
}
NS_IMETHODIMP
nsDocument::GetMozFullScreenElement(nsIDOMElement **aFullScreenElement)
{
Element* el = GetFullscreenElement();
nsCOMPtr<nsIDOMElement> retval = do_QueryInterface(el);
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -1088,20 +1088,18 @@
this.fullscreenButton.setAttribute("aria-label", value);
if (this.isVideoInFullScreen())
this.fullscreenButton.setAttribute("fullscreened", "true");
else
this.fullscreenButton.removeAttribute("fullscreened");
},
- onFullscreenChange: function () {
- if (this.isVideoInFullScreen()) {
- Utils._hideControlsTimeout = setTimeout(this._hideControlsFn, this.HIDE_CONTROLS_TIMEOUT_MS);
- }
+ onEnteredFullscreen: function () {
+ Utils._hideControlsTimeout = setTimeout(this._hideControlsFn, this.HIDE_CONTROLS_TIMEOUT_MS);
},
clickToPlayClickHandler : function(e) {
if (e.button != 0)
return;
if (this.hasError() && !this.suppressError) {
// Errors that can be dismissed should be placed here as we discover them.
if (this.video.error.code != this.video.error.MEDIA_ERR_ABORTED)
@@ -1519,17 +1517,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, "MediaEnteredFullscreen", this.onEnteredFullscreen);
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 ---");
}