[scenic] Cleanup for fuchsia_scenic_flutter
This logic is no longer needed now that ViewManager is gone.
Also, delete "scenic" which is unused.
Tested: mondrian_story_shell_tests; Ran ermine
SCN-1214 #comment
Change-Id: Ie256031fe95be3fa6f6239085fb05d282f39cac1
diff --git a/public/dart/fuchsia_scenic_flutter/BUILD.gn b/public/dart/fuchsia_scenic_flutter/BUILD.gn
index 738f03e..5685585 100644
--- a/public/dart/fuchsia_scenic_flutter/BUILD.gn
+++ b/public/dart/fuchsia_scenic_flutter/BUILD.gn
@@ -15,9 +15,9 @@
sources = [
"child_view.dart",
"child_view_connection.dart",
- "src/child_scene_layer.dart",
"src/child_view.dart",
"src/child_view_connection.dart",
+ "src/child_view_render_box.dart",
]
deps = [
diff --git a/public/dart/fuchsia_scenic_flutter/lib/child_view.dart b/public/dart/fuchsia_scenic_flutter/lib/child_view.dart
index 2bb2dfd..b7a3eb8 100644
--- a/public/dart/fuchsia_scenic_flutter/lib/child_view.dart
+++ b/public/dart/fuchsia_scenic_flutter/lib/child_view.dart
@@ -1,7 +1,7 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-/// A package which provides support for working directly with scenic from
-/// flutter
+/// Utilities for working with Scenic Views through Flutter.
export 'src/child_view.dart';
+export 'src/child_view_connection.dart';
diff --git a/public/dart/fuchsia_scenic_flutter/lib/child_view_connection.dart b/public/dart/fuchsia_scenic_flutter/lib/child_view_connection.dart
index 46a5bfb..30e4c96 100644
--- a/public/dart/fuchsia_scenic_flutter/lib/child_view_connection.dart
+++ b/public/dart/fuchsia_scenic_flutter/lib/child_view_connection.dart
@@ -1,7 +1,6 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-/// A package which provides support for working directly with scenic from
-/// flutter
-export 'src/child_view_connection.dart';
+/// Utilities for working with Scenic Views through Flutter.
+export 'child_view.dart';
diff --git a/public/dart/fuchsia_scenic_flutter/lib/src/child_scene_layer.dart b/public/dart/fuchsia_scenic_flutter/lib/src/child_scene_layer.dart
deleted file mode 100644
index f1e3042..0000000
--- a/public/dart/fuchsia_scenic_flutter/lib/src/child_scene_layer.dart
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2016 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-import 'dart:ui';
-import 'package:flutter/rendering.dart';
-
-/// A layer that represents content from another process.
-class ChildSceneLayer extends Layer {
- /// Creates a layer that displays content rendered by another process.
- ///
- /// All of the arguments must not be null.
- ChildSceneLayer({
- this.offset = Offset.zero,
- this.width = 0.0,
- this.height = 0.0,
- this.sceneHost,
- this.hitTestable = true,
- });
-
- /// Offset from parent in the parent's coordinate system.
- Offset offset;
-
- /// The horizontal extent of the child, in logical pixels.
- double width;
-
- /// The vertical extent of the child, in logical pixels.
- double height;
-
- /// The host site for content rendered by the child.
- SceneHost sceneHost;
-
- /// Whether this child should be included during hit testing.
- ///
- /// Defaults to true.
- bool hitTestable;
-
- @override
- EngineLayer addToScene(SceneBuilder builder,
- [Offset layerOffset = Offset.zero]) {
- builder.addChildScene(
- offset: offset + layerOffset,
- width: width,
- height: height,
- sceneHost: sceneHost,
- hitTestable: hitTestable,
- );
- return null;
- }
-
- @override
- void debugFillProperties(DiagnosticPropertiesBuilder description) {
- super.debugFillProperties(description);
- description
- ..add(DiagnosticsProperty<Offset>('offset', offset))
- ..add(DoubleProperty('width', width))
- ..add(DoubleProperty('height', height))
- ..add(DiagnosticsProperty<SceneHost>('sceneHost', sceneHost))
- ..add(DiagnosticsProperty<bool>('hitTestable', hitTestable));
- }
-
- @override
- S find<S>(Offset regionOffset) => null;
-}
diff --git a/public/dart/fuchsia_scenic_flutter/lib/src/child_view.dart b/public/dart/fuchsia_scenic_flutter/lib/src/child_view.dart
index 6887b1a..3e47a60 100644
--- a/public/dart/fuchsia_scenic_flutter/lib/src/child_view.dart
+++ b/public/dart/fuchsia_scenic_flutter/lib/src/child_view.dart
@@ -2,12 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
-import 'package:fuchsia_logger/logger.dart';
import 'package:meta/meta.dart';
import 'child_view_connection.dart';
+import 'child_view_render_box.dart';
/// A widget that is replaced by content from another process.
///
@@ -34,7 +33,7 @@
@override
RenderBox createRenderObject(BuildContext context) {
- return RenderChildView(
+ return ChildViewRenderBox(
connection: connection,
hitTestable: hitTestable,
focusable: focusable,
@@ -43,14 +42,12 @@
@override
void updateRenderObject(BuildContext context, RenderObject renderObject) {
- if (renderObject is RenderChildView) {
+ assert(renderObject is ChildViewRenderBox);
+ if (renderObject is ChildViewRenderBox) {
renderObject
..connection = connection
..hitTestable = hitTestable
..focusable = focusable;
- } else {
- log.warning('updateRenderObject was called with unknown renderObject: '
- '[$renderObject]');
}
}
}
diff --git a/public/dart/fuchsia_scenic_flutter/lib/src/child_view_connection.dart b/public/dart/fuchsia_scenic_flutter/lib/src/child_view_connection.dart
index de5d830..648d55a 100644
--- a/public/dart/fuchsia_scenic_flutter/lib/src/child_view_connection.dart
+++ b/public/dart/fuchsia_scenic_flutter/lib/src/child_view_connection.dart
@@ -3,303 +3,58 @@
// found in the LICENSE file.
import 'dart:ui';
-
import 'package:fidl_fuchsia_ui_views/fidl_async.dart';
-import 'package:flutter/rendering.dart';
-import 'package:flutter/widgets.dart';
-
-import 'child_scene_layer.dart';
typedef ChildViewConnectionCallback = void Function(
ChildViewConnection connection);
typedef ChildViewConnectionStateCallback = void Function(
ChildViewConnection connection, bool newState);
-/// A connection with a child view.
-///
-/// Used with the [ChildView] widget to display a child view.
+/// A connection to a child view. It can be used to construct a [ChildView]
+/// widget that will display the view's contents on their own layer.
class ChildViewConnection {
- // TODO consider providing this API after MS-2293 is fixed
- // factory ChildViewConnection.launch(String url, Launcher launcher,
- // {InterfaceRequest<ComponentController> controller,
- // InterfaceRequest<ServiceProvider> childServices,
- // ChildViewConnectionCallback onConnected,
- // ChildViewConnectionCallback onDisconnected}) {
- // final Services services = Services();
- // final LaunchInfo launchInfo =
- // LaunchInfo(url: url, directoryRequest: services.request());
- // try {
- // launcher.createComponent(launchInfo, controller);
- // return ChildViewConnection.connect(services,
- // childServices: childServices,
- // onConnected: onConnected,
- // onDisconnected: onDisconnected);
- // } finally {
- // services.close();
- // }
- // }
-
- // TODO consider providing this API after MS-2293 is fixed
- // factory ChildViewConnection.connect(Services services,
- // {InterfaceRequest<ServiceProvider> childServices,
- // ChildViewConnectionCallback onConnected,
- // ChildViewConnectionCallback onDisconnected}) {
- // final app.ViewProviderProxy viewProvider = app.ViewProviderProxy();
- // services.connectToService(viewProvider.ctrl);
- // try {
- // EventPairPair viewTokens = EventPairPair();
- // assert(viewTokens.status == ZX.OK);
-
- // viewProvider.createView(viewTokens.second, childServices, null);
- // return ChildViewConnection.fromViewHolderToken(viewTokens.first,
- // onConnected: onConnected, onDisconnected: onDisconnected);
- // } finally {
- // viewProvider.ctrl.close();
- // }
- // }
-
- // Status callbacks.
- final ChildViewConnectionCallback _onConnectedCallback;
- final ChildViewConnectionCallback _onDisconnectedCallback;
- final ChildViewConnectionStateCallback _onStateChangedCallback;
- VoidCallback _onViewInfoAvailable;
-
- // Token and SceneHost used to reference and render content from a remote
- // Scene.
- ViewHolderToken _viewHolderToken;
+ /// SceneHost used to reference and render content from a remote Scene.
+ SceneHost get sceneHost => _sceneHost;
SceneHost _sceneHost;
- // The number of render objects attached to this view. In between frames, we
- // might have more than one connected if we get added to a render object
- // before we get removed from the old render object. By the time we get around
- // to computing our layout, we must be back to just having one render object.
- int _attachments = 0;
- bool get _attached => _attachments > 0;
-
/// Creates this connection from a ViewHolderToken.
ChildViewConnection(ViewHolderToken viewHolderToken,
{ChildViewConnectionCallback onAvailable,
ChildViewConnectionCallback onUnavailable,
ChildViewConnectionStateCallback onStateChanged})
- : _onConnectedCallback = onAvailable,
- _onDisconnectedCallback = onUnavailable,
- _onStateChangedCallback = onStateChanged,
- _viewHolderToken = viewHolderToken {
- assert(_viewHolderToken?.value != null);
+ : assert(viewHolderToken?.value != null) {
+ if (viewHolderToken.value.isValid) {
+ _sceneHost = SceneHost.fromViewHolderToken(
+ viewHolderToken.value.passHandle(),
+ (onAvailable == null)
+ ? null
+ : () {
+ onAvailable(this);
+ },
+ (onUnavailable == null)
+ ? null
+ : () {
+ onUnavailable(this);
+ },
+ (onStateChanged == null)
+ ? null
+ : (bool state) {
+ onStateChanged(this, state);
+ });
+ }
}
- /// Only call when the connection is available.
+ /// Requests that focus be transferred to the remote Scene represented by
+ /// this connection.
void requestFocus() {
// TODO(SCN-1186): Use new mechanism to implement RequestFocus.
}
- /// Callback that is fired when the |ChildViewConnection|'s View is connected.
- void _onConnected() {
- if (_onViewInfoAvailable != null) {
- _onViewInfoAvailable();
- }
- if (_onConnectedCallback != null) {
- _onConnectedCallback(this);
- }
- }
-
- /// Callback that is fired when the |ChildViewConnection|'s View is disconnected.
- void _onDisconnected() {
- if (_onDisconnectedCallback != null) {
- _onDisconnectedCallback(this);
- }
- }
-
- /// Callback that is fired when the |ChildViewConnection|'s View changes state.
- void _onStateChanged(bool newState) {
- if (_onStateChangedCallback != null) {
- _onStateChangedCallback(this, newState);
- }
- }
-
- void _attach() {
- if (_sceneHost == null) {
- assert(!_attached);
- assert(_viewHolderToken.value.isValid);
- _sceneHost = SceneHost.fromViewHolderToken(
- _viewHolderToken.value.passHandle(),
- _onConnected,
- _onDisconnected,
- _onStateChanged);
- }
- ++_attachments;
- }
-
- void _detach() {
- assert(_attached);
- --_attachments;
- }
-
- void _setChildProperties(
- double width,
- double height,
- double insetTop,
- double insetRight,
- double insetBottom,
- double insetLeft,
- bool focusable,
- ) {
- assert(_attached);
- assert(_attachments == 1);
-
- _sceneHost.setProperties(
+ /// Sets properties on the remote Scene represented by this connection.
+ void setChildProperties(double width, double height, double insetTop,
+ double insetRight, double insetBottom, double insetLeft,
+ {bool focusable = true}) {
+ _sceneHost?.setProperties(
width, height, insetTop, insetRight, insetBottom, insetLeft, focusable);
}
}
-
-/// A |RenderBox| that allows hit-testing and focusing of a |ChildViewConnection|.
-class RenderChildView extends RenderBox {
- ChildViewConnection _connection;
-
- bool _hitTestable;
- bool _focusable;
-
- double _width;
- double _height;
-
- /// Creates a child view render object.
- RenderChildView({
- ChildViewConnection connection,
- bool hitTestable = true,
- bool focusable = true,
- }) : _connection = connection,
- _hitTestable = hitTestable,
- _focusable = focusable,
- assert(hitTestable != null);
-
- /// The child to display.
- ChildViewConnection get connection => _connection;
- set connection(ChildViewConnection value) {
- if (value == _connection) {
- return;
- }
- if (attached && _connection != null) {
- _connection._detach();
- assert(_connection._onViewInfoAvailable != null);
- _connection._onViewInfoAvailable = null;
- }
- _connection = value;
- if (attached && _connection != null) {
- _connection._attach();
- assert(_connection._onViewInfoAvailable == null);
- _connection._onViewInfoAvailable = markNeedsPaint;
- }
- if (_connection == null) {
- markNeedsPaint();
- } else {
- markNeedsLayout();
- }
- }
-
- /// Whether this child should be able to recieve focus events
- bool get focusable => _focusable;
-
- set focusable(bool value) {
- assert(value != null);
- if (value == _focusable) {
- return;
- }
- _focusable = value;
- if (_connection != null) {
- markNeedsLayout();
- }
- }
-
- /// Whether this child should be included during hit testing.
- bool get hitTestable => _hitTestable;
-
- set hitTestable(bool value) {
- assert(value != null);
- if (value == _hitTestable) {
- return;
- }
- _hitTestable = value;
- if (_connection != null) {
- markNeedsLayout();
- }
- }
-
- @override
- bool get alwaysNeedsCompositing => true;
-
- @override
- bool hitTestSelf(Offset position) => true;
-
- @override
- void debugFillProperties(DiagnosticPropertiesBuilder description) {
- super.debugFillProperties(description);
- description.add(
- DiagnosticsProperty<ChildViewConnection>(
- 'connection',
- connection,
- ),
- );
- }
-
- @override
- void attach(PipelineOwner owner) {
- super.attach(owner);
- if (_connection != null) {
- _connection._attach();
- assert(_connection._onViewInfoAvailable == null);
- _connection._onViewInfoAvailable = markNeedsPaint;
- }
- }
-
- @override
- void detach() {
- if (_connection != null) {
- _connection._detach();
- assert(_connection._onViewInfoAvailable != null);
- _connection._onViewInfoAvailable = null;
- }
- super.detach();
- }
-
- @override
- void paint(PaintingContext context, Offset offset) {
- // Ignore if we have no child view connection.
- assert(needsCompositing);
- if (_connection == null) {
- return;
- }
-
- context.addLayer(ChildSceneLayer(
- offset: offset,
- width: _width,
- height: _height,
- sceneHost: _connection._sceneHost,
- hitTestable: hitTestable,
- ));
- }
-
- @override
- void performLayout() {
- size = constraints.biggest;
-
- // Ignore if we have no child view connection.
- if (_connection == null) {
- return;
- }
-
- if (_width != null && _height != null) {
- double deltaWidth = (_width - size.width).abs();
- double deltaHeight = (_height - size.height).abs();
-
- // Ignore insignificant changes in size that are likely rounding errors.
- if (deltaWidth < 0.0001 && deltaHeight < 0.0001) {
- return;
- }
- }
-
- _width = size.width;
- _height = size.height;
- _connection._setChildProperties(
- _width, _height, 0.0, 0.0, 0.0, 0.0, _focusable);
- }
-}
diff --git a/public/dart/fuchsia_scenic_flutter/lib/src/child_view_render_box.dart b/public/dart/fuchsia_scenic_flutter/lib/src/child_view_render_box.dart
new file mode 100644
index 0000000..2b8660b
--- /dev/null
+++ b/public/dart/fuchsia_scenic_flutter/lib/src/child_view_render_box.dart
@@ -0,0 +1,189 @@
+// Copyright 2018 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:ui';
+import 'package:flutter/rendering.dart';
+
+import 'child_view_connection.dart';
+
+/// A |RenderBox| that allows hit-testing and focusing of a |ChildViewConnection|. Renders itself by creating a |ChildSceneLayer|.
+class ChildViewRenderBox extends RenderBox {
+ ChildViewConnection _connection;
+
+ bool _hitTestable;
+ bool _focusable;
+
+ double _width;
+ double _height;
+
+ /// Creates a |RenderBox| for the child view.
+ ChildViewRenderBox({
+ ChildViewConnection connection,
+ bool hitTestable = true,
+ bool focusable = true,
+ }) : _connection = connection,
+ _hitTestable = hitTestable,
+ _focusable = focusable,
+ assert(hitTestable != null);
+
+ /// The child to display.
+ ChildViewConnection get connection => _connection;
+ set connection(ChildViewConnection value) {
+ if (value == _connection) {
+ return;
+ }
+ _connection = value;
+ if (_connection != null) {
+ markNeedsLayout();
+ }
+ markNeedsPaint();
+ }
+
+ /// Whether this child should be able to recieve focus events
+ bool get focusable => _focusable;
+
+ set focusable(bool value) {
+ assert(value != null);
+ if (value == _focusable) {
+ return;
+ }
+ _focusable = value;
+ if (_connection != null) {
+ markNeedsLayout();
+ }
+ }
+
+ /// Whether this child should be included during hit testing.
+ bool get hitTestable => _hitTestable;
+
+ set hitTestable(bool value) {
+ assert(value != null);
+ if (value == _hitTestable) {
+ return;
+ }
+ _hitTestable = value;
+ if (_connection != null) {
+ markNeedsPaint();
+ }
+ }
+
+ @override
+ bool get alwaysNeedsCompositing => true;
+
+ @override
+ bool hitTestSelf(Offset position) => true;
+
+ @override
+ void debugFillProperties(DiagnosticPropertiesBuilder description) {
+ super.debugFillProperties(description);
+ description.add(
+ DiagnosticsProperty<ChildViewConnection>(
+ 'connection',
+ connection,
+ ),
+ );
+ }
+
+ @override
+ void paint(PaintingContext context, Offset offset) {
+ // Ignore if we have no child view connection.
+ assert(needsCompositing);
+ if (_connection?.sceneHost == null) {
+ return;
+ }
+
+ context.addLayer(_ChildSceneLayer(
+ offset: offset,
+ width: _width,
+ height: _height,
+ sceneHost: _connection.sceneHost,
+ hitTestable: _hitTestable,
+ ));
+ }
+
+ @override
+ void performLayout() {
+ size = constraints.biggest;
+
+ // Ignore if we have no child view connection.
+ if (_connection == null) {
+ return;
+ }
+
+ if (_width != null && _height != null) {
+ double deltaWidth = (_width - size.width).abs();
+ double deltaHeight = (_height - size.height).abs();
+
+ // Ignore insignificant changes in size that are likely rounding errors.
+ if (deltaWidth < 0.0001 && deltaHeight < 0.0001) {
+ return;
+ }
+ }
+
+ _width = size.width;
+ _height = size.height;
+ _connection.setChildProperties(_width, _height, 0.0, 0.0, 0.0, 0.0,
+ focusable: _focusable);
+ }
+}
+
+/// A layer that represents content from another process.
+class _ChildSceneLayer extends Layer {
+ /// Creates a layer that displays content rendered by another process.
+ ///
+ /// All of the arguments must not be null.
+ _ChildSceneLayer({
+ this.offset = Offset.zero,
+ this.width = 0.0,
+ this.height = 0.0,
+ this.sceneHost,
+ this.hitTestable = true,
+ });
+
+ /// Offset from parent in the parent's coordinate system.
+ Offset offset;
+
+ /// The horizontal extent of the child, in logical pixels.
+ double width;
+
+ /// The vertical extent of the child, in logical pixels.
+ double height;
+
+ /// The host site for content rendered by the child.
+ SceneHost sceneHost;
+
+ /// Whether this child should be included during hit testing.
+ ///
+ /// Defaults to true.
+ bool hitTestable;
+
+ @override
+ EngineLayer addToScene(SceneBuilder builder,
+ [Offset layerOffset = Offset.zero]) {
+ assert(sceneHost != null);
+
+ builder.addChildScene(
+ offset: offset + layerOffset,
+ width: width,
+ height: height,
+ sceneHost: sceneHost,
+ hitTestable: hitTestable,
+ );
+ return null;
+ }
+
+ @override
+ void debugFillProperties(DiagnosticPropertiesBuilder description) {
+ super.debugFillProperties(description);
+ description
+ ..add(DiagnosticsProperty<Offset>('offset', offset))
+ ..add(DoubleProperty('width', width))
+ ..add(DoubleProperty('height', height))
+ ..add(DiagnosticsProperty<SceneHost>('sceneHost', sceneHost))
+ ..add(DiagnosticsProperty<bool>('hitTestable', hitTestable));
+ }
+
+ @override
+ S find<S>(Offset regionOffset) => null;
+}
diff --git a/public/dart/scenic/BUILD.gn b/public/dart/scenic/BUILD.gn
deleted file mode 100644
index 5317003..0000000
--- a/public/dart/scenic/BUILD.gn
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright 2018 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import("//build/dart/dart_library.gni")
-
-dart_library("scenic") {
- package_name = "scenic"
-
- sdk_category = "partner"
-
- source_dir = "lib"
-
- sources = [
- "child_view.dart",
- ]
-
- deps = []
-}
diff --git a/public/dart/scenic/analysis_options.yaml b/public/dart/scenic/analysis_options.yaml
deleted file mode 100644
index 48e8ec9..0000000
--- a/public/dart/scenic/analysis_options.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
-# Copyright 2018 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-include: ../../analysis_options.yaml
diff --git a/public/dart/scenic/lib/child_view.dart b/public/dart/scenic/lib/child_view.dart
deleted file mode 100644
index 3da5d61..0000000
--- a/public/dart/scenic/lib/child_view.dart
+++ /dev/null
@@ -1,6 +0,0 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-/// A widget which is used to embed scenic views in a Flutter Widget tree.
-library child_view;
diff --git a/public/dart/scenic/pubspec.yaml b/public/dart/scenic/pubspec.yaml
deleted file mode 100644
index 04b5a1a..0000000
--- a/public/dart/scenic/pubspec.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
-# Copyright 2018 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-name: scenic
-environment:
- sdk: '>=2.0.0 <3.0.0'