hterm: Improve accessibility command output
This improves accessibility command output in several ways:
1) Rather than using multiple elements for rendering the output to a
live region, instead we use a single <p> element which we manipulate the
aria-label attribute of. This is far more performant than the existing
solution. Because of this, it's no longer necessary to limit the amount
of output that we add per iteration which also simplifies logic.
2) As a result of the above change, it's necessary to introduce the
additional step of clearing the previous value of the aria-label prior
to setting its new value. This is necessary so that if the same string
is repeated multiple times, the screen reader will actually register it
as an attribute change. This adds an additional delay between iterations
however this can be optimized later if necessary.
3) Rather than inserting newlines between all strings passed to
announce() we instead only do this when there is actually a newline in
the terminal output. This avoids unwanted interruptions in text that
should appear together in the terminal.
Bug: 822490, 646690
Change-Id: I024d13d24f126d31dae3fe0b2a0d8f818740354a
Reviewed-on: https://chromium-review.googlesource.com/1060716
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Raymes Khoury <raymes@chromium.org>
diff --git a/hterm/js/hterm_terminal.js b/hterm/js/hterm_terminal.js
index 306f87b..4b7791a 100644
--- a/hterm/js/hterm_terminal.js
+++ b/hterm/js/hterm_terminal.js
@@ -1776,8 +1776,9 @@
*/
hterm.Terminal.prototype.print = function(str) {
// Basic accessibility output for the screen reader.
- if (this.accessibilityEnabled_)
+ if (this.accessibilityEnabled_) {
this.accessibilityReader_.announce(str);
+ }
var startOffset = 0;
@@ -1790,7 +1791,7 @@
while (startOffset < strWidth) {
if (this.options_.wraparound && this.screen_.cursorPosition.overflow) {
this.screen_.commitLineOverflow();
- this.newLine();
+ this.newLine(true);
}
var count = strWidth - startOffset;
@@ -1903,8 +1904,14 @@
* buffer.
*
* Otherwise, this moves the cursor to column zero of the next row.
+ *
+ * @param {boolean=} dueToOverflow Whether the newline is due to wraparound of
+ * the terminal.
*/
-hterm.Terminal.prototype.newLine = function() {
+hterm.Terminal.prototype.newLine = function(dueToOverflow = false) {
+ if (!dueToOverflow)
+ this.accessibilityReader_.newLine();
+
var cursorAtEndOfScreen = (this.screen_.cursorPosition.row ==
this.screen_.rowsArray.length - 1);