| 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.map(view.childViews, (view) => view.layout); | 155 final items = CollectionUtils.map(view.childViews, (view_) => view_.layout); |
| 156 CollectionUtils.sortBy(items, (item) => _getSpanCount(item)); | 156 CollectionUtils.sortBy(items, (item) => _getSpanCount(item)); |
| 157 | 157 |
| 158 // 1. Initialize per Grid Track variables | 158 // 1. Initialize per Grid Track variables |
| 159 for (final t in tracks) { | 159 for (final t in tracks) { |
| 160 // percentage or length sizing functions will return a value | 160 // percentage or length sizing functions will return a value |
| 161 // min-content, max-content, or a fraction will be set to 0 | 161 // min-content, max-content, or a fraction will be set to 0 |
| 162 t.usedBreadth = t.minSizing.resolveLength(_getGridContentSize()); | 162 t.usedBreadth = t.minSizing.resolveLength(_getGridContentSize()); |
| 163 t.maxBreadth = t.maxSizing.resolveLength(_getGridContentSize()); | 163 t.maxBreadth = t.maxSizing.resolveLength(_getGridContentSize()); |
| 164 t.updatedBreadth = 0; | 164 t.updatedBreadth = 0; |
| 165 } | 165 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 */ | 378 */ |
| 379 static bool _hasContentSizedTracks(Collection<GridTrack> tracks, | 379 static bool _hasContentSizedTracks(Collection<GridTrack> tracks, |
| 380 ContentSizeMode sizeMode, _BreadthAccumulator breadth) { | 380 ContentSizeMode sizeMode, _BreadthAccumulator breadth) { |
| 381 | 381 |
| 382 for (final t in tracks) { | 382 for (final t in tracks) { |
| 383 final fn = breadth.getSizingFunction(t); | 383 final fn = breadth.getSizingFunction(t); |
| 384 if (sizeMode == ContentSizeMode.MAX && fn.isMaxContentSized || | 384 if (sizeMode == ContentSizeMode.MAX && fn.isMaxContentSized || |
| 385 sizeMode == ContentSizeMode.MIN && fn.isContentSized) { | 385 sizeMode == ContentSizeMode.MIN && fn.isContentSized) { |
| 386 | 386 |
| 387 // Make sure we don't cross a fractional track | 387 // Make sure we don't cross a fractional track |
| 388 return tracks.length == 1 || !tracks.some((t) => t.isFractional); | 388 return tracks.length == 1 || !tracks.some((t_) => t_.isFractional); |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 return false; | 391 return false; |
| 392 } | 392 } |
| 393 | 393 |
| 394 /** Ensures that the numbered track exists. */ | 394 /** Ensures that the numbered track exists. */ |
| 395 void _ensureTrack(List<GridTrack> tracks, TrackSizing sizing, | 395 void _ensureTrack(List<GridTrack> tracks, TrackSizing sizing, |
| 396 int start, int span) { | 396 int start, int span) { |
| 397 // Start is 1-based. Make it 0-based. | 397 // Start is 1-based. Make it 0-based. |
| 398 start -= 1; | 398 start -= 1; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 411 } | 411 } |
| 412 | 412 |
| 413 /** | 413 /** |
| 414 * Scans children creating GridLayoutParams as needed, and creates all of the | 414 * Scans children creating GridLayoutParams as needed, and creates all of the |
| 415 * rows and columns that we will need. | 415 * rows and columns that we will need. |
| 416 * | 416 * |
| 417 * Note: this can potentially create new rows/columns, so this needs to be | 417 * Note: this can potentially create new rows/columns, so this needs to be |
| 418 * run before the track sizing algorithm. | 418 * run before the track sizing algorithm. |
| 419 */ | 419 */ |
| 420 void _ensureAllTracks() { | 420 void _ensureAllTracks() { |
| 421 final items = CollectionUtils.map(view.childViews, (view) => view.layout); | 421 final items = CollectionUtils.map(view.childViews, (view_) => view_.layout); |
| 422 | 422 |
| 423 for (final child in items) { | 423 for (final child in items) { |
| 424 if (child.layoutParams == null) { | 424 if (child.layoutParams == null) { |
| 425 final p = new GridLayoutParams(child.view, this); | 425 final p = new GridLayoutParams(child.view, this); |
| 426 _ensureTrack(_rowTracks, rowSizing, p.row, p.rowSpan); | 426 _ensureTrack(_rowTracks, rowSizing, p.row, p.rowSpan); |
| 427 _ensureTrack(_columnTracks, columnSizing, p.column, p.columnSpan); | 427 _ensureTrack(_columnTracks, columnSizing, p.column, p.columnSpan); |
| 428 child.layoutParams = p; | 428 child.layoutParams = p; |
| 429 } | 429 } |
| 430 child.cacheExistingBrowserLayout(); | 430 child.cacheExistingBrowserLayout(); |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 | 433 |
| 434 /** | 434 /** |
| 435 * Given the track sizes that were computed, position children in the grid. | 435 * Given the track sizes that were computed, position children in the grid. |
| 436 */ | 436 */ |
| 437 void _setBoundsOfChildren() { | 437 void _setBoundsOfChildren() { |
| 438 final items = CollectionUtils.map(view.childViews, (view) => view.layout); | 438 final items = CollectionUtils.map(view.childViews, (view_) => view_.layout); |
| 439 | 439 |
| 440 for (final item in items) { | 440 for (final item in items) { |
| 441 GridLayoutParams childLayout = item.layoutParams; | 441 GridLayoutParams childLayout = item.layoutParams; |
| 442 var xPos = _getTrackLocationX(childLayout); | 442 var xPos = _getTrackLocationX(childLayout); |
| 443 var yPos = _getTrackLocationY(childLayout); | 443 var yPos = _getTrackLocationY(childLayout); |
| 444 | 444 |
| 445 int left = xPos.start, width = xPos.length; | 445 int left = xPos.start, width = xPos.length; |
| 446 int top = yPos.start, height = yPos.length; | 446 int top = yPos.start, height = yPos.length; |
| 447 | 447 |
| 448 // Somewhat counterintuitively (at least to me): | 448 // Somewhat counterintuitively (at least to me): |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 } | 511 } |
| 512 return result; | 512 return result; |
| 513 } | 513 } |
| 514 | 514 |
| 515 int _getSpanCount(ViewLayout item) { | 515 int _getSpanCount(ViewLayout item) { |
| 516 GridLayoutParams childLayout = item.layoutParams; | 516 GridLayoutParams childLayout = item.layoutParams; |
| 517 return (_dimension == Dimension.WIDTH ? | 517 return (_dimension == Dimension.WIDTH ? |
| 518 childLayout.columnSpan : childLayout.rowSpan); | 518 childLayout.columnSpan : childLayout.rowSpan); |
| 519 } | 519 } |
| 520 } | 520 } |
| OLD | NEW |