Files
deedra edd6c560b8 Read Thunderbird message text and preserve link announcements
Thunderbird HTML messages expose readable text on containers around embedded
objects. The browse cursor previously considered only text leaves, and native
document capture omitted heading/link character counts. This skipped message
content, headings and link text. A caret event following Tab could also replace
a complete link announcement with its first character.

Capture owned hypertext child identities and native placeholder offsets on the
GLib thread, releasing native interfaces before returning. Require every child
to occupy one embedded-object character so providers exposing duplicate text
through static descendants retain their ordinary traversal.

Traverse native text ranges before and after embedded children without changing
their offset domains. Preserve character, word, line and document-boundary
navigation; normalize native caret and Braille routing positions at adjacent
embedded links. Keep the Braille cursor on the correct fragment when a parent
contributes text more than once to an assembled line.

Ignore same-input link caret echoes after focus while retaining subsequent
arrow and selection feedback. Add regression tests, extend the private Firefox
fixture, and record behavior and remaining acceptance in the parity ledger.

Validation:
- Full Go test suite with count=1; focused app/atspi/review race checks.
- go vet ./...; reader and brlapi helper builds.
- Private Firefox baseline, mixed-parent offsets and tab navigation.
- Private Chromium fragments, named links, document navigation and selection.
- Parity ledger validation and whitespace checks.

The existing Firefox tab test intermittently timed out on both an untouched
HEAD copy and the changed tree; the final run passed. The unchanged
TestRunReachesSoundStopAfterEarlierServiceStopError also failed once during
startup cancellation and passed in subsequent full-suite and race runs.

Both installed binaries were verified and the reader reloaded in its original
desktop session. The maintainer confirmed readable message text and later
working links after an earlier intermittent omission. That omission remains
untraced; repeat live acceptance and physical Braille verification remain open.
2026-10-20 10:41:38 -07:00

99 lines
4.1 KiB
Go

// Cthulhu screen reader.
// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package app
import (
"time"
"git.stormux.org/storm/cthulhu/internal/atspi"
"git.stormux.org/storm/cthulhu/internal/input"
"git.stormux.org/storm/cthulhu/internal/review"
)
func (handler *accessibilityEventHandler) handleCaret(event atspi.Event, activity input.Activity, intent input.Intent) bool {
state := handler.state
logger := handler.logger
speech := handler.speech
browser := handler.browser
objectReview := handler.objectReview
debounce := handler.debounce
if event.Type == atspi.CaretEvent {
if event.Source.ID() == state.selectionCaretID {
state.selectionCaretID = atspi.ObjectID{}
if activity.Sequence == state.selectionCaretSequence && time.Since(state.selectionCaretAt) < 150*time.Millisecond {
logger.Debug("skipped caret covered by text selection")
return true
}
}
if (event.Source.Autocomplete || activity.Sequence != 0 &&
(event.Source.Role == "spin button" || event.Source.Role == "button" || event.Source.Role == "link")) &&
event.Source.ID() == state.focusCaretID && activity.Sequence == state.focusCaretSequence &&
!activity.Selecting &&
(intent == input.NoIntent || intent == input.OtherIntent) {
// Address bars, spin buttons, and Gecko buttons/links move their
// text caret on focus. With the same input sequence and no
// caret-navigation intent, this must not interrupt the label.
logger.Debug("skipped control caret caused by focus", "role", event.Source.Role)
return true
}
if browser != nil && browser.ready && !event.Source.Editable {
state.current = event.Source
if objectReview != nil {
objectReview.SyncFocus(event.Source.ID())
if err := objectReview.SyncDocumentCaret(event.Source.ID(), event.Detail1); err != nil {
logger.Debug("could not queue native document caret", "error", err)
}
}
}
if browser != nil && browser.ready && !event.Source.Editable && event.Source.TextCaretKnown && event.Source.Role != "password text" {
if state.documentSelection.id != event.Source.ID() {
state.documentSelection.reset(atspi.Snapshot{BusName: event.Source.BusName, Path: event.Source.Path})
}
fragmentLimit := selectionFragmentLimit
if activity.Selecting && intent == input.LineIntent {
fragmentLimit = lineSelectionFragmentLimit
}
if message := state.documentSelection.changedWithLimit(event.Source, fragmentLimit); message != "" {
state.pending.caret.clear()
speech.Enqueue(speechRequest{Text: message, Role: "system", Cause: event.Type})
return true
}
}
// Any newer caret event supersedes an outstanding visual-line
// assembly, even when the new event can use its already-captured
// current-object line.
state.documentLineFocus = atspi.ObjectID{}
state.documentLineRequest = 0
state.documentLineEvent = atspi.Event{}
// Python's default non-layout web mode reads the current object's
// line. A blank browse caret is not a reason to scan the whole
// document; focus mode still assembles visual lines across objects.
if browser != nil && browser.ready && browser.mode == review.FocusMode &&
intent == input.LineIntent && !event.Source.Editable && objectReview != nil {
state.current = event.Source
objectReview.SyncFocus(event.Source.ID())
if request, err := objectReview.ReadDocumentLine(event.Source.ID(), event.Detail1); err == nil {
state.documentLineFocus = event.Source.ID()
state.documentLineRequest = request
state.documentLineEvent = event
logger.Debug("queued document caret line", "role", event.Source.Role)
return true
}
}
if event.Source.Path != "" && event.Source.Path == state.suppressNextCaretPath {
state.suppressNextCaretPath = ""
logger.Debug("skipped caret event already covered by text change", "type", event.Type, "role", event.Source.Role)
return true
}
// Keep a short coalescing window for selection/focus events without
// adding the terminal focus delay to every caret movement.
state.pending.caret.schedule(event, intent, min(debounce, 20*time.Millisecond))
return true
}
return false
}