Chromium Code Reviews| 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 'render_node.dart'; | 5 import 'render_node.dart'; |
| 6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
| 7 | 7 |
| 8 // GENERIC BOX RENDERING | 8 // GENERIC BOX RENDERING |
| 9 // Anything that has a concept of x, y, width, height is going to derive from th is | 9 // Anything that has a concept of x, y, width, height is going to derive from th is |
| 10 | 10 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 void paint(RenderNodeDisplayList canvas) { | 138 void paint(RenderNodeDisplayList canvas) { |
| 139 if (child != null) | 139 if (child != null) |
| 140 child.paint(canvas); | 140 child.paint(canvas); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 class RenderSizedBox extends RenderProxyBox { | 144 class RenderSizedBox extends RenderProxyBox { |
| 145 final sky.Size desiredSize; | 145 final sky.Size desiredSize; |
| 146 | 146 |
| 147 RenderSizedBox({ | 147 RenderSizedBox({ |
| 148 RenderBox child, | 148 RenderBox child, |
| 149 this.desiredSize: const sky.Size.infinite() | 149 this.desiredSize: const sky.Size.infinite() |
| 150 }) : super(child); | 150 }) : super(child); |
| 151 | 151 |
| 152 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { | 152 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 153 return constraints.constrain(desiredSize); | 153 return constraints.constrain(desiredSize); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void performLayout() { | 156 void performLayout() { |
| 157 size = constraints.constrain(desiredSize); | 157 size = constraints.constrain(desiredSize); |
| 158 child.layout(new BoxConstraints.tight(size)); | 158 child.layout(new BoxConstraints.tight(size)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 | 254 |
| 255 if (_decoration.backgroundColor != null) { | 255 if (_decoration.backgroundColor != null) { |
| 256 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; | 256 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; |
| 257 canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint); | 257 canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint); |
| 258 } | 258 } |
| 259 super.paint(canvas); | 259 super.paint(canvas); |
| 260 } | 260 } |
| 261 | 261 |
| 262 } | 262 } |
| 263 | 263 |
| 264 // This must be immutable, because we won't notice when it changes | |
| 265 class BoxShadow { | |
| 266 const BoxShadow({ | |
| 267 this.color, | |
| 268 this.offset | |
| 269 }); | |
| 270 | |
| 271 final sky.Size offset; | |
| 272 final sky.Color color; | |
| 273 } | |
| 274 | |
| 275 class RenderShadowedBox extends RenderProxyBox { | |
| 276 | |
| 277 RenderShadowedBox({ | |
| 278 BoxShadow shadow, | |
| 279 RenderBox child | |
| 280 }) : _shadow = shadow, super(child); | |
| 281 | |
| 282 BoxShadow _shadow; | |
| 283 BoxShadow get shadow => _decoration; | |
|
Matt Perry
2015/06/02 20:57:37
Did you mean to return _shadow here?
| |
| 284 void set shadow (BoxShadow value) { | |
| 285 if (value == _shadow) | |
| 286 return; | |
| 287 _shadow = value; | |
| 288 markNeedsPaint(); | |
| 289 } | |
| 290 | |
| 291 sky.Paint _createShadowPaint(BoxShadow shadow) { | |
| 292 sky.Paint paint = new sky.Paint()..color = shadow.color; | |
|
Matt Perry
2015/06/02 20:57:36
This should be the color of the Main layer, not th
| |
| 293 sky.Size offset = shadow.offset; | |
| 294 var builder = new sky.LayerDrawLooperBuilder() | |
| 295 // Shadow layer. | |
| 296 ..addLayerOnTop( | |
| 297 new sky.DrawLooperLayerInfo() | |
| 298 ..setOffset(offset.toPoint()) | |
| 299 ..setColorMode(sky.TransferMode.srcInMode), | |
|
Matt Perry
2015/06/02 21:19:01
BTW, the existing code[1] uses srcMode. We might w
| |
| 300 (sky.Paint layerPaint) { | |
| 301 layerPaint.setARGB(128, 55, 55, 55); | |
|
Matt Perry
2015/06/02 20:57:36
This is the shadow color. Since we're using Transf
| |
| 302 // TODO(mpcomplete): add blur filter | |
| 303 }) | |
| 304 // Main layer. | |
| 305 ..addLayerOnTop(new sky.DrawLooperLayerInfo(), (_) {}); | |
| 306 paint.setDrawLooper(builder.build()); | |
| 307 return paint; | |
| 308 } | |
| 309 | |
| 310 void paint(RenderNodeDisplayList canvas) { | |
| 311 sky.Paint paint = _createShadowPaint(_shadow); | |
| 312 canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height), pa int); | |
| 313 super.paint(canvas); | |
| 314 } | |
| 315 } | |
| 264 | 316 |
| 265 // RENDER VIEW LAYOUT MANAGER | 317 // RENDER VIEW LAYOUT MANAGER |
| 266 | 318 |
| 267 class ViewConstraints { | 319 class ViewConstraints { |
| 268 | 320 |
| 269 const ViewConstraints({ | 321 const ViewConstraints({ |
| 270 this.width: 0.0, this.height: 0.0, this.orientation: null | 322 this.width: 0.0, this.height: 0.0, this.orientation: null |
| 271 }); | 323 }); |
| 272 | 324 |
| 273 final double width; | 325 final double width; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 | 414 |
| 363 void defaultPaint(RenderNodeDisplayList canvas) { | 415 void defaultPaint(RenderNodeDisplayList canvas) { |
| 364 RenderBox child = firstChild; | 416 RenderBox child = firstChild; |
| 365 while (child != null) { | 417 while (child != null) { |
| 366 assert(child.parentData is ParentDataType); | 418 assert(child.parentData is ParentDataType); |
| 367 canvas.paintChild(child, child.parentData.position); | 419 canvas.paintChild(child, child.parentData.position); |
| 368 child = child.parentData.nextSibling; | 420 child = child.parentData.nextSibling; |
| 369 } | 421 } |
| 370 } | 422 } |
| 371 } | 423 } |
| OLD | NEW |