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

Side by Side Diff: sky/sdk/lib/widgets/basic.dart

Issue 1190793002: Rename UINode to Widget. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « sky/sdk/lib/editing2/input.dart ('k') | sky/sdk/lib/widgets/button_base.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'package:vector_math/vector_math.dart'; 5 import 'package:vector_math/vector_math.dart';
6 6
7 import '../rendering/block.dart'; 7 import '../rendering/block.dart';
8 import '../rendering/box.dart'; 8 import '../rendering/box.dart';
9 import '../rendering/flex.dart'; 9 import '../rendering/flex.dart';
10 import '../rendering/object.dart'; 10 import '../rendering/object.dart';
11 import '../rendering/paragraph.dart'; 11 import '../rendering/paragraph.dart';
12 import '../rendering/stack.dart'; 12 import '../rendering/stack.dart';
13 import 'ui_node.dart'; 13 import 'widget.dart';
14 14
15 export '../rendering/box.dart' show BoxConstraints, BoxDecoration, Border, Borde rSide, EdgeDims; 15 export '../rendering/box.dart' show BoxConstraints, BoxDecoration, Border, Borde rSide, EdgeDims;
16 export '../rendering/flex.dart' show FlexDirection, FlexJustifyContent, FlexAlig nItems; 16 export '../rendering/flex.dart' show FlexDirection, FlexJustifyContent, FlexAlig nItems;
17 export '../rendering/object.dart' show Point, Size, Rect, Color, Paint, Path; 17 export '../rendering/object.dart' show Point, Size, Rect, Color, Paint, Path;
18 export 'ui_node.dart' show UINode, Component, App, EventListenerNode, ParentData Node; 18 export 'widget.dart' show Widget, Component, App, EventListenerNode, ParentDataN ode;
19 19
20 20
21 // PAINTING NODES 21 // PAINTING NODES
22 22
23 class Opacity extends OneChildRenderObjectWrapper { 23 class Opacity extends OneChildRenderObjectWrapper {
24 Opacity({ String key, this.opacity, UINode child }) 24 Opacity({ String key, this.opacity, Widget child })
25 : super(key: key, child: child); 25 : super(key: key, child: child);
26 26
27 RenderOpacity get root => super.root; 27 RenderOpacity get root => super.root;
28 final double opacity; 28 final double opacity;
29 29
30 RenderOpacity createNode() => new RenderOpacity(opacity: opacity); 30 RenderOpacity createNode() => new RenderOpacity(opacity: opacity);
31 31
32 void syncRenderObject(Opacity old) { 32 void syncRenderObject(Opacity old) {
33 super.syncRenderObject(old); 33 super.syncRenderObject(old);
34 root.opacity = opacity; 34 root.opacity = opacity;
35 } 35 }
36 } 36 }
37 37
38 class DecoratedBox extends OneChildRenderObjectWrapper { 38 class DecoratedBox extends OneChildRenderObjectWrapper {
39 39
40 DecoratedBox({ String key, this.decoration, UINode child }) 40 DecoratedBox({ String key, this.decoration, Widget child })
41 : super(key: key, child: child); 41 : super(key: key, child: child);
42 42
43 RenderDecoratedBox get root => super.root; 43 RenderDecoratedBox get root => super.root;
44 final BoxDecoration decoration; 44 final BoxDecoration decoration;
45 45
46 RenderDecoratedBox createNode() => new RenderDecoratedBox(decoration: decorati on); 46 RenderDecoratedBox createNode() => new RenderDecoratedBox(decoration: decorati on);
47 47
48 void syncRenderObject(DecoratedBox old) { 48 void syncRenderObject(DecoratedBox old) {
49 super.syncRenderObject(old); 49 super.syncRenderObject(old);
50 root.decoration = decoration; 50 root.decoration = decoration;
51 } 51 }
52 52
53 } 53 }
54 54
55 class CustomPaint extends OneChildRenderObjectWrapper { 55 class CustomPaint extends OneChildRenderObjectWrapper {
56 56
57 CustomPaint({ String key, this.callback, this.token, UINode child }) 57 CustomPaint({ String key, this.callback, this.token, Widget child })
58 : super(key: key, child: child); 58 : super(key: key, child: child);
59 59
60 RenderCustomPaint get root => super.root; 60 RenderCustomPaint get root => super.root;
61 final CustomPaintCallback callback; 61 final CustomPaintCallback callback;
62 final dynamic token; // set this to be repainted automatically when the token changes 62 final dynamic token; // set this to be repainted automatically when the token changes
63 63
64 RenderCustomPaint createNode() => new RenderCustomPaint(callback: callback); 64 RenderCustomPaint createNode() => new RenderCustomPaint(callback: callback);
65 65
66 void syncRenderObject(CustomPaint old) { 66 void syncRenderObject(CustomPaint old) {
67 super.syncRenderObject(old); 67 super.syncRenderObject(old);
68 if (old != null && old.token != token) 68 if (old != null && old.token != token)
69 root.markNeedsPaint(); 69 root.markNeedsPaint();
70 root.callback = callback; 70 root.callback = callback;
71 } 71 }
72 72
73 void remove() { 73 void remove() {
74 root.callback = null; 74 root.callback = null;
75 super.remove(); 75 super.remove();
76 } 76 }
77 77
78 } 78 }
79 79
80 class ClipRect extends OneChildRenderObjectWrapper { 80 class ClipRect extends OneChildRenderObjectWrapper {
81 ClipRect({ String key, UINode child }) 81 ClipRect({ String key, Widget child })
82 : super(key: key, child: child); 82 : super(key: key, child: child);
83 83
84 RenderClipRect get root => super.root; 84 RenderClipRect get root => super.root;
85 RenderClipRect createNode() => new RenderClipRect(); 85 RenderClipRect createNode() => new RenderClipRect();
86 } 86 }
87 87
88 class ClipOval extends OneChildRenderObjectWrapper { 88 class ClipOval extends OneChildRenderObjectWrapper {
89 ClipOval({ String key, UINode child }) 89 ClipOval({ String key, Widget child })
90 : super(key: key, child: child); 90 : super(key: key, child: child);
91 91
92 RenderClipOval get root => super.root; 92 RenderClipOval get root => super.root;
93 RenderClipOval createNode() => new RenderClipOval(); 93 RenderClipOval createNode() => new RenderClipOval();
94 } 94 }
95 95
96 96
97 // POSITIONING AND SIZING NODES 97 // POSITIONING AND SIZING NODES
98 98
99 class Transform extends OneChildRenderObjectWrapper { 99 class Transform extends OneChildRenderObjectWrapper {
100 100
101 Transform({ String key, this.transform, UINode child }) 101 Transform({ String key, this.transform, Widget child })
102 : super(key: key, child: child); 102 : super(key: key, child: child);
103 103
104 RenderTransform get root => super.root; 104 RenderTransform get root => super.root;
105 final Matrix4 transform; 105 final Matrix4 transform;
106 106
107 RenderTransform createNode() => new RenderTransform(transform: transform); 107 RenderTransform createNode() => new RenderTransform(transform: transform);
108 108
109 void syncRenderObject(Transform old) { 109 void syncRenderObject(Transform old) {
110 super.syncRenderObject(old); 110 super.syncRenderObject(old);
111 root.transform = transform; 111 root.transform = transform;
112 } 112 }
113 113
114 } 114 }
115 115
116 class Padding extends OneChildRenderObjectWrapper { 116 class Padding extends OneChildRenderObjectWrapper {
117 117
118 Padding({ String key, this.padding, UINode child }) 118 Padding({ String key, this.padding, Widget child })
119 : super(key: key, child: child); 119 : super(key: key, child: child);
120 120
121 RenderPadding get root => super.root; 121 RenderPadding get root => super.root;
122 final EdgeDims padding; 122 final EdgeDims padding;
123 123
124 RenderPadding createNode() => new RenderPadding(padding: padding); 124 RenderPadding createNode() => new RenderPadding(padding: padding);
125 125
126 void syncRenderObject(Padding old) { 126 void syncRenderObject(Padding old) {
127 super.syncRenderObject(old); 127 super.syncRenderObject(old);
128 root.padding = padding; 128 root.padding = padding;
129 } 129 }
130 130
131 } 131 }
132 132
133 class Center extends OneChildRenderObjectWrapper { 133 class Center extends OneChildRenderObjectWrapper {
134 Center({ String key, UINode child }) 134 Center({ String key, Widget child })
135 : super(key: key, child: child); 135 : super(key: key, child: child);
136 136
137 RenderPositionedBox get root => super.root; 137 RenderPositionedBox get root => super.root;
138 RenderPositionedBox createNode() => new RenderPositionedBox(); 138 RenderPositionedBox createNode() => new RenderPositionedBox();
139 } 139 }
140 140
141 class SizedBox extends OneChildRenderObjectWrapper { 141 class SizedBox extends OneChildRenderObjectWrapper {
142 142
143 SizedBox({ 143 SizedBox({
144 String key, 144 String key,
145 this.width, 145 this.width,
146 this.height, 146 this.height,
147 UINode child 147 Widget child
148 }) : super(key: key, child: child); 148 }) : super(key: key, child: child);
149 149
150 RenderConstrainedBox get root => super.root; 150 RenderConstrainedBox get root => super.root;
151 151
152 final double width; 152 final double width;
153 final double height; 153 final double height;
154 154
155 RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstr aints: _additionalConstraints()); 155 RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstr aints: _additionalConstraints());
156 156
157 BoxConstraints _additionalConstraints() { 157 BoxConstraints _additionalConstraints() {
158 var result = const BoxConstraints(); 158 var result = const BoxConstraints();
159 if (width != null) 159 if (width != null)
160 result = result.applyWidth(width); 160 result = result.applyWidth(width);
161 if (height != null) 161 if (height != null)
162 result = result.applyHeight(height); 162 result = result.applyHeight(height);
163 return result; 163 return result;
164 } 164 }
165 165
166 void syncRenderObject(SizedBox old) { 166 void syncRenderObject(SizedBox old) {
167 super.syncRenderObject(old); 167 super.syncRenderObject(old);
168 root.additionalConstraints = _additionalConstraints(); 168 root.additionalConstraints = _additionalConstraints();
169 } 169 }
170 170
171 } 171 }
172 172
173 class ConstrainedBox extends OneChildRenderObjectWrapper { 173 class ConstrainedBox extends OneChildRenderObjectWrapper {
174 174
175 ConstrainedBox({ String key, this.constraints, UINode child }) 175 ConstrainedBox({ String key, this.constraints, Widget child })
176 : super(key: key, child: child); 176 : super(key: key, child: child);
177 177
178 RenderConstrainedBox get root => super.root; 178 RenderConstrainedBox get root => super.root;
179 179
180 final BoxConstraints constraints; 180 final BoxConstraints constraints;
181 181
182 RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstr aints: constraints); 182 RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstr aints: constraints);
183 183
184 void syncRenderObject(ConstrainedBox old) { 184 void syncRenderObject(ConstrainedBox old) {
185 super.syncRenderObject(old); 185 super.syncRenderObject(old);
186 root.additionalConstraints = constraints; 186 root.additionalConstraints = constraints;
187 } 187 }
188 188
189 } 189 }
190 190
191 class ShrinkWrapWidth extends OneChildRenderObjectWrapper { 191 class ShrinkWrapWidth extends OneChildRenderObjectWrapper {
192 ShrinkWrapWidth({ String key, UINode child }) 192 ShrinkWrapWidth({ String key, Widget child })
193 : super(key: key, child: child); 193 : super(key: key, child: child);
194 194
195 RenderShrinkWrapWidth get root => super.root; 195 RenderShrinkWrapWidth get root => super.root;
196 RenderShrinkWrapWidth createNode() => new RenderShrinkWrapWidth(); 196 RenderShrinkWrapWidth createNode() => new RenderShrinkWrapWidth();
197 } 197 }
198 198
199 class SizeObserver extends OneChildRenderObjectWrapper { 199 class SizeObserver extends OneChildRenderObjectWrapper {
200 200
201 SizeObserver({ String key, this.callback, UINode child }) 201 SizeObserver({ String key, this.callback, Widget child })
202 : super(key: key, child: child); 202 : super(key: key, child: child);
203 203
204 RenderSizeObserver get root => super.root; 204 RenderSizeObserver get root => super.root;
205 final SizeChangedCallback callback; 205 final SizeChangedCallback callback;
206 206
207 RenderSizeObserver createNode() => new RenderSizeObserver(callback: callback); 207 RenderSizeObserver createNode() => new RenderSizeObserver(callback: callback);
208 208
209 void syncRenderObject(SizeObserver old) { 209 void syncRenderObject(SizeObserver old) {
210 super.syncRenderObject(old); 210 super.syncRenderObject(old);
211 root.callback = callback; 211 root.callback = callback;
(...skipping 16 matching lines...) Expand all
228 this.child, 228 this.child,
229 this.constraints, 229 this.constraints,
230 this.decoration, 230 this.decoration,
231 this.width, 231 this.width,
232 this.height, 232 this.height,
233 this.margin, 233 this.margin,
234 this.padding, 234 this.padding,
235 this.transform 235 this.transform
236 }) : super(key: key); 236 }) : super(key: key);
237 237
238 final UINode child; 238 final Widget child;
239 final BoxConstraints constraints; 239 final BoxConstraints constraints;
240 final BoxDecoration decoration; 240 final BoxDecoration decoration;
241 final EdgeDims margin; 241 final EdgeDims margin;
242 final EdgeDims padding; 242 final EdgeDims padding;
243 final Matrix4 transform; 243 final Matrix4 transform;
244 final double width; 244 final double width;
245 final double height; 245 final double height;
246 246
247 UINode build() { 247 Widget build() {
248 UINode current = child; 248 Widget current = child;
249 249
250 if (child == null && width == null && height == null) 250 if (child == null && width == null && height == null)
251 current = new SizedBox( 251 current = new SizedBox(
252 width: double.INFINITY, 252 width: double.INFINITY,
253 height: double.INFINITY 253 height: double.INFINITY
254 ); 254 );
255 255
256 if (padding != null) 256 if (padding != null)
257 current = new Padding(padding: padding, child: current); 257 current = new Padding(padding: padding, child: current);
258 258
(...skipping 18 matching lines...) Expand all
277 277
278 return current; 278 return current;
279 } 279 }
280 280
281 } 281 }
282 282
283 283
284 // LAYOUT NODES 284 // LAYOUT NODES
285 285
286 class Block extends MultiChildRenderObjectWrapper { 286 class Block extends MultiChildRenderObjectWrapper {
287 Block(List<UINode> children, { String key }) 287 Block(List<Widget> children, { String key })
288 : super(key: key, children: children); 288 : super(key: key, children: children);
289 289
290 RenderBlock get root => super.root; 290 RenderBlock get root => super.root;
291 RenderBlock createNode() => new RenderBlock(); 291 RenderBlock createNode() => new RenderBlock();
292 } 292 }
293 293
294 class Stack extends MultiChildRenderObjectWrapper { 294 class Stack extends MultiChildRenderObjectWrapper {
295 Stack(List<UINode> children, { String key }) 295 Stack(List<Widget> children, { String key })
296 : super(key: key, children: children); 296 : super(key: key, children: children);
297 297
298 RenderStack get root => super.root; 298 RenderStack get root => super.root;
299 RenderStack createNode() => new RenderStack(); 299 RenderStack createNode() => new RenderStack();
300 } 300 }
301 301
302 class Positioned extends ParentDataNode { 302 class Positioned extends ParentDataNode {
303 Positioned({ 303 Positioned({
304 String key, 304 String key,
305 UINode child, 305 Widget child,
306 double top, 306 double top,
307 double right, 307 double right,
308 double bottom, 308 double bottom,
309 double left 309 double left
310 }) : super(child, 310 }) : super(child,
311 new StackParentData()..top = top 311 new StackParentData()..top = top
312 ..right = right 312 ..right = right
313 ..bottom = bottom 313 ..bottom = bottom
314 ..left = left, 314 ..left = left,
315 key: key); 315 key: key);
316 } 316 }
317 317
318 class Flex extends MultiChildRenderObjectWrapper { 318 class Flex extends MultiChildRenderObjectWrapper {
319 319
320 Flex(List<UINode> children, { 320 Flex(List<Widget> children, {
321 String key, 321 String key,
322 this.direction: FlexDirection.horizontal, 322 this.direction: FlexDirection.horizontal,
323 this.justifyContent: FlexJustifyContent.flexStart, 323 this.justifyContent: FlexJustifyContent.flexStart,
324 this.alignItems: FlexAlignItems.center 324 this.alignItems: FlexAlignItems.center
325 }) : super(key: key, children: children); 325 }) : super(key: key, children: children);
326 326
327 RenderFlex get root => super.root; 327 RenderFlex get root => super.root;
328 RenderFlex createNode() => new RenderFlex(direction: this.direction); 328 RenderFlex createNode() => new RenderFlex(direction: this.direction);
329 329
330 final FlexDirection direction; 330 final FlexDirection direction;
331 final FlexJustifyContent justifyContent; 331 final FlexJustifyContent justifyContent;
332 final FlexAlignItems alignItems; 332 final FlexAlignItems alignItems;
333 333
334 void syncRenderObject(UINode old) { 334 void syncRenderObject(Widget old) {
335 super.syncRenderObject(old); 335 super.syncRenderObject(old);
336 root.direction = direction; 336 root.direction = direction;
337 root.justifyContent = justifyContent; 337 root.justifyContent = justifyContent;
338 root.alignItems = alignItems; 338 root.alignItems = alignItems;
339 } 339 }
340 340
341 } 341 }
342 342
343 class Flexible extends ParentDataNode { 343 class Flexible extends ParentDataNode {
344 Flexible({ String key, UINode child, int flex: 1 }) 344 Flexible({ String key, Widget child, int flex: 1 })
345 : super(child, new FlexBoxParentData()..flex = flex, key: key); 345 : super(child, new FlexBoxParentData()..flex = flex, key: key);
346 } 346 }
347 347
348 class Paragraph extends RenderObjectWrapper { 348 class Paragraph extends RenderObjectWrapper {
349 349
350 Paragraph({ String key, this.text, this.style }) : super(key: key); 350 Paragraph({ String key, this.text, this.style }) : super(key: key);
351 351
352 RenderParagraph get root => super.root; 352 RenderParagraph get root => super.root;
353 RenderParagraph createNode() => new RenderParagraph(text: text, style: style); 353 RenderParagraph createNode() => new RenderParagraph(text: text, style: style);
354 354
355 final String text; 355 final String text;
356 final TextStyle style; 356 final TextStyle style;
357 357
358 void syncRenderObject(UINode old) { 358 void syncRenderObject(Widget old) {
359 super.syncRenderObject(old); 359 super.syncRenderObject(old);
360 root.text = text; 360 root.text = text;
361 root.style = style; 361 root.style = style;
362 } 362 }
363 363
364 void insert(RenderObjectWrapper child, dynamic slot) { 364 void insert(RenderObjectWrapper child, dynamic slot) {
365 assert(false); 365 assert(false);
366 // Paragraph does not support having children currently 366 // Paragraph does not support having children currently
367 } 367 }
368 368
369 } 369 }
370 370
371 class Text extends Component { 371 class Text extends Component {
372 Text(this.data, { TextStyle this.style }) : super(key: '*text*'); 372 Text(this.data, { TextStyle this.style }) : super(key: '*text*');
373 final String data; 373 final String data;
374 final TextStyle style; 374 final TextStyle style;
375 bool get interchangeable => true; 375 bool get interchangeable => true;
376 UINode build() => new Paragraph(text: data, style: style); 376 Widget build() => new Paragraph(text: data, style: style);
377 } 377 }
378 378
379 class Image extends RenderObjectWrapper { 379 class Image extends RenderObjectWrapper {
380 380
381 Image({ 381 Image({
382 String key, 382 String key,
383 this.src, 383 this.src,
384 this.size 384 this.size
385 }) : super(key: key); 385 }) : super(key: key);
386 386
387 RenderImage get root => super.root; 387 RenderImage get root => super.root;
388 RenderImage createNode() => new RenderImage(this.src, this.size); 388 RenderImage createNode() => new RenderImage(this.src, this.size);
389 389
390 final String src; 390 final String src;
391 final Size size; 391 final Size size;
392 392
393 void syncRenderObject(UINode old) { 393 void syncRenderObject(Widget old) {
394 super.syncRenderObject(old); 394 super.syncRenderObject(old);
395 root.src = src; 395 root.src = src;
396 root.requestedSize = size; 396 root.requestedSize = size;
397 } 397 }
398 398
399 void insert(RenderObjectWrapper child, dynamic slot) { 399 void insert(RenderObjectWrapper child, dynamic slot) {
400 assert(false); 400 assert(false);
401 // Image does not support having children currently 401 // Image does not support having children currently
402 } 402 }
403 403
404 } 404 }
405 405
406 class UINodeToRenderBoxAdapter extends RenderObjectWrapper { 406 class WidgetToRenderBoxAdapter extends RenderObjectWrapper {
407 407
408 UINodeToRenderBoxAdapter(RenderBox renderBox) 408 WidgetToRenderBoxAdapter(RenderBox renderBox)
409 : this.renderBox = renderBox, 409 : this.renderBox = renderBox,
410 super(key: renderBox.hashCode.toString()); 410 super(key: renderBox.hashCode.toString());
411 411
412 RenderBox get root => super.root; 412 RenderBox get root => super.root;
413 RenderBox createNode() => this.renderBox; 413 RenderBox createNode() => this.renderBox;
414 414
415 final RenderBox renderBox; 415 final RenderBox renderBox;
416 416
417 void syncRenderObject(UINode old) { 417 void syncRenderObject(Widget old) {
418 super.syncRenderObject(old); 418 super.syncRenderObject(old);
419 if (old != null) { 419 if (old != null) {
420 assert(old is UINodeToRenderBoxAdapter); 420 assert(old is WidgetToRenderBoxAdapter);
421 assert(root == old.renderBox); 421 assert(root == old.renderBox);
422 } 422 }
423 } 423 }
424 424
425 void insert(RenderObjectWrapper child, dynamic slot) { 425 void insert(RenderObjectWrapper child, dynamic slot) {
426 assert(false); 426 assert(false);
427 // UINodeToRenderBoxAdapter cannot have UINode children; by 427 // WidgetToRenderBoxAdapter cannot have Widget children; by
428 // definition, it is the transition out of the UINode world. 428 // definition, it is the transition out of the Widget world.
429 } 429 }
430 430
431 } 431 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/editing2/input.dart ('k') | sky/sdk/lib/widgets/button_base.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698