From cdc0b4a5e10fe892aa9b1478c0fe4b5e0a58384e Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Fri, 12 Jul 2024 18:38:11 +0800 Subject: [PATCH 1/9] openHarmony mouseAdapt --- .../src/main/cpp/types/libflutter/index.d.ets | 10 +++ .../main/ets/embedding/engine/FlutterNapi.ets | 27 ++++++ .../main/ets/embedding/ohos/FlutterPage.ets | 13 +++ .../flutter/src/main/ets/view/FlutterView.ets | 4 + shell/platform/ohos/library_loader.cpp | 3 + .../ohos/napi/platform_view_ohos_napi.cpp | 85 ++++++++++++++++++ .../ohos/napi/platform_view_ohos_napi.h | 13 +++ shell/platform/ohos/ohos_touch_processor.cpp | 82 +++++++++++++++++ shell/platform/ohos/ohos_touch_processor.h | 8 ++ .../platform/ohos/ohos_xcomponent_adapter.cpp | 90 +++++++++++++++++++ shell/platform/ohos/ohos_xcomponent_adapter.h | 5 ++ 11 files changed, 340 insertions(+) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets index ce5ef18b90..d38b7a0e4c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/cpp/types/libflutter/index.d.ets @@ -94,6 +94,16 @@ export const nativeXComponentAttachFlutterEngine: (xcomponentId: string, nativeS export const nativeXComponentDetachFlutterEngine: (xcomponentId: string, nativeShellHolderId: number) => void; +export const nativeXComponentDispatchMouseWheel: (nativeShellHolderId: number, + xcomponentId: string, + eventType: string, + fingerId: number, + globalX: number, + globalY: number, + offsetY: number, + timestamp: number + ) => void; + /** * Detaches flutterNapi和engine之间的关联 * 这个方法执行前提是flutterNapi已经和engine关联 diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets index b74c2d4c63..c97363ffc9 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterNapi.ets @@ -377,6 +377,33 @@ export default class FlutterNapi { flutter.nativeXComponentDetachFlutterEngine(xcomponentId, this.nativeShellHolderId!); } + /** + * xcomponent send mouseWheel event to flutterEngine + * @param xcomponentId + * @param eventType + * @param event + */ + xComponentDisPatchMouseWheel(xcomponentId: string, eventType: string, event: PanGestureEvent) { + // only mouse + if (event.source !== SourceType.Mouse) { + return; + } + const vaildFinger = event.fingerList?.find(item => item.globalX && item.globalY); + if (!vaildFinger) { + return; + } + flutter.nativeXComponentDispatchMouseWheel( + this.nativeShellHolderId!!, + xcomponentId, + eventType, + vaildFinger?.id, + vaildFinger?.localX, + vaildFinger?.localY, + event.offsetY, + event.timestamp + ); + } + detachFromNativeAndReleaseResources() { flutter.nativeDestroy(this.nativeShellHolderId!!); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index df00af2cf2..7b4ab6b37f 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -42,6 +42,7 @@ export struct FlutterPage { private flutterView?: FlutterView | null private nodeController: EmbeddingNodeController | undefined = undefined private lastArea?: Area; + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); aboutToAppear() { this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); @@ -102,5 +103,17 @@ export struct FlutterPage { Log.d(TAG, "onKeyEvent " + event.type); this.flutterView?.onKeyEvent(event) }) + .gesture( + PanGesture(this.panOption) + .onActionStart((event: GestureEvent) => { + this.flutterView?.onMouseWheel("actionStart", event); + }) + .onActionUpdate((event: GestureEvent) => { + this.flutterView?.onMouseWheel("actionUpdate", event); + }) + .onActionEnd((event: GestureEvent) => { + this.flutterView?.onMouseWheel("actionEnd", event); + }) + ) } } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets index 6198536c35..3f23984aee 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/FlutterView.ets @@ -336,6 +336,10 @@ export class FlutterView { this.keyboardManager?.handleKeyEvent(event) } + onMouseWheel(eventType: string, event: PanGestureEvent) { + this.flutterEngine?.getFlutterNapi()?.xComponentDisPatchMouseWheel(this.id, eventType, event); + } + addFirstFrameListener(listener: FirstFrameListener) { this.mFirstFrameListeners.add(listener); } diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index 415bf46a65..231723d337 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -107,6 +107,9 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_FUNCTION( "nativeXComponentDetachFlutterEngine", flutter::PlatformViewOHOSNapi::nativeXComponentDetachFlutterEngine), + DECLARE_NAPI_FUNCTION( + "nativeXComponentDispatchMouseWheel", + flutter::PlatformViewOHOSNapi::nativeXComponentDispatchMouseWheel), DECLARE_NAPI_FUNCTION( "nativeInitNativeImage", flutter::PlatformViewOHOSNapi::nativeInitNativeImage), diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index b2ebeb46a3..48b2d20f1d 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1626,4 +1626,89 @@ napi_value PlatformViewOHOSNapi::nativeXComponentDetachFlutterEngine( return nullptr; } + +/** + * @brief flutterEngine get mouseWheel event from ets + * @note + * @param nativeShellHolderId: number + * @param xcomponentId: number + * @param eventType: string + * @param fingerId: number + * @param globalX: number + * @param globalY: number + * @param offsetY: number + * @param timestamp: number + * @return napi_value + */ +napi_value PlatformViewOHOSNapi::nativeXComponentDispatchMouseWheel( + napi_env env, + napi_callback_info info){ + napi_status ret; + size_t argc = 8; + napi_value args[8] = {nullptr}; + int64_t shell_holder; + std::string xcomponent_id; + std::string event_type; + int64_t finger_id; + double global_x; + double global_y; + double offset_y; + int64_t timestamp; + ret = napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "nativeXComponentDispatchMouseWheel napi_get_cb_info error:" + << ret; + return nullptr; + } + ret = napi_get_value_int64(env, args[0], &shell_holder); + if (ret != napi_ok) { + LOGE("nativeXComponentDispatchMouseWheel shell_holder napi_get_value_int64 error"); + return nullptr; + } + if (fml::napi::GetString(env, args[1], xcomponent_id) != 0) { + FML_DLOG(ERROR) << "nativeXComponentDispatchMouseWheel xcomponent_id GetString error"; + return nullptr; + } + if (fml::napi::GetString(env, args[2], event_type) != 0) { + FML_DLOG(ERROR) << "nativeXComponentDispatchMouseWheel event_type GetString error"; + return nullptr; + } + ret = napi_get_value_int64(env, args[3], &finger_id); + if (ret != napi_ok) { + LOGE("nativeXComponentDispatchMouseWheel finger_id napi_get_value_int64 error"); + return nullptr; + } + ret = napi_get_value_double(env, args[4], &global_x); + if (ret != napi_ok) { + LOGE("nativeXComponentDispatchMouseWheel global_x napi_get_value_double error"); + return nullptr; + } + ret = napi_get_value_double(env, args[5], &global_y); + if (ret != napi_ok) { + LOGE("nativeXComponentDispatchMouseWheel global_y napi_get_value_double error"); + return nullptr; + } + ret = napi_get_value_double(env, args[6], &offset_y); + if (ret != napi_ok) { + LOGE("nativeXComponentDispatchMouseWheel offset_y napi_get_value_double error"); + return nullptr; + } + ret = napi_get_value_int64(env, args[7], ×tamp); + if (ret != napi_ok) { + LOGE("nativeXComponentDispatchMouseWheel timestamp napi_get_value_int64 error"); + return nullptr; + } + flutter::mouseWheelEvent event { + event_type, + shell_holder, + finger_id, + global_x, + global_y, + offset_y, + timestamp + }; + XComponentAdapter::GetInstance()->OnMouseWheel(xcomponent_id, event); + return nullptr; +} + } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 8e3748a6ff..5949a80863 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -37,6 +37,16 @@ struct locale { std::string region; }; +struct mouseWheelEvent { + std::string event_type; + int64_t shell_holder; + int64_t finger_id; + double global_x; + double global_y; + double offset_y; + int64_t timestamp; +}; + class PlatformViewOHOSNapi { public: static napi_value nativeDispatchEmptyPlatformMessage( @@ -181,6 +191,9 @@ class PlatformViewOHOSNapi { static napi_value nativeXComponentDetachFlutterEngine( napi_env env, napi_callback_info info); + static napi_value nativeXComponentDispatchMouseWheel( + napi_env env, + napi_callback_info info); private: static napi_env env_; diff --git a/shell/platform/ohos/ohos_touch_processor.cpp b/shell/platform/ohos/ohos_touch_processor.cpp index 98f02d10ea..55c9ed3f56 100644 --- a/shell/platform/ohos/ohos_touch_processor.cpp +++ b/shell/platform/ohos/ohos_touch_processor.cpp @@ -39,6 +39,38 @@ PointerData::Change OhosTouchProcessor::getPointerChangeForAction( return PointerData::Change::kCancel; } +PointerData::Change OhosTouchProcessor::getPointerChangeForMouseAction( + OH_NativeXComponent_MouseEventAction mouseAction) { + switch (mouseAction) { + case OH_NATIVEXCOMPONENT_MOUSE_PRESS: + return PointerData::Change::kDown; + case OH_NATIVEXCOMPONENT_MOUSE_RELEASE: + return PointerData::Change::kUp; + case OH_NATIVEXCOMPONENT_MOUSE_MOVE: + return PointerData::Change::kMove; + default: + return PointerData::Change::kCancel; + } +} + +PointerButtonMouse OhosTouchProcessor::getPointerButtonFromMouse( + OH_NativeXComponent_MouseEventButton mouseButton) { + switch (mouseButton) { + case OH_NATIVEXCOMPONENT_LEFT_BUTTON: + return kPointerButtonMousePrimary; + case OH_NATIVEXCOMPONENT_RIGHT_BUTTON: + return kPointerButtonMouseSecondary; + case OH_NATIVEXCOMPONENT_MIDDLE_BUTTON: + return kPointerButtonMouseMiddle; + case OH_NATIVEXCOMPONENT_BACK_BUTTON: + return kPointerButtonMouseBack; + case OH_NATIVEXCOMPONENT_FORWARD_BUTTON: + return kPointerButtonMouseForward; + default: + return kPointerButtonMousePrimary; + } +} + PointerData::DeviceKind OhosTouchProcessor::getPointerDeviceTypeForToolType( int toolType) { switch (toolType) { @@ -176,4 +208,54 @@ void OhosTouchProcessor::HandleTouchEvent( return; } +void OhosTouchProcessor::HandleMouseEvent( + int64_t shell_holderID, + OH_NativeXComponent* component, + OH_NativeXComponent_MouseEvent mouseEvent, + double offsetY) { + const int numTouchPoints = 1; + std::unique_ptr packet = std::make_unique(numTouchPoints); + PointerData pointerData; + pointerData.Clear(); + pointerData.embedder_id = mouseEvent.button; + pointerData.time_stamp = mouseEvent.timestamp / MSEC_PER_SECOND; + pointerData.change = getPointerChangeForMouseAction(mouseEvent.action); + pointerData.physical_y = mouseEvent.y; + pointerData.physical_x = mouseEvent.x; + // Delta will be generated in pointer_data_packet_converter.cc. + pointerData.physical_delta_x = 0.0; + pointerData.physical_delta_y = 0.0; + pointerData.device = mouseEvent.button; + // Pointer identifier will be generated in pointer_data_packet_converter.cc. + pointerData.pointer_identifier = 0; + // XComponent not support Scroll + // now it's support + pointerData.signal_kind = offsetY != 0 ? PointerData::SignalKind::kScroll : PointerData::SignalKind::kNone; + pointerData.scroll_delta_x = 0.0; + pointerData.scroll_delta_y = offsetY; + pointerData.pressure = 0.0; + pointerData.pressure_max = 1.0; + pointerData.pressure_min = 0.0; + pointerData.kind = PointerData::DeviceKind::kMouse; + pointerData.buttons = getPointerButtonFromMouse(mouseEvent.button); + // hover support + if (mouseEvent.button == OH_NATIVEXCOMPONENT_NONE_BUTTON && pointerData.change == PointerData::Change::kMove) { + pointerData.change = PointerData::Change::kHover; + pointerData.buttons = 0; + } + pointerData.pan_x = 0.0; + pointerData.pan_y = 0.0; + // Delta will be generated in pointer_data_packet_converter.cc. + pointerData.pan_delta_x = 0.0; + pointerData.pan_delta_y = 0.0; + // The contact area between the fingerpad and the screen + pointerData.size = 0.0; + pointerData.scale = 1.0; + pointerData.rotation = 0.0; + packet->SetPointerData(0, pointerData); + auto ohos_shell_holder = reinterpret_cast(shell_holderID); + ohos_shell_holder->GetPlatformView()->DispatchPointerDataPacket( + std::move(packet)); + return; + } } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/ohos_touch_processor.h b/shell/platform/ohos/ohos_touch_processor.h index ec70f2b0b5..812d56a81e 100644 --- a/shell/platform/ohos/ohos_touch_processor.h +++ b/shell/platform/ohos/ohos_touch_processor.h @@ -36,9 +36,17 @@ class OhosTouchProcessor { void HandleTouchEvent(int64_t shell_holderID, OH_NativeXComponent* component, OH_NativeXComponent_TouchEvent* touchEvent); + void HandleMouseEvent(int64_t shell_holderID, + OH_NativeXComponent* component, + OH_NativeXComponent_MouseEvent mouseEvent, + double offsetY); flutter::PointerData::Change getPointerChangeForAction(int maskedAction); flutter::PointerData::DeviceKind getPointerDeviceTypeForToolType( int toolType); + flutter::PointerData::Change getPointerChangeForMouseAction( + OH_NativeXComponent_MouseEventAction mouseAction); + PointerButtonMouse getPointerButtonFromMouse( + OH_NativeXComponent_MouseEventButton mouseButton); private: std::shared_ptr packagePacketData(std::unique_ptr touchPacket); diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index d20ac4ab20..0b7ca1e577 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -19,6 +19,9 @@ #include namespace flutter { +bool isMouseLeftActive = false; +double scrollDistance = 0.0; + XComponentAdapter XComponentAdapter::mXComponentAdapter; XComponentAdapter::XComponentAdapter(/* args */) {} @@ -102,6 +105,13 @@ void XComponentAdapter::DetachFlutterEngine(std::string& id) { } } +void XComponentAdapter::OnMouseWheel(std::string& id, mouseWheelEvent event) { + auto iter = xcomponetMap_.find(id); + if (iter != xcomponetMap_.end()) { + iter->second->OnDispatchMouseWheelEvent(event); + } +} + #include using OHOS_SurfaceBufferUsage = enum { BUFFER_USAGE_CPU_READ = (1ULL << 0), /**< CPU read buffer */ @@ -229,11 +239,26 @@ void DispatchTouchEventCB(OH_NativeXComponent* component, void* window) { } } +void DispatchMouseEventCB(OH_NativeXComponent* component, void* window) { + for(auto it: XComponentAdapter::GetInstance()->xcomponetMap_) + { + if(it.second->nativeXComponent_ == component) { + it.second->OnDispatchMouseEvent(component, window); + } + } +} + +void DispatchHoverEventCB(OH_NativeXComponent* component, bool isHover) { + LOGD("XComponentManger::DispatchHoverEventCB"); +} + void XComponentBase::BindXComponentCallback() { callback_.OnSurfaceCreated = OnSurfaceCreatedCB; callback_.OnSurfaceChanged = OnSurfaceChangedCB; callback_.OnSurfaceDestroyed = OnSurfaceDestroyedCB; callback_.DispatchTouchEvent = DispatchTouchEventCB; + mouseCallback_.DispatchMouseEvent = DispatchMouseEventCB; + mouseCallback_.DispatchHoverEvent = DispatchHoverEventCB; } XComponentBase::XComponentBase(std::string id){ @@ -276,6 +301,7 @@ void XComponentBase::SetNativeXComponent(OH_NativeXComponent* nativeXComponent){ if (nativeXComponent_ != nullptr) { BindXComponentCallback(); OH_NativeXComponent_RegisterCallback(nativeXComponent_, &callback_); + OH_NativeXComponent_RegisterMouseEventCallback(nativeXComponent_, &mouseCallback_); } } @@ -342,6 +368,14 @@ void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, OH_NativeXComponent_GetTouchEvent(component, window, &touchEvent_); if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { if (isEngineAttached_) { + // if this touchEvent triggered by mouse, return + OH_NativeXComponent_EventSourceType sourceType; + int32_t ret2 = OH_NativeXComponent_GetTouchEventSourceType(component, touchEvent_.id, &sourceType); + if (ret2 == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + if (sourceType == OH_NATIVEXCOMPONENT_SOURCE_TYPE_MOUSE) { + return; + } + } ohosTouchProcessor_.HandleTouchEvent(std::stoll(shellholderId_), component, &touchEvent_); } else { @@ -352,4 +386,60 @@ void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, } } +void XComponentBase::OnDispatchMouseEvent(OH_NativeXComponent* component, + void* window) { + OH_NativeXComponent_MouseEvent mouseEvent_; + int32_t ret = + OH_NativeXComponent_GetMouseEvent(component, window, &mouseEvent_); + if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { + if (isEngineAttached_) { + if (mouseEvent_.button == OH_NATIVEXCOMPONENT_LEFT_BUTTON) { + if (mouseEvent_.action == OH_NATIVEXCOMPONENT_MOUSE_PRESS) { + isMouseLeftActive = true; + } else if (mouseEvent_.action == OH_NATIVEXCOMPONENT_MOUSE_RELEASE) { + isMouseLeftActive = false; + } + } + ohosTouchProcessor_.HandleMouseEvent(std::stoll(shellholderId_), + component, mouseEvent_, 0.0); + } else { + LOGE( + "XComponentManger::DispatchMouseEvent XComponentBase is not " + "attached"); + } + } +} + +void XComponentBase::OnDispatchMouseWheelEvent(mouseWheelEvent event) { + std::string shell_holder_str = std::to_string(event.shell_holder); + if (shell_holder_str != shellholderId_) { + return; + } + if (isEngineAttached_) { + if (isMouseLeftActive) { + return; + } + if (event.event_type == "actionUpdate") { + OH_NativeXComponent_MouseEvent mouseEvent_; + double scrollY_ = event.offset_y - scrollDistance; + scrollDistance = event.offset_y; + // resize for flutter + mouseEvent_.x = event.global_x / 0.8; + mouseEvent_.y = event.global_y / 0.8; + scrollY_ = scrollY_ / 0.8; + mouseEvent_.button = OH_NATIVEXCOMPONENT_NONE_BUTTON; + mouseEvent_.action = OH_NATIVEXCOMPONENT_MOUSE_NONE; + mouseEvent_.timestamp = event.timestamp; + ohosTouchProcessor_.HandleMouseEvent(std::stoll(shellholderId_), + nullptr, mouseEvent_, + scrollY_); + } else { + scrollDistance = 0.0; + } + } else { + LOGE( + "XComponentManger::DispatchMouseWheelEvent XComponentBase is not " + "attached"); + } +} } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.h b/shell/platform/ohos/ohos_xcomponent_adapter.h index 4fd6ff4990..aecea89ded 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.h +++ b/shell/platform/ohos/ohos_xcomponent_adapter.h @@ -18,6 +18,7 @@ #include #include #include "flutter/shell/platform/ohos/ohos_touch_processor.h" +#include "flutter/shell/platform/ohos/napi/platform_view_ohos_napi.h" #include "napi/native_api.h" #include "napi_common.h" #include @@ -41,9 +42,12 @@ public: void OnSurfaceChanged(OH_NativeXComponent* component, void* window); void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window); void OnDispatchTouchEvent(OH_NativeXComponent* component, void* window); + void OnDispatchMouseEvent(OH_NativeXComponent* component, void* window); + void OnDispatchMouseWheelEvent(mouseWheelEvent event); OH_NativeXComponent_TouchEvent touchEvent_; OH_NativeXComponent_Callback callback_; + OH_NativeXComponent_MouseEvent_Callback mouseCallback_; std::string id_; std::string shellholderId_; bool isEngineAttached_; @@ -66,6 +70,7 @@ class XComponentAdapter { OH_NativeXComponent* nativeXComponent); void AttachFlutterEngine(std::string& id, std::string& shellholderId); void DetachFlutterEngine(std::string& id); + void OnMouseWheel(std::string& id, mouseWheelEvent event); public: std::map xcomponetMap_; -- Gitee From 4084eea0675169e5ad1b082ff375dbbcd1f117a7 Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Thu, 15 Aug 2024 09:40:20 +0800 Subject: [PATCH 2/9] =?UTF-8?q?panGesture=E9=80=89=E9=A1=B9=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E9=80=9A=E8=BF=87=E5=8F=82=E6=95=B0=E6=9D=A5=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/embedding/ohos/FlutterPage.ets | 121 +++++++++++++----- 1 file changed, 89 insertions(+), 32 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 3c7c84be08..e2e53ca2df 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -31,43 +31,57 @@ export struct FlutterPage { @Builder doNothingBuilder() {} @BuilderParam splashScreenView: () => void = this.doNothingBuilder; - @State showSplashScreen: boolean = true; - - @State checkFullScreen: boolean = true; - @State checkKeyboard: boolean = true; - @State checkGesture: boolean = true; - - @StorageLink('nodeWidth') storageLinkWidth: number = 0; - @StorageLink('nodeHeight') storageLinkHeight: number = 0; - - @State rootDvModel: DVModelChildren | undefined = undefined - - - private flutterView?: FlutterView | null - private lastArea?: Area; - private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); - - aboutToAppear() { - this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.flutterView?.addFirstFrameListener(this) - - this.flutterView?.setCheckFullScreen(this.checkFullScreen) - this.flutterView?.setCheckKeyboard(this.checkKeyboard) - this.flutterView?.setCheckGesture(this.checkGesture) + @Builder defaultStack() { + Stack() { + ForEach(this.rootDvModel!!, (child: ESObject) => { + DynamicView({ + model: child as DVModel, + params: child.params, + events: child.events, + children: child.children, + customBuilder: child.builder + }) + .position({x: (child.params as Record)['left'] as number, y: (child.params as Record)['top'] as number}) + }, (child: ESObject) => `${child.id_}`) - this.rootDvModel = this.flutterView!!.getDVModel().children - } + Text('') + .id('emptyFocusText' + this.viewId) + .size({ width: 0, height: 0 }) + .opacity(0) + .focusable(true) - aboutToDisappear() { - this.flutterView?.removeFirstFrameListener(this); - } + XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) + .focusable(true) + .onLoad((context) => { + this.flutterView?.onSurfaceCreated() + Log.d(TAG, "XComponent onLoad "); + }) + .onDestroy(() => { + Log.d(TAG, "XComponent onDestroy "); + this.flutterView?.onSurfaceDestroyed() + }) + .backgroundColor(Color.Transparent) - onFirstFrame() { - this.showSplashScreen = false; + if (this.showSplashScreen) { + this.splashScreenView(); + } + } + .onAreaChange((oldValue: Area, newValue: Area) => { + if (!this.lastArea || oldValue.width != newValue.width + || oldValue.height != newValue.height) { + Log.d(TAG, "onAreaChange, old=" + JSON.stringify(oldValue)); + Log.d(TAG, "onAreaChange, new=" + JSON.stringify(newValue)); + this.lastArea = newValue; + this.flutterView?.onAreaChange(newValue) + } + }) + .onKeyEvent((event: KeyEvent) => { + Log.d(TAG, "onKeyEvent " + event.type); + this.flutterView?.onKeyEvent(event) + }) } - - build() { + @Builder mouseWheelStack() { Stack() { ForEach(this.rootDvModel!!, (child: ESObject) => { DynamicView({ @@ -129,4 +143,47 @@ export struct FlutterPage { }) ) } + @State showSplashScreen: boolean = true; + + @State checkFullScreen: boolean = true; + @State checkKeyboard: boolean = true; + @State checkGesture: boolean = true; + @State checkMouseWheel: boolean = true; + + @StorageLink('nodeWidth') storageLinkWidth: number = 0; + @StorageLink('nodeHeight') storageLinkHeight: number = 0; + + @State rootDvModel: DVModelChildren | undefined = undefined + + private flutterView?: FlutterView | null + private lastArea?: Area; + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); + + aboutToAppear() { + this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); + this.flutterView?.addFirstFrameListener(this) + + this.flutterView?.setCheckFullScreen(this.checkFullScreen) + this.flutterView?.setCheckKeyboard(this.checkKeyboard) + this.flutterView?.setCheckGesture(this.checkGesture) + + this.rootDvModel = this.flutterView!!.getDVModel().children + + } + + aboutToDisappear() { + this.flutterView?.removeFirstFrameListener(this); + } + + onFirstFrame() { + this.showSplashScreen = false; + } + + build() { + if (this.checkMouseWheel) { + this.mouseWheelStack(); + } else { + this.defaultStack(); + } + } } -- Gitee From aed9530c6c57d5ae041925ba0ea0e573dff9a919 Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Thu, 15 Aug 2024 10:05:02 +0800 Subject: [PATCH 3/9] =?UTF-8?q?flutterPage=E6=96=87=E4=BB=B6=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E6=88=90=E4=B8=8A=E6=B8=B8dev=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/embedding/ohos/FlutterPage.ets | 121 +++++------------- 1 file changed, 32 insertions(+), 89 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 90b630c650..e5385a643f 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -31,57 +31,43 @@ export struct FlutterPage { @Builder doNothingBuilder() {} @BuilderParam splashScreenView: () => void = this.doNothingBuilder; - @Builder defaultStack() { - Stack() { - ForEach(this.rootDvModel!!, (child: ESObject) => { - DynamicView({ - model: child as DVModel, - params: child.params, - events: child.events, - children: child.children, - customBuilder: child.builder - }) - .position({x: (child.params as Record)['left'] as number, y: (child.params as Record)['top'] as number}) - }, (child: ESObject) => `${child.id_}`) + @State showSplashScreen: boolean = true; + @State checkFullScreen: boolean = true; + @State checkKeyboard: boolean = true; + @State checkGesture: boolean = true; - Text('') - .id('emptyFocusText' + this.viewId) - .size({ width: 0, height: 0 }) - .opacity(0) - .focusable(true) + @StorageLink('nodeWidth') storageLinkWidth: number = 0; + @StorageLink('nodeHeight') storageLinkHeight: number = 0; - XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) - .focusable(true) - .onLoad((context) => { - this.flutterView?.onSurfaceCreated() - Log.d(TAG, "XComponent onLoad "); - }) - .onDestroy(() => { - Log.d(TAG, "XComponent onDestroy "); - this.flutterView?.onSurfaceDestroyed() - }) - .backgroundColor(Color.Transparent) + @State rootDvModel: DVModelChildren | undefined = undefined - if (this.showSplashScreen) { - this.splashScreenView(); - } - } - .onAreaChange((oldValue: Area, newValue: Area) => { - if (!this.lastArea || oldValue.width != newValue.width - || oldValue.height != newValue.height) { - Log.d(TAG, "onAreaChange, old=" + JSON.stringify(oldValue)); - Log.d(TAG, "onAreaChange, new=" + JSON.stringify(newValue)); - this.lastArea = newValue; - this.flutterView?.onAreaChange(newValue) - } - }) - .onKeyEvent((event: KeyEvent) => { - Log.d(TAG, "onKeyEvent " + event.type); - this.flutterView?.onKeyEvent(event) - }) + + private flutterView?: FlutterView | null + private lastArea?: Area; + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); + + aboutToAppear() { + this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); + this.flutterView?.addFirstFrameListener(this) + + this.flutterView?.setCheckFullScreen(this.checkFullScreen) + this.flutterView?.setCheckKeyboard(this.checkKeyboard) + this.flutterView?.setCheckGesture(this.checkGesture) + + this.rootDvModel = this.flutterView!!.getDVModel().children + + } + + aboutToDisappear() { + this.flutterView?.removeFirstFrameListener(this); + } + + onFirstFrame() { + this.showSplashScreen = false; } - @Builder mouseWheelStack() { + + build() { Stack() { ForEach(this.rootDvModel!!, (child: ESObject) => { DynamicView({ @@ -144,47 +130,4 @@ export struct FlutterPage { }) ) } - @State showSplashScreen: boolean = true; - - @State checkFullScreen: boolean = true; - @State checkKeyboard: boolean = true; - @State checkGesture: boolean = true; - @State checkMouseWheel: boolean = true; - - @StorageLink('nodeWidth') storageLinkWidth: number = 0; - @StorageLink('nodeHeight') storageLinkHeight: number = 0; - - @State rootDvModel: DVModelChildren | undefined = undefined - - private flutterView?: FlutterView | null - private lastArea?: Area; - private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); - - aboutToAppear() { - this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.flutterView?.addFirstFrameListener(this) - - this.flutterView?.setCheckFullScreen(this.checkFullScreen) - this.flutterView?.setCheckKeyboard(this.checkKeyboard) - this.flutterView?.setCheckGesture(this.checkGesture) - - this.rootDvModel = this.flutterView!!.getDVModel().children - - } - - aboutToDisappear() { - this.flutterView?.removeFirstFrameListener(this); - } - - onFirstFrame() { - this.showSplashScreen = false; - } - - build() { - if (this.checkMouseWheel) { - this.mouseWheelStack(); - } else { - this.defaultStack(); - } - } } -- Gitee From 3ea8a73bea3510f09414bd1581337489c07b5314 Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Thu, 15 Aug 2024 10:09:20 +0800 Subject: [PATCH 4/9] =?UTF-8?q?gesture=E5=B1=9E=E6=80=A7=E7=94=B1=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=8F=82=E6=95=B0checkMouseWheel=E6=9D=A5=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/embedding/ohos/FlutterPage.ets | 123 +++++++++++++----- 1 file changed, 91 insertions(+), 32 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index e5385a643f..624a23a109 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -31,43 +31,58 @@ export struct FlutterPage { @Builder doNothingBuilder() {} @BuilderParam splashScreenView: () => void = this.doNothingBuilder; - @State showSplashScreen: boolean = true; - - @State checkFullScreen: boolean = true; - @State checkKeyboard: boolean = true; - @State checkGesture: boolean = true; - - @StorageLink('nodeWidth') storageLinkWidth: number = 0; - @StorageLink('nodeHeight') storageLinkHeight: number = 0; - - @State rootDvModel: DVModelChildren | undefined = undefined - - - private flutterView?: FlutterView | null - private lastArea?: Area; - private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); - - aboutToAppear() { - this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.flutterView?.addFirstFrameListener(this) - - this.flutterView?.setCheckFullScreen(this.checkFullScreen) - this.flutterView?.setCheckKeyboard(this.checkKeyboard) - this.flutterView?.setCheckGesture(this.checkGesture) + @Builder defaultPage() { + Stack() { + ForEach(this.rootDvModel!!, (child: ESObject) => { + DynamicView({ + model: child as DVModel, + params: child.params, + events: child.events, + children: child.children, + customBuilder: child.builder + }) + }, (child: ESObject) => `${child.id_}`) - this.rootDvModel = this.flutterView!!.getDVModel().children - } + Text('') + .id('emptyFocusText' + this.viewId) + .size({ width: 0, height: 0 }) + .opacity(0) + .focusable(true) - aboutToDisappear() { - this.flutterView?.removeFirstFrameListener(this); - } + XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) + .focusable(true) + .onLoad((context) => { + this.flutterView?.onSurfaceCreated() + Log.d(TAG, "XComponent onLoad "); + }) + .onDestroy(() => { + Log.d(TAG, "XComponent onDestroy "); + this.flutterView?.onSurfaceDestroyed() + }) + .backgroundColor(Color.Transparent) - onFirstFrame() { - this.showSplashScreen = false; + if (this.showSplashScreen) { + this.splashScreenView(); + } + } + .defaultFocus(true) + .onAreaChange((oldValue: Area, newValue: Area) => { + if (!this.lastArea || oldValue.width != newValue.width + || oldValue.height != newValue.height) { + Log.d(TAG, "onAreaChange, old=" + JSON.stringify(oldValue)); + Log.d(TAG, "onAreaChange, new=" + JSON.stringify(newValue)); + this.lastArea = newValue; + this.flutterView?.onAreaChange(newValue) + } + }) + .onKeyPreIme((event: KeyEvent) => { + Log.d(TAG, "onKeyEvent " + event.type); + this.flutterView?.onKeyEvent(event); + return false; + }) } - - build() { + @Builder mouseWheelPage() { Stack() { ForEach(this.rootDvModel!!, (child: ESObject) => { DynamicView({ @@ -130,4 +145,48 @@ export struct FlutterPage { }) ) } + @State showSplashScreen: boolean = true; + + @State checkFullScreen: boolean = true; + @State checkKeyboard: boolean = true; + @State checkGesture: boolean = true; + @State checkMouseWheel: boolean = true; + + @StorageLink('nodeWidth') storageLinkWidth: number = 0; + @StorageLink('nodeHeight') storageLinkHeight: number = 0; + + @State rootDvModel: DVModelChildren | undefined = undefined + + + private flutterView?: FlutterView | null + private lastArea?: Area; + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); + + aboutToAppear() { + this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); + this.flutterView?.addFirstFrameListener(this) + + this.flutterView?.setCheckFullScreen(this.checkFullScreen) + this.flutterView?.setCheckKeyboard(this.checkKeyboard) + this.flutterView?.setCheckGesture(this.checkGesture) + + this.rootDvModel = this.flutterView!!.getDVModel().children + + } + + aboutToDisappear() { + this.flutterView?.removeFirstFrameListener(this); + } + + onFirstFrame() { + this.showSplashScreen = false; + } + + build() { + if (this.checkMouseWheel) { + this.mouseWheelPage(); + } else { + this.defaultPage(); + } + } } -- Gitee From c0741583aa77dbd9e304d6eb70973a717cd6a95f Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Tue, 20 Aug 2024 09:24:34 +0800 Subject: [PATCH 5/9] =?UTF-8?q?flutterPage=E6=81=A2=E5=A4=8D=E4=B8=8E?= =?UTF-8?q?=E4=B8=BB=E5=B9=B2dev=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/embedding/ohos/FlutterPage.ets | 73 ++++--------------- 1 file changed, 13 insertions(+), 60 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 0fe00e5488..390bd370c6 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -31,25 +31,22 @@ export struct FlutterPage { @Builder doNothingBuilder() {} @BuilderParam splashScreenView: () => void = this.doNothingBuilder; - @Builder defaultPage() { - Stack() { - ForEach(this.rootDvModel!!, (child: ESObject) => { - DynamicView({ - model: child as DVModel, - params: child.params, - events: child.events, - children: child.children, - customBuilder: child.builder - }) - }, (child: ESObject) => `${child.id_}`) + @State showSplashScreen: boolean = true; + + @State checkFullScreen: boolean = true; + @State checkKeyboard: boolean = true; + @State checkGesture: boolean = true; + + @StorageLink('nodeWidth') storageLinkWidth: number = 0; + @StorageLink('nodeHeight') storageLinkHeight: number = 0; + + @State rootDvModel: DVModelChildren | undefined = undefined @State isNeedUpdate: boolean = false; - Text('') - .id('emptyFocusText' + this.viewId) - .size({ width: 0, height: 0 }) - .opacity(0) - .focusable(true) + private flutterView?: FlutterView | null + private lastArea?: Area; + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); aboutToAppear() { this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); @@ -139,48 +136,4 @@ export struct FlutterPage { }) ) } - @State showSplashScreen: boolean = true; - - @State checkFullScreen: boolean = true; - @State checkKeyboard: boolean = true; - @State checkGesture: boolean = true; - @State checkMouseWheel: boolean = true; - - @StorageLink('nodeWidth') storageLinkWidth: number = 0; - @StorageLink('nodeHeight') storageLinkHeight: number = 0; - - @State rootDvModel: DVModelChildren | undefined = undefined - - - private flutterView?: FlutterView | null - private lastArea?: Area; - private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); - - aboutToAppear() { - this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.flutterView?.addFirstFrameListener(this) - - this.flutterView?.setCheckFullScreen(this.checkFullScreen) - this.flutterView?.setCheckKeyboard(this.checkKeyboard) - this.flutterView?.setCheckGesture(this.checkGesture) - - this.rootDvModel = this.flutterView!!.getDVModel().children - - } - - aboutToDisappear() { - this.flutterView?.removeFirstFrameListener(this); - } - - onFirstFrame() { - this.showSplashScreen = false; - } - - build() { - if (this.checkMouseWheel) { - this.mouseWheelPage(); - } else { - this.defaultPage(); - } - } } -- Gitee From ad6af2067f1cba23d7809d2886e3165117407151 Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Tue, 20 Aug 2024 10:01:46 +0800 Subject: [PATCH 6/9] =?UTF-8?q?gesture=E5=B1=9E=E6=80=A7=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=8F=82=E6=95=B0checkMouseWheel=E6=9D=A5?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/embedding/ohos/FlutterPage.ets | 131 +++++++++++++----- 1 file changed, 96 insertions(+), 35 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index 390bd370c6..1634db5f6f 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -31,47 +31,60 @@ export struct FlutterPage { @Builder doNothingBuilder() {} @BuilderParam splashScreenView: () => void = this.doNothingBuilder; - @State showSplashScreen: boolean = true; - - @State checkFullScreen: boolean = true; - @State checkKeyboard: boolean = true; - @State checkGesture: boolean = true; - - @StorageLink('nodeWidth') storageLinkWidth: number = 0; - @StorageLink('nodeHeight') storageLinkHeight: number = 0; - - @State rootDvModel: DVModelChildren | undefined = undefined - - @State isNeedUpdate: boolean = false; + @Builder defaultPage() { + Stack() { + ForEach(this.rootDvModel!!, (child: ESObject) => { + DynamicView({ + model: child as DVModel, + params: child.params, + events: child.events, + children: child.children, + customBuilder: child.builder + }) + }, (child: ESObject) => `${child.id_}`) - private flutterView?: FlutterView | null - private lastArea?: Area; - private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); - aboutToAppear() { - this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.flutterView?.addFirstFrameListener(this) + Text('') + .id('emptyFocusText' + this.viewId) + .size({ width: 0, height: 0 }) + .opacity(0) + .focusable(true) - this.flutterView?.setCheckFullScreen(this.checkFullScreen) - this.flutterView?.setCheckKeyboard(this.checkKeyboard) - this.flutterView?.setCheckGesture(this.checkGesture) + XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) + .id(this.viewId) + .focusable(true) + .onLoad((context) => { + this.flutterView?.onSurfaceCreated() + Log.d(TAG, "XComponent onLoad "); + }) + .onDestroy(() => { + Log.d(TAG, "XComponent onDestroy "); + this.flutterView?.onSurfaceDestroyed() + }) + .backgroundColor(Color.Transparent) - this.rootDvModel = this.flutterView!!.getDVModel().children - getContext().eventHub.on(OHOS_FLUTTER_PAGE_UPDATE, () => { - this.isNeedUpdate = true; + if (this.showSplashScreen) { + this.splashScreenView(); + } + } + .defaultFocus(true) + .onAreaChange((oldValue: Area, newValue: Area) => { + if (this.isNeedUpdate || !this.lastArea || oldValue.width != newValue.width + || oldValue.height != newValue.height) { + Log.d(TAG, "onAreaChange, old=" + JSON.stringify(oldValue)); + Log.d(TAG, "onAreaChange, new=" + JSON.stringify(newValue)); + this.lastArea = newValue; + this.flutterView?.onAreaChange(newValue) + this.isNeedUpdate = false; + } + }) + .onKeyPreIme((event: KeyEvent) => { + Log.d(TAG, "onKeyEvent " + event.type); + this.flutterView?.onKeyEvent(event); + return false; }) } - - aboutToDisappear() { - this.flutterView?.removeFirstFrameListener(this); - getContext().eventHub.off(OHOS_FLUTTER_PAGE_UPDATE) - } - - onFirstFrame() { - this.showSplashScreen = false; - } - - build() { + @Builder mouseWheelPage() { Stack() { ForEach(this.rootDvModel!!, (child: ESObject) => { DynamicView({ @@ -136,4 +149,52 @@ export struct FlutterPage { }) ) } + @State showSplashScreen: boolean = true; + + @State checkFullScreen: boolean = true; + @State checkKeyboard: boolean = true; + @State checkGesture: boolean = true; + @State checkMouseWheel: boolean = true; + + @StorageLink('nodeWidth') storageLinkWidth: number = 0; + @StorageLink('nodeHeight') storageLinkHeight: number = 0; + + @State rootDvModel: DVModelChildren | undefined = undefined + + @State isNeedUpdate: boolean = false; + + private flutterView?: FlutterView | null + private lastArea?: Area; + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }); + + aboutToAppear() { + this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); + this.flutterView?.addFirstFrameListener(this) + + this.flutterView?.setCheckFullScreen(this.checkFullScreen) + this.flutterView?.setCheckKeyboard(this.checkKeyboard) + this.flutterView?.setCheckGesture(this.checkGesture) + + this.rootDvModel = this.flutterView!!.getDVModel().children + getContext().eventHub.on(OHOS_FLUTTER_PAGE_UPDATE, () => { + this.isNeedUpdate = true; + }) + } + + aboutToDisappear() { + this.flutterView?.removeFirstFrameListener(this); + getContext().eventHub.off(OHOS_FLUTTER_PAGE_UPDATE) + } + + onFirstFrame() { + this.showSplashScreen = false; + } + + build() { + if (this.checkMouseWheel) { + this.mouseWheelPage(); + } else { + this.defaultPage(); + } + } } -- Gitee From 139b6d1629e7fbe481224d4eb53de9f63e7592b0 Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Mon, 26 Aug 2024 20:54:15 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebview=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E7=A7=BB?= =?UTF-8?q?=E9=99=A4touch=E7=9A=84=E4=BA=8B=E4=BB=B6=E6=9D=A5=E6=BA=90?= =?UTF-8?q?=E5=88=A4=E6=96=AD=EF=BC=8C=E4=B8=8D=E6=8B=A6=E6=88=AA=E6=9D=A5?= =?UTF-8?q?=E8=87=AA=E9=BC=A0=E6=A0=87=E7=9A=84touch=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/platform/ohos/ohos_xcomponent_adapter.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index d1b62dcd70..46c51ccabb 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -373,13 +373,6 @@ void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, OH_NativeXComponent_GetTouchEvent(component, window, &touchEvent_); if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { if (isEngineAttached_) { - // if this touchEvent triggered by mouse, return - OH_NativeXComponent_EventSourceType sourceType; - int32_t ret2 = OH_NativeXComponent_GetTouchEventSourceType(component, touchEvent_.id, &sourceType); - if (ret2 == OH_NATIVEXCOMPONENT_RESULT_SUCCESS && - sourceType == OH_NATIVEXCOMPONENT_SOURCE_TYPE_MOUSE) { - return; - } ohosTouchProcessor_.HandleTouchEvent(std::stoll(shellholderId_), component, &touchEvent_); } else { -- Gitee From 252394a057294a5a638fab8df3df944913fc53a4 Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Fri, 13 Sep 2024 17:59:57 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E5=8D=95=E7=8B=AC=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=BC=A0=E6=A0=87=E4=BA=A7=E7=94=9F=E7=9A=84touch=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E4=BC=A0=E9=80=92=E7=BB=99PlatformView?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3webview=E6=97=A0=E6=B3=95=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/platform/ohos/ohos_touch_processor.cpp | 25 +++++++++++++++++++ shell/platform/ohos/ohos_touch_processor.h | 3 +++ .../platform/ohos/ohos_xcomponent_adapter.cpp | 8 ++++++ 3 files changed, 36 insertions(+) diff --git a/shell/platform/ohos/ohos_touch_processor.cpp b/shell/platform/ohos/ohos_touch_processor.cpp index 4849075ba0..1606a7da52 100644 --- a/shell/platform/ohos/ohos_touch_processor.cpp +++ b/shell/platform/ohos/ohos_touch_processor.cpp @@ -260,4 +260,29 @@ void OhosTouchProcessor::HandleMouseEvent( ohos_shell_holder->GetPlatformView()->DispatchPointerDataPacket(std::move(packet)); return; } + +void OhosTouchProcessor::HandleVirtualTouchEvent( + int64_t shell_holderID, + OH_NativeXComponent* component, + OH_NativeXComponent_TouchEvent* touchEvent) { + int numPoints = touchEvent->numPoints; + float tiltX = 0.0; + float tiltY = 0.0; + auto ohos_shell_holder = reinterpret_cast(shell_holderID); + OH_NativeXComponent_TouchPointToolType toolType; + OH_NativeXComponent_GetTouchPointToolType(component, 0, &toolType); + OH_NativeXComponent_GetTouchPointTiltX(component, 0, &tiltX); + OH_NativeXComponent_GetTouchPointTiltY(component, 0, &tiltY); + std::unique_ptr touchPacket = + std::make_unique(); + touchPacket->touchEventInput = touchEvent; + touchPacket->toolTypeInput = toolType; + touchPacket->tiltX = tiltX; + touchPacket->tiltX = tiltY; + + std::shared_ptr touchPacketString = packagePacketData(std::move(touchPacket)); + int size = CHANGES_POINTER_MEMBER + PER_POINTER_MEMBER * numPoints + TOUCH_EVENT_ADDITIONAL_ATTRIBUTES; + ohos_shell_holder->GetPlatformView()->OnTouchEvent(touchPacketString, size); + return; +} } // namespace flutter \ No newline at end of file diff --git a/shell/platform/ohos/ohos_touch_processor.h b/shell/platform/ohos/ohos_touch_processor.h index 94012bf1a8..1f59bd16a9 100644 --- a/shell/platform/ohos/ohos_touch_processor.h +++ b/shell/platform/ohos/ohos_touch_processor.h @@ -40,6 +40,9 @@ class OhosTouchProcessor { OH_NativeXComponent* component, OH_NativeXComponent_MouseEvent mouseEvent, double offsetY); + void HandleVirtualTouchEvent(int64_t shell_holderID, + OH_NativeXComponent* component, + OH_NativeXComponent_TouchEvent* touchEvent); flutter::PointerData::Change getPointerChangeForAction(int maskedAction); flutter::PointerData::DeviceKind getPointerDeviceTypeForToolType( int toolType); diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 46c51ccabb..562e17f44b 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -373,6 +373,14 @@ void XComponentBase::OnDispatchTouchEvent(OH_NativeXComponent* component, OH_NativeXComponent_GetTouchEvent(component, window, &touchEvent_); if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { if (isEngineAttached_) { + // if this touchEvent triggered by mouse, return + OH_NativeXComponent_EventSourceType sourceType; + int32_t ret2 = OH_NativeXComponent_GetTouchEventSourceType(component, touchEvent_.id, &sourceType); + if (ret2 == OH_NATIVEXCOMPONENT_RESULT_SUCCESS && + sourceType == OH_NATIVEXCOMPONENT_SOURCE_TYPE_MOUSE) { + ohosTouchProcessor_.HandleVirtualTouchEvent(std::stoll(shellholderId_), component, &touchEvent_); + return; + } ohosTouchProcessor_.HandleTouchEvent(std::stoll(shellholderId_), component, &touchEvent_); } else { -- Gitee From 6e6af4e8b39f5ebebe1ec92710793b4739f70abc Mon Sep 17 00:00:00 2001 From: duanaoqi Date: Thu, 26 Sep 2024 20:29:31 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E8=A7=A3=E5=86=B3scrollBar=E5=9C=A8pc?= =?UTF-8?q?=E4=B8=8A=E6=97=A0=E6=B3=95=E6=A8=AA=E5=90=91=E6=8B=96=E6=8B=BD?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: duanaoqi --- shell/platform/ohos/ohos_touch_processor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/ohos/ohos_touch_processor.cpp b/shell/platform/ohos/ohos_touch_processor.cpp index f3fec1b654..2e0af90819 100644 --- a/shell/platform/ohos/ohos_touch_processor.cpp +++ b/shell/platform/ohos/ohos_touch_processor.cpp @@ -244,11 +244,12 @@ void OhosTouchProcessor::HandleMouseEvent( pointerData.pressure = 0.0; pointerData.pressure_max = 1.0; pointerData.pressure_min = 0.0; - pointerData.kind = PointerData::DeviceKind::kMouse; + pointerData.kind = PointerData::DeviceKind::kTouch; pointerData.buttons = getPointerButtonFromMouse(mouseEvent.button); // hover support if (mouseEvent.button == OH_NATIVEXCOMPONENT_NONE_BUTTON && pointerData.change == PointerData::Change::kMove) { pointerData.change = PointerData::Change::kHover; + pointerData.kind = PointerData::DeviceKind::kMouse; pointerData.buttons = 0; } pointerData.pan_x = 0.0; -- Gitee