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>
|
|
|
|
|
/// Handler for Border on Linux using Skia rendering.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class BorderHandler : ViewHandler<IBorderView, SkiaBorder>
|
|
|
|
|
{
|
|
|
|
|
public static IPropertyMapper<IBorderView, BorderHandler> Mapper =
|
|
|
|
|
new PropertyMapper<IBorderView, BorderHandler>(ViewHandler.ViewMapper)
|
|
|
|
|
{
|
|
|
|
|
[nameof(IBorderView.Content)] = MapContent,
|
|
|
|
|
[nameof(IBorderStroke.Stroke)] = MapStroke,
|
|
|
|
|
[nameof(IBorderStroke.StrokeThickness)] = MapStrokeThickness,
|
2025-12-21 13:26:56 -05:00
|
|
|
["StrokeShape"] = MapStrokeShape, // StrokeShape is on Border, not IBorderStroke
|
2025-12-19 09:30:16 +00:00
|
|
|
[nameof(IView.Background)] = MapBackground,
|
2025-12-21 13:26:56 -05:00
|
|
|
["BackgroundColor"] = MapBackgroundColor,
|
2025-12-19 09:30:16 +00:00
|
|
|
[nameof(IPadding.Padding)] = MapPadding,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static CommandMapper<IBorderView, BorderHandler> CommandMapper =
|
|
|
|
|
new(ViewHandler.ViewCommandMapper)
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public BorderHandler() : base(Mapper, CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BorderHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
|
|
|
|
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SkiaBorder CreatePlatformView()
|
|
|
|
|
{
|
|
|
|
|
return new SkiaBorder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ConnectHandler(SkiaBorder platformView)
|
|
|
|
|
{
|
|
|
|
|
base.ConnectHandler(platformView);
|
2026-01-01 17:08:52 -05:00
|
|
|
if (VirtualView is View view)
|
|
|
|
|
{
|
|
|
|
|
platformView.MauiView = view;
|
|
|
|
|
}
|
|
|
|
|
platformView.Tapped += OnPlatformViewTapped;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void DisconnectHandler(SkiaBorder platformView)
|
|
|
|
|
{
|
2026-01-01 17:08:52 -05:00
|
|
|
platformView.Tapped -= OnPlatformViewTapped;
|
|
|
|
|
platformView.MauiView = null;
|
2025-12-19 09:30:16 +00:00
|
|
|
base.DisconnectHandler(platformView);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-01 17:08:52 -05:00
|
|
|
private void OnPlatformViewTapped(object? sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (VirtualView is View view)
|
|
|
|
|
{
|
|
|
|
|
GestureManager.ProcessTap(view, 0.0, 0.0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
public static void MapContent(BorderHandler handler, IBorderView border)
|
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
handler.PlatformView.ClearChildren();
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
var content = border.PresentedContent;
|
|
|
|
|
if (content != null)
|
2025-12-19 09:30:16 +00:00
|
|
|
{
|
2025-12-21 13:26:56 -05:00
|
|
|
// Create handler for content if it doesn't exist
|
|
|
|
|
if (content.Handler == null)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"[BorderHandler] 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (content.Handler?.PlatformView is SkiaView skiaContent)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"[BorderHandler] Adding content: {skiaContent.GetType().Name}");
|
|
|
|
|
handler.PlatformView.AddChild(skiaContent);
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapStroke(BorderHandler handler, IBorderView border)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (border.Stroke is SolidPaint solidPaint && solidPaint.Color is not null)
|
|
|
|
|
{
|
2026-01-16 05:30:52 +00:00
|
|
|
handler.PlatformView.Stroke = solidPaint.Color;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapStrokeThickness(BorderHandler handler, IBorderView border)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
2026-01-16 05:30:52 +00:00
|
|
|
handler.PlatformView.StrokeThickness = border.StrokeThickness;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapBackground(BorderHandler handler, IBorderView border)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (border.Background is SolidPaint solidPaint && solidPaint.Color is not null)
|
|
|
|
|
{
|
|
|
|
|
handler.PlatformView.BackgroundColor = solidPaint.Color.ToSKColor();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
public static void MapBackgroundColor(BorderHandler handler, IBorderView border)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (border is VisualElement ve && ve.BackgroundColor != null)
|
|
|
|
|
{
|
|
|
|
|
handler.PlatformView.BackgroundColor = ve.BackgroundColor.ToSKColor();
|
|
|
|
|
handler.PlatformView.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
public static void MapPadding(BorderHandler handler, IBorderView border)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
var padding = border.Padding;
|
2026-01-16 05:30:52 +00:00
|
|
|
handler.PlatformView.PaddingLeft = padding.Left;
|
|
|
|
|
handler.PlatformView.PaddingTop = padding.Top;
|
|
|
|
|
handler.PlatformView.PaddingRight = padding.Right;
|
|
|
|
|
handler.PlatformView.PaddingBottom = padding.Bottom;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
2025-12-21 13:26:56 -05:00
|
|
|
|
|
|
|
|
public static void MapStrokeShape(BorderHandler handler, IBorderView border)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
// StrokeShape is on the Border control class, not IBorderView interface
|
|
|
|
|
if (border is not Border borderControl) return;
|
|
|
|
|
|
|
|
|
|
var shape = borderControl.StrokeShape;
|
|
|
|
|
if (shape is Microsoft.Maui.Controls.Shapes.RoundRectangle roundRect)
|
|
|
|
|
{
|
|
|
|
|
// RoundRectangle can have different corner radii, but we use a uniform one
|
|
|
|
|
// Take the top-left corner as the uniform radius
|
|
|
|
|
var cornerRadius = roundRect.CornerRadius;
|
2026-01-16 05:30:52 +00:00
|
|
|
handler.PlatformView.CornerRadius = cornerRadius.TopLeft;
|
2025-12-21 13:26:56 -05:00
|
|
|
}
|
|
|
|
|
else if (shape is Microsoft.Maui.Controls.Shapes.Rectangle)
|
|
|
|
|
{
|
2026-01-16 05:30:52 +00:00
|
|
|
handler.PlatformView.CornerRadius = 0.0;
|
2025-12-21 13:26:56 -05:00
|
|
|
}
|
|
|
|
|
else if (shape is Microsoft.Maui.Controls.Shapes.Ellipse)
|
|
|
|
|
{
|
|
|
|
|
// For ellipse, use half the min dimension as corner radius
|
|
|
|
|
// This will be applied during rendering when bounds are known
|
2026-01-16 05:30:52 +00:00
|
|
|
handler.PlatformView.CornerRadius = double.MaxValue; // Marker for "fully rounded"
|
2025-12-21 13:26:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handler.PlatformView.Invalidate();
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|