Bug 1490820, elements without frames shouldn't be focusable in shadow DOM, r=ehsan
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Fri, 21 Sep 2018 21:46:17 +0300
changeset 437714 2718c0bfff1d6e9cf07e28212cf7d1dd5b09485e
parent 437713 1879856ca1ab0def40038be7482a9bc2e140cfee
child 437715 6b11a8172db4ec81c9b1d1fc8f5548ffab27898d
push id108134
push useropettay@mozilla.com
push dateFri, 21 Sep 2018 19:11:38 +0000
treeherdermozilla-inbound@2718c0bfff1d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1490820
milestone64.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 1490820, elements without frames shouldn't be focusable in shadow DOM, r=ehsan
dom/base/nsFocusManager.cpp
dom/base/test/file_bug1453693.html
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -3289,27 +3289,28 @@ nsFocusManager::GetNextTabbableContentIn
         }
         iterContent = contentTraversal.GetCurrent();
       }
       if (!iterContent) {
         // Reach the end
         break;
       }
 
-      // Get the tab index of the next element. For NAC we rely on frames.
-      //XXXsmaug we should probably use frames also for Shadow DOM and special
-      //         case only display:contents elements.
       int32_t tabIndex = 0;
       if (iterContent->IsInNativeAnonymousSubtree() &&
           iterContent->GetPrimaryFrame()) {
         iterContent->GetPrimaryFrame()->IsFocusable(&tabIndex);
       } else if (IsHostOrSlot(iterContent)) {
         tabIndex = HostOrSlotTabIndexValue(iterContent);
       } else {
-        iterContent->IsFocusable(&tabIndex);
+        nsIFrame* frame = iterContent->GetPrimaryFrame();
+        if (!frame) {
+          continue;
+        }
+        frame->IsFocusable(&tabIndex, 0);
       }
       if (tabIndex < 0 || !(aIgnoreTabIndex || tabIndex == aCurrentTabIndex)) {
         // If the element has native anonymous content, we may need to
         // focus some NAC element, even if the element itself isn't focusable.
         // This happens for example with <input type="date">.
         // So, try to find NAC and then traverse the frame tree to find elements
         // to focus.
         nsIFrame* possibleAnonOwnerFrame = iterContent->GetPrimaryFrame();
--- a/dom/base/test/file_bug1453693.html
+++ b/dom/base/test/file_bug1453693.html
@@ -120,16 +120,20 @@
         var shadowAnchor = anchor.cloneNode(false);
         shadowAnchor.onfocus = focusLogger;
         shadowAnchor.textContent = "in shadow DOM";
         sr.appendChild(shadowAnchor);
         var shadowInput = document.createElement("input");
         shadowInput.onfocus = focusLogger;
         sr.appendChild(shadowInput);
 
+        var hiddenShadowButton = document.createElement("button");
+        hiddenShadowButton.setAttribute("style", "display: none;");
+        sr.appendChild(hiddenShadowButton);
+
         var input = document.createElement("input");
         input.onfocus = focusLogger;
         document.body.appendChild(input);
 
         var input2 = document.createElement("input");
         input2.onfocus = focusLogger;
         document.body.appendChild(input2);