XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESystem

【Rust】XFE系统,基于Rust和汇编

公开
关注 0 Fork 0 Star 0
UTF-8
namespace XFESystem.Desktop;

/// <summary>Each browser window owns a page runtime; no DOM or globals are shared across windows.</summary>
public interface IInteractiveBrowserFactory
{
    IInteractiveBrowserSession CreatePageSession();
}

public interface IInteractiveBrowserSession
{
    BrowserPage CurrentPage { get; }
    long Revision { get; }
    BrowserPage Navigate(string address);
    BrowserPage NavigateDocument(string source, string path, bool dark = true) => throw new NotSupportedException("Document web previews are unavailable.");
    /// <summary>Show the real sanitized document before running its packaged enhancement scripts.</summary>
    BrowserPage BeginDocumentPreview(string source, string path, bool dark = true) => NavigateDocument(source, path, dark);
    BrowserPage NavigateEditor(string source, string path) => throw new NotSupportedException("The web editor is unavailable.");
    string? ReadEditorText() => null;
    void SetCanvas(IDesktopCanvas canvas) { }
    /// <summary>The platform has exclusively transferred and verified the prepared font caches.</summary>
    void CompleteEditorPreparationHandoff(IDesktopCanvas canvas, bool equivalentTextMetrics) => SetCanvas(canvas);
    void ResizeViewport(int width, int height) { }
    void Paint(IDesktopCanvas canvas, DesktopBounds viewport, double scrollY);
    bool Pointer(BrowserPointerInput input);
    bool Key(BrowserKeyboardInput input);
    bool AdvanceTime(long monotonicMilliseconds);
    /// <summary>Called only after the desktop successfully presents a complete frame.</summary>
    void FramePresented() { }
    double DocumentHeight { get; }
    bool TextCursor => false;
}

public readonly record struct BrowserPointerInput(string Type, double X, double Y, int Button = 0,
    int Buttons = 0, double DeltaY = 0, bool Shift = false, bool Control = false, bool Alt = false);
public readonly record struct BrowserKeyboardInput(string Type, string Key, string Code = "", string Text = "",
    bool Shift = false, bool Control = false, bool Alt = false, bool Repeat = false);

/// <summary>Native raster/font operations required by laid-out web content. Clipping nests inside scene damage.</summary>
public interface IDesktopWebCanvas : IDesktopCanvas
{
    void PushClip(DesktopBounds bounds);
    void PopClip();
    double MeasureWebText(string text, double fontSize, string fontFamily, int fontWeight);
    double MeasureWebLineHeight(double fontSize,string fontFamily,int fontWeight)=>fontSize*1.2;
    (int Width, int Height, byte[] Alpha) RasterizeWebText(string text, double fontSize, string fontFamily, int fontWeight);
    void WebText(string text, uint color, double x, double y, double fontSize, string fontFamily, int fontWeight, double opacity = 1);
}