Skip to content

Commit

Permalink
Merge pull request #18900 from unoplatform/dev/jela/bbox-perf
Browse files Browse the repository at this point in the history
fix: Move to jsimport for bbox
  • Loading branch information
jeromelaban authored Nov 24, 2024
2 parents 9883391 + 00f3ced commit 37cac2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
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 @@ -984,24 +984,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 @@ -1028,12 +1011,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

0 comments on commit 37cac2e

Please sign in to comment.