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

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

Issue 1132983007: [Layout] Put in some guards to prevent us from reintroducing 'display' properties into the CSS. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: git cl status 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/components/menu_item.dart ('k') | 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 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
11 class Style { 11 class Style {
12 final String _className; 12 final String _className;
13 static final Map<String, Style> _cache = new HashMap<String, Style>(); 13 static final Map<String, Style> _cache = new HashMap<String, Style>();
14 14
15 static int _nextStyleId = 1; 15 static int _nextStyleId = 1;
16 16
17 static String _getNextClassName() { return "style${_nextStyleId++}"; } 17 static String _getNextClassName() { return "style${_nextStyleId++}"; }
18 18
19 Style extend(Style other) { 19 Style extend(Style other) {
20 var className = "$_className ${other._className}"; 20 var className = "$_className ${other._className}";
21 21
22 return _cache.putIfAbsent(className, () { 22 return _cache.putIfAbsent(className, () {
23 return new Style._internal(className); 23 return new Style._construct(className);
24 }); 24 });
25 } 25 }
26 26
27 factory Style(String styles) { 27 factory Style(String styles) {
28 assert(!styles.contains(new RegExp('\\b(display|flex|flex-direction)\\b')));
29 return new Style._addToCache(styles);
30 }
31
32 factory Style._addToCache(String styles) {
28 return _cache.putIfAbsent(styles, () { 33 return _cache.putIfAbsent(styles, () {
29 var className = _getNextClassName(); 34 var className = _getNextClassName();
30 sky.Element styleNode = sky.document.createElement('style'); 35 sky.Element styleNode = sky.document.createElement('style');
31 styleNode.setChild(new sky.Text(".$className { $styles }")); 36 styleNode.setChild(new sky.Text(".$className { $styles }"));
32 sky.document.appendChild(styleNode); 37 sky.document.appendChild(styleNode);
33 return new Style._internal(className); 38 return new Style._construct(className);
34 }); 39 });
35 } 40 }
36 41
37 Style._internal(this._className); 42 Style._construct(this._className);
38 } 43 }
39 44
40 class Rect { 45 class Rect {
41 const Rect(this.x, this.y, this.width, this.height); 46 const Rect(this.x, this.y, this.width, this.height);
42 final double x; 47 final double x;
43 final double y; 48 final double y;
44 final double width; 49 final double width;
45 final double height; 50 final double height;
46 } 51 }
47 52
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 267 }
263 268
264 String stylesToClasses(List<Style> styles) { 269 String stylesToClasses(List<Style> styles) {
265 return styles.map((s) => s._className).join(' '); 270 return styles.map((s) => s._className).join(' ');
266 } 271 }
267 272
268 String _inlineStyles = ''; 273 String _inlineStyles = '';
269 String _additionalStylesFromParent = ''; // used internally to propagate paren tData settings to the child 274 String _additionalStylesFromParent = ''; // used internally to propagate paren tData settings to the child
270 275
271 void updateInlineStyle(String newStyle) { 276 void updateInlineStyle(String newStyle) {
277 assert(newStyle == null || !newStyle.contains(new RegExp('\\b(display|flex|f lex-direction)\\b')));
272 _inlineStyles = newStyle != null ? newStyle : ''; 278 _inlineStyles = newStyle != null ? newStyle : '';
273 _updateInlineStyleAttribute(); 279 _updateInlineStyleAttribute();
274 } 280 }
275 281
276 void _updateInlineStyleAttribute() { 282 void _updateInlineStyleAttribute() {
277 if ((_inlineStyles != '') && (_additionalStylesFromParent != '')) 283 if ((_inlineStyles != '') && (_additionalStylesFromParent != ''))
278 _skyElement.setAttribute('style', "$_inlineStyles;$_additionalStylesFromPa rent"); 284 _skyElement.setAttribute('style', "$_inlineStyles;$_additionalStylesFromPa rent");
279 else 285 else
280 _skyElement.setAttribute('style', "$_inlineStyles$_additionalStylesFromPar ent"); 286 _skyElement.setAttribute('style', "$_inlineStyles$_additionalStylesFromPar ent");
281 } 287 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 void set direction (FlexDirection value) { 361 void set direction (FlexDirection value) {
356 _direction = value; 362 _direction = value;
357 markNeedsLayout(); 363 markNeedsLayout();
358 } 364 }
359 365
360 void setupPos(RenderNode child) { 366 void setupPos(RenderNode child) {
361 if (child.parentData is! FlexBoxParentData) 367 if (child.parentData is! FlexBoxParentData)
362 child.parentData = new FlexBoxParentData(); 368 child.parentData = new FlexBoxParentData();
363 } 369 }
364 370
365 static final Style _displayFlex = new Style('display:flex'); 371 static final Style _displayFlex = new Style._addToCache('display:flex');
366 static final Style _displayFlexRow = new Style('flex-direction:row'); 372 static final Style _displayFlexRow = new Style._addToCache('flex-direction:row ');
367 static final Style _displayFlexColumn = new Style('flex-direction:column'); 373 static final Style _displayFlexColumn = new Style._addToCache('flex-direction: column');
368 374
369 String stylesToClasses(List<Style> styles) { 375 String stylesToClasses(List<Style> styles) {
370 var settings = _displayFlex._className; 376 var settings = _displayFlex._className;
371 switch (_direction) { 377 switch (_direction) {
372 case FlexDirection.Row: settings += ' ' + _displayFlexRow._className; brea k; 378 case FlexDirection.Row: settings += ' ' + _displayFlexRow._className; brea k;
373 case FlexDirection.Column: settings += ' ' + _displayFlexColumn._className ; break; 379 case FlexDirection.Column: settings += ' ' + _displayFlexColumn._className ; break;
374 } 380 }
375 return super.stylesToClasses(styles) + ' ' + settings; 381 return super.stylesToClasses(styles) + ' ' + settings;
376 } 382 }
377 383
(...skipping 11 matching lines...) Expand all
389 child = child.parentData.nextSibling; 395 child = child.parentData.nextSibling;
390 } 396 }
391 } 397 }
392 398
393 } 399 }
394 400
395 class RenderCSSParagraph extends RenderCSSContainer { 401 class RenderCSSParagraph extends RenderCSSContainer {
396 402
397 RenderCSSParagraph(debug) : super(debug); 403 RenderCSSParagraph(debug) : super(debug);
398 404
399 static final Style _displayParagraph = new Style('display:paragraph'); 405 static final Style _displayParagraph = new Style._addToCache('display:paragrap h');
400 406
401 String stylesToClasses(List<Style> styles) { 407 String stylesToClasses(List<Style> styles) {
402 return super.stylesToClasses(styles) + ' ' + _displayParagraph._className; 408 return super.stylesToClasses(styles) + ' ' + _displayParagraph._className;
403 } 409 }
404 410
405 } 411 }
406 412
407 class RenderCSSInline extends RenderCSS { 413 class RenderCSSInline extends RenderCSS {
408 414
409 RenderCSSInline(debug, String newData) : super(debug) { 415 RenderCSSInline(debug, String newData) : super(debug) {
410 data = newData; 416 data = newData;
411 } 417 }
412 418
413 static final Style _displayInline = new Style('display:inline'); 419 static final Style _displayInline = new Style._addToCache('display:inline');
414 420
415 String stylesToClasses(List<Style> styles) { 421 String stylesToClasses(List<Style> styles) {
416 return super.stylesToClasses(styles) + ' ' + _displayInline._className; 422 return super.stylesToClasses(styles) + ' ' + _displayInline._className;
417 } 423 }
418 424
419 sky.Element createSkyElement() { 425 sky.Element createSkyElement() {
420 return sky.document.createElement('div') 426 return sky.document.createElement('div')
421 ..setChild(new sky.Text()) 427 ..setChild(new sky.Text())
422 ..setAttribute('debug', debug.toString()); 428 ..setAttribute('debug', debug.toString());
423 } 429 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 print(prefix + node.toString() + _attributes(node)); 494 print(prefix + node.toString() + _attributes(node));
489 var children = node.getChildNodes(); 495 var children = node.getChildNodes();
490 prefix = prefix + ' '; 496 prefix = prefix + ' ';
491 for (var child in children) 497 for (var child in children)
492 _serialiseDOM(child, prefix); 498 _serialiseDOM(child, prefix);
493 } 499 }
494 500
495 void dumpState() { 501 void dumpState() {
496 _serialiseDOM(sky.document); 502 _serialiseDOM(sky.document);
497 } 503 }
OLDNEW
« no previous file with comments | « sky/framework/components/menu_item.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698