Commit d9d09bb0 authored by Edgar Chen's avatar Edgar Chen
Browse files

Bug 1519090 - Part 3: nsFocusManager::GetNextTabbableContentInScope should...

Bug 1519090 - Part 3: nsFocusManager::GetNextTabbableContentInScope should also check slot if aSkipOwner is false; r=smaug

Slot element could be also focusable.

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

--HG--
extra : moz-landing-system : lando
parent 2b9f6f61
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -3015,10 +3015,9 @@ nsIContent* nsFocusManager::GetNextTabbableContentInScope(
    nsIContent* aOwner, nsIContent* aStartContent,
    nsIContent* aOriginalStartContent, bool aForward, int32_t aCurrentTabIndex,
    bool aIgnoreTabIndex, bool aForDocumentNavigation, bool aSkipOwner) {
  // Return shadow host at first for forward navigation if its tabindex
  // is non-negative
  bool skipOwner = aSkipOwner || !aOwner->GetShadowRoot();
  if (!skipOwner && (aForward && aOwner == aStartContent)) {
  MOZ_ASSERT(IsHostOrSlot(aOwner), "Scope owner should be host or slot");

  if (!aSkipOwner && (aForward && aOwner == aStartContent)) {
    int32_t tabIndex = -1;
    nsIFrame* frame = aOwner->GetPrimaryFrame();
    if (frame && frame->IsFocusable(&tabIndex, false) && tabIndex >= 0) {
@@ -3120,9 +3119,9 @@ nsIContent* nsFocusManager::GetNextTabbableContentInScope(
    contentTraversal.Reset();
  }

  // Return shadow host at last for backward navigation if its tabindex
  // Return scope owner at last for backward navigation if its tabindex
  // is non-negative
  if (!skipOwner && !aForward) {
  if (!aSkipOwner && !aForward) {
    int32_t tabIndex = -1;
    nsIFrame* frame = aOwner->GetPrimaryFrame();
    if (frame && frame->IsFocusable(&tabIndex, false) && tabIndex >= 0) {
+67 −1
Original line number Diff line number Diff line
@@ -588,6 +588,71 @@
        input2.remove();
      }

      function testTabbingThroughFocusableSlotInLightDOM() {
        opener.is(document.activeElement, document.body.firstChild, "body's first child should have focus.");

        var slot0 = document.createElement("slot");
        slot0.tabIndex = 0;
        slot0.setAttribute("style", "display: inline;");
        slot0.onfocus = focusLogger;
        document.body.appendChild(slot0);

        var slot00 = document.createElement("slot");
        slot00.tabIndex = 0;
        slot00.setAttribute("style", "display: inline;");
        slot00.onfocus = focusLogger;
        slot0.appendChild(slot00);

        var input000 = document.createElement("input");
        input000.onfocus = focusLogger;
        slot00.appendChild(input000);

        var input01 = document.createElement("input");
        input01.onfocus = focusLogger;
        slot0.appendChild(input01);

        var input1 = document.createElement("input");
        input1.onfocus = focusLogger;
        document.body.appendChild(input1);

        document.body.offsetLeft;

        synthesizeKey("KEY_Tab");
        opener.is(lastFocusTarget, slot0, "Should have focused slot element. (1)");

        synthesizeKey("KEY_Tab");
        opener.is(lastFocusTarget, slot00, "Should have focused slot element. (2)");

        synthesizeKey("KEY_Tab");
        opener.is(lastFocusTarget, input000, "Should have focused input element in slot. (3)");

        synthesizeKey("KEY_Tab");
        opener.is(lastFocusTarget, input01, "Should have focused input element in slot. (4)");

        synthesizeKey("KEY_Tab");
        opener.is(lastFocusTarget, input1, "Should have focused input element. (5)");

        // Backwards
        synthesizeKey("KEY_Tab", {shiftKey: true});
        opener.is(lastFocusTarget, input01, "Should have focused input element in slot. (6)");

        synthesizeKey("KEY_Tab", {shiftKey: true});
        opener.is(lastFocusTarget, input000, "Should have focused input element in slot. (7)");

        synthesizeKey("KEY_Tab", {shiftKey: true});
        opener.is(lastFocusTarget, slot00, "Should have focused slot element. (8)");

        synthesizeKey("KEY_Tab", {shiftKey: true});
        opener.is(lastFocusTarget, slot0, "Should have focused slot element. (9)");

        synthesizeKey("KEY_Tab", {shiftKey: true});
        opener.is(document.activeElement, document.body.firstChild,
                  "body's first child should have focus.");

        slot0.remove();
        input1.remove();
      }

      function runTest() {

        testTabbingThroughShadowDOMWithTabIndexes();
@@ -599,6 +664,7 @@
        testShiftTabbingThroughFocusableHost();
        testTabbingThroughNestedSlot();
        testTabbingThroughSlotInLightDOM();
        testTabbingThroughFocusableSlotInLightDOM();

        opener.didRunTests();
        window.close();