From 656c5d18cfb7838714d4a5b52ccaa1ea1a27c4fa Mon Sep 17 00:00:00 2001 From: houhaoyue Date: Tue, 24 Sep 2024 15:47:06 +0800 Subject: [PATCH 01/33] fix the onAreaChange position Signed-off-by: houhaoyue --- .../flutter/src/main/ets/view/FlutterView.ets | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 59038f9f33..02838a0127 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,7 +336,7 @@ export class FlutterView { } // 根据是否全屏显示,设置标题栏高度(若全屏,则及时规避) - if (this.checkFullScreen && (setFullScreen || FlutterManager.getInstance().getFullScreenListener().useFullScreen())) { // 全屏显示 + if (this.checkFullScreen && (setFullScreen || this.mainWindow.getWindowProperties().isLayoutFullScreen)) { // 全屏显示 this.viewportMetrics.physicalViewPaddingTop = this.systemAvoidArea?.topRect.height ?? 0; this.viewportMetrics.physicalViewPaddingBottom = this.navigationAvoidArea?.bottomRect.height ?? 0; } else { // 非全屏显示(保持规避效果) @@ -358,10 +358,10 @@ export class FlutterView { private onKeyboardAreaChange() { if (this.checkKeyboard) { let keyboardAvoidArea = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); - this.viewportMetrics.physicalViewInsetTop = keyboardAvoidArea?.topRect.height ?? 0 - this.viewportMetrics.physicalViewInsetLeft = keyboardAvoidArea?.leftRect.width ?? 0 - this.viewportMetrics.physicalViewInsetBottom = keyboardAvoidArea?.bottomRect.height ?? 0 - this.viewportMetrics.physicalViewInsetRight = keyboardAvoidArea?.rightRect.width ?? 0 + this.viewportMetrics.physicalViewInsetTop = this.keyboardAvoidArea!.topRect.height + this.viewportMetrics.physicalViewInsetLeft = this.keyboardAvoidArea!.leftRect.width + this.viewportMetrics.physicalViewInsetBottom = this.keyboardAvoidArea!.bottomRect.height + this.viewportMetrics.physicalViewInsetRight = this.keyboardAvoidArea!.rightRect.width } else { this.viewportMetrics.physicalViewInsetTop = 0 this.viewportMetrics.physicalViewInsetLeft = 0 @@ -373,10 +373,10 @@ export class FlutterView { private onGestureAreaChange() { if (this.checkGesture) { let gestureAvoidArea = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE); - this.viewportMetrics.systemGestureInsetTop = gestureAvoidArea?.topRect.height ?? 0 - this.viewportMetrics.systemGestureInsetLeft = gestureAvoidArea?.leftRect.width ?? 0 - this.viewportMetrics.systemGestureInsetBottom = gestureAvoidArea?.bottomRect.height ?? 0 - this.viewportMetrics.systemGestureInsetRight = gestureAvoidArea?.rightRect.width ?? 0 + this.viewportMetrics.systemGestureInsetTop = this.gestureAvoidArea!.topRect.height + this.viewportMetrics.systemGestureInsetLeft = this.gestureAvoidArea!.leftRect.width + this.viewportMetrics.systemGestureInsetBottom = this.gestureAvoidArea!.bottomRect.height + this.viewportMetrics.systemGestureInsetRight = this.gestureAvoidArea!.rightRect.width } else { this.viewportMetrics.systemGestureInsetTop = 0 this.viewportMetrics.systemGestureInsetLeft = 0 -- Gitee From d49c19745a1a849a343a552745d4fadf3b862ee8 Mon Sep 17 00:00:00 2001 From: houhaoyue Date: Tue, 24 Sep 2024 19:09:26 +0800 Subject: [PATCH 02/33] fix Signed-off-by: houhaoyue --- .../flutter/src/main/ets/view/FlutterView.ets | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 02838a0127..0a0ffca259 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 @@ -166,16 +166,16 @@ export class FlutterView { private avoidAreaChangeCallback = (data: window.AvoidAreaOptions) => { Log.i(TAG, "avoidAreaChangeCallback, type=" + data.type); + if (data.type == window.AvoidAreaType.TYPE_SYSTEM) { //0 + this.systemAvoidArea = data.area; + } else if (data.type == window.AvoidAreaType.TYPE_SYSTEM_GESTURE) { //2 + this.gestureAvoidArea = data.area; + } else if (data.type == window.AvoidAreaType.TYPE_KEYBOARD) { //3 + this.keyboardAvoidArea = data.area; + } else if (data.type == window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { //4 + this.navigationAvoidArea = data.area; + } if (this.isAttachedToFlutterEngine()) { - if (data.type == window.AvoidAreaType.TYPE_SYSTEM) { //0 - this.systemAvoidArea = data.area; - } else if (data.type == window.AvoidAreaType.TYPE_SYSTEM_GESTURE) { //2 - this.gestureAvoidArea = data.area; - } else if (data.type == window.AvoidAreaType.TYPE_KEYBOARD) { //3 - this.keyboardAvoidArea = data.area; - } else if (data.type == window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { //4 - this.navigationAvoidArea = data.area; - } this.onAreaChange(null); } } -- Gitee From 94d91b8d2d6ca8de7ecf0f447d6d93964d56ff00 Mon Sep 17 00:00:00 2001 From: houhaoyue Date: Wed, 25 Sep 2024 17:08:29 +0800 Subject: [PATCH 03/33] fix the issue where physicalSize is overwritten by display size when the app invokes onAreaChange before attaching the engine Signed-off-by: houhaoyue --- .../flutter/src/main/ets/view/FlutterView.ets | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 0a0ffca259..a1e447533d 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 @@ -135,6 +135,7 @@ export class FlutterView { private navigationAvoidArea: window.AvoidArea; private gestureAvoidArea: window.AvoidArea; private keyboardAvoidArea: window.AvoidArea; + private needSetViewport: boolean = false; constructor(viewId: string, context: Context) { @@ -350,8 +351,10 @@ export class FlutterView { this.onKeyboardAreaChange() this.onGestureAreaChange() - if (!this.viewportMetrics.isEqual(originalMetrics)) { - this.updateViewportMetrics() + if (!this.viewportMetrics.isEqual(originalMetrics) || this.needSetViewport) { + if (!this.updateViewportMetrics()) { + this.needSetViewport = true; + } } } @@ -389,7 +392,7 @@ export class FlutterView { return this.flutterEngine != null } - private updateViewportMetrics() { + private updateViewportMetrics(): boolean{ if (this.isAttachedToFlutterEngine()) { this?.flutterEngine?.getFlutterNapi()?.setViewportMetrics(this.viewportMetrics.devicePixelRatio, this.viewportMetrics.physicalWidth, @@ -410,7 +413,9 @@ export class FlutterView { new Array(0), new Array(0), new Array(0)) + return true; } + return false; } onKeyEvent(event: KeyEvent) { -- Gitee From 5d12789e71e8358266b99a7bb53f6042f229b3dd Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Mon, 7 Oct 2024 16:26:42 +0800 Subject: [PATCH 04/33] =?UTF-8?q?=E5=9B=9E=E9=80=80PR416=E7=9A=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20=E5=A2=9E=E5=8A=A0InputMethod=E7=9A=84detach?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BF=9D=E8=AF=81=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E6=8B=89=E8=B5=B7=E8=BD=AF=E9=94=AE=E7=9B=98=E5=8F=AF=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../ets/plugin/editing/TextInputPlugin.ets | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index c499dacb39..36c52b7faa 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -17,17 +17,11 @@ import TextInputChannel, { Configuration, TextEditState, TextInputMethodHandler, - TextInputType } from '../../embedding/engine/systemchannels/TextInputChannel'; import inputMethod from '@ohos.inputMethod'; import Log from '../../util/Log'; import { EditingStateWatcher, ListenableEditingState } from './ListenableEditingState'; import Any from '../common/Any'; -import { window } from '@kit.ArkUI'; -import FlutterManager from '../../embedding/ohos/FlutterManager'; -import { IntentionCode } from '@ohos.multimodalInput.intentionCode'; -import {KeyCode} from '@kit.InputKit'; -import { BusinessError } from '@kit.BasicServicesKit'; /// 临时规避缺少newline对应枚举问题 const NEWLINE_KEY_TYPE: number = 8; @@ -273,37 +267,12 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.imcFlag = true; } - sendKeyboardEvent(type: KeyType, keyCode: number): void { - let event: KeyEvent = { - type: type, - keyCode: keyCode, - keyText: '', - keySource: KeySource.Keyboard, - deviceId: 0, - metaKey: 0, - timestamp: 0, - stopPropagation: (): void => { - throw new Error('Function not implemented.'); - }, - intentionCode: IntentionCode.INTENTION_BACK - } - FlutterManager.getInstance().getFlutterViewList().forEach((value) => { - value.onKeyEvent(event) - }) - } - private insertTextCallback = (text: string) => { Log.d(TextInputMethodHandlerImpl.TAG, "insertText: " + text); this.mEditable.handleInsertTextEvent(text); } private deleteLeftCallback = (length: number) => { - /// 暂时规避方案 - /// OS机制与Android不一致,需要去监听软键盘事件才能发送KeyEvent事件 - if (this.mEditable.getStringCache() == "") { - this.sendKeyboardEvent(KeyType.Down, KeyCode.KEYCODE_DEL) - this.sendKeyboardEvent(KeyType.Up, KeyCode.KEYCODE_DEL) - } this.mEditable.handleDeleteEvent(false, length); } @@ -340,6 +309,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.inputMethodController.off('sendKeyboardStatus', this.sendKeyboardStatusCallback); this.inputMethodController.off('selectByRange', this.selectByRangeCallback); this.imcFlag = false; + this.inputMethodController.detach() } public clearTextInputClient(): void { -- Gitee From f8a8256a8fed52524e9eb4eca776d8d4fa10b02c Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Mon, 7 Oct 2024 18:44:41 +0800 Subject: [PATCH 05/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=96=E6=8E=A5?= =?UTF-8?q?=E7=BA=B9=E7=90=86=E9=A6=96=E5=B8=A7=E6=B8=B2=E6=9F=93=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- shell/platform/ohos/ohos_external_texture_gl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 46fa22e2a0..59887d8d3d 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -134,7 +134,7 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, GrGLTextureInfo textureInfo; - if (!freeze && !first_update_ && !isEmulator_ && backGroundTextureName_ == 0 && pixelMap_ == nullptr) { + if (!freeze && !first_update_ && !isEmulator_ && !new_frame_ready_ && pixelMap_ == nullptr) { setBackground(bounds.width(), bounds.height()); textureInfo = {GL_TEXTURE_EXTERNAL_OES, backGroundTextureName_, GL_RGBA8_OES}; } else { -- Gitee From ff03e9210aaa7a024d91db05ced7cc503b08494a Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Tue, 8 Oct 2024 14:58:34 +0800 Subject: [PATCH 06/33] =?UTF-8?q?=E9=80=82=E9=85=8D=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=B3=95=E9=A2=84=E4=B8=8A=E5=B1=8F=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../src/main/ets/plugin/editing/TextInputPlugin.ets | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index 36c52b7faa..6a6b814e38 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -270,14 +270,17 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { private insertTextCallback = (text: string) => { Log.d(TextInputMethodHandlerImpl.TAG, "insertText: " + text); this.mEditable.handleInsertTextEvent(text); + this.changeSelection(); } private deleteLeftCallback = (length: number) => { this.mEditable.handleDeleteEvent(false, length); + this.changeSelection(); } private deleteRightCallback = (length: number) => { this.mEditable.handleDeleteEvent(true, length); + this.changeSelection(); } private sendFunctionKeyCallback = (functionKey: inputMethod.FunctionKey) => { @@ -301,6 +304,14 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.mEditable.handleSelectByRange(range); } + changeSelection(): void { + try { + this.inputMethodController.changeSelection(this.mEditable.getStringCache(), this.mEditable.getSelectionStart(), this.mEditable.getSelectionEnd()); + } catch (err) { + Log.e(TextInputMethodHandlerImpl.TAG, "Failed to changeSelection:" + JSON.stringify(err)); + } + } + cancelListenKeyBoardEvent(): void { this.inputMethodController.off('insertText', this.insertTextCallback); this.inputMethodController.off('deleteLeft', this.deleteLeftCallback); -- Gitee From 0aa37307d94dea6bb2e8ed4684c6f2a081fb92f6 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Tue, 8 Oct 2024 18:59:42 +0800 Subject: [PATCH 07/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9NativeWindow=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E7=A8=B3=E5=AE=9A=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- shell/platform/ohos/ohos_xcomponent_adapter.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 4d49b0c753..12c633ec66 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -330,9 +330,13 @@ void XComponentBase::OnSurfaceCreated(OH_NativeXComponent* component, (int)height_); ret = SetNativeWindowOpt((OHNativeWindow*)window, width_, height_); if (ret) { - LOGD("SetNativeWindowOpt failed:%{public}d", ret); + LOGE("SetNativeWindowOpt failed:%{public}d", ret); } if (isEngineAttached_) { + ret = OH_NativeWindow_NativeObjectReference(window); + if (ret) { + LOGE("NativeObjectReference failed:%{public}d", ret); + } PlatformViewOHOSNapi::SurfaceCreated(std::stoll(shellholderId_), window); } else { LOGE("OnSurfaceCreated XComponentBase is not attached"); @@ -362,8 +366,12 @@ void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, LOGD("XComponentManger::OnSurfaceDestroyed"); if (isEngineAttached_) { PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); + int32_t ret = OH_NativeWindow_NativeObjectUnreference(window); + if (ret) { + LOGE("NativeObjectReference failed:%{public}d", ret); + } } else { - LOGE("OnSurfaceCreated OnSurfaceDestroyed is not attached"); + LOGE("XComponentManger::OnSurfaceDestroyed XComponentBase is not attached"); } } -- Gitee From ca0289c1c054f46c044a2897e36738ef422b7da5 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Tue, 8 Oct 2024 21:31:56 +0800 Subject: [PATCH 08/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- shell/platform/ohos/ohos_xcomponent_adapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index 12c633ec66..d6b8f9446d 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -368,7 +368,7 @@ void XComponentBase::OnSurfaceDestroyed(OH_NativeXComponent* component, PlatformViewOHOSNapi::SurfaceDestroyed(std::stoll(shellholderId_)); int32_t ret = OH_NativeWindow_NativeObjectUnreference(window); if (ret) { - LOGE("NativeObjectReference failed:%{public}d", ret); + LOGE("NativeObjectUnreference failed:%{public}d", ret); } } else { LOGE("XComponentManger::OnSurfaceDestroyed XComponentBase is not attached"); -- Gitee From 89b5494a05189e6f10183224b8ebaa34b7b48f89 Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Wed, 9 Oct 2024 11:43:09 +0800 Subject: [PATCH 09/33] =?UTF-8?q?=E8=A7=A3=E5=86=B3YUV10bit=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E7=BC=A9=E7=95=A5=E5=9B=BE=E8=8A=B1=E5=B1=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwyang <137208408@qq.com> --- .../ohos/ohos_external_texture_gl.cpp | 53 ++++++++++++++++++- .../platform/ohos/ohos_external_texture_gl.h | 1 + 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 59887d8d3d..966afa007a 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -39,6 +39,42 @@ constexpr const char *EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland"; constexpr const char *EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland"; constexpr const char *EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT"; +static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) { + switch (pixel_format) { + case PIXEL_FORMAT_RGB_565: + return NATIVEBUFFER_PIXEL_FMT_RGB_565; + case PIXEL_FORMAT_RGBA_8888: + return NATIVEBUFFER_PIXEL_FMT_RGBA_8888; + case PIXEL_FORMAT_BGRA_8888: + return NATIVEBUFFER_PIXEL_FMT_BGRA_8888; + case PIXEL_FORMAT_RGB_888: + return NATIVEBUFFER_PIXEL_FMT_RGB_888; + case PIXEL_FORMAT_NV21: + return NATIVEBUFFER_PIXEL_FMT_YCRCB_420_SP; + case PIXEL_FORMAT_NV12: + return NATIVEBUFFER_PIXEL_FMT_YCBCR_420_SP; + case PIXEL_FORMAT_RGBA_1010102: + return NATIVEBUFFER_PIXEL_FMT_RGBA_1010102; + case PIXEL_FORMAT_YCBCR_P010: + return NATIVEBUFFER_PIXEL_FMT_YCBCR_P010; + case PIXEL_FORMAT_YCRCB_P010: + return NATIVEBUFFER_PIXEL_FMT_YCRCB_P010; + case PIXEL_FORMAT_ALPHA_8: + case PIXEL_FORMAT_RGBA_F16: + case PIXEL_FORMAT_UNKNOWN: + default: + // no support/unknow format: cannot copy + return 0; + } + return 0; +} + +static bool IsPixelMapYUVFormat(PIXEL_FORMAT format) { + return format == PIXEL_FORMAT_NV21 || format == PIXEL_FORMAT_NV12 || + format == PIXEL_FORMAT_YCBCR_P010 || format == PIXEL_FORMAT_YCRCB_P010; +} + + OHOSExternalTextureGL::OHOSExternalTextureGL(int64_t id, const std::shared_ptr& ohos_surface) : Texture(id), ohos_surface_(std::move(ohos_surface)), transform(SkMatrix::I()) { @@ -410,6 +446,10 @@ void OHOSExternalTextureGL::ProducePixelMapToBackGroundImage() << ret; return; } + + int window_format = PixelMapToWindowFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat); + ret = OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, SET_FORMAT, window_format); + uint64_t usage = 0; OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, GET_USAGE, &usage); usage |= NATIVEBUFFER_USAGE_CPU_READ; @@ -478,13 +518,22 @@ void OHOSExternalTextureGL::HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNat FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowSize:" << pixelMapInfo.rowSize << " format:" << pixelMapInfo.pixelFormat; + FML_LOG(ERROR)<<"OHOSExternalTextureGL IsPixelMapYUVFormat 0"; + + uint32_t real_height = pixelMapInfo.height; + if (IsPixelMapYUVFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat)) { + FML_LOG(ERROR)<<"OHOSExternalTextureGL IsPixelMapYUVFormat 1"; + // y is height, uv is height/2 + real_height = pixelMapInfo.height + (pixelMapInfo.height + 1) / 2; + } + // 复制图片纹理数据到内存中,需要处理DMA内存补齐相关的逻辑 if (pixelMapInfo.width * PIXEL_SIZE != pixelMapInfo.rowSize) { // 直接复制整块内存 - memcpy(destAddr, pixel, pixelMapInfo.height * pixelMapInfo.rowSize); + memcpy(destAddr, pixel, real_height * pixelMapInfo.rowSize); } else { // 需要处理DMA内存补齐相关的逻辑 - for (uint32_t i = 0; i < pixelMapInfo.height; i++) { + for (uint32_t i = 0; i < real_height; i++) { memcpy(destAddr, pixel, pixelMapInfo.rowSize); destAddr += stride / PIXEL_SIZE; pixel += pixelMapInfo.width; diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index 5ac18743a6..2458ac9c54 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include -- Gitee From 388d241eea692a83e22556d41f81ef7491a61375 Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Wed, 9 Oct 2024 11:47:03 +0800 Subject: [PATCH 10/33] =?UTF-8?q?=E8=A7=A3=E5=86=B3YUV10bit=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E7=BC=A9=E7=95=A5=E5=9B=BE=E8=8A=B1=E5=B1=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwyang <137208408@qq.com> --- shell/platform/ohos/ohos_external_texture_gl.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 966afa007a..ac9f116b78 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -518,11 +518,9 @@ void OHOSExternalTextureGL::HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNat FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowSize:" << pixelMapInfo.rowSize << " format:" << pixelMapInfo.pixelFormat; - FML_LOG(ERROR)<<"OHOSExternalTextureGL IsPixelMapYUVFormat 0"; uint32_t real_height = pixelMapInfo.height; if (IsPixelMapYUVFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat)) { - FML_LOG(ERROR)<<"OHOSExternalTextureGL IsPixelMapYUVFormat 1"; // y is height, uv is height/2 real_height = pixelMapInfo.height + (pixelMapInfo.height + 1) / 2; } -- Gitee From 3f7f42b91ca42d9ba4fd3c35fd0e1f60b9f2d10e Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Wed, 9 Oct 2024 16:52:40 +0800 Subject: [PATCH 11/33] =?UTF-8?q?=E9=97=A8=E7=A6=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwyang <137208408@qq.com> --- shell/platform/ohos/ohos_external_texture_gl.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index ac9f116b78..05c8449bf5 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -39,7 +39,8 @@ constexpr const char *EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland"; constexpr const char *EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland"; constexpr const char *EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT"; -static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) { +static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) +{ switch (pixel_format) { case PIXEL_FORMAT_RGB_565: return NATIVEBUFFER_PIXEL_FMT_RGB_565; @@ -69,7 +70,8 @@ static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) { return 0; } -static bool IsPixelMapYUVFormat(PIXEL_FORMAT format) { +static bool IsPixelMapYUVFormat(PIXEL_FORMAT format) +{ return format == PIXEL_FORMAT_NV21 || format == PIXEL_FORMAT_NV12 || format == PIXEL_FORMAT_YCBCR_P010 || format == PIXEL_FORMAT_YCRCB_P010; } @@ -447,8 +449,8 @@ void OHOSExternalTextureGL::ProducePixelMapToBackGroundImage() return; } - int window_format = PixelMapToWindowFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat); - ret = OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, SET_FORMAT, window_format); + int windowFormat = PixelMapToWindowFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat); + ret = OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, SET_FORMAT, windowFormat); uint64_t usage = 0; OH_NativeWindow_NativeWindowHandleOpt(backGroundNativeWindow_, GET_USAGE, &usage); @@ -518,7 +520,6 @@ void OHOSExternalTextureGL::HandlePixelMapBuffer(NativePixelMap* pixelMap, OHNat FML_DLOG(INFO) << "OHOSExternalTextureGL pixelMapInfo rowSize:" << pixelMapInfo.rowSize << " format:" << pixelMapInfo.pixelFormat; - uint32_t real_height = pixelMapInfo.height; if (IsPixelMapYUVFormat((PIXEL_FORMAT)pixelMapInfo.pixelFormat)) { // y is height, uv is height/2 -- Gitee From 2e9492b727c6b4cabec265fbf3ce7952b114b099 Mon Sep 17 00:00:00 2001 From: houhaoyue Date: Thu, 10 Oct 2024 09:18:47 +0800 Subject: [PATCH 12/33] fix Signed-off-by: houhaoyue --- .../flutter_embedding/flutter/src/main/ets/view/FlutterView.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a1e447533d..0488d6e131 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 @@ -337,7 +337,7 @@ export class FlutterView { } // 根据是否全屏显示,设置标题栏高度(若全屏,则及时规避) - if (this.checkFullScreen && (setFullScreen || this.mainWindow.getWindowProperties().isLayoutFullScreen)) { // 全屏显示 + if (this.checkFullScreen && (setFullScreen || this.mainWindow?.getWindowProperties().isLayoutFullScreen)) { // 全屏显示 this.viewportMetrics.physicalViewPaddingTop = this.systemAvoidArea?.topRect.height ?? 0; this.viewportMetrics.physicalViewPaddingBottom = this.navigationAvoidArea?.bottomRect.height ?? 0; } else { // 非全屏显示(保持规避效果) -- Gitee From a05a3a39e3fc95b51d95dc2c31091fca5fe9e0ee Mon Sep 17 00:00:00 2001 From: houhaoyue Date: Thu, 10 Oct 2024 14:33:36 +0800 Subject: [PATCH 13/33] fix: code check Signed-off-by: houhaoyue --- .../flutter/src/main/ets/view/FlutterView.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 0488d6e131..2649e43296 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 @@ -360,7 +360,7 @@ export class FlutterView { private onKeyboardAreaChange() { if (this.checkKeyboard) { - let keyboardAvoidArea = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); + let keyboardAvoidArea: window.AvoidArea | null = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); this.viewportMetrics.physicalViewInsetTop = this.keyboardAvoidArea!.topRect.height this.viewportMetrics.physicalViewInsetLeft = this.keyboardAvoidArea!.leftRect.width this.viewportMetrics.physicalViewInsetBottom = this.keyboardAvoidArea!.bottomRect.height @@ -375,7 +375,7 @@ export class FlutterView { private onGestureAreaChange() { if (this.checkGesture) { - let gestureAvoidArea = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE); + let gestureAvoidArea: window.AvoidArea | null = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE); this.viewportMetrics.systemGestureInsetTop = this.gestureAvoidArea!.topRect.height this.viewportMetrics.systemGestureInsetLeft = this.gestureAvoidArea!.leftRect.width this.viewportMetrics.systemGestureInsetBottom = this.gestureAvoidArea!.bottomRect.height @@ -392,7 +392,7 @@ export class FlutterView { return this.flutterEngine != null } - private updateViewportMetrics(): boolean{ + private updateViewportMetrics(): boolean { if (this.isAttachedToFlutterEngine()) { this?.flutterEngine?.getFlutterNapi()?.setViewportMetrics(this.viewportMetrics.devicePixelRatio, this.viewportMetrics.physicalWidth, -- Gitee From cf09170d64d87583280bc36a2ba665eec24e35a0 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Tue, 8 Oct 2024 16:08:23 +0800 Subject: [PATCH 14/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=96=E6=8E=A5?= =?UTF-8?q?=E7=BA=B9=E7=90=86=E7=9A=84Detach=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- .../ohos/ohos_external_texture_gl.cpp | 71 +++++++++++-------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 05c8449bf5..69d104bb71 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -99,14 +99,7 @@ OHOSExternalTextureGL::~OHOSExternalTextureGL() { FML_DLOG(INFO) << "~OHOSExternalTextureGL, texture_name_=" << texture_name_ << ", Id()=" << Id(); if (state_ == AttachmentState::attached) { - if (texture_name_ != 0) { - glDeleteTextures(1, &texture_name_); - texture_name_ = 0; - } - if (backGroundTextureName_ != 0) { - glDeleteTextures(1, &backGroundTextureName_); - backGroundTextureName_ = 0; - } + Detach(); } state_ = AttachmentState::uninitialized; nativeImage_ = nullptr; @@ -124,7 +117,6 @@ OHOSExternalTextureGL::~OHOSExternalTextureGL() void OHOSExternalTextureGL::Attach() { - FML_DLOG(INFO) << "OHOSExternalTextureGL::Attach, Id()=" << Id(); if (state_ != AttachmentState::uninitialized) { FML_LOG(ERROR) << "OHOSExternalTextureGL::Attach, the current status is not uninitialized"; return; @@ -216,20 +208,20 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, void OHOSExternalTextureGL::OnGrContextCreated() { - FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextCreated"; + FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextCreated" + << ", texture_name_=" << texture_name_ + << ", Id()=" << Id(); state_ = AttachmentState::uninitialized; } void OHOSExternalTextureGL::OnGrContextDestroyed() { - FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextDestroyed"; + FML_DLOG(INFO) << " OHOSExternalTextureGL::OnGrContextDestroyed" + << ", texture_name_=" << texture_name_ + << ", Id()=" << Id(); if (state_ == AttachmentState::attached) { Detach(); - glDeleteTextures(1, &texture_name_); - } - state_ = AttachmentState::detached; - if (backGroundTextureName_ != 0) { - glDeleteTextures(1, &backGroundTextureName_); + state_ = AttachmentState::detached; } } @@ -253,14 +245,9 @@ void OHOSExternalTextureGL::OnTextureUnregistered() << ", nativeImage_=" << nativeImage_ << ", backGroundNativeImage_=" << backGroundNativeImage_; first_update_ = false; - if (nativeImage_ != nullptr) { - OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage_); - OH_NativeImage_Destroy(&nativeImage_); - nativeImage_ = nullptr; - } - if (backGroundNativeImage_ != nullptr) { - OH_NativeImage_Destroy(&backGroundNativeImage_); - backGroundNativeImage_ = nullptr; + if (state_ == AttachmentState::attached) { + Detach(); + state_ = AttachmentState::detached; } } @@ -287,12 +274,36 @@ void OHOSExternalTextureGL::Detach() FML_LOG(ERROR) << "OHOSExternalTextureGL::Detach, the current status is not attached"; return; } - OH_NativeImage_DetachContext(nativeImage_); - OH_NativeImage_DetachContext(backGroundNativeImage_); - OH_NativeWindow_DestroyNativeWindow(nativeWindow_); - OH_NativeWindow_DestroyNativeWindow(backGroundNativeWindow_); - nativeWindow_ = nullptr; - backGroundNativeWindow_ = nullptr; + + if (nativeImage_ != nullptr) { + OH_NativeImage_DetachContext(nativeImage_); + OH_NativeImage_UnsetOnFrameAvailableListener(nativeImage_); + OH_NativeImage_Destroy(&nativeImage_); + nativeImage_ = nullptr; + } + if (nativeWindow_ != nullptr) { + OH_NativeWindow_DestroyNativeWindow(nativeWindow_); + nativeWindow_ = nullptr; + } + + if (backGroundNativeImage_ != nullptr) { + OH_NativeImage_DetachContext(backGroundNativeImage_); + OH_NativeImage_Destroy(&backGroundNativeImage_); + backGroundNativeImage_ = nullptr; + } + if (backGroundNativeWindow_ != nullptr) { + OH_NativeWindow_DestroyNativeWindow(backGroundNativeWindow_); + backGroundNativeWindow_ = nullptr; + } + + if (texture_name_ != 0) { + glDeleteTextures(1, &texture_name_); + texture_name_ = 0; + } + if (backGroundTextureName_ != 0) { + glDeleteTextures(1, &backGroundTextureName_); + backGroundTextureName_ = 0; + } } void OHOSExternalTextureGL::UpdateTransform(OH_NativeImage *image) -- Gitee From 4cbf3e0a660adc09880fa88b6d172391bb4653b7 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Tue, 8 Oct 2024 21:30:05 +0800 Subject: [PATCH 15/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9A=E5=BC=95?= =?UTF-8?q?=E6=93=8E=E5=9C=BA=E6=99=AF=E7=9A=84=E5=A4=96=E6=8E=A5=E7=BA=B9?= =?UTF-8?q?=E7=90=86=E7=9B=B8=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- shell/platform/ohos/ohos_external_texture_gl.cpp | 6 ++++++ shell/platform/ohos/ohos_external_texture_gl.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 69d104bb71..741edd1020 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -161,6 +161,10 @@ void OHOSExternalTextureGL::Paint(PaintContext& context, FML_LOG(ERROR) << "OHOSExternalTextureGL::Paint, the current status is detached"; return; } + if (!freeze && texture_update_ && pixelMap_ == nullptr) { + // 多引擎场景(multi_flutters_ohos)需要在这里执行Update + Update(); + } GrGLTextureInfo textureInfo; @@ -229,6 +233,7 @@ void OHOSExternalTextureGL::MarkNewFrameAvailable() { FML_DLOG(INFO) << " OHOSExternalTextureGL::MarkNewFrameAvailable"; new_frame_ready_ = true; + texture_update_ = true; if (texture_name_ == 0) { Attach(); } @@ -259,6 +264,7 @@ void OHOSExternalTextureGL::Update() return; } int32_t ret = OH_NativeImage_UpdateSurfaceImage(nativeImage_); + texture_update_ = false; if (ret != 0) { FML_LOG(ERROR) << "OHOSExternalTextureGL OH_NativeImage_UpdateSurfaceImage err code:" << ret; return; diff --git a/shell/platform/ohos/ohos_external_texture_gl.h b/shell/platform/ohos/ohos_external_texture_gl.h index 2458ac9c54..26847c228b 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.h +++ b/shell/platform/ohos/ohos_external_texture_gl.h @@ -97,6 +97,8 @@ class OHOSExternalTextureGL : public flutter::Texture { bool new_frame_ready_ = false; + bool texture_update_ = false; + GLuint texture_name_ = 0; GLuint backGroundTextureName_ = 0; -- Gitee From efd86c6e94c76a2b69cd1d12c566a0a543626ff3 Mon Sep 17 00:00:00 2001 From: houhaoyue Date: Thu, 10 Oct 2024 17:08:45 +0800 Subject: [PATCH 16/33] fix Signed-off-by: houhaoyue --- .../flutter/src/main/ets/view/FlutterView.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 2649e43296..a508977720 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 @@ -360,7 +360,7 @@ export class FlutterView { private onKeyboardAreaChange() { if (this.checkKeyboard) { - let keyboardAvoidArea: window.AvoidArea | null = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); + let keyboardAvoidArea: window.AvoidArea | undefined = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); this.viewportMetrics.physicalViewInsetTop = this.keyboardAvoidArea!.topRect.height this.viewportMetrics.physicalViewInsetLeft = this.keyboardAvoidArea!.leftRect.width this.viewportMetrics.physicalViewInsetBottom = this.keyboardAvoidArea!.bottomRect.height @@ -375,7 +375,7 @@ export class FlutterView { private onGestureAreaChange() { if (this.checkGesture) { - let gestureAvoidArea: window.AvoidArea | null = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE); + let gestureAvoidArea: window.AvoidArea | undefined = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE); this.viewportMetrics.systemGestureInsetTop = this.gestureAvoidArea!.topRect.height this.viewportMetrics.systemGestureInsetLeft = this.gestureAvoidArea!.leftRect.width this.viewportMetrics.systemGestureInsetBottom = this.gestureAvoidArea!.bottomRect.height -- Gitee From 66d3e41a7d452c150e0603235effe371fcca7de1 Mon Sep 17 00:00:00 2001 From: houhaoyue Date: Thu, 10 Oct 2024 18:48:32 +0800 Subject: [PATCH 17/33] fix Signed-off-by: houhaoyue --- .../flutter/src/main/ets/view/FlutterView.ets | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) 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 a508977720..7a15e99e5d 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 @@ -360,11 +360,10 @@ export class FlutterView { private onKeyboardAreaChange() { if (this.checkKeyboard) { - let keyboardAvoidArea: window.AvoidArea | undefined = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_KEYBOARD); - this.viewportMetrics.physicalViewInsetTop = this.keyboardAvoidArea!.topRect.height - this.viewportMetrics.physicalViewInsetLeft = this.keyboardAvoidArea!.leftRect.width - this.viewportMetrics.physicalViewInsetBottom = this.keyboardAvoidArea!.bottomRect.height - this.viewportMetrics.physicalViewInsetRight = this.keyboardAvoidArea!.rightRect.width + this.viewportMetrics.physicalViewInsetTop = this.keyboardAvoidArea?.topRect.height ?? 0 + this.viewportMetrics.physicalViewInsetLeft = this.keyboardAvoidArea?.leftRect.width ?? 0 + this.viewportMetrics.physicalViewInsetBottom = this.keyboardAvoidArea?.bottomRect.height ?? 0 + this.viewportMetrics.physicalViewInsetRight = this.keyboardAvoidArea?.rightRect.width ?? 0 } else { this.viewportMetrics.physicalViewInsetTop = 0 this.viewportMetrics.physicalViewInsetLeft = 0 @@ -375,11 +374,10 @@ export class FlutterView { private onGestureAreaChange() { if (this.checkGesture) { - let gestureAvoidArea: window.AvoidArea | undefined = this.mainWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM_GESTURE); - this.viewportMetrics.systemGestureInsetTop = this.gestureAvoidArea!.topRect.height - this.viewportMetrics.systemGestureInsetLeft = this.gestureAvoidArea!.leftRect.width - this.viewportMetrics.systemGestureInsetBottom = this.gestureAvoidArea!.bottomRect.height - this.viewportMetrics.systemGestureInsetRight = this.gestureAvoidArea!.rightRect.width + this.viewportMetrics.systemGestureInsetTop = this.gestureAvoidArea?.topRect.height ?? 0 + this.viewportMetrics.systemGestureInsetLeft = this.gestureAvoidArea?.leftRect.width ?? 0 + this.viewportMetrics.systemGestureInsetBottom = this.gestureAvoidArea?.bottomRect.height ?? 0 + this.viewportMetrics.systemGestureInsetRight = this.gestureAvoidArea?.rightRect.width ?? 0 } else { this.viewportMetrics.systemGestureInsetTop = 0 this.viewportMetrics.systemGestureInsetLeft = 0 -- Gitee From 02aa5430550b20b586b8431450d522be8c608e20 Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Fri, 11 Oct 2024 16:34:52 +0800 Subject: [PATCH 18/33] =?UTF-8?q?=E5=9B=9E=E9=80=80pr486=E7=9A=84=E4=B8=8D?= =?UTF-8?q?=E5=90=88=E7=90=86=E4=BF=AE=E6=94=B9=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=8D=E5=90=88=E7=90=86=E7=9A=84=E6=96=B9=E6=B3=95=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../ets/plugin/editing/TextInputPlugin.ets | 30 ++----------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index 6a6b814e38..60888e9b95 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -78,7 +78,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { mEditable: ListenableEditingState; private mRestartInputPending: boolean = false; private plugin: EditingStateWatcher | Any; - private imcFlag: boolean = false; private inputTypeNone: string = 'NONE' private keyboardStatus: inputMethod.KeyboardStatus = inputMethod.KeyboardStatus.HIDE; private inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 } @@ -144,22 +143,11 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { return; } await this.attach(true); - if (!this.imcFlag) { - this.listenKeyBoardEvent(); - } - this.inputMethodController.showTextInput().then(() => { - Log.d(TextInputMethodHandlerImpl.TAG, "Succeeded in showing softKeyboard"); - }).catch((err: Any) => { - Log.e(TextInputMethodHandlerImpl.TAG, "Failed to show softKeyboard:" + JSON.stringify(err)); - }); + this.listenKeyBoardEvent(); } private async hideTextInput(): Promise { - this.inputMethodController.hideTextInput().then(() => { - Log.d(TextInputMethodHandlerImpl.TAG, "Succeeded in hide softKeyboard"); - }).catch((err: Any) => { - Log.e(TextInputMethodHandlerImpl.TAG, "Failed to hide softKeyboard:" + JSON.stringify(err)); - }) + this.inputMethodController.detach(); } async attach(showKeyboard: boolean): Promise { @@ -264,23 +252,19 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { return; } Log.d(TextInputMethodHandlerImpl.TAG, "listenKeyBoardEvent success"); - this.imcFlag = true; } private insertTextCallback = (text: string) => { Log.d(TextInputMethodHandlerImpl.TAG, "insertText: " + text); this.mEditable.handleInsertTextEvent(text); - this.changeSelection(); } private deleteLeftCallback = (length: number) => { this.mEditable.handleDeleteEvent(false, length); - this.changeSelection(); } private deleteRightCallback = (length: number) => { this.mEditable.handleDeleteEvent(true, length); - this.changeSelection(); } private sendFunctionKeyCallback = (functionKey: inputMethod.FunctionKey) => { @@ -304,14 +288,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.mEditable.handleSelectByRange(range); } - changeSelection(): void { - try { - this.inputMethodController.changeSelection(this.mEditable.getStringCache(), this.mEditable.getSelectionStart(), this.mEditable.getSelectionEnd()); - } catch (err) { - Log.e(TextInputMethodHandlerImpl.TAG, "Failed to changeSelection:" + JSON.stringify(err)); - } - } - cancelListenKeyBoardEvent(): void { this.inputMethodController.off('insertText', this.insertTextCallback); this.inputMethodController.off('deleteLeft', this.deleteLeftCallback); @@ -319,8 +295,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.inputMethodController.off('sendFunctionKey', this.sendFunctionKeyCallback); this.inputMethodController.off('sendKeyboardStatus', this.sendKeyboardStatusCallback); this.inputMethodController.off('selectByRange', this.selectByRangeCallback); - this.imcFlag = false; - this.inputMethodController.detach() } public clearTextInputClient(): void { -- Gitee From f2c4e1ee0fc2a7cdbf3a9f26c727732dddd2afd2 Mon Sep 17 00:00:00 2001 From: SimpleLove520 <1960997571@qq.com> Date: Fri, 11 Oct 2024 20:48:46 +0800 Subject: [PATCH 19/33] =?UTF-8?q?=E5=87=8F=E5=B0=91resize=E6=97=B6Platform?= =?UTF-8?q?View=E6=8B=89=E4=BC=B8=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SimpleLove520 <1960997571@qq.com> --- .../src/main/ets/plugin/platform/PlatformViewsController.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index 8afcd87043..c3fd15e16e 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -89,7 +89,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili private platformViewParent: Map; private nodeControllers: Stack; private viewPhysicalInfo: Map = new Map(); - private dValue: number = 3; + private dValue: number = 1; constructor() { this.registry = new PlatformViewRegistryImpl(); @@ -188,7 +188,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let oldPhysicalHeight: number = 0; if (this.viewPhysicalInfo.has(viewId)) { oldPhysicalHeight = this.viewPhysicalInfo.get(viewId) as number; - //高度变化小于3,不做刷新处理,减少闪烁 + //高度变化小于1,不做刷新处理,减少闪烁 if (physicalHeight - oldPhysicalHeight < this.dValue) { this.setParams(params!, "width", physicalWidth); -- Gitee From 01816ef0623f811d5863acf82d8c8a6c5c2a8c1b Mon Sep 17 00:00:00 2001 From: zjxi Date: Fri, 11 Oct 2024 20:51:58 +0800 Subject: [PATCH 20/33] =?UTF-8?q?feat:=E6=97=A0=E9=9A=9C=E7=A2=8D=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E7=B2=97=E7=BB=86=E9=9C=80=E6=B1=82=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- shell/platform/ohos/BUILD.gn | 2 + .../ohos_accessibility_features.cpp | 58 +++++++++++++++++++ .../ohos_accessibility_features.h | 43 ++++++++++++++ .../src/main/cpp/types/libflutter/index.d.ets | 24 +++++++- .../main/ets/embedding/engine/FlutterNapi.ets | 22 ++++++- .../ets/embedding/ohos/FlutterAbility.ets | 7 +++ .../src/main/ets/view/AccessibilityBridge.ets | 25 ++++++++ shell/platform/ohos/library_loader.cpp | 16 ++++- .../ohos/napi/platform_view_ohos_napi.cpp | 53 +++++++++++++++++ .../ohos/napi/platform_view_ohos_napi.h | 22 +++++-- 10 files changed, 263 insertions(+), 9 deletions(-) create mode 100644 shell/platform/ohos/accessibility/ohos_accessibility_features.cpp create mode 100644 shell/platform/ohos/accessibility/ohos_accessibility_features.h diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index 689f5015c2..c8e36f5796 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -84,6 +84,7 @@ source_set("flutter_ohos_sources") { "ohos_surface_gl_skia.h", "types.h", "ohos_logging.h", + "./accessibility/ohos_accessibility_features.h", ] #configs += [ "//flutter/shell/platform/ohos/config:gtk" ] @@ -114,6 +115,7 @@ source_set("flutter_ohos_sources") { "ohos_image_generator.cpp", "ohos_external_texture_gl.cpp", "./surface/ohos_snapshot_surface_producer.cpp", + "./accessibility/ohos_accessibility_features.cpp", ] # Set flag to stop headers being directly included (library users should not do this) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp new file mode 100644 index 0000000000..caea517fee --- /dev/null +++ b/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "flutter/shell/platform/ohos/accessibility/ohos_accessibility_features.h" +#include "flutter/shell/platform/ohos/ohos_shell_holder.h" +#include "flutter/fml/logging.h" + +namespace flutter { + + OhosAccessibilityFeatures OhosAccessibilityFeatures::instance; + + OhosAccessibilityFeatures::OhosAccessibilityFeatures() {}; + OhosAccessibilityFeatures::~OhosAccessibilityFeatures() {}; + + OhosAccessibilityFeatures* OhosAccessibilityFeatures::GetInstance() { + return &OhosAccessibilityFeatures::instance; + } + + /** + * bold text for AccessibilityFeature + */ + void OhosAccessibilityFeatures::SetBoldText(double fontWeightScale, int64_t shell_holder_id) { + bool shouldBold = fontWeightScale > 1.0; + + if (shouldBold) { + accessibilityFeatureFlags |= static_cast(flutter::AccessibilityFeatureFlag::kBoldText); + FML_DLOG(INFO) << "SetBoldText -> accessibilityFeatureFlags: "<(flutter::AccessibilityFeatureFlag::kBoldText); + } + + SendAccessibilityFlags(shell_holder_id); + } + + /** + * send the accessibility flags to flutter dart sdk + */ + void OhosAccessibilityFeatures::SendAccessibilityFlags(int64_t shell_holder_id) { + auto ohos_shell_holder = reinterpret_cast(shell_holder_id); + ohos_shell_holder->GetPlatformView()->PlatformView::SetAccessibilityFeatures(accessibilityFeatureFlags); + FML_DLOG(INFO) << "SendAccessibilityFlags -> accessibilityFeatureFlags = " + << accessibilityFeatureFlags; + accessibilityFeatureFlags = 0; + } + +} \ No newline at end of file diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_features.h b/shell/platform/ohos/accessibility/ohos_accessibility_features.h new file mode 100644 index 0000000000..093e89ce11 --- /dev/null +++ b/shell/platform/ohos/accessibility/ohos_accessibility_features.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_ACCESSIBILITY_FEATURES_H +#define OHOS_ACCESSIBILITY_FEATURES_H +#include +#include "flutter/lib/ui/window/platform_configuration.h" +#include "flutter/shell/platform/ohos/napi/platform_view_ohos_napi.h" + +namespace flutter { + +class OhosAccessibilityFeatures { + public: + OhosAccessibilityFeatures(); + ~OhosAccessibilityFeatures(); + + static OhosAccessibilityFeatures* GetInstance(); + + void SetBoldText(double fontWeightScale, int64_t shell_holder_id); + void SendAccessibilityFlags(int64_t shell_holder_id); + + private: + static OhosAccessibilityFeatures instance; + + // Font weight adjustment (FontWeight.Bold - FontWeight.Normal = w700 - w400 = 300) + static const int32_t BOLD_TEXT_WEIGHT_ADJUSTMENT = 300; + int32_t accessibilityFeatureFlags = 0; +}; + +} + +#endif \ No newline at end of file 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 53a5eabeca..0cf14a41b0 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 @@ -17,6 +17,7 @@ import common from '@ohos.app.ability.common'; import resourceManager from '@ohos.resourceManager'; import image from '@ohos.multimedia.image'; import FlutterNapi from '../../../ets/embedding/engine/FlutterNapi'; +import { ByteBuffer } from '../../../ets/util/ByteBuffer'; import { FlutterCallbackInformation } from '../../../ets/view/FlutterCallbackInformation'; export const getContext: (a: number) => napiContext; @@ -110,6 +111,12 @@ export const nativeXComponentDispatchMouseWheel: (nativeShellHolderId: number, timestamp: number ) => void; + +// send updateSemantics and updateCustomAccessibilityActions from ets to c++ +export const nativeUpdateSemantics: (buffer: ByteBuffer, strings: string[], stringAttributeArgs: ByteBuffer[]) => void; +export const nativeUpdateCustomAccessibilityActions: (buffer: ByteBuffer, strings: string[]) => void; + + /** * Detaches flutterNapi和engine之间的关联 * 这个方法执行前提是flutterNapi已经和engine关联 @@ -134,4 +141,19 @@ export const nativeDecodeUtf8: (array: Uint8Array) => string; export const nativeSetTextureBufferSize: (nativeShellHolderId: number, textureId: number, width: number, height: number) => void; -export const nativeLookupCallbackInformation: (callback: FlutterCallbackInformation, handler: number) => number; \ No newline at end of file +/** + * accessibiltyChannel中的 + */ +export const nativeSetAccessibilityFeatures: (accessibilityFeatureFlags: number, responseId: number) => void; + +export const nativeAccessibilityStateChange: (state: Boolean) => void; + +export const nativeAnnounce: (message: string) => void; + +export const nativeSetSemanticsEnabled: (nativeShellHolderId: number, enabled: boolean) => void; + +export const nativeSetFontWeightScale: (nativeShellHolderId: number, fontWeightScale: number) => void; + +export const nativeGetShellHolderId: (nativeShellHolderId: number) => void; + +export const nativeLookupCallbackInformation: (callback: FlutterCallbackInformation, handler: number) => number; 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 78f1a520e7..787722ab06 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 @@ -22,7 +22,7 @@ import { FlutterCallbackInformation } from '../../view/FlutterCallbackInformatio import image from '@ohos.multimedia.image'; import { EngineLifecycleListener } from './FlutterEngine'; import { ByteBuffer } from '../../util/ByteBuffer'; -import { Action } from '../../view/AccessibilityBridge' +import { AccessibilityManager, Action } from '../../view/AccessibilityBridge' import LocalizationPlugin from '../../plugin/localization/LocalizationPlugin'; import i18n from '@ohos.i18n'; import Any from '../../plugin/common/Any'; @@ -54,6 +54,9 @@ export default class FlutterNapi { localizationPlugin: LocalizationPlugin | null = null; isDisplayingFlutterUi: boolean = false; + accessibilityManager: AccessibilityManager | null = null; + + /** * 更新刷新率 * @param rate @@ -502,6 +505,23 @@ export default class FlutterNapi { } } + getShellHolderId(): void { + this.ensureRunningOnMainThread(); + if (this.isAttached()) { + flutter.nativeGetShellHolderId(this.nativeShellHolderId!); + } + } + + setFontWeightScale(fontWeightScale: number): void { + this.ensureRunningOnMainThread(); + if (this.isAttached()) { + Log.i(TAG, "setFontWeightScale: " + fontWeightScale); + flutter.nativeSetFontWeightScale(this.nativeShellHolderId!, fontWeightScale); + } else { + Log.w(TAG, "setFontWeightScale is detached !"); + } + } + } export interface AccessibilityDelegate { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index 8ba4463178..5904485da1 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -36,6 +36,7 @@ import appRecovery from '@ohos.app.ability.appRecovery'; import FlutterManager from './FlutterManager'; import { FlutterView } from '../../view/FlutterView'; import ApplicationInfoLoader from '../engine/loader/ApplicationInfoLoader'; +import { AccessibilityManager } from '../../view/AccessibilityBridge'; const TAG = "FlutterAbility"; const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; @@ -51,6 +52,7 @@ export class FlutterAbility extends UIAbility implements Host { private flutterView: FlutterView | null = null; private mainWindow?: window.Window | null; private errorManagerId:number = 0; + private accessibilityManager?: AccessibilityManager | null; getFlutterView(): FlutterView | null { return this.flutterView; @@ -377,6 +379,11 @@ export class FlutterAbility extends UIAbility implements Host { .setTextScaleFactor(config.fontSizeScale == undefined? 1.0 : config.fontSizeScale) .send(); //热启动生命周期内,实时监听系统设置环境改变并实时发送相应信息 + //实时获取系统字体加粗系数 + // this.accessibilityManager?.setFontWeightScale(config.fontWeightScale == undefined? 0 : config.fontWeightScale); + this.delegate?.getFlutterNapi()?.setFontWeightScale(config.fontWeightScale == undefined? 0 : config.fontWeightScale); + Log.i(TAG, 'fontWeightScale: ' + JSON.stringify(config.fontWeightScale)); + if (config.language != '') { this.getFlutterEngine()?.getLocalizationPlugin()?.sendLocaleToFlutter(); } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/AccessibilityBridge.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/AccessibilityBridge.ets index 0e08f41fe9..e5a9c5bfab 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/AccessibilityBridge.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/AccessibilityBridge.ets @@ -12,11 +12,36 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import AccessibilityChannel from '../embedding/engine/systemchannels/AccessibilityChannel'; +import { ByteBuffer } from '../util/ByteBuffer'; +import Log from '../util/Log'; + +const TAG = "AccessibilityBridge"; export default class AccessibilityBridge { + + private accessibilityChannel: AccessibilityChannel | null = null; + constructor(){ } + + + +} + +export class AccessibilityManager { + private fontWeightScale: number | null = null; + + setFontWeightScale(fontWeightScale: number): void { + this.fontWeightScale = fontWeightScale; + Log.i(TAG, 'setFontWeightScale: ' + JSON.stringify(this.fontWeightScale)); + } + + getFontWeightScale(): number { + Log.i(TAG, 'getFontWeightScale: ' + JSON.stringify(this.fontWeightScale)); + return this.fontWeightScale!; + } } export enum Action { diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index 473feb562e..f596341474 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -132,9 +132,21 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_FUNCTION( "nativeSetTextureBackGroundPixelMap", flutter::PlatformViewOHOSNapi::nativeSetTextureBackGroundPixelMap), + DECLARE_NAPI_FUNCTION("nativeEncodeUtf8", + flutter::PlatformViewOHOSNapi::nativeEncodeUtf8), + DECLARE_NAPI_FUNCTION("nativeDecodeUtf8", + flutter::PlatformViewOHOSNapi::nativeDecodeUtf8), DECLARE_NAPI_FUNCTION( - "nativeEncodeUtf8", - flutter::PlatformViewOHOSNapi::nativeEncodeUtf8), + "nativeUpdateSemantics", + flutter::PlatformViewOHOSNapi::nativeUpdateSemantics), + DECLARE_NAPI_FUNCTION( + "nativeUpdateCustomAccessibilityActions", + flutter::PlatformViewOHOSNapi::nativeUpdateCustomAccessibilityActions), + + DECLARE_NAPI_FUNCTION( + "nativeSetFontWeightScale", + flutter::PlatformViewOHOSNapi::nativeSetFontWeightScale), + DECLARE_NAPI_FUNCTION( "nativeDecodeUtf8", flutter::PlatformViewOHOSNapi::nativeDecodeUtf8), diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index d46617ef3a..102a162404 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1798,6 +1798,59 @@ napi_value PlatformViewOHOSNapi::nativeDecodeUtf8(napi_env env, napi_callback_in return result; } +napi_value PlatformViewOHOSNapi::nativeUpdateSemantics( + napi_env env, + napi_callback_info info) { + // TODO ets calls c++ + + return nullptr; +} + +napi_value PlatformViewOHOSNapi::nativeUpdateCustomAccessibilityActions( + napi_env env, + napi_callback_info info) { + // TODO ets calls c++ + + return nullptr; +} + + + + +napi_value PlatformViewOHOSNapi::nativeSetFontWeightScale(napi_env env, napi_callback_info info) { + napi_status ret; + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + // get param nativeShellHolderId + int64_t shell_holder; + ret = napi_get_value_int64(env, args[0], &shell_holder); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "PlatformViewOHOSNapi::nativeSetFontWeightScale " + "napi_get_value_int64 error:" + << ret; + return nullptr; + } + //get param fontWeightScale + double fontWeightScale = 1.0; + ret = napi_get_value_double(env, args[1], &fontWeightScale); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "PlatformViewOHOSNapi::nativeSetFontWeightScale " + "napi_get_value_double error:" + << ret; + return nullptr; + } + // accessibility features get the params + auto ohosAccessibilityFeatures = OhosAccessibilityFeatures::GetInstance(); + ohosAccessibilityFeatures->SetBoldText(fontWeightScale, shell_holder); + FML_DLOG(INFO) << "PlatformViewOHOSNapi::nativeSetFontWeightScale -> shell_holder: " + << shell_holder + << " fontWeightScale: "<< fontWeightScale; + return nullptr; +} + + + napi_value PlatformViewOHOSNapi::nativeLookupCallbackInformation(napi_env env, napi_callback_info info) { napi_value result; diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 9ca6b6f90b..4cbe6cd572 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -28,6 +28,9 @@ #include "flutter/shell/common/run_configuration.h" #include "flutter/shell/platform/ohos/napi_common.h" #include "napi/native_api.h" + +#include "flutter/shell/platform/ohos/accessibility/ohos_accessibility_features.h" + // class for all c++ to call js function namespace flutter { @@ -199,15 +202,24 @@ class PlatformViewOHOSNapi { static napi_value nativeXComponentDetachFlutterEngine( napi_env env, napi_callback_info info); - static napi_value nativeXComponentDispatchMouseWheel( - napi_env env, - napi_callback_info info); - static napi_value nativeEncodeUtf8( + static napi_value nativeXComponentDispatchMouseWheel(napi_env env, + napi_callback_info info); + static napi_value nativeEncodeUtf8(napi_env env, napi_callback_info info); + static napi_value nativeDecodeUtf8(napi_env env, napi_callback_info info); + + /** + * ets call c++ + */ + static napi_value nativeUpdateSemantics(napi_env env, + napi_callback_info info); + static napi_value nativeUpdateCustomAccessibilityActions( napi_env env, napi_callback_info info); - static napi_value nativeDecodeUtf8( + + static napi_value nativeSetFontWeightScale( napi_env env, napi_callback_info info); + static napi_value nativeLookupCallbackInformation( napi_env env, napi_callback_info info); -- Gitee From 4382cc3108927083c43f64e2ee1e1ee64bf40b8c Mon Sep 17 00:00:00 2001 From: zjxi Date: Fri, 11 Oct 2024 21:10:16 +0800 Subject: [PATCH 21/33] =?UTF-8?q?fix:=E5=AE=8C=E5=96=84=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../ohos/accessibility/ohos_accessibility_features.cpp | 1 - .../platform/ohos/accessibility/ohos_accessibility_features.h | 3 +-- shell/platform/ohos/napi/platform_view_ohos_napi.cpp | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp index caea517fee..a99bcbd96d 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp @@ -54,5 +54,4 @@ namespace flutter { << accessibilityFeatureFlags; accessibilityFeatureFlags = 0; } - } \ No newline at end of file diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_features.h b/shell/platform/ohos/accessibility/ohos_accessibility_features.h index 093e89ce11..b6abf906b0 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_features.h +++ b/shell/platform/ohos/accessibility/ohos_accessibility_features.h @@ -37,7 +37,6 @@ class OhosAccessibilityFeatures { static const int32_t BOLD_TEXT_WEIGHT_ADJUSTMENT = 300; int32_t accessibilityFeatureFlags = 0; }; - + } - #endif \ No newline at end of file diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 102a162404..b78d86d0b8 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1801,7 +1801,6 @@ napi_value PlatformViewOHOSNapi::nativeDecodeUtf8(napi_env env, napi_callback_in napi_value PlatformViewOHOSNapi::nativeUpdateSemantics( napi_env env, napi_callback_info info) { - // TODO ets calls c++ return nullptr; } @@ -1809,7 +1808,6 @@ napi_value PlatformViewOHOSNapi::nativeUpdateSemantics( napi_value PlatformViewOHOSNapi::nativeUpdateCustomAccessibilityActions( napi_env env, napi_callback_info info) { - // TODO ets calls c++ return nullptr; } -- Gitee From 5d49bd1f3f3de8e99f808425aded46c649579f42 Mon Sep 17 00:00:00 2001 From: hezhengyi Date: Fri, 11 Oct 2024 21:27:40 +0800 Subject: [PATCH 22/33] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E4=B8=BA0,=E5=87=8F=E5=B0=91appfreeze?= =?UTF-8?q?=E7=9A=84=E6=A6=82=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hezhengyi --- shell/platform/ohos/ohos_external_texture_gl.cpp | 6 ++++++ shell/platform/ohos/ohos_xcomponent_adapter.cpp | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 741edd1020..50f08f4711 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -589,6 +589,12 @@ void OHOSExternalTextureGL::ProducePixelMapToNativeImage() return; } + ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, SET_TIMEOUT, 0); + if (ret != 0) { + FML_LOG(ERROR) << "OHOSExternalTextureGL SET_TIMEOUT err:" << ret; + return; + } + uint64_t usage = 0; OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, GET_USAGE, &usage); usage |= NATIVEBUFFER_USAGE_CPU_READ; diff --git a/shell/platform/ohos/ohos_xcomponent_adapter.cpp b/shell/platform/ohos/ohos_xcomponent_adapter.cpp index d6b8f9446d..ce9b10f61d 100644 --- a/shell/platform/ohos/ohos_xcomponent_adapter.cpp +++ b/shell/platform/ohos/ohos_xcomponent_adapter.cpp @@ -199,6 +199,14 @@ static int32_t SetNativeWindowOpt(OHNativeWindow* nativeWindow, ",w:%{public}d x %{public}d:%{public}d", nativeWindow, width, height, ret); } + + ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, SET_TIMEOUT, 0); + if (ret) { + LOGE( + "Set NativeWindow SET_TIMEOUT Failed :window:%{public}p " + ",w:%{public}d x %{public}d:%{public}d", + nativeWindow, width, height, ret); + } return ret; } -- Gitee From cb70e81753cd06dc382524289bca21f1ef38e9ed Mon Sep 17 00:00:00 2001 From: zjxi Date: Sat, 12 Oct 2024 11:02:57 +0800 Subject: [PATCH 23/33] =?UTF-8?q?refactor:=E5=AE=8C=E5=96=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A7=84=E8=8C=83=EF=BC=8C=E8=A1=A5=E5=85=85=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../ohos/accessibility/ohos_accessibility_features.cpp | 2 ++ .../flutter/src/main/ets/view/AccessibilityBridge.ets | 7 +------ shell/platform/ohos/napi/platform_view_ohos_napi.cpp | 8 +++----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp b/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp index a99bcbd96d..6953998fe3 100644 --- a/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp +++ b/shell/platform/ohos/accessibility/ohos_accessibility_features.cpp @@ -52,6 +52,8 @@ namespace flutter { ohos_shell_holder->GetPlatformView()->PlatformView::SetAccessibilityFeatures(accessibilityFeatureFlags); FML_DLOG(INFO) << "SendAccessibilityFlags -> accessibilityFeatureFlags = " << accessibilityFeatureFlags; + // set accessibility feature flag to 0 accessibilityFeatureFlags = 0; } + } \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/AccessibilityBridge.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/AccessibilityBridge.ets index e5a9c5bfab..cff9525630 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/AccessibilityBridge.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/view/AccessibilityBridge.ets @@ -22,12 +22,7 @@ export default class AccessibilityBridge { private accessibilityChannel: AccessibilityChannel | null = null; - constructor(){ - - } - - - + constructor(){} } export class AccessibilityManager { diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index b78d86d0b8..2594687c15 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1812,9 +1812,9 @@ napi_value PlatformViewOHOSNapi::nativeUpdateCustomAccessibilityActions( return nullptr; } - - - +/** + * 无障碍特征之字体加粗功能,获取ets侧系统字体粗细系数 + */ napi_value PlatformViewOHOSNapi::nativeSetFontWeightScale(napi_env env, napi_callback_info info) { napi_status ret; size_t argc = 2; @@ -1847,8 +1847,6 @@ napi_value PlatformViewOHOSNapi::nativeSetFontWeightScale(napi_env env, napi_cal return nullptr; } - - napi_value PlatformViewOHOSNapi::nativeLookupCallbackInformation(napi_env env, napi_callback_info info) { napi_value result; -- Gitee From 7541d65894132268b745d5e386c8ab1c3f463266 Mon Sep 17 00:00:00 2001 From: zjxi Date: Sat, 12 Oct 2024 13:00:42 +0800 Subject: [PATCH 24/33] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zjxi --- .../flutter/src/main/ets/embedding/ohos/FlutterAbility.ets | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets index 5904485da1..4013fed189 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbility.ets @@ -380,7 +380,6 @@ export class FlutterAbility extends UIAbility implements Host { .send(); //热启动生命周期内,实时监听系统设置环境改变并实时发送相应信息 //实时获取系统字体加粗系数 - // this.accessibilityManager?.setFontWeightScale(config.fontWeightScale == undefined? 0 : config.fontWeightScale); this.delegate?.getFlutterNapi()?.setFontWeightScale(config.fontWeightScale == undefined? 0 : config.fontWeightScale); Log.i(TAG, 'fontWeightScale: ' + JSON.stringify(config.fontWeightScale)); -- Gitee From 196e7965b79829c237f5daa04255b007a7ebb345 Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Mon, 14 Oct 2024 08:52:12 +0800 Subject: [PATCH 25/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4emoji?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=8F=8A=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../src/main/cpp/types/libflutter/index.d.ets | 10 + .../main/ets/embedding/engine/FlutterNapi.ets | 20 + .../plugin/editing/ListenableEditingState.ets | 26 +- .../src/main/ets/plugin/editing/TextUtils.ets | 357 ++++++++++++++++++ shell/platform/ohos/library_loader.cpp | 16 + .../ohos/napi/platform_view_ohos_napi.cpp | 117 ++++++ .../ohos/napi/platform_view_ohos_napi.h | 15 + 7 files changed, 547 insertions(+), 14 deletions(-) create mode 100644 shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextUtils.ets 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 0cf14a41b0..be366b7cb7 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 @@ -157,3 +157,13 @@ export const nativeSetFontWeightScale: (nativeShellHolderId: number, fontWeightS export const nativeGetShellHolderId: (nativeShellHolderId: number) => void; export const nativeLookupCallbackInformation: (callback: FlutterCallbackInformation, handler: number) => number; + +export const nativeUnicodeIsEmoji: (code: number) => number; + +export const nativeUnicodeIsEmojiModifier: (code: number) => number; + +export const nativeUnicodeIsEmojiModifierBase: (code: number) => number; + +export const nativeUnicodeIsVariationSelector: (code: number) => number; + +export const nativeUnicodeIsRegionalIndicatorSymbol: (code: number) => number; \ No newline at end of file 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 787722ab06..9be47241dc 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 @@ -522,6 +522,26 @@ export default class FlutterNapi { } } + static unicodeIsEmoji(code: number): boolean { + return Boolean(flutter.nativeUnicodeIsEmoji(code)); + } + + static unicodeIsEmojiModifier(code: number): boolean { + return Boolean(flutter.nativeUnicodeIsEmojiModifier(code)); + } + + static unicodeIsEmojiModifierBase(code: number): boolean { + return Boolean(flutter.nativeUnicodeIsEmojiModifierBase(code)); + } + + static unicodeIsVariationSelector(code: number): boolean { + return Boolean(flutter.nativeUnicodeIsVariationSelector(code)); + } + + static unicodeIsRegionalIndicatorSymbol(code: number): boolean { + return Boolean(flutter.nativeUnicodeIsRegionalIndicatorSymbol(code)); + } + } export interface AccessibilityDelegate { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets index 837253925b..351277019b 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/ListenableEditingState.ets @@ -19,6 +19,7 @@ import inputMethod from '@ohos.inputMethod'; import ArrayList from '@ohos.util.ArrayList'; import { TextEditingDelta } from './TextEditingDelta'; import TextInputChannel from '../../embedding/engine/systemchannels/TextInputChannel'; +import { FlutterTextUtils } from './TextUtils'; const TAG = "ListenableEditingState"; @@ -260,15 +261,13 @@ export class ListenableEditingState { if (start == 0 && end == 0) { return; } - let tbStart = start == end ? start - 1 : start; - let tbEnd = start == end ? -1 : 0; - let crCode: number = this.mStringCache.charCodeAt(tbStart) - if ( 0xdc00 <= crCode && crCode <= 0xdffff ) { - tbStart = tbStart - 1 + let unicodeStart = start; + if (start == end) { + unicodeStart = FlutterTextUtils.getOffsetBefore(this.mStringCache, start); } - this.replace(tbStart, end, "", 0, tbEnd); - this.mSelectionStartCache = tbStart; - let tempStr: string = this.mStringCache.slice(0, tbStart) + this.mStringCache.slice(end); + this.replace(unicodeStart, end, "", 0, 0); + this.mSelectionStartCache = unicodeStart; + let tempStr: string = this.mStringCache.slice(0, unicodeStart) + this.mStringCache.slice(end); this.mStringCache = tempStr; this.mSelectionEndCache = this.mSelectionStartCache; } else if (leftOrRight == true) { @@ -276,14 +275,13 @@ export class ListenableEditingState { if (start == this.mStringCache.length) { return; } - let tbStart = start == end ? 1 : 0; - let crCode: number = this.mStringCache.charCodeAt(tbStart) - if ( 0xdc00 <= crCode && crCode <= 0xdffff ) { - tbStart = tbStart - 1 + let unicodeEnd = end; + if (start == end) { + unicodeEnd = FlutterTextUtils.getOffsetAfter(this.mStringCache, start); } - this.replace(start, end, "", tbStart, 0); + this.replace(start, unicodeEnd, "", 0, 0); this.mSelectionEndCache = start; - let tempStr: string = this.mStringCache.slice(0, start) + (end + 1 >= this.mStringCache.length ? "" : this.mStringCache.slice(end + 1)); + let tempStr: string = this.mStringCache.slice(0, start) + (unicodeEnd >= this.mStringCache.length ? "" : this.mStringCache.slice(unicodeEnd)); this.mStringCache = tempStr; this.mSelectionStartCache = this.mSelectionEndCache; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextUtils.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextUtils.ets new file mode 100644 index 0000000000..f1948d01be --- /dev/null +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextUtils.ets @@ -0,0 +1,357 @@ +import FlutterNapi from '../../embedding/engine/FlutterNapi'; +import Log from '../../util/Log'; + +const LINE_FEED: number = 0x0A; +const CARRIAGE_RETURN: number = 0x0D; +const COMBINING_ENCLOSING_KEYCAP: number = 0x20E3; +const CANCEL_TAG: number = 0xE007F; +const ZERO_WIDTH_JOINER: number = 0x200D; + +const TAG = "TextUtils"; + +export class FlutterTextUtils { + + static isEmoji(code: number): boolean { + return FlutterNapi.unicodeIsEmoji(code); + } + + static isEmojiModifier(code: number): boolean { + return FlutterNapi.unicodeIsEmojiModifier(code); + } + + static isEmojiModifierBase(code: number): boolean { + return FlutterNapi.unicodeIsEmojiModifierBase(code); + } + + static isVariationSelector(code: number): boolean { + return FlutterNapi.unicodeIsVariationSelector(code); + } + + static isRegionalIndicatorSymbol(code: number): boolean { + return FlutterNapi.unicodeIsRegionalIndicatorSymbol(code); + } + + static isTagSpecChar(code: number): boolean { + return 0xE0020 <= code && code <= 0xE007E; + } + + static isKeycapBase(code: number): boolean { + return ('0'.charCodeAt(0) <= code && code <= '9'.charCodeAt(0)) || code == '#'.charCodeAt(0) || code == '*'.charCodeAt(0); + } + + static codePointBefore(text: string, offset: number): number { + if (offset <= 0 || offset > text.length) { + throw new RangeError('Offset out of range'); + } + + // Get the character before the offset + const char = text[offset - 1]; + + // Check if it is a low surrogate (part of a surrogate pair) + if (offset > 1 && char >= '\uDC00' && char <= '\uDFFF') { + const prevChar = text[offset - 2]; + // Check if the previous character is a high surrogate + if (prevChar >= '\uD800' && prevChar <= '\uDBFF') { + // If it is, combine the surrogate pair into a full Unicode code point + return (prevChar.charCodeAt(0) - 0xD800) * 0x400 + (char.charCodeAt(0) - 0xDC00) + 0x10000; + } + } + + // Return the code point of the single character (if it's not a surrogate pair) + return char.charCodeAt(0); + } + + static codePointAt(text: string, offset: number): number { + if (offset >= text.length) { + throw new RangeError('Offset out of range'); + } + let char = text[offset]; + + // Check if it is a high surrogate (part of a surrogate pair) + if (char >= '\uD800' && char <= '\uDBFF' && offset + 1 < text.length) { + const nextChar = text[offset + 1]; + // Check if the previous character is a low surrogate + if (nextChar >= '\uDC00' && nextChar <= '\uDFFF') { + // If it is, combine the surrogate pair into a full Unicode code point + return (char.charCodeAt(0) - 0xD800) * 0x400 + (nextChar.charCodeAt(0) - 0xDC00) + 0x10000; + } + } + return char.charCodeAt(0); + } + + static charCount(codePoint: number): number { + // If the code point is in the BMP range (0x0000 - 0xFFFF), it needs 1 UTF-16 code unit + if (codePoint <= 0xFFFF) { + return 1; + } + // If the code point is in the supplementary range (0x10000 - 0x10FFFF), it needs 2 UTF-16 code units + return 2; + } + + static getOffsetBefore(text: string, offset: number): number { + if (offset <= 1) { + return 0; + } + + let codePoint: number = FlutterTextUtils.codePointBefore(text, offset); + let deleteCharCount: number = FlutterTextUtils.charCount(codePoint); + let lastOffset: number = offset - deleteCharCount; + + if (lastOffset == 0) { + return 0; + } + + // Line Feed + if (codePoint == LINE_FEED) { + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + if (codePoint == CARRIAGE_RETURN) { + ++deleteCharCount; + } + return offset - deleteCharCount; + } + + // Flags + if (FlutterTextUtils.isRegionalIndicatorSymbol(codePoint)) { + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + lastOffset -= FlutterTextUtils.charCount(codePoint); + let regionalIndicatorSymbolCount: number = 1; + while (lastOffset > 0 && FlutterTextUtils.isRegionalIndicatorSymbol(codePoint)) { + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + lastOffset -= FlutterTextUtils.charCount(codePoint); + regionalIndicatorSymbolCount++; + } + if (FlutterTextUtils.isRegionalIndicatorSymbol(codePoint)) { + regionalIndicatorSymbolCount++; + } + if (regionalIndicatorSymbolCount % 2 == 0) { + deleteCharCount += 2; + } + return offset - deleteCharCount; + } + + // Keycaps + if (codePoint == COMBINING_ENCLOSING_KEYCAP) { + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + lastOffset -= FlutterTextUtils.charCount(codePoint); + if (lastOffset > 0 && FlutterTextUtils.isVariationSelector(codePoint)) { + let tmpCodePoint: number = FlutterTextUtils.codePointBefore(text, lastOffset); + if (FlutterTextUtils.isKeycapBase(tmpCodePoint)) { + deleteCharCount += FlutterTextUtils.charCount(codePoint) + FlutterTextUtils.charCount(tmpCodePoint); + } + } else if (FlutterTextUtils.isKeycapBase(codePoint)) { + deleteCharCount += FlutterTextUtils.charCount(codePoint); + } + return offset - deleteCharCount; + } + + /** + * Following if statements for Emoji tag sequence and Variation selector are skipping these + * modifiers for going through the last statement that is for handling emojis. They return the + * offset if they don't find proper base characters + */ + // Emoji Tag Sequence + if (codePoint == CANCEL_TAG) { // tag_end + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + lastOffset -= FlutterTextUtils.charCount(codePoint); + while (lastOffset > 0 && FlutterTextUtils.isTagSpecChar(codePoint)) { // tag_spec + deleteCharCount += FlutterTextUtils.charCount(codePoint); + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + lastOffset -= FlutterTextUtils.charCount(codePoint); + } + if (!FlutterTextUtils.isEmoji(codePoint)) { // tag_base not found. Just delete the end. + return offset - 2; + } + deleteCharCount += FlutterTextUtils.charCount(codePoint); + } + + if (FlutterTextUtils.isVariationSelector(codePoint)) { + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + if (!FlutterTextUtils.isEmoji(codePoint)) { + return offset - deleteCharCount; + } + deleteCharCount += FlutterTextUtils.charCount(codePoint); + + lastOffset -= FlutterTextUtils.charCount(codePoint); + } + + if (FlutterTextUtils.isEmoji(codePoint)) { + let isZwj: boolean = false; + let lastSeenVariantSelectorCharCount: number = 0; + do { + if (isZwj) { + deleteCharCount += FlutterTextUtils.charCount(codePoint) + lastSeenVariantSelectorCharCount + 1; + isZwj = false; + } + lastSeenVariantSelectorCharCount = 0; + if (FlutterTextUtils.isEmojiModifier(codePoint)) { + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + lastOffset -= FlutterTextUtils.charCount(codePoint); + if (lastOffset > 0 && FlutterTextUtils.isVariationSelector(codePoint)) { + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + if (!FlutterTextUtils.isEmoji(codePoint)) { + return offset - deleteCharCount; + } + lastSeenVariantSelectorCharCount = FlutterTextUtils.charCount(codePoint); + lastOffset -= FlutterTextUtils.charCount(codePoint); + } + if (FlutterTextUtils.isEmojiModifierBase(codePoint)) { + deleteCharCount += lastSeenVariantSelectorCharCount + FlutterTextUtils.charCount(codePoint); + } + break; + } + + if (lastOffset > 0) { + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + lastOffset -= FlutterTextUtils.charCount(codePoint); + if (codePoint == ZERO_WIDTH_JOINER) { + isZwj = true; + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + lastOffset -= FlutterTextUtils.charCount(codePoint); + if (lastOffset > 0 && FlutterTextUtils.isVariationSelector(codePoint)) { + codePoint = FlutterTextUtils.codePointBefore(text, lastOffset); + lastSeenVariantSelectorCharCount = FlutterTextUtils.charCount(codePoint); + lastOffset -= FlutterTextUtils.charCount(codePoint); + } + } + } + + if (lastOffset == 0) { + break; + } + } while (isZwj && FlutterTextUtils.isEmoji(codePoint)); + + if (isZwj && lastOffset == 0) { + deleteCharCount += FlutterTextUtils.charCount(codePoint) + lastSeenVariantSelectorCharCount + 1; + isZwj = false; + } + } + + return offset - deleteCharCount; + } + + static getOffsetAfter(text: string, offset: number): number { + const len = text.length; + if (offset >= len - 1) { + return len; + } + + let codePoint: number = FlutterTextUtils.codePointAt(text, offset); + let nextCharCount: number = FlutterTextUtils.charCount(codePoint); + let nextOffset: number = offset + nextCharCount; + + if (nextOffset == 0) { + return 0; + } + // Line Feed + if (codePoint == LINE_FEED) { + codePoint = FlutterTextUtils.codePointAt(text, nextOffset); + if (codePoint == CARRIAGE_RETURN) { + ++nextCharCount; + } + return offset + nextCharCount; + } + + // Flags + if (FlutterTextUtils.isRegionalIndicatorSymbol(codePoint)) { + if (nextOffset >= len - 1 + || !FlutterTextUtils.isRegionalIndicatorSymbol(FlutterTextUtils.codePointAt(text, nextOffset))) { + return offset + nextCharCount; + } + // In this case there are at least two regional indicator symbols ahead of + // offset. If those two regional indicator symbols are a pair that + // represent a region together, the next offset should be after both of + // them. + let regionalIndicatorSymbolCount: number = 0; + let regionOffset: number = offset; + while (regionOffset > 0 + && FlutterTextUtils.isRegionalIndicatorSymbol(FlutterTextUtils.codePointBefore(text, regionOffset))) { + regionOffset -= FlutterTextUtils.charCount(FlutterTextUtils.codePointBefore(text, regionOffset)); + regionalIndicatorSymbolCount++; + } + if (regionalIndicatorSymbolCount % 2 == 0) { + nextCharCount += 2; + } + return offset + nextCharCount; + } + + // Keycaps + if (FlutterTextUtils.isKeycapBase(codePoint)) { + nextCharCount += FlutterTextUtils.charCount(codePoint); + } + if (codePoint == COMBINING_ENCLOSING_KEYCAP) { + codePoint = FlutterTextUtils.codePointBefore(text, nextOffset); + nextOffset += FlutterTextUtils.charCount(codePoint); + if (nextOffset < len && FlutterTextUtils.isVariationSelector(codePoint)) { + let tmpCodePoint: number = FlutterTextUtils.codePointAt(text, nextOffset); + if (FlutterTextUtils.isKeycapBase(tmpCodePoint)) { + nextCharCount += FlutterTextUtils.charCount(codePoint) + FlutterTextUtils.charCount(tmpCodePoint); + } + } else if (FlutterTextUtils.isKeycapBase(codePoint)) { + nextCharCount += FlutterTextUtils.charCount(codePoint); + } + return offset + nextCharCount; + } + + if (FlutterTextUtils.isEmoji(codePoint)) { + let isZwj: boolean = false; + let lastSeenVariantSelectorCharCount: number = 0; + do { + if (isZwj) { + nextCharCount += FlutterTextUtils.charCount(codePoint) + lastSeenVariantSelectorCharCount + 1; + isZwj = false; + } + lastSeenVariantSelectorCharCount = 0; + if (FlutterTextUtils.isEmojiModifier(codePoint)) { + break; + } + + if (nextOffset < len) { + codePoint = FlutterTextUtils.codePointAt(text, nextOffset); + nextOffset += FlutterTextUtils.charCount(codePoint); + if (codePoint == COMBINING_ENCLOSING_KEYCAP) { + codePoint = FlutterTextUtils.codePointBefore(text, nextOffset); + nextOffset += FlutterTextUtils.charCount(codePoint); + if (nextOffset < len && FlutterTextUtils.isVariationSelector(codePoint)) { + let tmpCodePoint: number = FlutterTextUtils.codePointAt(text, nextOffset); + if (FlutterTextUtils.isKeycapBase(tmpCodePoint)) { + nextCharCount += FlutterTextUtils.charCount(codePoint) + FlutterTextUtils.charCount(tmpCodePoint); + } + } else if (FlutterTextUtils.isKeycapBase(codePoint)) { + nextCharCount += FlutterTextUtils.charCount(codePoint); + } + return offset + nextCharCount; + } + if (FlutterTextUtils.isEmojiModifier(codePoint)) { + nextCharCount += lastSeenVariantSelectorCharCount + FlutterTextUtils.charCount(codePoint); + break; + } + if (FlutterTextUtils.isVariationSelector(codePoint)) { + nextCharCount += lastSeenVariantSelectorCharCount + FlutterTextUtils.charCount(codePoint); + break; + } + if (codePoint == ZERO_WIDTH_JOINER) { + isZwj = true; + codePoint = FlutterTextUtils.codePointAt(text, nextOffset); + nextOffset += FlutterTextUtils.charCount(codePoint); + if (nextOffset < len && FlutterTextUtils.isVariationSelector(codePoint)) { + codePoint = FlutterTextUtils.codePointAt(text, nextOffset); + lastSeenVariantSelectorCharCount = FlutterTextUtils.charCount(codePoint); + nextOffset += FlutterTextUtils.charCount(codePoint); + } + } + } + + if (nextOffset >= len) { + break; + } + } while (isZwj && FlutterTextUtils.isEmoji(codePoint)); + + if (isZwj && nextOffset >= len) { + nextCharCount += FlutterTextUtils.charCount(codePoint) + lastSeenVariantSelectorCharCount + 1; + isZwj = false; + } + } + + return offset + nextCharCount; + } +} \ No newline at end of file diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index f596341474..b04d4c0016 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -153,6 +153,22 @@ static napi_value Init(napi_env env, napi_value exports) { DECLARE_NAPI_FUNCTION( "nativeLookupCallbackInformation", flutter::PlatformViewOHOSNapi::nativeLookupCallbackInformation), + + DECLARE_NAPI_FUNCTION( + "nativeUnicodeIsEmoji", + flutter::PlatformViewOHOSNapi::nativeUnicodeIsEmoji), + DECLARE_NAPI_FUNCTION( + "nativeUnicodeIsEmojiModifier", + flutter::PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifier), + DECLARE_NAPI_FUNCTION( + "nativeUnicodeIsEmojiModifierBase", + flutter::PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifierBase), + DECLARE_NAPI_FUNCTION( + "nativeUnicodeIsVariationSelector", + flutter::PlatformViewOHOSNapi::nativeUnicodeIsVariationSelector), + DECLARE_NAPI_FUNCTION( + "nativeUnicodeIsRegionalIndicatorSymbol", + flutter::PlatformViewOHOSNapi::nativeUnicodeIsRegionalIndicatorSymbol), }; FML_DLOG(INFO) << "Init NAPI size=" << sizeof(desc) / sizeof(desc[0]); diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index 2594687c15..a8242691dd 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1899,4 +1899,121 @@ napi_value PlatformViewOHOSNapi::nativeLookupCallbackInformation(napi_env env, n napi_create_int32(env, 0, &result); return result; } + +napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmoji(napi_env env, + napi_callback_info info) { + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + bool is_emoji = false; + int64_t codePoint = 0; + bool ret = napi_get_value_int64(env, args[0], &codePoint); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "nativeXComponentAttachFlutterEngine shell_holder " + "napi_get_value_int64 error"; + return nullptr; + } + + is_emoji = u_hasBinaryProperty(codePoint, UProperty::UCHAR_EMOJI); + + napi_value result; + napi_create_int32(env, (int)is_emoji, &result); + return result; +} + +napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifier( + napi_env env, + napi_callback_info info) { + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + bool is_emoji = false; + int64_t codePoint = 0; + bool ret = napi_get_value_int64(env, args[0], &codePoint); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "nativeXComponentAttachFlutterEngine shell_holder " + "napi_get_value_int64 error"; + return nullptr; + } + + is_emoji = u_hasBinaryProperty(codePoint, UProperty::UCHAR_EMOJI_MODIFIER); + + napi_value result; + napi_create_int32(env, (int)is_emoji, &result); + return result; +} + +napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifierBase( + napi_env env, + napi_callback_info info) { + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + bool is_emoji = false; + int64_t codePoint = 0; + bool ret = napi_get_value_int64(env, args[0], &codePoint); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "nativeXComponentAttachFlutterEngine shell_holder " + "napi_get_value_int64 error"; + return nullptr; + } + + is_emoji = + u_hasBinaryProperty(codePoint, UProperty::UCHAR_EMOJI_MODIFIER_BASE); + + napi_value result; + napi_create_int32(env, (int)is_emoji, &result); + return result; +} + +napi_value PlatformViewOHOSNapi::nativeUnicodeIsVariationSelector( + napi_env env, + napi_callback_info info) { + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + bool is_emoji = false; + int64_t codePoint = 0; + bool ret = napi_get_value_int64(env, args[0], &codePoint); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "nativeXComponentAttachFlutterEngine shell_holder " + "napi_get_value_int64 error"; + return nullptr; + } + + is_emoji = + u_hasBinaryProperty(codePoint, UProperty::UCHAR_VARIATION_SELECTOR); + + napi_value result; + napi_create_int32(env, (int)is_emoji, &result); + return result; +} + +napi_value PlatformViewOHOSNapi::nativeUnicodeIsRegionalIndicatorSymbol( + napi_env env, + napi_callback_info info) { + size_t argc = 1; + napi_value args[1] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + + bool is_emoji = false; + int64_t codePoint = 0; + bool ret = napi_get_value_int64(env, args[0], &codePoint); + if (ret != napi_ok) { + FML_DLOG(ERROR) << "nativeXComponentAttachFlutterEngine shell_holder " + "napi_get_value_int64 error"; + return nullptr; + } + + is_emoji = + u_hasBinaryProperty(codePoint, UProperty::UCHAR_REGIONAL_INDICATOR); + + napi_value result; + napi_create_int32(env, (int)is_emoji, &result); + return result; +} } // 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 4cbe6cd572..1a42f5b3b0 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -224,6 +224,21 @@ class PlatformViewOHOSNapi { napi_env env, napi_callback_info info); + static napi_value nativeUnicodeIsEmoji(napi_env env, napi_callback_info info); + + static napi_value nativeUnicodeIsEmojiModifier(napi_env env, + napi_callback_info info); + + static napi_value nativeUnicodeIsEmojiModifierBase(napi_env env, + napi_callback_info info); + + static napi_value nativeUnicodeIsVariationSelector(napi_env env, + napi_callback_info info); + + static napi_value nativeUnicodeIsRegionalIndicatorSymbol( + napi_env env, + napi_callback_info info); + private: static napi_env env_; napi_ref ref_napi_obj_; -- Gitee From c5b3773b47be12dad2a481909a9188117205077b Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Mon, 14 Oct 2024 09:39:08 +0800 Subject: [PATCH 26/33] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- shell/platform/ohos/library_loader.cpp | 30 ++++++++--------- .../ohos/napi/platform_view_ohos_napi.cpp | 33 ++++++++----------- .../ohos/napi/platform_view_ohos_napi.h | 19 +++++++---- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/shell/platform/ohos/library_loader.cpp b/shell/platform/ohos/library_loader.cpp index b04d4c0016..ab9f2df807 100644 --- a/shell/platform/ohos/library_loader.cpp +++ b/shell/platform/ohos/library_loader.cpp @@ -154,21 +154,21 @@ static napi_value Init(napi_env env, napi_value exports) { "nativeLookupCallbackInformation", flutter::PlatformViewOHOSNapi::nativeLookupCallbackInformation), - DECLARE_NAPI_FUNCTION( - "nativeUnicodeIsEmoji", - flutter::PlatformViewOHOSNapi::nativeUnicodeIsEmoji), - DECLARE_NAPI_FUNCTION( - "nativeUnicodeIsEmojiModifier", - flutter::PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifier), - DECLARE_NAPI_FUNCTION( - "nativeUnicodeIsEmojiModifierBase", - flutter::PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifierBase), - DECLARE_NAPI_FUNCTION( - "nativeUnicodeIsVariationSelector", - flutter::PlatformViewOHOSNapi::nativeUnicodeIsVariationSelector), - DECLARE_NAPI_FUNCTION( - "nativeUnicodeIsRegionalIndicatorSymbol", - flutter::PlatformViewOHOSNapi::nativeUnicodeIsRegionalIndicatorSymbol), + DECLARE_NAPI_FUNCTION( + "nativeUnicodeIsEmoji", + flutter::PlatformViewOHOSNapi::nativeUnicodeIsEmoji), + DECLARE_NAPI_FUNCTION( + "nativeUnicodeIsEmojiModifier", + flutter::PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifier), + DECLARE_NAPI_FUNCTION( + "nativeUnicodeIsEmojiModifierBase", + flutter::PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifierBase), + DECLARE_NAPI_FUNCTION( + "nativeUnicodeIsVariationSelector", + flutter::PlatformViewOHOSNapi::nativeUnicodeIsVariationSelector), + DECLARE_NAPI_FUNCTION( + "nativeUnicodeIsRegionalIndicatorSymbol", + flutter::PlatformViewOHOSNapi::nativeUnicodeIsRegionalIndicatorSymbol), }; FML_DLOG(INFO) << "Init NAPI size=" << sizeof(desc) / sizeof(desc[0]); diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp index a8242691dd..f6f23e803a 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.cpp +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.cpp @@ -1900,8 +1900,8 @@ napi_value PlatformViewOHOSNapi::nativeLookupCallbackInformation(napi_env env, n return result; } -napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmoji(napi_env env, - napi_callback_info info) { +napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmoji(napi_env env, napi_callback_info info) +{ size_t argc = 1; napi_value args[1] = {nullptr}; napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); @@ -1922,9 +1922,8 @@ napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmoji(napi_env env, return result; } -napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifier( - napi_env env, - napi_callback_info info) { +napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifier(napi_env env, napi_callback_info info) +{ size_t argc = 1; napi_value args[1] = {nullptr}; napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); @@ -1945,9 +1944,8 @@ napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifier( return result; } -napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifierBase( - napi_env env, - napi_callback_info info) { +napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifierBase(napi_env env, napi_callback_info info) +{ size_t argc = 1; napi_value args[1] = {nullptr}; napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); @@ -1961,17 +1959,15 @@ napi_value PlatformViewOHOSNapi::nativeUnicodeIsEmojiModifierBase( return nullptr; } - is_emoji = - u_hasBinaryProperty(codePoint, UProperty::UCHAR_EMOJI_MODIFIER_BASE); + is_emoji = u_hasBinaryProperty(codePoint, UProperty::UCHAR_EMOJI_MODIFIER_BASE); napi_value result; napi_create_int32(env, (int)is_emoji, &result); return result; } -napi_value PlatformViewOHOSNapi::nativeUnicodeIsVariationSelector( - napi_env env, - napi_callback_info info) { +napi_value PlatformViewOHOSNapi::nativeUnicodeIsVariationSelector(napi_env env, napi_callback_info info) +{ size_t argc = 1; napi_value args[1] = {nullptr}; napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); @@ -1985,17 +1981,15 @@ napi_value PlatformViewOHOSNapi::nativeUnicodeIsVariationSelector( return nullptr; } - is_emoji = - u_hasBinaryProperty(codePoint, UProperty::UCHAR_VARIATION_SELECTOR); + is_emoji = u_hasBinaryProperty(codePoint, UProperty::UCHAR_VARIATION_SELECTOR); napi_value result; napi_create_int32(env, (int)is_emoji, &result); return result; } -napi_value PlatformViewOHOSNapi::nativeUnicodeIsRegionalIndicatorSymbol( - napi_env env, - napi_callback_info info) { +napi_value PlatformViewOHOSNapi::nativeUnicodeIsRegionalIndicatorSymbol(napi_env env, napi_callback_info info) +{ size_t argc = 1; napi_value args[1] = {nullptr}; napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); @@ -2009,8 +2003,7 @@ napi_value PlatformViewOHOSNapi::nativeUnicodeIsRegionalIndicatorSymbol( return nullptr; } - is_emoji = - u_hasBinaryProperty(codePoint, UProperty::UCHAR_REGIONAL_INDICATOR); + is_emoji = u_hasBinaryProperty(codePoint, UProperty::UCHAR_REGIONAL_INDICATOR); napi_value result; napi_create_int32(env, (int)is_emoji, &result); diff --git a/shell/platform/ohos/napi/platform_view_ohos_napi.h b/shell/platform/ohos/napi/platform_view_ohos_napi.h index 1a42f5b3b0..65f11e8776 100644 --- a/shell/platform/ohos/napi/platform_view_ohos_napi.h +++ b/shell/platform/ohos/napi/platform_view_ohos_napi.h @@ -224,16 +224,21 @@ class PlatformViewOHOSNapi { napi_env env, napi_callback_info info); - static napi_value nativeUnicodeIsEmoji(napi_env env, napi_callback_info info); + static napi_value nativeUnicodeIsEmoji( + napi_env env, + napi_callback_info info); - static napi_value nativeUnicodeIsEmojiModifier(napi_env env, - napi_callback_info info); + static napi_value nativeUnicodeIsEmojiModifier( + napi_env env, + napi_callback_info info); - static napi_value nativeUnicodeIsEmojiModifierBase(napi_env env, - napi_callback_info info); + static napi_value nativeUnicodeIsEmojiModifierBase( + napi_env env, + napi_callback_info info); - static napi_value nativeUnicodeIsVariationSelector(napi_env env, - napi_callback_info info); + static napi_value nativeUnicodeIsVariationSelector( + napi_env env, + napi_callback_info info); static napi_value nativeUnicodeIsRegionalIndicatorSymbol( napi_env env, -- Gitee From fe95af4363d1968854e4bb33933f393b54872776 Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Mon, 14 Oct 2024 09:49:10 +0800 Subject: [PATCH 27/33] =?UTF-8?q?OAT=20=E8=AE=B8=E5=8F=AF=E8=AF=81?= =?UTF-8?q?=E5=A4=B4=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../src/main/ets/plugin/editing/TextUtils.ets | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextUtils.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextUtils.ets index f1948d01be..61aa4b3dee 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextUtils.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextUtils.ets @@ -1,3 +1,17 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ import FlutterNapi from '../../embedding/engine/FlutterNapi'; import Log from '../../util/Log'; -- Gitee From 1365649e7e78c723f77b9e480bc6dcd3a87066d7 Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Mon, 14 Oct 2024 17:31:12 +0800 Subject: [PATCH 28/33] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E7=99=BD=E8=89=B2=E8=83=8C=E6=99=AF=E5=B0=8F=E4=BA=8E=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=A4=A7=E5=B0=8F=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: cjand <1747143535@qq.com> --- shell/platform/ohos/ohos_external_texture_gl.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 05c8449bf5..911ea153cf 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -398,10 +398,8 @@ void OHOSExternalTextureGL::ProduceColorToBackGroundImage(int32_t width, int32_t uint32_t* destAddr = static_cast(mappedAddr); uint32_t value = 0xFFFFFFFF; - for (int32_t x = 0; x < handle->width; x++) { - for (int32_t y = 0; y < handle->height; y++) { - *destAddr++ = value; - } + for (int32_t x = 0; x < handle->size / 4; x++) { + *destAddr++ = value; } // munmap after use -- Gitee From db01d3f9874763f075bfbeb560446ac3ca874a66 Mon Sep 17 00:00:00 2001 From: cjand <1747143535@qq.com> Date: Mon, 14 Oct 2024 17:47:48 +0800 Subject: [PATCH 29/33] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E7=99=BD=E8=89=B2=E8=83=8C=E6=99=AF=E5=B0=8F=E4=BA=8E=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=A4=A7=E5=B0=8F=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: cjand <1747143535@qq.com> --- shell/platform/ohos/ohos_external_texture_gl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 911ea153cf..ec1414a700 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -38,6 +38,7 @@ constexpr const char *CHARACTER_STRING_WHITESPACE = " "; constexpr const char *EGL_EXT_PLATFORM_WAYLAND = "EGL_EXT_platform_wayland"; constexpr const char *EGL_KHR_PLATFORM_WAYLAND = "EGL_KHR_platform_wayland"; constexpr const char *EGL_GET_PLATFORM_DISPLAY_EXT = "eglGetPlatformDisplayEXT"; +constexpr uint32_t WHITE_COLOR = 0xFFFFFFFF; static int PixelMapToWindowFormat(PIXEL_FORMAT pixel_format) { @@ -396,10 +397,9 @@ void OHOSExternalTextureGL::ProduceColorToBackGroundImage(int32_t width, int32_t } uint32_t* destAddr = static_cast(mappedAddr); - uint32_t value = 0xFFFFFFFF; - for (int32_t x = 0; x < handle->size / 4; x++) { - *destAddr++ = value; + for (int32_t x = 0; x < handle->size / PIXEL_SIZE; x++) { + *destAddr++ = WHITE_COLOR; } // munmap after use -- Gitee From 2157d0c073ce2cf4e5827e9a083bd08ed36eb03e Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Thu, 17 Oct 2024 10:58:50 +0800 Subject: [PATCH 30/33] =?UTF-8?q?=E4=BC=98=E5=8C=96=E2=80=9C=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=BE=93=E5=85=A5=E6=A1=86=E8=BD=AF=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E6=94=B6=E8=B5=B7=E5=86=8D=E5=BC=B9=E8=B5=B7=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=9C=AA=E9=87=8D=E7=BD=AE=E2=80=9D=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B9=E6=B3=95=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E5=9B=A0=E4=B8=BA=E7=B3=BB=E7=BB=9F=E6=94=B6=E8=B5=B7=E8=BD=AF?= =?UTF-8?q?=E9=94=AE=E7=9B=98=E5=B8=A6=E6=9D=A5=E7=9A=84=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../ets/plugin/editing/TextInputPlugin.ets | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index 60888e9b95..2abc41a2a1 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -78,9 +78,10 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { mEditable: ListenableEditingState; private mRestartInputPending: boolean = false; private plugin: EditingStateWatcher | Any; - private inputTypeNone: string = 'NONE' + private imcFlag: boolean = false; + private inputTypeNone: string = 'NONE'; private keyboardStatus: inputMethod.KeyboardStatus = inputMethod.KeyboardStatus.HIDE; - private inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 } + private inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; constructor(plugin: TextInputPlugin | Any) { this.textConfig = { @@ -143,11 +144,15 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { return; } await this.attach(true); - this.listenKeyBoardEvent(); + if (!this.imcFlag) { + this.listenKeyBoardEvent(); + } } private async hideTextInput(): Promise { this.inputMethodController.detach(); + this.keyboardStatus = inputMethod.KeyboardStatus.NONE; + this.cancelListenKeyBoardEvent(); } async attach(showKeyboard: boolean): Promise { @@ -252,6 +257,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { return; } Log.d(TextInputMethodHandlerImpl.TAG, "listenKeyBoardEvent success"); + this.imcFlag = true; } private insertTextCallback = (text: string) => { @@ -279,8 +285,9 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.keyboardStatus = state; if (state == inputMethod.KeyboardStatus.HIDE) { this.plugin.textInputChannel.onConnectionClosed(this.inputTarget.id); - this.hideTextInput() - this.cancelListenKeyBoardEvent() + /// 收起软键盘时重置键盘状态,避免出现软键盘类型问题 + /// 系统对软键盘的改变也会被该方法监听到,如果继续使用使用detach和取消监听方法会导致其他问题,使用updateAttribute方法去重置,取消监听放在detach方法内,避免出现问题 + this.inputMethodController.updateAttribute({ textInputType: 0, enterKeyType: 1 }); } } @@ -295,6 +302,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.inputMethodController.off('sendFunctionKey', this.sendFunctionKeyCallback); this.inputMethodController.off('sendKeyboardStatus', this.sendKeyboardStatusCallback); this.inputMethodController.off('selectByRange', this.selectByRangeCallback); + this.imcFlag = false; } public clearTextInputClient(): void { -- Gitee From f9078cb5b4d01718407fb6af51c83f690f576944 Mon Sep 17 00:00:00 2001 From: wwyang <137208408@qq.com> Date: Thu, 17 Oct 2024 17:07:25 +0800 Subject: [PATCH 31/33] =?UTF-8?q?=E8=A7=A3=E5=86=B3web=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wwyang <137208408@qq.com> --- .../platform/PlatformViewsController.ets | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets index c3fd15e16e..e0552a797a 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformViewsController.ets @@ -88,8 +88,6 @@ export default class PlatformViewsController implements PlatformViewsAccessibili private currentFrameUsedPlatformViewIds: HashSet; private platformViewParent: Map; private nodeControllers: Stack; - private viewPhysicalInfo: Map = new Map(); - private dValue: number = 1; constructor() { this.registry = new PlatformViewRegistryImpl(); @@ -138,9 +136,6 @@ export default class PlatformViewsController implements PlatformViewsAccessibili return; } this.platformViews.delete(viewId); - if (this.viewPhysicalInfo.has(viewId)) { - this.viewPhysicalInfo.delete(viewId); - } let textureId = this.viewIdWithTextureId.get(viewId); if (textureId != undefined) { @@ -182,26 +177,6 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let viewWrapper = this.viewWrappers.get(request.viewId) let params: DVModelParameters | undefined = viewWrapper?.getDvModel()!.params - - const platformView = this.platformViews.get(request.viewId); - if (platformView?.getType() === 'web') { - let oldPhysicalHeight: number = 0; - if (this.viewPhysicalInfo.has(viewId)) { - oldPhysicalHeight = this.viewPhysicalInfo.get(viewId) as number; - //高度变化小于1,不做刷新处理,减少闪烁 - if (physicalHeight - oldPhysicalHeight < this.dValue) { - - this.setParams(params!, "width", physicalWidth); - this.setParams(params!, "height", oldPhysicalHeight); - - onComplete.run(new PlatformViewBufferSize(physicalWidth, oldPhysicalHeight)); - return; - } - } - } - - //保存组件最高位置,解决webview上下滑动带来的组件高度变化而引起的页面闪烁 - this.viewPhysicalInfo.set(viewId, physicalHeight); this.setParams(params!, "width", physicalWidth); this.setParams(params!, "height", physicalHeight); -- Gitee From f460e4424b22432cfd7d4ff4b33c1581da5bcdf0 Mon Sep 17 00:00:00 2001 From: chaoxizhang Date: Fri, 18 Oct 2024 16:29:13 +0800 Subject: [PATCH 32/33] Fix https://gitee.com/openharmony-sig/flutter_engine/issues/IAXKIK Signed-off-by: chaoxizhang --- .../ohos/ohos_external_texture_gl.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/shell/platform/ohos/ohos_external_texture_gl.cpp b/shell/platform/ohos/ohos_external_texture_gl.cpp index 966d566e3d..fda7cae8a0 100755 --- a/shell/platform/ohos/ohos_external_texture_gl.cpp +++ b/shell/platform/ohos/ohos_external_texture_gl.cpp @@ -136,11 +136,12 @@ void OHOSExternalTextureGL::Attach() FML_LOG(ERROR) << "Error with OH_NativeImage_Create"; return; } - nativeWindow_ = OH_NativeImage_AcquireNativeWindow(nativeImage_); - if (nativeWindow_ == nullptr) { - FML_LOG(ERROR) << "Error with OH_NativeImage_AcquireNativeWindow"; - return; - } + } + + nativeWindow_ = OH_NativeImage_AcquireNativeWindow(nativeImage_); + if (nativeWindow_ == nullptr) { + FML_LOG(ERROR) << "Error with OH_NativeImage_AcquireNativeWindow"; + return; } int32_t ret = OH_NativeImage_AttachContext(nativeImage_, texture_name_); @@ -382,6 +383,15 @@ void OHOSExternalTextureGL::setBackground(int32_t width, int32_t height) void OHOSExternalTextureGL::setTextureBufferSize(int32_t width, int32_t height) { FML_DLOG(INFO) << "OHOSExternalTextureGL::SetTextureBufferSize"; + if (nativeWindow_ == nullptr && nativeImage_) { + nativeWindow_ = OH_NativeImage_AcquireNativeWindow(nativeImage_); + } + + if (nativeWindow_ == nullptr) { + FML_LOG(ERROR) << "OHOSExternalTextureGL::SetTextureBufferSize nativeWindow_ is nullptr"; + return; + } + int code = SET_BUFFER_GEOMETRY; int32_t ret = OH_NativeWindow_NativeWindowHandleOpt(nativeWindow_, code, width, height); if (ret != 0) { -- Gitee From 187951f944bb19000101501f60badab23539365a Mon Sep 17 00:00:00 2001 From: laoguanyao <806103474@qq.com> Date: Fri, 18 Oct 2024 17:49:29 +0800 Subject: [PATCH 33/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: laoguanyao <806103474@qq.com> --- .../flutter/src/main/ets/plugin/editing/TextInputPlugin.ets | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets index 2abc41a2a1..2d5c4ac2a3 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/editing/TextInputPlugin.ets @@ -164,7 +164,7 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { } async updateAttribute(): Promise { - if (this.keyboardStatus == inputMethod.KeyboardStatus.HIDE) { + if (this.keyboardStatus != inputMethod.KeyboardStatus.SHOW) { return; } try { @@ -285,9 +285,6 @@ class TextInputMethodHandlerImpl implements TextInputMethodHandler { this.keyboardStatus = state; if (state == inputMethod.KeyboardStatus.HIDE) { this.plugin.textInputChannel.onConnectionClosed(this.inputTarget.id); - /// 收起软键盘时重置键盘状态,避免出现软键盘类型问题 - /// 系统对软键盘的改变也会被该方法监听到,如果继续使用使用detach和取消监听方法会导致其他问题,使用updateAttribute方法去重置,取消监听放在detach方法内,避免出现问题 - this.inputMethodController.updateAttribute({ textInputType: 0, enterKeyType: 1 }); } } -- Gitee