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

Commit

Permalink
Bring shadow dom algorithms up to date
Browse files Browse the repository at this point in the history
This is a complete update of the distribution, composition and event
path algorithms from the spec draft.

Fixes #420
  • Loading branch information
arv committed Apr 22, 2014
1 parent 9513e0c commit b04881f
Show file tree
Hide file tree
Showing 16 changed files with 593 additions and 536 deletions.
488 changes: 231 additions & 257 deletions src/ShadowRenderer.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/TreeScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@
* A tree scope represents the root of a tree. All nodes in a tree point to
* the same TreeScope object. The tree scope of a node get set the first time
* it is accessed or when a node is added or remove to a tree.
*
* The root is a Node that has no parent.
*
* The parent is another TreeScope. For ShadowRoots, it is the TreeScope of
* the host of the ShadowRoot.
*
* @param {!Node} root
* @param {TreeScope} parent
* @constructor
*/
function TreeScope(root, parent) {
/** @type {!Node} */
this.root = root;

/** @type {TreeScope} */
this.parent = parent;
}

Expand Down Expand Up @@ -48,6 +59,10 @@
}

function getTreeScope(node) {
if (node instanceof scope.wrappers.Window) {
debugger;
}

if (node.treeScope_)
return node.treeScope_;
var parent = node.parentNode;
Expand Down
4 changes: 4 additions & 0 deletions src/wrappers/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@
new DOMImplementation(unwrap(this).implementation);
implementationTable.set(this, implementation);
return implementation;
},

get defaultView() {
return wrap(unwrap(this).defaultView);
}
});

Expand Down
2 changes: 2 additions & 0 deletions src/wrappers/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
return this.impl.polymerShadowRoot_ || null;
},

// getDestinationInsertionPoints added in ShadowRenderer.js

setAttribute: function(name, value) {
var oldValue = this.impl.getAttribute(name);
this.impl.setAttribute(name, value);
Expand Down
2 changes: 0 additions & 2 deletions src/wrappers/HTMLContentElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
}

// getDistributedNodes is added in ShadowRenderer

// TODO: attribute boolean resetStyleInheritance;
});

if (OriginalHTMLContentElement)
Expand Down
6 changes: 3 additions & 3 deletions src/wrappers/HTMLShadowElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

var HTMLElement = scope.wrappers.HTMLElement;
var mixin = scope.mixin;
var NodeList = scope.wrappers.NodeList;
var registerWrapper = scope.registerWrapper;

var OriginalHTMLShadowElement = window.HTMLShadowElement;
Expand All @@ -15,9 +16,8 @@
HTMLElement.call(this, node);
}
HTMLShadowElement.prototype = Object.create(HTMLElement.prototype);
mixin(HTMLShadowElement.prototype, {
// TODO: attribute boolean resetStyleInheritance;
});

// getDistributedNodes is added in ShadowRenderer

if (OriginalHTMLShadowElement)
registerWrapper(OriginalHTMLShadowElement, HTMLShadowElement);
Expand Down
5 changes: 3 additions & 2 deletions src/wrappers/ShadowRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
// DocumentFragment instance. Override that.
rewrap(node, this);

this.treeScope_ = new TreeScope(this, getTreeScope(hostWrapper));

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

this.treeScope_ =
new TreeScope(this, getTreeScope(oldShadowRoot || hostWrapper));

shadowHostTable.set(this, hostWrapper);
}
ShadowRoot.prototype = Object.create(DocumentFragment.prototype);
Expand Down
6 changes: 5 additions & 1 deletion src/wrappers/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@
renderAllPending();
return new Selection(originalGetSelection.call(unwrap(this)));
},

get document() {
return wrap(unwrap(this).document);
}
});

registerWrapper(OriginalWindow, Window);
registerWrapper(OriginalWindow, Window, window);

scope.wrappers.Window = Window;

Expand Down
Loading

0 comments on commit b04881f

Please sign in to comment.