| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 rowSizing = _GridTrackParser.parseTrackSizing( | 78 rowSizing = _GridTrackParser.parseTrackSizing( |
| 79 view.customStyle['grid-row-sizing']), | 79 view.customStyle['grid-row-sizing']), |
| 80 | 80 |
| 81 columnSizing = _GridTrackParser.parseTrackSizing( | 81 columnSizing = _GridTrackParser.parseTrackSizing( |
| 82 view.customStyle['grid-column-sizing']) { | 82 view.customStyle['grid-column-sizing']) { |
| 83 | 83 |
| 84 _rowTracks = rows != null ? rows.tracks : new List<GridTrack>(); | 84 _rowTracks = rows != null ? rows.tracks : new List<GridTrack>(); |
| 85 _columnTracks = columns != null ? columns.tracks : new List<GridTrack>(); | 85 _columnTracks = columns != null ? columns.tracks : new List<GridTrack>(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 |
| 88 int get currentWidth() => _gridWidth; | 89 int get currentWidth() => _gridWidth; |
| 89 int get currentHeight() => _gridHeight; | 90 int get currentHeight() => _gridHeight; |
| 90 | 91 |
| 92 void cacheExistingBrowserLayout() { |
| 93 // We don't need to do anything as we don't rely on the _cachedViewRect |
| 94 // when the grid layout is used. |
| 95 } |
| 96 |
| 97 // TODO(jacobr): cleanup this method so that it returns a Future |
| 98 // rather than taking a Completer as an argument. |
| 91 /** The main entry point for layout computation. */ | 99 /** The main entry point for layout computation. */ |
| 92 bool measureLayout(int width, int height) { | 100 void measureLayout(Future<Size> size, Completer<bool> changed) { |
| 93 _gridWidth = width; | 101 _ensureAllTracks(); |
| 94 _gridHeight = height; | 102 window.requestLayoutFrame(() { |
| 103 _gridWidth = size.value.width; |
| 104 _gridHeight = size.value.height; |
| 95 | 105 |
| 96 _ensureAllTracks(); | 106 if (_rowTracks.length > 0 && _columnTracks.length > 0) { |
| 97 | 107 _measureTracks(); |
| 98 if (_rowTracks.length < 1 || _columnTracks.length < 1) { | 108 _setBoundsOfChildren(); |
| 99 return false; // nothing to do | 109 if (changed != null) { |
| 100 } | 110 changed.complete(true); |
| 101 | 111 } |
| 102 _measureTracks(); | 112 } |
| 103 _setBoundsOfChildren(); | 113 }); |
| 104 return true; | |
| 105 } | 114 } |
| 106 | 115 |
| 107 /** | 116 /** |
| 108 * The top level measurement function. | 117 * The top level measurement function. |
| 109 * [http://dev.w3.org/csswg/css3-grid-align/#calculating-size-of-grid-tracks] | 118 * [http://dev.w3.org/csswg/css3-grid-align/#calculating-size-of-grid-tracks] |
| 110 */ | 119 */ |
| 111 void _measureTracks() { | 120 void _measureTracks() { |
| 112 // Resolve logical width, then height. Width comes first so we can use | 121 // Resolve logical width, then height. Width comes first so we can use |
| 113 // the width when determining the content-sized height. | 122 // the width when determining the content-sized height. |
| 114 try { | 123 try { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 void _ensureAllTracks() { | 420 void _ensureAllTracks() { |
| 412 final items = CollectionUtils.map(view.childViews, (view) => view.layout); | 421 final items = CollectionUtils.map(view.childViews, (view) => view.layout); |
| 413 | 422 |
| 414 for (final child in items) { | 423 for (final child in items) { |
| 415 if (child.layoutParams == null) { | 424 if (child.layoutParams == null) { |
| 416 final p = new GridLayoutParams(child.view, this); | 425 final p = new GridLayoutParams(child.view, this); |
| 417 _ensureTrack(_rowTracks, rowSizing, p.row, p.rowSpan); | 426 _ensureTrack(_rowTracks, rowSizing, p.row, p.rowSpan); |
| 418 _ensureTrack(_columnTracks, columnSizing, p.column, p.columnSpan); | 427 _ensureTrack(_columnTracks, columnSizing, p.column, p.columnSpan); |
| 419 child.layoutParams = p; | 428 child.layoutParams = p; |
| 420 } | 429 } |
| 430 child.cacheExistingBrowserLayout(); |
| 421 } | 431 } |
| 422 } | 432 } |
| 423 | 433 |
| 424 /** | 434 /** |
| 425 * 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. |
| 426 */ | 436 */ |
| 427 void _setBoundsOfChildren() { | 437 void _setBoundsOfChildren() { |
| 428 final items = CollectionUtils.map(view.childViews, (view) => view.layout); | 438 final items = CollectionUtils.map(view.childViews, (view) => view.layout); |
| 429 | 439 |
| 430 for (final item in items) { | 440 for (final item in items) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 } | 511 } |
| 502 return result; | 512 return result; |
| 503 } | 513 } |
| 504 | 514 |
| 505 int _getSpanCount(ViewLayout item) { | 515 int _getSpanCount(ViewLayout item) { |
| 506 GridLayoutParams childLayout = item.layoutParams; | 516 GridLayoutParams childLayout = item.layoutParams; |
| 507 return (_dimension == Dimension.WIDTH ? | 517 return (_dimension == Dimension.WIDTH ? |
| 508 childLayout.columnSpan : childLayout.rowSpan); | 518 childLayout.columnSpan : childLayout.rowSpan); |
| 509 } | 519 } |
| 510 } | 520 } |
| OLD | NEW |