diff --git a/src/lib/dom-api-shady.html b/src/lib/dom-api-shady.html
index a729c16117..461566cd7f 100644
--- a/src/lib/dom-api-shady.html
+++ b/src/lib/dom-api-shady.html
@@ -502,61 +502,28 @@
firstElementChild: {
get: function() {
- if (this.node.__firstChild) {
- var n = this.node.__firstChild;
- while (n && n.nodeType !== Node.ELEMENT_NODE) {
- n = n.__nextSibling;
- }
- return n;
- } else {
- return this.node.firstElementChild;
- }
-
+ return TreeApi.Logical.getFirstElementChild(this.node);
},
configurable: true
},
lastElementChild: {
get: function() {
- if (this.node.__lastChild) {
- var n = this.node.__lastChild;
- while (n && n.nodeType !== Node.ELEMENT_NODE) {
- n = n.__previousSibling;
- }
- return n;
- } else {
- return this.node.lastElementChild;
- }
+ return TreeApi.Logical.getLastElementChild(this.node);
},
configurable: true
},
nextElementSibling: {
get: function() {
- if (this.node.__nextSibling) {
- var n = this.node.__nextSibling;
- while (n && n.nodeType !== Node.ELEMENT_NODE) {
- n = n.__nextSibling;
- }
- return n;
- } else {
- return this.node.nextElementSibling;
- }
+ return TreeApi.Logical.getNextElementSibling(this.node);
},
configurable: true
},
previousElementSibling: {
get: function() {
- if (this.node.__previousSibling) {
- var n = this.node.__previousSibling;
- while (n && n.nodeType !== Node.ELEMENT_NODE) {
- n = n.__previousSibling;
- }
- return n;
- } else {
- return this.node.previousElementSibling;
- }
+ return TreeApi.Logical.getPreviousElementSibling(this.node);
},
configurable: true
},
diff --git a/src/lib/dom-tree-api.html b/src/lib/dom-tree-api.html
index eaf81474bb..a1889cab79 100644
--- a/src/lib/dom-tree-api.html
+++ b/src/lib/dom-tree-api.html
@@ -104,6 +104,54 @@
return node.__previousSibling || TreeApi.Composed.getPreviousSibling(node);
},
+ getFirstElementChild: function(node) {
+ if (node.__firstChild) {
+ var n = node.__firstChild;
+ while (n && n.nodeType !== Node.ELEMENT_NODE) {
+ n = n.__nextSibling;
+ }
+ return n;
+ } else {
+ return TreeApi.Composed.getFirstElementChild(node);
+ }
+ },
+
+ getLastElementChild: function(node) {
+ if (node.__lastChild) {
+ var n = node.__lastChild;
+ while (n && n.nodeType !== Node.ELEMENT_NODE) {
+ n = n.__previousSibling;
+ }
+ return n;
+ } else {
+ return TreeApi.Composed.getLastElementChild(node);
+ }
+ },
+
+ getNextElementSibling: function(node) {
+ if (node.__nextSibling) {
+ var n = node.__nextSibling;
+ while (n && n.nodeType !== Node.ELEMENT_NODE) {
+ n = n.__nextSibling;
+ }
+ return n;
+ } else {
+ return TreeApi.Composed.getNextElementSibling(node);
+ }
+ },
+
+ getPreviousElementSibling: function(node) {
+ if (node.__previousSibling) {
+ var n = node.__previousSibling;
+ while (n && n.nodeType !== Node.ELEMENT_NODE) {
+ n = n.__previousSibling;
+ }
+ return n;
+ } else {
+ return TreeApi.Composed.getPreviousElementSibling(node);
+ }
+ },
+
// Capture the list of light children. It's important to do this before we
// start transforming the DOM into "rendered" state.
// Children may be added to this list dynamically. It will be treated as the
@@ -222,6 +270,22 @@
return node.previousSibling;
},
+ getFirstElementChild: function(node) {
+ return node.firstElementChild;
+ },
+
+ getLastElementChild: function(node) {
+ return node.lastElementChild;
+ },
+
+ getNextElementSibling: function(node) {
+ return node.nextElementSibling;
+ },
+
+ getPreviousElementSibling: function(node) {
+ return node.previousElementSibling;
+ },
+
// composed tracking needs to reset composed children here in case
// they may have already been set (this shouldn't happen but can
// if dependency ordering is incorrect and as a result upgrade order
diff --git a/src/lib/experimental/patch-dom.html b/src/lib/experimental/patch-dom.html
index e1005d5436..571983e67c 100644
--- a/src/lib/experimental/patch-dom.html
+++ b/src/lib/experimental/patch-dom.html
@@ -27,6 +27,8 @@
return;
}
+ count = 0;
+
var baseFinishDistribute = Polymer.Base._finishDistribute;
var TreeApi = Polymer.TreeApi;
var DomApi = Polymer.DomApi;
@@ -116,6 +118,8 @@
var log = false;
+ var count = 0;
+
var patchImpl = {
hasPrototypeDescriptors: Boolean(Object.getOwnPropertyDescriptor(
@@ -338,6 +342,68 @@
}
},
+ getFirstElementChild: function(node) {
+ if (node.__patched) {
+ var c$ = this.getChildNodes(node);
+ for (var i=0, n; i < c$.length; i++) {
+ n = c$[i];
+ if (n.nodeType === Node.ELEMENT_NODE) {
+ return n;
+ }
+ }
+ } else {
+ return node.firstElementChild;
+ }
+ },
+
+ getLastElementChild: function(node) {
+ if (node.__patched) {
+ var c$ = this.getChildNodes(node);
+ for (var i=c$.length, n; i >=0 ; i--) {
+ n = c$[i];
+ if (n.nodeType === Node.ELEMENT_NODE) {
+ return n;
+ }
+ }
+ } else {
+ return node.lastElementChild;
+ }
+ },
+
+ getNextElementSibling: function(node) {
+ if (node.__patched) {
+ var c$ = this.getChildNodes(node);
+ var i = c$.indexOf(node);
+ if (i >= 0) {
+ for (var n; i < c$.length; i++) {
+ n = c$[i];
+ if (n.nodeType === Node.ELEMENT_NODE) {
+ return n;
+ }
+ }
+ }
+ } else {
+ return node.nextElementSibling;
+ }
+ },
+
+ getPreviousElementSibling: function(node) {
+ if (node.__patched) {
+ var c$ = this.getChildNodes(node);
+ var i = c$.indexOf(node);
+ if (i >= 0) {
+ for (var n; i >=0 ; i--) {
+ n = c$[i];
+ if (n.nodeType === Node.ELEMENT_NODE) {
+ return n;
+ }
+ }
+ }
+ } else {
+ return node.previousElementSibling;
+ }
+ },
+
// composed tracking needs to reset composed children here in case
// they may have already been set (this shouldn't happen but can
// if dependency ordering is incorrect and as a result upgrade order