Commit 9bc6d281 authored by Adam Barth's avatar Adam Barth

Merge pull request #2674 from abarth/child_view_error

Improve error handling for ChildView outside MojoShell
parents d8b4a4a3 afacec9a
...@@ -19,11 +19,8 @@ import 'object.dart'; ...@@ -19,11 +19,8 @@ import 'object.dart';
mojom.ViewProxy _initViewProxy() { mojom.ViewProxy _initViewProxy() {
int viewHandle = ui.takeViewHandle(); int viewHandle = ui.takeViewHandle();
assert(() { if (viewHandle == core.MojoHandle.INVALID)
if (viewHandle == core.MojoHandle.INVALID) return null;
debugPrint('Child view are supported only when running in Mojo shell.');
return true;
});
return new mojom.ViewProxy.fromHandle(new core.MojoHandle(viewHandle)); return new mojom.ViewProxy.fromHandle(new core.MojoHandle(viewHandle));
} }
...@@ -74,7 +71,7 @@ class ChildViewConnection { ...@@ -74,7 +71,7 @@ class ChildViewConnection {
assert(_viewOwner != null); assert(_viewOwner != null);
assert(_viewKey == null); assert(_viewKey == null);
_viewKey = _nextViewKey++; _viewKey = _nextViewKey++;
_view.addChild(_viewKey, _viewOwner.impl); _view?.addChild(_viewKey, _viewOwner.impl);
_viewOwner = null; _viewOwner = null;
} }
...@@ -83,7 +80,7 @@ class ChildViewConnection { ...@@ -83,7 +80,7 @@ class ChildViewConnection {
assert(_viewOwner == null); assert(_viewOwner == null);
assert(_viewKey != null); assert(_viewKey != null);
_viewOwner = new mojom.ViewOwnerProxy.unbound(); _viewOwner = new mojom.ViewOwnerProxy.unbound();
_view.removeChild(_viewKey, _viewOwner); _view?.removeChild(_viewKey, _viewOwner);
_viewKey = null; _viewKey = null;
} }
...@@ -117,6 +114,8 @@ class ChildViewConnection { ...@@ -117,6 +114,8 @@ class ChildViewConnection {
assert(_attached); assert(_attached);
assert(_attachments == 1); assert(_attachments == 1);
assert(_viewKey != null); assert(_viewKey != null);
if (_view == null)
return new Future<mojom.ViewLayoutInfo>.value(null);
int width = (size.width * scale).round(); int width = (size.width * scale).round();
int height = (size.height * scale).round(); int height = (size.height * scale).round();
// TODO(abarth): Ideally we would propagate our actually constraints to be // TODO(abarth): Ideally we would propagate our actually constraints to be
...@@ -188,9 +187,25 @@ class RenderChildView extends RenderBox { ...@@ -188,9 +187,25 @@ class RenderChildView extends RenderBox {
size = constraints.biggest; size = constraints.biggest;
} }
TextPainter _debugErrorMessage;
void performLayout() { void performLayout() {
if (_child != null) if (_child != null) {
_child._layout(size: size, scale: scale).then(_handleLayoutInfoChanged); _child._layout(size: size, scale: scale).then(_handleLayoutInfoChanged);
assert(() {
if (_view == null) {
_debugErrorMessage ??= new TextPainter()
..text = new TextSpan(text: 'Child view are supported only when running in Mojo shell.');
_debugErrorMessage
..minWidth = size.width
..maxWidth = size.width
..minHeight = size.height
..maxHeight = size.height
..layout();
}
return true;
});
}
} }
mojom.ViewLayoutInfo _layoutInfo; mojom.ViewLayoutInfo _layoutInfo;
...@@ -206,6 +221,13 @@ class RenderChildView extends RenderBox { ...@@ -206,6 +221,13 @@ class RenderChildView extends RenderBox {
assert(needsCompositing); assert(needsCompositing);
if (_layoutInfo != null) if (_layoutInfo != null)
context.pushChildScene(offset, scale, _layoutInfo); context.pushChildScene(offset, scale, _layoutInfo);
assert(() {
if (_view == null) {
context.canvas.drawRect(offset & size, new Paint()..color = const Color(0xFF0000FF));
_debugErrorMessage.paint(context.canvas, offset);
}
return true;
});
} }
void debugFillDescription(List<String> description) { void debugFillDescription(List<String> description) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment