Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Call nodeWasAdded on all the nodes in the added tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Sep 20, 2013
1 parent ce8d190 commit 434b710
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/ShadowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,9 @@
};

HTMLContentElement.prototype.getDistributedNodes = function() {
var renderer = this.impl.polymerShadowRenderer_;
if (renderer)
renderer.render();
// TODO(arv): We should only rerender the dirty ancestor renderers (from
// the root and down).
renderAllPending();
return getDistributedChildNodes(this);
};

Expand Down
6 changes: 5 additions & 1 deletion src/wrappers/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,11 @@
* the renderer as needed.
* @private
*/
nodeWasAdded_: function() {},
nodeWasAdded_: function() {
for (var child = this.firstChild; child; child = child.nextSibling) {
child.nodeWasAdded_();
}
},

hasChildNodes: function() {
return this.firstChild === null;
Expand Down
59 changes: 59 additions & 0 deletions test/js/HTMLContentElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,39 @@ suite('HTMLContentElement', function() {
assertArrayEqual(content.getDistributedNodes().length, 3);
});

test('getDistributedNodes add content deep inside tree', function() {
var host = document.createElement('div');
host.innerHTML = ' <a></a> <a></a> <a></a> ';
var root = host.createShadowRoot();
var b = document.createElement('b');
var content = b.appendChild(document.createElement('content'));
content.select = '*';
root.appendChild(b);

assert.equal(content.getDistributedNodes().length, 3);
assertArrayEqual(content.getDistributedNodes(), host.children);
});

test('getDistributedNodes add content deeper inside tree', function() {
var foo = document.createElement('div');
var fooRoot = foo.createShadowRoot();
fooRoot.innerHTML = '<div>' +
' <div>item1</div> <div>item2</div> <div>item3</div> ' +
'</div>';

var bar = fooRoot.firstChild;
var barRoot = bar.createShadowRoot();
barRoot.innerHTML = '<div><content></content></div>';

var zot = barRoot.firstChild;
var zotRoot = zot.createShadowRoot();
zotRoot.innerHTML = '<content select="*"></content>';
var content = zotRoot.firstChild;

assert.equal(content.getDistributedNodes().length, 3);
assertArrayEqual(content.getDistributedNodes(), fooRoot.firstChild.children);
});

test('adding a new content element to a shadow tree', function() {
var host = document.createElement('div');
host.innerHTML = '<a></a><b></b>';
Expand All @@ -80,6 +113,32 @@ suite('HTMLContentElement', function() {
assert.equal(unwrap(host).innerHTML, '<c></c>');
});

test('adding a new content element to a shadow tree 2', function() {
var host = document.createElement('div');
host.innerHTML = '<a></a><b></b>';
var a = host.firstChild;
var b = host.lastChild;

var sr = host.createShadowRoot();
sr.innerHTML = '<c></c>';
var c = sr.firstChild;

host.offsetHeight;
assert.equal(unwrap(host).innerHTML, '<c></c>');

var d = document.createElement('d');
var content = d.appendChild(document.createElement('content'));
content.select = 'b';
c.appendChild(d);

host.offsetHeight;
assert.equal(unwrap(host).innerHTML, '<c><d><b></b></d></c>');

c.removeChild(d);
host.offsetHeight;
assert.equal(unwrap(host).innerHTML, '<c></c>');
});

test('restricting select further', function() {
var host = document.createElement('div');
host.innerHTML = '<a></a><b></b>';
Expand Down

0 comments on commit 434b710

Please sign in to comment.