| 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:sky' as sky; | 5 import 'dart:sky' as sky; |
| 6 | 6 |
| 7 import 'box.dart'; | 7 import 'box.dart'; |
| 8 import 'object.dart'; | 8 import 'object.dart'; |
| 9 import '../painting/text_style.dart'; | 9 import '../painting/text_style.dart'; |
| 10 | 10 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 class RenderParagraph extends RenderBox { | 96 class RenderParagraph extends RenderBox { |
| 97 | 97 |
| 98 RenderParagraph(InlineBase inlineValue) { | 98 RenderParagraph(InlineBase inlineValue) { |
| 99 _layoutRoot.rootElement = _document.createElement('p'); | 99 _layoutRoot.rootElement = _document.createElement('p'); |
| 100 inline = inlineValue; | 100 inline = inlineValue; |
| 101 } | 101 } |
| 102 | 102 |
| 103 final sky.Document _document = new sky.Document(); | 103 final sky.Document _document = new sky.Document(); |
| 104 final sky.LayoutRoot _layoutRoot = new sky.LayoutRoot(); | 104 final sky.LayoutRoot _layoutRoot = new sky.LayoutRoot(); |
| 105 | 105 |
| 106 BoxConstraints _constraintsForCurrentLayout; // when null, we don't have a cur
rent layout |
| 107 |
| 106 InlineBase _inline; | 108 InlineBase _inline; |
| 107 BoxConstraints _constraintsForCurrentLayout; | |
| 108 | |
| 109 InlineBase get inline => _inline; | 109 InlineBase get inline => _inline; |
| 110 void set inline (InlineBase value) { | 110 void set inline (InlineBase value) { |
| 111 if (_inline == value) | 111 if (_inline == value) |
| 112 return; | 112 return; |
| 113 _inline = value; | 113 _inline = value; |
| 114 _layoutRoot.rootElement.setChild(_inline._toDOM(_document)); | 114 _layoutRoot.rootElement.setChild(_inline._toDOM(_document)); |
| 115 _constraintsForCurrentLayout = null; |
| 115 markNeedsLayout(); | 116 markNeedsLayout(); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void _layout(BoxConstraints constraints) { | 119 void _layout(BoxConstraints constraints) { |
| 120 assert(constraints != null); |
| 121 if (_constraintsForCurrentLayout == constraints) |
| 122 return; // already cached this layout |
| 119 _layoutRoot.maxWidth = constraints.maxWidth; | 123 _layoutRoot.maxWidth = constraints.maxWidth; |
| 120 _layoutRoot.minWidth = constraints.minWidth; | 124 _layoutRoot.minWidth = constraints.minWidth; |
| 121 _layoutRoot.minHeight = constraints.minHeight; | 125 _layoutRoot.minHeight = constraints.minHeight; |
| 122 _layoutRoot.maxHeight = constraints.maxHeight; | 126 _layoutRoot.maxHeight = constraints.maxHeight; |
| 123 _layoutRoot.layout(); | 127 _layoutRoot.layout(); |
| 124 _constraintsForCurrentLayout = constraints; | 128 _constraintsForCurrentLayout = constraints; |
| 125 } | 129 } |
| 126 | 130 |
| 127 double getMinIntrinsicWidth(BoxConstraints constraints) { | 131 double getMinIntrinsicWidth(BoxConstraints constraints) { |
| 128 _layout(constraints); | 132 _layout(constraints); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 159 } | 163 } |
| 160 | 164 |
| 161 void paint(RenderCanvas canvas) { | 165 void paint(RenderCanvas canvas) { |
| 162 // Ideally we could compute the min/max intrinsic width/height with a | 166 // Ideally we could compute the min/max intrinsic width/height with a |
| 163 // non-destructive operation. However, currently, computing these values | 167 // non-destructive operation. However, currently, computing these values |
| 164 // will destroy state inside the layout root. If that happens, we need to | 168 // will destroy state inside the layout root. If that happens, we need to |
| 165 // get back the correct state by calling _layout again. | 169 // get back the correct state by calling _layout again. |
| 166 // | 170 // |
| 167 // TODO(abarth): Make computing the min/max intrinsic width/height a | 171 // TODO(abarth): Make computing the min/max intrinsic width/height a |
| 168 // non-destructive operation. | 172 // non-destructive operation. |
| 169 if (_constraintsForCurrentLayout != constraints && constraints != null) | 173 _layout(constraints); |
| 170 _layout(constraints); | |
| 171 | |
| 172 _layoutRoot.paint(canvas); | 174 _layoutRoot.paint(canvas); |
| 173 } | 175 } |
| 174 | 176 |
| 175 // we should probably expose a way to do precise (inter-glpyh) hit testing | 177 // we should probably expose a way to do precise (inter-glpyh) hit testing |
| 176 | 178 |
| 177 String debugDescribeSettings(String prefix) { | 179 String debugDescribeSettings(String prefix) { |
| 178 String result = '${super.debugDescribeSettings(prefix)}'; | 180 String result = '${super.debugDescribeSettings(prefix)}'; |
| 179 result += '${prefix}inline:\n${inline.toString("$prefix ")}\n'; | 181 result += '${prefix}inline:\n${inline.toString("$prefix ")}\n'; |
| 180 return result; | 182 return result; |
| 181 } | 183 } |
| 182 } | 184 } |
| OLD | NEW |