Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 26 matching lines...) Expand all Loading... | |
| 37 _handlers.add(new EventHandler(type, listener)); | 37 _handlers.add(new EventHandler(type, listener)); |
| 38 } | 38 } |
| 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 final String _styles; | |
| 48 final List<String> _classList; | |
|
abarth-chromium
2015/03/13 20:47:40
Remove?
| |
| 49 | |
| 47 static final Map<String, Style> _cache = new HashMap<String, Style>(); | 50 static final Map<String, Style> _cache = new HashMap<String, Style>(); |
| 48 | 51 |
| 49 static int nextStyleId = 1; | 52 static int _nextStyleId = 1; |
| 50 | 53 |
| 51 static String nextClassName(String styles) { | 54 static String _getNextClassName() { return "style${_nextStyleId++}"; } |
| 52 assert(sky.document != null); | |
| 53 String className = "style$nextStyleId"; | |
| 54 nextStyleId++; | |
| 55 | 55 |
| 56 sky.Element styleNode = sky.document.createElement('style'); | 56 factory Style(String styles) { |
| 57 styleNode.setChild(new sky.Text(".$className { $styles }")); | 57 return _getOrCreateStyle(styles); |
| 58 sky.document.appendChild(styleNode); | |
| 59 | |
| 60 return className; | |
| 61 } | 58 } |
| 62 | 59 |
| 63 factory Style(String styles) { | 60 Style extend(Style other) { |
| 64 return _cache.putIfAbsent(styles, () { | 61 List<String> classList = new List.from(_classList)..addAll(other._classList) ; |
| 65 return new Style._internal(nextClassName(styles)); | 62 var cacheId = "${classList.join(' ')}"; |
| 63 | |
| 64 return _cache.putIfAbsent(cacheId, () { | |
| 65 return new Style._internal(null, classList); | |
| 66 }); | 66 }); |
| 67 } | 67 } |
| 68 | 68 |
| 69 Style._internal(this._className); | 69 static Style _getOrCreateStyle(String styles) { |
| 70 return _cache.putIfAbsent(styles, () { | |
| 71 var className = _getNextClassName(); | |
| 72 var selector = ".$className"; | |
| 73 sky.Element styleNode = sky.document.createElement('style'); | |
| 74 styleNode.setChild(new sky.Text("$selector { $styles }")); | |
| 75 sky.document.appendChild(styleNode); | |
| 76 | |
| 77 return new Style._internal(styles, [className]); | |
| 78 }); | |
| 79 } | |
| 80 | |
| 81 Style._internal(this._styles, List<String> classList) | |
| 82 : _classList = classList, | |
| 83 _className = classList.join(' '); | |
| 70 } | 84 } |
| 71 | 85 |
| 72 void _parentInsertBefore(sky.ParentNode parent, | 86 void _parentInsertBefore(sky.ParentNode parent, |
| 73 sky.Node node, | 87 sky.Node node, |
| 74 sky.Node ref) { | 88 sky.Node ref) { |
| 75 if (ref != null) { | 89 if (ref != null) { |
| 76 ref.insertBefore([node]); | 90 ref.insertBefore([node]); |
| 77 } else { | 91 } else { |
| 78 parent.appendChild(node); | 92 parent.appendChild(node); |
| 79 } | 93 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 Element get _emptyElement; | 147 Element get _emptyElement; |
| 134 | 148 |
| 135 String inlineStyle; | 149 String inlineStyle; |
| 136 | 150 |
| 137 List<Node> _children = null; | 151 List<Node> _children = null; |
| 138 String _class = ''; | 152 String _class = ''; |
| 139 | 153 |
| 140 Element({ | 154 Element({ |
| 141 Object key, | 155 Object key, |
| 142 List<Node> children, | 156 List<Node> children, |
| 143 List<Style> styles, | 157 Style style, |
| 144 | 158 |
| 145 this.inlineStyle | 159 this.inlineStyle |
| 146 }) : super(key:key) { | 160 }) : super(key:key) { |
| 147 _class = styles == null ? '' : styles.map((s) => s._className).join(' '); | 161 _class = style == null ? '' : style._className; |
| 148 _children = children == null ? _emptyList : children; | 162 _children = children == null ? _emptyList : children; |
| 149 | 163 |
| 150 if (_isInCheckedMode) { | 164 if (_isInCheckedMode) { |
| 151 _debugReportDuplicateIds(); | 165 _debugReportDuplicateIds(); |
| 152 } | 166 } |
| 153 } | 167 } |
| 154 | 168 |
| 155 void _remove() { | 169 void _remove() { |
| 156 super._remove(); | 170 super._remove(); |
| 157 if (_children != null) { | 171 if (_children != null) { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 class Container extends Element { | 419 class Container extends Element { |
| 406 | 420 |
| 407 String get _tagName => 'div'; | 421 String get _tagName => 'div'; |
| 408 | 422 |
| 409 static final Container _emptyContainer = new Container(); | 423 static final Container _emptyContainer = new Container(); |
| 410 Element get _emptyElement => _emptyContainer; | 424 Element get _emptyElement => _emptyContainer; |
| 411 | 425 |
| 412 Container({ | 426 Container({ |
| 413 Object key, | 427 Object key, |
| 414 List<Node> children, | 428 List<Node> children, |
| 415 List<Style> styles, | 429 Style style, |
| 416 String inlineStyle | 430 String inlineStyle |
| 417 }) : super( | 431 }) : super( |
| 418 key: key, | 432 key: key, |
| 419 children: children, | 433 children: children, |
| 420 styles: styles, | 434 style: style, |
| 421 inlineStyle: inlineStyle | 435 inlineStyle: inlineStyle |
| 422 ); | 436 ); |
| 423 } | 437 } |
| 424 | 438 |
| 425 class Image extends Element { | 439 class Image extends Element { |
| 426 | 440 |
| 427 String get _tagName => 'img'; | 441 String get _tagName => 'img'; |
| 428 | 442 |
| 429 static final Image _emptyImage = new Image(); | 443 static final Image _emptyImage = new Image(); |
| 430 Element get _emptyElement => _emptyImage; | 444 Element get _emptyElement => _emptyImage; |
| 431 | 445 |
| 432 String src; | 446 String src; |
| 433 int width; | 447 int width; |
| 434 int height; | 448 int height; |
| 435 | 449 |
| 436 Image({ | 450 Image({ |
| 437 Object key, | 451 Object key, |
| 438 List<Node> children, | 452 List<Node> children, |
| 439 List<Style> styles, | 453 Style style, |
| 440 String inlineStyle, | 454 String inlineStyle, |
| 441 this.width, | 455 this.width, |
| 442 this.height, | 456 this.height, |
| 443 this.src | 457 this.src |
| 444 }) : super( | 458 }) : super( |
| 445 key: key, | 459 key: key, |
| 446 children: children, | 460 children: children, |
| 447 styles: styles, | 461 style: style, |
| 448 inlineStyle: inlineStyle | 462 inlineStyle: inlineStyle |
| 449 ); | 463 ); |
| 450 | 464 |
| 451 void _syncNode([Element old]) { | 465 void _syncNode([Element old]) { |
| 452 super._syncNode(old); | 466 super._syncNode(old); |
| 453 | 467 |
| 454 Image oldImage = old != null ? old : _emptyImage; | 468 Image oldImage = old != null ? old : _emptyImage; |
| 455 sky.HTMLImageElement skyImage = _root as sky.HTMLImageElement; | 469 sky.HTMLImageElement skyImage = _root as sky.HTMLImageElement; |
| 456 if (src != oldImage.src) { | 470 if (src != oldImage.src) { |
| 457 skyImage.src = src; | 471 skyImage.src = src; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 473 static final Anchor _emptyAnchor = new Anchor(); | 487 static final Anchor _emptyAnchor = new Anchor(); |
| 474 Element get _emptyElement => _emptyAnchor; | 488 Element get _emptyElement => _emptyAnchor; |
| 475 | 489 |
| 476 String href; | 490 String href; |
| 477 int width; | 491 int width; |
| 478 int height; | 492 int height; |
| 479 | 493 |
| 480 Anchor({ | 494 Anchor({ |
| 481 Object key, | 495 Object key, |
| 482 List<Node> children, | 496 List<Node> children, |
| 483 List<Style> styles, | 497 Style style, |
| 484 String inlineStyle, | 498 String inlineStyle, |
| 485 this.width, | 499 this.width, |
| 486 this.height, | 500 this.height, |
| 487 this.href | 501 this.href |
| 488 }) : super( | 502 }) : super( |
| 489 key: key, | 503 key: key, |
| 490 children: children, | 504 children: children, |
| 491 styles: styles, | 505 style: style, |
| 492 inlineStyle: inlineStyle | 506 inlineStyle: inlineStyle |
| 493 ); | 507 ); |
| 494 | 508 |
| 495 void _syncNode([Element old]) { | 509 void _syncNode([Element old]) { |
| 496 Anchor oldAnchor = old != null ? old as Anchor : _emptyAnchor; | 510 Anchor oldAnchor = old != null ? old as Anchor : _emptyAnchor; |
| 497 super._syncNode(oldAnchor); | 511 super._syncNode(oldAnchor); |
| 498 | 512 |
| 499 sky.HTMLAnchorElement skyAnchor = _root as sky.HTMLAnchorElement; | 513 sky.HTMLAnchorElement skyAnchor = _root as sky.HTMLAnchorElement; |
| 500 if (href != oldAnchor.href) { | 514 if (href != oldAnchor.href) { |
| 501 skyAnchor.href = href; | 515 skyAnchor.href = href; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 | 692 |
| 679 _sync(null, _host, null); | 693 _sync(null, _host, null); |
| 680 assert(_root is sky.Node); | 694 assert(_root is sky.Node); |
| 681 | 695 |
| 682 sw.stop(); | 696 sw.stop(); |
| 683 if (_shouldLogRenderDuration) | 697 if (_shouldLogRenderDuration) |
| 684 print("Initial build: ${sw.elapsedMicroseconds} microseconds"); | 698 print("Initial build: ${sw.elapsedMicroseconds} microseconds"); |
| 685 }); | 699 }); |
| 686 } | 700 } |
| 687 } | 701 } |
| OLD | NEW |