Skip to content
Browse files

Add logical info iff an element being added is an insertion point; do…

… not add logical info for any element in a shady root.
  • Loading branch information...
1 parent 21500fb commit 45cb1506a610a4f4421f84ac9e0d690902537335 @sorvell sorvell committed
Showing with 26 additions and 6 deletions.
  1. +26 −6 src/lib/dom-api.html
View
32 src/lib/dom-api.html
@@ -65,11 +65,15 @@
// 3. node is <content> (host of container needs distribution)
appendChild: function(node) {
var handled;
+ // if a <content> is added, make sure it's parent has logical info.
+ this._ensureContentLogicalInfo(node);
this._removeNodeFromHost(node, true);
if (this._nodeIsInLogicalTree(this.node)) {
this._addLogicalInfo(node, this.node);
this._addNodeToHost(node);
handled = this._maybeDistribute(node, this.node);
+ } else {
+ this._addNodeToHost(node);
}
// if not distributing and not adding to host, do a fast path addition
if (!handled && !this._tryRemoveUndistributedNode(node)) {
@@ -86,9 +90,10 @@
return this.appendChild(node);
}
var handled;
+ // if a <content> is added, make sure it's parent has logical info.
+ this._ensureContentLogicalInfo(node);
this._removeNodeFromHost(node, true);
if (this._nodeIsInLogicalTree(this.node)) {
- saveLightChildrenIfNeeded(this.node);
var children = this.childNodes;
var index = children.indexOf(ref_node);
if (index < 0) {
@@ -98,6 +103,8 @@
this._addLogicalInfo(node, this.node, index);
this._addNodeToHost(node);
handled = this._maybeDistribute(node, this.node);
+ } else {
+ this._addNodeToHost(node);
}
// if not distributing and not adding to host, do a fast path addition
if (!handled && !this._tryRemoveUndistributedNode(node)) {
@@ -125,6 +132,8 @@
if (this._nodeIsInLogicalTree(this.node)) {
this._removeNodeFromHost(node);
handled = this._maybeDistribute(node, this.node);
+ } else {
+ this._removeNodeFromHost(node);
}
if (!handled) {
// if removing from a shadyRoot, remove form host instead
@@ -237,10 +246,23 @@
// or has a lightParent
_nodeIsInLogicalTree: function(node) {
return Boolean((node._lightParent !== undefined) || node._isShadyRoot ||
- this._ownerShadyRootForNode(node) ||
node.shadyRoot);
},
+ _ensureContentLogicalInfo: function(node) {
+ if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
+ saveLightChildrenIfNeeded(this.node);
+ var c$ = Array.prototype.slice.call(node.childNodes);
+ for (var i=0, n; (i<c$.length) && (n=c$[i]); i++) {
+ this._ensureContentLogicalInfo(n);
+ }
+ } else if (node.localName === CONTENT) {
+ // should be parent not this.node, but this is before parent is set.
+ saveLightChildrenIfNeeded(this.node);
+ saveLightChildrenIfNeeded(node);
+ }
+ },
+
_parentNeedsDistribution: function(parent) {
return parent && parent.shadyRoot && hasInsertionPoint(parent.shadyRoot);
},
@@ -298,17 +320,15 @@
}
},
+ // a node being added is always in this same host as this.node.
_addNodeToHost: function(node) {
- var checkNode = node.nodeType === Node.DOCUMENT_FRAGMENT_NODE ?
- node.firstChild : node;
- var root = this._ownerShadyRootForNode(checkNode);
+ var root = this.getOwnerRoot();
if (root) {
root.host._elementAdd(node);
}
},
_addLogicalInfo: function(node, container, index) {
- saveLightChildrenIfNeeded(container);
var children = factory(container).childNodes;
index = index === undefined ? children.length : index;
// handle document fragments

0 comments on commit 45cb150

Please sign in to comment.
Something went wrong with that request. Please try again.