* Fix duplicate insertion of shared StyleInstance into the same ValueStore
StyleBase cached a single shared StyleInstance per ControlTheme and reused
it for every attach, regardless of the FrameType it was attached as and
regardless of whether it was already present in the target's ValueStore.
The same ControlTheme can legitimately be attached to one control twice
(once as its own Theme and once via the templated parent's theme), and on
re-attach / re-application of styling the cached shared instance was
inserted a second time into the same store, triggering
- Cache shared instances per FrameType (Theme / TemplatedParentTheme)
- Only reuse a shared instance if it is not already in the target store
* Cache shared style instances per FrameType; drop redundant ContainsFrame
Address review feedback on #22276:
- Replace the two shared-instance fields with a fixed-size array indexed
by FrameType, giving one cached instance per frame type (Style,
TemplatedParentTheme, Theme). InlineDictionary was considered but
requires a class type key, so an array indexed by the enum is the
equivalent zero-allocation structure.
- Remove the ContainsFrame linear scan: with one instance per frame type
a duplicate insert of the same instance into the same ValueStore is no
longer possible, because OnControlThemeChanged /
OnTemplatedParentControlThemeChanged always RemoveFrames(type) before
re-attaching. This is now proven by unit tests.
- Add unit tests:
- ControlTheme attached as both Theme and TemplatedParentTheme to the
same control creates two distinct instances.
- Re-attaching after RemoveFrames does not duplicate the instance.
- The same instance is shared between different controls for the same
frame type.
* Avoid per-style array allocation for the single shared instance case
Address review feedback: the vast majority of styles only ever have a
single shared instance, so keep a plain field + FrameType for that case
and only allocate the FrameType-indexed array lazily once a second frame
type is shared. This removes the extra array allocation added to every
style by the previous implementation.
* Address review nits: succinct comment, avoid eager GetSharedInstance call
- Shorten the shared-instance comment per the AI guidelines.
- Invert the condition so GetSharedInstance is only called when
canShareInstance is true.
* Comment shortened to two lines :)
* Add failing test for focus staying on a removed or hidden element
When a focus scope is removed or hidden while its focused element has the
focus and the root scope's focused element can't be focused (e.g. a button
disabled while its command waits for a choice in a flyout), the keyboard
focus stays on the removed or hidden element.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Clear focus when the focused element is removed or hidden and can't be restored
Focus(null) leaves the focus alone when the focused element is in another
focus scope than the focus root, but a removed or hidden element also passes
that check. Only apply it while the focused element is attached and visible.
Fixes#22342
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Add popup tests with actual focus services
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add a failing test for re-attaching a cleared child visual
A control that sets a child visual on attach and clears it on detach cannot
attach the same visual again: the cleared child stays parented to the
element's discarded composition visual.
* Un-parent the previous child visual when replacing it
SetElementChildVisual left removing the old child to the renderer's next
sync of the element's children. That sync may never come: a control that
clears its child visual in OnDetachedFromVisualTree does so before
DetachFromCompositor discards the element's composition visual, so the old
child stays parented to it and attaching it anywhere later throws.
Remove the previous child from the element's composition visual directly.
* Add render tests for StreamGeometry Clone and Open with a Transform
* Fix StreamGeometry Clone and Open when a Transform is set
* Add tests for when a geometry reports that its drawing changed
* Report the change when the drawing finishes, and let PathGeometry.Open add figures
* Remove the comments and revert the interface type
* Report deselected items and batch SelectAll in TreeView
Selecting a different item clears and repopulates SelectedItems. The clear
raises a Reset, which carries no OldItems, so the deselection was dropped and
only the addition was reported. Track the previous selection so the reset can
work out what was deselected, and raise the clear and the add as one event.
SelectAll added items one at a time, raising an event per item. Batch it the
same way.
* Simplify TreeView selection tracking
Keep a single snapshot of the last reported selection and diff against it,
instead of tracking the snapshot and the pending changes separately. A reset
that keeps some items no longer reports them as added.
Co-authored-by: Steven Kirk <grokys@users.noreply.github.com>
* Simplify comments
* Remove comment.
No other fields have comments, pretty much in the whole codebase. This isn't an exception.
---------
Co-authored-by: Steven Kirk <grokys@users.noreply.github.com>
CreateTextLayoutCore measured the inline embedded controls whenever the
layout was built. The compositor renders dirty visuals under hidden
ancestors too, and layout never measures those, so a TextBlock in a
hidden subtree built its layout from RenderCore and measured its
InlineUIContainer children there. A child measured for the first time
applies its template, attaching visuals inside the render pass, and
CompositingRenderer.AddDirty throws "Visual was invalidated during the
render pass".
- Only measure the embedded controls from CreateTextLayoutCore when the
block's own measure is valid. An invalid block has a measure pass
pending, and MeasureOverride measures the children once the block is
reachable.
- Cover a block hidden at first render, an embedded control shown while
its page is hidden, and a page hidden after it was shown.
Fixes#22380
* Update caret bounds after TextLayout recreation
* Drop redundant TextLayout access from the centered caret test
- Arrange already recreates the layout when the constraint changes, so the explicit getter call added nothing
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* test(menu): cover NativeMenuItem command parameter changes
A NativeMenuItem keeps the CanExecute result from the moment its Command
is set. When CommandParameter is set or cleared afterwards, IsEnabled
does not change.
Add tests that set and clear CommandParameter after Command. Both fail
at present. A third test records that a parameter change does not enable
an item that has no command.
* fix(menu): update NativeMenuItem state when CommandParameter changes
A NativeMenuItem queries CanExecute only when its Command changes. If
CommandParameter is assigned afterwards, IsEnabled keeps the result for
the previous parameter.
This occurs in XAML when the data context is set before the XAML is
loaded. The Command binding resolves when it is applied, which is before
a CommandParameter property element is assigned. A command that rejects
a null parameter, such as RelayCommand<int>, then leaves the item
disabled permanently.
Query CanExecute again when CommandParameter changes, as Button and
MenuItem do. Skip the query when the item has no command, because there
is no result to refresh and the query would reset IsEnabled to true.
Fixes#21914
* chore: trim code comments
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* test(datepicker): cover Shift+Tab out of CalendarDatePicker
Shift+Tab from the text box of a CalendarDatePicker does not reach the
previous control. The previous tab stop is the picker, and the picker
moves focus back to its text box, so focus stays in the text box.
The test fails until the picker leaves the tab order.
* fix(datepicker): allow Shift+Tab out of CalendarDatePicker
CalendarDatePicker is a tab stop, and it moves focus to its text box
when it receives focus. Shift+Tab from the text box selects the picker
as the previous tab stop, so focus returns to the text box and the
keyboard cannot leave the picker backwards.
Remove the picker from the tab order, as AutoCompleteBox and
NumericUpDown do. Tab navigation then reaches the text box directly in
both directions. The picker stays focusable, so pointer focus and
Focus() calls behave as before.
Fixes#15193
* chore: trim code comments
* test(controls): cover CanExecuteChanged subscription for a style-set Command
The existing tests set Command as a local value. A Command that a style
setter supplies takes a different path: the style applies the value during
attach, and removes the value during detach, before the control overrides run.
For Button and MenuItem the new tests fail. Each control subscribes two times
on attach, and both subscriptions remain after the control leaves the logical
tree, so the command keeps the control alive.
The SplitButton test passes. SplitButton already handles this sequence, and
the test guards that behaviour.
* fix(controls): release a style-set Command when Button or MenuItem detaches
When a style setter supplies Command, Button and MenuItem subscribe to
CanExecuteChanged two times on attach and do not unsubscribe on detach. The
command then holds the control, and every control behind it, for the lifetime
of the command.
Both controls decide whether to move the subscription from
ILogical.IsAttachedToLogicalTree. StyledElement changes that state before the
styles change and before the attach and detach overrides run:
- On attach, the style sets Command while the control already reports
attached. The property handler subscribes, then OnAttachedToLogicalTree
subscribes again.
- On detach, the style value goes away while the control already reports
detached. The property handler skips the unsubscribe, then
OnDetachedFromLogicalTree finds no Command to unsubscribe from.
Track the subscription state in the control instead. Set the flag where
OnAttachedToLogicalTree subscribes and clear the flag where
OnDetachedFromLogicalTree unsubscribes. The Command property handler then
moves the subscription only while the control owns one. SplitButton already
uses this approach.
Fixes#20588Fixes#19619
* chore: trim code comments
* chore: remove the comment on _isSubscribedToCommand
The field name states its purpose. The comment only gave the history of
the change.
* Wayland : Add the AppId in WaylandPlatformOptions or in Windows WaylandProperties to overload the app id if the executable name don't match the app name of the .desktop file
* Rework AppId handling in Wayland backend:
- Centralize default AppId definition in WaylandGlobals
- Use fallback to `Globals.AppId` where applicable.
- Add detailed documentation for the `WaylandProperties.AppId` attached property.
* Make WaylandProperties static
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Stop radial gradients with a moved origin from hiding the background
When the gradient origin differs from the center, the gradient is composed
over a solid shader of the colour it clamps to, because Skia leaves the area
no gradient circle reaches unpainted. That backdrop sits behind the whole
brush, so it also shows through transparent stops. Only compose it when the
origin is outside the circle, which is the only case that leaves such an area.
* Fix regression when the origin lies on the circle
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Fix showing ellipsis when word wrap and limited by height or MaxLines.
* Simplify fix based on comment
* Align height clip behavior with WPF/HTML when last visible line fits in the available width
No ellipsis is shown in this case so I guess it makes sense for Avalonia to behave the same.
* Clarify truncation comments and cover them at the TextLayout level
- Reword the MaxHeight and MaxLines truncation comments: the two limits
differ on purpose (a height cut only ellipsizes a soft-wrapped line, a
line-count cut ellipsizes after a hard break too, like CSS line-clamp).
- Add TextLayout tests with the real shaper for MaxLines at a hard break,
MaxHeight at a hard break and MaxHeight at a wrapped line, so the
behavior is guarded below the TextBlock layer.
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* Add failing tests for bidi controls being ignored after the first paragraph
* Allow embedding and isolate flags to be set after a reset
Append only set HasEmbeddings and HasIsolates if they had no value, but Reset
sets them to false. Once a BidiData had been reset, explicit formatting
characters could no longer raise them, so overrides, embeddings and isolates
were only applied only applied in the first paragraph formatted on a thread.
HasBrackets is reset the same way, this makes the flags match.
* Escape bidi control characters in tests
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* DiagnosticTextRenderer: Make numbers monospace
* Center diagnostic digits in their own cell and derive line height from metrics
- Digits were centered against the widest printable ASCII glyph instead of the digit cell, so each digit was drawn right of its cell, overlapped the next glyph and the last one left the background rect. Center against the digit cell and drop the unused max glyph width.
- Compute the line height once from the font metrics (LineSpacing scaled to the em size) instead of scanning glyph run bounds, which already resolve to that value.
- Add tests for fixed digit width, cell centering, stable trailing text and the metrics-based height.
* Draw the FPS line from shaped labels and a fixed digit grid
- Shape the static labels once into single glyph runs and draw the frame number, FPS and visual counts as zero-padded digits in fixed cells. A frame no longer formats a string or measures text.
- Rebuild the memory text only when the pool sizes change, and compute the background rect width once.
- RenderFps takes the raw memory and visual counts instead of a preformatted string. Counters now have a fixed width (frame 8 digits, FPS 3, visual counts 5) and clamp instead of growing.
- Hoist the translucent layer brush into a static field.
---------
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* [Text] Fix RunIndex mapping in BidiReorderer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* [Text] Cover BidiReorderer run index mapping at both layers
- BidiReordererTests: assert RunIndex is the visual position of each logical IndexedTextRun, and that textRuns ends up in visual order, for level sequences that form non-involutive permutations (the old lookup only worked for swaps and reversals).
- TextLayoutTests: splitting runs with style spans must not change line width, per-character bounds or hit-test results, across LTR and RTL paragraphs with mixed Hebrew/Latin/digit text.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Benedikt Stebner <Gillibald@users.noreply.github.com>
* Add regression tests for empty text layout ranges
Exercise empty ranges at interior and CRLF boundaries using real text layouts, and retain checks for completed-line geometry and existing negative-range behavior.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Handle empty ranges in TextLayout hit testing
Return empty geometry for zero-length requests and stop traversing lines when the remaining range is empty. Keep negative-range behavior and TextLine validation unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add direct TextLine empty range regressions
Expect no text bounds for zero-length ranges at caret and CRLF line boundaries. Retain checks for normal nonempty geometry. Before the fix, the TextLine suite has 8 failures and 81 passes, with all failures throwing for textLength = 0.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Return no text bounds for empty ranges
Handle zero-length ranges in TextLineImpl.GetTextBounds so all consumers share the empty bounds contract. Remove the TextLayout-only guards and document the result. Negative-length behavior is unchanged.
Verified 168 passing TextLine/TextLayout tests, with one existing profiling test skipped.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: adirh <27368554+adirh3@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* MenuItem automation: expand/collapse and invoke.
Implement `IExpandCollapseProvider` and `IInvokeProvider` on the `MenuItemAutomationPeer`. This was surprisingly involved so got Claude to generate some tests for it.
- The provider split matches WPF: `Invoke` for leaf items, `ExpandCollapse` for items with a submenu.
- `Invoke()` goes through `DefaultMenuInteractionHandler.Click`, so checkable items toggle and the menu closes. This works for a `Menu`, a `ContextMenu` and a `MenuFlyout`.
- `MenuItem.MenuInteractionHandler` is now exposed internally so we don't need to do the lookup in two places
* Close the menu when collapsing a top-level menu item.
Collapse on a top-level item now closes the whole menu, matching a click on an
open top-level header. Menu tests now open menus via the peer and assert
Menu.IsOpen, and cover collapsing top-level and nested items.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BZgdE18BxKaTJZQZKUppXW
* Make Collapse a no-op when the menu item is already collapsed.
Previously, collapsing an already-collapsed top-level item closed the whole
menu, including another top-level item's open submenu.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BZgdE18BxKaTJZQZKUppXW
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
UI Automation calls GetPatternProvider and the provider-based InvokeSync
overloads on a background thread, where they called Peer.GetProvider
directly. MenuItemAutomationPeer.GetProviderCore reads ToggleType, which
throws off the UI thread, so checkable menu items never exposed the
Toggle pattern.
Co-authored-by: Steven Kirk <grokys@users.noreply.github.com>
* Use `Microsoft.NET.Sdk.StaticWebAssets` in Avalonia.Browser, rely on built-in assets packaging
* Update ControlCatalog.Browser to use OverrideHtmlAssetPlaceholders + fingerprint
* Fix default BrowserPlatformOptions.FrameworkAssetPathResolver behavior
* Remove outdated ShouldIncludeNativeSkiaSharp/ShouldIncludeNativeHarfBuzzSharp
* Update BuildTests.Browser
* Support static web assets in single project browser apps
The browser TFM now layers Microsoft.NET.Sdk.WebAssembly on top of Microsoft.NET.Sdk,
so Avalonia.Browser's javascript resolves from _content/Avalonia.Browser/.
The static web assets SDK only discovers wwwroot at the project root and offers no
property to relocate it, so define the assets under $(BrowserProjectFolder)wwwroot
directly. WasmExtraFilesToDeploy is kept for the legacy WasmApp model and is now
guarded so the two paths cannot both run.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Restore WasmExtraFilesToDeploy fallback
* Remove unused runtimeconfig.template.json
* Fingerprint Avalonia.Browser javascript from the app build
Avalonia.Browser no longer packs its javascript as static web assets.
build/Avalonia.Browser.targets defines them in the consuming app instead,
the same way Microsoft.NET.Sdk.BlazorWebAssembly handles blazor.webassembly.js.
A hard fingerprint renames the file, which plain static hosting needs,
but it does not survive dotnet pack on the .NET 10 SDK:
the packed props record the resolved name and drop the marker,
so no import map entry is emitted and package consumers request a file that was never renamed.
Evaluating the expression in the app keeps it intact.
.NET 11 fixes pack, but only for consumers on the .NET 11 SDK.
avalonia.js and storage.js are fingerprinted, sw.js and the source maps are not:
those load by URL through serviceWorker.register and sourceMappingURL,
which the import map does not rewrite.
The project drops back to Microsoft.NET.Sdk,
so it no longer emits staticwebassets.runtime.json and .endpoints.json next to the assembly.
A project reference carried those into the app output and made the wasm dev server
serve the app from the wrong manifest, 404ing the icu .dat and .pdb files.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1TywZ5LUqgagfuzPcxjf5
* Only fingerprint Avalonia javascript when an import map is generated
A renamed file resolves only through the import map,
which the SDK emits only when OverrideHtmlAssetPlaceholders is true.
Apps that do not opt in got renamed files and an empty import map placeholder,
so JSHost.ImportAsync requested a file that no longer existed.
$(StaticWebAssetsFingerprintContent)=false is now honoured too.
Prefer wwwroot/ over staticwebassets/ when locating the javascript.
esbuild wrote to staticwebassets/ before this branch and both are gitignored,
so a leftover directory would otherwise shadow the current output forever.
Skip the assets, and AVA3002, in design time builds.
Those do not build the project reference, so wwwroot may legitimately be absent.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1TywZ5LUqgagfuzPcxjf5
* Serve the Avalonia service worker from the app root
A service worker is scoped to its own directory,
and the save picker polyfill looks the registration up with getRegistration(),
which matches against the document URL.
From _content/Avalonia.Browser/ the lookup found nothing,
so every save fell back to buffering the whole file into a Blob
instead of streaming through the worker.
Rename the entry point to avalonia-sw.ts and place the output at the app root,
which is the only location whose default scope covers the document.
The polyfill builds its URLs from sw.scope, so nothing else has to change.
Registration was already broken before this branch for a different reason:
the path resolved to ./sw.js while the file shipped under _framework/,
so register() hit a 404 that nothing observed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1TywZ5LUqgagfuzPcxjf5
* Remove unused modulepreload
* Fix duplicated _AvaloniaBrowserStaticWebAsset for AvaloniaSingleProject.targets
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Fix TrayIcon being added to the system tray on creation
- Create the native tray icon only after it is attached to Application
- Unsubscribe from the previous TrayIcons collection when it is replaced
- Ensure tray icons cannot escape cleanup during application shutdown
* Add tray icon test.
* Remove tray icon visibility toggle to verify macOS integration tests
* Unified code style
* Keep the native icon hidden until all properties have been initialized.
* Handling invalid waits in testing
* Fix bad auto-merge
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Introduced a better opengl context management API on top of existing interop APIs
* Rename ICompositionGlTexture.Texture to TextureInfo
* Wait for potentially pending import and present
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Test immediate synchronous and asynchronous headless session disposal
* Initialize headless dispatch task before starting and stop it before queue completion
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add test for Win32 BeginMoveDrag with a non-primary pointer
BeginMoveDrag throws for a non-primary pointer from a posted callback, so the
caller can't catch the exception and it ends up unhandled on the dispatcher.
* Throw from Win32 BeginMoveDrag before posting the drag
Since #14190 the non-primary pointer check runs inside the posted callback
together with the native drag calls, so its exception is raised after
BeginMoveDrag has returned. Check the pointer before posting, as #14186 did,
and only post the SendMessage calls.
Fixes#22220
* Pass the test cancellation token to InvokeAsync
Fixes the xUnit1051 analyzer warning in BeginMoveDragTests.
* Init Avalonia.Themes.UnitTests.csproj, add first tests
* All XAML files should be internal in our themes
* Run proper headless unit test application in Themes tests
* Add ControlThemeTests
* Fix missing resource definitions
* Add Should_Not_Define_Setters_With_Hardcoded_Brushes_Or_Colors test
* Add Should_Define_All_Requested_Template_Parts test
* Update control theme tests to include resolved template parts and their setters
* Whitespace string resource was in fact ignored, use non-breaking space
* Move NavigationBarShadowBackground to the dynamic resource, instead of hardcoding
* Also validate that no BoxShadow is hardcoded - fix existing issues
* Update Should_Not_Include_Any_Reachable_Xaml_Files doc
* Add Should_Define_Identical_Keys_In_ThemeDictionaries and fix existing issues
* Add [Trait] to group theme tests
* Add missing build.cs RunCoreTest("Avalonia.Themes.UnitTests")
* EnumerateTemplateChildren should respect window decoration templates, fix existing issues
* Adjust ControlThemeTests to also check nested style templates, and fix existing issues
* Add API suppressions for XamlX generated types (unreachable by the C#)
* Make sure that empty collections are not passed as green
* Fix StreamGeometry Clone and Open when a Transform is set
Clone() and Open() cast PlatformImpl to IStreamGeometryImpl, but once
Transform is set PlatformImpl is a transformed wrapper, so both threw.
Use the stream itself instead, and keep the Transform on the clone.
The transformed wrapper copies the path when it is created, so after
Open() it would keep showing the old content. Invalidate the geometry
when the context is disposed if a transform is set.
* Remove the Open() refresh from StreamGeometry
Refreshing a transformed geometry after Open() works around a Skia backend
bug that is being fixed separately, so this PR only fixes Clone() and Open()
throwing when a Transform is set.
* Add tests for right-clicking below the text in SelectableTextBlock
A right-click below the text clears the selection, while the same click in a
TextBox keeps it.
* Keep the selection when right-clicking below the text in SelectableTextBlock
A point below the text hit-tests to one past the end of the text.
SelectableTextBlock compared that raw position with the selection, so a
right-click below the text moved the caret and cleared the selection. Clamp it
with TextBox.CoerceCaretIndex, as TextBox does through its caret.
* [X11] Implement support for PRIMARY selection
* Compile
* Replace TopLevel.PrimarySelection with TryGetClipboard(ClipboardType)
* Address review: reuse GetSelectionRange, X11-only doc comment
* Access each property only once in `GetSelectionRange`
* Return Task from PublishText
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add failing test: preedit crashes when a CaretBoundsChanged handler invalidates layout
TextPresenter's TextLayout getter runs UpdateCaret after creating the
layout, and UpdateCaret raises CaretBoundsChanged. A subscriber that
synchronously invalidates the text layout - the IME candidate window or
any caret-following code forcing a layout pass does this in practice -
nulls the field before the getter returns it, so the surrounding
computation (the preedit update, or the measure pass materializing the
layout) dereferences null. Found live by TextInputDebugger on its first
Japanese IME session: the trace viewer's scroll-into-view pumped a layout
pass from inside the caret callback and every composition update crashed.
* Measure the caret outside the text layout getter
The getter built the layout and then ran UpdateCaret, which raises
CaretBoundsChanged. A handler that invalidates the layout - an IME candidate
window, or caret-following code forcing a layout pass - disposed the layout the
getter was about to return, so the getter handed back a field the handler had
already cleared and the caller dereferenced null.
- The getter builds the layout, marks the caret dirty and returns. It raises no
events, so nothing invalidates the layout while it is being built.
- EnsureCaretBounds measures the caret against the layout field rather than the
property, so it can neither build a layout nor recurse. A handler invalidating
from there only schedules the next measure pass.
- The measure pass builds the layout once and settles the caret against it, so a
preedit key press builds one layout where it built three.
- A preedit change records the caret position it wants and lets that pass place
it, normalized through the line's caret hit walkers so a position on the seam
of a fallback-font run resolves to a hit the layout can measure.
- The declaration of the layout field now names the five members that own its
lifetime.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Repaint instead of rebuilding the layout to hide the caret
HideCaret disposed the text layout and reshaped the text on the next access,
which is work the caret does not need: it blinks over the text rather than
taking part in it. Anything holding the layout across the call also lost it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
* MacOS: Make sure macOS child window layer is not lower than parent window.
* Add WindowOrder_Owned_Window_Stays_InFront_Of_Topmost_Owner integration test
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Thread.Sleep should be done before the assert in WindowOrder_Modal_Dialog_Stays_InFront_Of_Parent
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Fix CalendarDatePicker.Focus() not focusing the text box
OnGotFocus only forwarded focus to PART_TextBox when the navigation method
was Tab, so a programmatic Focus() call left focus on the picker itself.
Gate on the focus source instead, and keep select-all on Tab only.
* Remove comment from CalendarDatePicker.OnGotFocus
* Handle DataValidationError notifications returned by ConvertBack
A converter returning a BindingNotification with DataValidationError fell
through to the target type converter, which replaced it with a cast error
that stringified the notification. Publish the original error instead.
* Add additional failing tests.
There are more `BindingNotification` cases to handle.
* Handle the other `BindingNotification` cases.
---------
Co-authored-by: grokys <grokys@users.noreply.github.com>
* Added failng popup child margin test
* Ignore popup child margin when positioning
Avoids drop shadows and other out-of-bounds visual effects from affecting popup positioning
* Fix warnings in tests
* Pass Deflate to WSurface
---------
Co-authored-by: Tom Edwards <tom.edwards@chaos.com>
Follow-up to #22082, which added the short-circuit to the property accessor
nodes. The cast nodes still called ValidateNonNullSource, so a cast reported
"Value is null" before the following ?. could suppress it.
Casting null now produces null, as in C#, leaving any error to the member
access that follows.
The binding path parser built type names with ParseIdentifier, which doesn't
accept '+', so a cast like ((local:Outer+Nested)DataContext) stopped parsing at
the '+' and then failed expecting a ')'. Parse type names with a variant that
accepts '+'. Ordinary identifiers are unchanged.