Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Move to jsimport for bbox (backport #18900) #18905

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/Uno.UI/UI/Xaml/Window/WindowManagerInterop.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using System.Runtime.InteropServices.JavaScript;
using Microsoft.UI.Xaml.Controls;
using System.Xml.Linq;

namespace Uno.UI.Xaml
{
Expand Down Expand Up @@ -517,14 +518,8 @@ private struct WindowManagerRegisterEventOnViewParams

internal static Rect GetBBox(IntPtr htmlId)
{
var parms = new WindowManagerGetBBoxParams
{
HtmlId = htmlId
};

var ret = (WindowManagerGetBBoxReturn)TSInteropMarshaller.InvokeJS("Uno:getBBoxNative", parms, typeof(WindowManagerGetBBoxReturn));

return new Rect(ret.X, ret.Y, ret.Width, ret.Height);
var ret = NativeMethods.GetBBox(htmlId);
return new Rect(ret[0], ret[1], ret[2], ret[3]);
}

[TSInteropMessage]
Expand Down Expand Up @@ -890,6 +885,9 @@ internal static partial void ArrangeElement(

[JSImport("globalThis.Uno.UI.WindowManager.current.setUnsetCssClasses")]
internal static partial void SetUnsetCssClasses(IntPtr htmlId, string[] cssClassesToSet, string[] cssClassesToUnset);

[JSImport("globalThis.Uno.UI.WindowManager.current.getBBox")]
internal static partial double[] GetBBox(IntPtr htmlId);
}
}
}
28 changes: 8 additions & 20 deletions src/Uno.UI/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,24 +983,7 @@ namespace Uno.UI {
delete this.allActiveElementsById[elementId];
}

public getBBoxNative(pParams: number, pReturn: number): boolean {

const params = WindowManagerGetBBoxParams.unmarshal(pParams);

const bbox = this.getBBoxInternal(params.HtmlId);

const ret = new WindowManagerGetBBoxReturn();
ret.X = bbox.x;
ret.Y = bbox.y;
ret.Width = bbox.width;
ret.Height = bbox.height;

ret.marshal(pReturn);

return true;
}

private getBBoxInternal(elementId: number): any {
public getBBox(elementId: number): any {

const element = this.getView(elementId) as SVGGraphicsElement;
let unconnectedRoot: HTMLElement | SVGGraphicsElement = null;
Expand All @@ -1027,12 +1010,17 @@ namespace Uno.UI {
this.containerElement.appendChild(unconnectedRoot);
}

return element.getBBox();
let bbox = element.getBBox();

return [
bbox.x,
bbox.y,
bbox.width,
bbox.height];
}
finally {
cleanupUnconnectedRoot(this.containerElement);
}

}

public setSvgElementRect(pParams: number): boolean {
Expand Down
Loading