| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // This file contains View framework classes. | 5 // This file contains View framework classes. |
| 6 // As it grows, it may need to be split into multiple files. | 6 // As it grows, it may need to be split into multiple files. |
| 7 | 7 |
| 8 /** A factory that creates a view from a data model. */ | 8 /** A factory that creates a view from a data model. */ |
| 9 interface ViewFactory<D> { | 9 interface ViewFactory<D> { |
| 10 View newView(D item); | 10 View newView(D item); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 scroller = new Scroller( | 213 scroller = new Scroller( |
| 214 _containerElem, | 214 _containerElem, |
| 215 _vertical /* verticalScrollEnabled */, | 215 _vertical /* verticalScrollEnabled */, |
| 216 !_vertical /* horizontalScrollEnabled */, | 216 !_vertical /* horizontalScrollEnabled */, |
| 217 true /* momentumEnabled */, | 217 true /* momentumEnabled */, |
| 218 () { | 218 () { |
| 219 num width = _layout.getWidth(_viewLength); | 219 num width = _layout.getWidth(_viewLength); |
| 220 num height = _layout.getHeight(_viewLength); | 220 num height = _layout.getHeight(_viewLength); |
| 221 width = width != null ? width : 0; | 221 width = width != null ? width : 0; |
| 222 height = height != null ? height : 0; | 222 height = height != null ? height : 0; |
| 223 return new Size(width, height); | 223 final completer = new Completer<Size>(); |
| 224 completer.complete(new Size(width, height)); |
| 225 return completer.future; |
| 224 }, | 226 }, |
| 225 _paginate && _snapToItems ? | 227 _paginate && _snapToItems ? |
| 226 Scroller.FAST_SNAP_DECELERATION_FACTOR : 1); | 228 Scroller.FAST_SNAP_DECELERATION_FACTOR : 1); |
| 227 scroller.onContentMoved.add((e) => renderVisibleItems(false)); | 229 scroller.onContentMoved.add((e) => renderVisibleItems(false)); |
| 228 if (_pages != null) { | 230 if (_pages != null) { |
| 229 watch(_pages.target, (s) => _onPageSelected()); | 231 watch(_pages.target, (s) => _onPageSelected()); |
| 230 } | 232 } |
| 231 | 233 |
| 232 if (_snapToItems) { | 234 if (_snapToItems) { |
| 233 scroller.onDecelStart.add((e) => _decelStart()); | 235 scroller.onDecelStart.add((e) => _decelStart()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 style.height = '${height}px'; | 282 style.height = '${height}px'; |
| 281 } | 283 } |
| 282 // TODO(jacobr): this should be specified by the default CSS for a | 284 // TODO(jacobr): this should be specified by the default CSS for a |
| 283 // GenericListView. | 285 // GenericListView. |
| 284 style.overflow = 'hidden'; | 286 style.overflow = 'hidden'; |
| 285 } | 287 } |
| 286 | 288 |
| 287 | 289 |
| 288 void onResize() { | 290 void onResize() { |
| 289 int lastViewLength = _viewLength; | 291 int lastViewLength = _viewLength; |
| 290 calculateViewLength(); | 292 node.rect.then((ElementRect rect) { |
| 291 if (_viewLength != lastViewLength) { | 293 _viewLength = _vertical ? rect.offset.height : rect.offset.width; |
| 292 if (_scrollbar != null) { | 294 if (_viewLength != lastViewLength) { |
| 293 _scrollbar.refresh(); | 295 if (_scrollbar != null) { |
| 296 _scrollbar.refresh(); |
| 297 } |
| 298 renderVisibleItems(true); |
| 294 } | 299 } |
| 295 renderVisibleItems(true); | 300 }); |
| 296 } | |
| 297 } | |
| 298 | |
| 299 void calculateViewLength() { | |
| 300 if (_vertical) { | |
| 301 _viewLength = node.offsetHeight; | |
| 302 } else { | |
| 303 _viewLength = node.offsetWidth; | |
| 304 } | |
| 305 } | 301 } |
| 306 | 302 |
| 307 void enterDocument() { | 303 void enterDocument() { |
| 308 if (scroller != null) { | 304 if (scroller != null) { |
| 309 onResize(); | 305 onResize(); |
| 310 | 306 |
| 311 if (_scrollbar != null) { | 307 if (_scrollbar != null) { |
| 312 _scrollbar.initialize(); | 308 _scrollbar.initialize(); |
| 313 } | 309 } |
| 314 } | 310 } |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 | 976 |
| 981 container = node.query('.dialog-body'); | 977 container = node.query('.dialog-body'); |
| 982 container.nodes.add(_content.node); | 978 container.nodes.add(_content.node); |
| 983 | 979 |
| 984 return node; | 980 return node; |
| 985 } | 981 } |
| 986 | 982 |
| 987 /** Override to handle dialog done. */ | 983 /** Override to handle dialog done. */ |
| 988 void onDone() { } | 984 void onDone() { } |
| 989 } | 985 } |
| OLD | NEW |