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

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

Issue 1006053002: Allow Effen Styles to be extendable (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: sdfsd 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/framework/editing/editable_text.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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 library fn; 5 library fn;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:sky' as sky; 9 import 'dart:sky' as sky;
10 import 'reflect.dart' as reflect; 10 import 'reflect.dart' as reflect;
(...skipping 28 matching lines...) Expand all
39 39
40 void addAll(EventMap events) { 40 void addAll(EventMap events) {
41 _handlers.addAll(events._handlers); 41 _handlers.addAll(events._handlers);
42 } 42 }
43 } 43 }
44 44
45 class Style { 45 class Style {
46 final String _className; 46 final String _className;
47 static final Map<String, Style> _cache = new HashMap<String, Style>(); 47 static final Map<String, Style> _cache = new HashMap<String, Style>();
48 48
49 static int nextStyleId = 1; 49 static int _nextStyleId = 1;
50 50
51 static String nextClassName(String styles) { 51 static String _getNextClassName() { return "style${_nextStyleId++}"; }
52 assert(sky.document != null);
53 String className = "style$nextStyleId";
54 nextStyleId++;
55 52
56 sky.Element styleNode = sky.document.createElement('style'); 53 Style extend(Style other) {
57 styleNode.setChild(new sky.Text(".$className { $styles }")); 54 var className = "$_className ${other._className}";
58 sky.document.appendChild(styleNode);
59 55
60 return className; 56 return _cache.putIfAbsent(className, () {
57 return new Style._internal(className);
58 });
61 } 59 }
62 60
63 factory Style(String styles) { 61 factory Style(String styles) {
64 return _cache.putIfAbsent(styles, () { 62 return _cache.putIfAbsent(styles, () {
65 return new Style._internal(nextClassName(styles)); 63 var className = _getNextClassName();
64 sky.Element styleNode = sky.document.createElement('style');
65 styleNode.setChild(new sky.Text(".$className { $styles }"));
66 sky.document.appendChild(styleNode);
67 return new Style._internal(className);
66 }); 68 });
67 } 69 }
68 70
69 Style._internal(this._className); 71 Style._internal(this._className);
70 } 72 }
71 73
72 void _parentInsertBefore(sky.ParentNode parent, 74 void _parentInsertBefore(sky.ParentNode parent,
73 sky.Node node, 75 sky.Node node,
74 sky.Node ref) { 76 sky.Node ref) {
75 if (ref != null) { 77 if (ref != null) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 Element get _emptyElement; 135 Element get _emptyElement;
134 136
135 String inlineStyle; 137 String inlineStyle;
136 138
137 List<Node> _children = null; 139 List<Node> _children = null;
138 String _class = ''; 140 String _class = '';
139 141
140 Element({ 142 Element({
141 Object key, 143 Object key,
142 List<Node> children, 144 List<Node> children,
143 List<Style> styles, 145 Style style,
144 146
145 this.inlineStyle 147 this.inlineStyle
146 }) : super(key:key) { 148 }) : super(key:key) {
147 _class = styles == null ? '' : styles.map((s) => s._className).join(' '); 149 _class = style == null ? '' : style._className;
148 _children = children == null ? _emptyList : children; 150 _children = children == null ? _emptyList : children;
149 151
150 if (_isInCheckedMode) { 152 if (_isInCheckedMode) {
151 _debugReportDuplicateIds(); 153 _debugReportDuplicateIds();
152 } 154 }
153 } 155 }
154 156
155 void _remove() { 157 void _remove() {
156 super._remove(); 158 super._remove();
157 if (_children != null) { 159 if (_children != null) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 class Container extends Element { 407 class Container extends Element {
406 408
407 String get _tagName => 'div'; 409 String get _tagName => 'div';
408 410
409 static final Container _emptyContainer = new Container(); 411 static final Container _emptyContainer = new Container();
410 Element get _emptyElement => _emptyContainer; 412 Element get _emptyElement => _emptyContainer;
411 413
412 Container({ 414 Container({
413 Object key, 415 Object key,
414 List<Node> children, 416 List<Node> children,
415 List<Style> styles, 417 Style style,
416 String inlineStyle 418 String inlineStyle
417 }) : super( 419 }) : super(
418 key: key, 420 key: key,
419 children: children, 421 children: children,
420 styles: styles, 422 style: style,
421 inlineStyle: inlineStyle 423 inlineStyle: inlineStyle
422 ); 424 );
423 } 425 }
424 426
425 class Image extends Element { 427 class Image extends Element {
426 428
427 String get _tagName => 'img'; 429 String get _tagName => 'img';
428 430
429 static final Image _emptyImage = new Image(); 431 static final Image _emptyImage = new Image();
430 Element get _emptyElement => _emptyImage; 432 Element get _emptyElement => _emptyImage;
431 433
432 String src; 434 String src;
433 int width; 435 int width;
434 int height; 436 int height;
435 437
436 Image({ 438 Image({
437 Object key, 439 Object key,
438 List<Node> children, 440 List<Node> children,
439 List<Style> styles, 441 Style style,
440 String inlineStyle, 442 String inlineStyle,
441 this.width, 443 this.width,
442 this.height, 444 this.height,
443 this.src 445 this.src
444 }) : super( 446 }) : super(
445 key: key, 447 key: key,
446 children: children, 448 children: children,
447 styles: styles, 449 style: style,
448 inlineStyle: inlineStyle 450 inlineStyle: inlineStyle
449 ); 451 );
450 452
451 void _syncNode([Element old]) { 453 void _syncNode([Element old]) {
452 super._syncNode(old); 454 super._syncNode(old);
453 455
454 Image oldImage = old != null ? old : _emptyImage; 456 Image oldImage = old != null ? old : _emptyImage;
455 sky.HTMLImageElement skyImage = _root as sky.HTMLImageElement; 457 sky.HTMLImageElement skyImage = _root as sky.HTMLImageElement;
456 if (src != oldImage.src) { 458 if (src != oldImage.src) {
457 skyImage.src = src; 459 skyImage.src = src;
(...skipping 15 matching lines...) Expand all
473 static final Anchor _emptyAnchor = new Anchor(); 475 static final Anchor _emptyAnchor = new Anchor();
474 Element get _emptyElement => _emptyAnchor; 476 Element get _emptyElement => _emptyAnchor;
475 477
476 String href; 478 String href;
477 int width; 479 int width;
478 int height; 480 int height;
479 481
480 Anchor({ 482 Anchor({
481 Object key, 483 Object key,
482 List<Node> children, 484 List<Node> children,
483 List<Style> styles, 485 Style style,
484 String inlineStyle, 486 String inlineStyle,
485 this.width, 487 this.width,
486 this.height, 488 this.height,
487 this.href 489 this.href
488 }) : super( 490 }) : super(
489 key: key, 491 key: key,
490 children: children, 492 children: children,
491 styles: styles, 493 style: style,
492 inlineStyle: inlineStyle 494 inlineStyle: inlineStyle
493 ); 495 );
494 496
495 void _syncNode([Element old]) { 497 void _syncNode([Element old]) {
496 Anchor oldAnchor = old != null ? old as Anchor : _emptyAnchor; 498 Anchor oldAnchor = old != null ? old as Anchor : _emptyAnchor;
497 super._syncNode(oldAnchor); 499 super._syncNode(oldAnchor);
498 500
499 sky.HTMLAnchorElement skyAnchor = _root as sky.HTMLAnchorElement; 501 sky.HTMLAnchorElement skyAnchor = _root as sky.HTMLAnchorElement;
500 if (href != oldAnchor.href) { 502 if (href != oldAnchor.href) {
501 skyAnchor.href = href; 503 skyAnchor.href = href;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 680
679 _sync(null, _host, null); 681 _sync(null, _host, null);
680 assert(_root is sky.Node); 682 assert(_root is sky.Node);
681 683
682 sw.stop(); 684 sw.stop();
683 if (_shouldLogRenderDuration) 685 if (_shouldLogRenderDuration)
684 print("Initial build: ${sw.elapsedMicroseconds} microseconds"); 686 print("Initial build: ${sw.elapsedMicroseconds} microseconds");
685 }); 687 });
686 } 688 }
687 } 689 }
OLDNEW
« no previous file with comments | « sky/framework/editing/editable_text.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698