OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 view; | 5 library view; |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'dart:math' as Math; | 8 import 'dart:math' as Math; |
9 | 9 |
10 import '../base/base.dart'; | 10 import '../base/base.dart'; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 : customStyle = new Map<String, String>(); | 49 : customStyle = new Map<String, String>(); |
50 | 50 |
51 View.html(String html) | 51 View.html(String html) |
52 : customStyle = new Map<String, String>(), | 52 : customStyle = new Map<String, String>(), |
53 _node = new Element.html(html); | 53 _node = new Element.html(html); |
54 | 54 |
55 // TODO(rnystrom): Get rid of this when all views are refactored to not use | 55 // TODO(rnystrom): Get rid of this when all views are refactored to not use |
56 // it. | 56 // it. |
57 Element get node { | 57 Element get node { |
58 // Lazy render. | 58 // Lazy render. |
59 if (_node === null) { | 59 if (_node == null) { |
60 _render(); | 60 _render(); |
61 } | 61 } |
62 | 62 |
63 return _node; | 63 return _node; |
64 } | 64 } |
65 | 65 |
66 /** | 66 /** |
67 * A subclass that contains child views should override this to return those | 67 * A subclass that contains child views should override this to return those |
68 * views. View uses this to ensure that child views are properly rendered | 68 * views. View uses this to ensure that child views are properly rendered |
69 * and initialized when their parent view is without the parent having to | 69 * and initialized when their parent view is without the parent having to |
(...skipping 25 matching lines...) Expand all Loading... |
95 * been removed. | 95 * been removed. |
96 */ | 96 */ |
97 void childViewRemoved(View child) { | 97 void childViewRemoved(View child) { |
98 if (isInDocument) { | 98 if (isInDocument) { |
99 child._exitDocument(); | 99 child._exitDocument(); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 /** Gets whether this View has already been rendered or not. */ | 103 /** Gets whether this View has already been rendered or not. */ |
104 bool get isRendered { | 104 bool get isRendered { |
105 return _node !== null; | 105 return _node != null; |
106 } | 106 } |
107 | 107 |
108 /** | 108 /** |
109 * Gets whether this View (or one of its parents) has been added to the | 109 * Gets whether this View (or one of its parents) has been added to the |
110 * document or not. | 110 * document or not. |
111 */ | 111 */ |
112 bool get isInDocument { | 112 bool get isInDocument { |
113 return _node !== null && node.document.body.contains(node); | 113 return _node != null && node.document.body.contains(node); |
114 } | 114 } |
115 | 115 |
116 /** | 116 /** |
117 * Adds this view to the document as a child of the given node. This should | 117 * Adds this view to the document as a child of the given node. This should |
118 * generally only be called once for the top-level view. | 118 * generally only be called once for the top-level view. |
119 */ | 119 */ |
120 void addToDocument(Element parentNode) { | 120 void addToDocument(Element parentNode) { |
121 assert(!isInDocument); | 121 assert(!isInDocument); |
122 | 122 |
123 _render(); | 123 _render(); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } | 364 } |
365 } | 365 } |
366 | 366 |
367 void _applyLayout() { | 367 void _applyLayout() { |
368 if (_layout != null) { | 368 if (_layout != null) { |
369 _layout.applyLayout(); | 369 _layout.applyLayout(); |
370 } | 370 } |
371 _applyLayoutToChildren(); | 371 _applyLayoutToChildren(); |
372 } | 372 } |
373 } | 373 } |
OLD | NEW |