Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Side by Side Diff: sky/specs/elements.md

Issue 938183002: Specs: move needsShadow to an annotation (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 Sky DOM APIs 1 Sky DOM APIs
2 ============ 2 ============
3 3
4 ```dart 4 ```dart
5 SKY MODULE 5 SKY MODULE
6 <!-- part of dart:sky --> 6 <!-- part of dart:sky -->
7 7
8 <script> 8 <script>
9 // ELEMENT TREE API 9 // ELEMENT TREE API
10 10
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 const tagname(this.name); 190 const tagname(this.name);
191 final String name; 191 final String name;
192 void init(DeclarationMirror target, Module module) { 192 void init(DeclarationMirror target, Module module) {
193 assert(target is ClassMirror); 193 assert(target is ClassMirror);
194 if (!target.isSubclassOf(reflectClass(Element))) 194 if (!target.isSubclassOf(reflectClass(Element)))
195 throw Error('@tagname can only be used on descendants of Element'); 195 throw Error('@tagname can only be used on descendants of Element');
196 module.registerElement(name, (target as ClassMirror).reflectedType); 196 module.registerElement(name, (target as ClassMirror).reflectedType);
197 } 197 }
198 } 198 }
199 199
200 // @hasShadow annotation for registering elements
201 class _HasShadow {
202 const HasShadow();
203 }
204 const hasShadow = const _HasShadow();
205
200 abstract class Element extends ParentNode { 206 abstract class Element extends ParentNode {
201 external Element({Map<String, String> attributes: null, 207 Element({Map<String, String> attributes: null,
202 List children: null, 208 List children: null,
203 Module hostModule: null}); // O(M+N), M = number of attribute s, N = number of children nodes plus all their descendants 209 Module hostModule: null}) { // O(M+N), M = number of attributes, N = number of children nodes plus all their descendants
210 var shadowClass = reflectClass(hasShadow);
211 bool needsShadow = reflect(this).type.metadata.singleWhere((mirror) => mirro r.type == hasShadowClass);
212 if (children != null)
213 children = children.map((node) => node is String ? new Text(node) : node). toList();
214 this._initElement(attributes, children, hostModule, needsShadow);
215 }
216 external void _initElement(Map<String, String> attributes, List children, Modu le hostModule, bool needsShadow);
204 // initialises the internal attributes table, which is a ordered list 217 // initialises the internal attributes table, which is a ordered list
205 // appends the given children nodes 218 // appends the given children nodes
206 // children must be String, Text, or Element 219 // children must be Text or Element
207 // if this.needsShadow, creates a shadow tree 220 // if needsShadow is true, creates a shadow tree
208 221
209 String get tagName { // O(N) in number of annotations on the class 222 String get tagName { // O(N) in number of annotations on the class
210 // throws a StateError if the class doesn't have an @tagname annotation 223 // throws a StateError if the class doesn't have an @tagname annotation
211 var tagnameClass = reflectClass(tagname); 224 var tagnameClass = reflectClass(tagname);
212 return (reflectClass(this.runtimeType).metadata.singleWhere((mirror) => mirr or.type == tagnameClass).reflectee as tagname).value; 225 return (reflectClass(this.runtimeType).metadata.singleWhere((mirror) => mirr or.type == tagnameClass).reflectee as tagname).value;
213 } 226 }
214 227
215 external bool hasAttribute(String name); // O(N) in number of attributes 228 external bool hasAttribute(String name); // O(N) in number of attributes
216 external String getAttribute(String name); // O(N) in number of attributes 229 external String getAttribute(String name); // O(N) in number of attributes
217 external void setAttribute(String name, [String value = '']); // O(N) in numbe r of attributes 230 external void setAttribute(String name, [String value = '']); // O(N) in numbe r of attributes
218 external void removeAttribute(String name); // O(N) in number of attributes 231 external void removeAttribute(String name); // O(N) in number of attributes
219 // calling setAttribute() with a null value removes the attribute 232 // calling setAttribute() with a null value removes the attribute
220 // (calling it without a value sets it to the empty string) 233 // (calling it without a value sets it to the empty string)
221 234
222 // Returns a new Array and new Attr instances every time. 235 // Returns a new Array and new Attr instances every time.
223 external List<Attr> getAttributes(); // O(N) in number of attributes 236 external List<Attr> getAttributes(); // O(N) in number of attributes
224 237
225 get bool needsShadow => false; // O(1)
226 external final Root shadowRoot; // O(1) 238 external final Root shadowRoot; // O(1)
227 // returns the shadow root 239 // returns the shadow root
228 240
229 void endTagParsedCallback() { } 241 void endTagParsedCallback() { }
230 void attributeChangeCallback(String name, String oldValue, String newValue) { } 242 void attributeChangeCallback(String name, String oldValue, String newValue) { }
231 // name will never be null when this is called by sky 243 // name will never be null when this is called by sky
232 244
233 // TODO(ianh): does a node ever need to know when it's been redistributed? 245 // TODO(ianh): does a node ever need to know when it's been redistributed?
234 246
235 @override 247 @override
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 external bool matches(Element element); // O(F()) 397 external bool matches(Element element); // O(F())
386 external Element find(Node root); // O(N*F())+O(M) where N is the number of de scendants and M the average depth of the tree 398 external Element find(Node root); // O(N*F())+O(M) where N is the number of de scendants and M the average depth of the tree
387 external List<Element> findAll(Node root); // O(N*F())+O(N*M) where N is the n umber of descendants and M the average depth of the tree 399 external List<Element> findAll(Node root); // O(N*F())+O(N*M) where N is the n umber of descendants and M the average depth of the tree
388 // find() and findAll() throw if the root is not one of the following: 400 // find() and findAll() throw if the root is not one of the following:
389 // - Element 401 // - Element
390 // - Fragment 402 // - Fragment
391 // - Root 403 // - Root
392 } 404 }
393 </script> 405 </script>
394 ``` 406 ```
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698