1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview A JavaScript class for walking lines.
*/
goog.provide('cvox.StructuralLineWalker');
goog.require('cvox.AbstractSelectionWalker');
goog.require('cvox.BrailleUtil');
goog.require('cvox.TraverseContent');
/**
* @constructor
* @extends {cvox.AbstractSelectionWalker}
*/
cvox.StructuralLineWalker = function() {
goog.base(this);
this.grain = cvox.TraverseContent.kLine;
};
goog.inherits(cvox.StructuralLineWalker, cvox.AbstractSelectionWalker);
/**
* @override
*/
cvox.StructuralLineWalker.prototype.getGranularityMsg = function() {
return cvox.ChromeVox.msgs.getMsg('structural_line');
};
/**
* @override
*/
cvox.StructuralLineWalker.prototype.getDescription = function(prevSel, sel) {
var desc = goog.base(this, 'getDescription', prevSel, sel);
desc[0].text = cvox.DomUtil.getPrefixText(
sel.absStart().node, sel.absStart().index) + desc[0].text;
return desc;
};
/**
* @override
*/
cvox.StructuralLineWalker.prototype.getBraille = function(prevSel, sel) {
var braille = goog.base(this, 'getBraille', prevSel, sel);
var objNode = this.objWalker_.sync(sel).absStart().node;
var node = sel.absStart().node;
var prevNode = prevSel.absEnd().node;
// Show only the visible line in braille for DOM ranges. This overrides any
// labels computed for the node.
//
// <textarea> needs to be treated specially. It may have TextNode children,
// but these reflect the initial value of the node only, and are not updated
// as content changes.
var name = undefined;
if (!sel.start.equals(sel.end) &&
!cvox.DomPredicates.editTextPredicate([objNode])) {
var prefix =
cvox.DomUtil.getPrefixText(sel.absStart().node, sel.absStart().index);
name = prefix + sel.getText();
}
var spannable =
cvox.BrailleUtil.getTemplated(prevNode, objNode, {name: name});
spannable.setSpan(objNode, 0, spannable.getLength());
braille.text = spannable;
// Remove any selections.
braille.startIndex = 0;
braille.endIndex = 0;
return braille;
};
|