| 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 |
| 11 abstract class InlineBase { | 11 abstract class InlineBase { |
| 12 sky.Node _toDOM(sky.Document owner); | 12 sky.Node _toDOM(sky.Document owner); |
| 13 String toString([String prefix = '']); | 13 String toString([String prefix = '']); |
| 14 } | 14 } |
| 15 | 15 |
| 16 class InlineText extends InlineBase { | 16 class InlineText extends InlineBase { |
| 17 InlineText(this.text) { | 17 InlineText(this.text) { |
| 18 assert(text != null); | 18 assert(text != null); |
| 19 } | 19 } |
| 20 | 20 |
| 21 final String text; | 21 final String text; |
| 22 | 22 |
| 23 sky.Node _toDOM(sky.Document owner) { | 23 sky.Node _toDOM(sky.Document owner) { |
| 24 return owner.createText(text); | 24 return owner.createText(text); |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool operator ==(other) => other is InlineText && text == other.text; |
| 28 int get hashCode => text.hashCode; |
| 29 |
| 27 String toString([String prefix = '']) => '${prefix}InlineText: "${text}"'; | 30 String toString([String prefix = '']) => '${prefix}InlineText: "${text}"'; |
| 28 } | 31 } |
| 29 | 32 |
| 30 class InlineStyle extends InlineBase { | 33 class InlineStyle extends InlineBase { |
| 31 InlineStyle(this.style, this.children) { | 34 InlineStyle(this.style, this.children) { |
| 32 assert(style != null); | 35 assert(style != null); |
| 33 assert(children != null); | 36 assert(children != null); |
| 34 } | 37 } |
| 35 | 38 |
| 36 final TextStyle style; | 39 final TextStyle style; |
| 37 final List<InlineBase> children; | 40 final List<InlineBase> children; |
| 38 | 41 |
| 39 sky.Node _toDOM(sky.Document owner) { | 42 sky.Node _toDOM(sky.Document owner) { |
| 40 sky.Element parent = owner.createElement('t'); | 43 sky.Element parent = owner.createElement('t'); |
| 41 style.applyToCSSStyle(parent.style); | 44 style.applyToCSSStyle(parent.style); |
| 42 for (InlineBase child in children) { | 45 for (InlineBase child in children) { |
| 43 parent.appendChild(child._toDOM(owner)); | 46 parent.appendChild(child._toDOM(owner)); |
| 44 } | 47 } |
| 45 return parent; | 48 return parent; |
| 46 } | 49 } |
| 47 | 50 |
| 51 bool operator ==(other) { |
| 52 if (identical(this, other)) |
| 53 return true; |
| 54 if (other is! InlineStyle |
| 55 || style != other.style |
| 56 || children.length != other.children.length) |
| 57 return false; |
| 58 for (int i = 0; i < children.length; ++i) { |
| 59 if (children[i] != other.children[i]) |
| 60 return false; |
| 61 } |
| 62 return true; |
| 63 } |
| 64 |
| 65 int get hashCode { |
| 66 int value = 373; |
| 67 value = 37 * value + style.hashCode; |
| 68 for (InlineBase child in children) |
| 69 value = 37 * value + child.hashCode; |
| 70 return value; |
| 71 } |
| 72 |
| 48 String toString([String prefix = '']) { | 73 String toString([String prefix = '']) { |
| 49 List<String> result = []; | 74 List<String> result = []; |
| 50 result.add('${prefix}InlineStyle:'); | 75 result.add('${prefix}InlineStyle:'); |
| 51 var indent = '${prefix} '; | 76 var indent = '${prefix} '; |
| 52 result.add('${style.toString(indent)}'); | 77 result.add('${style.toString(indent)}'); |
| 53 for (InlineBase child in children) { | 78 for (InlineBase child in children) { |
| 54 result.add(child.toString(indent)); | 79 result.add(child.toString(indent)); |
| 55 } | 80 } |
| 56 return result.join('\n'); | 81 return result.join('\n'); |
| 57 } | 82 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 76 } | 101 } |
| 77 | 102 |
| 78 final sky.Document _document = new sky.Document(); | 103 final sky.Document _document = new sky.Document(); |
| 79 final sky.LayoutRoot _layoutRoot = new sky.LayoutRoot(); | 104 final sky.LayoutRoot _layoutRoot = new sky.LayoutRoot(); |
| 80 | 105 |
| 81 InlineBase _inline; | 106 InlineBase _inline; |
| 82 BoxConstraints _constraintsForCurrentLayout; | 107 BoxConstraints _constraintsForCurrentLayout; |
| 83 | 108 |
| 84 InlineBase get inline => _inline; | 109 InlineBase get inline => _inline; |
| 85 void set inline (InlineBase value) { | 110 void set inline (InlineBase value) { |
| 111 if (_inline == value) |
| 112 return; |
| 86 _inline = value; | 113 _inline = value; |
| 87 _layoutRoot.rootElement.setChild(_inline._toDOM(_document)); | 114 _layoutRoot.rootElement.setChild(_inline._toDOM(_document)); |
| 88 markNeedsLayout(); | 115 markNeedsLayout(); |
| 89 } | 116 } |
| 90 | 117 |
| 91 void _layout(BoxConstraints constraints) { | 118 void _layout(BoxConstraints constraints) { |
| 92 _layoutRoot.maxWidth = constraints.maxWidth; | 119 _layoutRoot.maxWidth = constraints.maxWidth; |
| 93 _layoutRoot.minWidth = constraints.minWidth; | 120 _layoutRoot.minWidth = constraints.minWidth; |
| 94 _layoutRoot.minHeight = constraints.minHeight; | 121 _layoutRoot.minHeight = constraints.minHeight; |
| 95 _layoutRoot.maxHeight = constraints.maxHeight; | 122 _layoutRoot.maxHeight = constraints.maxHeight; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 173 } |
| 147 | 174 |
| 148 // we should probably expose a way to do precise (inter-glpyh) hit testing | 175 // we should probably expose a way to do precise (inter-glpyh) hit testing |
| 149 | 176 |
| 150 String debugDescribeSettings(String prefix) { | 177 String debugDescribeSettings(String prefix) { |
| 151 String result = '${super.debugDescribeSettings(prefix)}'; | 178 String result = '${super.debugDescribeSettings(prefix)}'; |
| 152 result += '${prefix}inline: ${inline}\n'; | 179 result += '${prefix}inline: ${inline}\n'; |
| 153 return result; | 180 return result; |
| 154 } | 181 } |
| 155 } | 182 } |
| OLD | NEW |