From 417f08d1ded7953c636196085f1d6b849878a43c Mon Sep 17 00:00:00 2001 From: Mouad Debbar Date: Thu, 2 Dec 2021 14:34:00 -0500 Subject: [PATCH 1/2] [web] Clean up lib/ui.dart --- ci/licenses_golden/licenses_flutter | 1 + lib/web_ui/lib/ui.dart | 59 +-------------------------- lib/web_ui/lib/util.dart | 63 +++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 58 deletions(-) create mode 100644 lib/web_ui/lib/util.dart diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 9b3e97e3cfeaf..547e989776e0d 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -660,6 +660,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/window.dart FILE: ../../../flutter/lib/web_ui/lib/text.dart FILE: ../../../flutter/lib/web_ui/lib/tile_mode.dart FILE: ../../../flutter/lib/web_ui/lib/ui.dart +FILE: ../../../flutter/lib/web_ui/lib/util.dart FILE: ../../../flutter/lib/web_ui/lib/window.dart FILE: ../../../flutter/lib/web_ui/tool/unicode_sync_script.dart FILE: ../../../flutter/runtime/dart_isolate.cc diff --git a/lib/web_ui/lib/ui.dart b/lib/web_ui/lib/ui.dart index e47bb5a2dc577..baa98faa99603 100644 --- a/lib/web_ui/lib/ui.dart +++ b/lib/web_ui/lib/ui.dart @@ -34,62 +34,5 @@ part 'pointer.dart'; part 'semantics.dart'; part 'text.dart'; part 'tile_mode.dart'; +part 'util.dart'; part 'window.dart'; - -/// Provides a compile time constant to customize flutter framework and other -/// users of ui engine for web runtime. -const bool isWeb = true; - -/// Web specific SMI. Used by bitfield. The 0x3FFFFFFFFFFFFFFF used on VM -/// is not supported on Web platform. -const int kMaxUnsignedSMI = -1; - -void webOnlyInitializeEngine() { - engine.initializeEngine(); -} - -void webOnlySetPluginHandler(Future Function(String, ByteData?, PlatformMessageResponseCallback?) handler) { - engine.pluginMessageCallHandler = handler; -} - -// TODO(yjbanov): The code below was temporarily moved from lib/web_ui/lib/src/engine/platform_views.dart -// during the NNBD migration so that `dart:ui` does not have to export `dart:_engine`. NNBD -// does not allow exported non-migrated libraries from migrated libraries. When `dart:_engine` -// is migrated, we can move it back. - -/// A function which takes a unique `id` and creates an HTML element. -typedef PlatformViewFactory = html.Element Function(int viewId); - -/// A registry for factories that create platform views. -class PlatformViewRegistry { - /// Register [viewTypeId] as being creating by the given [factory]. - bool registerViewFactory(String viewTypeId, PlatformViewFactory viewFactory, - {bool isVisible = true}) { - // TODO(web): Deprecate this once there's another way of calling `registerFactory` (js interop?) - return engine.platformViewManager - .registerFactory(viewTypeId, viewFactory, isVisible: isVisible); - } -} - -/// The platform view registry for this app. -final PlatformViewRegistry platformViewRegistry = PlatformViewRegistry(); - -// TODO(yjbanov): remove _Callback, _Callbacker, and _futurize. They are here only -// because the analyzer wasn't able to infer the correct types during -// NNBD migration. -typedef _Callback = void Function(T result); -typedef _Callbacker = String? Function(_Callback callback); -Future _futurize(_Callbacker callbacker) { - final Completer completer = Completer.sync(); - final String? error = callbacker((T t) { - if (t == null) { - completer.completeError(Exception('operation failed')); - } else { - completer.complete(t); - } - }); - if (error != null) { - throw Exception(error); - } - return completer.future; -} diff --git a/lib/web_ui/lib/util.dart b/lib/web_ui/lib/util.dart new file mode 100644 index 0000000000000..d309496f195d6 --- /dev/null +++ b/lib/web_ui/lib/util.dart @@ -0,0 +1,63 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +part of ui; + +/// Provides a compile time constant to customize flutter framework and other +/// users of ui engine for web runtime. +const bool isWeb = true; + +/// Web specific SMI. Used by bitfield. The 0x3FFFFFFFFFFFFFFF used on VM +/// is not supported on Web platform. +const int kMaxUnsignedSMI = -1; + +void webOnlyInitializeEngine() { + engine.initializeEngine(); +} + +void webOnlySetPluginHandler(Future Function(String, ByteData?, PlatformMessageResponseCallback?) handler) { + engine.pluginMessageCallHandler = handler; +} + +// TODO(yjbanov): The code below was temporarily moved from lib/web_ui/lib/src/engine/platform_views.dart +// during the NNBD migration so that `dart:ui` does not have to export `dart:_engine`. NNBD +// does not allow exported non-migrated libraries from migrated libraries. When `dart:_engine` +// is migrated, we can move it back. + +/// A function which takes a unique `id` and creates an HTML element. +typedef PlatformViewFactory = html.Element Function(int viewId); + +/// A registry for factories that create platform views. +class PlatformViewRegistry { + /// Register [viewTypeId] as being creating by the given [factory]. + bool registerViewFactory(String viewTypeId, PlatformViewFactory viewFactory, + {bool isVisible = true}) { + // TODO(web): Deprecate this once there's another way of calling `registerFactory` (js interop?) + return engine.platformViewManager + .registerFactory(viewTypeId, viewFactory, isVisible: isVisible); + } +} + +/// The platform view registry for this app. +final PlatformViewRegistry platformViewRegistry = PlatformViewRegistry(); + +// TODO(yjbanov): remove _Callback, _Callbacker, and _futurize. They are here only +// because the analyzer wasn't able to infer the correct types during +// NNBD migration. +typedef _Callback = void Function(T result); +typedef _Callbacker = String? Function(_Callback callback); +Future _futurize(_Callbacker callbacker) { + final Completer completer = Completer.sync(); + final String? error = callbacker((T t) { + if (t == null) { + completer.completeError(Exception('operation failed')); + } else { + completer.complete(t); + } + }); + if (error != null) { + throw Exception(error); + } + return completer.future; +} From e784571c1478ea58148b10811dee48aca48b7fc2 Mon Sep 17 00:00:00 2001 From: Mouad Debbar Date: Thu, 20 Jan 2022 13:08:02 -0500 Subject: [PATCH 2/2] move code to lib/initialization.dart --- ci/licenses_golden/licenses_flutter | 1 - lib/web_ui/lib/initialization.dart | 58 ++++++++++++++++++++++++++ lib/web_ui/lib/ui.dart | 1 - lib/web_ui/lib/util.dart | 63 ----------------------------- 4 files changed, 58 insertions(+), 65 deletions(-) delete mode 100644 lib/web_ui/lib/util.dart diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 547e989776e0d..9b3e97e3cfeaf 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -660,7 +660,6 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/window.dart FILE: ../../../flutter/lib/web_ui/lib/text.dart FILE: ../../../flutter/lib/web_ui/lib/tile_mode.dart FILE: ../../../flutter/lib/web_ui/lib/ui.dart -FILE: ../../../flutter/lib/web_ui/lib/util.dart FILE: ../../../flutter/lib/web_ui/lib/window.dart FILE: ../../../flutter/lib/web_ui/tool/unicode_sync_script.dart FILE: ../../../flutter/runtime/dart_isolate.cc diff --git a/lib/web_ui/lib/initialization.dart b/lib/web_ui/lib/initialization.dart index 13662b627b2a5..be7572cedcccc 100644 --- a/lib/web_ui/lib/initialization.dart +++ b/lib/web_ui/lib/initialization.dart @@ -95,3 +95,61 @@ set debugEmulateFlutterTesterEnvironment(bool value) { bool _debugEmulateFlutterTesterEnvironment = false; engine.AssetManager get webOnlyAssetManager => _assetManager!; engine.FontCollection get webOnlyFontCollection => _fontCollection!; + +/// Provides a compile time constant to customize flutter framework and other +/// users of ui engine for web runtime. +const bool isWeb = true; + +/// Web specific SMI. Used by bitfield. The 0x3FFFFFFFFFFFFFFF used on VM +/// is not supported on Web platform. +const int kMaxUnsignedSMI = -1; + +void webOnlyInitializeEngine() { + engine.initializeEngine(); +} + +void webOnlySetPluginHandler(Future Function(String, ByteData?, PlatformMessageResponseCallback?) handler) { + engine.pluginMessageCallHandler = handler; +} + +// TODO(yjbanov): The code below was temporarily moved from lib/web_ui/lib/src/engine/platform_views.dart +// during the NNBD migration so that `dart:ui` does not have to export `dart:_engine`. NNBD +// does not allow exported non-migrated libraries from migrated libraries. When `dart:_engine` +// is migrated, we can move it back. + +/// A function which takes a unique `id` and creates an HTML element. +typedef PlatformViewFactory = html.Element Function(int viewId); + +/// A registry for factories that create platform views. +class PlatformViewRegistry { + /// Register [viewTypeId] as being creating by the given [factory]. + bool registerViewFactory(String viewTypeId, PlatformViewFactory viewFactory, + {bool isVisible = true}) { + // TODO(web): Deprecate this once there's another way of calling `registerFactory` (js interop?) + return engine.platformViewManager + .registerFactory(viewTypeId, viewFactory, isVisible: isVisible); + } +} + +/// The platform view registry for this app. +final PlatformViewRegistry platformViewRegistry = PlatformViewRegistry(); + +// TODO(yjbanov): remove _Callback, _Callbacker, and _futurize. They are here only +// because the analyzer wasn't able to infer the correct types during +// NNBD migration. +typedef _Callback = void Function(T result); +typedef _Callbacker = String? Function(_Callback callback); +Future _futurize(_Callbacker callbacker) { + final Completer completer = Completer.sync(); + final String? error = callbacker((T t) { + if (t == null) { + completer.completeError(Exception('operation failed')); + } else { + completer.complete(t); + } + }); + if (error != null) { + throw Exception(error); + } + return completer.future; +} diff --git a/lib/web_ui/lib/ui.dart b/lib/web_ui/lib/ui.dart index baa98faa99603..baa2a5c2b7a26 100644 --- a/lib/web_ui/lib/ui.dart +++ b/lib/web_ui/lib/ui.dart @@ -34,5 +34,4 @@ part 'pointer.dart'; part 'semantics.dart'; part 'text.dart'; part 'tile_mode.dart'; -part 'util.dart'; part 'window.dart'; diff --git a/lib/web_ui/lib/util.dart b/lib/web_ui/lib/util.dart deleted file mode 100644 index d309496f195d6..0000000000000 --- a/lib/web_ui/lib/util.dart +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -part of ui; - -/// Provides a compile time constant to customize flutter framework and other -/// users of ui engine for web runtime. -const bool isWeb = true; - -/// Web specific SMI. Used by bitfield. The 0x3FFFFFFFFFFFFFFF used on VM -/// is not supported on Web platform. -const int kMaxUnsignedSMI = -1; - -void webOnlyInitializeEngine() { - engine.initializeEngine(); -} - -void webOnlySetPluginHandler(Future Function(String, ByteData?, PlatformMessageResponseCallback?) handler) { - engine.pluginMessageCallHandler = handler; -} - -// TODO(yjbanov): The code below was temporarily moved from lib/web_ui/lib/src/engine/platform_views.dart -// during the NNBD migration so that `dart:ui` does not have to export `dart:_engine`. NNBD -// does not allow exported non-migrated libraries from migrated libraries. When `dart:_engine` -// is migrated, we can move it back. - -/// A function which takes a unique `id` and creates an HTML element. -typedef PlatformViewFactory = html.Element Function(int viewId); - -/// A registry for factories that create platform views. -class PlatformViewRegistry { - /// Register [viewTypeId] as being creating by the given [factory]. - bool registerViewFactory(String viewTypeId, PlatformViewFactory viewFactory, - {bool isVisible = true}) { - // TODO(web): Deprecate this once there's another way of calling `registerFactory` (js interop?) - return engine.platformViewManager - .registerFactory(viewTypeId, viewFactory, isVisible: isVisible); - } -} - -/// The platform view registry for this app. -final PlatformViewRegistry platformViewRegistry = PlatformViewRegistry(); - -// TODO(yjbanov): remove _Callback, _Callbacker, and _futurize. They are here only -// because the analyzer wasn't able to infer the correct types during -// NNBD migration. -typedef _Callback = void Function(T result); -typedef _Callbacker = String? Function(_Callback callback); -Future _futurize(_Callbacker callbacker) { - final Completer completer = Completer.sync(); - final String? error = callbacker((T t) { - if (t == null) { - completer.completeError(Exception('operation failed')); - } else { - completer.complete(t); - } - }); - if (error != null) { - throw Exception(error); - } - return completer.future; -}