From 9d914b29359c3d49f8c82ecee53dbc2aaa6571e9 Mon Sep 17 00:00:00 2001 From: zjt123 Date: Mon, 22 May 2023 21:53:41 +0800 Subject: [PATCH 1/8] feat:document add visibilitychange and support api visibilityState, hidden --- bridge/core/binding_call_methods.json5 | 2 + bridge/core/dom/document.cc | 5 ++ bridge/core/dom/document.d.ts | 2 + bridge/core/dom/document.h | 2 + integration_tests/specs/dom/nodes/document.ts | 8 ++ webf/lib/src/dom/binding.dart | 4 +- webf/lib/src/dom/document.dart | 76 ++++++++++++++++++- webf/lib/src/launcher/controller.dart | 26 +++++-- 8 files changed, 114 insertions(+), 11 deletions(-) diff --git a/bridge/core/binding_call_methods.json5 b/bridge/core/binding_call_methods.json5 index 71c57a24b9..f4dc74c486 100644 --- a/bridge/core/binding_call_methods.json5 +++ b/bridge/core/binding_call_methods.json5 @@ -170,5 +170,7 @@ "domain", "compatMode", "readyState", + "visibilityState", + "hidden", ] } diff --git a/bridge/core/dom/document.cc b/bridge/core/dom/document.cc index a8b4137777..06a29bc5d1 100644 --- a/bridge/core/dom/document.cc +++ b/bridge/core/dom/document.cc @@ -236,6 +236,11 @@ AtomicString Document::readyState() { return NativeValueConverter::FromNativeValue(ctx(), std::move(dart_result)); } +bool Document::hidden() { + NativeValue dart_result = GetBindingProperty(binding_call_methods::khidden, ASSERT_NO_EXCEPTION()); + return NativeValueConverter::FromNativeValue(dart_result); +} + template static inline bool IsValidNameASCII(const CharType* characters, unsigned length) { CharType c = characters[0]; diff --git a/bridge/core/dom/document.d.ts b/bridge/core/dom/document.d.ts index 47b3cbd44f..08e4db7324 100644 --- a/bridge/core/dom/document.d.ts +++ b/bridge/core/dom/document.d.ts @@ -22,6 +22,8 @@ interface Document extends Node { readonly location: any; readonly compatMode: string; readonly readyState: string; + readonly visibilityState: DartImpl; + readonly hidden: boolean; createElement(tagName: string, options?: any): Element; createElementNS(uri: string | null, tagName: string, options?: any): Element; diff --git a/bridge/core/dom/document.h b/bridge/core/dom/document.h index 2004ed3ec9..989fbaf79b 100644 --- a/bridge/core/dom/document.h +++ b/bridge/core/dom/document.h @@ -77,6 +77,8 @@ class Document : public ContainerNode, public TreeScope { AtomicString readyState(); DEFINE_DOCUMENT_ATTRIBUTE_EVENT_LISTENER(readystatechange, kreadystatechange); + bool hidden(); + // The following implements the rule from HTML 4 for what valid names are. static bool IsValidName(const AtomicString& name); diff --git a/integration_tests/specs/dom/nodes/document.ts b/integration_tests/specs/dom/nodes/document.ts index 7b43731b96..0458d64d4a 100644 --- a/integration_tests/specs/dom/nodes/document.ts +++ b/integration_tests/specs/dom/nodes/document.ts @@ -44,4 +44,12 @@ describe('Document api', () => { it('document.readyState', () => { expect(document.readyState).not.toBeUndefined(); }); + + it('document.visibilityState', () => { + expect(document.visibilityState).not.toBeUndefined(); + }); + + it('document.hidden', () => { + expect(document.hidden).not.toBeUndefined(); + }); }); diff --git a/webf/lib/src/dom/binding.dart b/webf/lib/src/dom/binding.dart index 5d1b26487b..11d8890c08 100644 --- a/webf/lib/src/dom/binding.dart +++ b/webf/lib/src/dom/binding.dart @@ -73,7 +73,7 @@ abstract class ElementsBindingObserver { /// settings. /// /// This method exposes notifications from [Window.onLocaleChanged]. - void didChangeLocales(List locale) {} + void didChangeLocales(List? locale) {} /// Called when the system puts the app in the background or returns /// the app to the foreground. @@ -192,7 +192,7 @@ mixin ElementsBinding /// notification is received. @protected @mustCallSuper - void dispatchLocalesChanged(List locales) { + void dispatchLocalesChanged(List? locales) { for (ElementsBindingObserver observer in _observers) observer.didChangeLocales(locales); } diff --git a/webf/lib/src/dom/document.dart b/webf/lib/src/dom/document.dart index 7e8c1233b8..0f02567c76 100644 --- a/webf/lib/src/dom/document.dart +++ b/webf/lib/src/dom/document.dart @@ -6,6 +6,7 @@ import 'dart:collection'; import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; +import 'package:flutter/scheduler.dart'; import 'package:webf/css.dart'; import 'package:webf/dom.dart'; import 'package:webf/html.dart'; @@ -61,8 +62,9 @@ class _InactiveRenderObjects { } } enum DocumentReadyState { loading, interactive, complete} +enum VisibilityState { visible, hidden} -class Document extends ContainerNode { +class Document extends ContainerNode implements ElementsBindingObserver { final WebFController controller; final AnimationTimeline animationTimeline = AnimationTimeline(); RenderViewportBox? _viewport; @@ -82,6 +84,7 @@ class Document extends ContainerNode { final String _compatMode = 'CSS1Compat'; String? _readyState; + VisibilityState _visibilityState = VisibilityState.hidden; @override bool get isConnected => true; @@ -180,6 +183,8 @@ class Document extends ContainerNode { properties['compatMode'] = BindingObjectProperty(getter: () => compatMode,); properties['domain'] = BindingObjectProperty(getter: () => domain, setter: (value) => domain = value); properties['readyState'] = BindingObjectProperty(getter: () => readyState,); + properties['visibilityState'] = BindingObjectProperty(getter: () => visibilityState,); + properties['hidden'] = BindingObjectProperty(getter: () => hidden,); } @override @@ -211,6 +216,19 @@ class Document extends ContainerNode { } } + get visibilityState { + return _visibilityState.name; + } + + get hidden { + return _visibilityState == VisibilityState.visible; + } + + void _visibilityChange(VisibilityState state) { + _visibilityState = state; + ownerDocument.dispatchEvent(Event('visibilitychange')); + } + void _dispatchReadyStateChangeEvent() { Event event = Event(EVENT_READY_STATE_CHANGE); defaultView.dispatchEvent(event); @@ -313,6 +331,8 @@ class Document extends ContainerNode { // Init with viewport size. element.renderStyle.width = CSSLengthValue(viewport.viewportSize.width, CSSLengthType.PX); element.renderStyle.height = CSSLengthValue(viewport.viewportSize.height, CSSLengthType.PX); + _visibilityState = VisibilityState.visible; + controller.view.addObserver(this); } else { // Detach document element. viewport.removeAll(); @@ -452,6 +472,7 @@ class Document extends ContainerNode { @override Future dispose() async { + controller.view.removeObserver(this); _viewport = null; gestureListener = null; styleSheets.clear(); @@ -459,4 +480,57 @@ class Document extends ContainerNode { cookie.clearCookie(); super.dispose(); } + + @override + void didChangeAccessibilityFeatures() { + // TODO: implement didChangeAccessibilityFeatures + } + + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + switch (state) { + case AppLifecycleState.resumed: + _visibilityChange(VisibilityState.visible); + break; + case AppLifecycleState.paused: + _visibilityChange(VisibilityState.hidden); + break; + } + } + + @override + void didChangeLocales(List? locale) { + // TODO: implement didChangeLocales + } + + @override + void didChangeMetrics() { + // TODO: implement didChangeMetrics + } + + @override + void didChangePlatformBrightness() { + // TODO: implement didChangePlatformBrightness + } + + @override + void didChangeTextScaleFactor() { + // TODO: implement didChangeTextScaleFactor + } + + @override + void didHaveMemoryPressure() { + // TODO: implement didHaveMemoryPressure + } + + @override + Future didPopRoute() { + return Future.value(false); + } + + @override + Future didPushRoute(String route) { + return Future.value(false); + } + } diff --git a/webf/lib/src/launcher/controller.dart b/webf/lib/src/launcher/controller.dart index 9b53090745..318b5e4bd6 100644 --- a/webf/lib/src/launcher/controller.dart +++ b/webf/lib/src/launcher/controller.dart @@ -617,17 +617,17 @@ class WebFViewController implements WidgetsBindingObserver, ElementsBindingObser @override void didChangeAccessibilityFeatures() { - // TODO: implement didChangeAccessibilityFeatures + for (ElementsBindingObserver observer in _observers) observer.didChangeAccessibilityFeatures(); } @override void didChangeAppLifecycleState(AppLifecycleState state) { - // TODO: implement didChangeAppLifecycleState + for (ElementsBindingObserver observer in _observers) observer.didChangeAppLifecycleState(state); } @override void didChangeLocales(List? locales) { - // TODO: implement didChangeLocales + for (ElementsBindingObserver observer in _observers) observer.didChangeLocales(locales); } ui.WindowPadding _prevViewInsets = ui.window.viewInsets; @@ -662,32 +662,37 @@ class WebFViewController implements WidgetsBindingObserver, ElementsBindingObser } } _prevViewInsets = ui.window.viewInsets; + for (ElementsBindingObserver observer in _observers) observer.didChangeMetrics(); } @override void didChangePlatformBrightness() { - // TODO: implement didChangePlatformBrightness + for (ElementsBindingObserver observer in _observers) observer.didChangePlatformBrightness(); } @override void didChangeTextScaleFactor() { - // TODO: implement didChangeTextScaleFactor + for (ElementsBindingObserver observer in _observers) observer.didChangeTextScaleFactor(); } @override void didHaveMemoryPressure() { - // TODO: implement didHaveMemoryPressure + for (ElementsBindingObserver observer in _observers) observer.didHaveMemoryPressure(); } @override Future didPopRoute() async { - // TODO: implement didPopRoute + for (ElementsBindingObserver observer in List.from(_observers)) { + if (await observer.didPopRoute()) return Future.value(true); + } return false; } @override Future didPushRoute(String route) async { - // TODO: implement didPushRoute + for (ElementsBindingObserver observer in List.from(_observers)) { + if (await observer.didPushRoute(route)) return Future.value(true); + } return false; } @@ -696,6 +701,11 @@ class WebFViewController implements WidgetsBindingObserver, ElementsBindingObser // TODO: implement didPushRouteInformation return false; } + + final List _observers = []; + void addObserver(ElementsBindingObserver observer) => _observers.add(observer); + bool removeObserver(ElementsBindingObserver observer) => _observers.remove(observer); + } // An controller designed to control kraken's functional modules. From e893f07e8d07784c1a103f5f754865c93db96f0a Mon Sep 17 00:00:00 2001 From: openwebf-bot Date: Mon, 22 May 2023 13:54:40 +0000 Subject: [PATCH 2/8] Committing clang-format changes --- bridge/core/dom/document.h | 8 ++++---- bridge/core/dom/events/event_target.h | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bridge/core/dom/document.h b/bridge/core/dom/document.h index 989fbaf79b..282533c18d 100644 --- a/bridge/core/dom/document.h +++ b/bridge/core/dom/document.h @@ -7,9 +7,9 @@ #include "bindings/qjs/cppgc/local_handle.h" #include "container_node.h" +#include "event_type_names.h" #include "scripted_animation_controller.h" #include "tree_scope.h" -#include "event_type_names.h" namespace webf { @@ -70,11 +70,11 @@ class Document : public ContainerNode, public TreeScope { std::vector getElementsByTagName(const AtomicString& tag_name, ExceptionState& exception_state); std::vector getElementsByName(const AtomicString& name, ExceptionState& exception_state); - AtomicString domain(); + AtomicString domain(); void setDomain(const AtomicString& value, ExceptionState& exception_state); - AtomicString compatMode(); + AtomicString compatMode(); - AtomicString readyState(); + AtomicString readyState(); DEFINE_DOCUMENT_ATTRIBUTE_EVENT_LISTENER(readystatechange, kreadystatechange); bool hidden(); diff --git a/bridge/core/dom/events/event_target.h b/bridge/core/dom/events/event_target.h index 5440363565..14344ce331 100644 --- a/bridge/core/dom/events/event_target.h +++ b/bridge/core/dom/events/event_target.h @@ -209,12 +209,12 @@ class EventTargetWithInlineData : public EventTarget { GetDocument().SetWindowAttributeEventListener(event_type_names::symbol_name, listener, exception_state); \ } -#define DEFINE_DOCUMENT_ATTRIBUTE_EVENT_LISTENER(lower_name, symbol_name) \ - std::shared_ptr on##lower_name() { \ - return GetWindowAttributeEventListener(event_type_names::symbol_name); \ - } \ - void setOn##lower_name(const std::shared_ptr& listener, ExceptionState& exception_state) { \ - SetWindowAttributeEventListener(event_type_names::symbol_name, listener, exception_state); \ +#define DEFINE_DOCUMENT_ATTRIBUTE_EVENT_LISTENER(lower_name, symbol_name) \ + std::shared_ptr on##lower_name() { \ + return GetWindowAttributeEventListener(event_type_names::symbol_name); \ + } \ + void setOn##lower_name(const std::shared_ptr& listener, ExceptionState& exception_state) { \ + SetWindowAttributeEventListener(event_type_names::symbol_name, listener, exception_state); \ } #define DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(lower_name, symbol_name) \ From 18436fe66d30ebea3e3d5b9421c356d5af04bb0a Mon Sep 17 00:00:00 2001 From: zjt123 Date: Tue, 23 May 2023 00:19:54 +0800 Subject: [PATCH 3/8] fix:WebFController impl ElementsBindingObserver --- webf/lib/src/dom/document.dart | 58 +-------------------------- webf/lib/src/launcher/controller.dart | 57 +++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/webf/lib/src/dom/document.dart b/webf/lib/src/dom/document.dart index 0f02567c76..979c47b3c7 100644 --- a/webf/lib/src/dom/document.dart +++ b/webf/lib/src/dom/document.dart @@ -64,7 +64,7 @@ class _InactiveRenderObjects { enum DocumentReadyState { loading, interactive, complete} enum VisibilityState { visible, hidden} -class Document extends ContainerNode implements ElementsBindingObserver { +class Document extends ContainerNode { final WebFController controller; final AnimationTimeline animationTimeline = AnimationTimeline(); RenderViewportBox? _viewport; @@ -224,7 +224,7 @@ class Document extends ContainerNode implements ElementsBindingObserver { return _visibilityState == VisibilityState.visible; } - void _visibilityChange(VisibilityState state) { + void visibilityChange(VisibilityState state) { _visibilityState = state; ownerDocument.dispatchEvent(Event('visibilitychange')); } @@ -332,7 +332,6 @@ class Document extends ContainerNode implements ElementsBindingObserver { element.renderStyle.width = CSSLengthValue(viewport.viewportSize.width, CSSLengthType.PX); element.renderStyle.height = CSSLengthValue(viewport.viewportSize.height, CSSLengthType.PX); _visibilityState = VisibilityState.visible; - controller.view.addObserver(this); } else { // Detach document element. viewport.removeAll(); @@ -472,7 +471,6 @@ class Document extends ContainerNode implements ElementsBindingObserver { @override Future dispose() async { - controller.view.removeObserver(this); _viewport = null; gestureListener = null; styleSheets.clear(); @@ -481,56 +479,4 @@ class Document extends ContainerNode implements ElementsBindingObserver { super.dispose(); } - @override - void didChangeAccessibilityFeatures() { - // TODO: implement didChangeAccessibilityFeatures - } - - @override - void didChangeAppLifecycleState(AppLifecycleState state) { - switch (state) { - case AppLifecycleState.resumed: - _visibilityChange(VisibilityState.visible); - break; - case AppLifecycleState.paused: - _visibilityChange(VisibilityState.hidden); - break; - } - } - - @override - void didChangeLocales(List? locale) { - // TODO: implement didChangeLocales - } - - @override - void didChangeMetrics() { - // TODO: implement didChangeMetrics - } - - @override - void didChangePlatformBrightness() { - // TODO: implement didChangePlatformBrightness - } - - @override - void didChangeTextScaleFactor() { - // TODO: implement didChangeTextScaleFactor - } - - @override - void didHaveMemoryPressure() { - // TODO: implement didHaveMemoryPressure - } - - @override - Future didPopRoute() { - return Future.value(false); - } - - @override - Future didPushRoute(String route) { - return Future.value(false); - } - } diff --git a/webf/lib/src/launcher/controller.dart b/webf/lib/src/launcher/controller.dart index 318b5e4bd6..ebbc17126f 100644 --- a/webf/lib/src/launcher/controller.dart +++ b/webf/lib/src/launcher/controller.dart @@ -289,6 +289,7 @@ class WebFViewController implements WidgetsBindingObserver, ElementsBindingObser } else { WidgetsBinding.instance.addObserver(this); } + addObserver(rootController); } void _teardownObserver() { @@ -297,6 +298,7 @@ class WebFViewController implements WidgetsBindingObserver, ElementsBindingObser } else { WidgetsBinding.instance.removeObserver(this); } + removeObserver(rootController); } // Attach kraken's renderObject to an renderObject. @@ -724,7 +726,7 @@ class WebFModuleController with TimerMixin, ScheduleFrameMixin { } } -class WebFController { +class WebFController implements ElementsBindingObserver { static final SplayTreeMap _controllerMap = SplayTreeMap(); static final Map _nameIdMap = {}; @@ -1193,4 +1195,57 @@ class WebFController { }); SchedulerBinding.instance.scheduleFrame(); } + + @override + void didChangeAccessibilityFeatures() { + // TODO: implement didChangeAccessibilityFeatures + } + + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + switch (state) { + case AppLifecycleState.resumed: + _view.document.visibilityChange(VisibilityState.visible); + break; + case AppLifecycleState.paused: + _view.document.visibilityChange(VisibilityState.hidden); + break; + } + } + + @override + void didChangeLocales(List? locale) { + // TODO: implement didChangeLocales + } + + @override + void didChangeMetrics() { + // TODO: implement didChangeMetrics + } + + @override + void didChangePlatformBrightness() { + // TODO: implement didChangePlatformBrightness + } + + @override + void didChangeTextScaleFactor() { + // TODO: implement didChangeTextScaleFactor + } + + @override + void didHaveMemoryPressure() { + // TODO: implement didHaveMemoryPressure + } + + @override + Future didPopRoute() { + return Future.value(false); + } + + @override + Future didPushRoute(String route) { + return Future.value(false); + } + } From 6ac25db735aecc4dc2a58b0c395d7fe495efee52 Mon Sep 17 00:00:00 2001 From: zjt123 Date: Tue, 23 May 2023 12:55:14 +0800 Subject: [PATCH 4/8] fix: test run check --- webf/lib/src/dom/document.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/webf/lib/src/dom/document.dart b/webf/lib/src/dom/document.dart index 979c47b3c7..125d6d897a 100644 --- a/webf/lib/src/dom/document.dart +++ b/webf/lib/src/dom/document.dart @@ -6,7 +6,6 @@ import 'dart:collection'; import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; -import 'package:flutter/scheduler.dart'; import 'package:webf/css.dart'; import 'package:webf/dom.dart'; import 'package:webf/html.dart'; From f32e1b30b4557ba285924abbeb2e3e007ae64098 Mon Sep 17 00:00:00 2001 From: zjt123 Date: Tue, 23 May 2023 14:15:26 +0800 Subject: [PATCH 5/8] fix: format code --- webf/lib/src/dom/document.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webf/lib/src/dom/document.dart b/webf/lib/src/dom/document.dart index 125d6d897a..39532d4e96 100644 --- a/webf/lib/src/dom/document.dart +++ b/webf/lib/src/dom/document.dart @@ -60,8 +60,8 @@ class _InactiveRenderObjects { _renderObjects.clear(); } } -enum DocumentReadyState { loading, interactive, complete} -enum VisibilityState { visible, hidden} +enum DocumentReadyState { loading, interactive, complete } +enum VisibilityState { visible, hidden } class Document extends ContainerNode { final WebFController controller; From f73d3c52048a7e64d58038d76e5a2698a3adea3d Mon Sep 17 00:00:00 2001 From: zjt123 Date: Tue, 23 May 2023 15:25:30 +0800 Subject: [PATCH 6/8] fix:test run check --- webf/lib/src/launcher/controller.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webf/lib/src/launcher/controller.dart b/webf/lib/src/launcher/controller.dart index ebbc17126f..7317887205 100644 --- a/webf/lib/src/launcher/controller.dart +++ b/webf/lib/src/launcher/controller.dart @@ -1210,6 +1210,10 @@ class WebFController implements ElementsBindingObserver { case AppLifecycleState.paused: _view.document.visibilityChange(VisibilityState.hidden); break; + case AppLifecycleState.inactive: + break; + case AppLifecycleState.detached: + break; } } From 6aaacac7be38c81bee4cdac8f1a750dbb3d10edb Mon Sep 17 00:00:00 2001 From: andycall Date: Tue, 23 May 2023 18:46:45 +0800 Subject: [PATCH 7/8] chore: remove app life circles into WebFViewController. --- webf/lib/src/launcher/controller.dart | 99 ++++++--------------------- 1 file changed, 20 insertions(+), 79 deletions(-) diff --git a/webf/lib/src/launcher/controller.dart b/webf/lib/src/launcher/controller.dart index 7317887205..92c2e6652a 100644 --- a/webf/lib/src/launcher/controller.dart +++ b/webf/lib/src/launcher/controller.dart @@ -289,7 +289,6 @@ class WebFViewController implements WidgetsBindingObserver, ElementsBindingObser } else { WidgetsBinding.instance.addObserver(this); } - addObserver(rootController); } void _teardownObserver() { @@ -298,7 +297,6 @@ class WebFViewController implements WidgetsBindingObserver, ElementsBindingObser } else { WidgetsBinding.instance.removeObserver(this); } - removeObserver(rootController); } // Attach kraken's renderObject to an renderObject. @@ -619,17 +617,32 @@ class WebFViewController implements WidgetsBindingObserver, ElementsBindingObser @override void didChangeAccessibilityFeatures() { - for (ElementsBindingObserver observer in _observers) observer.didChangeAccessibilityFeatures(); } @override void didChangeAppLifecycleState(AppLifecycleState state) { - for (ElementsBindingObserver observer in _observers) observer.didChangeAppLifecycleState(state); + switch (state) { + case AppLifecycleState.resumed: + document.visibilityChange(VisibilityState.visible); + break; + case AppLifecycleState.paused: + document.visibilityChange(VisibilityState.hidden); + break; + case AppLifecycleState.inactive: + if (document.visibilityState != VisibilityState.hidden) { + document.visibilityChange(VisibilityState.hidden); + } + break; + case AppLifecycleState.detached: + if (document.visibilityState != VisibilityState.hidden) { + document.visibilityChange(VisibilityState.hidden); + } + break; + } } @override void didChangeLocales(List? locales) { - for (ElementsBindingObserver observer in _observers) observer.didChangeLocales(locales); } ui.WindowPadding _prevViewInsets = ui.window.viewInsets; @@ -664,50 +677,35 @@ class WebFViewController implements WidgetsBindingObserver, ElementsBindingObser } } _prevViewInsets = ui.window.viewInsets; - for (ElementsBindingObserver observer in _observers) observer.didChangeMetrics(); } @override void didChangePlatformBrightness() { - for (ElementsBindingObserver observer in _observers) observer.didChangePlatformBrightness(); } @override void didChangeTextScaleFactor() { - for (ElementsBindingObserver observer in _observers) observer.didChangeTextScaleFactor(); } @override void didHaveMemoryPressure() { - for (ElementsBindingObserver observer in _observers) observer.didHaveMemoryPressure(); } @override Future didPopRoute() async { - for (ElementsBindingObserver observer in List.from(_observers)) { - if (await observer.didPopRoute()) return Future.value(true); - } + return false; } @override Future didPushRoute(String route) async { - for (ElementsBindingObserver observer in List.from(_observers)) { - if (await observer.didPushRoute(route)) return Future.value(true); - } return false; } @override Future didPushRouteInformation(RouteInformation routeInformation) async { - // TODO: implement didPushRouteInformation return false; } - - final List _observers = []; - void addObserver(ElementsBindingObserver observer) => _observers.add(observer); - bool removeObserver(ElementsBindingObserver observer) => _observers.remove(observer); - } // An controller designed to control kraken's functional modules. @@ -726,7 +724,7 @@ class WebFModuleController with TimerMixin, ScheduleFrameMixin { } } -class WebFController implements ElementsBindingObserver { +class WebFController { static final SplayTreeMap _controllerMap = SplayTreeMap(); static final Map _nameIdMap = {}; @@ -1195,61 +1193,4 @@ class WebFController implements ElementsBindingObserver { }); SchedulerBinding.instance.scheduleFrame(); } - - @override - void didChangeAccessibilityFeatures() { - // TODO: implement didChangeAccessibilityFeatures - } - - @override - void didChangeAppLifecycleState(AppLifecycleState state) { - switch (state) { - case AppLifecycleState.resumed: - _view.document.visibilityChange(VisibilityState.visible); - break; - case AppLifecycleState.paused: - _view.document.visibilityChange(VisibilityState.hidden); - break; - case AppLifecycleState.inactive: - break; - case AppLifecycleState.detached: - break; - } - } - - @override - void didChangeLocales(List? locale) { - // TODO: implement didChangeLocales - } - - @override - void didChangeMetrics() { - // TODO: implement didChangeMetrics - } - - @override - void didChangePlatformBrightness() { - // TODO: implement didChangePlatformBrightness - } - - @override - void didChangeTextScaleFactor() { - // TODO: implement didChangeTextScaleFactor - } - - @override - void didHaveMemoryPressure() { - // TODO: implement didHaveMemoryPressure - } - - @override - Future didPopRoute() { - return Future.value(false); - } - - @override - Future didPushRoute(String route) { - return Future.value(false); - } - } From b94fc34ed3077feb3f748c48ec41a21b4356fc16 Mon Sep 17 00:00:00 2001 From: "justin02.zhang" Date: Tue, 23 May 2023 19:45:32 +0800 Subject: [PATCH 8/8] fix:remove unused code --- webf/lib/src/launcher/controller.dart | 6 ------ 1 file changed, 6 deletions(-) diff --git a/webf/lib/src/launcher/controller.dart b/webf/lib/src/launcher/controller.dart index 92c2e6652a..d7878b5b0e 100644 --- a/webf/lib/src/launcher/controller.dart +++ b/webf/lib/src/launcher/controller.dart @@ -629,14 +629,8 @@ class WebFViewController implements WidgetsBindingObserver, ElementsBindingObser document.visibilityChange(VisibilityState.hidden); break; case AppLifecycleState.inactive: - if (document.visibilityState != VisibilityState.hidden) { - document.visibilityChange(VisibilityState.hidden); - } break; case AppLifecycleState.detached: - if (document.visibilityState != VisibilityState.hidden) { - document.visibilityChange(VisibilityState.hidden); - } break; } }