diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets index f6950fde1e1386b9d9f89607ea1c8f1cfa0e8e44..ad6757c2fb6fa3479154e8869ac17753087389ae 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/FlutterEngine.ets @@ -102,7 +102,7 @@ export default class FlutterEngine implements EngineLifecycleListener{ platformViewsController = new PlatformViewsController(); } this.platformViewsController = platformViewsController; - this.platformViewsController.attach(context, null, this.dartExecutor); + this.platformViewsController.attach(context, this.renderer, this.dartExecutor); } async init(context: common.Context, dartVmArgs: Array | null, waitForRestorationData: boolean) { diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets index 66531efde816b11f903d4d946dc697051d5f5c3a..30066899e9675ca3748168f53d81a89e3051797d 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/engine/systemchannels/PlatformViewsChannel.ets @@ -207,6 +207,12 @@ export default class PlatformViewsChannel { const setDirectionArgs: Map = call.args; const newDirectionViewId: number = setDirectionArgs.get("id"); const direction: number = setDirectionArgs.get("direction"); + // let direction: Direction = Direction.Ltr; + // if (directionNumber == 0) { + // direction = Direction.Ltr; + // } else if (directionNumber == 1) { + // direction = Direction.Ltr; + // } try { this.handler?.setDirection(newDirectionViewId, direction); @@ -307,7 +313,7 @@ export interface PlatformViewsHandler { * The Flutter application would like to change the layout direction of an existing Android * {@code View}, i.e., platform view. */ - setDirection(viewId: number, direction: number): void; + setDirection(viewId: number, direction: Direction): void; /** Clears the focus from the platform view with a give id if it is currently focused. */ clearFocus(viewId: number): void; @@ -355,7 +361,7 @@ export class PlatformViewCreationRequest { /** * The layout direction of the new platform view. */ - public direction: number; + public direction: Direction; public displayMode: RequestedDisplayMode; /** Custom parameters that are unique to the desired platform view. */ diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets new file mode 100644 index 0000000000000000000000000000000000000000..a78f35ff4f02cd720a789ac61287f2ab3cc0a1c3 --- /dev/null +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/EmbeddingNodeController.ets @@ -0,0 +1,125 @@ +/* +* Copyright (c) 2024 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 { BuilderNode, FrameNode, NodeController, NodeRenderType } from '@kit.ArkUI'; +import Any from '../../plugin/common/Any'; +import PlatformView, { Params } from '../../plugin/platform/PlatformView'; +import { DVModel, DVModelChildren, DynamicView } from '../../view/DynamicView/dynamicView'; + + +declare class nodeControllerParams { + surfaceId : string + type : string + renderType : NodeRenderType + embedId : string + width : number + height : number +} + +@Component +struct ButtonComponent { + @Prop params: Params + @State bkColor: Color = Color.Red + + build() { + Column() { + Button("test button") + .border({ width: 2, color: Color.Red}) + .backgroundColor(this.bkColor) + } + } +} + +@Builder +function ButtonBuilder(params: Params) { + ButtonComponent({ params: params }) + .backgroundColor(Color.Green) +} + + +export class EmbeddingNodeController extends NodeController { + private rootNode: BuilderNode<[Params]> | undefined | null = null; + private wrappedBuilder: WrappedBuilder<[Params]> | null = null; + private platformView: PlatformView | undefined = undefined; + private embedId : string = ""; + private surfaceId : string = ""; + private renderType :NodeRenderType = NodeRenderType.RENDER_TYPE_DISPLAY; + private direction: Direction = Direction.Auto; + private isDestroy : boolean = false; + + setRenderOption(platformView: PlatformView, surfaceId: string, renderType: NodeRenderType, direction: Direction) { + if (platformView == undefined) { + console.log("nodeController platformView undefined") + } else { + this.wrappedBuilder = platformView.getView(); + } + this.platformView = platformView; + this.surfaceId = surfaceId; + this.renderType = renderType; + this.direction = direction; + } + + makeNode(uiContext: UIContext): FrameNode | null{ + this.rootNode = new BuilderNode(uiContext, { surfaceId: this.surfaceId, type: this.renderType}); + if (this.wrappedBuilder == null) { + console.log("nodeController makeNode 1") + this.rootNode.build(wrapBuilder(ButtonBuilder), {}); + } else { + console.log("nodeController makeNode 2") + this.rootNode.build(this.wrappedBuilder, {direction: this.direction, platformView: this.platformView}); + } + return this.rootNode.getFrameNode(); + } + + setBuilderNode(rootNode: BuilderNode | null): void{ + this.rootNode = rootNode; + } + + getBuilderNode(): BuilderNode<[Params]> | undefined | null{ + return this.rootNode; + } + + updateNode(arg: Object): void { + this.rootNode?.update(arg); + } + getEmbedId() : string { + return this.embedId; + } + + setDestroy(isDestroy : boolean) : void { + this.isDestroy = isDestroy; + if (this.isDestroy) { + this.rootNode = null; + } + } + + postEvent(event: TouchEvent | undefined) : boolean { + if (event != undefined) { + let changedTouchLen = event.changedTouches.length; + for (let i = 0; i< changedTouchLen; i++) { + event.changedTouches[i].displayX = vp2px(event.changedTouches[i].displayX); + event.changedTouches[i].displayY = vp2px(event.changedTouches[i].displayY); + event.changedTouches[i].windowX = vp2px(event.changedTouches[i].windowX); + event.changedTouches[i].windowY = vp2px(event.changedTouches[i].windowY); + event.changedTouches[i].screenX = vp2px(event.changedTouches[i].screenX); + event.changedTouches[i].screenY = vp2px(event.changedTouches[i].screenY); + event.changedTouches[i].x = vp2px(event.changedTouches[i].x); + event.changedTouches[i].y = vp2px(event.changedTouches[i].y); + } + return this.rootNode?.postTouchEvent(event) as boolean + } else { + return false; + } + } +} \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets index cdadecac91cc387b01de4353e32e22837e39360b..9d17e66231b40154303853a97b841702df4c4bf0 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterPage.ets @@ -12,10 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Any from '../../plugin/common/Any'; + import Log from '../../util/Log'; -import { DVModel, DVModelChildren, DynamicView } from '../../view/DynamicView/dynamicView'; import { FlutterView } from '../../view/FlutterView'; +import { EmbeddingNodeController } from './EmbeddingNodeController'; import FlutterManager from './FlutterManager'; const TAG = "FlutterPage"; @@ -25,19 +25,20 @@ const TAG = "FlutterPage"; */ @Component export struct FlutterPage { - @State rootDvModel: DVModelChildren | undefined = undefined @Prop viewId: string = "" @Prop xComponentType: XComponentType = XComponentType.TEXTURE @Builder doNothingBuilder() {} @BuilderParam splashScreenView: () => void = this.doNothingBuilder; @State showSplashScreen: boolean = true; + @StorageLink('nodeWidth') storageLinkWidth: number = 0; + @StorageLink('nodeHeight') storageLinkHeight: number = 0; private flutterView?: FlutterView | null - + private nodeController: EmbeddingNodeController | undefined = undefined aboutToAppear() { this.flutterView = FlutterManager.getInstance().getFlutterView(this.viewId); - this.rootDvModel = this.flutterView!!.getDVModel().children + this.nodeController = this.flutterView!!.getEmbeddingNodeController(); this.flutterView?.addFirstFrameListener(this) } @@ -51,6 +52,10 @@ export struct FlutterPage { build() { Stack() { + NodeContainer(this.nodeController) + .width(this.storageLinkWidth) + .height(this.storageLinkHeight) + XComponent({ id: this.viewId, type: this.xComponentType, libraryname: 'flutter' }) .focusable(true) .focusOnTouch(true) @@ -64,16 +69,6 @@ export struct FlutterPage { }) .backgroundColor(Color.Transparent) - ForEach(this.rootDvModel!!, (child: Any) => { - DynamicView({ - model: child as DVModel, - params: child.params, - events: child.events, - children: child.children, - customBuilder: child.builder - }) - },(child: Any) => `${child.id_}`) - if (this.showSplashScreen) { this.splashScreenView(); } @@ -88,3 +83,9 @@ export struct FlutterPage { }) } } + +function sleep(ms: number): Promise { + return new Promise( + (resolve) => setTimeout(resolve, ms) + ) +} diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/CustomTouchEvent.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/CustomTouchEvent.ets new file mode 100644 index 0000000000000000000000000000000000000000..bcf3e4bb5a06e149c6b86b8c80562563c2e2c987 --- /dev/null +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/CustomTouchEvent.ets @@ -0,0 +1,80 @@ +export class CustomTouchEvent implements TouchEvent { + type: TouchType = 0; + touches: CustomTouchObject[]; + changedTouches: CustomTouchObject[]; + stopPropagation: () => void = () => {}; + + timestamp: number; + source: SourceType; + pressure: number; + tiltX: number; + tiltY: number; + sourceTool: SourceTool; + + constructor(type: TouchType, touches: CustomTouchObject[], changedTouches: CustomTouchObject[], timestamp: number, source: SourceType, pressure: number, tiltX: number, tiltY: number, sourceTool: SourceTool) { + this.type = type; + this.touches = touches; + this.changedTouches = changedTouches; + this.timestamp = timestamp; + this.source = source; + this.pressure = pressure; + this.tiltX = tiltX; + this.tiltY = tiltY; + this.sourceTool = sourceTool; + } + + target: EventTarget = new CustomEventTarget(new CustomArea(0, 0, {x: 0, y: 0}, {x: 0, y: 0})); + + getHistoricalPoints(): HistoricalPoint[] { + throw new Error('Method not implemented.'); + } +} + +class CustomEventTarget implements EventTarget { + area: Area = new CustomArea(0, 0, {x: 0, y: 0}, {x: 0, y: 0}); + + constructor(area: Area) { + this.area = area; + } +} + +class CustomArea implements Area { + width: Length = 0; + height: Length = 0; + position: Position = {x: 0, y: 0}; + globalPosition: Position = {x: 0, y: 0}; + + constructor(width: Length, height: Length, position: Position, globalPosition: Position ) { + this.width = width; + this.height = height; + this.position = position; + this.globalPosition = globalPosition; + } +} + + +export class CustomTouchObject implements TouchObject { + type: TouchType; + id: number; + displayX: number; + displayY: number; + windowX: number; + windowY: number; + screenX: number; + screenY: number; + x: number; + y: number; + + constructor(type: TouchType, id: number, displayX: number, displayY: number, windowX: number, windowY: number, screenX: number, screenY: number, x: number, y: number) { + this.type = type; + this.id = id; + this.displayX = displayX; + this.displayY = displayY; + this.windowX = windowX; + this.windowY = windowY; + this.screenX = screenX; + this.screenY = screenY; + this.x = x; + this.y = y; + } +} \ No newline at end of file diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets index ddf5f59a71c4d1c7d51082bcf104990e0faa08c6..320e5e973d4e0b4452856a676f20c8b1156aa9a0 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/PlatformView.ets @@ -15,11 +15,15 @@ import { DVModel, DynamicView } from '../../view/DynamicView/dynamicView' +export declare class Params { + direction: Direction + platformView : PlatformView +} + /** A handle to an DynamicView to be embedded in the Flutter hierarchy. */ export default abstract class PlatformView { /** Returns the DynamicView to be embedded in the Flutter hierarchy. */ - abstract getView(): DVModel; - + abstract getView(): WrappedBuilder<[Params]>; /** * Called by the {@link io.flutter.embedding.engine.FlutterEngine} that owns this {@code * PlatformView} when the DynamicView responsible for rendering a Flutter UI is 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 82c87cd521a6a5a4dc661e8b8df8238430437d5e..21cd6283d1df34bcfd332c69889952d0bfd9537a 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 @@ -20,7 +20,7 @@ import PlatformViewsChannel, { PlatformViewResizeRequest, PlatformViewsHandler, PlatformViewTouch, PlatformViewBufferSize } from '../../../ets/embedding/engine/systemchannels/PlatformViewsChannel'; -import PlatformView from './PlatformView'; +import PlatformView, { Params } from './PlatformView'; import { DVModel, DVModelContainer, DVModelParameters, DynamicView } from '../../view/DynamicView/dynamicView'; import display from '@ohos.display'; import { FlutterView } from '../../view/FlutterView'; @@ -42,9 +42,14 @@ import OhosTouchProcessor from '../../embedding/ohos/OhosTouchProcessor' import PlatformViewFactory from './PlatformViewFactory' import { ByteBuffer } from '../../util/ByteBuffer'; import Any from '../common/Any'; +import { RawPointerCoords } from './RawPointerCoord'; +import { ArrayList } from '@kit.ArkTS'; +import { CustomTouchEvent, CustomTouchObject } from './CustomTouchEvent'; +import { NodeRenderType } from '@kit.ArkUI'; -const TAG = "PlatformViewsController" +const TAG = "PlatformViewsController" +let tsp: number = 52086377781000 export default class PlatformViewsController implements PlatformViewsAccessibilityDelegate, PlatformViewsHandler { private registry: PlatformViewRegistryImpl; private context: Context | null = null; @@ -57,11 +62,14 @@ export default class PlatformViewsController implements PlatformViewsAccessibili private usesSoftwareRendering: boolean = false; private platformViews: Map; + private viewIdWithTextureId: Map; private overlayLayerViews: Map; private viewWrappers: Map; private currentFrameUsedOverlayLayerIds: HashSet; private currentFrameUsedPlatformViewIds: HashSet; private platformViewParent: Map; + private nodeWidthLink: SubscribedAbstractProperty = AppStorage.link('nodeWidth'); + private nodeHeightLink: SubscribedAbstractProperty = AppStorage.link('nodeHeight'); constructor() { this.registry = new PlatformViewRegistryImpl(); @@ -71,6 +79,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili this.currentFrameUsedPlatformViewIds = new HashSet(); this.viewWrappers = new Map(); this.platformViews = new Map(); + this.viewIdWithTextureId = new Map(); this.platformViewParent = new Map(); } @@ -95,7 +104,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili Log.i(TAG, "Enter createForPlatformViewLayer"); this.ensureValidRequest(request); - let platformView: PlatformView = this.createPlatformView(request, false); + let platformView: PlatformView = this.createPlatformView(request); this.configureForHybridComposition(platformView, request); } @@ -107,6 +116,11 @@ export default class PlatformViewsController implements PlatformViewsAccessibili return; } this.platformViews.delete(viewId); + let textureId = this.viewIdWithTextureId.get(viewId); + + if (textureId != undefined) { + this.textureRegistry!.unregisterTexture(textureId); + } try { platformView.dispose(); @@ -114,21 +128,7 @@ export default class PlatformViewsController implements PlatformViewsAccessibili Log.e(TAG, "Disposing platform view threw an exception", err); } - let viewWrapper: PlatformViewWrapper | null = this.viewWrappers.get(viewId) || null; - if (viewWrapper != null) { - let children = viewWrapper.getDvModel().children; - if (this.flutterView) { - let index = this.flutterView.getDVModel().children.indexOf(viewWrapper.getDvModel()); - children.splice(0, children.length); - this.flutterView.getDVModel().children.splice(index, 1); - } - this.viewWrappers.delete(viewId); - } - let parentView: FlutterMutatorView | null = this.platformViewParent.get(viewId) || null; - if (parentView != null) { - this.platformViewParent.delete(viewId); - } } setParams: (params: DVModelParameters, key: string, element: Any ) => void = (params: DVModelParameters, key: string, element: Any): void => { @@ -141,96 +141,60 @@ export default class PlatformViewsController implements PlatformViewsAccessibili let physicalHeight: number = this.toPhysicalPixels(request.newLogicalHeight); let viewId: number = request.viewId; Log.i(TAG, `Resize viewId ${viewId}, pw:${physicalWidth}, ph:${physicalHeight},lw:${request.newLogicalWidth}, lh:${request.newLogicalHeight}`); - - let platformView: PlatformView | null = this.platformViews.get(viewId) || null; - let viewWrapper: PlatformViewWrapper | null = this.viewWrappers.get(viewId) || null; - if (platformView == null || viewWrapper == null) { - Log.e(TAG, "Resizing unknown platform view with id: " + viewId); + let oldNodeWidth: number = AppStorage.get('nodeWidth')! + let oldNodeHeight: number = AppStorage.get('nodeHeight')! + if ((oldNodeWidth == physicalWidth) && (oldNodeHeight == physicalHeight)) { + onComplete.run(new PlatformViewBufferSize(physicalWidth, physicalHeight)); return; } + this.nodeWidthLink.set(physicalWidth); + this.nodeHeightLink.set(physicalHeight); + this.flutterView!.getPlatformViewSize().direction = Direction.Rtl; + this.flutterView!.getEmbeddingNodeController().setRenderOption(this.flutterView!.getPlatformView()!, this.flutterView!.getSurfaceId(), NodeRenderType.RENDER_TYPE_TEXTURE, this.flutterView!.getPlatformViewSize().direction); + this.flutterView!.getEmbeddingNodeController().rebuild(); + - let viewWrapperLayoutParams: DVModelParameters | undefined = viewWrapper.getDvModel()?.getLayoutParams(); - if (physicalWidth && viewWrapperLayoutParams) { - this.setParams(viewWrapperLayoutParams, "width", physicalWidth); - // viewWrapperLayoutParams.width = physicalWidth; - } - - if (physicalHeight && viewWrapperLayoutParams) { - this.setParams(viewWrapperLayoutParams, "height", physicalHeight); - // viewWrapperLayoutParams.height = physicalHeight; - } - - let embeddedView: DVModel = platformView.getView(); - if (embeddedView != null) { - let embeddedViewLayoutParams = embeddedView.getLayoutParams(); - if (physicalWidth) { - this.setParams(embeddedViewLayoutParams, "width", physicalWidth); - // embeddedViewLayoutParams.width = physicalWidth; - } - - if (physicalHeight) { - this.setParams(embeddedViewLayoutParams, "height", physicalHeight); - // embeddedViewLayoutParams.height = physicalHeight; - } - } - - onComplete.run(new PlatformViewBufferSize(request.newLogicalWidth, request.newLogicalHeight)); + onComplete.run(new PlatformViewBufferSize(physicalWidth, physicalHeight)); } offset(viewId: number, top: number, left: number): void { Log.i(TAG, `Offset is id${viewId}, t:${top}, l:${left}`); - let viewWrapper: PlatformViewWrapper | null = this.viewWrappers.get(viewId) || null; - if (viewWrapper == null) { - Log.e(TAG, "Setting offset for an unknown platform view with id: " + viewId); - return; - } - - let physicalTop = this.toPhysicalPixels(top); - let physicalLeft = this.toPhysicalPixels(left); - let params = viewWrapper.getDvModel()!.params; - this.setParams(params!, "marginTop", physicalTop); - this.setParams(params!, "marginLeft", physicalLeft); - viewWrapper.setLayoutParams(params!); } onTouch(touch: PlatformViewTouch): void { - let viewId: number = touch.viewId; - let density: number = display.getDefaultDisplaySync().densityDPI; + console.log("nodeController onTouch:") + let xx = 0; + let yy = 0; + let rawPointerCoords1: Array = touch.rawPointerCoords as Array ; + let length = rawPointerCoords1.length + rawPointerCoords1.forEach((item: ESObject) => { + let rawPoints: ArrayList = item as ArrayList; + let length2 = rawPoints.length + xx = rawPoints[7]; + yy = rawPoints[8]; + console.log("nodeController onTouch rawPoints.x :" + rawPoints[7]) + console.log("nodeController onTouch rawPoints.y :" + rawPoints[8]) + }) - let platformView: PlatformView | null = this.platformViews.get(viewId) ?? null; - if (platformView == null) { - Log.e(TAG, "Sending touch to an unknown platform view with id: " + viewId); - return; - } - let dvModel: DVModel = platformView.getView(); - if (dvModel == null) { - Log.e(TAG, "Sending touch to a null dv model with id: " + viewId); - } - Log.e(TAG, "Sending touch to a dv model with id: " + viewId.toString()); - sendEventByKey(viewId.toString(), 10, ""); - } + - setDirection(viewId: number, direction: number): void { - if (!this.validateDirection(direction)) { - throw new Error("Trying to set unknown direction value: " - + direction - + "(view id: " - + viewId - + ")"); - } + tsp = tsp + 10000; + let touches1: CustomTouchObject = new CustomTouchObject(touch.action, 0, xx, yy, xx, yy, xx, yy, xx, yy); + let changedTouches1: CustomTouchObject = new CustomTouchObject(touch.action, 0, xx, yy, xx, yy, xx, yy, xx, yy); + let customTouchEvent1: CustomTouchEvent = new CustomTouchEvent(touch.action, [touches1], [changedTouches1], tsp, 2, 1, 0, 0, 1); - const platformView = this.platformViews.get(viewId); - if (platformView == null) { - Log.e(TAG, "Setting direction to an unknown view with id: " + viewId); - return; - } - const embeddedView = platformView.getView(); - if (embeddedView == null) { - Log.e(TAG, "Setting direction to a null view with id: " + viewId); - return; + + console.log("nodeController onTouch type " + touch.action) + console.log("nodeController onTouch timestamp " + tsp) + if (this.flutterView == null) { + console.log("nodeController flutterView == null") } - this.setParams(embeddedView.params, "direction", direction); - // embeddedView.params.direction = direction; + this.flutterView?.getEmbeddingNodeController().postEvent(customTouchEvent1) + } + + setDirection(viewId: number, direction: Direction): void { + this.flutterView!.getEmbeddingNodeController().setRenderOption(this.flutterView!.getPlatformView()!, this.flutterView!.getSurfaceId(), NodeRenderType.RENDER_TYPE_TEXTURE, direction); + this.flutterView!.getEmbeddingNodeController().rebuild(); } validateDirection(direction:number):boolean { @@ -248,7 +212,8 @@ export default class PlatformViewsController implements PlatformViewsAccessibili Log.e(TAG, "Setting direction to a null view with id: " + viewId); return; } - focusControl.requestFocus("flutterXComponent"); + // focusControl.requestFocus("flutterXComponent"); + focusControl.requestFocus(this.flutterView?.getId()); } synchronizeToNativeViewHierarchy(yes: boolean): void { throw new Error('Method not implemented.'); @@ -258,15 +223,10 @@ export default class PlatformViewsController implements PlatformViewsAccessibili Log.i(TAG, "Enter createForTextureLayer"); this.ensureValidRequest(request); - let viewId: number = request.viewId; - if (this.viewWrappers.get(request.viewId) != null) { - throw new Error( - "Trying to create an already created platform view, view id: " + viewId); - } - - let platformView: PlatformView = this.createPlatformView(request, true); - let dynamicView: DVModel = platformView.getView(); - return this.configureForTextureLayerComposition(platformView, request); + let platformView: PlatformView = this.createPlatformView(request); + let textureId = this.configureForTextureLayerComposition(platformView, request); + this.viewIdWithTextureId.set(request.viewId, textureId); + return textureId; } private ensureValidRequest(request: PlatformViewCreationRequest): void { @@ -279,8 +239,8 @@ export default class PlatformViewsController implements PlatformViewsAccessibili } } - private createPlatformView(request: PlatformViewCreationRequest, wrapContext: boolean): PlatformView { - Log.i(TAG, "Enter createPlatformView"); + private createPlatformView(request: PlatformViewCreationRequest): PlatformView { + Log.i(TAG, "begin createPlatformView"); const viewFactory: PlatformViewFactory = this.registry.getFactory(request.viewType); if (viewFactory == null) { throw new Error("Trying to create a platform view of unregistered type: " + request.viewType) @@ -297,13 +257,11 @@ export default class PlatformViewsController implements PlatformViewsAccessibili } let platformView = viewFactory.create(this.context, request.viewId, createParams); - let embeddedView: DVModel = platformView.getView(); + let embeddedView: WrappedBuilder<[Params]> = platformView.getView(); if (embeddedView == null) { - throw new Error("PlatformView#getView() returned null, but an dynamic view reference was expected."); + throw new Error("PlatformView#getView() returned null, but an WrappedBuilder reference was expected."); } - this.setParams(embeddedView.params, "direction", request.direction); - // embeddedView.params.direction = request.direction; this.platformViews.set(request.viewId, platformView); return platformView; @@ -317,43 +275,25 @@ export default class PlatformViewsController implements PlatformViewsAccessibili private configureForTextureLayerComposition(platformView: PlatformView, request: PlatformViewCreationRequest): number { Log.i(TAG, "Hosting view in view hierarchy for platform view: " + request.viewId); - let viewWrapper: PlatformViewWrapper = new PlatformViewWrapper(); + // let viewWrapper: PlatformViewWrapper = new PlatformViewWrapper(); + let surfaceId: string = '0'; let textureId: number = 0; - - let physicalTop: number = this.toPhysicalPixels(request.logicalTop); - let physicalLeft: number = this.toPhysicalPixels(request.logicalLeft); - - Log.i(TAG, `View pW:${request.logicalWidth}, pH:${request.logicalHeight}, pT:${physicalTop}, pL:${physicalLeft}`); - - let param: DVModelParameters = new DVModelParameters(); - - this.setParams(param, "marginLeft", physicalLeft); - this.setParams(param, "marginTop", physicalTop); - // param.marginLeft = physicalLeft; - // param.marginTop = physicalTop; - - let model = platformView.getView(); - if (request.logicalWidth != null) { - let physicalWidth: number = this.toPhysicalPixels(request.logicalWidth); - this.setParams(model.params, "width", physicalWidth); - this.setParams(param, "width", physicalWidth); - // model.params.width = physicalWidth; - // param.width = physicalWidth; - } - - if (request.logicalHeight != null) { - let physicalHeight: number = this.toPhysicalPixels(request.logicalHeight); - this.setParams(model.params, "height", physicalHeight); - this.setParams(param, "height", physicalHeight); - // model.params.height = physicalHeight; - // param.height = physicalHeight; - } - - viewWrapper.setLayoutParams(param); - viewWrapper.addDvModel(model); - - this.flutterView?.getDVModel().children.push(viewWrapper.getDvModel()!); - this.viewWrappers.set(request.viewId, viewWrapper); + if (this.textureRegistry != null) { + textureId = this.textureRegistry!.getTextureId(); + surfaceId = this.textureRegistry!.registerTexture(textureId).getSurfaceId().toString(); + Log.i(TAG, "nodeController getSurfaceId: " + surfaceId); + this.flutterView!.setSurfaceId(surfaceId); + } + + let wrappedBuilder: WrappedBuilder<[Params]> = platformView.getView(); + this.flutterView?.setWrappedBuilder(wrappedBuilder); + this.flutterView?.setPlatformView(platformView); + let physicalWidth: number = this.toPhysicalPixels(request.logicalWidth); + let physicalHeight: number = this.toPhysicalPixels(request.logicalHeight); + this.nodeWidthLink.set(physicalWidth); + this.nodeHeightLink.set(physicalHeight); + this.flutterView!.getEmbeddingNodeController().setRenderOption(platformView, surfaceId, NodeRenderType.RENDER_TYPE_TEXTURE, request.direction); + this.flutterView!.getEmbeddingNodeController().rebuild(); Log.i(TAG, "Create platform view success"); return textureId; @@ -454,28 +394,6 @@ export default class PlatformViewsController implements PlatformViewsAccessibili private initializeRootImageViewIfNeeded(): void { } - initializePlatformViewIfNeeded(viewId: number): void { - let platformView: PlatformView = this.platformViews[viewId]; - if (platformView == null) { - throw new Error("Platform view hasn't been initialized from the platform view channel."); - } - if (this.platformViewParent[viewId] == null) { - return; - } - let dvModel: DVModel = platformView.getView(); - if (dvModel == null) { - throw new Error("PlatformView#getView() returned null, but an ohos dv model reference was expected."); - } - let parentView: FlutterMutatorView = new FlutterMutatorView(); - parentView.setOnDescendantFocusChangeListener(() => { - this.platformViewsChannel?.invokeViewFocused(viewId); - }, () => { - if (this.textInputPlugin != null) { - this.textInputPlugin.clearTextInputClient(); - } - }); - } - public onDisplayOverlaySurface(id: number, x: number, y: number, width: number, height: number): void { } diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/RawPointerCoord.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/RawPointerCoord.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad28649e47a33d788d7eaffe1026a84e8c37f48c --- /dev/null +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/plugin/platform/RawPointerCoord.ets @@ -0,0 +1,33 @@ +export class RawPointerCoords { + private orientation: number = 0; + private pressure: number = 0; + private size: number = 0; + private toolMajor: number = 0; + private toolMinor: number = 0; + private touchMajor: number = 0; + private touchMinor: number = 0; + private x: number = 0; + private y: number = 0; + + constructor(orientation: number, pressure: number, size: number, toolMajor: number, toolMinor: number, + touchMajor: number, touchMinor: number, x: number, y: number) { + this.orientation = orientation; + this.pressure = pressure; + this.size = size; + this.toolMajor = toolMajor; + this.toolMinor = toolMinor; + this.touchMajor = touchMajor; + this.touchMinor = touchMinor; + this.x = x; + this.y = y; + } + + getX(): number { + return this.x; + } + + getY(): number { + return this.y; + } + +} \ 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 d092c6c5d33f835ad82a6ea2b20891cdf41b1f90..97cf84a04871cf094bcaf3e7ab8b51a3deb15163 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 @@ -23,6 +23,8 @@ import MouseCursorPlugin from '../plugin/mouse/MouseCursorPlugin'; import Any from '../plugin/common/Any'; import Settings from '../embedding/ohos/Settings'; import ArrayList from '@ohos.util.ArrayList'; +import { EmbeddingNodeController } from '../embedding/ohos/EmbeddingNodeController'; +import PlatformView, { Params } from '../plugin/platform/PlatformView'; const TAG = "FlutterView"; @@ -45,10 +47,17 @@ class ViewportMetrics { physicalTouchSlop = -1; } +export class PlatformViewParas { + width: number = 0; + height: number = 0; + direction: Direction = Direction.Auto; +} export class FlutterView { private flutterEngine: FlutterEngine | null = null private id: string = "" private dVModel: DVModel = new DVModel("Stack", new DVModelParameters(), new DVModelEvents(), new DVModelChildren(), null); + private wrapBuilder: WrappedBuilder<[Params]> | undefined = undefined; + private platformView: PlatformView | undefined = undefined; private isSurfaceAvailableForRendering: boolean = false private viewportMetrics = new ViewportMetrics(); private displayInfo?: display.Display; @@ -59,6 +68,9 @@ export class FlutterView { private settings?: Settings; private mFirstFrameListeners: ArrayList; private isFlutterUiDisplayed: boolean = false; + private surfaceId: string = "0"; + private nodeController: EmbeddingNodeController = new EmbeddingNodeController(); + private platformViewSize: PlatformViewParas = new PlatformViewParas(); constructor(viewId: string, context: Context) { this.id = viewId @@ -91,6 +103,38 @@ export class FlutterView { return this.id } + setSurfaceId(surfaceId: string): void { + this.surfaceId = surfaceId; + } + + getSurfaceId(): string { + return this.surfaceId; + } + + getEmbeddingNodeController(): EmbeddingNodeController { + return this.nodeController; + } + + setWrappedBuilder(wrappedBuilder: WrappedBuilder<[Params]>) { + this.wrapBuilder = wrappedBuilder; + } + + getWrappedBuilder(): WrappedBuilder<[Params]> | undefined { + return this.wrapBuilder; + } + + setPlatformView(platformView: PlatformView) { + this.platformView = platformView; + } + + getPlatformView(): PlatformView | undefined { + return this.platformView; + } + + getPlatformViewSize(): PlatformViewParas { + return this.platformViewSize; + } + getDVModel() { return this.dVModel }