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 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.querySelector('#grid'); | 68 final grid = document.body.querySelector('#grid'); |
69 final colors = const [ 'darkred', 'darkorange', 'darkgoldenrod', | 69 final colors = const [ |
70 'darkgreen', 'darkblue', 'darkviolet']; | 70 'darkred', |
| 71 'darkorange', |
| 72 'darkgoldenrod', |
| 73 'darkgreen', |
| 74 'darkblue', |
| 75 'darkviolet' |
| 76 ]; |
71 int c = 0; | 77 int c = 0; |
72 var node = grid.children[0]; | 78 var node = grid.children[0]; |
73 while (node != null) { | 79 while (node != null) { |
74 if (node.id != '') { | 80 if (node.id != '') { |
75 node.style.cssText += "color:" + colors[c++]; | 81 node.style.cssText += "color:" + colors[c++]; |
76 } | 82 } |
77 node = node.nextElementSibling; | 83 node = node.nextElementSibling; |
78 } | 84 } |
79 } | 85 } |
80 | 86 |
81 class MockCompositeView extends CompositeView { | 87 class MockCompositeView extends CompositeView { |
82 MockCompositeView(String id, Map styles, List childViews) | 88 MockCompositeView(String id, Map styles, List childViews) : super('') { |
83 : super('') { | |
84 node.id = id; | 89 node.id = id; |
85 CollectionUtils.copyMap(customStyle, styles); | 90 CollectionUtils.copyMap(customStyle, styles); |
86 | 91 |
87 for (final v in childViews) { | 92 for (final v in childViews) { |
88 addChild(v); | 93 addChild(v); |
89 } | 94 } |
90 } | 95 } |
91 } | 96 } |
92 | 97 |
93 class MockView extends View { | 98 class MockView extends View { |
94 MockView(String id, Map styles) | 99 MockView(String id, Map styles) |
95 : super.fromNode(new Element.html( | 100 : super.fromNode( |
96 '<div class="grid-item">MockView-$id</div>')) { | 101 new Element.html('<div class="grid-item">MockView-$id</div>')) { |
97 node.id = id; | 102 node.id = id; |
98 CollectionUtils.copyMap(customStyle, styles); | 103 CollectionUtils.copyMap(customStyle, styles); |
99 // TODO(jmesserly): this is needed to get horizontal content-sizing to work | 104 // TODO(jmesserly): this is needed to get horizontal content-sizing to work |
100 node.style.display = 'inline-block'; | 105 node.style.display = 'inline-block'; |
101 } | 106 } |
102 } | 107 } |
103 | 108 |
104 | |
105 void printMetrics(String example) { | 109 void printMetrics(String example) { |
106 final node = document.body.querySelector('#grid'); | 110 final node = document.body.querySelector('#grid'); |
107 String exampleId = example.split(' ')[0]; | 111 String exampleId = example.split(' ')[0]; |
108 final sb = new StringBuffer(); | 112 final sb = new StringBuffer(); |
109 sb.write("test('Spec Example $exampleId', () {\n"); | 113 sb.write("test('Spec Example $exampleId', () {\n"); |
110 sb.write(" verifyExample('$example', {\n"); | 114 sb.write(" verifyExample('$example', {\n"); |
111 final children = node.children; | 115 final children = node.children; |
112 | 116 |
113 scheduleMicrotask(() { | 117 scheduleMicrotask(() { |
114 for (int i = 0; i < children.length; i++) { | 118 for (int i = 0; i < children.length; i++) { |
115 _appendMetrics(sb, children[i], ' '); | 119 _appendMetrics(sb, children[i], ' '); |
116 } | 120 } |
117 sb.write(' });\n'); | 121 sb.write(' });\n'); |
118 sb.write('});\n\n'); | 122 sb.write('});\n\n'); |
119 window.console.log(sb.toString()); | 123 window.console.log(sb.toString()); |
120 }); | 124 }); |
121 } | 125 } |
122 | 126 |
123 void _appendMetrics(StringBuffer sb, Element node, [String indent = '']) { | 127 void _appendMetrics(StringBuffer sb, Element node, [String indent = '']) { |
124 String id = node.id; | 128 String id = node.id; |
125 num left = node.offsetLeft, top = node.offsetTop; | 129 num left = node.offsetLeft, top = node.offsetTop; |
126 num width = node.offsetWidth, height = node.offsetHeight; | 130 num width = node.offsetWidth, height = node.offsetHeight; |
127 sb.write("${indent}'$id': [$left, $top, $width, $height],\n"); | 131 sb.write("${indent}'$id': [$left, $top, $width, $height],\n"); |
128 } | 132 } |
OLD | NEW |