2025-12-19 09:30:16 +00:00
|
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
|
|
|
|
|
|
using Microsoft.Maui.Handlers;
|
|
|
|
|
using Microsoft.Maui.Graphics;
|
|
|
|
|
using Microsoft.Maui.Controls;
|
|
|
|
|
using Microsoft.Maui.Platform;
|
Major production merge: GTK support, context menus, and dispatcher fixes
Core Infrastructure:
- Add Dispatching folder with LinuxDispatcher, LinuxDispatcherProvider, LinuxDispatcherTimer
- Add Native folder with P/Invoke wrappers (GTK, GLib, GDK, Cairo, WebKit)
- Add GTK host window system with GtkHostWindow and GtkSkiaSurfaceWidget
- Update LinuxApplication with GTK mode, theme handling, and icon support
- Fix duplicate LinuxDispatcher in LinuxMauiContext
Handlers:
- Add GtkWebViewManager and GtkWebViewPlatformView for GTK WebView
- Add FlexLayoutHandler and GestureManager
- Update multiple handlers with ToViewHandler fix and missing mappers
- Add MauiHandlerExtensions with ToViewHandler extension method
Views:
- Add SkiaContextMenu with hover, keyboard, and dark theme support
- Add LinuxDialogService with context menu management
- Add SkiaFlexLayout for flex container support
- Update SkiaShell with RefreshTheme, MauiShell, ContentRenderer
- Update SkiaWebView with SetMainWindow, ProcessGtkEvents
- Update SkiaImage with LoadFromBitmap method
Services:
- Add AppInfoService, ConnectivityService, DeviceDisplayService, DeviceInfoService
- Add GtkHostService, GtkContextMenuService, MauiIconGenerator
Window:
- Add CursorType enum and GtkHostWindow
- Update X11Window with SetIcon, SetCursor methods
Build: SUCCESS (0 errors)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 11:19:58 -05:00
|
|
|
using Microsoft.Maui.Platform.Linux.Hosting;
|
2025-12-19 09:30:16 +00:00
|
|
|
using SkiaSharp;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Base handler for Page on Linux using Skia rendering.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class PageHandler : ViewHandler<Page, SkiaPage>
|
|
|
|
|
{
|
|
|
|
|
public static IPropertyMapper<Page, PageHandler> Mapper =
|
|
|
|
|
new PropertyMapper<Page, PageHandler>(ViewHandler.ViewMapper)
|
|
|
|
|
{
|
|
|
|
|
[nameof(Page.Title)] = MapTitle,
|
|
|
|
|
[nameof(Page.BackgroundImageSource)] = MapBackgroundImageSource,
|
2026-01-17 01:18:35 +00:00
|
|
|
[nameof(Page.IconImageSource)] = MapIconImageSource,
|
2025-12-19 09:30:16 +00:00
|
|
|
[nameof(Page.Padding)] = MapPadding,
|
2026-01-17 01:18:35 +00:00
|
|
|
[nameof(Page.IsBusy)] = MapIsBusy,
|
2025-12-19 09:30:16 +00:00
|
|
|
[nameof(IView.Background)] = MapBackground,
|
2026-01-01 12:20:28 -05:00
|
|
|
[nameof(VisualElement.BackgroundColor)] = MapBackgroundColor,
|
2025-12-19 09:30:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static CommandMapper<Page, PageHandler> CommandMapper =
|
|
|
|
|
new(ViewHandler.ViewCommandMapper)
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public PageHandler() : base(Mapper, CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PageHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
|
|
|
|
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SkiaPage CreatePlatformView()
|
|
|
|
|
{
|
|
|
|
|
return new SkiaPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ConnectHandler(SkiaPage platformView)
|
|
|
|
|
{
|
|
|
|
|
base.ConnectHandler(platformView);
|
|
|
|
|
platformView.Appearing += OnAppearing;
|
|
|
|
|
platformView.Disappearing += OnDisappearing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void DisconnectHandler(SkiaPage platformView)
|
|
|
|
|
{
|
|
|
|
|
platformView.Appearing -= OnAppearing;
|
|
|
|
|
platformView.Disappearing -= OnDisappearing;
|
|
|
|
|
base.DisconnectHandler(platformView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAppearing(object? sender, EventArgs e)
|
|
|
|
|
{
|
2025-12-21 13:26:56 -05:00
|
|
|
Console.WriteLine($"[PageHandler] OnAppearing received for: {VirtualView?.Title}");
|
2025-12-19 09:30:16 +00:00
|
|
|
(VirtualView as IPageController)?.SendAppearing();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDisappearing(object? sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
(VirtualView as IPageController)?.SendDisappearing();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapTitle(PageHandler handler, Page page)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.Title = page.Title ?? "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapBackgroundImageSource(PageHandler handler, Page page)
|
|
|
|
|
{
|
|
|
|
|
// Background image would be loaded and set here
|
|
|
|
|
// For now, we just invalidate
|
|
|
|
|
handler.PlatformView?.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapPadding(PageHandler handler, Page page)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
var padding = page.Padding;
|
|
|
|
|
handler.PlatformView.PaddingLeft = (float)padding.Left;
|
|
|
|
|
handler.PlatformView.PaddingTop = (float)padding.Top;
|
|
|
|
|
handler.PlatformView.PaddingRight = (float)padding.Right;
|
|
|
|
|
handler.PlatformView.PaddingBottom = (float)padding.Bottom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapBackground(PageHandler handler, Page page)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (page.Background is SolidColorBrush solidBrush)
|
|
|
|
|
{
|
2026-01-17 03:10:29 +00:00
|
|
|
handler.PlatformView.BackgroundColor = solidBrush.Color;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-01-01 12:20:28 -05:00
|
|
|
|
|
|
|
|
public static void MapBackgroundColor(PageHandler handler, Page page)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
var backgroundColor = page.BackgroundColor;
|
|
|
|
|
if (backgroundColor != null && backgroundColor != Colors.Transparent)
|
|
|
|
|
{
|
2026-01-17 03:10:29 +00:00
|
|
|
handler.PlatformView.BackgroundColor = backgroundColor;
|
2026-01-01 12:20:28 -05:00
|
|
|
Console.WriteLine($"[PageHandler] MapBackgroundColor: {backgroundColor}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-17 01:18:35 +00:00
|
|
|
|
|
|
|
|
public static void MapIconImageSource(PageHandler handler, Page page)
|
|
|
|
|
{
|
|
|
|
|
// Icon is typically used by navigation containers (Shell, TabbedPage)
|
|
|
|
|
// Store for later use but don't render directly on the page
|
|
|
|
|
handler.PlatformView?.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapIsBusy(PageHandler handler, Page page)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.IsBusy = page.IsBusy;
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handler for ContentPage on Linux using Skia rendering.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class ContentPageHandler : PageHandler
|
|
|
|
|
{
|
|
|
|
|
public static new IPropertyMapper<ContentPage, ContentPageHandler> Mapper =
|
|
|
|
|
new PropertyMapper<ContentPage, ContentPageHandler>(PageHandler.Mapper)
|
|
|
|
|
{
|
|
|
|
|
[nameof(ContentPage.Content)] = MapContent,
|
2026-01-17 01:18:35 +00:00
|
|
|
[nameof(ContentPage.ToolbarItems)] = MapToolbarItems,
|
2025-12-19 09:30:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static new CommandMapper<ContentPage, ContentPageHandler> CommandMapper =
|
|
|
|
|
new(PageHandler.CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public ContentPageHandler() : base(Mapper, CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ContentPageHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
|
|
|
|
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SkiaPage CreatePlatformView()
|
|
|
|
|
{
|
|
|
|
|
return new SkiaContentPage();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-17 01:18:35 +00:00
|
|
|
protected override void ConnectHandler(SkiaPage platformView)
|
|
|
|
|
{
|
|
|
|
|
base.ConnectHandler(platformView);
|
|
|
|
|
|
|
|
|
|
// Sync toolbar items initially
|
|
|
|
|
if (VirtualView is ContentPage contentPage && platformView is SkiaContentPage skiaContentPage)
|
|
|
|
|
{
|
|
|
|
|
SyncToolbarItems(skiaContentPage, contentPage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
public static void MapContent(ContentPageHandler handler, ContentPage page)
|
|
|
|
|
{
|
2025-12-21 13:26:56 -05:00
|
|
|
if (handler.PlatformView is null || handler.MauiContext is null) return;
|
2025-12-19 09:30:16 +00:00
|
|
|
|
|
|
|
|
// Get the platform view for the content
|
|
|
|
|
var content = page.Content;
|
|
|
|
|
if (content != null)
|
|
|
|
|
{
|
2025-12-21 13:26:56 -05:00
|
|
|
// Create handler for content if it doesn't exist
|
|
|
|
|
if (content.Handler == null)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"[ContentPageHandler] Creating handler for content: {content.GetType().Name}");
|
Major production merge: GTK support, context menus, and dispatcher fixes
Core Infrastructure:
- Add Dispatching folder with LinuxDispatcher, LinuxDispatcherProvider, LinuxDispatcherTimer
- Add Native folder with P/Invoke wrappers (GTK, GLib, GDK, Cairo, WebKit)
- Add GTK host window system with GtkHostWindow and GtkSkiaSurfaceWidget
- Update LinuxApplication with GTK mode, theme handling, and icon support
- Fix duplicate LinuxDispatcher in LinuxMauiContext
Handlers:
- Add GtkWebViewManager and GtkWebViewPlatformView for GTK WebView
- Add FlexLayoutHandler and GestureManager
- Update multiple handlers with ToViewHandler fix and missing mappers
- Add MauiHandlerExtensions with ToViewHandler extension method
Views:
- Add SkiaContextMenu with hover, keyboard, and dark theme support
- Add LinuxDialogService with context menu management
- Add SkiaFlexLayout for flex container support
- Update SkiaShell with RefreshTheme, MauiShell, ContentRenderer
- Update SkiaWebView with SetMainWindow, ProcessGtkEvents
- Update SkiaImage with LoadFromBitmap method
Services:
- Add AppInfoService, ConnectivityService, DeviceDisplayService, DeviceInfoService
- Add GtkHostService, GtkContextMenuService, MauiIconGenerator
Window:
- Add CursorType enum and GtkHostWindow
- Update X11Window with SetIcon, SetCursor methods
Build: SUCCESS (0 errors)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 11:19:58 -05:00
|
|
|
content.Handler = content.ToViewHandler(handler.MauiContext);
|
2025-12-21 13:26:56 -05:00
|
|
|
}
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
// The content's handler should provide the platform view
|
2025-12-21 13:26:56 -05:00
|
|
|
if (content.Handler?.PlatformView is SkiaView skiaContent)
|
2025-12-19 09:30:16 +00:00
|
|
|
{
|
2025-12-21 13:26:56 -05:00
|
|
|
Console.WriteLine($"[ContentPageHandler] Setting content: {skiaContent.GetType().Name}");
|
2025-12-19 09:30:16 +00:00
|
|
|
handler.PlatformView.Content = skiaContent;
|
|
|
|
|
}
|
2025-12-21 13:26:56 -05:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"[ContentPageHandler] Content handler PlatformView is not SkiaView: {content.Handler?.PlatformView?.GetType().Name ?? "null"}");
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
handler.PlatformView.Content = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-17 01:18:35 +00:00
|
|
|
|
|
|
|
|
public static void MapToolbarItems(ContentPageHandler handler, ContentPage page)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is not SkiaContentPage skiaContentPage) return;
|
|
|
|
|
SyncToolbarItems(skiaContentPage, page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SyncToolbarItems(SkiaContentPage platformView, ContentPage page)
|
|
|
|
|
{
|
|
|
|
|
platformView.ToolbarItems.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (var item in page.ToolbarItems)
|
|
|
|
|
{
|
|
|
|
|
var skiaItem = new SkiaToolbarItem
|
|
|
|
|
{
|
|
|
|
|
Text = item.Text ?? "",
|
|
|
|
|
Command = item.Command,
|
|
|
|
|
Order = item.Order == ToolbarItemOrder.Primary
|
|
|
|
|
? SkiaToolbarItemOrder.Primary
|
|
|
|
|
: SkiaToolbarItemOrder.Secondary
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Load icon if present
|
|
|
|
|
if (item.IconImageSource is FileImageSource fileSource)
|
|
|
|
|
{
|
|
|
|
|
// Icon loading would be async - simplified for now
|
|
|
|
|
Console.WriteLine($"[ContentPageHandler] Toolbar item icon: {fileSource.File}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
platformView.ToolbarItems.Add(skiaItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
platformView.Invalidate();
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|