Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: sky/sdk/lib/framework/rendering/paragraph.dart

Issue 1168113005: ShrinkWrap the Stocks menu (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: more worky Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/sdk/lib/framework/rendering/box.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'box.dart'; 6 import 'box.dart';
7 import 'object.dart'; 7 import 'object.dart';
8 8
9 class RenderInline extends RenderObject { 9 class RenderInline extends RenderObject {
10 String data; 10 String data;
11 11
12 RenderInline(this.data); 12 RenderInline(this.data);
13 } 13 }
14 14
15 // Unfortunately, using full precision floating point here causes bad layouts
16 // because floating point math isn't associative. If we add and subtract
17 // padding, for example, we'll get different values when we estimate sizes and
18 // when we actually compute layout because the operations will end up associated
19 // differently. To work around this problem for now, we round fractional pixel
20 // values up to the nearest whole pixel value. The right long-term fix is to do
21 // layout using fixed precision arithmetic.
22 double _applyFloatingPointHack(double layoutValue) {
23 return layoutValue.ceilToDouble();
24 }
25
15 class RenderParagraph extends RenderBox { 26 class RenderParagraph extends RenderBox {
16 27
17 RenderParagraph({ 28 RenderParagraph({
18 String text, 29 String text,
19 Color color 30 Color color
20 }) : _color = color { 31 }) : _color = color {
21 _layoutRoot.rootElement = _document.createElement('p'); 32 _layoutRoot.rootElement = _document.createElement('p');
22 this.text = text; 33 this.text = text;
23 } 34 }
24 35
25 final sky.Document _document = new sky.Document(); 36 final sky.Document _document = new sky.Document();
26 final sky.LayoutRoot _layoutRoot = new sky.LayoutRoot(); 37 final sky.LayoutRoot _layoutRoot = new sky.LayoutRoot();
27 38
28 String get text => (_layoutRoot.rootElement.firstChild as sky.Text).data; 39 String get text => (_layoutRoot.rootElement.firstChild as sky.Text).data;
29 void set text (String value) { 40 void set text (String value) {
30 _layoutRoot.rootElement.setChild(_document.createText(value)); 41 _layoutRoot.rootElement.setChild(_document.createText(value));
31 markNeedsLayout(); 42 markNeedsLayout();
32 } 43 }
33 44
34 Color _color = const Color(0xFF000000); 45 Color _color = const Color(0xFF000000);
35 Color get color => _color; 46 Color get color => _color;
36 void set color (Color value) { 47 void set color (Color value) {
37 if (_color != value) { 48 if (_color != value) {
38 _color = value; 49 _color = value;
39 markNeedsPaint(); 50 markNeedsPaint();
40 } 51 }
41 } 52 }
42 53
43 // We don't currently support this for RenderParagraph 54 sky.Element _layout(BoxConstraints constraints) {
44 double getMinIntrinsicWidth(BoxConstraints constraints) {
45 assert(false);
46 return constraints.constrainWidth(0.0);
47 }
48
49 // We don't currently support this for RenderParagraph
50 double getMaxIntrinsicWidth(BoxConstraints constraints) {
51 assert(false);
52 return constraints.constrainWidth(0.0);
53 }
54
55 // We don't currently support this for RenderParagraph
56 double getMinIntrinsicHeight(BoxConstraints constraints) {
57 assert(false);
58 return constraints.constrainHeight(0.0);
59 }
60
61 // We don't currently support this for RenderParagraph
62 double getMaxIntrinsicHeight(BoxConstraints constraints) {
63 assert(false);
64 return constraints.constrainHeight(0.0);
65 }
66
67 void performLayout() {
68 _layoutRoot.maxWidth = constraints.maxWidth; 55 _layoutRoot.maxWidth = constraints.maxWidth;
69 _layoutRoot.minWidth = constraints.minWidth; 56 _layoutRoot.minWidth = constraints.minWidth;
70 _layoutRoot.minHeight = constraints.minHeight; 57 _layoutRoot.minHeight = constraints.minHeight;
71 _layoutRoot.maxHeight = constraints.maxHeight; 58 _layoutRoot.maxHeight = constraints.maxHeight;
72 _layoutRoot.layout(); 59 _layoutRoot.layout();
60 }
61
62 double getMinIntrinsicWidth(BoxConstraints constraints) {
63 _layout(constraints);
64 return constraints.constrainWidth(
65 _applyFloatingPointHack(_layoutRoot.rootElement.minContentWidth));
66 }
67
68 double getMaxIntrinsicWidth(BoxConstraints constraints) {
69 _layout(constraints);
70 return constraints.constrainWidth(
71 _applyFloatingPointHack(_layoutRoot.rootElement.maxContentWidth));
72 }
73
74 double _getIntrinsicHeight(BoxConstraints constraints) {
75 _layout(constraints);
76 return constraints.constrainHeight(
77 _applyFloatingPointHack(_layoutRoot.rootElement.height.ceilToDouble));
78 }
79
80 double getMinIntrinsicHeight(BoxConstraints constraints) {
81 return _getIntrinsicHeight(constraints);
82 }
83
84 double getMaxIntrinsicHeight(BoxConstraints constraints) {
85 return _getIntrinsicHeight(constraints);
86 }
87
88 void performLayout() {
89 _layout(constraints);
90 sky.Element root = _layoutRoot.rootElement;
73 // rootElement.width always expands to fill, use maxContentWidth instead. 91 // rootElement.width always expands to fill, use maxContentWidth instead.
74 sky.Element root = _layoutRoot.rootElement; 92 size = constraints.constrain(new Size(_applyFloatingPointHack(root.maxConten tWidth),
75 size = constraints.constrain(new Size(root.maxContentWidth, root.height)); 93 _applyFloatingPointHack(root.height))) ;
76 } 94 }
77 95
78 void paint(RenderObjectDisplayList canvas) { 96 void paint(RenderObjectDisplayList canvas) {
79 // _layoutRoot.rootElement.style['color'] = 'rgba(' + ...color... + ')'; 97 // _layoutRoot.rootElement.style['color'] = 'rgba(' + ...color... + ')';
80 _layoutRoot.paint(canvas); 98 _layoutRoot.paint(canvas);
81 } 99 }
82 100
83 // we should probably expose a way to do precise (inter-glpyh) hit testing 101 // we should probably expose a way to do precise (inter-glpyh) hit testing
84 102
85 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}color: ${color}\n${prefix}text: ${text}\n'; 103 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}color: ${color}\n${prefix}text: ${text}\n';
86 } 104 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/rendering/box.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698