| OLD | NEW |
| 1 library layout; | 1 library layout; |
| 2 | 2 |
| 3 import 'node.dart'; | 3 import 'node.dart'; |
| 4 import 'dart:sky' as sky; | 4 import 'dart:sky' as sky; |
| 5 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 // UTILS | 7 // UTILS |
| 8 | 8 |
| 9 // Bridge to legacy CSS-like style specification | 9 // Bridge to legacy CSS-like style specification |
| 10 // Eventually we'll replace this with something else | 10 // Eventually we'll replace this with something else |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 | 48 |
| 49 // ABSTRACT LAYOUT | 49 // ABSTRACT LAYOUT |
| 50 | 50 |
| 51 class ParentData { | 51 class ParentData { |
| 52 void detach() { | 52 void detach() { |
| 53 detachSiblings(); | 53 detachSiblings(); |
| 54 } | 54 } |
| 55 void detachSiblings() { } // workaround for lack of inter-class mixins in Dart | 55 void detachSiblings() { } // workaround for lack of inter-class mixins in Dart |
| 56 void merge(ParentData other) { |
| 57 // override this in subclasses to merge in data from other into this |
| 58 assert(other.runtimeType == this.runtimeType); |
| 59 } |
| 56 } | 60 } |
| 57 | 61 |
| 58 abstract class RenderNode extends Node { | 62 abstract class RenderNode extends Node { |
| 59 | 63 |
| 60 // LAYOUT | 64 // LAYOUT |
| 61 | 65 |
| 62 // parentData is only for use by the RenderNode that actually lays this | 66 // parentData is only for use by the RenderNode that actually lays this |
| 63 // node out, and any other nodes who happen to know exactly what | 67 // node out, and any other nodes who happen to know exactly what |
| 64 // kind of node that is. | 68 // kind of node that is. |
| 65 ParentData parentData; | 69 ParentData parentData; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 sky.Element createSkyElement(); | 258 sky.Element createSkyElement(); |
| 255 | 259 |
| 256 void updateStyles(List<Style> styles) { | 260 void updateStyles(List<Style> styles) { |
| 257 _skyElement.setAttribute('class', stylesToClasses(styles)); | 261 _skyElement.setAttribute('class', stylesToClasses(styles)); |
| 258 } | 262 } |
| 259 | 263 |
| 260 String stylesToClasses(List<Style> styles) { | 264 String stylesToClasses(List<Style> styles) { |
| 261 return styles.map((s) => s._className).join(' '); | 265 return styles.map((s) => s._className).join(' '); |
| 262 } | 266 } |
| 263 | 267 |
| 268 String _inlineStyles = ''; |
| 269 String _additionalStylesFromParent = ''; // used internally to propagate paren
tData settings to the child |
| 270 |
| 264 void updateInlineStyle(String newStyle) { | 271 void updateInlineStyle(String newStyle) { |
| 265 _skyElement.setAttribute('style', newStyle); | 272 _inlineStyles = newStyle; |
| 273 _updateInlineStyleAttribute(); |
| 274 } |
| 275 |
| 276 void _updateInlineStyleAttribute() { |
| 277 _skyElement.setAttribute('style', "$_inlineStyles;$_additionalStylesFromPare
nt"); |
| 266 } | 278 } |
| 267 | 279 |
| 268 double get width { | 280 double get width { |
| 269 sky.ClientRect rect = _skyElement.getBoundingClientRect(); | 281 sky.ClientRect rect = _skyElement.getBoundingClientRect(); |
| 270 return rect.width; | 282 return rect.width; |
| 271 } | 283 } |
| 272 | 284 |
| 273 double get height { | 285 double get height { |
| 274 sky.ClientRect rect = _skyElement.getBoundingClientRect(); | 286 sky.ClientRect rect = _skyElement.getBoundingClientRect(); |
| 275 return rect.height; | 287 return rect.height; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 _skyElement.appendChild(child._skyElement); | 325 _skyElement.appendChild(child._skyElement); |
| 314 } | 326 } |
| 315 } | 327 } |
| 316 void remove(RenderCSS child) { | 328 void remove(RenderCSS child) { |
| 317 child._skyElement.remove(); | 329 child._skyElement.remove(); |
| 318 super.remove(child); | 330 super.remove(child); |
| 319 } | 331 } |
| 320 | 332 |
| 321 } | 333 } |
| 322 | 334 |
| 323 class FlexBoxParentData extends CSSParentData { } | 335 class FlexBoxParentData extends CSSParentData { |
| 336 int flex; |
| 337 void merge(FlexBoxParentData other) { |
| 338 if (other.flex != null) |
| 339 flex = other.flex; |
| 340 super.merge(other); |
| 341 } |
| 342 } |
| 324 | 343 |
| 325 enum FlexDirection { Row } | 344 enum FlexDirection { Row } |
| 326 | 345 |
| 327 class RenderCSSFlex extends RenderCSSContainer { | 346 class RenderCSSFlex extends RenderCSSContainer { |
| 328 | 347 |
| 329 RenderCSSFlex(debug, FlexDirection direction) : _direction = direction, super(
debug); | 348 RenderCSSFlex(debug, FlexDirection direction) : _direction = direction, super(
debug); |
| 330 | 349 |
| 331 FlexDirection _direction; | 350 FlexDirection _direction; |
| 332 FlexDirection get direction => _direction; | 351 FlexDirection get direction => _direction; |
| 333 void set direction (FlexDirection value) { | 352 void set direction (FlexDirection value) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 344 static final Style _displayFlexRow = new Style('flex-direction:row'); | 363 static final Style _displayFlexRow = new Style('flex-direction:row'); |
| 345 | 364 |
| 346 String stylesToClasses(List<Style> styles) { | 365 String stylesToClasses(List<Style> styles) { |
| 347 var settings = _displayFlex._className; | 366 var settings = _displayFlex._className; |
| 348 switch (_direction) { | 367 switch (_direction) { |
| 349 case FlexDirection.Row: settings += ' ' + _displayFlexRow._className; | 368 case FlexDirection.Row: settings += ' ' + _displayFlexRow._className; |
| 350 } | 369 } |
| 351 return super.stylesToClasses(styles) + ' ' + settings; | 370 return super.stylesToClasses(styles) + ' ' + settings; |
| 352 } | 371 } |
| 353 | 372 |
| 373 void markNeedsLayout() { |
| 374 super.markNeedsLayout(); |
| 375 |
| 376 // pretend we did the layout: |
| 377 RenderCSS child = _firstChild; |
| 378 while (child != null) { |
| 379 assert(child.parentData is FlexBoxParentData); |
| 380 if (child.parentData.flex != null) { |
| 381 child._additionalStylesFromParent = 'flex:${child.parentData.flex};'; |
| 382 child._updateInlineStyleAttribute(); |
| 383 } |
| 384 child = child.parentData.nextSibling; |
| 385 } |
| 386 } |
| 387 |
| 354 } | 388 } |
| 355 | 389 |
| 356 class RenderCSSText extends RenderCSS { | 390 class RenderCSSText extends RenderCSS { |
| 357 | 391 |
| 358 RenderCSSText(debug, String newData) : super(debug) { | 392 RenderCSSText(debug, String newData) : super(debug) { |
| 359 data = newData; | 393 data = newData; |
| 360 } | 394 } |
| 361 | 395 |
| 362 static final Style _displayParagraph = new Style('display:paragraph'); | 396 static final Style _displayParagraph = new Style('display:paragraph'); |
| 363 | 397 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 print(prefix + node.toString() + _attributes(node)); | 468 print(prefix + node.toString() + _attributes(node)); |
| 435 var children = node.getChildNodes(); | 469 var children = node.getChildNodes(); |
| 436 prefix = prefix + ' '; | 470 prefix = prefix + ' '; |
| 437 for (var child in children) | 471 for (var child in children) |
| 438 _serialiseDOM(child, prefix); | 472 _serialiseDOM(child, prefix); |
| 439 } | 473 } |
| 440 | 474 |
| 441 void dumpState() { | 475 void dumpState() { |
| 442 _serialiseDOM(sky.document); | 476 _serialiseDOM(sky.document); |
| 443 } | 477 } |
| OLD | NEW |