|
@@ -106,10 +106,10 @@ class RenderEditableImage extends RenderBox
|
106
|
106
|
}
|
107
|
107
|
|
108
|
108
|
@override
|
109
|
|
- double get preferredLineHeight => size.height;
|
|
109
|
+ double get preferredLineHeight => size.height - kPaddingBottom;
|
110
|
110
|
|
111
|
111
|
@override
|
112
|
|
- SelectionOrder get selectionOrder => SelectionOrder.background;
|
|
112
|
+ SelectionOrder get selectionOrder => SelectionOrder.foreground;
|
113
|
113
|
|
114
|
114
|
@override
|
115
|
115
|
TextSelection getLocalSelection(TextSelection documentSelection) {
|
|
@@ -127,16 +127,19 @@ class RenderEditableImage extends RenderBox
|
127
|
127
|
List<ui.TextBox> getEndpointsForSelection(TextSelection selection) {
|
128
|
128
|
TextSelection local = getLocalSelection(selection);
|
129
|
129
|
if (local.isCollapsed) {
|
130
|
|
- final dx = local.extentOffset == 0 ? 0.0 : size.width;
|
|
130
|
+ final dx = local.extentOffset == 0 ? _childOffset.dx : size.width;
|
131
|
131
|
return [
|
132
|
|
- new ui.TextBox.fromLTRBD(dx, 0.0, dx, size.height, TextDirection.ltr),
|
|
132
|
+ new ui.TextBox.fromLTRBD(
|
|
133
|
+ dx, 0.0, dx, size.height - kPaddingBottom, TextDirection.ltr),
|
133
|
134
|
];
|
134
|
135
|
}
|
135
|
136
|
|
|
137
|
+ final rect = _childRect;
|
136
|
138
|
return [
|
137
|
|
- new ui.TextBox.fromLTRBD(0.0, 0.0, 0.0, size.height, TextDirection.ltr),
|
138
|
139
|
new ui.TextBox.fromLTRBD(
|
139
|
|
- size.width, 0.0, size.width, size.height, TextDirection.ltr),
|
|
140
|
+ rect.left, rect.top, rect.left, rect.bottom, TextDirection.ltr),
|
|
141
|
+ new ui.TextBox.fromLTRBD(
|
|
142
|
+ rect.right, rect.top, rect.right, rect.bottom, TextDirection.ltr),
|
140
|
143
|
];
|
141
|
144
|
}
|
142
|
145
|
|
|
@@ -174,27 +177,56 @@ class RenderEditableImage extends RenderBox
|
174
|
177
|
}
|
175
|
178
|
|
176
|
179
|
@override
|
177
|
|
- void paintSelection(PaintingContext context, ui.Offset offset,
|
178
|
|
- TextSelection selection, ui.Color selectionColor) {
|
|
180
|
+ void paintSelection(PaintingContext context, Offset offset,
|
|
181
|
+ TextSelection selection, Color selectionColor) {
|
179
|
182
|
final localSelection = getLocalSelection(selection);
|
180
|
183
|
assert(localSelection != null);
|
181
|
184
|
if (!localSelection.isCollapsed) {
|
182
|
|
- final Paint paint = new Paint()..color = selectionColor;
|
183
|
|
- final rect = new Rect.fromLTWH(0.0, 0.0, size.width, size.height);
|
184
|
|
- context.canvas.drawRect(rect.shift(offset), paint);
|
|
185
|
+ final Paint paint = new Paint()
|
|
186
|
+ ..color = selectionColor
|
|
187
|
+ ..style = PaintingStyle.stroke
|
|
188
|
+ ..strokeWidth = 3.0;
|
|
189
|
+ final rect = new Rect.fromLTWH(
|
|
190
|
+ 0.0, 0.0, _lastChildSize.width, _lastChildSize.height);
|
|
191
|
+ context.canvas.drawRect(rect.shift(offset + _childOffset), paint);
|
185
|
192
|
}
|
186
|
193
|
}
|
187
|
194
|
|
|
195
|
+ void paint(PaintingContext context, Offset offset) {
|
|
196
|
+ super.paint(context, offset + _childOffset);
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ static const double kHorizontalPadding = 1.0;
|
|
200
|
+
|
|
201
|
+ Size _lastChildSize;
|
|
202
|
+
|
|
203
|
+ Offset get _childOffset {
|
|
204
|
+ final dx = (size.width - _lastChildSize.width) / 2 + kHorizontalPadding;
|
|
205
|
+ final dy = (size.height - _lastChildSize.height - kPaddingBottom) / 2;
|
|
206
|
+ return new Offset(dx, dy);
|
|
207
|
+ }
|
|
208
|
+
|
|
209
|
+ Rect get _childRect {
|
|
210
|
+ return new Rect.fromLTWH(_childOffset.dx, _childOffset.dy,
|
|
211
|
+ _lastChildSize.width, _lastChildSize.height);
|
|
212
|
+ }
|
|
213
|
+
|
188
|
214
|
@override
|
189
|
215
|
void performLayout() {
|
190
|
216
|
assert(constraints.hasBoundedWidth);
|
191
|
217
|
if (child != null) {
|
192
|
218
|
// Make constraints use 16:9 aspect ratio.
|
|
219
|
+ final width = constraints.maxWidth - kHorizontalPadding * 2;
|
193
|
220
|
final childConstraints = constraints.copyWith(
|
194
|
|
- maxHeight: (constraints.maxWidth * 9 / 16).floorToDouble(),
|
|
221
|
+ minWidth: 0.0,
|
|
222
|
+ maxWidth: width,
|
|
223
|
+ minHeight: 0.0,
|
|
224
|
+ maxHeight: (width * 9 / 16).floorToDouble(),
|
195
|
225
|
);
|
196
|
226
|
child.layout(childConstraints, parentUsesSize: true);
|
197
|
|
- size = new Size(child.size.width, child.size.height + kPaddingBottom);
|
|
227
|
+ _lastChildSize = child.size;
|
|
228
|
+ size = new Size(
|
|
229
|
+ constraints.maxWidth, _lastChildSize.height + kPaddingBottom);
|
198
|
230
|
} else {
|
199
|
231
|
performResize();
|
200
|
232
|
}
|