Skip to content

Commit

Permalink
Shady patching: patch element accessors in composed tree; fixes HTMLI…
Browse files Browse the repository at this point in the history
…mports polyfill support.
  • Loading branch information
Steven Orvell committed Dec 14, 2015
1 parent c3fbd10 commit d135fef
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 37 deletions.
41 changes: 4 additions & 37 deletions src/lib/dom-api-shady.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
64 changes: 64 additions & 0 deletions src/lib/dom-tree-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions src/lib/experimental/patch-dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
return;
}

count = 0;

var baseFinishDistribute = Polymer.Base._finishDistribute;
var TreeApi = Polymer.TreeApi;
var DomApi = Polymer.DomApi;
Expand Down Expand Up @@ -116,6 +118,8 @@

var log = false;

var count = 0;

var patchImpl = {

hasPrototypeDescriptors: Boolean(Object.getOwnPropertyDescriptor(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d135fef

Please sign in to comment.