From d1814415efdf7c6fd45f1b2a53ddc4ca1e78c812 Mon Sep 17 00:00:00 2001 From: liuyuehu <3455278857@qq.com> Date: Sat, 13 Jan 2024 12:08:47 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BC=A0=E6=A0=87=E6=A0=B7=E5=BC=8F=E7=9A=84?= =?UTF-8?q?=E6=8C=89=E9=92=AE=EF=BC=8C=E6=A0=B7=E5=BC=8F=E4=B8=8D=E5=8F=91?= =?UTF-8?q?=E7=94=9F=E6=94=B9=E5=8F=98=20Signed-off-by:=20liuyuehu=20<3455?= =?UTF-8?q?278857@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ets/embedding/ohos/FlutterAbility.ets | 20 +++++++++++++++++++ .../ohos/FlutterAbilityAndEntryDelegate.ets | 4 +++- 2 files changed, 23 insertions(+), 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 a5869a3cbf..6eeb696f49 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 @@ -35,6 +35,7 @@ import errorManager from '@ohos.app.ability.errorManager'; import appRecovery from '@ohos.app.ability.appRecovery'; import FlutterManager from './FlutterManager'; import { FlutterView } from '../../view/FlutterView'; +import { AsyncCallback } from '@ohos.base'; const TAG = "FlutterAbility"; const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; @@ -356,6 +357,25 @@ export class FlutterAbility extends UIAbility implements Host { ? PlatformBrightness.LIGHT : PlatformBrightness.DARK); } + getWindowId(callback: AsyncCallback): void { + if (callback === null) { + return; + } + try { + window.getLastWindow(this.context, (error, win) => { + if (error.code) { + callback(error, -1); + return; + } + let windowId = win.getWindowProperties().id; + callback(error, windowId); + }); + } catch (err) { + Log.e(TAG, "get window id error!"); + callback(err, -1); + } + } + getFlutterEngine(): FlutterEngine | null { return this.delegate?.flutterEngine || null; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets index 4d022782be..c43619b738 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets @@ -62,6 +62,7 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent private settings?: Settings; private isHost:boolean = false; private flutterView?: FlutterView + private mouseCursorPlugin?: MouseCursorPlugin; constructor(host?: Host) { this.host = host; @@ -99,6 +100,7 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent if (this.flutterEngine) { this.textInputPlugin = new TextInputPlugin(this.flutterEngine.getTextInputChannel()!); this.platformPlugin = new PlatformPlugin(this.flutterEngine.getPlatformChannel()!, this.context); + this.mouseCursorPlugin = new MouseCursorPlugin(this.host!, this.flutterEngine.getMouseCursorChannel()!); this.settings = new Settings(this.flutterEngine.getSettingsChannel()!); this.flutterEngine.getSystemLanguages(); } @@ -484,7 +486,7 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent /** * FlutterAbility句柄 */ -interface Host extends FlutterEngineProvider, FlutterEngineConfigurator, PlatformPluginDelegate { +interface Host extends FlutterEngineProvider, FlutterEngineConfigurator, PlatformPluginDelegate , MouseCursorViewDelegate { getAbility(): UIAbility; -- Gitee From 4455b0e5849b997a9a2363eb658e67504e436129 Mon Sep 17 00:00:00 2001 From: liuyuehu <3455278857@qq.com> Date: Sat, 13 Jan 2024 12:09:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=AE=98=E7=BD=91?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9A=84=E9=BC=A0=E6=A0=87=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=20Signed-off-by:=20liuyuehu=20<3455278857@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ets/plugin/mouse/MouseCursorPlugin.ets | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/mouse/MouseCursorPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/mouse/MouseCursorPlugin.ets index 0f8bf873c4..3b0acb556c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/mouse/MouseCursorPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/mouse/MouseCursorPlugin.ets @@ -79,7 +79,7 @@ export default class MouseCursorPlugin implements MouseCursorMethodHandler{ this.systemCursorConstants.set("text", pointer.PointerStyle.TEXT_CURSOR); this.systemCursorConstants.set("resizeColum", pointer.PointerStyle.NORTH_SOUTH); this.systemCursorConstants.set("resizeDown", pointer.PointerStyle.SOUTH); - this.systemCursorConstants.set("resizeUpLeft", pointer.PointerStyle.NORTH_WEST); + this.systemCursorConstants.set("resizeDownLeft", pointer.PointerStyle.SOUTH_WEST); this.systemCursorConstants.set("resizeDownRight", pointer.PointerStyle.SOUTH_EAST); this.systemCursorConstants.set("resizeLeft", pointer.PointerStyle.WEST); this.systemCursorConstants.set("resizeLeftRight", pointer.PointerStyle.RESIZE_LEFT_RIGHT); @@ -89,12 +89,30 @@ export default class MouseCursorPlugin implements MouseCursorMethodHandler{ this.systemCursorConstants.set("resizeUpDown", pointer.PointerStyle.RESIZE_UP_DOWN); this.systemCursorConstants.set("resizeUpLeft", pointer.PointerStyle.NORTH_WEST); this.systemCursorConstants.set("resizeUpRight", pointer.PointerStyle.NORTH_EAST); - this.systemCursorConstants.set("resizeUpLeftDownRight", pointer.PointerStyle.MOVE); - this.systemCursorConstants.set("resizeUpRightDownLeft", pointer.PointerStyle.MOVE); + this.systemCursorConstants.set("resizeUpLeftDownRight", pointer.PointerStyle.NORTH_WEST_SOUTH_EAST); + this.systemCursorConstants.set("resizeUpRightDownLeft", pointer.PointerStyle.NORTH_EAST_SOUTH_WEST); this.systemCursorConstants.set("verticalText", pointer.PointerStyle.TEXT_CURSOR); this.systemCursorConstants.set("wait", pointer.PointerStyle.DEFAULT); this.systemCursorConstants.set("zoomIn", pointer.PointerStyle.ZOOM_IN); this.systemCursorConstants.set("zoomOut", pointer.PointerStyle.ZOOM_OUT); + this.systemCursorConstants.set("middleBtnEast", pointer.PointerStyle.MIDDLE_BTN_EAST); + this.systemCursorConstants.set("middleBtnWest", pointer.PointerStyle.MIDDLE_BTN_WEST); + this.systemCursorConstants.set("middleBtnSouth", pointer.PointerStyle.MIDDLE_BTN_SOUTH); + this.systemCursorConstants.set("middleBtnNorth", pointer.PointerStyle.MIDDLE_BTN_NORTH); + this.systemCursorConstants.set("middleBtnNorthSouth", pointer.PointerStyle.MIDDLE_BTN_NORTH_SOUTH); + this.systemCursorConstants.set("middleBtnNorthEast", pointer.PointerStyle.MIDDLE_BTN_NORTH_EAST); + this.systemCursorConstants.set("middleBtnNorthWest", pointer.PointerStyle.MIDDLE_BTN_NORTH_WEST); + this.systemCursorConstants.set("middleBtnSouthEast", pointer.PointerStyle.MIDDLE_BTN_SOUTH_EAST); + this.systemCursorConstants.set("middleBtnSouthWest", pointer.PointerStyle.MIDDLE_BTN_SOUTH_WEST); + this.systemCursorConstants.set("middleBtnNorthSouthWestEast", pointer.PointerStyle.MIDDLE_BTN_NORTH_SOUTH_WEST_EAST); + this.systemCursorConstants.set("horizontalTextCursor", pointer.PointerStyle.HORIZONTAL_TEXT_CURSOR); + this.systemCursorConstants.set("cursorCross", pointer.PointerStyle.CURSOR_CROSS); + this.systemCursorConstants.set("cursorCircle", pointer.PointerStyle.CURSOR_CIRCLE); + this.systemCursorConstants.set("loading", pointer.PointerStyle.LOADING); + this.systemCursorConstants.set("running", pointer.PointerStyle.RUNNING); + this.systemCursorConstants.set("colorSucker", pointer.PointerStyle.COLOR_SUCKER); + this.systemCursorConstants.set("screenshotChoose", pointer.PointerStyle.SCREENSHOT_CHOOSE); + this.systemCursorConstants.set("screenshotCursor", pointer.PointerStyle.SCREENSHOT_CURSOR); } let pointStyle:pointer.PointerStyle = this.systemCursorConstants.get(kind); if (pointStyle === null) { -- Gitee From 8876d93ea1501b44fa14a51170ecee31b4f3208f Mon Sep 17 00:00:00 2001 From: liuyuehu <3455278857@qq.com> Date: Sat, 13 Jan 2024 19:21:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?mouseCursorPlugin=E6=94=BE=E5=88=B0FlutterV?= =?UTF-8?q?iew=E9=87=8C=E9=9D=A2=E5=88=9D=E5=A7=8B=E5=8C=96=20Signed-off-b?= =?UTF-8?q?y:=20liuyuehu=20<3455278857@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ets/embedding/ohos/FlutterAbility.ets | 20 -------- .../ohos/FlutterAbilityAndEntryDelegate.ets | 5 +- .../ets/plugin/mouse/MouseCursorPlugin.ets | 48 +++++++------------ .../flutter/src/main/ets/view/FlutterView.ets | 4 ++ 4 files changed, 21 insertions(+), 56 deletions(-) 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 6eeb696f49..a5869a3cbf 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 @@ -35,7 +35,6 @@ import errorManager from '@ohos.app.ability.errorManager'; import appRecovery from '@ohos.app.ability.appRecovery'; import FlutterManager from './FlutterManager'; import { FlutterView } from '../../view/FlutterView'; -import { AsyncCallback } from '@ohos.base'; const TAG = "FlutterAbility"; const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'; @@ -357,25 +356,6 @@ export class FlutterAbility extends UIAbility implements Host { ? PlatformBrightness.LIGHT : PlatformBrightness.DARK); } - getWindowId(callback: AsyncCallback): void { - if (callback === null) { - return; - } - try { - window.getLastWindow(this.context, (error, win) => { - if (error.code) { - callback(error, -1); - return; - } - let windowId = win.getWindowProperties().id; - callback(error, windowId); - }); - } catch (err) { - Log.e(TAG, "get window id error!"); - callback(err, -1); - } - } - getFlutterEngine(): FlutterEngine | null { return this.delegate?.flutterEngine || null; } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets index c43619b738..056d8c0b5c 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityAndEntryDelegate.ets @@ -32,7 +32,6 @@ import { FlutterPlugin } from '../engine/plugins/FlutterPlugin'; import FlutterEngineCache from '../engine/FlutterEngineCache'; import FlutterEngineGroupCache from '../engine/FlutterEngineGroupCache'; import FlutterEngineGroup, { Options } from '../engine/FlutterEngineGroup'; -import MouseCursorPlugin, { MouseCursorViewDelegate } from '../../plugin/mouse/MouseCursorPlugin'; import Settings from './Settings'; import FlutterNapi from '../engine/FlutterNapi'; import List from '@ohos.util.List'; @@ -62,7 +61,6 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent private settings?: Settings; private isHost:boolean = false; private flutterView?: FlutterView - private mouseCursorPlugin?: MouseCursorPlugin; constructor(host?: Host) { this.host = host; @@ -100,7 +98,6 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent if (this.flutterEngine) { this.textInputPlugin = new TextInputPlugin(this.flutterEngine.getTextInputChannel()!); this.platformPlugin = new PlatformPlugin(this.flutterEngine.getPlatformChannel()!, this.context); - this.mouseCursorPlugin = new MouseCursorPlugin(this.host!, this.flutterEngine.getMouseCursorChannel()!); this.settings = new Settings(this.flutterEngine.getSettingsChannel()!); this.flutterEngine.getSystemLanguages(); } @@ -486,7 +483,7 @@ class FlutterAbilityAndEntryDelegate implements ExclusiveAppComponent /** * FlutterAbility句柄 */ -interface Host extends FlutterEngineProvider, FlutterEngineConfigurator, PlatformPluginDelegate , MouseCursorViewDelegate { +interface Host extends FlutterEngineProvider, FlutterEngineConfigurator, PlatformPluginDelegate { getAbility(): UIAbility; diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/mouse/MouseCursorPlugin.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/mouse/MouseCursorPlugin.ets index 3b0acb556c..36c8d93cf7 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/mouse/MouseCursorPlugin.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/mouse/MouseCursorPlugin.ets @@ -17,37 +17,35 @@ import MouseCursorChannel, { MouseCursorMethodHandler } from '../../embedding/en import pointer from '@ohos.multimodalInput.pointer'; import HashMap from '@ohos.util.HashMap'; import Log from '../../util/Log'; -import { AsyncCallback } from '@ohos.base'; const TAG: string = "MouseCursorPlugin"; export default class MouseCursorPlugin implements MouseCursorMethodHandler{ - private mView: MouseCursorViewDelegate; private mouseCursorChannel: MouseCursorChannel; private systemCursorConstants: HashMap | null = null; - constructor(mouseCursorView: MouseCursorViewDelegate, mouseCursorChannel: MouseCursorChannel) { - this.mView = mouseCursorView; + private windowId : number; + + constructor(windowId : number, mouseCursorChannel: MouseCursorChannel) { + this.windowId = windowId; this.mouseCursorChannel = mouseCursorChannel; this.mouseCursorChannel.setMethodHandler(this); } activateSystemCursor(kind: string): void { - this.mView.getWindowId((error, windowId) => { - if (windowId < 0) { - Log.w(TAG, "set point style failed windowId is invalid"); - return; - } - let pointStyle: pointer.PointerStyle = this.resolveSystemCursor(kind); - try { - pointer.setPointerStyle(windowId, pointStyle, (err: ESObject) => { - Log.i(TAG, "set point style success kind : " + kind); - }) - } catch (e) { - Log.e(TAG, "set point style failed : " + kind + " " + JSON.stringify(e)); - } - }); + if (this.windowId < 0) { + Log.w(TAG, "set point style failed windowId is invalid"); + return; + } + let pointStyle: pointer.PointerStyle = this.resolveSystemCursor(kind); + try { + pointer.setPointerStyle(this.windowId, pointStyle, (err: ESObject) => { + Log.i(TAG, "set point style success kind : " + kind); + }) + } catch (e) { + Log.e(TAG, "set point style failed : " + kind + " " + JSON.stringify(e)); + } } /** @@ -131,17 +129,3 @@ export default class MouseCursorPlugin implements MouseCursorMethodHandler{ } } -/** - * Delegate interface for requesting the system to display a pointer icon object. - * - *

Typically implemented by an component, such as a{@code FlutterView} - */ -export interface MouseCursorViewDelegate { - /** - * get window id to set mouse style - *

component need to implement this interface to get windowId - * - * @param callback windowId - * */ - getWindowId(callback: AsyncCallback): void; -} \ No newline at end of file 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 3b2337aff4..0e19662f6c 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 @@ -19,6 +19,7 @@ import display from '@ohos.display'; import FlutterManager from '../embedding/ohos/FlutterManager'; import window from '@ohos.window'; import KeyboardManager from '../embedding/ohos/KeyboardManager'; +import MouseCursorPlugin from '../plugin/mouse/MouseCursorPlugin'; const TAG = "FlutterView"; @@ -50,6 +51,7 @@ export class FlutterView { private displayInfo?: display.Display; private keyboardManager: KeyboardManager | null = null; private mainWindow: window.Window + private mouseCursorPlugin?: MouseCursorPlugin; constructor(viewId: string, context: Context) { this.id = viewId @@ -116,6 +118,8 @@ export class FlutterView { this.flutterEngine?.getFlutterNapi()?.updateRefreshRate(this.displayInfo!.refreshRate) flutterEngine.getPlatformViewsController()?.attachToView(this); this.updateViewportMetrics() + let windowId = this.mainWindow?.getWindowProperties()?.id + this.mouseCursorPlugin = new MouseCursorPlugin(windowId, this.flutterEngine?.getMouseCursorChannel()!); } detachFromFlutterEngine(): void { -- Gitee