1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * @fileoverview A JavaScript class for walking lines.
10 goog.provide('cvox.StructuralLineWalker');
12 goog.require('cvox.AbstractSelectionWalker');
13 goog.require('cvox.BrailleUtil');
14 goog.require('cvox.TraverseContent');
18 * @extends {cvox.AbstractSelectionWalker}
20 cvox.StructuralLineWalker = function() {
22 this.grain = cvox.TraverseContent.kLine;
24 goog.inherits(cvox.StructuralLineWalker, cvox.AbstractSelectionWalker);
30 cvox.StructuralLineWalker.prototype.getGranularityMsg = function() {
31 return cvox.ChromeVox.msgs.getMsg('structural_line');
38 cvox.StructuralLineWalker.prototype.getDescription = function(prevSel, sel) {
39 var desc = goog.base(this, 'getDescription', prevSel, sel);
40 desc[0].text = cvox.DomUtil.getPrefixText(
41 sel.absStart().node, sel.absStart().index) + desc[0].text;
49 cvox.StructuralLineWalker.prototype.getBraille = function(prevSel, sel) {
50 var braille = goog.base(this, 'getBraille', prevSel, sel);
52 var objNode = this.objWalker_.sync(sel).absStart().node;
53 var node = sel.absStart().node;
54 var prevNode = prevSel.absEnd().node;
56 // Show only the visible line in braille for DOM ranges. This overrides any
57 // labels computed for the node.
59 // <textarea> needs to be treated specially. It may have TextNode children,
60 // but these reflect the initial value of the node only, and are not updated
61 // as content changes.
63 if (!sel.start.equals(sel.end) &&
64 !cvox.DomPredicates.editTextPredicate([objNode])) {
66 cvox.DomUtil.getPrefixText(sel.absStart().node, sel.absStart().index);
67 name = prefix + sel.getText();
70 cvox.BrailleUtil.getTemplated(prevNode, objNode, {name: name});
71 spannable.setSpan(objNode, 0, spannable.getLength());
72 braille.text = spannable;
74 // Remove any selections.
75 braille.startIndex = 0;