axnode: force manual formatting in switches

In order to uses less space and improve the readability.

zig fmt allows only 1 switch case per line or all in one line.
When having a lot of conditions, splitting the line is useful.
This commit is contained in:
Pierre Tachoire
2026-01-15 08:23:22 +01:00
parent 07acb9308d
commit 7d6ab5a708

View File

@@ -141,7 +141,22 @@ pub const Writer = struct {
} }
const AXProperty = struct { const AXProperty = struct {
name: enum(u8) { actions, busy, disabled, editable, focusable, focused, hidden, hiddenRoot, invalid, keyshortcuts, settable, roledescription, live, atomic, relevant, root, autocomplete, hasPopup, level, multiselectable, orientation, multiline, readonly, required, valuemin, valuemax, valuetext, checked, expanded, modal, pressed, selected, activedescendant, controls, describedby, details, errormessage, flowto, labelledby, owns, url, activeFullscreenElement, activeModalDialog, activeAriaModalDialog, ariaHiddenElement, ariaHiddenSubtree, emptyAlt, emptyText, inertElement, inertSubtree, labelContainer, labelFor, notRendered, notVisible, presentationalRole, probablyPresentational, inactiveCarouselTabContent, uninteresting }, // zig fmt: off
name: enum(u8) {
actions, busy, disabled, editable, focusable, focused, hidden,
hiddenRoot, invalid, keyshortcuts, settable, roledescription, live,
atomic, relevant, root, autocomplete, hasPopup, level,
multiselectable, orientation, multiline, readonly, required,
valuemin, valuemax, valuetext, checked, expanded, modal, pressed,
selected, activedescendant, controls, describedby, details,
errormessage, flowto, labelledby, owns, url,
activeFullscreenElement, activeModalDialog, activeAriaModalDialog,
ariaHiddenElement, ariaHiddenSubtree, emptyAlt, emptyText,
inertElement, inertSubtree, labelContainer, labelFor, notRendered,
notVisible, presentationalRole, probablyPresentational,
inactiveCarouselTabContent, uninteresting,
},
// zig fmt: on
value: AXValue, value: AXValue,
}; };
@@ -337,62 +352,16 @@ pub const Writer = struct {
}; };
pub const AXRole = enum(u8) { pub const AXRole = enum(u8) {
none, // zig fmt: off
article, none, article, banner, blockquote, button, caption, cell, checkbox, code,
banner, columnheader, combobox, complementary, contentinfo, definition, deletion,
blockquote, dialog, document, emphasis, figure, form, group, heading, image, insertion,
button, link, list, listbox, listitem, main, marquee, meter, navigation, option,
caption, paragraph, presentation, progressbar, radio, region, row, rowgroup,
cell, rowheader, searchbox, separator, slider, spinbutton, status, strong,
checkbox, subscript, superscript, table, term, textbox, time, RootWebArea, LineBreak,
code,
columnheader,
combobox,
complementary,
contentinfo,
definition,
deletion,
dialog,
document,
emphasis,
figure,
form,
group,
heading,
image,
insertion,
link,
list,
listbox,
listitem,
main,
marquee,
meter,
navigation,
option,
paragraph,
presentation,
progressbar,
radio,
region,
row,
rowgroup,
rowheader,
searchbox,
separator,
slider,
spinbutton,
status,
strong,
subscript,
superscript,
table,
term,
textbox,
time,
RootWebArea,
LineBreak,
StaticText, StaticText,
// zig fmt: on
fn fromNode(node: *DOMNode) !AXRole { fn fromNode(node: *DOMNode) !AXRole {
return switch (node._type) { return switch (node._type) {
@@ -447,7 +416,10 @@ pub const AXRole = enum(u8) {
.number => .spinbutton, .number => .spinbutton,
.search => .searchbox, .search => .searchbox,
.checkbox => .checkbox, .checkbox => .checkbox,
.password, .datetime_local, .hidden, .month, .color, .week, .time, .file, .date => .none, // zig fmt: off
.password, .datetime_local, .hidden, .month, .color,
.week, .time, .file, .date => .none,
// zig fmt: ofn
}; };
}, },
.textarea => .textbox, .textarea => .textbox,
@@ -616,37 +588,12 @@ fn writeName(axnode: AXNode, w: anytype, page: *Page) !?AXSource {
// TODO Check for <label> with matching "for" attribute // TODO Check for <label> with matching "for" attribute
// TODO Check if input is wrapped in a <label> // TODO Check if input is wrapped in a <label>
}, },
.textarea, // zig fmt: off
.select, .textarea, .select, .img, .audio, .video, .iframe, .embed,
.img, .object, .progress, .meter, .main, .nav, .aside, .header,
.audio, .footer, .form, .section, .article, .ul, .ol, .dl, .menu,
.video, .thead, .tbody, .tfoot, .tr, .td, .div, .span, .p, .details,
.iframe, // zig fmt: on
.embed,
.object,
.progress,
.meter,
.main,
.nav,
.aside,
.header,
.footer,
.form,
.section,
.article,
.ul,
.ol,
.dl,
.menu,
.thead,
.tbody,
.tfoot,
.tr,
.td,
.div,
.span,
.p,
.details,
=> {}, => {},
else => { else => {
// write text content if exists. // write text content if exists.
@@ -708,33 +655,21 @@ fn ignoreText(node: *DOMNode) bool {
// Only ignore text for structural/container elements that typically // Only ignore text for structural/container elements that typically
// don't have meaningful direct text content // don't have meaningful direct text content
return switch (elt.getTag()) { return switch (elt.getTag()) {
// zig fmt: off
// Structural containers // Structural containers
.html, .html, .body, .head,
.body,
.head,
// Lists (text is in li elements, not in ul/ol) // Lists (text is in li elements, not in ul/ol)
.ul, .ul, .ol, .menu,
.ol,
.menu,
// Tables (text is in cells, not in table/tbody/thead/tfoot/tr) // Tables (text is in cells, not in table/tbody/thead/tfoot/tr)
.table, .table, .thead, .tbody, .tfoot, .tr,
.thead,
.tbody,
.tfoot,
.tr,
// Form containers // Form containers
.form, .form, .fieldset, .datalist,
.fieldset,
.datalist,
// Grouping elements // Grouping elements
.details, .details, .figure,
.figure,
// Other containers // Other containers
.select, .select, .optgroup, .colgroup, .script,
.optgroup,
.colgroup,
.script,
=> true, => true,
// zig fmt: on
// All other elements should include their text content // All other elements should include their text content
else => false, else => false,
}; };
@@ -763,7 +698,12 @@ fn isIgnore(self: AXNode, page: *Page) bool {
const elt = node.as(DOMNode.Element); const elt = node.as(DOMNode.Element);
const tag = elt.getTag(); const tag = elt.getTag();
switch (tag) { switch (tag) {
.script, .style, .meta, .link, .title, .base, .head, .noscript, .template, .param, .source, .track, .datalist, .col, .colgroup, .html, .body => return true, // zig fmt: off
.script, .style, .meta, .link, .title, .base, .head, .noscript,
.template, .param, .source, .track, .datalist, .col, .colgroup, .html,
.body
=> return true,
// zig fmt: on
.img => { .img => {
// Check for empty decorative images // Check for empty decorative images
const alt_ = elt.getAttributeSafe("alt"); const alt_ = elt.getAttributeSafe("alt");