Bug 1119049 - Keyboard shortcuts should work in MediaDocuments without explicitly focusing the media element. r=bz

This commit is contained in:
Steffen Wilberg 2015-10-04 13:04:55 +02:00
parent ff83916a03
commit 77fb9fa11a
5 changed files with 51 additions and 0 deletions

View File

@ -344,6 +344,26 @@ MediaDocument::LinkStylesheet(const nsAString& aStylesheet)
return head->AppendChildTo(link, false);
}
nsresult
MediaDocument::LinkScript(const nsAString& aScript)
{
nsRefPtr<mozilla::dom::NodeInfo> nodeInfo;
nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::script, nullptr,
kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
nsRefPtr<nsGenericHTMLElement> script = NS_NewHTMLScriptElement(nodeInfo.forget());
NS_ENSURE_TRUE(script, NS_ERROR_OUT_OF_MEMORY);
script->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
NS_LITERAL_STRING("text/javascript;version=1.8"), true);
script->SetAttr(kNameSpaceID_None, nsGkAtoms::src, aScript, true);
Element* head = GetHeadElement();
return head->AppendChildTo(script, false);
}
void
MediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
nsIChannel* aChannel,

View File

@ -52,6 +52,7 @@ protected:
void GetFileName(nsAString& aResult, nsIChannel* aChannel);
nsresult LinkStylesheet(const nsAString& aStylesheet);
nsresult LinkScript(const nsAString& aScript);
// |aFormatNames[]| needs to have four elements in the following order:
// a format name with neither dimension nor file, a format name with

View File

@ -76,6 +76,7 @@ VideoDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
GetReadyStateEnum() != nsIDocument::READYSTATE_COMPLETE) {
LinkStylesheet(NS_LITERAL_STRING("resource://gre/res/TopLevelVideoDocument.css"));
LinkStylesheet(NS_LITERAL_STRING("chrome://global/skin/media/TopLevelVideoDocument.css"));
LinkScript(NS_LITERAL_STRING("chrome://global/content/TopLevelVideoDocument.js"));
}
BecomeInteractive();
}

View File

@ -0,0 +1,28 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
window.addEventListener("load", () => {
// <video> is used for top-level audio documents as well
let videoElement = document.getElementsByTagName("video")[0];
if (!videoElement)
return;
// Send keystrokes to the video element when the body element is focused,
// to be received by the event listener in videocontrols.xml.
document.addEventListener("keypress", ev => {
if (ev.synthetic) // prevent recursion
return;
// Check if the video element is focused, so it already receives
// keystrokes, and don't send it another one from here.
if (document.activeElement == videoElement)
return;
let newEvent = new KeyboardEvent("keypress", ev);
newEvent.synthetic = true;
videoElement.dispatchEvent(newEvent);
});
});

View File

@ -59,6 +59,7 @@ toolkit.jar:
content/global/resetProfile.xul
content/global/resetProfileProgress.xul
content/global/select-child.js
content/global/TopLevelVideoDocument.js
content/global/treeUtils.js
content/global/viewZoomOverlay.js
*+ content/global/bindings/autocomplete.xml (widgets/autocomplete.xml)