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

Side by Side Diff: dart/samples/swarm/test/swarm_ui_lib/layout/grid_layout_demo.dart

Issue 66253002: Version 0.8.10.9 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 1 month 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
OLDNEW
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 = SwarmUri.parseQuery(window.location.search)['q']; 29 var query = SwarmUri.parsequerySelector(window.location.search)['q'];
30 if (query != null && query.length == 1) { 30 if (query != null && query.length == 1) {
31 query = SwarmUri.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) {
(...skipping 18 matching lines...) Expand all
58 border: solid 2px; 58 border: solid 2px;
59 border-radius: 8px; 59 border-radius: 8px;
60 font-family:monospace; 60 font-family:monospace;
61 font-size:16px; 61 font-size:16px;
62 line-height:20px; 62 line-height:20px;
63 } 63 }
64 '''); 64 ''');
65 } 65 }
66 66
67 void _addColorStyles() { 67 void _addColorStyles() {
68 final grid = document.body.query('#grid'); 68 final grid = document.body.querySelector('#grid');
69 final colors = const [ 'darkred', 'darkorange', 'darkgoldenrod', 69 final colors = const [ 'darkred', 'darkorange', 'darkgoldenrod',
70 'darkgreen', 'darkblue', 'darkviolet']; 70 'darkgreen', 'darkblue', 'darkviolet'];
71 int c = 0; 71 int c = 0;
72 var node = grid.children[0]; 72 var node = grid.children[0];
73 while (node != null) { 73 while (node != null) {
74 if (node.id != '') { 74 if (node.id != '') {
75 node.style.cssText += "color:" + colors[c++]; 75 node.style.cssText += "color:" + colors[c++];
76 } 76 }
77 node = node.nextElementSibling; 77 node = node.nextElementSibling;
78 } 78 }
(...skipping 17 matching lines...) Expand all
96 '<div class="grid-item">MockView-$id</div>')) { 96 '<div class="grid-item">MockView-$id</div>')) {
97 node.id = id; 97 node.id = id;
98 CollectionUtils.copyMap(customStyle, styles); 98 CollectionUtils.copyMap(customStyle, styles);
99 // TODO(jmesserly): this is needed to get horizontal content-sizing to work 99 // TODO(jmesserly): this is needed to get horizontal content-sizing to work
100 node.style.display = 'inline-block'; 100 node.style.display = 'inline-block';
101 } 101 }
102 } 102 }
103 103
104 104
105 void printMetrics(String example) { 105 void printMetrics(String example) {
106 final node = document.body.query('#grid'); 106 final node = document.body.querySelector('#grid');
107 String exampleId = example.split(' ')[0]; 107 String exampleId = example.split(' ')[0];
108 final sb = new StringBuffer(); 108 final sb = new StringBuffer();
109 sb.write("test('Spec Example $exampleId', () {\n"); 109 sb.write("test('Spec Example $exampleId', () {\n");
110 sb.write(" verifyExample('$example', {\n"); 110 sb.write(" verifyExample('$example', {\n");
111 final children = node.children; 111 final children = node.children;
112 112
113 scheduleMicrotask(() { 113 scheduleMicrotask(() {
114 for (int i = 0; i < children.length; i++) { 114 for (int i = 0; i < children.length; i++) {
115 _appendMetrics(sb, children[i], ' '); 115 _appendMetrics(sb, children[i], ' ');
116 } 116 }
117 sb.write(' });\n'); 117 sb.write(' });\n');
118 sb.write('});\n\n'); 118 sb.write('});\n\n');
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 }
OLDNEW
« no previous file with comments | « dart/samples/swarm/test/swarm_test.dart ('k') | dart/samples/swarm/test/swarm_ui_lib/layout/layout_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698