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 4d022782be7d85ff29bc4172aef152dc489260c7..056d8c0b5cad796975b3121ef57848fa606cd23b 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'; 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 0f8bf873c41d36a2455442b857216b215418efbe..36c8d93cf7878d54d7c35e1932f0239394740797 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)); + } } /** @@ -79,7 +77,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 +87,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) { @@ -113,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 3b2337aff4ea325e4bed8b5a03f220cafdb34cfe..0e19662f6c8008e5feb29c225a7df7fcd630207a 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 {