Skip to content

Commit 67c2871

Browse files
authored
Merge pull request #1052 from mathjax/refactor/explorer_depth
Refactor/explorer depth
2 parents c7fdff3 + e4ae4f7 commit 67c2871

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

ts/a11y/explorer/KeyExplorer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type { ExplorerMathItem } from '../explorer.js';
2828
import {Explorer, AbstractExplorer} from './Explorer.js';
2929
import {ExplorerPool} from './ExplorerPool.js';
3030
import {MmlNode} from '../../core/MmlTree/MmlNode.js';
31-
import { honk } from '../speech/SpeechUtil.js';
31+
import { honk, InPlace } from '../speech/SpeechUtil.js';
3232
import {Sre} from '../sre.js';
3333

3434

@@ -295,6 +295,7 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
295295
['<', this.nextStyle.bind(this)],
296296
['x', this.summary.bind(this)],
297297
['-', this.expand.bind(this)],
298+
['d', this.depth.bind(this)],
298299
]);
299300

300301
/**
@@ -308,6 +309,13 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
308309
return parent && this.highlighter.isMactionNode(parent) ? parent : null;
309310
}
310311

312+
public depth(node: HTMLElement): HTMLElement {
313+
this.generators.depth(node, !!this.actionable(node));
314+
this.refocus(node);
315+
this.generators.lastMove = InPlace.DEPTH;
316+
return node;
317+
}
318+
311319
/**
312320
* Expands or collapses the currently focused node.
313321
*
@@ -330,6 +338,7 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
330338
public summary(node: HTMLElement): HTMLElement {
331339
this.generators.summary(node);
332340
this.refocus(node);
341+
this.generators.lastMove = InPlace.SUMMARY;
333342
return node;
334343
}
335344

ts/a11y/speech/GeneratorPool.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {mathjax} from '../../mathjax.js';
1919
import {Sre} from '../sre.js';
2020
import {OptionList} from '../../util/Options.js';
2121
import {LiveRegion} from '../explorer/Region.js';
22-
import { buildLabel, buildSpeech } from '../speech/SpeechUtil.js';
22+
import { buildLabel, buildSpeech, InPlace } from '../speech/SpeechUtil.js';
2323
import { DOMAdaptor } from '../../core/DOMAdaptor.js';
2424

2525
/**
@@ -177,7 +177,7 @@ export class GeneratorPool<N, T, D> {
177177
* @param {N} node The typeset node.
178178
*/
179179
public summary(node: N) {
180-
if (this.lastSummary) {
180+
if (this.lastMove === InPlace.SUMMARY) {
181181
this.CleanUp(node);
182182
return this.lastSpeech;
183183
}
@@ -193,11 +193,11 @@ export class GeneratorPool<N, T, D> {
193193
* @param {N} node
194194
*/
195195
public CleanUp(node: N) {
196-
if (this.lastSummary) {
196+
if (this.lastMove) {
197197
// TODO: Remember the speech.
198198
this.adaptor.setAttribute(node, 'aria-label', buildSpeech(this.getLabel(node))[0]);
199199
}
200-
this.lastSummary = false;
200+
this.lastMove = InPlace.NONE;
201201
}
202202

203203
/**
@@ -206,9 +206,24 @@ export class GeneratorPool<N, T, D> {
206206
private lastSpeech = '';
207207

208208
/**
209-
* Remembers that the last speech computation was a summary.
209+
* Remembers whether the last speech computation was in-place, i.e., a summary
210+
* or depth computation.
210211
*/
211-
private lastSummary = false;
212+
private lastMove_ = InPlace.NONE;
213+
214+
/**
215+
* Getter for last move.
216+
*/
217+
public get lastMove() {
218+
return this.lastMove_;
219+
}
220+
221+
/**
222+
* Setter for last move.
223+
*/
224+
public set lastMove(move: InPlace) {
225+
this.lastMove_ = this.lastSpeech ? move : InPlace.NONE;
226+
}
212227

213228
/**
214229
* Updates the given speech regions, possibly reinstanting previously saved
@@ -225,11 +240,7 @@ export class GeneratorPool<N, T, D> {
225240
) {
226241
let speech = this.getLabel(node, this.lastSpeech);
227242
speechRegion.Update(speech);
228-
// TODO: See if we can reuse the speech from the speech region.
229243
this.adaptor.setAttribute(node, 'aria-label', buildSpeech(speech)[0]);
230-
if (this.lastSpeech) {
231-
this.lastSummary = true;
232-
}
233244
this.lastSpeech = '';
234245
brailleRegion.Update(
235246
this.adaptor.getAttribute(node, 'aria-braillelabel'));
@@ -378,4 +389,19 @@ export class GeneratorPool<N, T, D> {
378389
);
379390
}
380391

392+
public depth(node: N, actionable: boolean) {
393+
if (this.lastMove === InPlace.DEPTH) {
394+
this.CleanUp(node);
395+
return this.lastSpeech;
396+
}
397+
let postfix = this.summaryGenerator.getExpandable(
398+
actionable ?
399+
(this.adaptor.childNodes(node).length === 0 ? -1 : 1)
400+
: 0);
401+
const depth = this.summaryGenerator.getLevel(
402+
this.adaptor.getAttribute(node, 'aria-level'));
403+
this.lastSpeech = `${depth} ${postfix}`;
404+
return this.lastSpeech;
405+
}
406+
381407
}

ts/a11y/speech/SpeechUtil.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,13 @@ export function honk() {
213213
os.start(ac.currentTime);
214214
os.stop(ac.currentTime + .05);
215215
}
216+
217+
/**
218+
* In place speech computations.
219+
*/
220+
export enum InPlace {
221+
NONE,
222+
DEPTH,
223+
SUMMARY
224+
}
225+

0 commit comments

Comments
 (0)