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.
112 lines
3.3 KiB
Go
112 lines
3.3 KiB
Go
// Cthulhu screen reader.
|
|
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package review
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.stormux.org/storm/cthulhu/internal/atspi"
|
|
)
|
|
|
|
// DocumentCaretCommand follows Python Cthulhu's browse caret key families.
|
|
type DocumentCaretCommand uint8
|
|
|
|
const (
|
|
CaretNextCharacter DocumentCaretCommand = iota + 1
|
|
CaretPreviousCharacter
|
|
CaretNextWord
|
|
CaretPreviousWord
|
|
CaretNextLine
|
|
CaretPreviousLine
|
|
CaretLineStart
|
|
CaretLineEnd
|
|
CaretDocumentStart
|
|
CaretDocumentEnd
|
|
CaretReadLine
|
|
TableLeft
|
|
TableRight
|
|
TableUp
|
|
TableDown
|
|
TableFirst
|
|
TableLast
|
|
)
|
|
|
|
func (command DocumentCaretCommand) valid() bool {
|
|
return command >= CaretNextCharacter && command <= TableLast
|
|
}
|
|
|
|
func (command DocumentCaretCommand) String() string {
|
|
names := [...]string{"invalid", "next-character", "previous-character",
|
|
"next-word", "previous-word", "next-line", "previous-line", "line-start",
|
|
"line-end", "document-start", "document-end", "read-line", "table-left",
|
|
"table-right", "table-up", "table-down", "table-first", "table-last"}
|
|
if !command.valid() {
|
|
return names[0]
|
|
}
|
|
return names[command]
|
|
}
|
|
|
|
type DocumentCaretReader interface {
|
|
ReadDocumentCaret(context.Context, atspi.ObjectReference, int, atspi.DocumentCaretUnit) (atspi.DocumentCaretText, error)
|
|
}
|
|
|
|
type DocumentCaretMove struct {
|
|
Position DocumentPosition
|
|
Text string
|
|
RawText string
|
|
Misspelled bool
|
|
// Line retains each object's native range for an assembled visual line.
|
|
Line *atspi.DocumentLine
|
|
TablePrefix, TableSuffix string
|
|
|
|
TableRowHeader, TableColumnHeader string
|
|
|
|
Moved bool
|
|
// Native text range used for this move, in Unicode character offsets.
|
|
Start, End int
|
|
}
|
|
|
|
// MoveCaret advances the independent browse position using AT-SPI text units.
|
|
// It does not depend on Chromium's retained native caret. A stale captured
|
|
// document is reported to the worker for one bounded refresh.
|
|
func (cursor *DocumentCursor) MoveCaret(ctx context.Context, reader DocumentCaretReader, command DocumentCaretCommand) (DocumentCaretMove, error) {
|
|
if !command.valid() || reader == nil {
|
|
return DocumentCaretMove{}, ErrInvalidDirection
|
|
}
|
|
cursor.mu.Lock()
|
|
defer cursor.mu.Unlock()
|
|
if !cursor.active.Valid() || len(cursor.places) == 0 {
|
|
return DocumentCaretMove{}, ErrNoCurrent
|
|
}
|
|
place := &cursor.places[len(cursor.places)-1]
|
|
doc, err := cursor.tree.Document(ctx, place.object)
|
|
if err != nil {
|
|
return DocumentCaretMove{}, err
|
|
}
|
|
if doc.Context.TopLevel != place.document {
|
|
return DocumentCaretMove{}, atspi.ErrStaleObject
|
|
}
|
|
if command >= TableLeft {
|
|
return cursor.moveTable(ctx, doc, place, command)
|
|
}
|
|
place.tableCell = atspi.ObjectID{}
|
|
_, current := caret_node_indices(doc.Nodes, place.object)
|
|
indices := caretNodeRanges(doc.Nodes)
|
|
if current < 0 {
|
|
return DocumentCaretMove{}, atspi.ErrStaleObject
|
|
}
|
|
if len(indices) == 0 {
|
|
return DocumentCaretMove{Position: documentPosition(doc, *place)}, nil
|
|
}
|
|
switch command {
|
|
case CaretNextWord, CaretPreviousWord, CaretNextCharacter, CaretPreviousCharacter:
|
|
return moveCaretText(ctx, reader, doc, place, indices, current,
|
|
command == CaretPreviousWord || command == CaretPreviousCharacter,
|
|
command == CaretNextWord || command == CaretPreviousWord)
|
|
}
|
|
return move_caret_line(ctx, reader, cursor.tree, doc, place, indices, current, command)
|
|
}
|