Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: client/layout/GridLayoutParams.dart

Issue 9382027: Move client/{base, observable, layout, touch, util, view} to samples/ui_lib . (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « client/layout/GridLayout.dart ('k') | client/layout/GridLayoutParser.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * Caches the layout parameters that were specified in CSS during a layout
7 * computation. These values are immutable during a layout.
8 */
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
11 // to create locals, and pass all parameters to the real constructor. Each
12 // field ends up being mentioned 4 times instead of just twice.
13 class GridLayoutParams extends LayoutParams {
14 /** The coordinates of this item in the grid. */
15 int row;
16 int column;
17 int rowSpan;
18 int columnSpan;
19 int layer;
20
21 /** Alignment within its box */
22 GridItemAlignment rowAlign;
23 GridItemAlignment columnAlign;
24
25 GridLayoutParams(Positionable view, GridLayout layout)
26 : super(view.node) {
27
28 // TODO(jmesserly): this can be cleaned up a lot by just passing "view"
29 // into the parsers.
30
31 rowAlign = new GridItemAlignment.fromString(
32 view.customStyle['grid-row-align']);
33 columnAlign = new GridItemAlignment.fromString(
34 view.customStyle['grid-column-align']);
35
36 layer = StringUtils.parseInt(view.customStyle['grid-layer'], 0);
37
38 rowSpan = StringUtils.parseInt(view.customStyle['grid-row-span']);
39 columnSpan = StringUtils.parseInt(view.customStyle['grid-column-span']);
40
41 var line = _GridItemParser.parse(
42 view.customStyle['grid-row'], layout.rows);
43 if (line != null) {
44 row = line.start;
45 if (line.length != null) {
46 if (rowSpan != null) {
47 throw new UnsupportedOperationException(
48 'grid-row-span cannot be with grid-row that defines an end');
49 }
50 rowSpan = line.length;
51 }
52 }
53
54 line = _GridItemParser.parse(
55 view.customStyle['grid-column'], layout.columns);
56
57 if (line != null) {
58 column = line.start;
59 if (line.length != null) {
60 if (columnSpan != null) {
61 throw new UnsupportedOperationException(
62 'grid-column-span cannot be with grid-column that defines an end');
63 }
64 columnSpan = line.length;
65 }
66 }
67
68 String cell = _GridTemplateParser.parseCell(view.customStyle['grid-cell']);
69 if (cell != null && cell != 'none') {
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.
72 // CSS is designed to be a permissive language, though, so we should do
73 // better and resolve conflicts more intelligently.
74 if (row != null || column != null ||
75 rowSpan != null || columnSpan != null) {
76 throw new UnsupportedOperationException(
77 'grid-cell cannot be used with grid-row and grid-column');
78 }
79
80 if (layout.template == null) {
81 throw new UnsupportedOperationException(
82 'grid-cell requires that grid-template is set on the parent');
83 }
84
85 final rect = layout.template.lookupCell(cell);
86 row = rect.row;
87 column = rect.column;
88 rowSpan = rect.rowSpan;
89 columnSpan = rect.columnSpan;
90
91 } else {
92 // Apply default row, column span values.
93 if (rowSpan == null) rowSpan = 1;
94 if (columnSpan == null) columnSpan = 1;
95
96 if (row == null && column == null) {
97 throw new UnsupportedOperationException('grid-flow is not implemented'
98 + ' so at least one row or one column must be defined');
99 }
100
101 if (row == null) row = 1;
102 if (column == null) column = 1;
103 }
104
105 assert(row > 0 && rowSpan > 0 && column > 0 && columnSpan > 0);
106 }
107 }
OLDNEW
« no previous file with comments | « client/layout/GridLayout.dart ('k') | client/layout/GridLayoutParser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698