Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explorer rewrite tmp #1035

Merged
merged 26 commits into from
Dec 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
11c87d9
Some new explorer experiments.
zorkow Jun 23, 2023
cf5d9d4
Updates chtml focus outline.
zorkow Jul 17, 2023
f4bf28b
Adds corrected types for Walker.
zorkow Jul 17, 2023
2841856
Walker cleanup.
zorkow Jul 25, 2023
58aad7f
Initial attempt at providing subtitles.
zorkow Jul 28, 2023
8d60263
Refactors ssml computations to speech util.
zorkow Jul 30, 2023
460f1e1
SSML extraction works.
zorkow Jul 31, 2023
12414e5
Initial regions mainly working.
zorkow Jul 31, 2023
73beb39
Messing with regions.
zorkow Aug 1, 2023
62d0a6d
Remove as much as possible.
zorkow Aug 3, 2023
cdc2710
Basics of new key explorer working.
zorkow Aug 4, 2023
47b010b
Link triggering on click.
zorkow Aug 5, 2023
1afbe37
Corrects keyboard triggering of links.
zorkow Aug 5, 2023
2cb1708
Improved tabindex and focus handling.
zorkow Aug 5, 2023
b4ad1ce
Removes unused Walker.
zorkow Aug 10, 2023
10b3854
Refactor set aria function.
zorkow Aug 11, 2023
a62b2c5
Refactoring speech computation to utilities.
zorkow Aug 11, 2023
64125e7
Refactoring moves to class level methods.
zorkow Aug 12, 2023
2c22adc
Better setting of speech and braille.
zorkow Aug 12, 2023
172e63c
Key explorer cleanup.
zorkow Aug 13, 2023
ebcb243
Refactors generator to be attached to item.
zorkow Aug 13, 2023
6c80337
Reinstantiates auto voicing.
zorkow Aug 13, 2023
c4449ae
Code cleanup.
zorkow Aug 14, 2023
2952d5e
Code cleanup.
zorkow Aug 14, 2023
693d0f2
Starts explorer on focus as suggested by @pkra.
zorkow Sep 6, 2023
59a778e
PR #987 incorporate review suggestions
zorkow Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds corrected types for Walker.
zorkow authored and dpvc committed Dec 9, 2023
commit f4bf28bc5dd3643c7d5a454583de227d068576b7
38 changes: 16 additions & 22 deletions ts/a11y/explorer/KeyExplorer.ts
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ export abstract class AbstractKeyExplorer<T> extends AbstractExplorer<T> impleme
[
// ['keydown', move],
['keydown', this.KeyDown.bind(this)],
['click', ((e: Event) => click(this.node, e)).bind(this)],
['click', ((e: MouseEvent) => click(this.node, e)).bind(this)],
['focusin', this.FocusIn.bind(this)],
['focusout', this.FocusOut.bind(this)]
]);
@@ -196,16 +196,10 @@ export abstract class AbstractKeyExplorer<T> extends AbstractExplorer<T> impleme
/**
* @override
*/
public Move(key: number) {
// let result = this.walker.move(key);
let result = move(key);
if (result) {
this.Update();
return;
}
if (this.sound) {
this.NoMove();
}
public Move(_key: number) {
// // let result = this.walker.move(key);
// let result = false;
// // let result = move(key);
}

/**
@@ -272,7 +266,6 @@ export class SpeechExplorer extends AbstractKeyExplorer<string> {
* @override
*/
public Start() {
console.log(16);
if (!this.attached) return;
let options = this.getOptions();
if (!this.init) {
@@ -296,7 +289,6 @@ export class SpeechExplorer extends AbstractKeyExplorer<string> {
this.Start();
});
})
.catch((error: Error) => console.log(error.message));
return;
}
super.Start();
@@ -368,10 +360,6 @@ export class SpeechExplorer extends AbstractKeyExplorer<string> {
*/
public KeyDown(event: KeyboardEvent) {
const code = event.keyCode;
console.log(event);
console.log(event.key);
console.log(event.code);
console.log(code);
this.walker.modifier = event.shiftKey;
if (code === 17) {
speechSynthesis.cancel();
@@ -382,9 +370,17 @@ export class SpeechExplorer extends AbstractKeyExplorer<string> {
this.stopEvent(event);
return;
}
console.log(9);
move(event);
console.log(13);
//
let result = move(event);
if (result) {
this.region.Show(this.node, this.highlighter);
this.region.Update('hello');
return;
}
if (this.sound) {
this.NoMove();
}
//
if (this.triggerLink(code)) return;
this.stopEvent(event);
if (code === 32 && event.shiftKey || code === 13) {
@@ -398,7 +394,6 @@ export class SpeechExplorer extends AbstractKeyExplorer<string> {
* @param {number} code The keycode of the last key pressed.
*/
protected triggerLink(code: number) {
console.log(15);
if (code !== 13) {
return false;
}
@@ -407,7 +402,6 @@ export class SpeechExplorer extends AbstractKeyExplorer<string> {
getAttribute('data-semantic-postfix')?.
match(/(^| )link($| )/);
if (focus) {
console.log(14);
node.parentNode.dispatchEvent(new MouseEvent('click'));
return true;
}
40 changes: 22 additions & 18 deletions ts/a11y/explorer/Walker.ts
Original file line number Diff line number Diff line change
@@ -27,12 +27,12 @@
const codeSelector = 'mjx-container[role="application"][data-shellac]';
const nav = '[role="application"][data-shellac],[role="tree"],[role="group"],[role="treeitem"]';

function isCodeBlock(el) {
function isCodeBlock(el: HTMLElement) {
return el.matches(codeSelector);
}

export function click(snippet, e) {
const clicked = e.target.closest(nav);
export function click(snippet: HTMLElement, e: MouseEvent) {
const clicked = (e.target as HTMLElement).closest(nav) as HTMLElement;
if (snippet.contains(clicked)) {
const prev = snippet.querySelector('[tabindex="0"][role="tree"],[tabindex="0"][role="group"],[tabindex="0"][role="treeitem"]');
if (prev) {
@@ -44,16 +44,16 @@ export function click(snippet, e) {
}
}

export function move(e) {
export function move(e: KeyboardEvent) {

function nextFocus() {
function nextSibling(el) {
const sib = el.nextElementSibling;
function nextFocus(): HTMLElement {
function nextSibling(el: HTMLElement): HTMLElement {
const sib = el.nextElementSibling as HTMLElement;
if (sib) {
if (sib.matches(nav)) {
return sib;
} else {
const sibChild = sib.querySelector(nav);
const sibChild = sib.querySelector(nav) as HTMLElement;
return sibChild ?? nextSibling(sib);
}
} else {
@@ -65,13 +65,13 @@ export function move(e) {
}
}

function prevSibling(el) {
const sib = el.previousElementSibling;
function prevSibling(el: HTMLElement): HTMLElement {
const sib = el.previousElementSibling as HTMLElement;
if (sib) {
if (sib.matches(nav)) {
return sib;
} else {
const sibChild = sib.querySelector(nav);
const sibChild = sib.querySelector(nav) as HTMLElement;
return sibChild ?? prevSibling(sib);
}
} else {
@@ -83,31 +83,35 @@ export function move(e) {
}
}

switch (event.key) {
const target = e.target as HTMLElement;
switch (e.key) {
case "ArrowDown":
e.preventDefault();
return e.target.querySelector(nav);
return target.querySelector(nav);
case "ArrowUp":
e.preventDefault();
return e.target.parentElement.closest(nav);
return target.parentElement.closest(nav);
case "ArrowLeft":
e.preventDefault();
return prevSibling(e.target);
return prevSibling(target);
case "ArrowRight":
e.preventDefault();
return nextSibling(e.target);
return nextSibling(target);
default:
return;
return null;
}
}

const next = nextFocus();


const target = e.target as HTMLElement;
if (next) {
e.target.removeAttribute("tabindex");
target.removeAttribute("tabindex");
next.setAttribute("tabindex", "0");
next.focus();
console.log(next.getAttribute('data-semantic-speech'));
console.log(next.getAttribute('data-semantic-braille'));
return true;
}
return false;