diff --git a/bower.json b/bower.json
index b6655cda..a13c6ad7 100644
--- a/bower.json
+++ b/bower.json
@@ -20,7 +20,7 @@
"url": "https://github.com/Polymer/polymer.git"
},
"dependencies": {
- "webcomponentsjs": "^0.7.18"
+ "webcomponentsjs": "^0.7.20"
},
"devDependencies": {
"web-component-tester": "*"
diff --git a/src/lib/dom-api-shadow.html b/src/lib/dom-api-shadow.html
index cc73842b..e442b761 100644
--- a/src/lib/dom-api-shadow.html
+++ b/src/lib/dom-api-shadow.html
@@ -58,6 +58,18 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
Object.defineProperties(DomApi.prototype, {
+ activeElement: {
+ get: function() {
+ var node = DomApi.wrap(this.node);
+ var activeElement = node.activeElement;
+ // Prevents `activeElement` from returning elements outside of the
+ // ShadowRoot, even if they would become descendants of the ShadowRoot
+ // in the composed tree. See w3c/webcomponents#358.
+ return node.contains(activeElement) ? activeElement : null;
+ },
+ configurable: true
+ },
+
childNodes: {
get: function() {
return TreeApi.arrayCopyChildNodes(this.node);
diff --git a/src/lib/dom-api-shady.html b/src/lib/dom-api-shady.html
index 64e41c1c..e1f62ffe 100644
--- a/src/lib/dom-api-shady.html
+++ b/src/lib/dom-api-shady.html
@@ -422,6 +422,47 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
Object.defineProperties(DomApi.prototype, {
+ activeElement: {
+ get: function() {
+ var active = document.activeElement;
+ if (!active) {
+ return null;
+ }
+ 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 (!isShadyRoot) {
+ return null;
+ }
+ // If this shady root's host is the active element or the active
+ // 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;
+ }
+ }
+ // 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 = dom(active).getOwnerRoot();
+ while (activeRoot && activeRoot !== this.node) {
+ active = activeRoot.host;
+ activeRoot = dom(active).getOwnerRoot();
+ }
+ 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
+ },
+
childNodes: {
get: function() {
var c$ = TreeApi.Logical.getChildNodes(this.node);
@@ -569,4 +610,4 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
};
})();
-
\ No newline at end of file
+
diff --git a/test/unit/polymer-dom-elements.html b/test/unit/polymer-dom-elements.html
index c0b28546..64ac6b59 100644
--- a/test/unit/polymer-dom-elements.html
+++ b/test/unit/polymer-dom-elements.html
@@ -357,3 +357,245 @@
});
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/unit/polymer-dom-native-shadow.html b/test/unit/polymer-dom-native-shadow.html
index d7b9d116..49b23aaf 100644
--- a/test/unit/polymer-dom-native-shadow.html
+++ b/test/unit/polymer-dom-native-shadow.html
@@ -56,6 +56,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
+
+
+
+