Chromium Code Reviews| 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 | |
| 91 /** The main entry point for layout computation. */ | 97 /** The main entry point for layout computation. */ |
| 92 bool measureLayout(int width, int height) { | 98 void measureLayout(Future<Size> size, Completer<bool> changed) { |
|
nweiz
2011/10/28 03:58:38
Passing in a Completer seems wrong... isn't the pa
Jacob
2011/10/31 22:09:50
I agree this is a bit odd looking.
However, for th
nweiz
2011/11/01 00:49:22
I would argue that the correct pattern here is to
Jacob
2011/11/01 02:42:39
Btw, the bool value is required as the completer i
| |
| 93 _gridWidth = width; | 99 _ensureAllTracks(); |
| 94 _gridHeight = height; | 100 window.requestLayoutFrame(() { |
| 101 _gridWidth = size.value.width; | |
| 102 _gridHeight = size.value.height; | |
| 95 | 103 |
| 96 _ensureAllTracks(); | 104 if (_rowTracks.length > 0 && _columnTracks.length > 0) { |
| 97 | 105 _measureTracks(); |
| 98 if (_rowTracks.length < 1 || _columnTracks.length < 1) { | 106 _setBoundsOfChildren(); |
| 99 return false; // nothing to do | 107 if (null != changed) { |
| 100 } | 108 changed.complete(true); |
| 101 | 109 } |
| 102 _measureTracks(); | 110 } |
| 103 _setBoundsOfChildren(); | 111 }); |
| 104 return true; | |
| 105 } | 112 } |
| 106 | 113 |
| 107 /** | 114 /** |
| 108 * The top level measurement function. | 115 * The top level measurement function. |
| 109 * [http://dev.w3.org/csswg/css3-grid-align/#calculating-size-of-grid-tracks] | 116 * [http://dev.w3.org/csswg/css3-grid-align/#calculating-size-of-grid-tracks] |
| 110 */ | 117 */ |
| 111 void _measureTracks() { | 118 void _measureTracks() { |
| 112 // Resolve logical width, then height. Width comes first so we can use | 119 // Resolve logical width, then height. Width comes first so we can use |
| 113 // the width when determining the content-sized height. | 120 // the width when determining the content-sized height. |
| 114 try { | 121 try { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 void _ensureAllTracks() { | 418 void _ensureAllTracks() { |
| 412 final items = CollectionUtils.map(view.childViews, (view) => view.layout); | 419 final items = CollectionUtils.map(view.childViews, (view) => view.layout); |
| 413 | 420 |
| 414 for (final child in items) { | 421 for (final child in items) { |
| 415 if (child.layoutParams == null) { | 422 if (child.layoutParams == null) { |
| 416 final p = new GridLayoutParams(child.view, this); | 423 final p = new GridLayoutParams(child.view, this); |
| 417 _ensureTrack(_rowTracks, rowSizing, p.row, p.rowSpan); | 424 _ensureTrack(_rowTracks, rowSizing, p.row, p.rowSpan); |
| 418 _ensureTrack(_columnTracks, columnSizing, p.column, p.columnSpan); | 425 _ensureTrack(_columnTracks, columnSizing, p.column, p.columnSpan); |
| 419 child.layoutParams = p; | 426 child.layoutParams = p; |
| 420 } | 427 } |
| 428 child.cacheExistingBrowserLayout(); | |
| 421 } | 429 } |
| 422 } | 430 } |
| 423 | 431 |
| 424 /** | 432 /** |
| 425 * Given the track sizes that were computed, position children in the grid. | 433 * Given the track sizes that were computed, position children in the grid. |
| 426 */ | 434 */ |
| 427 void _setBoundsOfChildren() { | 435 void _setBoundsOfChildren() { |
| 428 final items = CollectionUtils.map(view.childViews, (view) => view.layout); | 436 final items = CollectionUtils.map(view.childViews, (view) => view.layout); |
| 429 | 437 |
| 430 for (final item in items) { | 438 for (final item in items) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 } | 509 } |
| 502 return result; | 510 return result; |
| 503 } | 511 } |
| 504 | 512 |
| 505 int _getSpanCount(ViewLayout item) { | 513 int _getSpanCount(ViewLayout item) { |
| 506 GridLayoutParams childLayout = item.layoutParams; | 514 GridLayoutParams childLayout = item.layoutParams; |
| 507 return (_dimension == Dimension.WIDTH ? | 515 return (_dimension == Dimension.WIDTH ? |
| 508 childLayout.columnSpan : childLayout.rowSpan); | 516 childLayout.columnSpan : childLayout.rowSpan); |
| 509 } | 517 } |
| 510 } | 518 } |
| OLD | NEW |