| 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 part of view; | 5 part of view; |
| 6 | 6 |
| 7 class PageState { | 7 class PageState { |
| 8 final ObservableValue<int> current; | 8 final ObservableValue<int> current; |
| 9 final ObservableValue<int> target; | 9 final ObservableValue<int> target; |
| 10 final ObservableValue<int> length; | 10 final ObservableValue<int> length; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 | 178 |
| 179 /** Watch for resize and update page count. */ | 179 /** Watch for resize and update page count. */ |
| 180 void windowResized() { | 180 void windowResized() { |
| 181 // TODO(jmesserly): verify we aren't triggering unnecessary layouts. | 181 // TODO(jmesserly): verify we aren't triggering unnecessary layouts. |
| 182 | 182 |
| 183 // The content needs to have its height explicitly set, or columns don't | 183 // The content needs to have its height explicitly set, or columns don't |
| 184 // flow to the right correctly. So we copy our own height and set the height | 184 // flow to the right correctly. So we copy our own height and set the height |
| 185 // of the content. | 185 // of the content. |
| 186 window.setImmediate(() { | 186 window.setImmediate(() { |
| 187 contentView.node.style.height = '${node.offsetHeight}px'; | 187 contentView.node.style.height = '${node.offset.height}px'; |
| 188 }); | 188 }); |
| 189 _updatePageCount(null); | 189 _updatePageCount(null); |
| 190 } | 190 } |
| 191 | 191 |
| 192 bool _updatePageCount(Callback callback) { | 192 bool _updatePageCount(Callback callback) { |
| 193 int pageLength = 1; | 193 int pageLength = 1; |
| 194 window.setImmediate(() { | 194 window.setImmediate(() { |
| 195 if (_container.scrollWidth > _container.offsetWidth) { | 195 if (_container.scrollWidth > _container.offset.width) { |
| 196 pageLength = (_container.scrollWidth / _computePageSize(_container)) | 196 pageLength = (_container.scrollWidth / _computePageSize(_container)) |
| 197 .ceil().toInt(); | 197 .ceil().toInt(); |
| 198 } | 198 } |
| 199 pageLength = Math.max(pageLength, 1); | 199 pageLength = Math.max(pageLength, 1); |
| 200 | 200 |
| 201 int oldPage = pages.target.value; | 201 int oldPage = pages.target.value; |
| 202 int newPage = Math.min(oldPage, pageLength - 1); | 202 int newPage = Math.min(oldPage, pageLength - 1); |
| 203 | 203 |
| 204 // Hacky: make sure a change event always fires. | 204 // Hacky: make sure a change event always fires. |
| 205 // This is so we adjust the 3d transform after resize. | 205 // This is so we adjust the 3d transform after resize. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // Update the target page number when we are done animating. | 256 // Update the target page number when we are done animating. |
| 257 pages.target.value = pageNumber; | 257 pages.target.value = pageNumber; |
| 258 } | 258 } |
| 259 }); | 259 }); |
| 260 } | 260 } |
| 261 | 261 |
| 262 int _computePageSize(Element element) { | 262 int _computePageSize(Element element) { |
| 263 // Hacky: we need to duplicate the way the columns are being computed, | 263 // Hacky: we need to duplicate the way the columns are being computed, |
| 264 // including rounding, to figure out how far to translate the div. | 264 // including rounding, to figure out how far to translate the div. |
| 265 // See http://www.w3.org/TR/css3-multicol/#column-width | 265 // See http://www.w3.org/TR/css3-multicol/#column-width |
| 266 _viewportSize = element.offsetWidth; | 266 _viewportSize = element.offset.width; |
| 267 | 267 |
| 268 // Figure out how many columns we're rendering. | 268 // Figure out how many columns we're rendering. |
| 269 // The algorithm ensures we're bigger than the specified min size. | 269 // The algorithm ensures we're bigger than the specified min size. |
| 270 int perPage = Math.max(1, | 270 int perPage = Math.max(1, |
| 271 (_viewportSize + _columnGap) ~/ (_columnWidth + _columnGap)); | 271 (_viewportSize + _columnGap) ~/ (_columnWidth + _columnGap)); |
| 272 | 272 |
| 273 // Divide up the viewport between the columns. | 273 // Divide up the viewport between the columns. |
| 274 int columnSize = (_viewportSize - (perPage - 1) * _columnGap) ~/ perPage; | 274 int columnSize = (_viewportSize - (perPage - 1) * _columnGap) ~/ perPage; |
| 275 | 275 |
| 276 // Finally, compute how big each page is, and how far to translate. | 276 // Finally, compute how big each page is, and how far to translate. |
| 277 return perPage * (columnSize + _columnGap); | 277 return perPage * (columnSize + _columnGap); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void _onPageSelected() { | 280 void _onPageSelected() { |
| 281 window.setImmediate(() { | 281 window.setImmediate(() { |
| 282 int translate = -pages.target.value * _computePageSize(_container); | 282 int translate = -pages.target.value * _computePageSize(_container); |
| 283 scroller.throwTo(translate, 0); | 283 scroller.throwTo(translate, 0); |
| 284 }); | 284 }); |
| 285 } | 285 } |
| 286 } | 286 } |
| OLD | NEW |