| 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 * Caches the layout parameters that were specified in CSS during a layout | 6 * Caches the layout parameters that were specified in CSS during a layout |
| 7 * computation. These values are immutable during a layout. | 7 * computation. These values are immutable during a layout. |
| 8 */ | 8 */ |
| 9 // TODO(jmesserly): I would like all fields to be final, but it's too painful | 9 // TODO(jmesserly): I would like all fields to be final, but it's too painful |
| 10 // to do this right now in Dart. If I create a factory constructor, then I need | 10 // to do this right now in Dart. If I create a factory constructor, then I need |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 rowSpan = StringUtils.parseInt(view.customStyle['grid-row-span']); | 38 rowSpan = StringUtils.parseInt(view.customStyle['grid-row-span']); |
| 39 columnSpan = StringUtils.parseInt(view.customStyle['grid-column-span']); | 39 columnSpan = StringUtils.parseInt(view.customStyle['grid-column-span']); |
| 40 | 40 |
| 41 var line = _GridItemParser.parse( | 41 var line = _GridItemParser.parse( |
| 42 view.customStyle['grid-row'], layout.rows); | 42 view.customStyle['grid-row'], layout.rows); |
| 43 if (line != null) { | 43 if (line != null) { |
| 44 row = line.start; | 44 row = line.start; |
| 45 if (line.length != null) { | 45 if (line.length != null) { |
| 46 if (rowSpan != null) { | 46 if (rowSpan != null) { |
| 47 throw new UnsupportedOperationException( | 47 throw new StateError( |
| 48 'grid-row-span cannot be with grid-row that defines an end'); | 48 'grid-row-span cannot be with grid-row that defines an end'); |
| 49 } | 49 } |
| 50 rowSpan = line.length; | 50 rowSpan = line.length; |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 line = _GridItemParser.parse( | 54 line = _GridItemParser.parse( |
| 55 view.customStyle['grid-column'], layout.columns); | 55 view.customStyle['grid-column'], layout.columns); |
| 56 | 56 |
| 57 if (line != null) { | 57 if (line != null) { |
| 58 column = line.start; | 58 column = line.start; |
| 59 if (line.length != null) { | 59 if (line.length != null) { |
| 60 if (columnSpan != null) { | 60 if (columnSpan != null) { |
| 61 throw new UnsupportedOperationException( | 61 throw new StateError( |
| 62 'grid-column-span cannot be with grid-column that defines an end'); | 62 'grid-column-span cannot be with grid-column that defines an end'); |
| 63 } | 63 } |
| 64 columnSpan = line.length; | 64 columnSpan = line.length; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 String cell = _GridTemplateParser.parseCell(view.customStyle['grid-cell']); | 68 String cell = _GridTemplateParser.parseCell(view.customStyle['grid-cell']); |
| 69 if (cell != null && cell != 'none') { | 69 if (cell != null && cell != 'none') { |
| 70 // TODO(jmesserly): I didn't see anything spec'd about conflicts and | 70 // TODO(jmesserly): I didn't see anything spec'd about conflicts and |
| 71 // error handling. For now, throw an error on a misconfigured view. | 71 // error handling. For now, throw an error on a misconfigured view. |
| 72 // CSS is designed to be a permissive language, though, so we should do | 72 // CSS is designed to be a permissive language, though, so we should do |
| 73 // better and resolve conflicts more intelligently. | 73 // better and resolve conflicts more intelligently. |
| 74 if (row != null || column != null || | 74 if (row != null || column != null || |
| 75 rowSpan != null || columnSpan != null) { | 75 rowSpan != null || columnSpan != null) { |
| 76 throw new UnsupportedOperationException( | 76 throw new StateError( |
| 77 'grid-cell cannot be used with grid-row and grid-column'); | 77 'grid-cell cannot be used with grid-row and grid-column'); |
| 78 } | 78 } |
| 79 | 79 |
| 80 if (layout.template == null) { | 80 if (layout.template == null) { |
| 81 throw new UnsupportedOperationException( | 81 throw new StateError( |
| 82 'grid-cell requires that grid-template is set on the parent'); | 82 'grid-cell requires that grid-template is set on the parent'); |
| 83 } | 83 } |
| 84 | 84 |
| 85 final rect = layout.template.lookupCell(cell); | 85 final rect = layout.template.lookupCell(cell); |
| 86 row = rect.row; | 86 row = rect.row; |
| 87 column = rect.column; | 87 column = rect.column; |
| 88 rowSpan = rect.rowSpan; | 88 rowSpan = rect.rowSpan; |
| 89 columnSpan = rect.columnSpan; | 89 columnSpan = rect.columnSpan; |
| 90 | 90 |
| 91 } else { | 91 } else { |
| 92 // Apply default row, column span values. | 92 // Apply default row, column span values. |
| 93 if (rowSpan == null) rowSpan = 1; | 93 if (rowSpan == null) rowSpan = 1; |
| 94 if (columnSpan == null) columnSpan = 1; | 94 if (columnSpan == null) columnSpan = 1; |
| 95 | 95 |
| 96 if (row == null && column == null) { | 96 if (row == null && column == null) { |
| 97 throw new UnsupportedOperationException('grid-flow is not implemented' | 97 throw new StateError('grid-flow is not implemented' |
| 98 + ' so at least one row or one column must be defined'); | 98 + ' so at least one row or one column must be defined'); |
| 99 } | 99 } |
| 100 | 100 |
| 101 if (row == null) row = 1; | 101 if (row == null) row = 1; |
| 102 if (column == null) column = 1; | 102 if (column == null) column = 1; |
| 103 } | 103 } |
| 104 | 104 |
| 105 assert(row > 0 && rowSpan > 0 && column > 0 && columnSpan > 0); | 105 assert(row > 0 && rowSpan > 0 && column > 0 && columnSpan > 0); |
| 106 } | 106 } |
| 107 } | 107 } |
| OLD | NEW |