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

Side by Side Diff: sky/framework/layout.dart

Issue 1122413006: [Effen] Move 'flex' out of CSS also. (mark II) (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: git cl description Created 5 years, 7 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/framework/fn.dart ('k') | sky/tests/framework/basic.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 != null ? newStyle : '';
273 _updateInlineStyleAttribute();
274 }
275
276 void _updateInlineStyleAttribute() {
277 if ((_inlineStyles != '') && (_additionalStylesFromParent != ''))
278 _skyElement.setAttribute('style', "$_inlineStyles;$_additionalStylesFromPa rent");
279 else
280 _skyElement.setAttribute('style', "$_inlineStyles$_additionalStylesFromPar ent");
266 } 281 }
267 282
268 double get width { 283 double get width {
269 sky.ClientRect rect = _skyElement.getBoundingClientRect(); 284 sky.ClientRect rect = _skyElement.getBoundingClientRect();
270 return rect.width; 285 return rect.width;
271 } 286 }
272 287
273 double get height { 288 double get height {
274 sky.ClientRect rect = _skyElement.getBoundingClientRect(); 289 sky.ClientRect rect = _skyElement.getBoundingClientRect();
275 return rect.height; 290 return rect.height;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 _skyElement.appendChild(child._skyElement); 328 _skyElement.appendChild(child._skyElement);
314 } 329 }
315 } 330 }
316 void remove(RenderCSS child) { 331 void remove(RenderCSS child) {
317 child._skyElement.remove(); 332 child._skyElement.remove();
318 super.remove(child); 333 super.remove(child);
319 } 334 }
320 335
321 } 336 }
322 337
323 class FlexBoxParentData extends CSSParentData { } 338 class FlexBoxParentData extends CSSParentData {
339 int flex;
340 void merge(FlexBoxParentData other) {
341 if (other.flex != null)
342 flex = other.flex;
343 super.merge(other);
344 }
345 }
324 346
325 enum FlexDirection { Row } 347 enum FlexDirection { Row }
326 348
327 class RenderCSSFlex extends RenderCSSContainer { 349 class RenderCSSFlex extends RenderCSSContainer {
328 350
329 RenderCSSFlex(debug, FlexDirection direction) : _direction = direction, super( debug); 351 RenderCSSFlex(debug, FlexDirection direction) : _direction = direction, super( debug);
330 352
331 FlexDirection _direction; 353 FlexDirection _direction;
332 FlexDirection get direction => _direction; 354 FlexDirection get direction => _direction;
333 void set direction (FlexDirection value) { 355 void set direction (FlexDirection value) {
(...skipping 10 matching lines...) Expand all
344 static final Style _displayFlexRow = new Style('flex-direction:row'); 366 static final Style _displayFlexRow = new Style('flex-direction:row');
345 367
346 String stylesToClasses(List<Style> styles) { 368 String stylesToClasses(List<Style> styles) {
347 var settings = _displayFlex._className; 369 var settings = _displayFlex._className;
348 switch (_direction) { 370 switch (_direction) {
349 case FlexDirection.Row: settings += ' ' + _displayFlexRow._className; 371 case FlexDirection.Row: settings += ' ' + _displayFlexRow._className;
350 } 372 }
351 return super.stylesToClasses(styles) + ' ' + settings; 373 return super.stylesToClasses(styles) + ' ' + settings;
352 } 374 }
353 375
376 void markNeedsLayout() {
377 super.markNeedsLayout();
378
379 // pretend we did the layout:
380 RenderCSS child = _firstChild;
381 while (child != null) {
382 assert(child.parentData is FlexBoxParentData);
383 if (child.parentData.flex != null) {
384 child._additionalStylesFromParent = 'flex:${child.parentData.flex};';
385 child._updateInlineStyleAttribute();
386 }
387 child = child.parentData.nextSibling;
388 }
389 }
390
354 } 391 }
355 392
356 class RenderCSSText extends RenderCSS { 393 class RenderCSSText extends RenderCSS {
357 394
358 RenderCSSText(debug, String newData) : super(debug) { 395 RenderCSSText(debug, String newData) : super(debug) {
359 data = newData; 396 data = newData;
360 } 397 }
361 398
362 static final Style _displayParagraph = new Style('display:paragraph'); 399 static final Style _displayParagraph = new Style('display:paragraph');
363 400
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 print(prefix + node.toString() + _attributes(node)); 471 print(prefix + node.toString() + _attributes(node));
435 var children = node.getChildNodes(); 472 var children = node.getChildNodes();
436 prefix = prefix + ' '; 473 prefix = prefix + ' ';
437 for (var child in children) 474 for (var child in children)
438 _serialiseDOM(child, prefix); 475 _serialiseDOM(child, prefix);
439 } 476 }
440 477
441 void dumpState() { 478 void dumpState() {
442 _serialiseDOM(sky.document); 479 _serialiseDOM(sky.document);
443 } 480 }
OLDNEW
« no previous file with comments | « sky/framework/fn.dart ('k') | sky/tests/framework/basic.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698