| OLD | NEW |
| 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 'dart:math' as math; | 5 import 'dart:math' as math; |
| 6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 import 'object.dart'; | 8 import 'object.dart'; |
| 9 import 'package:vector_math/vector_math.dart'; | 9 import 'package:vector_math/vector_math.dart'; |
| 10 import 'package:sky/framework/net/image_cache.dart' as image_cache; | 10 import 'package:sky/framework/net/image_cache.dart' as image_cache; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 value = 37 * value + maxWidth.hashCode; | 102 value = 37 * value + maxWidth.hashCode; |
| 103 value = 37 * value + minHeight.hashCode; | 103 value = 37 * value + minHeight.hashCode; |
| 104 value = 37 * value + maxHeight.hashCode; | 104 value = 37 * value + maxHeight.hashCode; |
| 105 return value; | 105 return value; |
| 106 } | 106 } |
| 107 String toString() => "BoxConstraints($minWidth<=w<$maxWidth, $minHeight<=h<$ma
xHeight)"; | 107 String toString() => "BoxConstraints($minWidth<=w<$maxWidth, $minHeight<=h<$ma
xHeight)"; |
| 108 } | 108 } |
| 109 | 109 |
| 110 class BoxParentData extends ParentData { | 110 class BoxParentData extends ParentData { |
| 111 sky.Point position = new sky.Point(0.0, 0.0); | 111 sky.Point position = new sky.Point(0.0, 0.0); |
| 112 String toString() => 'position=$position'; |
| 112 } | 113 } |
| 113 | 114 |
| 114 abstract class RenderBox extends RenderObject { | 115 abstract class RenderBox extends RenderObject { |
| 115 | 116 |
| 116 void setParentData(RenderObject child) { | 117 void setParentData(RenderObject child) { |
| 117 if (child.parentData is! BoxParentData) | 118 if (child.parentData is! BoxParentData) |
| 118 child.parentData = new BoxParentData(); | 119 child.parentData = new BoxParentData(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 // override this to report what dimensions you would have if you | 122 // override this to report what dimensions you would have if you |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 207 |
| 207 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { | 208 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 208 return constraints.constrain(_desiredSize); | 209 return constraints.constrain(_desiredSize); |
| 209 } | 210 } |
| 210 | 211 |
| 211 void performLayout() { | 212 void performLayout() { |
| 212 size = constraints.constrain(_desiredSize); | 213 size = constraints.constrain(_desiredSize); |
| 213 if (child != null) | 214 if (child != null) |
| 214 child.layout(new BoxConstraints.tight(size)); | 215 child.layout(new BoxConstraints.tight(size)); |
| 215 } | 216 } |
| 217 |
| 218 String debugDescribeSettings(String prefix) => '${prefix}desiredSize: ${desire
dSize}'; |
| 216 } | 219 } |
| 217 | 220 |
| 218 class RenderClip extends RenderProxyBox { | 221 class RenderClip extends RenderProxyBox { |
| 219 RenderClip({ RenderBox child }) : super(child); | 222 RenderClip({ RenderBox child }) : super(child); |
| 220 | 223 |
| 221 void paint(RenderObjectDisplayList canvas) { | 224 void paint(RenderObjectDisplayList canvas) { |
| 222 if (child != null) { | 225 if (child != null) { |
| 223 canvas.save(); | 226 canvas.save(); |
| 224 canvas.clipRect(new sky.Rect.fromSize(size)); | 227 canvas.clipRect(new sky.Rect.fromSize(size)); |
| 225 child.paint(canvas); | 228 child.paint(canvas); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 if (child != null) { | 281 if (child != null) { |
| 279 assert(child.parentData is BoxParentData); | 282 assert(child.parentData is BoxParentData); |
| 280 sky.Rect childBounds = new sky.Rect.fromPointAndSize(child.parentData.posi
tion, child.size); | 283 sky.Rect childBounds = new sky.Rect.fromPointAndSize(child.parentData.posi
tion, child.size); |
| 281 if (childBounds.contains(position)) { | 284 if (childBounds.contains(position)) { |
| 282 child.hitTest(result, position: new sky.Point(position.x - child.parentD
ata.position.x, | 285 child.hitTest(result, position: new sky.Point(position.x - child.parentD
ata.position.x, |
| 283 position.y - child.parentD
ata.position.y)); | 286 position.y - child.parentD
ata.position.y)); |
| 284 } | 287 } |
| 285 } | 288 } |
| 286 } | 289 } |
| 287 | 290 |
| 291 String debugDescribeSettings(String prefix) => '${prefix}padding: ${padding}'; |
| 288 } | 292 } |
| 289 | 293 |
| 290 class RenderImage extends RenderBox { | 294 class RenderImage extends RenderBox { |
| 291 | 295 |
| 292 RenderImage(String url, sky.Size dimensions) { | 296 RenderImage(String url, sky.Size dimensions) { |
| 293 requestedSize = dimensions; | 297 requestedSize = dimensions; |
| 294 src = url; | 298 src = url; |
| 295 } | 299 } |
| 296 | 300 |
| 297 sky.Image _image; | 301 sky.Image _image; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 double widthScale = size.width / _image.width; | 356 double widthScale = size.width / _image.width; |
| 353 double heightScale = size.height / _image.height; | 357 double heightScale = size.height / _image.height; |
| 354 canvas.save(); | 358 canvas.save(); |
| 355 canvas.scale(widthScale, heightScale); | 359 canvas.scale(widthScale, heightScale); |
| 356 } | 360 } |
| 357 sky.Paint paint = new sky.Paint(); | 361 sky.Paint paint = new sky.Paint(); |
| 358 canvas.drawImage(_image, 0.0, 0.0, paint); | 362 canvas.drawImage(_image, 0.0, 0.0, paint); |
| 359 if (needsScale) | 363 if (needsScale) |
| 360 canvas.restore(); | 364 canvas.restore(); |
| 361 } | 365 } |
| 366 |
| 367 String debugDescribeSettings(String prefix) => '${prefix}url: ${src}\n${prefix
}dimensions: ${requestedSize}'; |
| 362 } | 368 } |
| 363 | 369 |
| 364 class BorderSide { | 370 class BorderSide { |
| 365 const BorderSide({ | 371 const BorderSide({ |
| 366 this.color: const sky.Color(0xFF000000), | 372 this.color: const sky.Color(0xFF000000), |
| 367 this.width: 1.0 | 373 this.width: 1.0 |
| 368 }); | 374 }); |
| 369 final sky.Color color; | 375 final sky.Color color; |
| 370 final double width; | 376 final double width; |
| 371 | 377 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 416 |
| 411 // This must be immutable, because we won't notice when it changes | 417 // This must be immutable, because we won't notice when it changes |
| 412 class BoxDecoration { | 418 class BoxDecoration { |
| 413 const BoxDecoration({ | 419 const BoxDecoration({ |
| 414 this.backgroundColor, | 420 this.backgroundColor, |
| 415 this.border | 421 this.border |
| 416 }); | 422 }); |
| 417 | 423 |
| 418 final sky.Color backgroundColor; | 424 final sky.Color backgroundColor; |
| 419 final Border border; | 425 final Border border; |
| 426 |
| 427 String toString([String prefix = '']) { |
| 428 List<String> result = []; |
| 429 if (backgroundColor != null) |
| 430 result.add('${prefix}backgroundColor: $backgroundColor'); |
| 431 if (border != null) |
| 432 result.add('${prefix}border: $border'); |
| 433 if (result.isEmpty) |
| 434 return '${prefix}<no decorations specified>'; |
| 435 return result.join('\n'); |
| 436 } |
| 420 } | 437 } |
| 421 | 438 |
| 422 class RenderDecoratedBox extends RenderProxyBox { | 439 class RenderDecoratedBox extends RenderProxyBox { |
| 423 | 440 |
| 424 RenderDecoratedBox({ | 441 RenderDecoratedBox({ |
| 425 BoxDecoration decoration, | 442 BoxDecoration decoration, |
| 426 RenderBox child | 443 RenderBox child |
| 427 }) : _decoration = decoration, super(child) { | 444 }) : _decoration = decoration, super(child) { |
| 428 assert(_decoration != null); | 445 assert(_decoration != null); |
| 429 } | 446 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 path.moveTo(0.0, size.height); | 505 path.moveTo(0.0, size.height); |
| 489 path.lineTo(_decoration.border.left.width, size.height - _decoration.borde
r.bottom.width); | 506 path.lineTo(_decoration.border.left.width, size.height - _decoration.borde
r.bottom.width); |
| 490 path.lineTo(_decoration.border.left.width, _decoration.border.top.width); | 507 path.lineTo(_decoration.border.left.width, _decoration.border.top.width); |
| 491 path.lineTo(0.0,0.0); | 508 path.lineTo(0.0,0.0); |
| 492 path.close(); | 509 path.close(); |
| 493 canvas.drawPath(path, paint); | 510 canvas.drawPath(path, paint); |
| 494 } | 511 } |
| 495 | 512 |
| 496 super.paint(canvas); | 513 super.paint(canvas); |
| 497 } | 514 } |
| 515 |
| 516 String debugDescribeSettings(String prefix) => '${prefix}decoration:\n${decora
tion.toString(prefix + " ")}'; |
| 498 } | 517 } |
| 499 | 518 |
| 500 class RenderTransform extends RenderProxyBox { | 519 class RenderTransform extends RenderProxyBox { |
| 501 RenderTransform({ | 520 RenderTransform({ |
| 502 Matrix4 transform, | 521 Matrix4 transform, |
| 503 RenderBox child | 522 RenderBox child |
| 504 }) : super(child) { | 523 }) : super(child) { |
| 505 assert(transform != null); | 524 assert(transform != null); |
| 506 this.transform = transform; | 525 this.transform = transform; |
| 507 } | 526 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 | 702 |
| 684 void defaultPaint(RenderObjectDisplayList canvas) { | 703 void defaultPaint(RenderObjectDisplayList canvas) { |
| 685 RenderBox child = firstChild; | 704 RenderBox child = firstChild; |
| 686 while (child != null) { | 705 while (child != null) { |
| 687 assert(child.parentData is ParentDataType); | 706 assert(child.parentData is ParentDataType); |
| 688 canvas.paintChild(child, child.parentData.position); | 707 canvas.paintChild(child, child.parentData.position); |
| 689 child = child.parentData.nextSibling; | 708 child = child.parentData.nextSibling; |
| 690 } | 709 } |
| 691 } | 710 } |
| 692 } | 711 } |
| OLD | NEW |