Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview A collection of JavaScript utilities used to simplify working | 6 * @fileoverview A collection of JavaScript utilities used to simplify working |
| 7 * with the DOM. | 7 * with the DOM. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 | 10 |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 for (var labelNodeId, i = 0; labelNodeId = labelNodeIds[i]; i++) { | 473 for (var labelNodeId, i = 0; labelNodeId = labelNodeIds[i]; i++) { |
| 474 var labelNode = document.getElementById(labelNodeId); | 474 var labelNode = document.getElementById(labelNodeId); |
| 475 if (labelNode) { | 475 if (labelNode) { |
| 476 label += ' ' + cvox.DomUtil.getName( | 476 label += ' ' + cvox.DomUtil.getName( |
| 477 labelNode, true, includeControls, true); | 477 labelNode, true, includeControls, true); |
| 478 } | 478 } |
| 479 } | 479 } |
| 480 } else if (node.hasAttribute('aria-label')) { | 480 } else if (node.hasAttribute('aria-label')) { |
| 481 label = node.getAttribute('aria-label'); | 481 label = node.getAttribute('aria-label'); |
| 482 } else if (node.constructor == HTMLImageElement) { | 482 } else if (node.constructor == HTMLImageElement) { |
| 483 label = cvox.DomUtil.getImageTitle(node); | 483 label = 'img ' + cvox.DomUtil.getImageTitle(node); |
| 484 } else if (node.tagName == 'FIELDSET') { | 484 } else if (node.tagName == 'FIELDSET') { |
| 485 // Other labels will trump fieldset legend with this implementation. | 485 // Other labels will trump fieldset legend with this implementation. |
| 486 // Depending on how this works out on the web, we may later switch this | 486 // Depending on how this works out on the web, we may later switch this |
| 487 // to appending the fieldset legend to any existing label. | 487 // to appending the fieldset legend to any existing label. |
| 488 var legends = node.getElementsByTagName('LEGEND'); | 488 var legends = node.getElementsByTagName('LEGEND'); |
| 489 label = ''; | 489 label = ''; |
| 490 for (var legend, i = 0; legend = legends[i]; i++) { | 490 for (var legend, i = 0; legend = legends[i]; i++) { |
| 491 label += ' ' + cvox.DomUtil.getName(legend, true, includeControls); | 491 label += ' ' + cvox.DomUtil.getName(legend, true, includeControls); |
| 492 } | 492 } |
| 493 } | 493 } |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 /** | 913 /** |
| 914 * Given an image node, return its title as a string. The preferred title | 914 * Given an image node, return its title as a string. The preferred title |
| 915 * is always the alt text, and if that's not available, then the title | 915 * is always the alt text, and if that's not available, then the title |
| 916 * attribute. If neither of those are available, it attempts to construct | 916 * attribute. If neither of those are available, it attempts to construct |
| 917 * a title from the filename, and if all else fails returns the word Image. | 917 * a title from the filename, and if all else fails returns the word Image. |
| 918 * @param {Node} node The image node. | 918 * @param {Node} node The image node. |
| 919 * @return {string} The title of the image. | 919 * @return {string} The title of the image. |
| 920 */ | 920 */ |
| 921 cvox.DomUtil.getImageTitle = function(node) { | 921 cvox.DomUtil.getImageTitle = function(node) { |
| 922 var text; | 922 var text; |
| 923 | |
| 923 if (node.hasAttribute('alt')) { | 924 if (node.hasAttribute('alt')) { |
| 924 text = node.alt; | 925 text = node.alt; |
| 926 text = 'alt'; | |
|
dmazzoni
2016/11/04 18:36:07
i'm assuming this is debugging code?
| |
| 925 } else if (node.hasAttribute('title')) { | 927 } else if (node.hasAttribute('title')) { |
| 926 text = node.title; | 928 text = node.title; |
| 929 text = 'title'; | |
| 927 } else { | 930 } else { |
| 928 var url = node.src; | 931 var url = node.src; |
| 929 if (url.substring(0, 4) != 'data') { | 932 if (url.substring(0, 4) != 'data') { |
| 930 var filename = url.substring( | 933 var filename = url.substring( |
| 931 url.lastIndexOf('/') + 1, url.lastIndexOf('.')); | 934 url.lastIndexOf('/') + 1, url.lastIndexOf('.')); |
| 932 | 935 |
| 933 // Hack to not speak the filename if it's ridiculously long. | 936 // Hack to not speak the filename if it's ridiculously long. |
| 934 if (filename.length >= 1 && filename.length <= 16) { | 937 if (filename.length >= 1 && filename.length <= 16) { |
| 935 text = filename + ' Image'; | 938 text = filename + ' Image'; |
| 936 } else { | 939 } else { |
| 937 text = 'Image'; | 940 text = 'Image'; |
| 938 } | 941 } |
| 939 } else { | 942 } else { |
| 940 text = 'Image'; | 943 text = 'Image'; |
| 941 } | 944 } |
| 945 text = 'else ' + text; | |
| 942 } | 946 } |
| 943 return text; | 947 return text; |
| 944 }; | 948 }; |
| 945 | 949 |
| 946 | 950 |
| 947 /** | 951 /** |
| 948 * Search the whole page for any aria-labelledby attributes and collect | 952 * Search the whole page for any aria-labelledby attributes and collect |
| 949 * the complete set of ids they map to, so that we can skip elements that | 953 * the complete set of ids they map to, so that we can skip elements that |
| 950 * just label other elements and not double-speak them. We cache this | 954 * just label other elements and not double-speak them. We cache this |
| 951 * result and then throw it away at the next event loop. | 955 * result and then throw it away at the next event loop. |
| (...skipping 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2601 var describedNode = document.getElementById(describedById); | 2605 var describedNode = document.getElementById(describedById); |
| 2602 if (describedNode) { | 2606 if (describedNode) { |
| 2603 desc += ' ' + cvox.DomUtil.getName( | 2607 desc += ' ' + cvox.DomUtil.getName( |
| 2604 describedNode, true, true, true); | 2608 describedNode, true, true, true); |
| 2605 } | 2609 } |
| 2606 } | 2610 } |
| 2607 } | 2611 } |
| 2608 } | 2612 } |
| 2609 return desc; | 2613 return desc; |
| 2610 }; | 2614 }; |
| OLD | NEW |