| 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 /** | 5 /** |
| 6 * Implements a grid-based layout system based on: | 6 * Implements a grid-based layout system based on: |
| 7 * [http://dev.w3.org/csswg/css3-grid-align/] | 7 * [http://dev.w3.org/csswg/css3-grid-align/] |
| 8 * | 8 * |
| 9 * This layout is designed to support animations and work on browsers that | 9 * This layout is designed to support animations and work on browsers that |
| 10 * don't support grid natively. As such, we implement it on top of absolute | 10 * don't support grid natively. As such, we implement it on top of absolute |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 * and Grid rows. The goal of the function is to ensure: | 145 * and Grid rows. The goal of the function is to ensure: |
| 146 * 1. That each Grid Track satisfies its minSizing | 146 * 1. That each Grid Track satisfies its minSizing |
| 147 * 2. That each Grid Track grows from the breadth which satisfied its | 147 * 2. That each Grid Track grows from the breadth which satisfied its |
| 148 * minSizing to a breadth which satifies its | 148 * minSizing to a breadth which satifies its |
| 149 * maxSizing, subject to RemainingSpace. | 149 * maxSizing, subject to RemainingSpace. |
| 150 */ | 150 */ |
| 151 // Note: spec does not correctly doc all the parameters to this function. | 151 // Note: spec does not correctly doc all the parameters to this function. |
| 152 void _computeUsedBreadthOfTracks(List<GridTrack> tracks) { | 152 void _computeUsedBreadthOfTracks(List<GridTrack> tracks) { |
| 153 | 153 |
| 154 // TODO(jmesserly): as a performance optimization we could cache this | 154 // TODO(jmesserly): as a performance optimization we could cache this |
| 155 final items = CollectionUtils.mappedBy(view.childViews, (view_) => view_.lay
out); | 155 final items = view.childViews |
| 156 .mappedBy((view_) => view_.layout) |
| 157 .toList(); |
| 156 CollectionUtils.sortBy(items, (item) => _getSpanCount(item)); | 158 CollectionUtils.sortBy(items, (item) => _getSpanCount(item)); |
| 157 | 159 |
| 158 // 1. Initialize per Grid Track variables | 160 // 1. Initialize per Grid Track variables |
| 159 for (final t in tracks) { | 161 for (final t in tracks) { |
| 160 // percentage or length sizing functions will return a value | 162 // percentage or length sizing functions will return a value |
| 161 // min-content, max-content, or a fraction will be set to 0 | 163 // min-content, max-content, or a fraction will be set to 0 |
| 162 t.usedBreadth = t.minSizing.resolveLength(_getGridContentSize()); | 164 t.usedBreadth = t.minSizing.resolveLength(_getGridContentSize()); |
| 163 t.maxBreadth = t.maxSizing.resolveLength(_getGridContentSize()); | 165 t.maxBreadth = t.maxSizing.resolveLength(_getGridContentSize()); |
| 164 t.updatedBreadth = 0; | 166 t.updatedBreadth = 0; |
| 165 } | 167 } |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 } | 413 } |
| 412 | 414 |
| 413 /** | 415 /** |
| 414 * Scans children creating GridLayoutParams as needed, and creates all of the | 416 * Scans children creating GridLayoutParams as needed, and creates all of the |
| 415 * rows and columns that we will need. | 417 * rows and columns that we will need. |
| 416 * | 418 * |
| 417 * Note: this can potentially create new rows/columns, so this needs to be | 419 * Note: this can potentially create new rows/columns, so this needs to be |
| 418 * run before the track sizing algorithm. | 420 * run before the track sizing algorithm. |
| 419 */ | 421 */ |
| 420 void _ensureAllTracks() { | 422 void _ensureAllTracks() { |
| 421 final items = CollectionUtils.mappedBy(view.childViews, (view_) => view_.lay
out); | 423 final items = view.childViews.mappedBy((view_) => view_.layout); |
| 422 | 424 |
| 423 for (final child in items) { | 425 for (final child in items) { |
| 424 if (child.layoutParams == null) { | 426 if (child.layoutParams == null) { |
| 425 final p = new GridLayoutParams(child.view, this); | 427 final p = new GridLayoutParams(child.view, this); |
| 426 _ensureTrack(_rowTracks, rowSizing, p.row, p.rowSpan); | 428 _ensureTrack(_rowTracks, rowSizing, p.row, p.rowSpan); |
| 427 _ensureTrack(_columnTracks, columnSizing, p.column, p.columnSpan); | 429 _ensureTrack(_columnTracks, columnSizing, p.column, p.columnSpan); |
| 428 child.layoutParams = p; | 430 child.layoutParams = p; |
| 429 } | 431 } |
| 430 child.cacheExistingBrowserLayout(); | 432 child.cacheExistingBrowserLayout(); |
| 431 } | 433 } |
| 432 } | 434 } |
| 433 | 435 |
| 434 /** | 436 /** |
| 435 * Given the track sizes that were computed, position children in the grid. | 437 * Given the track sizes that were computed, position children in the grid. |
| 436 */ | 438 */ |
| 437 void _setBoundsOfChildren() { | 439 void _setBoundsOfChildren() { |
| 438 final items = CollectionUtils.mappedBy(view.childViews, (view_) => view_.lay
out); | 440 final items = view.childViews.mappedBy((view_) => view_.layout); |
| 439 | 441 |
| 440 for (final item in items) { | 442 for (final item in items) { |
| 441 GridLayoutParams childLayout = item.layoutParams; | 443 GridLayoutParams childLayout = item.layoutParams; |
| 442 var xPos = _getTrackLocationX(childLayout); | 444 var xPos = _getTrackLocationX(childLayout); |
| 443 var yPos = _getTrackLocationY(childLayout); | 445 var yPos = _getTrackLocationY(childLayout); |
| 444 | 446 |
| 445 int left = xPos.start, width = xPos.length; | 447 int left = xPos.start, width = xPos.length; |
| 446 int top = yPos.start, height = yPos.length; | 448 int top = yPos.start, height = yPos.length; |
| 447 | 449 |
| 448 // Somewhat counterintuitively (at least to me): | 450 // Somewhat counterintuitively (at least to me): |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 } | 510 } |
| 509 return result; | 511 return result; |
| 510 } | 512 } |
| 511 | 513 |
| 512 int _getSpanCount(ViewLayout item) { | 514 int _getSpanCount(ViewLayout item) { |
| 513 GridLayoutParams childLayout = item.layoutParams; | 515 GridLayoutParams childLayout = item.layoutParams; |
| 514 return (_dimension == Dimension.WIDTH ? | 516 return (_dimension == Dimension.WIDTH ? |
| 515 childLayout.columnSpan : childLayout.rowSpan); | 517 childLayout.columnSpan : childLayout.rowSpan); |
| 516 } | 518 } |
| 517 } | 519 } |
| OLD | NEW |