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 Some utilities for defining what groups are.
10 goog.provide('cvox.GroupUtil');
12 goog.require('cvox.AriaUtil');
13 goog.require('cvox.DomUtil');
17 * If a node contains more characters than this, it should not be treated
18 * as a leaf node by the smart navigation algorithm.
20 * This number was determined by looking at the average number of
21 * characters in a paragraph:
22 * http://www.fullondesign.co.uk/design/usability/
23 * 285-how-many-characters-per-a-page-is-normal.htm
24 * and then trying it out on a few popular websites (CNN, BBC,
25 * Google Search, etc.) and making sure it made sense.
30 cvox.GroupUtil.MAX_CHARCOUNT_ = 1500;
34 * If a node contains any of these elements, it should not be treated
35 * as a leaf node by the smart navigation algorithm.
40 cvox.GroupUtil.BREAKOUT_SELECTOR_ = 'blockquote,' +
63 // This takes care of MathJax expressions.
65 // TODO (sorge) Do we want to group all math or only display math?
66 // '[mode="display"],' +
90 // Aria structure roles
104 * Returns true if this is a leaf node for groups.
105 * true for a node => true for all child nodes
106 * true if node has no children
107 * @param {!Node} node The node to check.
108 * @return {boolean} true if this is at the "leaf node" level or lower
109 * for this granularity.
111 cvox.GroupUtil.isLeafNode = function(node) {
112 // TODO (stoarca): Write test to make sure that this function satisfies
113 // the restriction given above.
114 if (node.tagName == 'LABEL') {
115 return cvox.DomUtil.isLeafNode(node);
117 if (cvox.DomUtil.isLeafNode(node)) {
121 if (!cvox.DomUtil.isSemanticElt(node)) {
122 var breakingNodes = node.querySelectorAll(
123 cvox.GroupUtil.BREAKOUT_SELECTOR_);
125 for (var i = 0; i < breakingNodes.length; ++i) {
126 if (cvox.DomUtil.hasContent(breakingNodes[i])) {
132 if (cvox.AriaUtil.isCompositeControl(node) &&
133 !cvox.DomUtil.isFocusable(node)) {
137 var content = cvox.DomUtil.collapseWhitespace(
138 cvox.DomUtil.getValue(node) + ' ' +
139 cvox.DomUtil.getName(node));
140 if (content.length > cvox.GroupUtil.MAX_CHARCOUNT_) {
144 if (content.replace(/\s/g, '') === '') {
145 // Text only contains whitespace