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

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

Issue 974313003: Specs: fix typos in style2.md, checkin forgotten builtins.md, add guard feature to runloop.md, rena… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 | « sky/specs/runloop.md ('k') | sky/specs/utils.md » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 Sky Style Language 1 Sky Style Language
2 ================== 2 ==================
3 3
4 Note: This is a work in progress that will eventually replace 4 This is a trimmed down version of the API in (style.md)[style.md]
5 (style.md)[style.md]. 5 that is intended to be a stepping stone to the long-term world where
6 there are no hard-coded properties in the engine.
6 7
7 The Sky style API looks like the following: 8 The Sky style API looks like the following:
8 9
9 ```dart 10 ```dart
10 11
11 // all properties can be set as strings: 12 // all properties can be set as strings:
12 element.style['color'] = 'blue'; 13 element.style['color'] = 'blue';
13 14
14 // some properties have dedicated APIs 15 // some properties have dedicated APIs
15 // color 16 // color
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // you can clone a StyleDeclaration object: 51 // you can clone a StyleDeclaration object:
51 var style2 = new StyleDeclaration.clone(style); 52 var style2 = new StyleDeclaration.clone(style);
52 ``` 53 ```
53 54
54 The dart:sky library contains the following to define this API: 55 The dart:sky library contains the following to define this API:
55 56
56 ```dart 57 ```dart
57 import 'dart:mirrors'; 58 import 'dart:mirrors';
58 import 'dart:math'; 59 import 'dart:math';
59 60
60 class WeakMap<Key, Value> {
61 // This is not actually a weak map right now, because Dart doesn't let us have weak references.
62 // We should fix that, or else we're going to keep alive every object you ever tear off through
63 // the StyleDeclaration API, even if you never use it again, until the StyleDe claration object
64 // itself is GC'ed, which is likely when the element is GC'ed, which is likely never.
65 Map<Key, Value> _map = new Map<Key, Value>();
66 operator[](Key key) => _map[key];
67 operator[]=(Key key, Value value) => _map[key] = value;
68 bool containsKey(Key key) => _map.containsKey(key);
69 }
70
71 typedef void StringSetter(Symbol propertySymbol, StyleDeclaration declaration, S tring value); 61 typedef void StringSetter(Symbol propertySymbol, StyleDeclaration declaration, S tring value);
72 typedef String StringGetter(Symbol propertySymbol, StyleDeclaration declaration) ; 62 typedef String StringGetter(Symbol propertySymbol, StyleDeclaration declaration) ;
73 typedef Property ObjectConstructor(Symbol propertySymbol, StyleDeclaration decla ration); 63 typedef Property ObjectConstructor(Symbol propertySymbol, StyleDeclaration decla ration);
74 64
75 class PropertyTable { 65 class PropertyTable {
76 const PropertyTable({this.symbol, this.inherited, this.stringGetter, this.stri ngSetter, this.objectConstructor}); 66 const PropertyTable({this.symbol, this.inherited, this.stringGetter, this.stri ngSetter, this.objectConstructor});
77 final Symbol symbol; 67 final Symbol symbol;
78 final bool inherited; 68 final bool inherited;
79 final StringSetter stringSetter; 69 final StringSetter stringSetter;
80 final StringGetter stringGetter; 70 final StringGetter stringGetter;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 102 }
113 103
114 operator []=(String propertyName, String newValue) { 104 operator []=(String propertyName, String newValue) {
115 var propertySymbol = new Symbol(propertyName); 105 var propertySymbol = new Symbol(propertyName);
116 if (_registeredProperties.containsKey(propertySymbol)) 106 if (_registeredProperties.containsKey(propertySymbol))
117 return _registeredProperties[propertySymbol].stringSetter(propertySymbol, this, newValue); 107 return _registeredProperties[propertySymbol].stringSetter(propertySymbol, this, newValue);
118 throw new ArgumentError(propertyName); 108 throw new ArgumentError(propertyName);
119 } 109 }
120 110
121 // some properties expose dedicated APIs so you don't have to use string manip ulation 111 // some properties expose dedicated APIs so you don't have to use string manip ulation
122 WeakMap<Symbol, Property> _properties = new WeakMap<Symbol, Property>(); 112 MapOfWeakReferences<Symbol, Property> _properties = new MapOfWeakReferences<Sy mbol, Property>();
123 noSuchMethod(Invocation invocation) { 113 noSuchMethod(Invocation invocation) {
124 Symbol propertySymbol; 114 Symbol propertySymbol;
125 if (invocation.isSetter) { 115 if (invocation.isSetter) {
126 // when it's a setter, the name will be "foo=" rather than "foo" 116 // when it's a setter, the name will be "foo=" rather than "foo"
127 String propertyName = MirrorSystem.getName(invocation.memberName); 117 String propertyName = MirrorSystem.getName(invocation.memberName);
128 assert(propertyName[propertyName.length-1] == '='); 118 assert(propertyName[propertyName.length-1] == '=');
129 propertySymbol = new Symbol(propertyName.substring(0, propertyName.length- 1)); 119 propertySymbol = new Symbol(propertyName.substring(0, propertyName.length- 1));
130 } else { 120 } else {
131 propertySymbol = invocation.memberName; 121 propertySymbol = invocation.memberName;
132 } 122 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 throw new ArgumentError(value); 161 throw new ArgumentError(value);
172 } 162 }
173 163
174 bool get inherit => _isInherit(); 164 bool get inherit => _isInherit();
175 void set inherit (value) { 165 void set inherit (value) {
176 if (value == true) 166 if (value == true)
177 return _setInherit(); 167 return _setInherit();
178 throw new ArgumentError(value); 168 throw new ArgumentError(value);
179 } 169 }
180 170
181 void setter(dynamic value) { 171 void setter(dynamic newValue) {
182 if (value == initial) 172 switch (newValue) {
183 return _setInitial(); 173 case initial:
184 if (value == inherit) 174 _setInitial();
185 return _setInitial(); 175 case inherit:
186 if (value == null) 176 _setInherit();
187 return _unset(); 177 case null:
188 throw new ArgumentError(value); 178 _unset();
179 default:
180 throw new ArgumentError(value);
181 }
189 } 182 }
190 183
191 external bool _isInitial(); 184 external bool _isInitial();
192 external void _setInitial(); 185 external void _setInitial();
193 external bool _isInherit(); 186 external bool _isInherit();
194 external void _setInherit(); 187 external void _setInherit();
195 external void _unset(); 188 external void _unset();
196 } 189 }
197 ``` 190 ```
198 191
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 registerProperty(new PropertyTable( 339 registerProperty(new PropertyTable(
347 symbol: #transform, 340 symbol: #transform,
348 inherited: false, 341 inherited: false,
349 stringSetter: transformPropertyStringSetter, 342 stringSetter: transformPropertyStringSetter,
350 stringGetter: transformPropertyStringGetter, 343 stringGetter: transformPropertyStringGetter,
351 objectConstructor: (Symbol propertySymbol, StyleDeclaration declaration) => 344 objectConstructor: (Symbol propertySymbol, StyleDeclaration declaration) =>
352 new TransformProperty(propertySymbol, declaration))); 345 new TransformProperty(propertySymbol, declaration)));
353 } 346 }
354 ``` 347 ```
355 348
OLDNEW
« no previous file with comments | « sky/specs/runloop.md ('k') | sky/specs/utils.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698