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_tests; | 5 part of layout_tests; |
6 | 6 |
7 /** | 7 /** |
8 * An app for testing the grid layout system. | 8 * An app for testing the grid layout system. |
9 */ | 9 */ |
10 | 10 |
11 /** Creates a grid view structure given the CSS styles. */ | 11 /** Creates a grid view structure given the CSS styles. */ |
12 View createGrid(Map<String, Map<String, String>> styles) { | 12 View createGrid(Map<String, Map<String, String>> styles) { |
13 final gridStyle = styles['#grid']; | 13 final gridStyle = styles['#grid']; |
14 | 14 |
15 final children = new List<MockView>(); | 15 final children = new List<MockView>(); |
16 for (final String id in styles.keys) { | 16 for (final String id in styles.keys) { |
17 // All selectors in this test are id selectors string the # prefix. | 17 // All selectors in this test are id selectors string the # prefix. |
18 assert(id.startsWith('#')); | 18 assert(id.startsWith('#')); |
19 String elemId = id.substring(1); | 19 String elemId = id.substring(1); |
20 if (elemId != 'grid') { | 20 if (elemId != 'grid') { |
21 children.add(new MockView(elemId, styles[id])); | 21 children.add(new MockView(elemId, styles[id])); |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 return new MockCompositeView('grid', gridStyle, children); | 25 return new MockCompositeView('grid', gridStyle, children); |
26 } | 26 } |
27 | 27 |
28 void _onLoad() { | 28 void _onLoad() { |
29 var query = Uri.parseQuery(window.location.search)['q']; | 29 var query = SwarmUri.parseQuery(window.location.search)['q']; |
30 if (query != null && query.length == 1) { | 30 if (query != null && query.length == 1) { |
31 query = Uri.decodeComponent(query[0]); | 31 query = SwarmUri.decodeComponent(query[0]); |
32 addGridStyles('100%', '100%', 'margin:0px;'); | 32 addGridStyles('100%', '100%', 'margin:0px;'); |
33 final view = createGrid(GridExamples.styles[query]); | 33 final view = createGrid(GridExamples.styles[query]); |
34 view.addToDocument(document.body); | 34 view.addToDocument(document.body); |
35 _addColorStyles(); | 35 _addColorStyles(); |
36 printMetrics(query); | 36 printMetrics(query); |
37 } else { | 37 } else { |
38 final html = new StringBuffer(); | 38 final html = new StringBuffer(); |
39 for (String ex in GridExamples.styles.keys) { | 39 for (String ex in GridExamples.styles.keys) { |
40 html.write('<div><a href="?q=$ex">Grid Example $ex</a></div>'); | 40 html.write('<div><a href="?q=$ex">Grid Example $ex</a></div>'); |
41 } | 41 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 window.console.log(sb.toString()); | 119 window.console.log(sb.toString()); |
120 }); | 120 }); |
121 } | 121 } |
122 | 122 |
123 void _appendMetrics(StringBuffer sb, Element node, [String indent = '']) { | 123 void _appendMetrics(StringBuffer sb, Element node, [String indent = '']) { |
124 String id = node.id; | 124 String id = node.id; |
125 num left = node.offsetLeft, top = node.offsetTop; | 125 num left = node.offsetLeft, top = node.offsetTop; |
126 num width = node.offsetWidth, height = node.offsetHeight; | 126 num width = node.offsetWidth, height = node.offsetHeight; |
127 sb.write("${indent}'$id': [$left, $top, $width, $height],\n"); | 127 sb.write("${indent}'$id': [$left, $top, $width, $height],\n"); |
128 } | 128 } |
OLD | NEW |