OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 |
11 * positioning. | 11 * positioning. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 | 88 |
89 int get currentWidth() => _gridWidth; | 89 int get currentWidth() => _gridWidth; |
90 int get currentHeight() => _gridHeight; | 90 int get currentHeight() => _gridHeight; |
91 | 91 |
92 void cacheExistingBrowserLayout() { | 92 void cacheExistingBrowserLayout() { |
93 // We don't need to do anything as we don't rely on the _cachedViewRect | 93 // We don't need to do anything as we don't rely on the _cachedViewRect |
94 // when the grid layout is used. | 94 // when the grid layout is used. |
95 } | 95 } |
96 | 96 |
97 // TODO(jacobr): cleanup this method so that it returns a Future | 97 // TODO(jacobr): cleanup this method so that it returns a Future |
98 // rather than taking a Completer as an argument. | 98 // rather than taking a Completer as an argument. |
arv (Not doing code reviews)
2012/01/17 20:25:00
Update TODO
Jacob
2012/01/21 03:01:25
Done.
| |
99 /** The main entry point for layout computation. */ | 99 /** The main entry point for layout computation. */ |
100 void measureLayout(Future<Size> size, Completer<bool> changed) { | 100 bool measureLayout(int width, int height) { |
101 assert(window.inMeasurementFrame); | |
101 _ensureAllTracks(); | 102 _ensureAllTracks(); |
102 window.requestLayoutFrame(() { | 103 _gridWidth = width; |
103 _gridWidth = size.value.width; | 104 _gridHeight = height; |
104 _gridHeight = size.value.height; | |
105 | 105 |
106 if (_rowTracks.length > 0 && _columnTracks.length > 0) { | 106 if (_rowTracks.length > 0 && _columnTracks.length > 0) { |
107 _measureTracks(); | 107 _measureTracks(); |
108 _setBoundsOfChildren(); | 108 _setBoundsOfChildren(); |
109 if (changed != null) { | 109 return true; |
110 changed.complete(true); | 110 } |
111 } | 111 return false; |
112 } | |
113 }); | |
114 } | 112 } |
115 | 113 |
116 /** | 114 /** |
117 * The top level measurement function. | 115 * The top level measurement function. |
118 * [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] |
119 */ | 117 */ |
120 void _measureTracks() { | 118 void _measureTracks() { |
121 // 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 |
122 // the width when determining the content-sized height. | 120 // the width when determining the content-sized height. |
123 try { | 121 try { |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 } | 509 } |
512 return result; | 510 return result; |
513 } | 511 } |
514 | 512 |
515 int _getSpanCount(ViewLayout item) { | 513 int _getSpanCount(ViewLayout item) { |
516 GridLayoutParams childLayout = item.layoutParams; | 514 GridLayoutParams childLayout = item.layoutParams; |
517 return (_dimension == Dimension.WIDTH ? | 515 return (_dimension == Dimension.WIDTH ? |
518 childLayout.columnSpan : childLayout.rowSpan); | 516 childLayout.columnSpan : childLayout.rowSpan); |
519 } | 517 } |
520 } | 518 } |
OLD | NEW |