OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 import 'dart:sky' as sky; |
| 6 import 'render_box.dart'; |
| 7 import 'render_node.dart'; |
| 8 |
| 9 class RenderInline extends RenderNode { |
| 10 String data; |
| 11 |
| 12 RenderInline(this.data); |
| 13 } |
| 14 |
| 15 class RenderParagraph extends RenderBox { |
| 16 |
| 17 RenderParagraph({ |
| 18 String text, |
| 19 int color |
| 20 }) : _color = color { |
| 21 _layoutRoot.rootElement = _document.createElement('p'); |
| 22 this.text = text; |
| 23 } |
| 24 |
| 25 final sky.Document _document = new sky.Document(); |
| 26 final sky.LayoutRoot _layoutRoot = new sky.LayoutRoot(); |
| 27 |
| 28 String get text => (_layoutRoot.rootElement.firstChild as sky.Text).data; |
| 29 void set text (String value) { |
| 30 _layoutRoot.rootElement.setChild(_document.createText(value)); |
| 31 markNeedsLayout(); |
| 32 } |
| 33 |
| 34 int _color = 0xFF000000; |
| 35 int get color => _color; |
| 36 void set color (int value) { |
| 37 if (_color != value) { |
| 38 _color = value; |
| 39 markNeedsPaint(); |
| 40 } |
| 41 } |
| 42 |
| 43 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 44 assert(false); |
| 45 return null; |
| 46 // we don't currently support this for RenderParagraph |
| 47 } |
| 48 |
| 49 void performLayout() { |
| 50 _layoutRoot.maxWidth = constraints.maxWidth; |
| 51 _layoutRoot.minWidth = constraints.minWidth; |
| 52 _layoutRoot.minHeight = constraints.minHeight; |
| 53 _layoutRoot.maxHeight = constraints.maxHeight; |
| 54 _layoutRoot.layout(); |
| 55 size = constraints.constrain(new sky.Size(_layoutRoot.rootElement.width, _la
youtRoot.rootElement.height)); |
| 56 } |
| 57 |
| 58 void paint(RenderNodeDisplayList canvas) { |
| 59 // _layoutRoot.rootElement.style['color'] = 'rgba(' + ...color... + ')'; |
| 60 _layoutRoot.paint(canvas); |
| 61 } |
| 62 |
| 63 // we should probably expose a way to do precise (inter-glpyh) hit testing |
| 64 } |
OLD | NEW |