dommy 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dommy/animation.rb +1 -0
- data/lib/dommy/backend.rb +3 -0
- data/lib/dommy/blob.rb +6 -0
- data/lib/dommy/browser.rb +12 -4
- data/lib/dommy/character_data.rb +1 -13
- data/lib/dommy/cookie_store.rb +2 -1
- data/lib/dommy/document.rb +67 -30
- data/lib/dommy/element.rb +11 -0
- data/lib/dommy/element_internals.rb +12 -0
- data/lib/dommy/encodings/legacy_multibyte.rb +800 -0
- data/lib/dommy/encodings/multibyte_overrides.rb +76 -0
- data/lib/dommy/encodings/prescan.rb +234 -0
- data/lib/dommy/encodings.rb +121 -57
- data/lib/dommy/event.rb +107 -54
- data/lib/dommy/event_source.rb +1 -0
- data/lib/dommy/fetch.rb +244 -53
- data/lib/dommy/file_reader.rb +1 -0
- data/lib/dommy/form_data.rb +22 -9
- data/lib/dommy/form_entry_list.rb +3 -3
- data/lib/dommy/html_canvas_element.rb +85 -12
- data/lib/dommy/html_elements/base.rb +1 -0
- data/lib/dommy/html_elements/forms/input.rb +3 -0
- data/lib/dommy/html_elements/interactive.rb +56 -48
- data/lib/dommy/html_elements/metadata.rb +23 -0
- data/lib/dommy/interaction/form_submission.rb +24 -42
- data/lib/dommy/internal/accessibility_tree.rb +149 -162
- data/lib/dommy/internal/accessibility_visibility.rb +16 -17
- data/lib/dommy/internal/accessible_name.rb +231 -246
- data/lib/dommy/internal/aria_role.rb +182 -195
- data/lib/dommy/internal/aria_snapshot.rb +35 -38
- data/lib/dommy/internal/aria_state.rb +102 -118
- data/lib/dommy/internal/autofill.rb +75 -75
- data/lib/dommy/internal/backend_prefilter.rb +127 -130
- data/lib/dommy/internal/child_navigable.rb +86 -83
- data/lib/dommy/internal/close_watcher_manager.rb +1 -0
- data/lib/dommy/internal/css/ancestor_filter.rb +64 -64
- data/lib/dommy/internal/css/calc.rb +90 -71
- data/lib/dommy/internal/css/cascade.rb +69 -67
- data/lib/dommy/internal/css/color.rb +249 -187
- data/lib/dommy/internal/css/computed_style_builder.rb +34 -0
- data/lib/dommy/internal/css/computed_style_declaration.rb +50 -11
- data/lib/dommy/internal/css/counters.rb +67 -67
- data/lib/dommy/internal/css/custom_properties.rb +114 -114
- data/lib/dommy/internal/css/parser.rb +277 -239
- data/lib/dommy/internal/css/property_registry.rb +321 -302
- data/lib/dommy/internal/css/renderability.rb +37 -35
- data/lib/dommy/internal/css/rule_index.rb +2 -2
- data/lib/dommy/internal/css/rule_index_inputs.rb +2 -2
- data/lib/dommy/internal/css/supports.rb +115 -113
- data/lib/dommy/internal/css/ua_stylesheet.rb +55 -53
- data/lib/dommy/internal/css_rule_text.rb +121 -119
- data/lib/dommy/internal/css_source.rb +1 -3
- data/lib/dommy/internal/css_syntax.rb +157 -92
- data/lib/dommy/internal/declarative_shadow_roots.rb +1 -0
- data/lib/dommy/internal/directionality.rb +120 -123
- data/lib/dommy/internal/document_live_ranges.rb +26 -1
- data/lib/dommy/internal/dom_matching.rb +185 -184
- data/lib/dommy/internal/element_geometry.rb +8 -1
- data/lib/dommy/internal/element_matching.rb +71 -69
- data/lib/dommy/internal/element_shadow.rb +1 -13
- data/lib/dommy/internal/element_state.rb +255 -265
- data/lib/dommy/internal/event_handlers.rb +66 -64
- data/lib/dommy/internal/exception_report.rb +88 -86
- data/lib/dommy/internal/focusability.rb +205 -205
- data/lib/dommy/internal/global_functions.rb +49 -47
- data/lib/dommy/internal/idl_reflection.rb +99 -97
- data/lib/dommy/internal/js_number.rb +35 -33
- data/lib/dommy/internal/light_dismiss.rb +130 -132
- data/lib/dommy/internal/literal_lookup.rb +75 -75
- data/lib/dommy/internal/mime_type.rb +54 -49
- data/lib/dommy/internal/mutation_coordinator.rb +46 -0
- data/lib/dommy/internal/mutation_observer_microtask.rb +60 -0
- data/lib/dommy/internal/namespaces.rb +51 -49
- data/lib/dommy/internal/node_adopter.rb +25 -1
- data/lib/dommy/internal/node_equality.rb +61 -59
- data/lib/dommy/internal/post_insertion_steps.rb +1 -0
- data/lib/dommy/internal/referrer.rb +144 -0
- data/lib/dommy/internal/rendered_text/collector.rb +22 -3
- data/lib/dommy/internal/rendered_text/computed_box.rb +3 -2
- data/lib/dommy/internal/rendered_text/fragment.rb +37 -38
- data/lib/dommy/internal/rendered_text/items.rb +7 -5
- data/lib/dommy/internal/selector_matcher.rb +361 -359
- data/lib/dommy/internal/selector_parser.rb +74 -62
- data/lib/dommy/internal/sequential_focus_navigation.rb +150 -151
- data/lib/dommy/internal/shadow_root_registry.rb +7 -0
- data/lib/dommy/internal/slot_assignment.rb +117 -0
- data/lib/dommy/internal/slot_signals.rb +125 -0
- data/lib/dommy/internal/unsafe_html.rb +79 -77
- data/lib/dommy/internal/url_parser.rb +5 -29
- data/lib/dommy/internal/web_idl.rb +158 -153
- data/lib/dommy/internal/window_bound.rb +14 -0
- data/lib/dommy/internal/window_constructors.rb +3 -0
- data/lib/dommy/internal/xml_serialization.rb +298 -296
- data/lib/dommy/js/dom_interfaces.rb +13 -1
- data/lib/dommy/js/host_bridge.rb +23 -1
- data/lib/dommy/js/host_callbacks.rb +7 -0
- data/lib/dommy/js/host_runtime.js +625 -61
- data/lib/dommy/js/import_map.rb +1 -1
- data/lib/dommy/js/observable_runtime.js +295 -128
- data/lib/dommy/js/webidl_members.js +1 -1
- data/lib/dommy/js/webidl_signatures.js +35 -6
- data/lib/dommy/media_query_list.rb +1 -0
- data/lib/dommy/message_channel.rb +2 -0
- data/lib/dommy/mutation_observer.rb +25 -29
- data/lib/dommy/navigator.rb +4 -1
- data/lib/dommy/node.rb +4 -0
- data/lib/dommy/notification.rb +1 -0
- data/lib/dommy/promise.rb +12 -0
- data/lib/dommy/range.rb +20 -3
- data/lib/dommy/shadow_root.rb +25 -1
- data/lib/dommy/streams.rb +18 -0
- data/lib/dommy/style_declaration.rb +15 -4
- data/lib/dommy/text_codec.rb +7 -5
- data/lib/dommy/tree_walker.rb +68 -61
- data/lib/dommy/version.rb +1 -1
- data/lib/dommy/web_socket.rb +1 -0
- data/lib/dommy/window.rb +22 -4
- data/lib/dommy/worker.rb +1 -0
- data/lib/dommy/xml_http_request.rb +12 -2
- data/lib/dommy.rb +17 -2
- metadata +11 -3
|
@@ -49,230 +49,217 @@ module Dommy
|
|
|
49
49
|
|
|
50
50
|
extend NodeIdentity
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
INPUT_ROLES = {
|
|
53
|
+
"button" => "button", "submit" => "button", "reset" => "button",
|
|
54
|
+
"image" => "button", "file" => "button", "checkbox" => "checkbox", "radio" => "radio",
|
|
55
|
+
"range" => "slider", "number" => "spinbutton", "email" => "textbox",
|
|
56
|
+
"tel" => "textbox", "text" => "textbox", "url" => "textbox", "search" => "searchbox",
|
|
57
|
+
# type=password has no ARIA role per HTML-AAM (to avoid exposing the
|
|
58
|
+
# value) but Chromium / Playwright expose it as a textbox. The
|
|
59
|
+
# date/time family and color likewise expose as a textbox.
|
|
60
|
+
"password" => "textbox", "color" => "textbox", "date" => "textbox",
|
|
61
|
+
"datetime-local" => "textbox", "month" => "textbox", "week" => "textbox",
|
|
62
|
+
"time" => "textbox"
|
|
63
|
+
}.freeze
|
|
58
64
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return aria.to_i if aria.match?(/\A\d+\z/) && aria.to_i.positive?
|
|
65
|
+
class << self
|
|
66
|
+
# The computed role string, or "" when the element maps to no role.
|
|
67
|
+
def compute(element)
|
|
68
|
+
explicit_role(element) || implicit_role(element) || ""
|
|
69
|
+
end
|
|
65
70
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
# The heading level for a heading element: an explicit positive
|
|
72
|
+
# `aria-level`, else the `hN` tag's number, else nil. The role itself
|
|
73
|
+
# stays "heading" (level is a separate ARIA property the a11y tree emits).
|
|
74
|
+
def heading_level(element)
|
|
75
|
+
aria = element.__internal_attribute_value__("aria-level").to_s
|
|
76
|
+
return aria.to_i if aria.match?(/\A\d+\z/) && aria.to_i.positive?
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return nil if raw.empty?
|
|
73
|
-
|
|
74
|
-
raw.split(/\s+/).each do |token|
|
|
75
|
-
role = SYNONYMS.fetch(token.downcase, token.downcase)
|
|
76
|
-
next unless CONCRETE.include?(role) && !ABSTRACT.include?(role)
|
|
77
|
-
# region / form need an author-supplied name; otherwise fall through to
|
|
78
|
-
# the next token (or the implicit role).
|
|
79
|
-
next if NAME_REQUIRED.include?(role) && !named?(element)
|
|
80
|
-
# A presentational role yields to the implicit role when the element is
|
|
81
|
-
# focusable or carries a global ARIA state/property (conflict
|
|
82
|
-
# resolution); otherwise it stands.
|
|
83
|
-
return nil if role == "none" && presentation_conflict?(element)
|
|
84
|
-
|
|
85
|
-
return role
|
|
78
|
+
tag = element.local_name.to_s.downcase
|
|
79
|
+
tag.match?(/\Ah[1-6]\z/) ? tag[1].to_i : nil
|
|
86
80
|
end
|
|
87
|
-
nil
|
|
88
|
-
end
|
|
89
81
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
when "form" then named?(element) ? "form" : "generic"
|
|
111
|
-
when "h1", "h2", "h3", "h4", "h5", "h6" then "heading"
|
|
112
|
-
when "header" then landmark_or_generic(element, "banner")
|
|
113
|
-
when "hr" then "separator"
|
|
114
|
-
when "img" then img_role(element)
|
|
115
|
-
when "input" then input_role(element)
|
|
116
|
-
when "ins" then "insertion"
|
|
117
|
-
when "li" then "listitem"
|
|
118
|
-
when "main" then "main"
|
|
119
|
-
when "mark" then "mark"
|
|
120
|
-
when "math" then "math"
|
|
121
|
-
when "menu", "ol", "ul" then "list"
|
|
122
|
-
when "meter" then "meter"
|
|
123
|
-
when "nav" then "navigation"
|
|
124
|
-
when "optgroup" then "group"
|
|
125
|
-
when "option" then "option"
|
|
126
|
-
when "output" then "status"
|
|
127
|
-
when "p" then "paragraph"
|
|
128
|
-
when "progress" then "progressbar"
|
|
129
|
-
when "search" then "search"
|
|
130
|
-
when "section" then named?(element) ? "region" : "generic"
|
|
131
|
-
when "select" then select_role(element)
|
|
132
|
-
when "strong" then "strong"
|
|
133
|
-
when "sub" then "subscript"
|
|
134
|
-
when "sup" then "superscript"
|
|
135
|
-
when "table" then "table"
|
|
136
|
-
when "tbody", "tfoot", "thead" then "rowgroup"
|
|
137
|
-
when "td" then "cell"
|
|
138
|
-
when "textarea" then "textbox"
|
|
139
|
-
when "th" then th_role(element)
|
|
140
|
-
when "time" then "time"
|
|
141
|
-
when "tr" then "row"
|
|
82
|
+
private
|
|
83
|
+
|
|
84
|
+
def explicit_role(element)
|
|
85
|
+
raw = element.__internal_aria_value__("role").to_s.strip
|
|
86
|
+
return nil if raw.empty?
|
|
87
|
+
|
|
88
|
+
raw.split(/\s+/).each do |token|
|
|
89
|
+
role = SYNONYMS.fetch(token.downcase, token.downcase)
|
|
90
|
+
next unless CONCRETE.include?(role) && !ABSTRACT.include?(role)
|
|
91
|
+
# region / form need an author-supplied name; otherwise fall through to
|
|
92
|
+
# the next token (or the implicit role).
|
|
93
|
+
next if NAME_REQUIRED.include?(role) && !named?(element)
|
|
94
|
+
# A presentational role yields to the implicit role when the element is
|
|
95
|
+
# focusable or carries a global ARIA state/property (conflict
|
|
96
|
+
# resolution); otherwise it stands.
|
|
97
|
+
return nil if role == "none" && presentation_conflict?(element)
|
|
98
|
+
|
|
99
|
+
return role
|
|
100
|
+
end
|
|
101
|
+
nil
|
|
142
102
|
end
|
|
143
|
-
end
|
|
144
103
|
|
|
145
|
-
|
|
104
|
+
def implicit_role(element)
|
|
105
|
+
case element.tag_name.to_s.downcase
|
|
106
|
+
when "a", "area" then element.__internal_has_attribute__?("href") ? "link" : (element.tag_name.casecmp?("a") ? "generic" : nil)
|
|
107
|
+
when "article" then "article"
|
|
108
|
+
when "aside" then "complementary"
|
|
109
|
+
when "b", "bdi", "bdo", "data", "i", "q", "samp", "small", "span", "u", "div" then "generic"
|
|
110
|
+
when "blockquote" then "blockquote"
|
|
111
|
+
when "button" then "button"
|
|
112
|
+
when "caption" then "caption"
|
|
113
|
+
when "code" then "code"
|
|
114
|
+
when "del" then "deletion"
|
|
115
|
+
when "dialog" then "dialog"
|
|
116
|
+
when "dd" then "definition"
|
|
117
|
+
when "details" then "group"
|
|
118
|
+
when "dfn" then "term"
|
|
119
|
+
when "dt" then "term"
|
|
120
|
+
when "em" then "emphasis"
|
|
121
|
+
when "fieldset" then "group"
|
|
122
|
+
when "figure" then "figure"
|
|
123
|
+
when "footer" then landmark_or_generic(element, "contentinfo")
|
|
124
|
+
when "form" then named?(element) ? "form" : "generic"
|
|
125
|
+
when "h1", "h2", "h3", "h4", "h5", "h6" then "heading"
|
|
126
|
+
when "header" then landmark_or_generic(element, "banner")
|
|
127
|
+
when "hr" then "separator"
|
|
128
|
+
when "img" then img_role(element)
|
|
129
|
+
when "input" then input_role(element)
|
|
130
|
+
when "ins" then "insertion"
|
|
131
|
+
when "li" then "listitem"
|
|
132
|
+
when "main" then "main"
|
|
133
|
+
when "mark" then "mark"
|
|
134
|
+
when "math" then "math"
|
|
135
|
+
when "menu", "ol", "ul" then "list"
|
|
136
|
+
when "meter" then "meter"
|
|
137
|
+
when "nav" then "navigation"
|
|
138
|
+
when "optgroup" then "group"
|
|
139
|
+
when "option" then "option"
|
|
140
|
+
when "output" then "status"
|
|
141
|
+
when "p" then "paragraph"
|
|
142
|
+
when "progress" then "progressbar"
|
|
143
|
+
when "search" then "search"
|
|
144
|
+
when "section" then named?(element) ? "region" : "generic"
|
|
145
|
+
when "select" then select_role(element)
|
|
146
|
+
when "strong" then "strong"
|
|
147
|
+
when "sub" then "subscript"
|
|
148
|
+
when "sup" then "superscript"
|
|
149
|
+
when "table" then "table"
|
|
150
|
+
when "tbody", "tfoot", "thead" then "rowgroup"
|
|
151
|
+
when "td" then "cell"
|
|
152
|
+
when "textarea" then "textbox"
|
|
153
|
+
when "th" then th_role(element)
|
|
154
|
+
when "time" then "time"
|
|
155
|
+
when "tr" then "row"
|
|
156
|
+
end
|
|
157
|
+
end
|
|
146
158
|
|
|
147
|
-
|
|
148
|
-
alt = element.__internal_attribute_value__("alt")
|
|
149
|
-
# An explicitly empty alt makes the image presentational. Return the
|
|
150
|
-
# canonical "none" (not its "presentation" synonym) so the accessibility
|
|
151
|
-
# tree flattens it like any other presentational node.
|
|
152
|
-
alt == "" ? "none" : "image"
|
|
153
|
-
end
|
|
159
|
+
# --- helpers --------------------------------------------------------
|
|
154
160
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
when "row", "rowgroup" then "rowheader"
|
|
162
|
-
when "col", "colgroup" then "columnheader"
|
|
163
|
-
else auto_th_role(element)
|
|
161
|
+
def img_role(element)
|
|
162
|
+
alt = element.__internal_attribute_value__("alt")
|
|
163
|
+
# An explicitly empty alt makes the image presentational. Return the
|
|
164
|
+
# canonical "none" (not its "presentation" synonym) so the accessibility
|
|
165
|
+
# tree flattens it like any other presentational node.
|
|
166
|
+
alt == "" ? "none" : "image"
|
|
164
167
|
end
|
|
165
|
-
end
|
|
166
168
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
169
|
+
# A <th> is a column or row header. An explicit `scope` wins; otherwise the
|
|
170
|
+
# auto algorithm: a header cell that borders a data cell (<td>) within its
|
|
171
|
+
# row heads that row, so it is a row header; a header cell with only header
|
|
172
|
+
# neighbors heads its column.
|
|
173
|
+
def th_role(element)
|
|
174
|
+
case element.__internal_attribute_value__("scope").to_s.downcase
|
|
175
|
+
when "row", "rowgroup" then "rowheader"
|
|
176
|
+
when "col", "colgroup" then "columnheader"
|
|
177
|
+
else auto_th_role(element)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
170
180
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
181
|
+
def auto_th_role(element)
|
|
182
|
+
row = element.respond_to?(:parent_element) ? element.parent_element : nil
|
|
183
|
+
return "columnheader" unless row
|
|
174
184
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
end
|
|
185
|
+
cells = row.children.select { |cell| %w[td th].include?(cell.local_name.to_s.downcase) }
|
|
186
|
+
index = cells.index { |cell| same_node?(cell, element) }
|
|
187
|
+
return "columnheader" unless index
|
|
179
188
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
"tel" => "textbox", "text" => "textbox", "url" => "textbox", "search" => "searchbox",
|
|
185
|
-
# type=password has no ARIA role per HTML-AAM (to avoid exposing the
|
|
186
|
-
# value) but Chromium / Playwright expose it as a textbox. The
|
|
187
|
-
# date/time family and color likewise expose as a textbox.
|
|
188
|
-
"password" => "textbox", "color" => "textbox", "date" => "textbox",
|
|
189
|
-
"datetime-local" => "textbox", "month" => "textbox", "week" => "textbox",
|
|
190
|
-
"time" => "textbox"
|
|
191
|
-
}.freeze
|
|
189
|
+
previous = index.zero? ? nil : cells[index - 1]
|
|
190
|
+
neighbors = [previous, cells[index + 1]].compact
|
|
191
|
+
neighbors.any? { |cell| cell.local_name.to_s.casecmp?("td") } ? "rowheader" : "columnheader"
|
|
192
|
+
end
|
|
192
193
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
def input_role(element)
|
|
195
|
+
type = element.__internal_attribute_value__("type").to_s.downcase
|
|
196
|
+
return "textbox" if type.empty?
|
|
196
197
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
# `type=search` is `combobox` when the control has a suggestions list
|
|
199
|
+
# and `searchbox` otherwise; INPUT_ROLES maps it to searchbox, because
|
|
200
|
+
# Dommy has no list to consult.
|
|
201
|
+
INPUT_ROLES[type]
|
|
202
|
+
end
|
|
202
203
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
204
|
+
def select_role(element)
|
|
205
|
+
multiple = element.__internal_has_attribute__?("multiple")
|
|
206
|
+
size = element.__internal_attribute_value__("size").to_s.to_i
|
|
207
|
+
multiple || size > 1 ? "listbox" : "combobox"
|
|
208
|
+
end
|
|
208
209
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
210
|
+
# <header>/<footer> are landmarks only when not scoped to sectioning
|
|
211
|
+
# content; otherwise generic.
|
|
212
|
+
def landmark_or_generic(element, landmark)
|
|
213
|
+
node = element.__dommy_backend_node__&.parent
|
|
214
|
+
while node
|
|
215
|
+
return "generic" if SECTIONING.include?(node.name.to_s.downcase)
|
|
215
216
|
|
|
216
|
-
|
|
217
|
+
node = node.parent
|
|
218
|
+
end
|
|
219
|
+
landmark
|
|
217
220
|
end
|
|
218
|
-
landmark
|
|
219
|
-
end
|
|
220
221
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
def named?(element)
|
|
223
|
+
return true if present?(element.__internal_aria_value__("aria-label"))
|
|
224
|
+
return true if references?(element, "aria-labelledby")
|
|
224
225
|
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
present?(element.__internal_attribute_value__("title"))
|
|
227
|
+
end
|
|
227
228
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
def present?(value)
|
|
230
|
+
!value.nil? && !value.to_s.empty?
|
|
231
|
+
end
|
|
231
232
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
233
|
+
# Whether an element-list attribute says something: a value, or the
|
|
234
|
+
# elements set through its reflection (which leave the value "").
|
|
235
|
+
def references?(element, attribute)
|
|
236
|
+
present?(element.__internal_attribute_value__(attribute)) ||
|
|
237
|
+
!element.__internal_aria_associated_elements__(attribute).to_a.empty?
|
|
238
|
+
end
|
|
238
239
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
# Presentation conflict resolution (simplified): a focusable element or one
|
|
241
|
+
# with a global ARIA attribute keeps its implicit role.
|
|
242
|
+
def presentation_conflict?(element)
|
|
243
|
+
return true if focusable?(element)
|
|
243
244
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
present?(element.__internal_aria_value__("aria-label")) ||
|
|
246
|
+
%w[aria-labelledby aria-describedby].any? { |a| references?(element, a) }
|
|
247
|
+
end
|
|
247
248
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
249
|
+
# Whether the element is focusable — a tabindex, or a natively-focusable
|
|
250
|
+
# control (a/area with href, or a non-disabled form control). Native
|
|
251
|
+
# focusability matters: <a href role=presentation> is still a link.
|
|
252
|
+
def focusable?(element)
|
|
253
|
+
return true if present?(element.__internal_attribute_value__("tabindex"))
|
|
254
|
+
|
|
255
|
+
case element.local_name.to_s.downcase
|
|
256
|
+
when "a", "area" then element.__internal_has_attribute__?("href")
|
|
257
|
+
when "button", "select", "textarea" then !element.__internal_has_attribute__?("disabled")
|
|
258
|
+
when "input" then element.__internal_attribute_value__("type").to_s.downcase != "hidden" && !element.__internal_has_attribute__?("disabled")
|
|
259
|
+
else false
|
|
260
|
+
end
|
|
259
261
|
end
|
|
260
262
|
end
|
|
261
|
-
|
|
262
|
-
# Everything below compute is how it is computed, not API.
|
|
263
|
-
private_class_method :explicit_role
|
|
264
|
-
private_class_method :implicit_role
|
|
265
|
-
private_class_method :img_role
|
|
266
|
-
private_class_method :th_role
|
|
267
|
-
private_class_method :auto_th_role
|
|
268
|
-
private_class_method :input_role
|
|
269
|
-
private_class_method :select_role
|
|
270
|
-
private_class_method :landmark_or_generic
|
|
271
|
-
private_class_method :named?
|
|
272
|
-
private_class_method :present?
|
|
273
|
-
private_class_method :references?
|
|
274
|
-
private_class_method :presentation_conflict?
|
|
275
|
-
private_class_method :focusable?
|
|
276
263
|
end
|
|
277
264
|
end
|
|
278
265
|
end
|
|
@@ -17,53 +17,50 @@ module Dommy
|
|
|
17
17
|
# neither in its snapshot — so they stay out of this list.
|
|
18
18
|
FLAG_ORDER = %i[checked disabled expanded level pressed selected].freeze
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
class << self
|
|
21
|
+
def serialize(root)
|
|
22
|
+
lines = []
|
|
23
|
+
root.children.each { |child| emit(child, 0, lines) }
|
|
24
|
+
return "" if lines.empty?
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
root.children.each { |child| emit(child, 0, lines) }
|
|
25
|
-
return "" if lines.empty?
|
|
26
|
+
"#{lines.join("\n")}\n"
|
|
27
|
+
end
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
+
private
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
def emit(node, depth, lines)
|
|
32
|
+
indent = " " * depth
|
|
33
|
+
if node.text?
|
|
34
|
+
lines << "#{indent}- text: #{quote(node.name)}"
|
|
35
|
+
return
|
|
36
|
+
end
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
header = "#{indent}- #{node.role}"
|
|
39
|
+
header += " #{quote(node.name)}" unless node.name.to_s.empty?
|
|
40
|
+
flags(node.states).each { |flag| header += " #{flag}" }
|
|
41
|
+
header += ":" unless node.children.empty?
|
|
42
|
+
lines << header
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
node.children.each { |child| emit(child, depth + 1, lines) }
|
|
45
|
+
end
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
# The bracketed flag tokens for a node's states, in FLAG_ORDER. Booleans
|
|
48
|
+
# render only when true/"mixed"; a "mixed" value renders `[flag=mixed]`.
|
|
49
|
+
def flags(states)
|
|
50
|
+
FLAG_ORDER.filter_map do |key|
|
|
51
|
+
value = states[key]
|
|
52
|
+
if key == :level
|
|
53
|
+
"[level=#{value}]" if value
|
|
54
|
+
elsif value == "mixed"
|
|
55
|
+
"[#{key}=mixed]"
|
|
56
|
+
elsif value == true
|
|
57
|
+
"[#{key}]"
|
|
58
|
+
end
|
|
57
59
|
end
|
|
58
60
|
end
|
|
59
|
-
end
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
# Everything below compute is how it is computed, not API.
|
|
64
|
-
private_class_method :emit
|
|
65
|
-
private_class_method :flags
|
|
66
|
-
private_class_method :quote
|
|
62
|
+
def quote(text) = "\"#{text.to_s.gsub("\\", "\\\\\\\\").gsub("\"", "\\\"")}\""
|
|
63
|
+
end
|
|
67
64
|
end
|
|
68
65
|
end
|
|
69
66
|
end
|