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 part of layout; | 5 part of layout; |
6 | 6 |
7 /** | 7 /** |
8 * Caches the layout parameters that were specified in CSS during a layout | 8 * Caches the layout parameters that were specified in CSS during a layout |
9 * computation. These values are immutable during a layout. | 9 * computation. These values are immutable during a layout. |
10 */ | 10 */ |
11 // TODO(jmesserly): I would like all fields to be final, but it's too painful | 11 // TODO(jmesserly): I would like all fields to be final, but it's too painful |
12 // to do this right now in Dart. If I create a factory constructor, then I need | 12 // to do this right now in Dart. If I create a factory constructor, then I need |
13 // to create locals, and pass all parameters to the real constructor. Each | 13 // to create locals, and pass all parameters to the real constructor. Each |
14 // field ends up being mentioned 4 times instead of just twice. | 14 // field ends up being mentioned 4 times instead of just twice. |
15 class GridLayoutParams extends LayoutParams { | 15 class GridLayoutParams extends LayoutParams { |
16 /** The coordinates of this item in the grid. */ | 16 /** The coordinates of this item in the grid. */ |
17 int row; | 17 int row; |
18 int column; | 18 int column; |
19 int rowSpan; | 19 int rowSpan; |
20 int columnSpan; | 20 int columnSpan; |
21 int layer; | 21 int layer; |
22 | 22 |
23 /** Alignment within its box */ | 23 /** Alignment within its box */ |
24 GridItemAlignment rowAlign; | 24 GridItemAlignment rowAlign; |
25 GridItemAlignment columnAlign; | 25 GridItemAlignment columnAlign; |
26 | 26 |
27 GridLayoutParams(Positionable view, GridLayout layout) | 27 GridLayoutParams(Positionable view, GridLayout layout) : super(view.node) { |
28 : super(view.node) { | |
29 | |
30 // TODO(jmesserly): this can be cleaned up a lot by just passing "view" | 28 // TODO(jmesserly): this can be cleaned up a lot by just passing "view" |
31 // into the parsers. | 29 // into the parsers. |
32 | 30 |
33 rowAlign = new GridItemAlignment.fromString( | 31 rowAlign = |
34 view.customStyle['grid-row-align']); | 32 new GridItemAlignment.fromString(view.customStyle['grid-row-align']); |
35 columnAlign = new GridItemAlignment.fromString( | 33 columnAlign = |
36 view.customStyle['grid-column-align']); | 34 new GridItemAlignment.fromString(view.customStyle['grid-column-align']); |
37 | 35 |
38 layer = StringUtils.parseInt(view.customStyle['grid-layer'], 0); | 36 layer = StringUtils.parseInt(view.customStyle['grid-layer'], 0); |
39 | 37 |
40 rowSpan = StringUtils.parseInt(view.customStyle['grid-row-span']); | 38 rowSpan = StringUtils.parseInt(view.customStyle['grid-row-span']); |
41 columnSpan = StringUtils.parseInt(view.customStyle['grid-column-span']); | 39 columnSpan = StringUtils.parseInt(view.customStyle['grid-column-span']); |
42 | 40 |
43 var line = _GridItemParser.parse( | 41 var line = _GridItemParser.parse(view.customStyle['grid-row'], layout.rows); |
44 view.customStyle['grid-row'], layout.rows); | |
45 if (line != null) { | 42 if (line != null) { |
46 row = line.start; | 43 row = line.start; |
47 if (line.length != null) { | 44 if (line.length != null) { |
48 if (rowSpan != null) { | 45 if (rowSpan != null) { |
49 throw new UnsupportedError( | 46 throw new UnsupportedError( |
50 'grid-row-span cannot be with grid-row that defines an end'); | 47 'grid-row-span cannot be with grid-row that defines an end'); |
51 } | 48 } |
52 rowSpan = line.length; | 49 rowSpan = line.length; |
53 } | 50 } |
54 } | 51 } |
55 | 52 |
56 line = _GridItemParser.parse( | 53 line = |
57 view.customStyle['grid-column'], layout.columns); | 54 _GridItemParser.parse(view.customStyle['grid-column'], layout.columns); |
58 | 55 |
59 if (line != null) { | 56 if (line != null) { |
60 column = line.start; | 57 column = line.start; |
61 if (line.length != null) { | 58 if (line.length != null) { |
62 if (columnSpan != null) { | 59 if (columnSpan != null) { |
63 throw new UnsupportedError( | 60 throw new UnsupportedError( |
64 'grid-column-span cannot be with grid-column that defines an end'); | 61 'grid-column-span cannot be with grid-column that defines an end')
; |
65 } | 62 } |
66 columnSpan = line.length; | 63 columnSpan = line.length; |
67 } | 64 } |
68 } | 65 } |
69 | 66 |
70 String cell = _GridTemplateParser.parseCell(view.customStyle['grid-cell']); | 67 String cell = _GridTemplateParser.parseCell(view.customStyle['grid-cell']); |
71 if (cell != null && cell != 'none') { | 68 if (cell != null && cell != 'none') { |
72 // TODO(jmesserly): I didn't see anything spec'd about conflicts and | 69 // TODO(jmesserly): I didn't see anything spec'd about conflicts and |
73 // error handling. For now, throw an error on a misconfigured view. | 70 // error handling. For now, throw an error on a misconfigured view. |
74 // CSS is designed to be a permissive language, though, so we should do | 71 // CSS is designed to be a permissive language, though, so we should do |
75 // better and resolve conflicts more intelligently. | 72 // better and resolve conflicts more intelligently. |
76 if (row != null || column != null || | 73 if (row != null || |
77 rowSpan != null || columnSpan != null) { | 74 column != null || |
| 75 rowSpan != null || |
| 76 columnSpan != null) { |
78 throw new UnsupportedError( | 77 throw new UnsupportedError( |
79 'grid-cell cannot be used with grid-row and grid-column'); | 78 'grid-cell cannot be used with grid-row and grid-column'); |
80 } | 79 } |
81 | 80 |
82 if (layout.template == null) { | 81 if (layout.template == null) { |
83 throw new UnsupportedError( | 82 throw new UnsupportedError( |
84 'grid-cell requires that grid-template is set on the parent'); | 83 'grid-cell requires that grid-template is set on the parent'); |
85 } | 84 } |
86 | 85 |
87 final rect = layout.template.lookupCell(cell); | 86 final rect = layout.template.lookupCell(cell); |
88 row = rect.row; | 87 row = rect.row; |
89 column = rect.column; | 88 column = rect.column; |
90 rowSpan = rect.rowSpan; | 89 rowSpan = rect.rowSpan; |
91 columnSpan = rect.columnSpan; | 90 columnSpan = rect.columnSpan; |
92 | |
93 } else { | 91 } else { |
94 // Apply default row, column span values. | 92 // Apply default row, column span values. |
95 if (rowSpan == null) rowSpan = 1; | 93 if (rowSpan == null) rowSpan = 1; |
96 if (columnSpan == null) columnSpan = 1; | 94 if (columnSpan == null) columnSpan = 1; |
97 | 95 |
98 if (row == null && column == null) { | 96 if (row == null && column == null) { |
99 throw new UnsupportedError('grid-flow is not implemented' | 97 throw new UnsupportedError('grid-flow is not implemented' + |
100 + ' so at least one row or one column must be defined'); | 98 ' so at least one row or one column must be defined'); |
101 } | 99 } |
102 | 100 |
103 if (row == null) row = 1; | 101 if (row == null) row = 1; |
104 if (column == null) column = 1; | 102 if (column == null) column = 1; |
105 } | 103 } |
106 | 104 |
107 assert(row > 0 && rowSpan > 0 && column > 0 && columnSpan > 0); | 105 assert(row > 0 && rowSpan > 0 && column > 0 && columnSpan > 0); |
108 } | 106 } |
109 } | 107 } |
OLD | NEW |