* Add failing test: LineBreakEnumerator infinite loop on empty string
* Return false immediately for empty string in LineBreakEnumerator
Empty text has no content and should not produce any line break
opportunities. Short-circuit in MoveNext before entering the
read/rule loop, while keeping the PeekAt EndOfText fix as a
defensive safeguard.
* test: cover platform input detachment on close
Closed top levels retain the presentation source as the platform input callback. A late platform input event can therefore target an already disposed visual tree.\n\nThe regression test requires top-level closure to clear ITopLevelImpl.Input.
* fix: detach platform input when presentation source closes
Win32 can deliver WM_CAPTURECHANGED while destroying a popup that owns mouse capture. The platform then calls the input handler retained by the disposed presentation source, which logs a warning and can route input into a detached visual tree.\n\nClear the platform input callback at the start of presentation source disposal, alongside the existing scaling event unsubscription.
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* test(headless): reproduce cleanup exception dispatch hang
A dispatcher job that throws during work-item cleanup leaves the dispatch task incomplete and prevents later work from running. The session contract requires every queued dispatch to reach a terminal state.
Add behavioral coverage that posts a throwing cleanup job, expects its exception from Dispatch, and verifies the assembly session can process the next dispatch. The shared NUnit test runs under both PerTest and PerAssembly projects.
* fix(headless): report dispatch cleanup exceptions
An exception during application cleanup escapes the work item before its completion source is settled, faults the private consumer task, and leaves current and future Dispatch calls waiting forever.
Capture cleanup failures as the work item's exception so the consumer can continue. Restore synchronization context, locator scope, and dispatcher state in finally blocks before processing later work.
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Added failing test for #21746.
* fix(binding): reapply cached source values during UpdateTarget
UpdateTarget did not restore an uncommitted explicit two-way target value when the source still matched the binding expression's cached value. Equal-value suppression then prevented ValueStore from receiving the refresh.\n\nTrack the synchronous UpdateTarget rebuild and force publication only for that path, so the source value is reapplied without changing normal binding notification deduplication. The preceding regression test covers the observable behavior in both reflection and compiled binding paths.
---------
Co-authored-by: grokys <grokys@users.noreply.github.com>
- Added a check for 'target.IsEffectivelyVisible' inside 'HotkeyCommandWrapper.CanExecute'.
- Prevents HotKey from globally triggering and swallowing keyboard input when the host control or its parent panels are invisible (IsVisible="False").
- Added a corresponding unit test to verify input routing for hidden clickable controls.
Closes#21708
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* fix(ScrollBar): use large scroll events for ScrollToHome and ScrollToEnd
* Fix failing test
---------
Co-authored-by: Tim <47110241+timunie@users.noreply.github.com>
#21740 - SplitView must not steal BackRequested when its pane is closed
When the SplitView is in Overlay or CompactOverlay mode it handled the
TopLevel.BackRequested event even if its pane was not open, which broke
system back navigation. Now it only closes the pane and marks the event
handled when the pane is actually open; otherwise the event bubbles on.
Adds unit tests covering both overlay modes.
@
Co-authored-by: alexander.marek <alexander.marek@opti-q.com>
* Add AutomationPeer.ToScreen so each peer converts its own bounding rectangle to screen coordinates, fixing empty UIA bounds for root providers that are not ControlAutomationPeers.
* Update AutomationPeer.cs
* Update AutomationPeer.cs
* Only include XAML/AXAML AvaloniaResource in the AdditionalFiles
* Expose AvaloniaResourcePaths for the source generators and Roslyn
* Typo
* Update Generators.Sandbox, include some test assets
* Fix working area changed on windows platform won't trigger screens changed
* Fix ScreensPage on IntegrationTestApp won't remove Screens.Changed listener
* Add SystemParametersInfo.SPI_SETWORKAREA to Win32 UnmanagedMethods class
* Move notify screen working area changed to Win32Platform.WndProc instead of WindowImpl.AppWndProc
* Notify working area changed to screens without check PlatformSettings is Win32PlatformSettings
* Fix SelectableTextBlock selection offset with InlineUIContainer (#15880)
EmbeddedControlRun inherits TextRun.DefaultTextSourceLength = 1, so each
InlineUIContainer occupies one position in TextLayout. However,
InlineUIContainer.AppendText was a no-op, causing Inlines.Text to have
zero characters for each embedded control. This made TextLayout.HitTestPoint
return positions that were ahead of Inlines.Text indices by one per
InlineUIContainer, breaking SelectedText for any text after an embedded
control.
Fix: append the Unicode Object Replacement Character (U+FFFC) — the
standard placeholder for embedded objects — in AppendText so that
Inlines.Text character offsets stay in sync with the TextLayout positions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Expand InlineUIContainer selection tests with fencepost cases
Replace single assertion with a [Theory] covering all boundary positions
around the embedded control in 'foo\uFFFCbar':
- entirely before the container
- exactly the container character
- up to and including the container
- starting exactly after the container
- container through end
- one character either side of the container
- entire content
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Fix inter-word justification distribution and safety
TextAlignment.Justify was incorrect or a no-op in several common cases.
This corrects glyph targeting, buffer safety, run partitioning, the fill
target, and which lines get justified.
- Target the glyph ending each break boundary; step zero-width breaks
(CJK/Korean ideograph boundaries, hyphens) back one so the widened gap
sits on the break and the last visible glyph is never stretched.
- Copy-on-write the shaped buffer before adjusting advances and swap in a
fresh run, so justification never mutates glyph storage shared with a
TextRunCache entry, a Split sibling or a WithBidiLevel alias. Adds
ShapedBuffer.CloneWritable and TextLineImpl.ReplaceTextRun, which also
repoints the bidi-reordered runs used by draw and hit-test.
- Consume break opportunities per run instead of draining the whole queue
against the first run.
- Fill the visible Width to the paragraph width rather than the width
including trailing whitespace, so wrapped lines with trailing whitespace
justify instead of being left un-justified.
- Target MaxWidth for wrapped text rather than the widest produced line.
- Skip the last line, newline-terminated lines and hard-break lines.
Adds justification test coverage: CJK, mixed Latin+CJK, Arabic buffer
integrity, Latin wrapping, trailing whitespace and multi-run lines.
* Add failing test for trailing-whitespace overcount across runs
- TextLineImpl.CreateLineMetrics walks a line's runs backward to
compute trailing whitespace, stopping only when a run has none of
its own - not when a run is only partly whitespace.
- On a multi-run line where an interior run also ends in a space
(common at a script boundary, since each script run tends to end at
the following space), that space gets wrongly counted as trailing
too, even though visible content follows it later in the line.
- This shrinks Width, which InterWordJustification uses to decide how
much space a line still needs to reach the target width.
* Fix trailing-whitespace overcount across runs
- Only continue accumulating trailing whitespace from an earlier run
when the current run is entirely whitespace; otherwise the current
run's own visible content is the line's true end, and an earlier
run's trailing space is interior, not trailing.
- Width now correctly includes interior, non-trailing whitespace, so
wrapped multi-run lines (e.g. mixed-script text) no longer get
stretched past the target width when justified.
* Ignore CLAUDE.md
* Fix: TalkBack should highlight controls instead of their ancestors
* Fix: make parent controls navigable for specific types
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add tests around skipping controls for FocusManager #21620
* Return false by default in CanHaveFocusableChildren #21620
Importantly, this will return false for controls that are not focusable (e.g. TextBlock) or that have no focusable childen (e.g. an empty StackPanel)
* Add skip tests for FindFirstFocusableElement and FindLastFocusableElement #21620
* win32: let GraphicsAdapterSelectionCallback see unfiltered adapters on ARM64
The ARM64 Adreno blocklist in AngleWin32EglDisplay removed every Adreno
adapter from the list before it was handed to GraphicsAdapterSelectionCallback,
so an application had no way to opt back into hardware acceleration and no
indication that WARP (the Microsoft Basic Render Driver) was being forced.
Stop mutating the adapter list. The blocklist now only moves the *default*
selection to the first non-Adreno adapter when no callback is supplied, and
logs a warning about the CPU-usage impact and the available workarounds. When
a callback is present it receives the full, unfiltered adapter list and its
choice is used as-is.
As a side effect this also removes a latent IndexOutOfRange: the old code
could empty the list when every enumerated adapter was Adreno.
Refs #21689
* Update src/Windows/Avalonia.Win32/OpenGl/Angle/AngleWin32EglDisplay.cs
Co-authored-by: Max Katz <maxkatz6@outlook.com>
---------
Co-authored-by: nickna <nick@nassiri.xyz>
Co-authored-by: Max Katz <maxkatz6@outlook.com>
* Skia: avoid SKBitmap.Copy when creating ImmutableBitmap from pixels
The pixel-data ImmutableBitmap constructor used by LoadBitmap(IntPtr) wrapped
the caller's buffer with InstallPixels and then called SKBitmap.Copy() to get
an owned copy. SKBitmap.Copy() internally spins up an SKCanvas and draws the
source via an SKPaint shader, which is far more expensive than a memory blit.
Instead, allocate the destination with Marshal.AllocHGlobal, blit the pixels
span-to-span, and hand ownership to Skia via InstallPixels with a release proc
that frees the buffer. This is dramatically faster (~6x at 4096x4096, 50-80x at
small/medium sizes) and allocates less managed memory.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Skia: back ImmutableBitmap-from-pixels with BitmapMemory + shared per-row copy
Follow-up to the previous change. Two corrections/improvements:
* Use BitmapMemory as the backing storage instead of a bare Marshal.AllocHGlobal
buffer, so allocation/lifetime (incl. GC memory pressure) is managed in one
place. Ownership is handed to Skia via InstallPixels with a release proc that
disposes the BitmapMemory.
* The previous single contiguous blit was incorrect: the source stride is allowed
to be negative (bottom-up layouts). Copy row by row instead, which also handles
the backing store's row alignment differing from the source stride.
To avoid duplicating the row-copy logic, Bitmap.CopyPixelsCore is now an
internal static helper taking the source as raw (address, rowBytes, format),
reused by both Bitmap/WriteableBitmap.CopyPixels and ImmutableBitmap. Source-rect
validation moves to the (instance) call sites.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Skia: keep a self-contained instance CopyPixelsCore for inheritors
Re-add the instance CopyPixelsCore(..., ILockedFramebuffer fb) overload that
validates the source rect and delegates to the static raw-buffer core. Inheritors
(WriteableBitmap) and the framebuffer-based CopyPixels paths use this self-contained
overload again, while ImmutableBitmap keeps using the static raw overload directly.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Bitmap: add contiguous fast-path to CopyPixelsCore
When the source and destination layouts are identical, tightly-packed and forward
(no row padding, no X offset, positive stride == minStride), the whole region is
contiguous in both buffers, so copy it with a single blit instead of the per-row
loop. Measured up to ~5x faster for small images and ~30% for large ones; requiring
stride == minStride also guarantees we never read past the source's last row.
Negative strides, sub-rect copies and padded layouts still take the per-row path.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Address code-review findings on the ImmutableBitmap pixel path
* BitmapMemory: make ReleaseUnmanagedResources idempotent (zero Address after
FreeHGlobal). SKBitmap.InstallPixels invokes the release proc even when it
returns false, so the failure branch in ImmutableBitmap could dispose the same
BitmapMemory twice -> double free / heap corruption. Idempotency also guards any
other native-handoff consumer that double-disposes.
* Bitmap.CopyPixelsCore: compute minBufferSize in 64-bit so a very large
stride*height can't overflow the buffer-size guard and let the new contiguous
blit (or the per-row loop) run past the buffers.
* ImmutableBitmap: dispose the SKBitmap if SKImage.FromBitmap returns null so the
backing memory is freed promptly via the release proc instead of waiting for the
finalizer.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* BitmapMemory: free the buffer atomically with Interlocked.Exchange
Back Address with a field and claim it via Interlocked.Exchange in
ReleaseUnmanagedResources, so the buffer is freed exactly once even if an
explicit Dispose() races with the finalizer or a native release callback running
on another thread.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* BitmapMemory: drop redundant Interlocked comment
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Skia: let SKBitmap own its pixels in ImmutableBitmap, drop BitmapMemory
Since CopyPixelsCore copies into the destination, ImmutableBitmap can simply
TryAllocPixels a Skia-owned SKBitmap and blit into it, instead of allocating a
separate BitmapMemory and handing it to InstallPixels with a release proc. This
removes the manual unmanaged-memory lifetime management (and the
release-proc/double-dispose hazard along with it). SKBitmap frees its own pixels
on Dispose.
Reverts the now-unneeded BitmapMemory idempotency/Interlocked change too, since
that code path no longer exists.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* comments
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Add GlyphTypeface.CanShapeScript(Script), backed by a lazy read of the GSUB/GPOS ScriptList via the new ScriptListTable parser.
Add FontFallbackScriptHints.TryGetComplexShapingTags, which maps 17 complex scripts to the OpenType script tag(s) a font must declare to shape them.
Thread a Script shapingScript constraint through FontManager.TryMatchCharacter and FontCollectionBase.TryMatchCharacter as internal overloads, leaving the public signatures untouched.
Rework TextCharacters.CreateShapeableRun into a capability preference: a complex script tries shaping-capable fonts first (tier 0), then cmap-only coverage (tier 1); simple scripts keep the single historical tier.
Replace the NUL placeholder U+200B (ZERO WIDTH SPACE) with U+2060 (WORD JOINER) so the substitution introduces no line-break opportunity.
Suppress previous-run font reuse across a culture change for locale-sensitive scripts, so a zh run's font no longer pins following ja text.
Add 3 subset test fonts and 3 new test files (7 new tests) and fix 2 stale doc-comment crefs.
* Fix comments
* Fix font fallback reusing the wrong cached face from the script bucket
FontCollectionBase.TryMatchCharacter caches a resolved fallback family per
(script, culture) bucket. Two bugs let that bucket hand back a face that does
not match the request:
- A positive bucket entry suppressed the Tier D platform lookup for any later
codepoint, even one the bucket family cannot cover. A CJK run left the
Simplified-only U+534E unmatched (tofu) because the bucket resolved to a
Japanese font that lacks it, while another installed font could place it.
Tier D now treats only a negative (null) entry as "platform already
attempted"; a positive entry no longer blocks the platform, since that
family may not cover this codepoint.
- A cached covering match of a neighbouring FontCollectionKey was reused for a
different requested key. After a Bold run cached a face, a following Normal
run reused it and rendered bold (and the symmetric style and stretch cases).
Tier A, B and C now keep the exact key: when the cached covering match is a
neighbouring key, the exact-key face of the same family is resolved from the
platform via TryMatchCharacterFromPlatform, falling back to the neighbour
only when the platform has no exact face. Collections without a platform are
unchanged.
Add regression tests for both: a bucket whose font lacks a later same-script
codepoint, and weight and style leaks resolved through Tier B (script cache)
and Tier C (the sweep, exercised via a non-locale-sensitive script with no
culture).