提交 67a3adff 编写于 作者: H Hixie

Specs: Simplify the platform by only having one shadow tree per element.

R=esprehn@chromium.org

Review URL: https://codereview.chromium.org/694613002
上级 cf29897c
...@@ -11,32 +11,36 @@ SKY MODULE - radio button and radio button group ...@@ -11,32 +11,36 @@ SKY MODULE - radio button and radio button group
</template> </template>
<script> <script>
module.exports = {}; module.exports = {};
module.exports.RadioElement = sky.registerElement('radio', class extends Element { module.exports.RadioElement = sky.registerElement({
constructor () { tagName: 'radio',
super(); shadow: true,
this.addEventListener('click', (event) => this.checked = true); prototype: class extends Element {
this.addShadowRoot(new sky.ShadowRoot(module.document.findId('radio-shadow').content.cloneNode(true))); constructor () {
} super();
get checked () { this.addEventListener('click', (event) => this.checked = true);
return this.hasAttribute('checked'); this.shadowRoot.appendChild(module.document.findId('radio-shadow').content.cloneNode(true));
} }
set checked (value) { get checked () {
if (value) return this.hasAttribute('checked');
this.setAttribute('checked', ''); }
else set checked (value) {
this.removeAttribute('checked'); if (value)
} this.setAttribute('checked', '');
get value () { else
return this.getAttribute('name'); this.removeAttribute('checked');
} }
set value (value) { get value () {
this.setAttribute('value', value); return this.getAttribute('name');
} }
attributeChanged(name, oldValue, newValue) { set value (value) {
if ((name == 'checked') && (newValue != null)) this.setAttribute('value', value);
if (this.parentNode instanceof module.exports.RadioGroupElement) }
this.parentNode.setChecked(this); attributeChanged(name, oldValue, newValue) {
} if ((name == 'checked') && (newValue != null))
if (this.parentNode instanceof module.exports.RadioGroupElement)
this.parentNode.setChecked(this);
}
},
}); });
</script> </script>
...@@ -47,34 +51,38 @@ SKY MODULE - radio button and radio button group ...@@ -47,34 +51,38 @@ SKY MODULE - radio button and radio button group
</style> </style>
</template> </template>
<script> <script>
module.exports.RadioGroupElement = sky.registerElement('radiogroup', class extends Element { module.exports.RadioGroupElement = sky.registerElement({
constructor () { tagName: 'radiogroup',
super(); shadow: true,
this.addShadowRoot(new sky.ShadowRoot(module.document.findId('radiogroup-shadow').content.cloneNode(true))); prototype: class extends Element {
} constructor () {
get value () { super();
let children = this.getChildNodes(); this.shadowRoot.appendChild(module.document.findId('radiogroup-shadow').content.cloneNode(true));
for (let child of children) }
if (child instanceof module.exports.RadioElement) get value () {
if (child.checked) let children = this.getChildNodes();
return child.name; for (let child of children)
return ''; if (child instanceof module.exports.RadioElement)
} if (child.checked)
set value (name) { return child.name;
let children = this.getChildNodes(); return '';
for (let child of children) }
if (child instanceof module.exports.RadioElement) set value (name) {
if (child.value == name) let children = this.getChildNodes();
child.checked = true; for (let child of children)
} if (child instanceof module.exports.RadioElement)
setChecked(radio) { if (child.value == name)
if (!((radio instanceof module.exports.Radio) && radio.parentNode == this)) child.checked = true;
throw; }
let children = this.getChildNodes(); setChecked(radio) {
for (let child of children) if (!((radio instanceof module.exports.Radio) && radio.parentNode == this))
if (child instanceof module.exports.RadioElement) throw;
if (child != radio) let children = this.getChildNodes();
child.checked = false; for (let child of children)
} if (child instanceof module.exports.RadioElement)
if (child != radio)
child.checked = false;
}
},
}); });
</script> </script>
...@@ -98,12 +98,10 @@ module 'sky:core' { ...@@ -98,12 +98,10 @@ module 'sky:core' {
// Returns a new Array and new Attr instances every time. // Returns a new Array and new Attr instances every time.
Array<Attr> getAttributes(); // O(N) in arguments Array<Attr> getAttributes(); // O(N) in arguments
readonly attribute ShadowRoot? shadowRoot; // O(1) // returns the youngest shadow root readonly attribute ShadowRoot? shadowRoot; // O(1) // returns the shadow root
void addShadowRoot(ShadowRoot root); // O(N) in descendants of argument
Array<ContentElement> getDestinationInsertionPoints(); // O(N) in number of insertion points the node is in Array<ContentElement> getDestinationInsertionPoints(); // O(N) in number of insertion points the node is in
virtual void attributeChangeCallback(String name, String? oldValue, String? newValue); // noop virtual void attributeChangeCallback(String name, String? oldValue, String? newValue); // noop
virtual void shadowRootChangeCallback(ShadowRoot root); // noop
// TODO(ianh): does a node ever need to know when it's been redistributed? // TODO(ianh): does a node ever need to know when it's been redistributed?
} }
Element createElement(String tagName, Dictionary attributes, ChildArguments... nodes); // O(M+N), M = number of attributes, N = number of nodes plus all their descendants Element createElement(String tagName, Dictionary attributes, ChildArguments... nodes); // O(M+N), M = number of attributes, N = number of nodes plus all their descendants
...@@ -111,7 +109,12 @@ module 'sky:core' { ...@@ -111,7 +109,12 @@ module 'sky:core' {
Element createElement(String tagName, ChildArguments... nodes); // shorthand Element createElement(String tagName, ChildArguments... nodes); // shorthand
Element createElement(String tagName); // shorthand Element createElement(String tagName); // shorthand
Object registerElement(String tagName, Object interfaceObject); // O(N) in number of outstanding elements with that tag name to be upgraded dictionary ElementRegistration {
String tagName;
Boolean shadow;
Object prototype;
}
Object registerElement(ElementRegistration options); // O(N) in number of outstanding elements with that tag name to be upgraded
interface Text : Node { interface Text : Node {
constructor (String value); // O(1) constructor (String value); // O(1)
...@@ -134,10 +137,8 @@ module 'sky:core' { ...@@ -134,10 +137,8 @@ module 'sky:core' {
} }
interface ShadowRoot : TreeScope { interface ShadowRoot : TreeScope {
constructor (ChildArguments... nodes); // O(N) in number of arguments plus all their descendants constructor (Element host); // O(1) // note that there is no way in the API to use a newly created ShadowRoot
readonly attribute Element? host; // O(1) readonly attribute Element host; // O(1)
readonly attribute ShadowRoot? olderShadowRoot; // O(1)
void removeShadowRoot(); // O(N) in descendants
} }
interface Document : TreeScope { interface Document : TreeScope {
...@@ -162,9 +163,6 @@ module 'sky:core' { ...@@ -162,9 +163,6 @@ module 'sky:core' {
interface ContentElement : Element { interface ContentElement : Element {
Array<Node> getDistributedNodes(); // O(N) in distributed nodes Array<Node> getDistributedNodes(); // O(N) in distributed nodes
} }
interface ShadowElement : Element {
Array<Node> getDistributedNodes(); // O(N) in distributed nodes
}
interface ImgElement : Element { } interface ImgElement : Element { }
interface IframeElement : Element { } interface IframeElement : Element { }
interface TElement : Element { } interface TElement : Element { }
...@@ -267,6 +265,11 @@ module 'sky:modulename' { ...@@ -267,6 +265,11 @@ module 'sky:modulename' {
ReturnType method(ArgumentType argumentName1, ArgumentType... allSubsequentArguments); ReturnType method(ArgumentType argumentName1, ArgumentType... allSubsequentArguments);
} }
dictionary Options {
String foo;
Integer bar;
}
// the module can have properties and methods also // the module can have properties and methods also
attribute String Foo; attribute String Foo;
void method(); void method();
...@@ -309,6 +312,7 @@ The following types are available: ...@@ -309,6 +312,7 @@ The following types are available:
* ``Boolean`` - WebIDL ``boolean`` * ``Boolean`` - WebIDL ``boolean``
# ``Object`` - WebIDL ``object`` # ``Object`` - WebIDL ``object``
* ``InterfaceName`` - an instance of the interface InterfaceName * ``InterfaceName`` - an instance of the interface InterfaceName
* ``DictionaryName`` - an instance of the dictionary DictionaryName
* ``Promise<Type>`` - WebIDL ``Promise<T>`` * ``Promise<Type>`` - WebIDL ``Promise<T>``
* ``Array<Type>`` - WebIDL ``sequence<T>`` * ``Array<Type>`` - WebIDL ``sequence<T>``
* ``Dictionary`` - unordered set of name-value String-String pairs with no duplicate names * ``Dictionary`` - unordered set of name-value String-String pairs with no duplicate names
......
...@@ -172,9 +172,6 @@ that everything of note would be provided by frameworks. ...@@ -172,9 +172,6 @@ that everything of note would be provided by frameworks.
The select="" attribute gives the selector to use to pick the nodes The select="" attribute gives the selector to use to pick the nodes
to place in this insertion point; it defaults to everything. to place in this insertion point; it defaults to everything.
``<shadow>``
- In a shadow tree, acts as an insertion point for older shadow trees.
``<img src="foo.bin">`` ``<img src="foo.bin">``
- Sky fetches the bits for foo.bin, looks for a decoder for those - Sky fetches the bits for foo.bin, looks for a decoder for those
bits, and renders the bits that the decoder returns. bits, and renders the bits that the decoder returns.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册