Skip to content

Commit

Permalink
Removes the case where activeElement could be in the light DOM of a S…
Browse files Browse the repository at this point in the history
…hadowRoot.
  • Loading branch information
bicknellr committed Jan 6, 2016
1 parent 2984576 commit e848af8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/lib/dom-api-shadow.html
Expand Up @@ -60,11 +60,13 @@

activeElement: {
get: function() {
return Polymer.DomApi.wrap(this.node).activeElement;
var node = Polymer.DomApi.wrap(this.node);
var activeElement = node.activeElement;
return node.contains(activeElement) ? activeElement : null;
},
configurable: true
},

childNodes: {
get: function() {
return TreeApi.arrayCopyChildNodes(this.node);
Expand Down
32 changes: 16 additions & 16 deletions src/lib/dom-api-shady.html
Expand Up @@ -430,35 +430,35 @@
}
var isShadyRoot = !!this.node._isShadyRoot;
if (this.node !== document) {
// If this node isn't a document or shady root, then it doesn't
// have an active element.
// If this node isn't a document or shady root, then it doesn't have
// an active element.
if (!isShadyRoot) {
return null;
}
// If this shady root's host is the active element or the active
// element is not a descendant of the host, then it doesn't have
// an active element.
// element is not a descendant of the host (in the composed tree),
// then it doesn't have an active element.
if (this.node.host === active ||
!this.node.host.contains(active)) {
return null;
}
// If the active element is a light descendant of the shady root's
// host, return the active element.
if (this.node.host !== active &&
this._contains(this.node.host, active)) {
return active;
}
}
// This node is either the document or a shady root of which the
// active element is a descendant of its host; iterate upwards to
// find the active element's most shallow host.
// This node is either the document or a shady root of which the active
// element is a (composed) descendant of its host; iterate upwards to
// find the active element's most shallow host within it.
var activeRoot = Polymer.dom(active).getOwnerRoot();
while (activeRoot && activeRoot !== this.node &&
!(isShadyRoot && this._contains(this.node.host, active))) {
while (activeRoot && activeRoot !== this.node) {
active = activeRoot.host;
activeRoot = Polymer.dom(active).getOwnerRoot();
}
return active;
if (this.node === document) {
// This node is the document, so activeRoot should be null.
return activeRoot ? null : active;
} else {
// This node is a non-document shady root, and it should be
// activeRoot.
return activeRoot === this.node ? active : null;
}
},
configurable: true
},
Expand Down
18 changes: 9 additions & 9 deletions test/unit/polymer-dom.js
Expand Up @@ -868,7 +868,7 @@ suite('Polymer.dom accessors', function() {
r_l.focus();

assert.equal(Polymer.dom(document).activeElement, r_l, 'document.activeElement === r_l');
assert.equal(Polymer.dom(r.root).activeElement, r_l, 'r.root.activeElement === r_l');
assert.equal(Polymer.dom(r.root).activeElement, null, 'r.root.activeElement === null');
assert.equal(Polymer.dom(r_0.root).activeElement, null, 'r_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
Expand All @@ -895,7 +895,7 @@ suite('Polymer.dom accessors', function() {

assert.equal(Polymer.dom(document).activeElement, r, 'document.activeElement === r');
assert.equal(Polymer.dom(r.root).activeElement, r_0_l, 'r.root.activeElement === r_0_l');
assert.equal(Polymer.dom(r_0.root).activeElement, r_0_l, 'r_0.root.activeElement === r_0_l');
assert.equal(Polymer.dom(r_0.root).activeElement, null, 'r_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');

assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
Expand Down Expand Up @@ -923,7 +923,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(document).activeElement, r, 'document.activeElement === r');
assert.equal(Polymer.dom(r.root).activeElement, r_0, 'r.root.activeElement === r_0');
assert.equal(Polymer.dom(r_0.root).activeElement, r_0_0_l, 'r_0.root.activeElement === r_0_0_l');
assert.equal(Polymer.dom(r_0_0.root).activeElement, r_0_0_l, 'r_0_0.root.activeElement === r_0_0_l');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
Expand All @@ -936,7 +936,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(document).activeElement, r, 'document.activeElement === r');
assert.equal(Polymer.dom(r.root).activeElement, r_0, 'r.root.activeElement === r_0');
assert.equal(Polymer.dom(r_0.root).activeElement, r_0_0_l, 'r_0.root.activeElement === r_0_0_l');
assert.equal(Polymer.dom(r_0_0.root).activeElement, r_0_0_l, 'r_0_0.root.activeElement === r_0_0_l');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_0_l.root).activeElement, r_0_0_l_0, 'r_0_0_l.root.activeElement === r_0_0_l_0');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
Expand Down Expand Up @@ -964,7 +964,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(r.root).activeElement, r_0, 'r.root.activeElement === r_0');
assert.equal(Polymer.dom(r_0.root).activeElement, r_0_1_l, 'r_0.root.activeElement === r_0_1_l');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, r_0_1_l, 'r_0_1.root.activeElement === r_0_1_l');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1_1.root).activeElement, null, 'r_1_1.root.activeElement === null');
Expand All @@ -991,7 +991,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(r_0.root).activeElement, null, 'r_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, r_1_l, 'r_1.root.activeElement === r_1_l');
assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1_1.root).activeElement, null, 'r_1_1.root.activeElement === null');
});
Expand All @@ -1004,7 +1004,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(r_0.root).activeElement, null, 'r_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, r_1_l, 'r_1.root.activeElement === r_1_l');
assert.equal(Polymer.dom(r_1.root).activeElement, null, 'r_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1_l.root).activeElement, r_1_l_0, 'r_1.root.activeElement === r_1_l_0');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1_1.root).activeElement, null, 'r_1_1.root.activeElement === null');
Expand Down Expand Up @@ -1032,7 +1032,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(r_0_0.root).activeElement, null, 'r_0_0.root.activeElement === null');
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, r_1_0_l, 'r_1.root.activeElement === r_1_0_l');
assert.equal(Polymer.dom(r_1_0.root).activeElement, r_1_0_l, 'r_1_0.root.activeElement === r_1_0_l');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1_1.root).activeElement, null, 'r_1_1.root.activeElement === null');
});

Expand All @@ -1059,7 +1059,7 @@ suite('Polymer.dom accessors', function() {
assert.equal(Polymer.dom(r_0_1.root).activeElement, null, 'r_0_1.root.activeElement === null');
assert.equal(Polymer.dom(r_1.root).activeElement, r_1_1_l, 'r_1.root.activeElement === r_1_1_l');
assert.equal(Polymer.dom(r_1_0.root).activeElement, null, 'r_1_0.root.activeElement === null');
assert.equal(Polymer.dom(r_1_1.root).activeElement, r_1_1_l, 'r_1_1.root.activeElement === r_1_1_l');
assert.equal(Polymer.dom(r_1_1.root).activeElement, null, 'r_1_1.root.activeElement === null');
});

test('setting activeElement on document has no effect', function() {
Expand Down

0 comments on commit e848af8

Please sign in to comment.