Reset() made the AvaloniaView first responder before SetClient handed it to the next text box. AvaloniaView is not a text input, so UIKit dismissed the keyboard and presented it again on every focus change between text boxes.
Reset() is now a no-op, as on Android. The input method manager always calls SetClient right after it, which makes the next text box's responder first responder directly. When focus leaves text input, SetClient(null) still dismisses the keyboard.
Adds LoggingExtensions.LogToTraceAreaVerbosity and LogToTrace/LogToDelegate overloads that take it, so each log area can have its own minimum level.
Fixes#21810
* Rotate render target output in the compositor
Expose the required surface orientation through render target properties and rotate retained-layer copies and overlays. Replace the DRM rotation framebuffer and shaders with the shared EGL render target.
Validate quarter-turn output, orientation changes and rotated overlays with Mesa render tests.
* Rename RequiredRotationForOrientation
---------
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Add failing tests for dispatcher timers on the wrong clock
* Align Dispatcher to the platform clock with an offset
`Dispatcher` stamped due times with a clock fixed in its constructor, but
the platform layer reads them against its own. When the platform layer
is installed after construction, such as in `InitializeUIThreadDispatcher`,
those clocks differ and timers fire early or late.
`Now` follows the current platform clock, with an offset that keeps it
continuous across the swap. Due times are converted back to the
platform's clock when handed over.
* 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>
* Browser: fix storage stream writes, seeking and reads
- StreamHelper.write fallback wrote the marshalled ArraySegment instead of the
copied buffer, breaking every save stream when the heap is a SharedArrayBuffer
(WasmEnableThreads). The fast path kept a raw heap view alive across an await,
which could be detached by memory growth. Always slice synchronously and
dispose the view.
- WriteableStream: Position setter seeked to the old position, Seek never
updated _position, and writes past the end never grew Length.
- WriteableStream.WriteAsync(ReadOnlyMemory) avoids ToArray for array-backed memory.
- BlobReadableStream.ReadAsync copies blob data directly into the managed
buffer in one interop call instead of slice -> JS array -> byte[] -> buffer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Blob stream seek is now actually implemented
* OpenWriteAsync opens with "keepExistingData: false", so it's initial length is 0
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: JS-wakeable managed dispatcher for multithreaded WASM
ManagedDispatcherImpl gets a pluggable IWakeupEvent plus BeforeWait/AfterWakeup hooks. The browser MT build backs it with an int32 in linear memory (native/avalonia_browser_dispatcher.c, atomic.wait32/notify) so JS on the main thread can wake the dispatcher thread via MultiThreadedDispatcherHelper.signal without entering managed code.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Update browser launch config
* RawEventGrouper: add DrainAll and keep platform points when merging moves
- Add HasJobs and DrainAll to AutomaticRawEventGrouperDispatchQueue for
inline, synchronous dispatch.
- Dequeue under the lock in DispatchFromQueue; only re-post when jobs remain.
- When merging move events, keep intermediate points the platform already
attached to the merged-in event, and take the newest point with all of
its properties.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: pass input through a queue in WASM memory
Pointer, wheel and key events are encoded by JS into a queue in WASM linear
memory and decoded by C# in one batch per burst, instead of one interop call
per DOM event.
- The queue is a chain of segments. C# allocates the first one and the
control block; JS appends records to the last segment and allocates a new
one with Module._malloc when a record doesn't fit. C# follows the links and
frees segments it has read past. _malloc is added to EmccExportedFunction.
- JS sets wakeRequested in the control block after publishing a tail and
signals the dispatcher if it was clear; C# clears it before reading the
tail, so a record published after the consumer's last read always wakes it.
- Decoded events go through the per-top-level RawEventGrouper on both
runtimes. Pointer moves carry getCoalescedEvents points as intermediate
points, replacing the getCoalescedEvents interop call.
- Single-threaded: JS posts the dispatcher signal, and OnSignaled drains the
queue before running jobs, so a burst costs one macrotask and one managed
entry. Key events and pointer presses are flushed synchronously: the handled
state is known before preventDefault, and actions that need a user gesture
(focusing the text input for the iOS on-screen keyboard) run inside the DOM
handler.
- Multithreaded: JS wakes the dispatcher thread directly through
MultiThreadedDispatcherHelper.signal. BrowserQueueDispatcherInputProvider
drains the queue on every pending-input query, which replaces the
BrowserMultiThreadedDispatcherHooks.
- Composition and drag events bypass the queue and flush it first to keep
ordering.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: use the DOM event clock for text input timestamps
Queued pointer, wheel and key events carry the DOM event.timeStamp, but text
input from composition end used a per-top-level Stopwatch. Pass the
compositionend timeStamp through instead, so all input shares one clock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: convert line and page wheel deltas to pixels
Wheel deltas were passed through as-is and scaled as pixels, so line-mode
wheels barely scrolled. JS now converts line and page deltas to pixels before
queuing, reading the deltas before deltaMode so Firefox keeps reporting pixels
where it can.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: compute MT dispatcher wait timeout from ticks
Convert the timeout with integer ticks instead of a double round-trip, and
treat timeouts too long to express in nanoseconds as an infinite wait.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: generate the input queue layout for JS from C# structs
The queue layout was written twice, as offset constants in BrowserInputQueue.cs
and inputQueue.ts, kept in sync by hand and an ABI version.
- BrowserInputLayout holds the control block, segment header and record
layouts as sequential structs and the enums they use; C# reads records
through them.
- The new Avalonia.Browser.BuildTasks project links BrowserInputLayout.cs and
its GenerateInputLayoutTask writes inputLayout.g.ts before the web app
build: a const enum per struct with field offsets and $size, and a const
enum per enum. It fails the build on implicit padding, so the generated
offsets match the struct layout on any runtime.
- JS writes records through typed-array views over the heap instead of a
DataView.
- JS copies DOM event fields as they are. Mapping buttons and modifier keys,
and converting line and page wheel deltas to pixels, moves to C#, including
for drag events.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Browser: suppress default actions only for input Avalonia handled
Keys and mouse/pen presses are dispatched inside their DOM handler on the
single-threaded runtime, so the handled state is known before the browser
applies the default action. Use it: unhandled keys (browser shortcuts, page
scroll keys) and unhandled mouse/pen presses now reach the browser.
FlushSync reports the handled state of the record just posted rather than
the last event dispatched, which differ when the record produced no event.
Presses are still suppressed while the hidden text input has focus, so the
compatibility mousedown can't take focus away from it, and for touch, which
doesn't report a handled state. Moves and wheel are not flushed and stay
suppressed, as does everything on the multithreaded runtime, where the
handled state isn't known in time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Disable dispatcher warnings where it's expected to block the thread
* New dispatcher hooks should be internal, only used in tests
* Use >>> in TypeScript input queue code to be safe
* Ensure Pack=1 on browser queue interop structures
* Validate browser input record sizes before decoding
Check that each record is large enough for its type, and that coalesced
points and key/code strings fit within the record before reading them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Remove "Count: > 0" check for IntermediatePoints, so we still dispose the pooled list
* Use Dispatcher.UIThread.Post for MT direct input events
* Remove new unused code
* DrainAll method was actually used, IDE fooled me
---------
Co-authored-by: Nikita Tsukanov <keks9n@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
* Add failing test for macOS context menu accessibility role
* Report AutomationMenu as AXMenu on macOS
* Close the context menu with a click in the macOS role test
mac2 on CI only supports pointer actions, so sending Escape via Actions
failed and took the driver down for the remaining tests.
shcore!GetDpiForMonitor returns a 32-bit HRESULT, but the P/Invoke was
declared as returning long. On 32-bit (win-x86) processes a 64-bit return
is marshalled from EDX:EAX; shcore only writes EAX, so the upper half holds
whatever was left in EDX. WindowImpl applies the DPI only when the result
== 0, so the window frequently stayed at RenderScaling 1.0 on >100 %
displays while Screens (which ignores the return value) reported the right
scaling. Reproduces 100 % under Windows 11 on ARM x86 emulation.
Fixes#22418
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
* Keep an iOS main thread display link alive while touches are down
UIKit delivers touches at the rate the main thread is animating at, and the
render timer's display link runs on a background thread, so drags updated at
60 Hz even with a 120 Hz render timer. When the display can go above 60 Hz,
keep one process-wide main thread display link with the same frame rate
range while any view has touches down, and stop it when the last touch ends.
A view forgets its touches in progress when it leaves its window or is
disposed, since UIKit doesn't report their end then, for example when
switching tabs with a finger held down.
* Run iOS trackpad scroll momentum at the display rate with time-based decay
The momentum link decayed the velocity per callback, assuming 60 callbacks
per second, so momentum would end twice as fast at 120 Hz. Give it the
display's frame rate range and decay the velocity by elapsed time, capped at
4 frames after a stall. Behaviour at 60 Hz is unchanged.
* Use the view's screen instead of UIScreen.MainScreen on iOS
UIScreen.MainScreen is deprecated and may not be the screen the app is on
when it runs on an external display. The touch display link now checks the
touched view's screen, and the 60 Hz warning checks the screen of the window
a view moves to. Also shortens the momentum comments.
* 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>
* fix: Support StylableElement for styles inside ContainerQueries
* chore: Add container query sample for TableView columns
Demonstrates a container query that targets a non-visual StyledElement, as requested in the PR review. The option row wraps so that it does not clip while the page is narrowed.
* 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>
Mesa before 24.1 merges the alpha configs of the 32-bit visual into the ones of the 24-bit default visual, so EGL_NATIVE_VISUAL_ID never points at a 32-bit visual and EGL windows can't be transparent.
Claude-Session: https://claude.ai/code/session_018hqMwAPQ1DfZNny7Fo1QB9
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
* test(rendering): cover visuals removed while rendering is stopped
A stopped CompositingRenderer skips its update pass, so nothing drains the
pending visuals. A visual that leaves the tree in that state must not stay
referenced by the renderer. Visuals that remain in the tree must stay queued
until rendering resumes.
The test fails: the renderer still references the removed visuals.
HasPendingUpdateForUnitTests exposes the pending state so that the test does
not depend on garbage collection.
* fix(rendering): release detached visuals from a stopped renderer
A minimized or hidden window stops its renderer. A stopped CompositingRenderer
skips its update pass, and that pass is the only place that clears the dirty
and recalculate-children sets. Each visual that detached in that state stayed
in the sets, so a window that kept changing its content while minimized
retained every removed visual until rendering resumed.
A visual reports itself dirty one last time when it detaches, after it has
dropped its composition visual. The update pass ignores such an entry. Remove
the visual from both sets at that point instead of adding it, and still request
a composition update so that the detach is committed.
Visuals that remain in the tree stay queued, so a restart still resumes the
pending update.
* chore: trim code comments
* 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>
* Let the iOS render timer follow the display refresh rate
CADisplayLink runs at 60 Hz on ProMotion iPhones unless a preferred frame
rate range is set. Request CAFrameRateRange(60, 120, 120); Core Animation
picks the closest supported rate and lowers it in Low Power Mode.
iOSPlatformOptions.EnableHighRefreshRate, on by default, lets apps that can't
sustain high rates keep the system default. iPhone apps also need
CADisableMinimumFrameDurationOnPhone for rates above 60 Hz, so a warning is
logged at startup when it's missing; ControlCatalog.iOS sets it.
* Pause the iOS render timer's display link while the render loop is idle
The link kept waking its thread on every vsync after the render loop cleared
Tick. Pause it while Tick is null or the application is in the background.
CADisplayLink.paused is thread safe, so the state is updated directly, under
a lock, by whichever thread changes it.
* 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.
* Rewrite PointerCanvas page making it more useful and easy to use
(cherry picked from commit aef6fff3965c29d34702db7513b566e289b541de)
* Remove "Clear" button to reduce vertical toolbar space
* 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>