Bug 1492582 - Support the <body> element being the default focus node in browser.xhtml r=Gijs
authorBrendan Dahl <bdahl@mozilla.com>
Fri, 08 Nov 2019 23:33:52 +0000
changeset 501404 fb6625e16994c73d7373bc0a068812903d25e32c
parent 501403 47030db7c541ef3e8102572d88a60289828dde62
child 501405 cd43140ba52879d74162066e1531e36ac32df1b8
push id36791
push usercsabou@mozilla.com
push dateSun, 10 Nov 2019 09:53:30 +0000
treeherdermozilla-central@72c52c0101cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1492582
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1492582 - Support the <body> element being the default focus node in browser.xhtml r=Gijs Previously we were returning the documentElement in order to match the old XUL behavior. Now that we have a document.body we can just follow the normal HTML convention. Differential Revision: https://phabricator.services.mozilla.com/D34021
browser/base/content/tabbrowser.js
browser/base/content/test/general/browser_tabfocus.js
dom/base/Document.cpp
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -1353,20 +1353,17 @@
         this.selectedTab._findBarFocused
       ) {
         gFindBar._findField.focus();
         return;
       }
 
       // Don't focus the content area if something has been focused after the
       // tab switch was initiated.
-      if (
-        gMultiProcessBrowser &&
-        document.activeElement != document.documentElement
-      ) {
+      if (gMultiProcessBrowser && document.activeElement != document.body) {
         return;
       }
 
       // We're now committed to focusing the content area.
       let fm = Services.focus;
       let focusFlags = fm.FLAG_NOSCROLL;
 
       if (!gMultiProcessBrowser) {
--- a/browser/base/content/test/general/browser_tabfocus.js
+++ b/browser/base/content/test/general/browser_tabfocus.js
@@ -671,16 +671,21 @@ function compareFocusResults() {
     if (gMultiProcessBrowser) {
       is(_expectedWindow, "main-window", "main-window is always expected");
     } else if (_expectedWindow != "main-window") {
       matchWindow =
         _expectedWindow == "window1"
           ? browser1.contentWindow
           : browser2.contentWindow;
     }
+    if (_expectedWindow == "main-window") {
+      // The browser window's body doesn't have an id set usually - set one now
+      // so it can be used for id comparisons below.
+      matchWindow.document.body.id = "main-window-body";
+    }
 
     var focusedElement = fm.focusedElement;
     is(
       getId(focusedElement),
       _expectedElement,
       currentTestName + " focusedElement"
     );
     is(fm.focusedWindow, matchWindow, currentTestName + " focusedWindow");
@@ -693,23 +698,17 @@ function compareFocusResults() {
     is(
       focusedWindow.value,
       matchWindow,
       currentTestName + " getFocusedElementForWindow frame"
     );
     is(matchWindow.document.hasFocus(), true, currentTestName + " hasFocus");
     var expectedActive = _expectedElement;
     if (!expectedActive) {
-      // Documents that have a XUL document element currently have a different
-      // active element behavior than regular HTML documents. This test will
-      // need to be updated when bug 1492582 is fixed.
-      expectedActive =
-        matchWindow.document.documentElement instanceof XULElement
-          ? "main-window"
-          : getId(matchWindow.document.body);
+      expectedActive = getId(matchWindow.document.body);
     }
     is(
       getId(matchWindow.document.activeElement),
       expectedActive,
       currentTestName + " activeElement"
     );
 
     currentPromiseResolver();
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -5679,19 +5679,19 @@ Element* Document::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.
+    // Special case to handle the transition to XHTML from XUL documents
+    // where there currently isn't a body element, but we need to match the
+    // XUL behavior. This should be removed when bug 1540278 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.