From 1f1d211c85efab86237f097d05bc705f5df25877 Mon Sep 17 00:00:00 2001 From: Russell Bicknell Date: Fri, 11 Dec 2015 16:50:12 -0800 Subject: [PATCH 01/12] Fix `activeElement` for ShadowRoot: focused elements in light DOM of host are now returned. --- src/ShadowDOM/wrappers/Document.js | 1 - src/ShadowDOM/wrappers/ShadowRoot.js | 11 +- tests/ShadowDOM/html/activeElement.html | 136 +++++++++++++++++++++--- 3 files changed, 131 insertions(+), 17 deletions(-) diff --git a/src/ShadowDOM/wrappers/Document.js b/src/ShadowDOM/wrappers/Document.js index 5ebe24537..4ceffaa0c 100644 --- a/src/ShadowDOM/wrappers/Document.js +++ b/src/ShadowDOM/wrappers/Document.js @@ -59,7 +59,6 @@ // Loop while activeElement is not a shallow child of this document. while (!this.contains(activeElement)) { - var lastHost = activeElement; // Iterate until we hit activeElement's containing ShadowRoot (which // isn't this one) or document. while (activeElement.parentNode) { diff --git a/src/ShadowDOM/wrappers/ShadowRoot.js b/src/ShadowDOM/wrappers/ShadowRoot.js index 915462ef4..d868014d1 100644 --- a/src/ShadowDOM/wrappers/ShadowRoot.js +++ b/src/ShadowDOM/wrappers/ShadowRoot.js @@ -80,8 +80,15 @@ var activeElement = wrap(unwrappedActiveElement); - // Loop while activeElement is not a shallow child of this ShadowRoot. - while (!this.contains(activeElement)) { + // If the active element is this ShadowRoot's host, this ShadowRoot + // has no active element. + if (activeElement === this.host) { + return null; + } + + // Loop while activeElement is not a shallow descendant of this ShadowRoot + // or this ShadowRoot's host. + while (!this.contains(activeElement) && !this.host.contains(activeElement)) { // Iterate until we hit activeElement's containing ShadowRoot (which // isn't this one) or document. while (activeElement.parentNode) { diff --git a/tests/ShadowDOM/html/activeElement.html b/tests/ShadowDOM/html/activeElement.html index 6ec9aa0d1..f79b24de5 100644 --- a/tests/ShadowDOM/html/activeElement.html +++ b/tests/ShadowDOM/html/activeElement.html @@ -57,6 +57,9 @@ var r_1; // light var r_1_l; + // shadow + var r_1_l_0; + var r_1_l_1; // shadow var r_1_0; // light @@ -85,6 +88,8 @@ r_0_1_l = r_0_1.querySelector('[shadow-template-id=x-shadow-host-root-0-1-light]'); r_1 = r.shadowRoot.querySelector('[shadow-template-id=x-shadow-host-root-1]'); r_1_l = r_1.querySelector('[shadow-template-id=x-shadow-host-root-1-light]'); + r_1_l_0 = r_1_l.shadowRoot.querySelector('[shadow-template-id=x-shadow-host-root-1-light-0]'); + r_1_l_1 = r_1_l.shadowRoot.querySelector('[shadow-template-id=x-shadow-host-root-1-light-1]'); r_1_0 = r_1.shadowRoot.querySelector('[shadow-template-id=x-shadow-host-root-1-0]'); r_1_0_l = r_1_0.querySelector('[shadow-template-id=x-shadow-host-root-1-0-light]'); r_1_1 = r_1.shadowRoot.querySelector('[shadow-template-id=x-shadow-host-root-1-1]'); @@ -94,11 +99,6 @@ }); teardown(function() { - assert.equal(r_0_0.shadowRoot.activeElement, null); - assert.equal(r_0_1.shadowRoot.activeElement, null); - assert.equal(r_1_0.shadowRoot.activeElement, null); - assert.equal(r_1_1.shadowRoot.activeElement, null); - document.body.removeChild(r); }); @@ -120,16 +120,24 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, null); assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, null); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_l.focus()', function() { r_l.focus(); assert.equal(doc.activeElement, r_l); - assert.equal(r.shadowRoot.activeElement, null); + assert.equal(r.shadowRoot.activeElement, r_l); assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, null); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_0.focus()', function() { @@ -138,7 +146,11 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_0); assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, null); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_0_l.focus()', function() { @@ -146,8 +158,12 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_0_l); - assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0.shadowRoot.activeElement, r_0_l); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, null); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_0_0.focus()', function() { @@ -156,7 +172,11 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_0); assert.equal(r_0.shadowRoot.activeElement, r_0_0); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, null); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_0_0_l.focus()', function() { @@ -165,7 +185,11 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_0); assert.equal(r_0.shadowRoot.activeElement, r_0_0_l); + assert.equal(r_0_0.shadowRoot.activeElement, r_0_0_l); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, null); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_0_1.focus()', function() { @@ -174,7 +198,11 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_0); assert.equal(r_0.shadowRoot.activeElement, r_0_1); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, null); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_0_1_l.focus()', function() { @@ -183,7 +211,11 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_0); assert.equal(r_0.shadowRoot.activeElement, r_0_1_l); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, r_0_1_l); assert.equal(r_1.shadowRoot.activeElement, null); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_1.focus()', function() { @@ -192,7 +224,11 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_1); assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, null); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_1_l.focus()', function() { @@ -201,7 +237,39 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_1_l); assert.equal(r_0.shadowRoot.activeElement, null); - assert.equal(r_1_l.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); + assert.equal(r_1.shadowRoot.activeElement, r_1_l); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); + }); + + test('r_1_l_0.focus()', function() { + r_1_l_0.focus(); + + assert.equal(doc.activeElement, r); + assert.equal(r.shadowRoot.activeElement, r_1_l); + assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); + assert.equal(r_1.shadowRoot.activeElement, r_1_l); + assert.equal(r_1_l.shadowRoot.activeElement, r_1_l_0); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); + }); + + test('r_1_l_1.focus()', function() { + r_1_l_1.focus(); + + assert.equal(doc.activeElement, r); + assert.equal(r.shadowRoot.activeElement, r_1_l); + assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); + assert.equal(r_1.shadowRoot.activeElement, r_1_l); + assert.equal(r_1_l.shadowRoot.activeElement, r_1_l_1); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_1_0.focus()', function() { @@ -210,7 +278,11 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_1); assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, r_1_0); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_1_0_l.focus()', function() { @@ -219,7 +291,11 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_1); assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, r_1_0_l); + assert.equal(r_1_0.shadowRoot.activeElement, r_1_0_l); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_1_1.focus()', function() { @@ -228,7 +304,11 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_1); assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, r_1_1); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, null); }); test('r_1_1_l.focus()', function() { @@ -237,7 +317,11 @@ assert.equal(doc.activeElement, r); assert.equal(r.shadowRoot.activeElement, r_1); assert.equal(r_0.shadowRoot.activeElement, null); + assert.equal(r_0_0.shadowRoot.activeElement, null); + assert.equal(r_0_1.shadowRoot.activeElement, null); assert.equal(r_1.shadowRoot.activeElement, r_1_1_l); + assert.equal(r_1_0.shadowRoot.activeElement, null); + assert.equal(r_1_1.shadowRoot.activeElement, r_1_1_l); }); }); @@ -249,13 +333,17 @@
-
+
+
+
-
+
+
+
@@ -266,7 +354,11 @@
-
+
+
+
+
+
@@ -292,21 +384,37 @@
-
+
+
+
+
+
-
+
+
+
- + + + + +