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

Side by Side Diff: runtime/observatory/lib/src/elements/curly_block.dart

Issue 2119733003: Wrapping leaf nodes in non polymer elements (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library curly_block_element; 5 library curly_block_element;
6 6
7 import 'package:polymer/polymer.dart'; 7 import 'dart:async';
8 import 'observatory_element.dart'; 8 import 'dart:html';
9 import 'helpers/tag.dart';
9 10
10 @CustomTag('curly-block') 11 class CurlyBlockToggleEvent {
11 class CurlyBlockElement extends ObservatoryElement { 12 final CurlyBlockElement control;
12 CurlyBlockElement.created() : super.created();
13 13
14 @observable bool expanded = false; 14 CurlyBlockToggleEvent(this.control);
15 @observable bool busy = false; 15 }
16 @published var callback = null;
17 @published bool expand = false;
18 @published String expandKey;
19 16
20 void expandChanged(oldValue) { 17 class CurlyBlockElement extends HtmlElement {
21 expanded = expand; 18 static final StyleElement _style = () {
19 var style = new StyleElement();
20 style.text = '.idle {'
21 ' display: inline-block;'
22 ' color: #0489c3;'
23 ' cursor: pointer;'
24 '}'
25 '.busy {'
26 ' display: inline-block;'
27 ' color: white;'
28 ' cursor: wait;'
29 '}';
30 return style;
31 }();
32
33 static const tag = const Tag<CurlyBlockElement>('curly-block-wrapped');
34
35 bool expanded;
36 bool busy;
37
38 final StreamController<CurlyBlockToggleEvent> _onToggle =
39 new StreamController<CurlyBlockToggleEvent>();
40 Stream<CurlyBlockToggleEvent> get onToggle => _onToggle.stream;
41
42 factory CurlyBlockElement() {
43 return document.createElement(tag.name);
22 } 44 }
23 45
24 void expandKeyChanged(oldValue) { 46 CurlyBlockElement.created() : super.created() {
25 if (expandKey != null) { 47 createShadowRoot();
26 var value = app.expansions[expandKey];
27 if (value != null) {
28 if (expanded != value) {
29 toggleExpand(null, null, null);
30 }
31 }
32 }
33 } 48 }
34 49
35 void doneCallback() { 50 @override
36 expanded = !expanded; 51 void attached() {
37 if (expandKey != null) { 52 super.attached();
38 app.expansions[expandKey] = expanded; 53 render();
39 }
40 busy = false;
41 } 54 }
42 55
43 void toggleExpand(var event, var b, var c) { 56 void toggle() {
44 assert(callback == null || expand == false); 57 expanded = !expanded;
58 _onToggle.add(new CurlyBlockToggleEvent(this));
59 render();
60 }
61
62 void render() {
63 List<Element> children = [
64 _style.clone(true),
65 new SpanElement()..text = '{'
66 ];
67 DivElement label = new DivElement()
68 ..classes = [busy ? 'busy' : 'idle']
69 ..innerHtml = expanded ?
70 '&nbsp;&nbsp;&#8863;&nbsp;&nbsp;' : '&nbsp;&nbsp;&#8862;&nbsp;&nbsp;';
45 if (busy) { 71 if (busy) {
46 return; 72 children.add(label);
73 } else {
74 children.add(new AnchorElement()
75 ..onClick.listen((_) { toggle(); })
76 ..children = [label]);
47 } 77 }
48 busy = true; 78 if (expanded) {
49 if (callback != null) { 79 children.addAll([
50 callback(!expanded, doneCallback); 80 new BRElement(),
51 } else { 81 new ContentElement()
52 doneCallback(); 82 ]);
53 } 83 }
84 children.add(new SpanElement()..text = '}');
85 shadowRoot.children = children;
54 } 86 }
55 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698