* Bake FontVariationSettings into Typeface
Typeface is the value every text property funnels into before font
resolution, so variable-font axis values belong on it - same pattern as
weight and stretch, and the only way a single settings value can flow
from a style through layout to the renderer.
- both ctors take an optional FontVariationSettings; Empty is coerced to
null at construction so equality, hashing and cache keys never
distinguish the two "design defaults" spellings
- equality and hash include the settings (structural, cached hash)
- Normalize() and the FormattedText per-run updaters (SetFontFamily /
SetFontWeight / SetFontStyle) carry the settings over when rebuilding
* Apply Typeface.FontVariations during font resolution
FontManager is the single seam every Typeface passes through on its way
to a GlyphTypeface, so the user-space settings are applied there - once,
at the end, whichever resolution path produced the base typeface.
- the resolution body moves to a private TryResolveGlyphTypeface (the
default-family recursions target it directly); the public method
resolves, then binds the variations via GlyphTypeface.WithVariations
- per-variation instances are cached on the resolved typeface, so
repeated lookups with equal settings return the same instance (pinned
by test against the embedded Inter Variable)
- font fallback carries the variations over: the matched fallback family
renders at the same axis values the primary typeface requested, each
font clamping to its own axes (CSS behavior)
* Expose FontVariations as an inherited text property
TextElement.FontVariationsProperty is the user-facing entry point for
variable-font configuration, following the FontStretch pattern exactly:
an inherited attached property that every typeface bake site folds into
the Typeface it constructs.
- attached property on TextElement (inherits) + CLR accessors and
Get/SetFontVariations statics
- AddOwner on TemplatedControl, ContentPresenter and TextBlock
- baked into the typeface at every control bake site: TextBlock,
SelectableTextBlock, TextPresenter, TextBox line-height layouts, and
Inline run properties
- property changes invalidate like the sibling font properties
(TextBlock/TextPresenter shaping group, TextElement inline host)
- XAML attribute strings ("wght=700, wdth=85") convert through the
static Parse the XAML compiler picks up - no TypeConverter needed
(pinned by a Markup.Xaml test)
* Animate FontVariations with CSS interpolation semantics
FontVariationSettings.Interpolate blends two settings the way CSS
font-variation-settings does: per-axis linear interpolation when both
endpoints set exactly the same axes (easing overshoot extrapolates),
discrete switch at the midpoint otherwise. Discrete is the only sound
fallback because a missing axis means "the font''s default", a value that
is not knowable in user space.
- FontVariationSettingsAnimator registered like the other value
animators, so keyframe Animations on FontVariations work out of the box
- FontVariationSettingsTransition for the Transitions collection,
following the TransformOperationsTransition pattern
- interpolation contract pinned at the value level (lerp, order
independence, overshoot, discrete mismatches, null/Empty endpoints)
and at the transition level through a test clock
* Quantize normalized coordinates to the F2Dot14 grid
An animated axis sweeps through arbitrary float user values; without
quantization every frame produced a fresh normalized position and a
fresh clone in the per-source variation cache, growing it without bound
across repeated sweeps.
Snap each coordinate to 1/16384 after avar correction. That is the
resolution the font binary itself stores - gvar, avar and the item
variation stores speak F2Dot14 - so no representable position is lost,
while a swept axis lands on at most 32769 distinct cache entries and
sub-resolution user values collapse to one clone (pinned by tests at the
position and clone-identity level).
* Add failing tests for shaping varied typefaces
A variation clone shares the source's HarfBuzz font, so shaping places
its glyphs at default-instance hmtx advances while GlyphTypeface reports
HVAR-adjusted advances for the same glyphs.
- Shaped advances of a wght=900 Inter Variable clone must equal the
clone's HVAR advances and differ from the default instance
- The default position keeps the source's shaper typeface
- Disposing a clone must leave the source shaper usable
* Shape variation clones with their own HarfBuzz coordinates
Layout advances come from HarfBuzz, but a varied GlyphTypeface shared the
source's hb_font, so text set through FontVariations was placed at
default-instance advances while its metrics and bounds were varied.
- HarfBuzzTypeface.WithVariation returns an instance owning a sub-font of
the source font with the normalized coordinates set in fvar axis order;
the face stays shared and only the sub-font is released on dispose
- The sub-font installs the OpenType font functions itself, since the
inherited parent functions evaluate HVAR at the parent's coordinates
- Bind hb_font_set_var_coords_normalized, which HarfBuzzSharp exports but
does not wrap, under HarfBuzzSharp's library name; map it to the
embedded framework on iOS, tvOS and Mac Catalyst, and fall back to the
default instance if the entry point cannot be resolved
- Let Avalonia.HarfBuzz see Avalonia.Base internals to implement the
internal ITextShaperTypeface members
* Add failing tests for popups with pointer placement not resizing
* Fix popups with pointer placement not resizing when their content grows
The pointer position is now captured once per open and passed with the
position request, so size and offset changes go through the positioner
again without following the current pointer.
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
Every top-level was exposed as a frame, so AT-SPI clients couldn't tell a
popup from a window. A popup root now has the window role, as AT-SPI
defines it for a top-level without a title bar or border. Windows keep
the frame role.
Fixes#22640
Claude-Session: https://claude.ai/code/session_01RUL2vrbjkJecJFTE9gUJnK
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Jumar Macato <16554748+jmacato@users.noreply.github.com>
* Implement IExpandCollapseProvider on TreeViewItemAutomationPeer
A tree item couldn't report whether it was expanded, and couldn't be
expanded or collapsed through accessibility APIs.
Expand and Collapse set IsExpanded, and throw for an item with no
children, as WPF does. ExpandCollapseState is LeafNode when the item has
no children. A change to IsExpanded or to the item count raises a
property-changed event when the state changes.
Fixes#22460
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GK2AhwrPmuRp98cikjR2Sk
* Avoid duplicate expand/collapse notifications on reentrant changes
The Expanded/Collapsed routed events are raised before the peer's
PropertyChanged handler runs, so a handler that populates children
caused an ItemCount notification followed by a second, incorrect
Collapsed -> Expanded notification. Track the last reported state
and compare against it instead of the event's old/new values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Add tests for ComboBox.WrapSelection with no selectable items
* Fix ComboBox.WrapSelection when there is nothing to select
MoveSelection assumed at least one item and that walking by +/-1 always returns to the
start index. An empty list, a list where nothing is selectable, or a single item with no
current selection therefore crashed (modulo by zero / negative index) or spun forever.
Bound the search to one full cycle and normalize wrapped indices before use.
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* test: add failing tests for culture-sensitive class and IterationCount checks
Culture-sensitive comparisons ignore a soft hyphen (U+00AD), so a class
that starts with one followed by ':' is treated as a pseudoclass, and
"Infinite" followed by one still parses as Infinite.
* fix: use ordinal comparisons for pseudoclass checks and IterationCount.Parse
These checks test syntax, so a culture-sensitive comparison gives wrong
answers for ignorable characters and opens an ICU collator on the UI
thread at startup.
* refactor: spell out the ordinal comparison in IterationCount.Parse
The char overload was already ordinal, but no test covers this check,
so say so explicitly, as the EndsWith check above it does.
* Add a test for AutoCompleteBox drop-down items not taking focus
* Keep focus in the text box when an AutoCompleteBox item is picked
* Keep the pointer handler's doc comment with its method
* Simplify comment
* Add test
* Keep the drop-down open while focus is inside it
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add tests for ContentControl automation peer names
* Don't use the content's type name as the automation name
A control's ToString returns its type name. Use the first TextBlock text in the content instead.
* Add keyboard tests for the pickers
* Make the keyboard work inside a picker popup
* Only tab through picker columns that are on screen
Use IsEffectivelyVisible cause a column can be IsVisible while off screen. We don't loop over things that the user cannot see.
* Open a picker popup without claiming the pointer moved focus
* Move the tests to proper place
* Pass the test cancellation token when running dispatcher jobs
* Remove SkiaSharp.props/HarfBuzzSharp.props - instead reference packages directly, with centralized versioning
* Switch to .NET 11 SDK
* Add net11.0-browser target to the Avalonia.Browser
* Remove manual skiasharp NativeFileReference from Avalonia.Browser - since 3.x it's included with the SkiaSharp itself
* Remove dotnet/runtime#109289 workaround
* Fix DetectThreadSupport on .NET 11 WASM
* ControlCatalog: Allow to set `PreferManagedThreadDispatcher` via browser URL arguments
* ControlCatalog: fix value.Normalize crashing on browser
* Fix global.json version syntax. CI task doesn't support * globs.
* Is includePreviewVersions: true necessary in UseDotNet@2 task?
* Use SDK 11.0.100-rc.1
* Disable roll forward?
* Full SDK version
* Install .NET 10 runtime alognside the .NET 11 SDK
* Fix windowsdesktop not being installed on CI
* Try without DOTNET_CLI_ENABLEAOT
* Try to remove .NET 8 runtime and see what fails
* Add AvsSkipBuildingNextTargetFrameworks, to allow disabling .NET 11 TFMs
* Try to cleanup disk space on linux job
* Fix space cleanup script
* Try to skip Nuke bootstrap, as it seems to be confusing new AOT CLI
* More of DOTNET_CLI_ENABLEAOT=false
* Remove DOTNET_CLI_ENABLEAOT=false hack, downgrade to .NET 10 for integration tests on macOS
* Update browser launch config
* Log PreferManagedThreadDispatcher when starting browser ControlCatalog
* Bump to rc2
* Remove dotnet-version: 8.0, as it shouldn't be needed anymore
* Remove ImageSharp added in a merge conflict
* Ignore global.json altogether on integration tests CI
* Missing --test-runner override
* Remove unnoticed SkiaSharp.props reference
* Update outdated build packages readme
* Fix Avalonia.Native.macOS.proj typo
* Temporary disable UseOptimizedPublish globally
* Missing UseOptimizedPublish in a nested directory.build.props
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add failing test for Popup.InheritsTransform Y scale
* Fix Popup.InheritsTransform using the X scale for the Y axis
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* add tabbed page test to check against changing page while focus is owned by content
* tabbed page - do not change page on keyboard nav if focus is owned by content.
* add some details.
* fix typo
* handle tab navigation
- Send one remove per child that leaves, with its old index, before detaching it.
- Send one add per child that arrives, with its new index.
- Stop sending an add that names the parent as its own child.
- Send nothing for nodes whose children no client has read.
- Add unit tests for the child list comparison.
Fixes#22397
Co-authored-by: Renaud Lepage <387759+cybik@users.noreply.github.com>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Expose TextPresenter.CursorRectangle as a public property.
API review for #18325 preferred a readonly CursorRectangle property over
making GetCursorRectangle public. Keep the internal helper as a thin wrapper
and add a unit test covering caret position.
Co-authored-by: Cursor <cursoragent@cursor.com>
* refactor: use CursorRectangle internally
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add tests for focus not closing the CalendarDatePicker drop-down
* Keep the CalendarDatePicker drop-down open when focus returns to it
* Simplify comment
* fix(atspi): expose heading and list metadata
- Map headings to the AT-SPI heading role.
- Expose explicit list positions and sizes.
- Match internal role IDs to the AT-SPI protocol.
- Cover metadata with regression tests.
* fix(atspi): match collection rules on all node attributes
- Build node attributes in one shared AtSpiNode helper.
- Use it for Accessible.GetAttributes and Collection matching.
- Let GetMatches find nodes by level, posinset and setsize.
- Cover collection attribute matching with tests.
---------
Co-authored-by: Jumar Macato <16554748+jmacato@users.noreply.github.com>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>