| 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', prefix: 'Math'); | 8 #import('dart:math', prefix: 'Math'); |
| 9 | 9 |
| 10 #import('../base/base.dart'); | 10 #import('../base/base.dart'); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 View.fromNode(Element this._node) | 48 View.fromNode(Element this._node) |
| 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 |
| 70 * manually handle that traversal. | 70 * manually handle that traversal. |
| 71 */ | 71 */ |
| 72 Collection<View> get childViews() { | 72 Collection<View> get childViews { |
| 73 return const []; | 73 return const []; |
| 74 } | 74 } |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * View presumes the collection of views returned by childViews is more or | 77 * View presumes the collection of views returned by childViews is more or |
| 78 * less static after the view is first created. Subclasses should call this | 78 * less static after the view is first created. Subclasses should call this |
| 79 * when that invariant doesn't hold to let View know that a new childView has | 79 * when that invariant doesn't hold to let View know that a new childView has |
| 80 * appeared. | 80 * appeared. |
| 81 */ | 81 */ |
| 82 void childViewAdded(View child) { | 82 void childViewAdded(View child) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 * when that invariant doesn't hold to let View know that a childView has | 94 * when that invariant doesn't hold to let View know that a childView has |
| 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 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // is discarded. | 199 // is discarded. |
| 200 } | 200 } |
| 201 | 201 |
| 202 void addOnClick(EventListener handler) { | 202 void addOnClick(EventListener handler) { |
| 203 _node.on.click.add(handler); | 203 _node.on.click.add(handler); |
| 204 } | 204 } |
| 205 | 205 |
| 206 /** | 206 /** |
| 207 * Gets whether the view is hidden. | 207 * Gets whether the view is hidden. |
| 208 */ | 208 */ |
| 209 bool get hidden() => _node.style.display == 'none'; | 209 bool get hidden => _node.style.display == 'none'; |
| 210 | 210 |
| 211 /** | 211 /** |
| 212 * Sets whether the view is hidden. | 212 * Sets whether the view is hidden. |
| 213 */ | 213 */ |
| 214 void set hidden(bool hidden) { | 214 void set hidden(bool hidden) { |
| 215 if (hidden) { | 215 if (hidden) { |
| 216 node.style.display = 'none'; | 216 node.style.display = 'none'; |
| 217 } else { | 217 } else { |
| 218 node.style.display = ''; | 218 node.style.display = ''; |
| 219 } | 219 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 // Notify the children first. | 268 // Notify the children first. |
| 269 for (final child in childViews) { | 269 for (final child in childViews) { |
| 270 child._enterDocument(); | 270 child._enterDocument(); |
| 271 } | 271 } |
| 272 | 272 |
| 273 enterDocument(); | 273 enterDocument(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Layout related methods | 276 // Layout related methods |
| 277 | 277 |
| 278 ViewLayout get layout() { | 278 ViewLayout get layout { |
| 279 if (_layout == null) { | 279 if (_layout == null) { |
| 280 _layout = new ViewLayout.fromView(this); | 280 _layout = new ViewLayout.fromView(this); |
| 281 } | 281 } |
| 282 return _layout; | 282 return _layout; |
| 283 } | 283 } |
| 284 | 284 |
| 285 /** | 285 /** |
| 286 * Internal method that deals with traversing child views. Should not be | 286 * Internal method that deals with traversing child views. Should not be |
| 287 * overridden. | 287 * overridden. |
| 288 */ | 288 */ |
| (...skipping 75 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 |