Removes the case where activeElement could be in the light DOM of a ShadowRoot.

This commit is contained in:
Russell Bicknell 2016-01-06 11:45:21 -08:00
parent 298457610b
commit e848af8964
3 changed files with 29 additions and 27 deletions

View File

@ -60,11 +60,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
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);

View File

@ -430,35 +430,35 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
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
},

View File

@ -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');
@ -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');
@ -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');
@ -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');
@ -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');
@ -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');
});
@ -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');
@ -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');
});
@ -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() {