From 434b71007d3c87edd063ac8c397c1d4c71523b91 Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Fri, 13 Sep 2013 17:21:09 -0400 Subject: [PATCH] Call nodeWasAdded on all the nodes in the added tree. --- src/ShadowRenderer.js | 6 ++-- src/wrappers/Node.js | 6 +++- test/js/HTMLContentElement.js | 59 +++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/ShadowRenderer.js b/src/ShadowRenderer.js index ee22efc..5c117e5 100644 --- a/src/ShadowRenderer.js +++ b/src/ShadowRenderer.js @@ -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); }; diff --git a/src/wrappers/Node.js b/src/wrappers/Node.js index 55c13fc..9633c59 100644 --- a/src/wrappers/Node.js +++ b/src/wrappers/Node.js @@ -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; diff --git a/test/js/HTMLContentElement.js b/test/js/HTMLContentElement.js index 9012f85..631d3a7 100644 --- a/test/js/HTMLContentElement.js +++ b/test/js/HTMLContentElement.js @@ -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 = ' '; + 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 = '
' + + '
item1
item2
item3
' + + '
'; + + var bar = fooRoot.firstChild; + var barRoot = bar.createShadowRoot(); + barRoot.innerHTML = '
'; + + var zot = barRoot.firstChild; + var zotRoot = zot.createShadowRoot(); + zotRoot.innerHTML = ''; + 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 = ''; @@ -80,6 +113,32 @@ suite('HTMLContentElement', function() { assert.equal(unwrap(host).innerHTML, ''); }); + test('adding a new content element to a shadow tree 2', function() { + var host = document.createElement('div'); + host.innerHTML = ''; + var a = host.firstChild; + var b = host.lastChild; + + var sr = host.createShadowRoot(); + sr.innerHTML = ''; + var c = sr.firstChild; + + host.offsetHeight; + assert.equal(unwrap(host).innerHTML, ''); + + 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.removeChild(d); + host.offsetHeight; + assert.equal(unwrap(host).innerHTML, ''); + }); + test('restricting select further', function() { var host = document.createElement('div'); host.innerHTML = '';