Bug 1492327 - Mimic XUL activeElement behavior for XUL in XHTML. r=smaug

Return the document element as the activeElement when there is no body
element, the document is chrome privileged, and the document element
is a XUL element.

MozReview-Commit-ID: JFDLAqOmLTS

Differential Revision: https://phabricator.services.mozilla.com/D6448

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brendan Dahl 2018-09-25 16:00:13 +00:00
Родитель 7e77a65a6b
Коммит 6c049f28fa
2 изменённых файлов: 15 добавлений и 4 удалений

Просмотреть файл

@ -1106,9 +1106,7 @@ window._gBrowser = {
newBrowser._urlbarFocused &&
gURLBar &&
gURLBar.focused;
// In an HTML document (built with MOZ_BROWSER_XHTML), the activeElement
// can be null, so check before attempting to blur it (Bug 1485157).
if (!keepFocusOnUrlBar && document.activeElement) {
if (!keepFocusOnUrlBar) {
// Clear focus so that _adjustFocusAfterTabSwitch can detect if
// some element has been focused and respect that.
document.activeElement.blur();

Просмотреть файл

@ -3586,9 +3586,22 @@ nsIDocument::GetActiveElement()
// No focused element anywhere in this document. Try to get the BODY.
if (IsHTMLOrXHTML()) {
Element* bodyElement = AsHTMLDocument()->GetBody();
if (bodyElement) {
return bodyElement;
}
// Special case to handle the transition to browser.xhtml where there is
// currently not a body element, but we need to match the XUL behavior.
// This should be removed when bug 1492582 is resolved.
if (nsContentUtils::IsChromeDoc(this)) {
Element* docElement = GetDocumentElement();
if (docElement && docElement->IsXULElement()) {
return docElement;
}
}
// Because of IE compatibility, return null when html document doesn't have
// a body.
return AsHTMLDocument()->GetBody();
return nullptr;
}
// If we couldn't get a BODY, return the root element.