| 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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 // grid-col-align is the horizontal alignment | 449 // grid-col-align is the horizontal alignment |
| 450 // grid-row-align is the vertical alignment | 450 // grid-row-align is the vertical alignment |
| 451 xPos = childLayout.columnAlign.align(xPos, item.currentWidth); | 451 xPos = childLayout.columnAlign.align(xPos, item.currentWidth); |
| 452 yPos = childLayout.rowAlign.align(yPos, item.currentHeight); | 452 yPos = childLayout.rowAlign.align(yPos, item.currentHeight); |
| 453 | 453 |
| 454 item.setBounds(xPos.start, yPos.start, xPos.length, yPos.length); | 454 item.setBounds(xPos.start, yPos.start, xPos.length, yPos.length); |
| 455 } | 455 } |
| 456 } | 456 } |
| 457 | 457 |
| 458 num _getGridContentSize() { | 458 num _getGridContentSize() { |
| 459 switch (_dimension) { | 459 if (_dimension == Dimension.WIDTH) { |
| 460 case Dimension.WIDTH: | 460 return _gridWidth; |
| 461 return _gridWidth; | 461 } else if (_dimension == Dimension.HEIGHT) { |
| 462 case Dimension.HEIGHT: | 462 return _gridHeight; |
| 463 return _gridHeight; | |
| 464 } | 463 } |
| 465 } | 464 } |
| 466 | 465 |
| 467 _GridLocation _getTrackLocationX(GridLayoutParams childLayout) { | 466 _GridLocation _getTrackLocationX(GridLayoutParams childLayout) { |
| 468 int start = childLayout.column - 1; | 467 int start = childLayout.column - 1; |
| 469 int end = start + childLayout.columnSpan - 1; | 468 int end = start + childLayout.columnSpan - 1; |
| 470 | 469 |
| 471 start = _columnTracks[start].start; | 470 start = _columnTracks[start].start; |
| 472 end = _columnTracks[end].end; | 471 end = _columnTracks[end].end; |
| 473 | 472 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 484 return new _GridLocation(start, end - start); | 483 return new _GridLocation(start, end - start); |
| 485 } | 484 } |
| 486 | 485 |
| 487 /** Gets the tracks that this item crosses. */ | 486 /** Gets the tracks that this item crosses. */ |
| 488 // TODO(jmesserly): might be better to return an iterable | 487 // TODO(jmesserly): might be better to return an iterable |
| 489 List<GridTrack> _getTracks(ViewLayout item) { | 488 List<GridTrack> _getTracks(ViewLayout item) { |
| 490 GridLayoutParams childLayout = item.layoutParams; | 489 GridLayoutParams childLayout = item.layoutParams; |
| 491 | 490 |
| 492 int start, span; | 491 int start, span; |
| 493 List<GridTrack> tracks; | 492 List<GridTrack> tracks; |
| 494 switch (_dimension) { | 493 if (_dimension == Dimension.WIDTH) { |
| 495 case Dimension.WIDTH: | 494 start = childLayout.column - 1; |
| 496 start = childLayout.column - 1; | 495 span = childLayout.columnSpan; |
| 497 span = childLayout.columnSpan; | 496 tracks = _columnTracks; |
| 498 tracks = _columnTracks; | 497 } else if (_dimension == Dimension.HEIGHT) { |
| 499 break; | 498 start = childLayout.row - 1; |
| 500 case Dimension.HEIGHT: | 499 span = childLayout.rowSpan; |
| 501 start = childLayout.row - 1; | 500 tracks = _rowTracks; |
| 502 span = childLayout.rowSpan; | |
| 503 tracks = _rowTracks; | |
| 504 } | 501 } |
| 505 | 502 |
| 506 assert(start >= 0 && span >= 1); | 503 assert(start >= 0 && span >= 1); |
| 507 | 504 |
| 508 final result = new List<GridTrack>(span); | 505 final result = new List<GridTrack>(span); |
| 509 for (int i = 0; i < span; i++) { | 506 for (int i = 0; i < span; i++) { |
| 510 result[i] = tracks[start + i]; | 507 result[i] = tracks[start + i]; |
| 511 } | 508 } |
| 512 return result; | 509 return result; |
| 513 } | 510 } |
| 514 | 511 |
| 515 int _getSpanCount(ViewLayout item) { | 512 int _getSpanCount(ViewLayout item) { |
| 516 GridLayoutParams childLayout = item.layoutParams; | 513 GridLayoutParams childLayout = item.layoutParams; |
| 517 return (_dimension == Dimension.WIDTH ? | 514 return (_dimension == Dimension.WIDTH ? |
| 518 childLayout.columnSpan : childLayout.rowSpan); | 515 childLayout.columnSpan : childLayout.rowSpan); |
| 519 } | 516 } |
| 520 } | 517 } |
| OLD | NEW |