| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 double horizontal = edges.left + edges.right; | 70 double horizontal = edges.left + edges.right; |
| 71 double vertical = edges.top + edges.bottom; | 71 double vertical = edges.top + edges.bottom; |
| 72 return new BoxConstraints( | 72 return new BoxConstraints( |
| 73 minWidth: math.max(0.0, minWidth - horizontal), | 73 minWidth: math.max(0.0, minWidth - horizontal), |
| 74 maxWidth: maxWidth - horizontal, | 74 maxWidth: maxWidth - horizontal, |
| 75 minHeight: math.max(0.0, minHeight - vertical), | 75 minHeight: math.max(0.0, minHeight - vertical), |
| 76 maxHeight: maxHeight - vertical | 76 maxHeight: maxHeight - vertical |
| 77 ); | 77 ); |
| 78 } | 78 } |
| 79 | 79 |
| 80 BoxConstraints apply(BoxConstraints constraints) { |
| 81 return new BoxConstraints( |
| 82 minWidth: math.max(minWidth, constraints.minWidth), |
| 83 maxWidth: math.min(maxWidth, constraints.maxWidth), |
| 84 minHeight: math.max(minHeight, constraints.minHeight), |
| 85 maxHeight: math.min(maxHeight, constraints.maxHeight)); |
| 86 } |
| 87 |
| 80 final double minWidth; | 88 final double minWidth; |
| 81 final double maxWidth; | 89 final double maxWidth; |
| 82 final double minHeight; | 90 final double minHeight; |
| 83 final double maxHeight; | 91 final double maxHeight; |
| 84 | 92 |
| 85 double constrainWidth(double width) { | 93 double constrainWidth(double width) { |
| 86 return clamp(min: minWidth, max: maxWidth, value: width); | 94 return clamp(min: minWidth, max: maxWidth, value: width); |
| 87 } | 95 } |
| 88 | 96 |
| 89 double constrainHeight(double height) { | 97 double constrainHeight(double height) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 if (child != null) | 193 if (child != null) |
| 186 child.paint(canvas); | 194 child.paint(canvas); |
| 187 } | 195 } |
| 188 } | 196 } |
| 189 | 197 |
| 190 class RenderSizedBox extends RenderProxyBox { | 198 class RenderSizedBox extends RenderProxyBox { |
| 191 | 199 |
| 192 RenderSizedBox({ | 200 RenderSizedBox({ |
| 193 RenderBox child, | 201 RenderBox child, |
| 194 Size desiredSize: Size.infinite | 202 Size desiredSize: Size.infinite |
| 195 }) : super(child) { | 203 }) : super(child), _desiredSize = desiredSize { |
| 196 assert(desiredSize != null); | 204 assert(desiredSize != null); |
| 197 this.desiredSize = desiredSize; | |
| 198 } | 205 } |
| 199 | 206 |
| 200 Size _desiredSize; | 207 Size _desiredSize; |
| 201 Size get desiredSize => _desiredSize; | 208 Size get desiredSize => _desiredSize; |
| 202 void set desiredSize (Size value) { | 209 void set desiredSize (Size value) { |
| 203 assert(value != null); | 210 assert(value != null); |
| 204 if (_desiredSize == value) | 211 if (_desiredSize == value) |
| 205 return; | 212 return; |
| 206 _desiredSize = value; | 213 _desiredSize = value; |
| 207 markNeedsLayout(); | 214 markNeedsLayout(); |
| 208 } | 215 } |
| 209 | 216 |
| 210 Size getIntrinsicDimensions(BoxConstraints constraints) { | 217 Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 211 return constraints.constrain(_desiredSize); | 218 return constraints.constrain(_desiredSize); |
| 212 } | 219 } |
| 213 | 220 |
| 214 void performLayout() { | 221 void performLayout() { |
| 215 size = constraints.constrain(_desiredSize); | 222 size = constraints.constrain(_desiredSize); |
| 216 if (child != null) | 223 if (child != null) |
| 217 child.layout(new BoxConstraints.tight(size)); | 224 child.layout(new BoxConstraints.tight(size)); |
| 218 } | 225 } |
| 219 | 226 |
| 220 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}desiredSize: ${desiredSize}\n'; | 227 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}desiredSize: ${desiredSize}\n'; |
| 221 } | 228 } |
| 222 | 229 |
| 230 class RenderConstrainedBox extends RenderProxyBox { |
| 231 RenderConstrainedBox({ |
| 232 RenderBox child, |
| 233 BoxConstraints additionalConstraints |
| 234 }) : super(child), _additionalConstraints = additionalConstraints { |
| 235 assert(additionalConstraints != null); |
| 236 } |
| 237 |
| 238 BoxConstraints _additionalConstraints; |
| 239 BoxConstraints get additionalConstraints => _additionalConstraints; |
| 240 void set additionalConstraints (BoxConstraints value) { |
| 241 assert(value != null); |
| 242 if (_additionalConstraints == value) |
| 243 return; |
| 244 _additionalConstraints = value; |
| 245 markNeedsLayout(); |
| 246 } |
| 247 |
| 248 Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 249 if (child == null) |
| 250 return constraints.constrain(Size.zero); |
| 251 return child.getIntrinsicDimensions(constraints.apply(_additionalConstraints
)); |
| 252 } |
| 253 |
| 254 void performLayout() { |
| 255 if (child != null) { |
| 256 child.layout(constraints.apply(_additionalConstraints)); |
| 257 size = child.size; |
| 258 } else { |
| 259 performResize(); |
| 260 } |
| 261 } |
| 262 |
| 263 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}additionalConstraints: ${additionalConstraints}\n'; |
| 264 } |
| 265 |
| 223 class RenderClip extends RenderProxyBox { | 266 class RenderClip extends RenderProxyBox { |
| 224 RenderClip({ RenderBox child }) : super(child); | 267 RenderClip({ RenderBox child }) : super(child); |
| 225 | 268 |
| 226 void paint(RenderObjectDisplayList canvas) { | 269 void paint(RenderObjectDisplayList canvas) { |
| 227 if (child != null) { | 270 if (child != null) { |
| 228 canvas.save(); | 271 canvas.save(); |
| 229 canvas.clipRect(new Rect.fromSize(size)); | 272 canvas.clipRect(new Rect.fromSize(size)); |
| 230 child.paint(canvas); | 273 child.paint(canvas); |
| 231 canvas.restore(); | 274 canvas.restore(); |
| 232 } | 275 } |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 | 842 |
| 800 void defaultPaint(RenderObjectDisplayList canvas) { | 843 void defaultPaint(RenderObjectDisplayList canvas) { |
| 801 RenderBox child = firstChild; | 844 RenderBox child = firstChild; |
| 802 while (child != null) { | 845 while (child != null) { |
| 803 assert(child.parentData is ParentDataType); | 846 assert(child.parentData is ParentDataType); |
| 804 canvas.paintChild(child, child.parentData.position); | 847 canvas.paintChild(child, child.parentData.position); |
| 805 child = child.parentData.nextSibling; | 848 child = child.parentData.nextSibling; |
| 806 } | 849 } |
| 807 } | 850 } |
| 808 } | 851 } |
| OLD | NEW |