| 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); |
| 11 | 11 |
| 12 /** The width of the created view or null if the width is not fixed. */ | 12 /** The width of the created view or null if the width is not fixed. */ |
| 13 int get width(); | 13 int get width; |
| 14 | 14 |
| 15 /** The height of the created view or null if the height is not fixed. */ | 15 /** The height of the created view or null if the height is not fixed. */ |
| 16 int get height(); | 16 int get height; |
| 17 } | 17 } |
| 18 | 18 |
| 19 interface VariableSizeViewFactory<D> { | 19 interface VariableSizeViewFactory<D> { |
| 20 View newView(D item); | 20 View newView(D item); |
| 21 | 21 |
| 22 /** The width of the created view for a specific data model. */ | 22 /** The width of the created view for a specific data model. */ |
| 23 int getWidth(D item); | 23 int getWidth(D item); |
| 24 | 24 |
| 25 /** The height of the created view for a specific data model. */ | 25 /** The height of the created view for a specific data model. */ |
| 26 int getHeight(D item); | 26 int getHeight(D item); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 161 } |
| 162 | 162 |
| 163 void onSelectedItemChange() { | 163 void onSelectedItemChange() { |
| 164 // TODO(rnystrom): use Observable to track the last value of _selectedItem | 164 // TODO(rnystrom): use Observable to track the last value of _selectedItem |
| 165 // rather than tracking it ourselves. | 165 // rather than tracking it ourselves. |
| 166 _select(findIndex(_lastSelectedItem), false); | 166 _select(findIndex(_lastSelectedItem), false); |
| 167 _select(findIndex(_selectedItem.value), true); | 167 _select(findIndex(_selectedItem.value), true); |
| 168 _lastSelectedItem = _selectedItem.value; | 168 _lastSelectedItem = _selectedItem.value; |
| 169 } | 169 } |
| 170 | 170 |
| 171 Collection<View> get childViews() { | 171 Collection<View> get childViews { |
| 172 return _itemViews.getValues(); | 172 return _itemViews.getValues(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void _onClick(MouseEvent e) { | 175 void _onClick(MouseEvent e) { |
| 176 int index = _findAssociatedIndex(e.target); | 176 int index = _findAssociatedIndex(e.target); |
| 177 if (index != null) { | 177 if (index != null) { |
| 178 _selectedItem.value = _data[index]; | 178 _selectedItem.value = _data[index]; |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 367 } |
| 368 | 368 |
| 369 void _onPageSelected() { | 369 void _onPageSelected() { |
| 370 if (_pages.target != | 370 if (_pages.target != |
| 371 _layout.getPage(_activeInterval.start, _viewLength)) { | 371 _layout.getPage(_activeInterval.start, _viewLength)) { |
| 372 _throwTo(_layout.getOffset( | 372 _throwTo(_layout.getOffset( |
| 373 _layout.getPageStartIndex(_pages.target.value, _viewLength))); | 373 _layout.getPageStartIndex(_pages.target.value, _viewLength))); |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 | 376 |
| 377 num get _offset() { | 377 num get _offset { |
| 378 return scroller.verticalEnabled ? | 378 return scroller.verticalEnabled ? |
| 379 scroller.getVerticalOffset() : scroller.getHorizontalOffset(); | 379 scroller.getVerticalOffset() : scroller.getHorizontalOffset(); |
| 380 } | 380 } |
| 381 | 381 |
| 382 /** | 382 /** |
| 383 * Calculates visible interval, based on the scroller position. | 383 * Calculates visible interval, based on the scroller position. |
| 384 */ | 384 */ |
| 385 Interval getVisibleInterval() { | 385 Interval getVisibleInterval() { |
| 386 return _layout.computeVisibleInterval(_offset, _viewLength, 0); | 386 return _layout.computeVisibleInterval(_offset, _viewLength, 0); |
| 387 } | 387 } |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 611 |
| 612 FixedSizeListViewLayout(this.itemViewFactory, this._data, this._vertical, | 612 FixedSizeListViewLayout(this.itemViewFactory, this._data, this._vertical, |
| 613 this._paginate); | 613 this._paginate); |
| 614 | 614 |
| 615 void onDataChange() {} | 615 void onDataChange() {} |
| 616 | 616 |
| 617 View newView(int index) { | 617 View newView(int index) { |
| 618 return itemViewFactory.newView(_data[index]); | 618 return itemViewFactory.newView(_data[index]); |
| 619 } | 619 } |
| 620 | 620 |
| 621 int get _itemLength() { | 621 int get _itemLength { |
| 622 return _vertical ? itemViewFactory.height : itemViewFactory.width; | 622 return _vertical ? itemViewFactory.height : itemViewFactory.width; |
| 623 } | 623 } |
| 624 | 624 |
| 625 | 625 |
| 626 int getWidth(int viewLength) { | 626 int getWidth(int viewLength) { |
| 627 return _vertical ? itemViewFactory.width : getLength(viewLength); | 627 return _vertical ? itemViewFactory.width : getLength(viewLength); |
| 628 } | 628 } |
| 629 | 629 |
| 630 int getHeight(int viewLength) { | 630 int getHeight(int viewLength) { |
| 631 return _vertical ? getLength(viewLength) : itemViewFactory.height; | 631 return _vertical ? getLength(viewLength) : itemViewFactory.height; |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 | 976 |
| 977 container = node.query('.dialog-body'); | 977 container = node.query('.dialog-body'); |
| 978 container.nodes.add(_content.node); | 978 container.nodes.add(_content.node); |
| 979 | 979 |
| 980 return node; | 980 return node; |
| 981 } | 981 } |
| 982 | 982 |
| 983 /** Override to handle dialog done. */ | 983 /** Override to handle dialog done. */ |
| 984 void onDone() { } | 984 void onDone() { } |
| 985 } | 985 } |
| OLD | NEW |