Adopt common v0.8.0 and preserve canceled hardware settings

This commit is contained in:
Storm Dragon committed 2026-11-16 20:10:47 -05:00
1 parent b21fceb311
commit 5dfa038706
410 files changed
+5353 -4803

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ func (worker *Worker) ReadCurrentLine(browse bool, style FlatSpeech) error {
}
}
func (worker *Worker) read_current_line(ctx context.Context, cursor *DocumentCursor, browse bool) Result {
func (worker *Worker) readCurrentLine(ctx context.Context, cursor *DocumentCursor, browse bool) Result {
result := Result{CurrentLine: true, CurrentLineBrowse: browse, DocumentFocus: worker.focus()}
if !result.DocumentFocus.Valid() {
result.Err = ErrNoCurrent
+7 -7
View File
@@ -49,7 +49,7 @@ func TestCurrentLineNativeMissingContextPreservesLocalText(t *testing.T) {
capturer := &currentLineCapturer{content: atspi.DocumentContent{Text: "Local line"}}
worker, _ := NewWorker(capturer, time.Second)
worker.SyncFocus(webID("/entry"))
result := worker.read_current_line(t.Context(), nil, false)
result := worker.readCurrentLine(t.Context(), nil, false)
if result.Err != nil || result.DocumentCaretText != "Local line" || len(result.DocumentCaretContext) != 0 {
t.Fatalf("missing privacy metadata changed local reading: %+v", result)
}
@@ -67,7 +67,7 @@ func TestCurrentLineReadsWholeBrowseLineWithoutMoving(t *testing.T) {
}
}
before := append([]documentPlace(nil), cursor.places...)
result := worker.read_current_line(context.Background(), cursor, true)
result := worker.readCurrentLine(context.Background(), cursor, true)
if result.Err != nil || strings.TrimSpace(result.DocumentCaretText) != "Second café 猫" {
t.Fatalf("whole browse line from middle: %+v", result)
}
@@ -81,7 +81,7 @@ func TestCurrentLineReadsWholeBrowseLineWithoutMoving(t *testing.T) {
}
func TestCurrentLineJoinsBrowseFragmentsWithoutMoving(t *testing.T) {
cursor, reader := fragment_cursor(t, "paragraph")
cursor, reader := fragmentCursor(t, "paragraph")
if _, err := cursor.MoveCaret(context.Background(), reader, CaretNextWord); err != nil {
t.Fatal(err)
}
@@ -91,7 +91,7 @@ func TestCurrentLineJoinsBrowseFragmentsWithoutMoving(t *testing.T) {
worker, _ := NewWorker(source, time.Second)
worker.SyncFocus(webID("/one"))
before := append([]documentPlace(nil), cursor.places...)
result := worker.read_current_line(context.Background(), cursor, true)
result := worker.readCurrentLine(context.Background(), cursor, true)
if result.Err != nil || result.DocumentCaretText != "One two." || !reflect.DeepEqual(cursor.places, before) {
t.Fatalf("fragmented current line: %+v", result)
}
@@ -115,7 +115,7 @@ func TestCurrentLineReadsBrowseControlLabel(t *testing.T) {
}
worker, _ := NewWorker(&readAllCapturer{tree: tree, caretTextReader: caretTextReader{}}, time.Second)
worker.SyncFocus(button.ID())
result := worker.read_current_line(context.Background(), cursor, true)
result := worker.readCurrentLine(context.Background(), cursor, true)
if result.Err != nil || result.DocumentCaretText != "Example button" {
t.Fatalf("browse control label: %+v", result)
}
@@ -129,7 +129,7 @@ func TestCurrentLineUsesRecapturedSourceContext(t *testing.T) {
invalidateTree: cursor.tree, staleAt: 2}
worker, _ := NewWorker(capturer, time.Second)
worker.SyncFocus(webID("/text"))
result := worker.read_current_line(t.Context(), cursor, true)
result := worker.readCurrentLine(t.Context(), cursor, true)
if result.Err != nil || strings.TrimSpace(result.DocumentCaretText) != "First" || capturer.index != 1 {
t.Fatalf("current line did not recover capture: %+v", result)
}
@@ -155,7 +155,7 @@ func TestCurrentLinePreservesLocalTextWithStaleContext(t *testing.T) {
capturer := &currentLineStaleContextCapturer{&readAllCapturer{caretTextReader: text, tree: cursor.tree}}
worker, _ := NewWorker(capturer, time.Second)
worker.SyncFocus(webID("/text"))
result := worker.read_current_line(t.Context(), cursor, true)
result := worker.readCurrentLine(t.Context(), cursor, true)
if result.Err != nil || result.DocumentCaretText != "Local line" || len(result.DocumentCaretContext) != 0 {
t.Fatalf("stale ancestry must leave local reading available without export metadata: %+v", result)
}
+8 -8
View File
@@ -119,10 +119,10 @@ func (cursor *DocumentCursor) rebindPlace(tree *atspi.AccessibleTree, oldPositio
cursor.active = newPosition.Document
}
// capture_anchor returns the saved document identity for a recapture when
// captureAnchor returns the saved document identity for a recapture when
// the page destroyed the focused anchor itself. The anchor only locates the
// document to capture; position recovery still runs against the fresh tree.
func (cursor *DocumentCursor) capture_anchor(focus atspi.ObjectID) (atspi.ObjectID, bool) {
func (cursor *DocumentCursor) captureAnchor(focus atspi.ObjectID) (atspi.ObjectID, bool) {
if cursor == nil {
return atspi.ObjectID{}, false
}
@@ -207,13 +207,13 @@ func (cursor *DocumentCursor) ActivationTarget() (atspi.ObjectReference, error)
}
func (cursor *DocumentCursor) SyncFocus(ctx context.Context, focus atspi.ObjectID) (DocumentPosition, error) {
position, _, err := cursor.sync_focus(ctx, focus)
position, _, err := cursor.syncFocus(ctx, focus)
return position, err
}
// The outcome explains whether focus synchronization retained the reading
// position, recovered a replacement text child, or fell back to native focus.
func (cursor *DocumentCursor) sync_focus(ctx context.Context, focus atspi.ObjectID) (DocumentPosition, string, error) {
func (cursor *DocumentCursor) syncFocus(ctx context.Context, focus atspi.ObjectID) (DocumentPosition, string, error) {
cursor.mu.Lock()
defer cursor.mu.Unlock()
// Failed ownership resolution must never leave web navigation active for
@@ -244,12 +244,12 @@ func (cursor *DocumentCursor) sync_focus(ctx context.Context, focus atspi.Object
recovery = "preserved"
place = saved
place.focus = ref
} else if replacement, kind, ok := replacement_text_node(doc, saved); ok {
} else if replacement, kind, ok := replacementTextNode(doc, saved); ok {
recovery = kind
place = saved
place.focus, place.object = ref, replacement.Reference
place.offset = min(saved.offset, max(0, replacement.Snapshot.CharacterCount-1))
} else if replacement, kind, ok := replacement_child_node(doc, saved); ok {
} else if replacement, kind, ok := replacementChildNode(doc, saved); ok {
recovery = kind
place = saved
place.focus, place.object = ref, replacement.Reference
@@ -278,7 +278,7 @@ func (cursor *DocumentCursor) sync_focus(ctx context.Context, focus atspi.Object
if removeIndex >= 0 {
cursor.places = append(cursor.places[:removeIndex], cursor.places[removeIndex+1:]...)
}
remember_text_parent(doc, &place)
rememberTextParent(doc, &place)
if len(cursor.places) == 16 {
cursor.places = cursor.places[1:]
}
@@ -423,7 +423,7 @@ func (cursor *DocumentCursor) Move(ctx context.Context, target DocumentTarget, l
}
place.tableCell = atspi.ObjectID{}
place.object, place.origin, place.offset = doc.Nodes[targetIndex].Reference, StructuralNavigation, 0
remember_text_parent(doc, place)
rememberTextParent(doc, place)
return DocumentMoveResult{Position: documentPosition(doc, *place), Moved: true, Wrapped: wrapped}, nil
}
step := 1
+7 -7
View File
@@ -19,7 +19,7 @@ import (
func BenchmarkDocumentWorkerHeadingNavigation(b *testing.B) {
for _, contentNodes := range []int{100, 1000, 10000} {
b.Run(fmt.Sprintf("nodes-%d", contentNodes), func(b *testing.B) {
tree, ids := benchmark_document_tree(b, contentNodes)
tree, ids := benchmarkDocumentTree(b, contentNodes)
cursor, err := NewDocumentCursor(tree)
if err != nil {
b.Fatal(err)
@@ -55,7 +55,7 @@ func BenchmarkDocumentWorkerHeadingNavigation(b *testing.B) {
func BenchmarkDocumentCaretNavigation(b *testing.B) {
for _, contentNodes := range []int{100, 1000, 10000} {
b.Run(fmt.Sprintf("nodes-%d", contentNodes), func(b *testing.B) {
tree, ids := benchmark_document_tree(b, contentNodes)
tree, ids := benchmarkDocumentTree(b, contentNodes)
cursor, err := NewDocumentCursor(tree)
if err != nil {
b.Fatal(err)
@@ -89,10 +89,10 @@ func BenchmarkDocumentCaretNavigation(b *testing.B) {
}
}
// benchmark_document_tree models an already captured page, not native AT-SPI
// benchmarkDocumentTree models an already captured page, not native AT-SPI
// capture. Each section has twenty content objects: a heading, a link, and
// ordinary text. Pairs of objects share a visual row, including Unicode text.
func benchmark_document_tree(b *testing.B, contentNodes int) (*atspi.AccessibleTree, []atspi.ObjectID) {
func benchmarkDocumentTree(b *testing.B, contentNodes int) (*atspi.AccessibleTree, []atspi.ObjectID) {
b.Helper()
rootID := webID("/benchmark/document")
root := atspi.NewSnapshot(rootID.Path, "Benchmark page", "document web", "", "")
@@ -144,7 +144,7 @@ func benchmark_document_tree(b *testing.B, contentNodes int) (*atspi.AccessibleT
func BenchmarkDocumentSnapshot(b *testing.B) {
for _, contentNodes := range []int{100, 1000, 10000} {
b.Run(fmt.Sprintf("nodes-%d", contentNodes), func(b *testing.B) {
tree, _ := benchmark_document_tree(b, contentNodes)
tree, _ := benchmarkDocumentTree(b, contentNodes)
root, err := tree.Root()
if err != nil {
b.Fatal(err)
@@ -166,7 +166,7 @@ func BenchmarkDocumentHeadingNavigation(b *testing.B) {
for _, contentNodes := range []int{100, 1000, 10000} {
for _, scenario := range []string{"adjacent", "wrap"} {
b.Run(fmt.Sprintf("nodes-%d/%s", contentNodes, scenario), func(b *testing.B) {
tree, contentIDs := benchmark_document_tree(b, contentNodes)
tree, contentIDs := benchmarkDocumentTree(b, contentNodes)
cursor, err := NewDocumentCursor(tree)
if err != nil {
b.Fatal(err)
@@ -202,7 +202,7 @@ func BenchmarkDocumentHeadingNavigation(b *testing.B) {
func BenchmarkDocumentLineAssembly(b *testing.B) {
for _, contentNodes := range []int{100, 1000, 10000} {
b.Run(fmt.Sprintf("nodes-%d", contentNodes), func(b *testing.B) {
tree, contentIDs := benchmark_document_tree(b, contentNodes)
tree, contentIDs := benchmarkDocumentTree(b, contentNodes)
middle := contentNodes / 2
reference, err := tree.Reference(contentIDs[middle])
if err != nil {
+5 -5
View File
@@ -35,7 +35,7 @@ func (worker *Worker) RouteDocumentBraille(ctx context.Context, epoch uint64, fo
}
}
func (worker *Worker) route_document_braille(ctx context.Context, cursor *DocumentCursor, request request) (result Result) {
func (worker *Worker) routeDocumentBraille(ctx context.Context, cursor *DocumentCursor, request request) (result Result) {
route := request.brailleRoute
result = Result{DocumentBrailleRoute: true, DocumentCaretCommand: CaretReadLine, DocumentFocus: route.focus, DocumentEpoch: request.documentEpoch}
defer func() { route.done <- result.Err }()
@@ -77,7 +77,7 @@ func (worker *Worker) route_document_braille(ctx context.Context, cursor *Docume
result.Err = err
return
}
node, caretOffset, err := native_caret_node(ctx, reader, doc, route.target, route.offset)
node, caretOffset, err := nativeCaretNode(ctx, reader, doc, route.target, route.offset)
if err != nil {
result.Err = err
return
@@ -103,7 +103,7 @@ func (worker *Worker) route_document_braille(ctx context.Context, cursor *Docume
place := &cursor.places[len(cursor.places)-1]
place.object, place.offset, place.origin = node.Reference, caretOffset, CaretNavigation
place.tableCell = atspi.ObjectID{}
remember_text_parent(doc, place)
rememberTextParent(doc, place)
snapshot, err := cursor.tree.Resolve(node.Reference)
result.DocumentPosition = DocumentPosition{Document: owner.TopLevel, Object: node.Reference, Snapshot: snapshot, Offset: caretOffset, Origin: CaretNavigation}
cursor.mu.Unlock()
@@ -123,9 +123,9 @@ func (worker *Worker) route_document_braille(ctx context.Context, cursor *Docume
}
}
if position >= 0 {
parts, err := collect_visual_line(deadline, reader, doc, indices, visual_line_owners(doc.Nodes), position, caretOffset, true)
parts, err := collectVisualLine(deadline, reader, doc, indices, visualLineOwners(doc.Nodes), position, caretOffset, true)
if err == nil && len(parts) > 1 {
line, _, _ := assemble_visual_line(cursor.tree, doc, parts)
line, _, _ := assembleVisualLine(cursor.tree, doc, parts)
result.DocumentCaretLine = &line
}
}
+5 -5
View File
@@ -115,8 +115,8 @@ func (cursor *DocumentCursor) MoveCaret(ctx context.Context, reader DocumentCare
if !doc.SameContent(cursor.caretDocument) {
cursor.caretDocument = doc
cursor.caretRanges = caretNodeRanges(doc.Nodes)
cursor.caretLookup = new_caret_range_lookup(cursor.caretRanges, len(doc.Nodes))
cursor.lineOwners = visual_line_owners(doc.Nodes)
cursor.caretLookup = newCaretRangeLookup(cursor.caretRanges, len(doc.Nodes))
cursor.lineOwners = visualLineOwners(doc.Nodes)
}
indices := cursor.caretRanges
if len(indices) == 0 {
@@ -137,7 +137,7 @@ func (cursor *DocumentCursor) MoveCaret(ctx context.Context, reader DocumentCare
command == CaretPreviousWord || command == CaretPreviousCharacter,
command == CaretNextWord || command == CaretPreviousWord)
default:
movement, err = move_caret_line(ctx, reader, cursor.tree, doc, place, indices, cursor.caretLookup, current, command, cursor.lineOwners)
movement, err = moveCaretLine(ctx, reader, cursor.tree, doc, place, indices, cursor.caretLookup, current, command, cursor.lineOwners)
}
if err == nil && movement.Moved {
target, found := doc.Index(place.object.ID())
@@ -148,12 +148,12 @@ func (cursor *DocumentCursor) MoveCaret(ctx context.Context, reader DocumentCare
// removes its ancestor immediately afterwards. Repeating that move
// during recovery would skip the line. Synthetic whole-object stops
// still need validation because they bypass the native text reader.
if !navigationReader.did_read(place.object) {
if !navigationReader.didRead(place.object) {
if err := cursor.tree.ValidateDocumentCaretRange(ctx, doc, current, target); err != nil {
return DocumentCaretMove{}, err
}
}
remember_text_parent(doc, place)
rememberTextParent(doc, place)
*saved = next
} else if err == nil {
// Reaching a boundary must not silently skip newly readable text in a
@@ -14,7 +14,7 @@ import (
"git.stormux.org/storm/cthulhu/internal/atspi"
)
func editable_caret_cursor(t *testing.T) (*DocumentCursor, caretTextReader) {
func editableCaretCursor(t *testing.T) (*DocumentCursor, caretTextReader) {
t.Helper()
reader := caretTextReader{
webID("/before"): "Suggested wording",
@@ -63,7 +63,7 @@ func editable_caret_cursor(t *testing.T) (*DocumentCursor, caretTextReader) {
func TestDocumentCaretReadsEditableDescendants(t *testing.T) {
ctx := context.Background()
cursor, reader := editable_caret_cursor(t)
cursor, reader := editableCaretCursor(t)
for _, step := range []struct {
command DocumentCaretCommand
want string
@@ -89,7 +89,7 @@ func TestDocumentCaretReadsEditableDescendants(t *testing.T) {
}
func TestReadAllIncludesEditableDescendants(t *testing.T) {
cursor, reader := editable_caret_cursor(t)
cursor, reader := editableCaretCursor(t)
capturer := &readAllCapturer{tree: cursor.tree, caretTextReader: reader}
worker, err := NewWorker(capturer, time.Second)
if err != nil {
+5 -5
View File
@@ -13,7 +13,7 @@ import (
"git.stormux.org/storm/cthulhu/internal/atspi"
)
func glyph_cursor(t *testing.T, parentRole string, modify func(*atspi.Snapshot)) (*DocumentCursor, caretTextReader) {
func glyphCursor(t *testing.T, parentRole string, modify func(*atspi.Snapshot)) (*DocumentCursor, caretTextReader) {
t.Helper()
reader := caretTextReader{webID("/before"): "Member", webID("/icon"): "\uf005", webID("/after"): "Join Date"}
node := func(path, role string, children ...string) atspi.TreeNode {
@@ -57,7 +57,7 @@ func TestDocumentCaretSkipsDecorativeGlyph(t *testing.T) {
ctx := context.Background()
for _, command := range []DocumentCaretCommand{CaretNextLine, CaretNextCharacter, CaretNextWord} {
t.Run(command.String(), func(t *testing.T) {
cursor, reader := glyph_cursor(t, "section", nil)
cursor, reader := glyphCursor(t, "section", nil)
if command != CaretNextLine {
cursor.places[0].offset = len("Member") - 1
}
@@ -74,7 +74,7 @@ func TestDocumentCaretSkipsDecorativeGlyph(t *testing.T) {
// Focus/routing may leave the cursor on an omitted icon. Both directions
// must still reach surrounding text rather than report a stale position.
for _, command := range []DocumentCaretCommand{CaretNextLine, CaretPreviousLine} {
cursor, reader := glyph_cursor(t, "section", nil)
cursor, reader := glyphCursor(t, "section", nil)
if _, err := cursor.SyncFocus(ctx, webID("/icon")); err != nil {
t.Fatal(err)
}
@@ -108,7 +108,7 @@ func TestDocumentCaretPreservesMeaningfulGlyphs(t *testing.T) {
{"different text", "section", func(s *atspi.Snapshot) { s.Text = "X" }},
} {
t.Run(test.name, func(t *testing.T) {
cursor, reader := glyph_cursor(t, test.parentRole, test.modify)
cursor, reader := glyphCursor(t, test.parentRole, test.modify)
move, err := cursor.MoveCaret(context.Background(), reader, CaretNextLine)
if err != nil || !move.Moved || move.Position.Object.ID() != webID("/icon") {
t.Fatalf("meaningful glyph omitted: %+v, %v", move, err)
@@ -118,7 +118,7 @@ func TestDocumentCaretPreservesMeaningfulGlyphs(t *testing.T) {
}
func TestReadAllSkipsDecorativeGlyph(t *testing.T) {
cursor, reader := glyph_cursor(t, "section", nil)
cursor, reader := glyphCursor(t, "section", nil)
capturer := &readAllCapturer{tree: cursor.tree, caretTextReader: reader}
worker, err := NewWorker(capturer, time.Second)
if err != nil {
+5 -5
View File
@@ -13,9 +13,9 @@ import (
"git.stormux.org/storm/cthulhu/internal/atspi"
)
// move_caret_line handles line and document boundaries under the cursor lock
// moveCaretLine handles line and document boundaries under the cursor lock
// held by MoveCaret. Text-unit movement has its separate traversal helper.
func move_caret_object_line(ctx context.Context, reader DocumentCaretReader, doc atspi.DocumentSnapshot, place *documentPlace, indices []caretRange, lookup *caretRangeLookup, current int, command DocumentCaretCommand) (DocumentCaretMove, error) {
func moveCaretObjectLine(ctx context.Context, reader DocumentCaretReader, doc atspi.DocumentSnapshot, place *documentPlace, indices []caretRange, lookup *caretRangeLookup, current int, command DocumentCaretCommand) (DocumentCaretMove, error) {
unit := atspi.DocumentCaretLine
if command == CaretReadLine {
unit = atspi.DocumentCaretLineRemainder
@@ -64,12 +64,12 @@ func move_caret_object_line(ctx context.Context, reader DocumentCaretReader, doc
continue
}
node := doc.Nodes[indices[position].index]
if named_link_label(node.Snapshot) != "" && (command == CaretLineStart || command == CaretLineEnd) {
if namedLinkLabel(node.Snapshot) != "" && (command == CaretLineStart || command == CaretLineEnd) {
offset = 0
if command == CaretLineEnd {
offset = caret_text_count(node.Snapshot) - 1
offset = caretTextCount(node.Snapshot) - 1
}
character, err := read_caret_text(ctx, reader, node, offset, atspi.DocumentCaretCharacter)
character, err := readCaretText(ctx, reader, node, offset, atspi.DocumentCaretCharacter)
if err != nil {
return DocumentCaretMove{}, err
}
+6 -6
View File
@@ -42,13 +42,13 @@ func wholeCaretControl(snapshot atspi.Snapshot) bool {
// caret placement moves focus away. Entering their text can strand navigation
// on a removed object and repeatedly recover to the owner's container. Match
// Orca's web caret policy while retaining focusable/editable tooltip content.
func passive_caret_tooltip(snapshot atspi.Snapshot) bool {
func passiveCaretTooltip(snapshot atspi.Snapshot) bool {
return snapshot.Role == "tool tip" && !snapshot.Focusable && !snapshot.Editable
}
// caret_node_indices preserves provider order and treats whole controls as one
// caretNodeIndices preserves provider order and treats whole controls as one
// stop. MoveCaret holds the document cursor lock while using these indices.
func caret_node_indices(nodes []atspi.DocumentNode, object atspi.ObjectReference) ([]int, int, map[atspi.ObjectID]bool) {
func caretNodeIndices(nodes []atspi.DocumentNode, object atspi.ObjectReference) ([]int, int, map[atspi.ObjectID]bool) {
// Container text normally embeds its child text. Whole controls are one
// caret stop even when their label is a child or they have no text interface.
// Python's web _treatObjectAsWhole makes the same distinction.
@@ -104,11 +104,11 @@ func caret_node_indices(nodes []atspi.DocumentNode, object atspi.ObjectReference
if node.Hidden || skipped[node.Reference.ID()] {
continue
}
if snapshot.Role == "password text" || passive_caret_tooltip(snapshot) {
if snapshot.Role == "password text" || passiveCaretTooltip(snapshot) {
skipChildren(node.Children)
continue
}
if !protected[node.Reference.ID()] && decorative_caret_glyph(node) {
if !protected[node.Reference.ID()] && decorativeCaretGlyph(node) {
continue
}
if wholeCaretNode(node.Snapshot) {
@@ -133,7 +133,7 @@ func caret_node_indices(nodes []atspi.DocumentNode, object atspi.ObjectReference
// Python's web hasValidName/isUselessEmptyElement rejects standalone unnamed
// private-use icons. Keep this narrower: only a known non-interactive static
// leaf with one matching name/text character is omitted from browse reading.
func decorative_caret_glyph(node atspi.DocumentNode) bool {
func decorativeCaretGlyph(node atspi.DocumentNode) bool {
snapshot := node.Snapshot
if snapshot.Role != "static" || !snapshot.StatesKnown || snapshot.Focusable ||
snapshot.Editable || node.ParentEditable || snapshot.SupportsClick || snapshot.ExplicitName ||
+6 -6
View File
@@ -18,7 +18,7 @@ import (
type caretRange struct{ index, start, end int }
func caretNodeRanges(nodes []atspi.DocumentNode) []caretRange {
indices, _, expanded := caret_node_indices(nodes, atspi.ObjectReference{})
indices, _, expanded := caretNodeIndices(nodes, atspi.ObjectReference{})
eligible := make(map[int]bool, len(indices))
byID := make(map[atspi.ObjectID]int, len(nodes))
for _, index := range indices {
@@ -31,7 +31,7 @@ func caretNodeRanges(nodes []atspi.DocumentNode) []caretRange {
var visit func(int)
visit = func(index int) {
node := nodes[index]
if node.Hidden || node.Snapshot.Role == "password text" || passive_caret_tooltip(node.Snapshot) {
if node.Hidden || node.Snapshot.Role == "password text" || passiveCaretTooltip(node.Snapshot) {
return
}
children := node.Snapshot.TextChildren
@@ -73,7 +73,7 @@ func caretNodeRanges(nodes []atspi.DocumentNode) []caretRange {
return
}
if eligible[index] {
result = append(result, caretRange{index, 0, caret_text_count(node.Snapshot)})
result = append(result, caretRange{index, 0, caretTextCount(node.Snapshot)})
if wholeCaretNode(node.Snapshot) && !expanded[node.Reference.ID()] {
return
}
@@ -98,7 +98,7 @@ type caretRangeLookup struct {
after []int
}
func new_caret_range_lookup(ranges []caretRange, nodeCount int) *caretRangeLookup {
func newCaretRangeLookup(ranges []caretRange, nodeCount int) *caretRangeLookup {
lookup := &caretRangeLookup{objects: make([][]int, nodeCount), after: make([]int, nodeCount)}
for position, item := range ranges {
lookup.objects[item.index] = append(lookup.objects[item.index], position)
@@ -139,11 +139,11 @@ func (lookup *caretRangeLookup) position(ranges []caretRange, current, offset in
func readCaretRange(ctx context.Context, reader DocumentCaretReader, doc atspi.DocumentSnapshot, item caretRange, offset int, unit atspi.DocumentCaretUnit) (atspi.DocumentCaretText, error) {
offset = max(item.start, min(offset, item.end-1))
node := doc.Nodes[item.index]
text, err := read_caret_text(ctx, reader, node, offset, unit)
text, err := readCaretText(ctx, reader, node, offset, unit)
if err != nil || text.End <= text.Start {
return text, err
}
if item.start == 0 && item.end == caret_text_count(node.Snapshot) {
if item.start == 0 && item.end == caretTextCount(node.Snapshot) {
return text, nil
}
if text.Start < 0 || text.Start > offset || text.End <= offset || text.End > text.CharacterCount {
+4 -4
View File
@@ -39,7 +39,7 @@ func moveCaretText(ctx context.Context, reader DocumentCaretReader, doc atspi.Do
return DocumentCaretMove{}, err
}
node := doc.Nodes[indices[position].index]
if caret_text_count(node.Snapshot) == 0 || wholeCaretNode(node.Snapshot) && named_link_label(node.Snapshot) == "" {
if caretTextCount(node.Snapshot) == 0 || wholeCaretNode(node.Snapshot) && namedLinkLabel(node.Snapshot) == "" {
if node.Reference != place.object {
place.object, place.offset, place.origin = node.Reference, 0, CaretNavigation
return DocumentCaretMove{Position: documentPosition(doc, *place), Moved: true}, nil
@@ -62,8 +62,8 @@ func moveCaretText(ctx context.Context, reader DocumentCaretReader, doc atspi.Do
if err == nil && character.End > character.Start {
value, _ := utf8.DecodeRuneInString(character.Text)
if character.Text == "" || byWord && unicode.IsSpace(value) || value == '\ufffc' || value == '\ufeff' {
if blocks, ok := reader.(DocumentCharacterReader); byWord && unicode.IsSpace(value) && ok && named_link_label(node.Snapshot) == "" {
nextOffset, err := skip_word_spaces(ctx, blocks, node.Reference, indices[position], offset, step)
if blocks, ok := reader.(DocumentCharacterReader); byWord && unicode.IsSpace(value) && ok && namedLinkLabel(node.Snapshot) == "" {
nextOffset, err := skipWordSpaces(ctx, blocks, node.Reference, indices[position], offset, step)
if err != nil {
return DocumentCaretMove{}, err
}
@@ -123,7 +123,7 @@ func moveCaretText(ctx context.Context, reader DocumentCaretReader, doc atspi.Do
// Keep native Unicode offsets and stop at embedded-object range boundaries.
// A broken optional block cannot advance the cursor; ordinary unit reads then
// retain their existing provider-error handling.
func skip_word_spaces(ctx context.Context, reader DocumentCharacterReader, object atspi.ObjectReference, item caretRange, offset, step int) (int, error) {
func skipWordSpaces(ctx context.Context, reader DocumentCharacterReader, object atspi.ObjectReference, item caretRange, offset, step int) (int, error) {
block, err := reader.ReadDocumentCharacters(ctx, object, offset)
if err != nil {
return offset, err
+3 -3
View File
@@ -35,7 +35,7 @@ type DocumentState struct {
Active bool `json:"active"`
}
func (cursor *DocumentCursor) diagnostic_state() DocumentState {
func (cursor *DocumentCursor) diagnosticState() DocumentState {
if cursor == nil {
return DocumentState{}
}
@@ -57,8 +57,8 @@ func (cursor *DocumentCursor) diagnostic_state() DocumentState {
Origin: origin, Active: cursor.active == place.document}
}
func (result *Result) record_document_attempt(cursor *DocumentCursor, attempt DocumentAttempt, err error) {
attempt.After = cursor.diagnostic_state()
func (result *Result) recordDocumentAttempt(cursor *DocumentCursor, attempt DocumentAttempt, err error) {
attempt.After = cursor.diagnosticState()
if err != nil {
attempt.Error = err.Error()
}
@@ -14,7 +14,7 @@ import (
"git.stormux.org/storm/cthulhu/internal/atspi"
)
func inline_replacement_cursor(t *testing.T, role string, slot int) (*DocumentCursor, caretTextReader, []atspi.TreeNode) {
func inlineReplacementCursor(t *testing.T, role string, slot int) (*DocumentCursor, caretTextReader, []atspi.TreeNode) {
t.Helper()
reader := caretTextReader{webID("/before"): "Published", webID("/old"): "↺ by Publisher", webID("/after"): "Article continues"}
paths := []string{"/before", "/after"}
@@ -57,7 +57,7 @@ func TestDocumentCaretRecoversReplacedInlineText(t *testing.T) {
for _, role := range []string{"paragraph", "heading", "section", "link"} {
for slot := 0; slot < 3; slot++ {
t.Run(fmt.Sprintf("%s/%d", role, slot), func(t *testing.T) {
cursor, reader, nodes := inline_replacement_cursor(t, role, slot)
cursor, reader, nodes := inlineReplacementCursor(t, role, slot)
ctx := context.Background()
for generation := 0; generation < 4; generation++ {
path := fmt.Sprintf("/replacement%d", generation)
@@ -67,7 +67,7 @@ func TestDocumentCaretRecoversReplacedInlineText(t *testing.T) {
if err := cursor.tree.Replace(webID("/doc"), nodes); err != nil {
t.Fatal(err)
}
position, recovery, err := cursor.sync_focus(ctx, webID("/paragraph"))
position, recovery, err := cursor.syncFocus(ctx, webID("/paragraph"))
if err != nil || recovery != "replaced-text-child" || position.Object.ID() != webID(path) {
t.Fatalf("replacement %d: %+v, %s, %v", generation, position, recovery, err)
}
@@ -100,7 +100,7 @@ func TestDocumentCaretRecoversReplacedInlineText(t *testing.T) {
func TestDocumentLinkReplacementPreservesActivationOwnership(t *testing.T) {
for _, kind := range []string{"same link", "replaced link", "named link", "editable link"} {
t.Run(kind, func(t *testing.T) {
cursor, _, nodes := inline_replacement_cursor(t, "link", 1)
cursor, _, nodes := inlineReplacementCursor(t, "link", 1)
ctx := context.Background()
originalTarget, err := cursor.ActivationTarget()
if err != nil || originalTarget.ID() != webID("/paragraph") {
@@ -122,7 +122,7 @@ func TestDocumentLinkReplacementPreservesActivationOwnership(t *testing.T) {
if _, err := cursor.syncActionFocus(ctx, webID("/paragraph")); err == nil {
t.Fatal("activation silently recovered a missing text target")
}
position, recovery, err := cursor.sync_focus(ctx, webID("/paragraph"))
position, recovery, err := cursor.syncFocus(ctx, webID("/paragraph"))
if err != nil {
t.Fatal(err)
}
@@ -141,7 +141,7 @@ func TestDocumentLinkReplacementPreservesActivationOwnership(t *testing.T) {
}
func TestReadAllAfterInlineReplacementRecovery(t *testing.T) {
cursor, reader, nodes := inline_replacement_cursor(t, "paragraph", 1)
cursor, reader, nodes := inlineReplacementCursor(t, "paragraph", 1)
nodes[1].Children[1] = webID("/new")
nodes[3].Snapshot.Path = "/new"
reader[webID("/new")] = reader[webID("/old")]
@@ -164,7 +164,7 @@ func TestReadAllAfterInlineReplacementRecovery(t *testing.T) {
func TestReadAllRecoveryRejectsReplacedDocument(t *testing.T) {
for _, refresh := range []bool{false, true} {
t.Run(fmt.Sprint(refresh), func(t *testing.T) {
cursor, reader, nodes := inline_replacement_cursor(t, "link", 1)
cursor, reader, nodes := inlineReplacementCursor(t, "link", 1)
cursor.tree.Invalidate(webID("/doc"))
if err := cursor.tree.Replace(webID("/doc"), nodes); err != nil {
t.Fatal(err)
@@ -172,7 +172,7 @@ func TestReadAllRecoveryRejectsReplacedDocument(t *testing.T) {
worker, _ := NewWorker(&readAllCapturer{tree: cursor.tree, caretTextReader: reader}, time.Second)
worker.SyncFocus(webID("/paragraph"))
if refresh {
if _, err := worker.refresh_read_all_cursor(context.Background(), cursor, webID("/paragraph")); err == nil {
if _, err := worker.refreshReadAllCursor(context.Background(), cursor, webID("/paragraph")); err == nil {
t.Fatal("Read All refresh crossed a document generation")
}
return
@@ -188,7 +188,7 @@ func TestReadAllRecoveryRejectsReplacedDocument(t *testing.T) {
func TestDocumentInlineReplacementRetainsAndClampsUnicodeOffset(t *testing.T) {
for _, replacement := range []string{"↺ by Another publisher", "↺"} {
t.Run(replacement, func(t *testing.T) {
cursor, reader, nodes := inline_replacement_cursor(t, "paragraph", 1)
cursor, reader, nodes := inlineReplacementCursor(t, "paragraph", 1)
ctx := context.Background()
move, err := cursor.MoveCaret(ctx, reader, CaretNextWord)
if err != nil || move.Position.Offset != 4 {
@@ -201,7 +201,7 @@ func TestDocumentInlineReplacementRetainsAndClampsUnicodeOffset(t *testing.T) {
if err := cursor.tree.Replace(webID("/doc"), nodes); err != nil {
t.Fatal(err)
}
position, recovery, err := cursor.sync_focus(ctx, webID("/paragraph"))
position, recovery, err := cursor.syncFocus(ctx, webID("/paragraph"))
wantOffset := min(move.Position.Offset, utf8.RuneCountInString(replacement)-1)
if err != nil || recovery != "replaced-text-child" || position.Offset != wantOffset {
t.Fatalf("replacement: offset=%d want=%d recovery=%s err=%v", position.Offset, wantOffset, recovery, err)
@@ -215,7 +215,7 @@ func TestDocumentInlineReplacementRejectsAmbiguousOrInteractiveChanges(t *testin
"replaced parent", "replaced document", "hidden parent", "editable parent", "clickable parent", "focusable parent",
"hidden child", "editable child", "clickable child", "focusable child", "named child", "password child", "native origin"} {
t.Run(kind, func(t *testing.T) {
cursor, reader, nodes := inline_replacement_cursor(t, "paragraph", 1)
cursor, reader, nodes := inlineReplacementCursor(t, "paragraph", 1)
nodes[1].Children[1] = webID("/new")
nodes[3].Snapshot.Path = "/new"
reader[webID("/new")] = reader[webID("/old")]
@@ -260,7 +260,7 @@ func TestDocumentInlineReplacementRejectsAmbiguousOrInteractiveChanges(t *testin
if err := cursor.tree.Replace(webID("/doc"), nodes); err != nil {
t.Fatal(err)
}
position, recovery, err := cursor.sync_focus(context.Background(), webID("/paragraph"))
position, recovery, err := cursor.syncFocus(context.Background(), webID("/paragraph"))
if err != nil || recovery == "replaced-text-child" || position.Object.ID() == webID("/new") {
t.Fatalf("unsafe replacement accepted: object=%+v recovery=%s err=%v", position.Object.ID(), recovery, err)
}
+1 -1
View File
@@ -259,7 +259,7 @@ func (worker *Worker) selectDocumentList(ctx context.Context, cursor *DocumentCu
place := &cursor.places[len(cursor.places)-1]
place.object, place.offset, place.origin = position.Object, 0, StructuralNavigation
place.tableCell = atspi.ObjectID{}
remember_text_parent(doc, place)
rememberTextParent(doc, place)
result.DocumentPosition = documentPosition(doc, *place)
cursor.mu.Unlock()
result.Moved = true
+2 -2
View File
@@ -22,12 +22,12 @@ func TestDocumentListPreservesCursorAndSelectsExactTarget(t *testing.T) {
capturer := &readAllCapturer{tree: tree}
worker, _ := NewWorker(capturer, time.Second)
worker.SyncFocus(webID("/doc"))
before := cursor.diagnostic_state()
before := cursor.diagnosticState()
list, err := worker.listDocument(ctx, cursor, &documentListRequest{ctx: ctx, target: DocumentHeading})
if err != nil || len(list.Entries) != 2 {
t.Fatalf("heading list: %+v %v", list, err)
}
if after := cursor.diagnostic_state(); after != before {
if after := cursor.diagnosticState(); after != before {
t.Fatalf("opening moved cursor: %+v -> %+v", before, after)
}
result, cursor := worker.selectDocumentList(ctx, cursor, &documentListSelection{list: list, index: 1})
+5 -5
View File
@@ -13,15 +13,15 @@ import (
"git.stormux.org/storm/cthulhu/internal/atspi"
)
func named_link_label(snapshot atspi.Snapshot) string {
func namedLinkLabel(snapshot atspi.Snapshot) string {
if snapshot.Role == "link" && snapshot.ExplicitName && !snapshot.Editable {
return strings.TrimSpace(snapshot.Name)
}
return ""
}
func caret_text_count(snapshot atspi.Snapshot) int {
if label := named_link_label(snapshot); label != "" {
func caretTextCount(snapshot atspi.Snapshot) int {
if label := namedLinkLabel(snapshot); label != "" {
return utf8.RuneCountInString(label)
}
return snapshot.CharacterCount
@@ -30,11 +30,11 @@ func caret_text_count(snapshot atspi.Snapshot) int {
// Named links can expose no Text interface, or only a badge/embedded object.
// Review the label used by line speech, retaining the link for activation.
// These offsets belong to the label and must never become native text offsets.
func read_caret_text(ctx context.Context, reader DocumentCaretReader, node atspi.DocumentNode, offset int, unit atspi.DocumentCaretUnit) (atspi.DocumentCaretText, error) {
func readCaretText(ctx context.Context, reader DocumentCaretReader, node atspi.DocumentNode, offset int, unit atspi.DocumentCaretUnit) (atspi.DocumentCaretText, error) {
if err := ctx.Err(); err != nil {
return atspi.DocumentCaretText{}, err
}
label := named_link_label(node.Snapshot)
label := namedLinkLabel(node.Snapshot)
if label == "" {
return reader.ReadDocumentCaret(ctx, node.Reference, offset, unit)
}
+3 -3
View File
@@ -28,18 +28,18 @@ func (cursor *DocumentCursor) syncNativeCaret(ctx context.Context, reader Docume
if err != nil {
return err
}
node, offset, err := native_caret_node(ctx, reader, doc, focus, offset)
node, offset, err := nativeCaretNode(ctx, reader, doc, focus, offset)
if err != nil {
return err
}
place.object, place.offset, place.origin = node.Reference, offset, CaretNavigation
place.tableCell = atspi.ObjectID{}
remember_text_parent(doc, place)
rememberTextParent(doc, place)
return nil
}
func native_caret_node(ctx context.Context, reader DocumentCaretReader, doc atspi.DocumentSnapshot, focus atspi.ObjectID, offset int) (atspi.DocumentNode, int, error) {
func nativeCaretNode(ctx context.Context, reader DocumentCaretReader, doc atspi.DocumentSnapshot, focus atspi.ObjectID, offset int) (atspi.DocumentNode, int, error) {
node, _ := doc.Node(focus)
if !node.Reference.Valid() || offset < 0 || offset > node.Snapshot.CharacterCount || node.Snapshot.Editable || node.Snapshot.Role == "password text" {
return atspi.DocumentNode{}, 0, atspi.ErrNoDocumentCaret
@@ -36,7 +36,7 @@ func (reader *navigationTextReader) ReadDocumentCaret(ctx context.Context, objec
return text, err
}
func (reader *navigationTextReader) did_read(object atspi.ObjectReference) bool {
func (reader *navigationTextReader) didRead(object atspi.ObjectReference) bool {
for _, read := range reader.readObjects {
if read == object {
return true
+14 -14
View File
@@ -14,7 +14,7 @@ import "git.stormux.org/storm/cthulhu/internal/atspi"
// generation-checked parent, then distinguish recreation from insertion.
// Labels alone still cannot establish the old reading position, and neither
// recovery is ever used for activation.
func remember_text_parent(doc atspi.DocumentSnapshot, place *documentPlace) {
func rememberTextParent(doc atspi.DocumentSnapshot, place *documentPlace) {
place.textParent = atspi.ObjectReference{}
place.textPrevious, place.textNext = atspi.ObjectReference{}, atspi.ObjectReference{}
place.textChildIndex, place.textChildCount = 0, 0
@@ -26,7 +26,7 @@ func remember_text_parent(doc atspi.DocumentSnapshot, place *documentPlace) {
if !ok || node.Reference != place.object {
return
}
plainText := replacement_text_leaf(node)
plainText := replacementTextLeaf(node)
firstParent := true
for parentID := node.Parent; parentID.Valid(); {
parent, ok := doc.Node(parentID)
@@ -35,10 +35,10 @@ func remember_text_parent(doc atspi.DocumentSnapshot, place *documentPlace) {
}
if firstParent {
firstParent = false
remember_child_slot(doc, place, parent, &place.parent, &place.parentPrevious, &place.parentNext,
rememberChildSlot(doc, place, parent, &place.parent, &place.parentPrevious, &place.parentNext,
&place.parentChildIndex, &place.parentChildCount)
}
if len(place.recoveryParents) == 0 && plainText && replacement_text_parent(parent) {
if len(place.recoveryParents) == 0 && plainText && replacementTextParent(parent) {
place.textParent = parent.Reference
for childIndex, id := range parent.Children {
if id != place.object.ID() {
@@ -89,7 +89,7 @@ func survivingDocumentParent(doc atspi.DocumentSnapshot, saved documentPlace) (a
return atspi.DocumentNode{}, false
}
func replacement_text_node(doc atspi.DocumentSnapshot, saved documentPlace) (atspi.DocumentNode, string, bool) {
func replacementTextNode(doc atspi.DocumentSnapshot, saved documentPlace) (atspi.DocumentNode, string, bool) {
if saved.document != doc.Context.TopLevel || !saved.textParent.Valid() || saved.origin != CaretNavigation {
return atspi.DocumentNode{}, "", false
}
@@ -99,7 +99,7 @@ func replacement_text_node(doc atspi.DocumentSnapshot, saved documentPlace) (ats
byID[node.Reference.ID()] = node
}
for _, parent := range doc.Nodes {
if parent.Reference != saved.textParent || !replacement_text_parent(parent) {
if parent.Reference != saved.textParent || !replacementTextParent(parent) {
continue
}
for index, id := range parent.Children {
@@ -119,7 +119,7 @@ func replacement_text_node(doc atspi.DocumentSnapshot, saved documentPlace) (ats
next = sibling.Reference
}
child := byID[id]
if previous == saved.textPrevious && next == saved.textNext && child != nil && replacement_text_leaf(*child) {
if previous == saved.textPrevious && next == saved.textNext && child != nil && replacementTextLeaf(*child) {
return *child, "replaced-text-child", true
}
}
@@ -140,7 +140,7 @@ func replacement_text_node(doc atspi.DocumentSnapshot, saved documentPlace) (ats
}
if siblingsRetired && saved.textChildCount > 0 && len(parent.Children) == saved.textChildCount &&
saved.textChildIndex >= 0 && saved.textChildIndex < len(parent.Children) {
if child := byID[parent.Children[saved.textChildIndex]]; child != nil && replacement_text_leaf(*child) {
if child := byID[parent.Children[saved.textChildIndex]]; child != nil && replacementTextLeaf(*child) {
return *child, "replaced-text-child-index", true
}
}
@@ -149,11 +149,11 @@ func replacement_text_node(doc atspi.DocumentSnapshot, saved documentPlace) (ats
return atspi.DocumentNode{}, "", false
}
// remember_child_slot records a child's slot under its immediate parent:
// rememberChildSlot records a child's slot under its immediate parent:
// the generation-checked parent, adjacent sibling references, and index
// and count. Any unresolved boundary clears the slot; indices alone are
// never enough evidence on their own.
func remember_child_slot(doc atspi.DocumentSnapshot, place *documentPlace, parent atspi.DocumentNode,
func rememberChildSlot(doc atspi.DocumentSnapshot, place *documentPlace, parent atspi.DocumentNode,
slotParent, slotPrevious, slotNext *atspi.ObjectReference, slotIndex, slotCount *int) {
for childIndex, id := range parent.Children {
if id != place.object.ID() {
@@ -179,14 +179,14 @@ func remember_child_slot(doc atspi.DocumentSnapshot, place *documentPlace, paren
}
}
// replacement_child_node generalizes the replaced-text-child recovery to
// replacementChildNode generalizes the replaced-text-child recovery to
// any child (recreated button rows, containers) under the same bounded
// evidence: either the generation-checked sibling boundaries still match,
// or every sibling retired together with the child count unchanged, so
// the same index under the same surviving parent is the recreation. Orca
// recovers removed children the same way (parent plus removed index);
// activation never uses this fallback.
func replacement_child_node(doc atspi.DocumentSnapshot, saved documentPlace) (atspi.DocumentNode, string, bool) {
func replacementChildNode(doc atspi.DocumentSnapshot, saved documentPlace) (atspi.DocumentNode, string, bool) {
if saved.document != doc.Context.TopLevel || !saved.parent.Valid() || saved.origin == NativeNavigation {
return atspi.DocumentNode{}, "", false
}
@@ -248,7 +248,7 @@ func replacement_child_node(doc atspi.DocumentSnapshot, saved documentPlace) (at
return atspi.DocumentNode{}, "", false
}
func replacement_text_parent(node atspi.DocumentNode) bool {
func replacementTextParent(node atspi.DocumentNode) bool {
if len(node.Children) == 0 || node.Hidden || node.ParentEditable || node.Snapshot.Editable {
return false
}
@@ -263,7 +263,7 @@ func replacement_text_parent(node atspi.DocumentNode) bool {
(node.Snapshot.Role == "paragraph" || node.Snapshot.Role == "heading" || node.Snapshot.Role == "section")
}
func replacement_text_leaf(node atspi.DocumentNode) bool {
func replacementTextLeaf(node atspi.DocumentNode) bool {
return len(node.Children) == 0 && !node.Hidden && !node.ParentEditable &&
!node.Snapshot.Editable && !node.Snapshot.Focusable && !node.Snapshot.SupportsClick &&
!node.Snapshot.ExplicitName && node.Snapshot.CharacterCount > 0 &&
+6 -6
View File
@@ -52,7 +52,7 @@ func TestDocumentCaretRecoversSingleReplacedTextChild(t *testing.T) {
if err := tree.Replace(webID("/doc"), nodes); err != nil {
t.Fatal(err)
}
position, recovery, err := cursor.sync_focus(ctx, webID("/doc"))
position, recovery, err := cursor.syncFocus(ctx, webID("/doc"))
if err != nil {
t.Fatal(err)
}
@@ -122,7 +122,7 @@ func TestDocumentCaretRecoversRecreatedTextSiblings(t *testing.T) {
if err := tree.Replace(webID("/doc"), generation("b")); err != nil {
t.Fatal(err)
}
position, recovery, err := cursor.sync_focus(ctx, webID("/doc"))
position, recovery, err := cursor.syncFocus(ctx, webID("/doc"))
if err != nil {
t.Fatal(err)
}
@@ -135,7 +135,7 @@ func TestDocumentCaretRecoversRecreatedTextSiblings(t *testing.T) {
if err := tree.Replace(webID("/doc"), generation("c")); err != nil {
t.Fatal(err)
}
if _, _, err := cursor.sync_focus(ctx, webID("/doc")); err != nil {
if _, _, err := cursor.syncFocus(ctx, webID("/doc")); err != nil {
t.Fatal(err)
}
if move, err := cursor.MoveCaret(ctx, reader, CaretNextLine); err != nil || move.Moved {
@@ -186,7 +186,7 @@ func TestDocumentCaretRecoversRecreatedChildByIndex(t *testing.T) {
if err := tree.Replace(webID("/doc"), generation("b")); err != nil {
t.Fatal(err)
}
position, recovery, err := cursor.sync_focus(ctx, webID("/doc"))
position, recovery, err := cursor.syncFocus(ctx, webID("/doc"))
if err != nil {
t.Fatal(err)
}
@@ -225,7 +225,7 @@ func TestDocumentCaretMoveCrossesTextInvalidatedLines(t *testing.T) {
}
tree.InvalidateText(webID("/first"))
tree.InvalidateText(webID("/second"))
if _, _, err := cursor.sync_focus(ctx, webID("/doc")); err != nil {
if _, _, err := cursor.syncFocus(ctx, webID("/doc")); err != nil {
t.Fatalf("sync across ticking text: %v", err)
}
move, err := cursor.MoveCaret(ctx, reader, CaretNextLine)
@@ -290,7 +290,7 @@ func TestDocumentRecoveryUsesSurvivingContainerWithoutTransferringOffset(t *test
if err := tree.Replace(webID("/doc"), nodes); err != nil {
t.Fatal(err)
}
position, recovery, err := cursor.sync_focus(ctx, webID("/doc"))
position, recovery, err := cursor.syncFocus(ctx, webID("/doc"))
if err != nil || recovery != "surviving-parent" || position.Object.ID() != webID("/section") || position.Offset != 0 {
t.Fatalf("container recovery: %+v, %s, %v", position, recovery, err)
}
+4 -4
View File
@@ -16,7 +16,7 @@ import (
// The virtual coordinate survives a spanning cell so reversing direction keeps
// the user's column/row. Nested tables have independent coordinate spaces.
func (cursor *DocumentCursor) moveTable(ctx context.Context, doc atspi.DocumentSnapshot, place *documentPlace, command DocumentCaretCommand) (DocumentCaretMove, error) {
tableIndex, found := document_table_index(doc, place.object.ID())
tableIndex, found := documentTableIndex(doc, place.object.ID())
message := func(text string) (DocumentCaretMove, error) {
return DocumentCaretMove{Position: documentPosition(doc, *place), Text: text}, nil
}
@@ -110,7 +110,7 @@ func (cursor *DocumentCursor) moveTable(ctx context.Context, doc atspi.DocumentS
}
}
if !target.Reference.Valid() && (dr != 0 || dc != 0) {
target, row, col = next_available_table_cell(cells, current, row, col, dr, dc)
target, row, col = nextAvailableTableCell(cells, current, row, col, dr, dc)
}
if !target.Reference.Valid() {
return message("Table cell unavailable.")
@@ -168,7 +168,7 @@ func (cursor *DocumentCursor) moveTable(ctx context.Context, doc atspi.DocumentS
}
// Use the immutable document index and avoid rebuilding whole-page parent maps.
func document_table_index(doc atspi.DocumentSnapshot, id atspi.ObjectID) (int, bool) {
func documentTableIndex(doc atspi.DocumentSnapshot, id atspi.ObjectID) (int, bool) {
for depth := 0; id.Valid() && depth < 128; depth++ {
index, ok := doc.Index(id)
if !ok {
@@ -185,7 +185,7 @@ func document_table_index(doc atspi.DocumentSnapshot, id atspi.ObjectID) (int, b
// Search captured cells rather than iterating potentially enormous sparse
// dimensions. Horizontal neighbors can occupy a lower row of a spanning cell.
func next_available_table_cell(cells []atspi.DocumentNode, current atspi.DocumentNode, row, col, dr, dc int) (atspi.DocumentNode, int, int) {
func nextAvailableTableCell(cells []atspi.DocumentNode, current atspi.DocumentNode, row, col, dr, dc int) (atspi.DocumentNode, int, int) {
var target atspi.DocumentNode
bestRow, bestCol := row, col
for _, node := range cells {
+4 -4
View File
@@ -12,7 +12,7 @@ import (
"git.stormux.org/storm/cthulhu/internal/atspi"
)
func tooltip_cursor(t *testing.T, focusable, editable, hypertext bool) (*DocumentCursor, caretTextReader) {
func tooltipCursor(t *testing.T, focusable, editable, hypertext bool) (*DocumentCursor, caretTextReader) {
t.Helper()
reader := caretTextReader{webID("/before"): "Project", webID("/tiptext"): "Project", webID("/after"): "After"}
node := func(path, role string, children ...atspi.ObjectID) atspi.TreeNode {
@@ -48,7 +48,7 @@ func TestDocumentCaretSkipsPassiveTooltip(t *testing.T) {
for _, hypertext := range []bool{false, true} {
for _, command := range []DocumentCaretCommand{CaretNextLine, CaretNextCharacter, CaretNextWord} {
t.Run(command.String(), func(t *testing.T) {
cursor, reader := tooltip_cursor(t, false, false, hypertext)
cursor, reader := tooltipCursor(t, false, false, hypertext)
if command != CaretNextLine {
cursor.places[0].offset = len("Project") - 1
}
@@ -74,7 +74,7 @@ func TestDocumentCaretSkipsPassiveTooltip(t *testing.T) {
func TestDocumentCaretPreservesInteractiveTooltip(t *testing.T) {
for _, focusable := range []bool{false, true} {
cursor, reader := tooltip_cursor(t, focusable, !focusable, false)
cursor, reader := tooltipCursor(t, focusable, !focusable, false)
move, err := cursor.MoveCaret(context.Background(), reader, CaretNextLine)
if err != nil || !move.Moved || move.Position.Object.ID() != webID("/tiptext") {
t.Fatalf("interactive tooltip: %+v, %v", move, err)
@@ -83,7 +83,7 @@ func TestDocumentCaretPreservesInteractiveTooltip(t *testing.T) {
}
func TestReadAllSkipsPassiveTooltip(t *testing.T) {
cursor, reader := tooltip_cursor(t, false, false, true)
cursor, reader := tooltipCursor(t, false, false, true)
worker, err := NewWorker(&readAllCapturer{tree: cursor.tree, caretTextReader: reader}, time.Second)
if err != nil {
t.Fatal(err)
+14 -14
View File
@@ -48,7 +48,7 @@ func (reader *visualLineReader) ReadDocumentCaret(ctx context.Context, object at
return text, err
}
func move_caret_line(ctx context.Context, source DocumentCaretReader, tree *atspi.AccessibleTree, doc atspi.DocumentSnapshot, place *documentPlace, indices []caretRange, lookup *caretRangeLookup, current int, command DocumentCaretCommand, owners map[int]atspi.ObjectID) (DocumentCaretMove, error) {
func moveCaretLine(ctx context.Context, source DocumentCaretReader, tree *atspi.AccessibleTree, doc atspi.DocumentSnapshot, place *documentPlace, indices []caretRange, lookup *caretRangeLookup, current int, command DocumentCaretCommand, owners map[int]atspi.ObjectID) (DocumentCaretMove, error) {
reader := &visualLineReader{DocumentCaretReader: source, cache: make(map[visualLineKey]atspi.DocumentCaretText)}
next := *place
// Move beyond the entire current line, even when character/word movement
@@ -60,7 +60,7 @@ func move_caret_line(ctx context.Context, source DocumentCaretReader, tree *atsp
position = lookup.after[current]
}
if position >= 0 {
parts, err := collect_visual_line(ctx, reader, doc, indices, owners, position, place.offset, true)
parts, err := collectVisualLine(ctx, reader, doc, indices, owners, position, place.offset, true)
if err != nil {
return DocumentCaretMove{}, err
}
@@ -74,7 +74,7 @@ func move_caret_line(ctx context.Context, source DocumentCaretReader, tree *atsp
}
}
}
movement, err := move_caret_object_line(ctx, reader, doc, &next, indices, lookup, current, command)
movement, err := moveCaretObjectLine(ctx, reader, doc, &next, indices, lookup, current, command)
if err != nil || !movement.Moved {
if err == nil {
movement.Position = documentPosition(doc, *place)
@@ -84,7 +84,7 @@ func move_caret_line(ctx context.Context, source DocumentCaretReader, tree *atsp
nextIndex, _ := doc.Index(next.object.ID())
position := lookup.containing(indices, nextIndex, next.offset)
if position >= 0 {
parts, err := collect_visual_line(ctx, reader, doc, indices, owners, position, next.offset, command != CaretReadLine)
parts, err := collectVisualLine(ctx, reader, doc, indices, owners, position, next.offset, command != CaretReadLine)
if err != nil {
return DocumentCaretMove{}, err
}
@@ -98,7 +98,7 @@ func move_caret_line(ctx context.Context, source DocumentCaretReader, tree *atsp
next.offset = part.text.End - 1
}
movement.Start, movement.End = part.text.Start, part.text.End
line, raw, misspelled := assemble_visual_line(tree, doc, parts)
line, raw, misspelled := assembleVisualLine(tree, doc, parts)
movement.Line, movement.RawText, movement.Misspelled = &line, raw, movement.Misspelled || misspelled
movement.Text = strings.Join(strings.Fields(movement.RawText), " ")
if command == CaretLineStart || command == CaretLineEnd {
@@ -118,7 +118,7 @@ func move_caret_line(ctx context.Context, source DocumentCaretReader, tree *atsp
// Retain semantic boundaries even if unrelated blocks have matching y values.
// Links and same-row list items inherit their surrounding block. Headings,
// paragraphs and table cells remain separate; grid items retain their boundaries.
func visual_line_owners(nodes []atspi.DocumentNode) map[int]atspi.ObjectID {
func visualLineOwners(nodes []atspi.DocumentNode) map[int]atspi.ObjectID {
owners := make(map[int]atspi.ObjectID, len(nodes))
byID := make(map[atspi.ObjectID]atspi.ObjectID, len(nodes))
displays := make(map[atspi.ObjectID]string, len(nodes))
@@ -156,7 +156,7 @@ func visual_line_owners(nodes []atspi.DocumentNode) map[int]atspi.ObjectID {
return owners
}
func collect_visual_line(ctx context.Context, reader DocumentCaretReader, doc atspi.DocumentSnapshot, indices []caretRange, owners map[int]atspi.ObjectID, position, offset int, left bool) ([]visualLinePart, error) {
func collectVisualLine(ctx context.Context, reader DocumentCaretReader, doc atspi.DocumentSnapshot, indices []caretRange, owners map[int]atspi.ObjectID, position, offset int, left bool) ([]visualLinePart, error) {
index := indices[position].index
node := doc.Nodes[index]
if !owners[index].Valid() || node.Snapshot.Editable || wholeCaretNode(node.Snapshot) || node.Snapshot.CharacterCount <= 0 {
@@ -173,7 +173,7 @@ func collect_visual_line(ctx context.Context, reader DocumentCaretReader, doc at
if err != nil {
return nil, err
}
if !visual_line_text(text) {
if !visualLineText(text) {
return nil, nil
}
if !left && text.RawText != "" {
@@ -206,7 +206,7 @@ func collect_visual_line(ctx context.Context, reader DocumentCaretReader, doc at
if err != nil {
return nil, err
}
if !visual_line_text(piece) || !visual_line_bounds(text.Bounds, piece.Bounds) {
if !visualLineText(piece) || !visualLineBounds(text.Bounds, piece.Bounds) {
break
}
// A fragment containing a hard newline ends the line, even when
@@ -233,12 +233,12 @@ func collect_visual_line(ctx context.Context, reader DocumentCaretReader, doc at
return parts, nil
}
func visual_line_text(text atspi.DocumentCaretText) bool {
func visualLineText(text atspi.DocumentCaretText) bool {
return text.Bounds.Valid() && text.Start >= 0 && text.End > text.Start && text.End <= text.CharacterCount &&
!strings.ContainsRune(text.Text, '\ufffc') && (text.Text != "" || text.RawText != "")
}
func visual_line_bounds(first, second atspi.Rectangle) bool {
func visualLineBounds(first, second atspi.Rectangle) bool {
if !first.Valid() || !second.Valid() {
return false
}
@@ -247,7 +247,7 @@ func visual_line_bounds(first, second atspi.Rectangle) bool {
return bottom > top && math.Abs(float64(first.Y)+float64(first.Height)/2-float64(second.Y)-float64(second.Height)/2) <= 5
}
func visual_line_space(first, second atspi.DocumentCaretText) bool {
func visualLineSpace(first, second atspi.DocumentCaretText) bool {
left, right := first.RawText, second.RawText
if left == "" {
left = first.Text
@@ -261,7 +261,7 @@ func visual_line_space(first, second atspi.DocumentCaretText) bool {
return gap > 1 && !unicode.IsSpace(last) && !unicode.IsSpace(start)
}
func assemble_visual_line(tree *atspi.AccessibleTree, doc atspi.DocumentSnapshot, parts []visualLinePart) (atspi.DocumentLine, string, bool) {
func assembleVisualLine(tree *atspi.AccessibleTree, doc atspi.DocumentSnapshot, parts []visualLinePart) (atspi.DocumentLine, string, bool) {
misspelled := false
line := atspi.DocumentLine{Document: doc.Context.TopLevel}
var raw strings.Builder
@@ -272,7 +272,7 @@ func assemble_visual_line(tree *atspi.AccessibleTree, doc atspi.DocumentSnapshot
}
// Preserve native spacing and punctuation across span boundaries.
separator := ""
if i > 0 && visual_line_space(parts[i-1].text, part.text) {
if i > 0 && visualLineSpace(parts[i-1].text, part.text) {
separator = " "
}
raw.WriteString(separator)
@@ -124,7 +124,7 @@ func TestNativeBrowserFragmentLines(t *testing.T) {
content := inline.Line.Contents[1]
displayRoute := &documentBrailleRequest{ctx: ctx, focus: focus, document: inline.Position.Document.ID(), target: content.Snapshot.ID(),
line: content.RawText, start: content.Start, offset: content.Start + 1, done: make(chan error, 1)}
routed := worker.route_document_braille(ctx, cursor, request{brailleRoute: displayRoute})
routed := worker.routeDocumentBraille(ctx, cursor, request{brailleRoute: displayRoute})
if routed.Err != nil || !routed.Moved || routed.DocumentPosition.Offset != content.Start+1 || routed.DocumentCaretLine == nil || len(routed.DocumentCaretLine.Contents) < 2 {
t.Fatalf("native inline braille route = %+v", routed)
}
@@ -148,7 +148,7 @@ func TestNativeBrowserFragmentLines(t *testing.T) {
t.Fatalf("Read All: %+v", result)
}
for index, want := range []string{"One two three.", "Four five six.", "Next paragraph."} {
if got := visual_line_test_text(result.ReadAllLines[index]); got != want {
if got := visualLineTestText(result.ReadAllLines[index]); got != want {
t.Fatalf("Read All line %d: %q, want %q", index, got, want)
}
}
+13 -13
View File
@@ -31,7 +31,7 @@ func (reader fragmentTextReader) ReadDocumentCaret(ctx context.Context, ref atsp
return text, err
}
func fragment_cursor(t *testing.T, boundary string) (*DocumentCursor, fragmentTextReader) {
func fragmentCursor(t *testing.T, boundary string) (*DocumentCursor, fragmentTextReader) {
t.Helper()
reader := fragmentTextReader{caretTextReader: caretTextReader{
webID("/one"): "One ", webID("/two"): "two.", webID("/three"): "Three ", webID("/four"): "four.", webID("/after"): "Next paragraph",
@@ -79,7 +79,7 @@ func fragment_cursor(t *testing.T, boundary string) (*DocumentCursor, fragmentTe
}
func TestDocumentFragmentLines(t *testing.T) {
cursor, reader := fragment_cursor(t, "paragraph")
cursor, reader := fragmentCursor(t, "paragraph")
ctx := context.Background()
for _, step := range []struct {
command DocumentCaretCommand
@@ -115,7 +115,7 @@ func TestDocumentFragmentSpacingAndPunctuation(t *testing.T) {
{"One", "two.", "One two.", 40},
{"Hello", ",", "Hello,", 30},
} {
cursor, reader := fragment_cursor(t, "paragraph")
cursor, reader := fragmentCursor(t, "paragraph")
reader.caretTextReader[webID("/one")] = test.first
reader.caretTextReader[webID("/two")] = test.second
bounds := reader.bounds[webID("/two")]
@@ -150,7 +150,7 @@ func (capturer *fragmentReadAllCapturer) ReadDocumentCaret(ctx context.Context,
}
func TestReadAllFragmentLinesAndRemainder(t *testing.T) {
cursor, reader := fragment_cursor(t, "paragraph")
cursor, reader := fragmentCursor(t, "paragraph")
ctx := context.Background()
if _, err := cursor.MoveCaret(ctx, reader, CaretNextCharacter); err != nil {
t.Fatal(err)
@@ -163,7 +163,7 @@ func TestReadAllFragmentLinesAndRemainder(t *testing.T) {
t.Fatalf("read all: %+v", result)
}
for index, want := range []string{"ne two.", "Three four.", "Next paragraph"} {
if got := visual_line_test_text(result.ReadAllLines[index]); got != want {
if got := visualLineTestText(result.ReadAllLines[index]); got != want {
t.Fatalf("line %d: %q, want %q", index, got, want)
}
}
@@ -190,7 +190,7 @@ func TestReadAllFragmentLinesAndRemainder(t *testing.T) {
}
func TestDocumentFragmentSourceLookupFailureKeepsLocalText(t *testing.T) {
cursor, reader := fragment_cursor(t, "paragraph")
cursor, reader := fragmentCursor(t, "paragraph")
doc, err := cursor.tree.Document(t.Context(), cursor.places[0].object)
if err != nil {
t.Fatal(err)
@@ -208,7 +208,7 @@ func TestDocumentFragmentSourceLookupFailureKeepsLocalText(t *testing.T) {
// Metadata can become stale after the successful text read. The local
// text stays usable; missing source evidence must remain explicit.
cursor.tree.InvalidateSnapshot(webID("/span"))
line, raw, _ := assemble_visual_line(cursor.tree, doc, parts)
line, raw, _ := assembleVisualLine(cursor.tree, doc, parts)
if raw != "One two." || len(line.SourceContexts) != 2 || len(line.SourceContexts[0]) == 0 || line.SourceContexts[1] != nil {
t.Fatal("stale source context changed local text or looked classified")
}
@@ -217,7 +217,7 @@ func TestDocumentFragmentSourceLookupFailureKeepsLocalText(t *testing.T) {
func TestDocumentFragmentBoundaries(t *testing.T) {
for _, boundary := range []string{"heading", "link", "table cell", "pre", "code", "entry"} {
t.Run(boundary, func(t *testing.T) {
cursor, reader := fragment_cursor(t, boundary)
cursor, reader := fragmentCursor(t, boundary)
move, err := cursor.MoveCaret(context.Background(), reader, CaretDocumentStart)
want := "One two."
if boundary == "pre" || boundary == "code" || boundary == "entry" {
@@ -235,7 +235,7 @@ func TestDocumentFragmentBoundaries(t *testing.T) {
func TestDocumentFragmentErrorsDoNotMoveCursor(t *testing.T) {
for _, failure := range []error{context.Canceled, atspi.ErrStaleObject} {
cursor, reader := fragment_cursor(t, "paragraph")
cursor, reader := fragmentCursor(t, "paragraph")
reader.err = failure
before := cursor.places[0]
_, err := cursor.MoveCaret(context.Background(), reader, CaretNextLine)
@@ -256,7 +256,7 @@ func (reader wrappedFragmentReader) ReadDocumentCaret(ctx context.Context, ref a
}
func TestDocumentFragmentLineAcrossWrappedObject(t *testing.T) {
cursor, base := fragment_cursor(t, "paragraph")
cursor, base := fragmentCursor(t, "paragraph")
base.caretTextReader[webID("/one")] = "First\nSecond "
base.bounds[webID("/two")] = atspi.Rectangle{X: 60, Y: 30, Width: 30, Height: 18}
base.bounds[webID("/three")] = atspi.Rectangle{X: 0, Y: 50, Width: 30, Height: 18}
@@ -291,7 +291,7 @@ func TestDocumentFragmentLineAcrossWrappedObject(t *testing.T) {
}
}
func visual_line_test_text(line atspi.DocumentLine) string {
func visualLineTestText(line atspi.DocumentLine) string {
var text strings.Builder
for _, part := range line.Contents {
text.WriteString(part.Separator)
@@ -303,7 +303,7 @@ func visual_line_test_text(line atspi.DocumentLine) string {
func TestDocumentSameRowLinksAndListItems(t *testing.T) {
for _, role := range []string{"link", "list item"} {
t.Run(role, func(t *testing.T) {
cursor, reader := fragment_cursor(t, "list")
cursor, reader := fragmentCursor(t, "list")
doc, _ := cursor.tree.Document(t.Context(), cursor.places[0].object)
var nodes []atspi.TreeNode
for _, node := range doc.Nodes {
@@ -332,7 +332,7 @@ func TestDocumentSameRowLinksAndListItems(t *testing.T) {
}
func TestDocumentGridListItemsStaySeparate(t *testing.T) {
cursor, reader := fragment_cursor(t, "list")
cursor, reader := fragmentCursor(t, "list")
doc, _ := cursor.tree.Document(t.Context(), cursor.places[0].object)
var nodes []atspi.TreeNode
for _, node := range doc.Nodes {
+14 -14
View File
@@ -187,7 +187,7 @@ func (worker *Worker) captureDocumentForMove(ctx context.Context, cursor *Docume
if err == nil || !errors.Is(err, atspi.ErrObjectNotFound) {
return tree, duration, err
}
anchor, ok := cursor.capture_anchor(focus)
anchor, ok := cursor.captureAnchor(focus)
if !ok {
return tree, duration, err
}
@@ -212,14 +212,14 @@ func (worker *Worker) moveDocumentRepeated(ctx context.Context, cursor *Document
return result, cursor
}
move := func() (moveErr error) {
attempt := DocumentAttempt{Focus: result.DocumentFocus, Before: cursor.diagnostic_state(), Stage: "focus"}
defer func() { result.record_document_attempt(cursor, attempt, moveErr) }()
attempt := DocumentAttempt{Focus: result.DocumentFocus, Before: cursor.diagnosticState(), Stage: "focus"}
defer func() { result.recordDocumentAttempt(cursor, attempt, moveErr) }()
if cursor == nil {
attempt.Recovery = "no-cursor"
return ErrNoCurrent
}
_, recovery, err := cursor.sync_focus(ctx, result.DocumentFocus)
attempt.Recovery, attempt.Synced = recovery, cursor.diagnostic_state()
_, recovery, err := cursor.syncFocus(ctx, result.DocumentFocus)
attempt.Recovery, attempt.Synced = recovery, cursor.diagnosticState()
if err != nil {
return err
}
@@ -398,14 +398,14 @@ func (worker *Worker) moveDocumentCaret(ctx context.Context, cursor *DocumentCur
return result, cursor
}
move := func() (moveErr error) {
attempt := DocumentAttempt{Focus: result.DocumentFocus, Before: cursor.diagnostic_state(), Stage: "focus"}
defer func() { result.record_document_attempt(cursor, attempt, moveErr) }()
attempt := DocumentAttempt{Focus: result.DocumentFocus, Before: cursor.diagnosticState(), Stage: "focus"}
defer func() { result.recordDocumentAttempt(cursor, attempt, moveErr) }()
if cursor == nil {
attempt.Recovery = "no-cursor"
return ErrNoCurrent
}
_, recovery, err := cursor.sync_focus(ctx, result.DocumentFocus)
attempt.Recovery, attempt.Synced = recovery, cursor.diagnostic_state()
_, recovery, err := cursor.syncFocus(ctx, result.DocumentFocus)
attempt.Recovery, attempt.Synced = recovery, cursor.diagnosticState()
if err != nil {
return err
}
@@ -506,7 +506,7 @@ func (worker *Worker) placeDocumentCaret(ctx context.Context, cursor *DocumentCu
deadline, cancel := context.WithTimeout(ctx, worker.captureTimeout)
defer cancel()
nativeOffset := result.DocumentPosition.Offset
if named_link_label(result.DocumentPosition.Snapshot) != "" {
if namedLinkLabel(result.DocumentPosition.Snapshot) != "" {
// The label's review offset has no relationship to the native badge
// or embedded-object text. Place only the link's native anchor.
nativeOffset = 0
@@ -600,17 +600,17 @@ func (cursor *DocumentCursor) syncActionFocus(ctx context.Context, focus atspi.O
// Refresh before an action, retaining the virtual position only within the same
// document and focus. Never substitute another link if the selected one vanished.
func (worker *Worker) refreshDocumentCursor(ctx context.Context, cursor *DocumentCursor, focus atspi.ObjectID) (*DocumentCursor, error) {
return worker.refresh_document_cursor(ctx, cursor, focus, false)
return worker.refreshDocumentCursorWithRecovery(ctx, cursor, focus, false)
}
// Read All is navigation: a missing text child can recover within the same
// captured tree using its generation-checked parent and sibling boundaries.
// Activation keeps the stricter refreshDocumentCursor path above.
func (worker *Worker) refresh_read_all_cursor(ctx context.Context, cursor *DocumentCursor, focus atspi.ObjectID) (*DocumentCursor, error) {
return worker.refresh_document_cursor(ctx, cursor, focus, true)
func (worker *Worker) refreshReadAllCursor(ctx context.Context, cursor *DocumentCursor, focus atspi.ObjectID) (*DocumentCursor, error) {
return worker.refreshDocumentCursorWithRecovery(ctx, cursor, focus, true)
}
func (worker *Worker) refresh_document_cursor(ctx context.Context, cursor *DocumentCursor, focus atspi.ObjectID, recoverNavigation bool) (*DocumentCursor, error) {
func (worker *Worker) refreshDocumentCursorWithRecovery(ctx context.Context, cursor *DocumentCursor, focus atspi.ObjectID, recoverNavigation bool) (*DocumentCursor, error) {
var saved documentPlace
if cursor != nil && len(cursor.places) > 0 {
saved = cursor.places[len(cursor.places)-1]
+3 -3
View File
@@ -85,7 +85,7 @@ func (cursor *FlatCursor) Refresh(ctx context.Context, tree *atspi.AccessibleTre
return err
}
nodes := snapshot.Nodes
lines, completeness, err := build_flat_layout(ctx, nodes)
lines, completeness, err := buildFlatLayout(ctx, nodes)
if err != nil {
return err
}
@@ -101,7 +101,7 @@ func (cursor *FlatCursor) Refresh(ctx context.Context, tree *atspi.AccessibleTre
// Exact identity takes priority over a displayed descendant of focus.
if !next.seek(focus, 0, false) {
if !next.seekDescendant(focus) {
next.seek_ancestor(focus)
next.seekAncestor(focus)
}
}
for _, n := range nodes {
@@ -127,7 +127,7 @@ func (cursor *FlatCursor) Refresh(ctx context.Context, tree *atspi.AccessibleTre
// A focused leaf can have no displayed zone while its parent supplies the
// text. Choose only an actual ancestor zone, never a sibling or window title.
func (cursor *FlatCursor) seek_ancestor(object atspi.ObjectID) bool {
func (cursor *FlatCursor) seekAncestor(object atspi.ObjectID) bool {
for id := cursor.parents[object]; id.Valid(); id = cursor.parents[id] {
if !cursor.parents[id].Valid() {
return false
+1 -1
View File
@@ -56,7 +56,7 @@ func TestNativeBrowserChromeFlatReview(t *testing.T) {
if err != nil {
t.Fatal(err)
}
lines, status, err := build_flat_layout(ctx, snapshot.Nodes)
lines, status, err := buildFlatLayout(ctx, snapshot.Nodes)
if err != nil {
t.Fatal(err)
}
+14 -14
View File
@@ -68,14 +68,14 @@ type flatLine struct{ zones []flatZone }
// vertical extents and centres within five pixels. Compare to the first zone
// so a staircase of overlapping objects cannot merge separate text rows.
func buildFlatLines(ctx context.Context, nodes []atspi.TreeNode) ([]flatLine, error) {
lines, _, err := build_flat_layout(ctx, nodes)
lines, _, err := buildFlatLayout(ctx, nodes)
return lines, err
}
func build_flat_layout(ctx context.Context, nodes []atspi.TreeNode) ([]flatLine, FlatCompleteness, error) {
func buildFlatLayout(ctx context.Context, nodes []atspi.TreeNode) ([]flatLine, FlatCompleteness, error) {
var status FlatCompleteness
parents, nodeClips, hidden := flat_node_visibility(nodes)
zones, err := collect_flat_zones(ctx, nodes, parents, nodeClips, hidden, &status)
parents, nodeClips, hidden := flatNodeVisibility(nodes)
zones, err := collectFlatZones(ctx, nodes, parents, nodeClips, hidden, &status)
if err != nil {
return nil, status, err
}
@@ -87,7 +87,7 @@ func build_flat_layout(ctx context.Context, nodes []atspi.TreeNode) ([]flatLine,
}
return nil, status, ErrUnavailableReview
}
lines, err := arrange_flat_lines(ctx, nodes, zones)
lines, err := arrangeFlatLines(ctx, nodes, zones)
return lines, status, err
}
@@ -107,8 +107,8 @@ func sameFlatLine(a, b flatZone) bool {
return delta >= -10 && delta <= 10
}
// flat_node_visibility follows parent clipping before collecting any text.
func flat_node_visibility(nodes []atspi.TreeNode) (map[atspi.ObjectID]atspi.Snapshot, map[atspi.ObjectID]atspi.Rectangle, map[atspi.ObjectID]bool) {
// flatNodeVisibility follows parent clipping before collecting any text.
func flatNodeVisibility(nodes []atspi.TreeNode) (map[atspi.ObjectID]atspi.Snapshot, map[atspi.ObjectID]atspi.Rectangle, map[atspi.ObjectID]bool) {
parents := make(map[atspi.ObjectID]atspi.Snapshot, len(nodes))
clips := make(map[atspi.ObjectID]atspi.Rectangle, len(nodes))
nodeClips := make(map[atspi.ObjectID]atspi.Rectangle, len(nodes))
@@ -144,9 +144,9 @@ func flat_node_visibility(nodes []atspi.TreeNode) (map[atspi.ObjectID]atspi.Snap
return parents, nodeClips, hidden
}
// collect_flat_zones walks children before parents to avoid repeating container
// collectFlatZones walks children before parents to avoid repeating container
// names and text. Password contents and partly clipped native runs stay excluded.
func collect_flat_zones(ctx context.Context, nodes []atspi.TreeNode, parents map[atspi.ObjectID]atspi.Snapshot, nodeClips map[atspi.ObjectID]atspi.Rectangle, hidden map[atspi.ObjectID]bool, status *FlatCompleteness) ([]flatZone, error) {
func collectFlatZones(ctx context.Context, nodes []atspi.TreeNode, parents map[atspi.ObjectID]atspi.Snapshot, nodeClips map[atspi.ObjectID]atspi.Rectangle, hidden map[atspi.ObjectID]bool, status *FlatCompleteness) ([]flatZone, error) {
var zones []flatZone
textBytes := 0
hasContent := make(map[atspi.ObjectID]bool, len(nodes))
@@ -163,7 +163,7 @@ func collect_flat_zones(ctx context.Context, nodes []atspi.TreeNode, parents map
if hasContent[id] {
hasContent[parent.ID()] = true
}
if labelContent[id] && !flat_label_control(n.Snapshot.Role) {
if labelContent[id] && !flatLabelControl(n.Snapshot.Role) {
labelContent[parent.ID()] = true
}
if hidden[id] {
@@ -264,7 +264,7 @@ func collect_flat_zones(ctx context.Context, nodes []atspi.TreeNode, parents map
if len(zones) > before || hasContent[id] {
hasContent[parent.ID()] = true
}
if !flat_label_control(n.Snapshot.Role) && (len(zones) > before || labelContent[id]) {
if !flatLabelControl(n.Snapshot.Role) && (len(zones) > before || labelContent[id]) {
labelContent[parent.ID()] = true
}
}
@@ -273,7 +273,7 @@ func collect_flat_zones(ctx context.Context, nodes []atspi.TreeNode, parents map
// Named child controls represent independent actions rather than their
// enclosing control's label. Text/label descendants retain normal deduplication.
func flat_label_control(role string) bool {
func flatLabelControl(role string) bool {
switch role {
case "button", "push button", "toggle button", "check box", "radio button", "page tab",
"menu item", "check menu item", "radio menu item":
@@ -282,9 +282,9 @@ func flat_label_control(role string) bool {
return false
}
// arrange_flat_lines keeps stable provider order for geometry ties and computes
// arrangeFlatLines keeps stable provider order for geometry ties and computes
// Unicode word spans only after all bounded content has been collected.
func arrange_flat_lines(ctx context.Context, nodes []atspi.TreeNode, zones []flatZone) ([]flatLine, error) {
func arrangeFlatLines(ctx context.Context, nodes []atspi.TreeNode, zones []flatZone) ([]flatLine, error) {
if len(zones) == 0 {
return nil, ErrNoReviewContent
}
+1 -1
View File
@@ -146,7 +146,7 @@ func TestFlatReviewCompositeControlKeepsLabelBesideChildAction(t *testing.T) {
nodes[0] = parent
nodes = append(nodes, label)
}
lines, status, err := build_flat_layout(context.Background(), nodes)
lines, status, err := buildFlatLayout(context.Background(), nodes)
if err != nil || status.Incomplete() {
t.Fatalf("layout: %+v %v", status, err)
}
+1 -1
View File
@@ -122,7 +122,7 @@ func (worker *Worker) readFlat(ctx context.Context, cursor *FlatCursor, tree *at
if !cursor.seek(origin, offset, true) {
if !cursor.seek(origin, 0, false) {
if !cursor.seekDescendant(origin) {
cursor.seek_ancestor(origin)
cursor.seekAncestor(origin)
}
}
}
+1 -1
View File
@@ -74,7 +74,7 @@ func (worker *Worker) ObjectOfInterest(ctx context.Context) (Interest, error) {
}
}
func resolve_interest(ctx context.Context, focus atspi.ObjectID, explicit interestMode, cursor *Cursor, flat *FlatCursor, flatTree *atspi.AccessibleTree, document *DocumentCursor) (Interest, error) {
func resolveInterest(ctx context.Context, focus atspi.ObjectID, explicit interestMode, cursor *Cursor, flat *FlatCursor, flatTree *atspi.AccessibleTree, document *DocumentCursor) (Interest, error) {
if err := ctx.Err(); err != nil {
return Interest{}, err
}
+2 -2
View File
@@ -103,14 +103,14 @@ func TestInterestPrefersVirtualCaretThenExplicitReview(t *testing.T) {
if _, err := document.MoveCaret(ctx, reader, CaretNextLine); err != nil {
t.Fatal(err)
}
got, err := resolve_interest(ctx, webID("/text"), 0, nil, nil, nil, document)
got, err := resolveInterest(ctx, webID("/text"), 0, nil, nil, nil, document)
if err != nil || got.Object != webID("/next") {
t.Fatalf("virtual caret: %+v %v", got, err)
}
cursor, _ := NewCursor(newTree(t))
cursor.SyncFocus(objectID("/first"))
cursor.Move(NextSibling)
got, err = resolve_interest(ctx, webID("/text"), 1, cursor, nil, nil, document)
got, err = resolveInterest(ctx, webID("/text"), 1, cursor, nil, nil, document)
if err != nil || got.Object != objectID("/second") {
t.Fatalf("explicit precedence: %+v %v", got, err)
}
+4 -4
View File
@@ -37,10 +37,10 @@ func (worker *Worker) readAll(ctx context.Context, cursor *DocumentCursor) Resul
result.Err = ErrNoCurrent
}
if documentNeedsCapture(result.Err) {
cursor, result.Err = worker.refresh_read_all_cursor(ctx, cursor, result.DocumentFocus)
cursor, result.Err = worker.refreshReadAllCursor(ctx, cursor, result.DocumentFocus)
}
if documentNeedsCapture(result.Err) {
cursor, result.Err = worker.refresh_read_all_cursor(ctx, cursor, result.DocumentFocus)
cursor, result.Err = worker.refreshReadAllCursor(ctx, cursor, result.DocumentFocus)
}
if errors.Is(result.Err, atspi.ErrNotInDocument) {
if reader, ok := worker.nativeCapturerFor(result.DocumentFocus).(interface {
@@ -123,7 +123,7 @@ func (worker *Worker) readAll(ctx context.Context, cursor *DocumentCursor) Resul
result.Err = err
return result
}
refreshed, refreshErr := worker.refresh_read_all_cursor(ctx, cursor, result.DocumentFocus)
refreshed, refreshErr := worker.refreshReadAllCursor(ctx, cursor, result.DocumentFocus)
if refreshErr != nil {
result.Err = refreshErr
return result
@@ -164,7 +164,7 @@ func (worker *Worker) readAllMove(ctx context.Context, cursor *DocumentCursor, r
if err == nil || !documentNeedsCapture(err) {
return movement, cursor, err
}
cursor, refreshErr := worker.refresh_read_all_cursor(ctx, cursor, focus)
cursor, refreshErr := worker.refreshReadAllCursor(ctx, cursor, focus)
if refreshErr != nil {
return movement, cursor, refreshErr
}
+1 -1
View File
@@ -34,7 +34,7 @@ func (worker *Worker) ReadWhereAmI(revision uint64) error {
}
}
func (worker *Worker) read_where_am_i(ctx context.Context, request request) Result {
func (worker *Worker) readWhereAmI(ctx context.Context, request request) Result {
result := Result{WhereAmI: true, WhereAmIRevision: request.whereAmIRevision, DocumentFocus: request.readFocus}
if !result.DocumentFocus.Valid() || result.DocumentFocus != worker.Focus() {
result.Err = ErrNoCurrent
+1 -1
View File
@@ -56,7 +56,7 @@ func TestWhereAmIRejectsChangedFocusBeforeCapture(t *testing.T) {
t.Fatal("missing focus queued a native request")
}
worker.SyncFocus(webID("/new"))
result := worker.read_where_am_i(t.Context(), request{readFocus: webID("/old")})
result := worker.readWhereAmI(t.Context(), request{readFocus: webID("/old")})
if result.Err == nil || capturer.reads != 0 {
t.Fatal("retired focus started a native capture")
}
+4 -4
View File
@@ -345,7 +345,7 @@ func (worker *Worker) run(ctx context.Context, done chan<- struct{}) {
continue
}
if request.interest != nil {
interest, err := resolve_interest(request.interest.ctx, interestFocus, explicitInterest, cursor, flat, flatTree, document)
interest, err := resolveInterest(request.interest.ctx, interestFocus, explicitInterest, cursor, flat, flatTree, document)
worker.stateMutex.Lock()
currentFocus, currentRevision := worker.latestFocus, worker.focusRevision
worker.stateMutex.Unlock()
@@ -370,14 +370,14 @@ func (worker *Worker) run(ctx context.Context, done chan<- struct{}) {
}
var result Result
if request.whereAmI {
result = worker.read_where_am_i(ctx, request)
result = worker.readWhereAmI(ctx, request)
} else if request.currentLine {
result = worker.read_current_line(ctx, document, request.currentLineBrowse)
result = worker.readCurrentLine(ctx, document, request.currentLineBrowse)
result.FlatSpeech = request.flatSpeech
} else if request.listSelection != nil {
result, document = worker.selectDocumentList(ctx, document, request.listSelection)
} else if request.brailleRoute != nil {
result = worker.route_document_braille(ctx, document, request)
result = worker.routeDocumentBraille(ctx, document, request)
} else if request.nativeCaret {
result, document = worker.syncDocumentCaret(ctx, document, request)
} else if request.readPosition != nil {