Chromium Code Reviews| 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 if (newStyle == null) |
|
eseidel
2015/05/12 17:31:59
dart doesn't have a fancy pattern for this?
_inli
| |
| 273 _inlineStyles = ''; | |
| 274 else | |
| 275 _inlineStyles = newStyle; | |
| 276 _updateInlineStyleAttribute(); | |
| 277 } | |
| 278 | |
| 279 void _updateInlineStyleAttribute() { | |
| 280 if ((_inlineStyles != '') && (_additionalStylesFromParent != '')) | |
|
eseidel
2015/05/12 17:31:59
style = [inlineStyles, additionalStylesFromParent]
| |
| 281 _skyElement.setAttribute('style', "$_inlineStyles;$_additionalStylesFromPa rent"); | |
| 282 else | |
| 283 _skyElement.setAttribute('style', "$_inlineStyles$_additionalStylesFromPar ent"); | |
| 266 } | 284 } |
| 267 | 285 |
| 268 double get width { | 286 double get width { |
| 269 sky.ClientRect rect = _skyElement.getBoundingClientRect(); | 287 sky.ClientRect rect = _skyElement.getBoundingClientRect(); |
| 270 return rect.width; | 288 return rect.width; |
| 271 } | 289 } |
| 272 | 290 |
| 273 double get height { | 291 double get height { |
| 274 sky.ClientRect rect = _skyElement.getBoundingClientRect(); | 292 sky.ClientRect rect = _skyElement.getBoundingClientRect(); |
| 275 return rect.height; | 293 return rect.height; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 _skyElement.appendChild(child._skyElement); | 331 _skyElement.appendChild(child._skyElement); |
| 314 } | 332 } |
| 315 } | 333 } |
| 316 void remove(RenderCSS child) { | 334 void remove(RenderCSS child) { |
| 317 child._skyElement.remove(); | 335 child._skyElement.remove(); |
| 318 super.remove(child); | 336 super.remove(child); |
| 319 } | 337 } |
| 320 | 338 |
| 321 } | 339 } |
| 322 | 340 |
| 323 class FlexBoxParentData extends CSSParentData { } | 341 class FlexBoxParentData extends CSSParentData { |
| 342 int flex; | |
| 343 void merge(FlexBoxParentData other) { | |
| 344 if (other.flex != null) | |
| 345 flex = other.flex; | |
| 346 super.merge(other); | |
| 347 } | |
| 348 } | |
| 324 | 349 |
| 325 enum FlexDirection { Row } | 350 enum FlexDirection { Row } |
| 326 | 351 |
| 327 class RenderCSSFlex extends RenderCSSContainer { | 352 class RenderCSSFlex extends RenderCSSContainer { |
| 328 | 353 |
| 329 RenderCSSFlex(debug, FlexDirection direction) : _direction = direction, super( debug); | 354 RenderCSSFlex(debug, FlexDirection direction) : _direction = direction, super( debug); |
| 330 | 355 |
| 331 FlexDirection _direction; | 356 FlexDirection _direction; |
| 332 FlexDirection get direction => _direction; | 357 FlexDirection get direction => _direction; |
| 333 void set direction (FlexDirection value) { | 358 void set direction (FlexDirection value) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 344 static final Style _displayFlexRow = new Style('flex-direction:row'); | 369 static final Style _displayFlexRow = new Style('flex-direction:row'); |
| 345 | 370 |
| 346 String stylesToClasses(List<Style> styles) { | 371 String stylesToClasses(List<Style> styles) { |
| 347 var settings = _displayFlex._className; | 372 var settings = _displayFlex._className; |
| 348 switch (_direction) { | 373 switch (_direction) { |
| 349 case FlexDirection.Row: settings += ' ' + _displayFlexRow._className; | 374 case FlexDirection.Row: settings += ' ' + _displayFlexRow._className; |
| 350 } | 375 } |
| 351 return super.stylesToClasses(styles) + ' ' + settings; | 376 return super.stylesToClasses(styles) + ' ' + settings; |
| 352 } | 377 } |
| 353 | 378 |
| 379 void markNeedsLayout() { | |
| 380 super.markNeedsLayout(); | |
| 381 | |
| 382 // pretend we did the layout: | |
| 383 RenderCSS child = _firstChild; | |
| 384 while (child != null) { | |
| 385 assert(child.parentData is FlexBoxParentData); | |
| 386 if (child.parentData.flex != null) { | |
| 387 child._additionalStylesFromParent = 'flex:${child.parentData.flex};'; | |
| 388 child._updateInlineStyleAttribute(); | |
| 389 } | |
| 390 child = child.parentData.nextSibling; | |
| 391 } | |
| 392 } | |
| 393 | |
| 354 } | 394 } |
| 355 | 395 |
| 356 class RenderCSSText extends RenderCSS { | 396 class RenderCSSText extends RenderCSS { |
| 357 | 397 |
| 358 RenderCSSText(debug, String newData) : super(debug) { | 398 RenderCSSText(debug, String newData) : super(debug) { |
| 359 data = newData; | 399 data = newData; |
| 360 } | 400 } |
| 361 | 401 |
| 362 static final Style _displayParagraph = new Style('display:paragraph'); | 402 static final Style _displayParagraph = new Style('display:paragraph'); |
| 363 | 403 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 print(prefix + node.toString() + _attributes(node)); | 474 print(prefix + node.toString() + _attributes(node)); |
| 435 var children = node.getChildNodes(); | 475 var children = node.getChildNodes(); |
| 436 prefix = prefix + ' '; | 476 prefix = prefix + ' '; |
| 437 for (var child in children) | 477 for (var child in children) |
| 438 _serialiseDOM(child, prefix); | 478 _serialiseDOM(child, prefix); |
| 439 } | 479 } |
| 440 | 480 |
| 441 void dumpState() { | 481 void dumpState() { |
| 442 _serialiseDOM(sky.document); | 482 _serialiseDOM(sky.document); |
| 443 } | 483 } |
| OLD | NEW |