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

8/1 master -> stable #192

Merged
merged 4 commits into from
Aug 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions src/ShadowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
var distributedChildNodesTable = new SideTable();
var eventParentsTable = new SideTable();
var insertionParentTable = new SideTable();
var nextOlderShadowTreeTable = new SideTable();
var rendererForHostTable = new SideTable();
var shadowDOMRendererTable = new SideTable();

Expand Down Expand Up @@ -370,10 +369,9 @@
},

renderShadowInsertionPoint: function(visualParent, tree, shadowInsertionPoint) {
var nextOlderTree = getNextOlderTree(tree);
var nextOlderTree = tree.olderShadowRoot;
if (nextOlderTree) {
assignToInsertionPoint(nextOlderTree, shadowInsertionPoint);
shadowInsertionPoint.olderShadowRoot_ = nextOlderTree;
this.remove(shadowInsertionPoint);
var shadowDOMChildNodes = getChildNodesSnapshot(nextOlderTree);
shadowDOMChildNodes.forEach(function(node) {
Expand Down Expand Up @@ -421,7 +419,7 @@

pool = distribute(tree, pool); // 4.2.
if (point) { // 4.3.
var nextOlderTree = getNextOlderTree(tree); // 4.3.1.
var nextOlderTree = tree.olderShadowRoot; // 4.3.1.
if (!nextOlderTree) {
break; // 4.3.1.1.
} else {
Expand Down Expand Up @@ -480,19 +478,10 @@
return !!shadowHost.shadowRoot;
}

/**
* @param {WrapperShadowRoot} tree
*/
function getNextOlderTree(tree) {
return nextOlderShadowTreeTable.get(tree);
}

function getShadowTrees(host) {
var trees = [];

for (var tree = host.shadowRoot;
tree;
tree = nextOlderShadowTreeTable.get(tree)) {
for (var tree = host.shadowRoot; tree; tree = tree.olderShadowRoot) {
trees.push(tree);
}
return trees;
Expand Down Expand Up @@ -535,9 +524,8 @@
scope.eventParentsTable = eventParentsTable;
scope.getRendererForHost = getRendererForHost;
scope.getShadowTrees = getShadowTrees;
scope.nextOlderShadowTreeTable = nextOlderShadowTreeTable;
scope.renderAllPending = renderAllPending;
scope.insertionParentTable = insertionParentTable;
scope.renderAllPending = renderAllPending;

// Exposed for testing
scope.visual = {
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
}

function adoptOlderShadowRoots(shadowRoot, doc) {
var oldShadowRoot = scope.nextOlderShadowTreeTable.get(shadowRoot);
var oldShadowRoot = shadowRoot.olderShadowRoot;
if (oldShadowRoot)
doc.adoptNode(oldShadowRoot);
}
Expand Down
7 changes: 1 addition & 6 deletions src/wrappers/HTMLShadowElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@

function HTMLShadowElement(node) {
HTMLElement.call(this, node);
this.olderShadowRoot_ = null;
}
HTMLShadowElement.prototype = Object.create(HTMLElement.prototype);
mixin(HTMLShadowElement.prototype, {
get olderShadowRoot() {
return this.olderShadowRoot_;
},

invalidateShadowRenderer: function() {
HTMLElement.prototype.invalidateShadowRenderer.call(this, true);
},
Expand All @@ -32,4 +27,4 @@
registerWrapper(OriginalHTMLShadowElement, HTMLShadowElement);

scope.wrappers.HTMLShadowElement = HTMLShadowElement;
})(this.ShadowDOMPolyfill);
})(this.ShadowDOMPolyfill);
7 changes: 6 additions & 1 deletion src/wrappers/ShadowRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
var unwrap = scope.unwrap;

var shadowHostTable = new SideTable();
var nextOlderShadowTreeTable = new SideTable();

function ShadowRoot(hostWrapper) {
var node = unwrap(hostWrapper.impl.ownerDocument.createDocumentFragment());
Expand All @@ -24,7 +25,7 @@
rewrap(node, this);

var oldShadowRoot = hostWrapper.shadowRoot;
scope.nextOlderShadowTreeTable.set(this, oldShadowRoot);
nextOlderShadowTreeTable.set(this, oldShadowRoot);

shadowHostTable.set(this, hostWrapper);
}
Expand All @@ -38,6 +39,10 @@
this.invalidateShadowRenderer();
},

get olderShadowRoot() {
return nextOlderShadowTreeTable.get(this) || null;
},

invalidateShadowRenderer: function() {
return shadowHostTable.get(this).invalidateShadowRenderer();
},
Expand Down
2 changes: 1 addition & 1 deletion src/wrappers/node-interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},

get previousElementSibling() {
return backwardsElement(this.nextSibling);
return backwardsElement(this.previousSibling);
}
};

Expand Down
54 changes: 54 additions & 0 deletions test/js/ChildNodeInterface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2013 The Polymer Authors. All rights reserved.
* Use of this source code is goverened by a BSD-style
* license that can be found in the LICENSE file.
*/

suite('ChildNodeInterface', function() {

function getTree() {
var tree = {};
var div = tree.div = document.createElement('div');
div.innerHTML = 'a<b></b>c<d></d>e';
var a = tree.a = div.firstChild;
var b = tree.b = a.nextSibling;
var c = tree.c = b.nextSibling;
var d = tree.d = c.nextSibling;
var e = tree.e = d.nextSibling;

var sr = tree.sr = div.createShadowRoot();
sr.innerHTML = 'f<g></g>h<content></content>i<j></j>k';
var f = tree.f = sr.firstChild;
var g = tree.g = f.nextSibling;
var h = tree.h = g.nextSibling;
var content = tree.content = h.nextSibling;
var i = tree.i = content.nextSibling;
var j = tree.j = i.nextSibling;
var k = tree.k = j.nextSibling;

div.offsetHeight; // trigger rendering

return tree;
}

test('nextElementSibling', function() {
var tree = getTree();

assert.equal(tree.b.nextElementSibling, tree.d);
assert.equal(tree.d.nextElementSibling, null);
assert.equal(tree.g.nextElementSibling, tree.content);
assert.equal(tree.content.nextElementSibling, tree.j);
assert.equal(tree.j.nextElementSibling, null);
});

test('previousElementSibling', function() {
var tree = getTree();

assert.equal(tree.b.previousElementSibling, null);
assert.equal(tree.d.previousElementSibling, tree.b);
assert.equal(tree.g.previousElementSibling, null);
assert.equal(tree.content.previousElementSibling, tree.g);
assert.equal(tree.j.previousElementSibling, tree.content);
});

});
5 changes: 1 addition & 4 deletions test/js/HTMLShadowElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ suite('HTMLShadowElement', function() {

var unwrap = ShadowDOMPolyfill.unwrap;

test('olderShadowRoot', function() {
test('instanceof HTMLShadowElement', function() {
var host = document.createElement('div');
host.innerHTML = '<a>a</a><b>b</b>';
var a = host.firstChild;
Expand All @@ -20,18 +20,15 @@ suite('HTMLShadowElement', function() {

host.offsetWidth;
assert.isTrue(shadow instanceof HTMLShadowElement);
assert.isNull(shadow.olderShadowRoot);

var sr2 = host.createShadowRoot();
sr2.innerHTML = 'd<shadow>e</shadow>f';
var shadow2 = sr2.firstElementChild;

host.offsetWidth;
assert.isTrue(shadow instanceof HTMLShadowElement);
assert.isNull(shadow.olderShadowRoot);

assert.isTrue(shadow2 instanceof HTMLShadowElement);
assert.equal(shadow2.olderShadowRoot, sr);

assert.equal(unwrap(host).innerHTML, 'dabcf');
});
Expand Down
19 changes: 19 additions & 0 deletions test/js/ShadowRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,23 @@ suite('ShadowRoot', function() {
assert.equal(sr.getElementById('b'), b);
});

test('olderShadowRoot', function() {
var host = document.createElement('div');
host.innerHTML = '<a>a</a><b>b</b>';
var a = host.firstChild;
var b = host.lastChild;

var sr = host.createShadowRoot();
sr.innerHTML = 'a';

host.offsetWidth;
assert.isNull(sr.olderShadowRoot);

var sr2 = host.createShadowRoot();
sr2.innerHTML = 'b';

host.offsetWidth;
assert.equal(sr2.olderShadowRoot, sr);
});

});
1 change: 1 addition & 0 deletions test/test.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mocha.setup({
})

var modules = [
'ChildNodeInterface.js',
'Comment.js',
'Document.js',
'Element.js',
Expand Down