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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318
|
/*
* Copyright (C) 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "core/accessibility/AXRenderObject.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/accessibility/AXImageMapLink.h"
#include "core/accessibility/AXInlineTextBox.h"
#include "core/accessibility/AXObjectCache.h"
#include "core/accessibility/AXSVGRoot.h"
#include "core/accessibility/AXSpinButton.h"
#include "core/accessibility/AXTable.h"
#include "core/dom/ElementTraversal.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/editing/FrameSelection.h"
#include "core/editing/RenderedPosition.h"
#include "core/editing/TextIterator.h"
#include "core/editing/VisibleUnits.h"
#include "core/editing/htmlediting.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLLabelElement.h"
#include "core/html/HTMLOptionElement.h"
#include "core/html/HTMLSelectElement.h"
#include "core/html/HTMLTextAreaElement.h"
#include "core/html/shadow/ShadowElementNames.h"
#include "core/loader/ProgressTracker.h"
#include "core/page/Page.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/RenderFieldset.h"
#include "core/rendering/RenderFileUploadControl.h"
#include "core/rendering/RenderHTMLCanvas.h"
#include "core/rendering/RenderImage.h"
#include "core/rendering/RenderInline.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderListMarker.h"
#include "core/rendering/RenderMenuList.h"
#include "core/rendering/RenderTextControlSingleLine.h"
#include "core/rendering/RenderTextFragment.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/RenderWidget.h"
#include "core/svg/SVGDocumentExtensions.h"
#include "core/svg/SVGSVGElement.h"
#include "core/svg/graphics/SVGImage.h"
#include "platform/text/PlatformLocale.h"
#include "wtf/StdLibExtras.h"
using blink::WebLocalizedString;
namespace WebCore {
using namespace HTMLNames;
static inline RenderObject* firstChildInContinuation(const RenderInline& renderer)
{
RenderBoxModelObject* r = renderer.continuation();
while (r) {
if (r->isRenderBlock())
return r;
if (RenderObject* child = r->slowFirstChild())
return child;
r = toRenderInline(r)->continuation();
}
return 0;
}
static inline bool isInlineWithContinuation(RenderObject* object)
{
if (!object->isBoxModelObject())
return false;
RenderBoxModelObject* renderer = toRenderBoxModelObject(object);
if (!renderer->isRenderInline())
return false;
return toRenderInline(renderer)->continuation();
}
static inline RenderObject* firstChildConsideringContinuation(RenderObject* renderer)
{
RenderObject* firstChild = renderer->slowFirstChild();
if (!firstChild && isInlineWithContinuation(renderer))
firstChild = firstChildInContinuation(toRenderInline(*renderer));
return firstChild;
}
static inline RenderInline* startOfContinuations(RenderObject* r)
{
if (r->isInlineElementContinuation()) {
return toRenderInline(r->node()->renderer());
}
// Blocks with a previous continuation always have a next continuation
if (r->isRenderBlock() && toRenderBlock(r)->inlineElementContinuation())
return toRenderInline(toRenderBlock(r)->inlineElementContinuation()->node()->renderer());
return 0;
}
static inline RenderObject* endOfContinuations(RenderObject* renderer)
{
RenderObject* prev = renderer;
RenderObject* cur = renderer;
if (!cur->isRenderInline() && !cur->isRenderBlock())
return renderer;
while (cur) {
prev = cur;
if (cur->isRenderInline()) {
cur = toRenderInline(cur)->inlineElementContinuation();
ASSERT(cur || !toRenderInline(prev)->continuation());
} else {
cur = toRenderBlock(cur)->inlineElementContinuation();
}
}
return prev;
}
static inline bool lastChildHasContinuation(RenderObject* renderer)
{
RenderObject* lastChild = renderer->slowLastChild();
return lastChild && isInlineWithContinuation(lastChild);
}
static RenderBoxModelObject* nextContinuation(RenderObject* renderer)
{
ASSERT(renderer);
if (renderer->isRenderInline() && !renderer->isReplaced())
return toRenderInline(renderer)->continuation();
if (renderer->isRenderBlock())
return toRenderBlock(renderer)->inlineElementContinuation();
return 0;
}
AXRenderObject::AXRenderObject(RenderObject* renderer)
: AXNodeObject(renderer->node())
, m_renderer(renderer)
, m_cachedElementRectDirty(true)
{
#ifndef NDEBUG
m_renderer->setHasAXObject(true);
#endif
}
PassRefPtr<AXRenderObject> AXRenderObject::create(RenderObject* renderer)
{
return adoptRef(new AXRenderObject(renderer));
}
AXRenderObject::~AXRenderObject()
{
ASSERT(isDetached());
}
LayoutRect AXRenderObject::elementRect() const
{
if (!m_explicitElementRect.isEmpty())
return m_explicitElementRect;
if (!m_renderer)
return LayoutRect();
if (!m_renderer->isBox())
return computeElementRect();
for (const AXObject* obj = this; obj; obj = obj->parentObject()) {
if (obj->isAXRenderObject())
toAXRenderObject(obj)->checkCachedElementRect();
}
for (const AXObject* obj = this; obj; obj = obj->parentObject()) {
if (obj->isAXRenderObject())
toAXRenderObject(obj)->updateCachedElementRect();
}
return m_cachedElementRect;
}
void AXRenderObject::setRenderer(RenderObject* renderer)
{
m_renderer = renderer;
setNode(renderer->node());
}
RenderBoxModelObject* AXRenderObject::renderBoxModelObject() const
{
if (!m_renderer || !m_renderer->isBoxModelObject())
return 0;
return toRenderBoxModelObject(m_renderer);
}
Document* AXRenderObject::topDocument() const
{
if (!document())
return 0;
return &document()->topDocument();
}
bool AXRenderObject::shouldNotifyActiveDescendant() const
{
// We want to notify that the combo box has changed its active descendant,
// but we do not want to change the focus, because focus should remain with the combo box.
if (isComboBox())
return true;
return shouldFocusActiveDescendant();
}
ScrollableArea* AXRenderObject::getScrollableAreaIfScrollable() const
{
// If the parent is a scroll view, then this object isn't really scrollable, the parent ScrollView should handle the scrolling.
if (parentObject() && parentObject()->isAXScrollView())
return 0;
if (!m_renderer || !m_renderer->isBox())
return 0;
RenderBox* box = toRenderBox(m_renderer);
if (!box->canBeScrolledAndHasScrollableArea())
return 0;
return box->scrollableArea();
}
AccessibilityRole AXRenderObject::determineAccessibilityRole()
{
if (!m_renderer)
return UnknownRole;
m_ariaRole = determineAriaRoleAttribute();
Node* node = m_renderer->node();
AccessibilityRole ariaRole = ariaRoleAttribute();
if (ariaRole != UnknownRole)
return ariaRole;
RenderBoxModelObject* cssBox = renderBoxModelObject();
if (node && node->isLink()) {
if (cssBox && cssBox->isImage())
return ImageMapRole;
return LinkRole;
}
if (cssBox && cssBox->isListItem())
return ListItemRole;
if (m_renderer->isListMarker())
return ListMarkerRole;
if (isHTMLButtonElement(node))
return buttonRoleType();
if (isHTMLLegendElement(node))
return LegendRole;
if (m_renderer->isText())
return StaticTextRole;
if (cssBox && cssBox->isImage()) {
if (isHTMLInputElement(node))
return ariaHasPopup() ? PopUpButtonRole : ButtonRole;
if (isSVGImage())
return SVGRootRole;
return ImageRole;
}
// Note: if JavaScript is disabled, the renderer won't be a RenderHTMLCanvas.
if (isHTMLCanvasElement(node) && m_renderer->isCanvas())
return CanvasRole;
if (cssBox && cssBox->isRenderView())
return WebAreaRole;
if (cssBox && cssBox->isTextField())
return TextFieldRole;
if (cssBox && cssBox->isTextArea())
return TextAreaRole;
if (isHTMLInputElement(node)) {
HTMLInputElement& input = toHTMLInputElement(*node);
if (input.isCheckbox())
return CheckBoxRole;
if (input.isRadioButton())
return RadioButtonRole;
if (input.isTextButton())
return buttonRoleType();
const AtomicString& type = input.getAttribute(typeAttr);
if (equalIgnoringCase(type, "color"))
return ColorWellRole;
}
if (isFileUploadButton())
return ButtonRole;
if (cssBox && cssBox->isMenuList())
return PopUpButtonRole;
if (headingLevel())
return HeadingRole;
if (m_renderer->isSVGImage())
return ImageRole;
if (m_renderer->isSVGRoot())
return SVGRootRole;
if (node && node->hasTagName(ddTag))
return DescriptionListDetailRole;
if (node && node->hasTagName(dtTag))
return DescriptionListTermRole;
if (node && (node->hasTagName(rpTag) || node->hasTagName(rtTag)))
return AnnotationRole;
// Table sections should be ignored.
if (m_renderer->isTableSection())
return IgnoredRole;
if (m_renderer->isHR())
return HorizontalRuleRole;
if (isHTMLParagraphElement(node))
return ParagraphRole;
if (isHTMLLabelElement(node))
return LabelRole;
if (isHTMLDivElement(node))
return DivRole;
if (isHTMLFormElement(node))
return FormRole;
if (node && node->hasTagName(articleTag))
return ArticleRole;
if (node && node->hasTagName(mainTag))
return MainRole;
if (node && node->hasTagName(navTag))
return NavigationRole;
if (node && node->hasTagName(asideTag))
return ComplementaryRole;
if (node && node->hasTagName(sectionTag))
return RegionRole;
if (node && node->hasTagName(addressTag))
return ContentInfoRole;
if (node && node->hasTagName(dialogTag))
return DialogRole;
// The HTML element should not be exposed as an element. That's what the RenderView element does.
if (isHTMLHtmlElement(node))
return IgnoredRole;
if (node && node->hasTagName(iframeTag))
return IframeRole;
if (isEmbeddedObject())
return EmbeddedObjectRole;
// There should only be one banner/contentInfo per page. If header/footer are being used within an article or section
// then it should not be exposed as whole page's banner/contentInfo
if (node && node->hasTagName(headerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
return BannerRole;
if (node && node->hasTagName(footerTag) && !isDescendantOfElementType(articleTag) && !isDescendantOfElementType(sectionTag))
return FooterRole;
if (isHTMLAnchorElement(node) && isClickable())
return LinkRole;
if (m_renderer->isRenderBlockFlow())
return GroupRole;
// If the element does not have role, but it has ARIA attributes, accessibility should fallback to exposing it as a group.
if (supportsARIAAttributes())
return GroupRole;
return UnknownRole;
}
void AXRenderObject::init()
{
AXNodeObject::init();
}
void AXRenderObject::detach()
{
AXNodeObject::detach();
detachRemoteSVGRoot();
#ifndef NDEBUG
if (m_renderer)
m_renderer->setHasAXObject(false);
#endif
m_renderer = 0;
}
//
// Check object role or purpose.
//
bool AXRenderObject::isAttachment() const
{
RenderBoxModelObject* renderer = renderBoxModelObject();
if (!renderer)
return false;
// Widgets are the replaced elements that we represent to AX as attachments
bool isWidget = renderer->isWidget();
ASSERT(!isWidget || (renderer->isReplaced() && !isImage()));
return isWidget;
}
bool AXRenderObject::isFileUploadButton() const
{
if (m_renderer && isHTMLInputElement(m_renderer->node())) {
HTMLInputElement& input = toHTMLInputElement(*m_renderer->node());
return input.isFileUpload();
}
return false;
}
static bool isLinkable(const AXObject& object)
{
if (!object.renderer())
return false;
// See https://wiki.mozilla.org/Accessibility/AT-Windows-API for the elements
// Mozilla considers linkable.
return object.isLink() || object.isImage() || object.renderer()->isText();
}
bool AXRenderObject::isLinked() const
{
if (!isLinkable(*this))
return false;
Element* anchor = anchorElement();
if (!isHTMLAnchorElement(anchor))
return false;
return !toHTMLAnchorElement(*anchor).href().isEmpty();
}
bool AXRenderObject::isLoaded() const
{
return !m_renderer->document().parser();
}
bool AXRenderObject::isOffScreen() const
{
ASSERT(m_renderer);
IntRect contentRect = pixelSnappedIntRect(m_renderer->absoluteClippedOverflowRect());
FrameView* view = m_renderer->frame()->view();
IntRect viewRect = view->visibleContentRect();
viewRect.intersect(contentRect);
return viewRect.isEmpty();
}
bool AXRenderObject::isReadOnly() const
{
ASSERT(m_renderer);
if (isWebArea()) {
Document& document = m_renderer->document();
HTMLElement* body = document.body();
if (body && body->rendererIsEditable())
return false;
return !document.rendererIsEditable();
}
return AXNodeObject::isReadOnly();
}
bool AXRenderObject::isVisited() const
{
// FIXME: Is it a privacy violation to expose visited information to accessibility APIs?
return m_renderer->style()->isLink() && m_renderer->style()->insideLink() == InsideVisitedLink;
}
//
// Check object state.
//
bool AXRenderObject::isFocused() const
{
if (!m_renderer)
return false;
Document& document = m_renderer->document();
Element* focusedElement = document.focusedElement();
if (!focusedElement)
return false;
// A web area is represented by the Document node in the DOM tree, which isn't focusable.
// Check instead if the frame's selection controller is focused
if (focusedElement == m_renderer->node()
|| (roleValue() == WebAreaRole && document.frame()->selection().isFocusedAndActive()))
return true;
return false;
}
bool AXRenderObject::isSelected() const
{
if (!m_renderer)
return false;
Node* node = m_renderer->node();
if (!node)
return false;
const AtomicString& ariaSelected = getAttribute(aria_selectedAttr);
if (equalIgnoringCase(ariaSelected, "true"))
return true;
if (isTabItem() && isTabItemSelected())
return true;
return false;
}
//
// Whether objects are ignored, i.e. not included in the tree.
//
AXObjectInclusion AXRenderObject::defaultObjectInclusion() const
{
// The following cases can apply to any element that's a subclass of AXRenderObject.
if (!m_renderer)
return IgnoreObject;
if (m_renderer->style()->visibility() != VISIBLE) {
// aria-hidden is meant to override visibility as the determinant in AX hierarchy inclusion.
if (equalIgnoringCase(getAttribute(aria_hiddenAttr), "false"))
return DefaultBehavior;
return IgnoreObject;
}
return AXObject::defaultObjectInclusion();
}
bool AXRenderObject::computeAccessibilityIsIgnored() const
{
#ifndef NDEBUG
ASSERT(m_initialized);
#endif
// Check first if any of the common reasons cause this element to be ignored.
// Then process other use cases that need to be applied to all the various roles
// that AXRenderObjects take on.
AXObjectInclusion decision = defaultObjectInclusion();
if (decision == IncludeObject)
return false;
if (decision == IgnoreObject)
return true;
// If this element is within a parent that cannot have children, it should not be exposed.
if (isDescendantOfBarrenParent())
return true;
if (roleValue() == IgnoredRole)
return true;
if (roleValue() == PresentationalRole || inheritsPresentationalRole())
return true;
// An ARIA tree can only have tree items and static text as children.
if (!isAllowedChildOfTree())
return true;
// TODO: we should refactor this - but right now this is necessary to make
// sure scroll areas stay in the tree.
if (isAttachment())
return false;
// ignore popup menu items because AppKit does
for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
if (parent->isBoxModelObject() && toRenderBoxModelObject(parent)->isMenuList())
return true;
}
// find out if this element is inside of a label element.
// if so, it may be ignored because it's the label for a checkbox or radio button
AXObject* controlObject = correspondingControlForLabelElement();
if (controlObject && !controlObject->exposesTitleUIElement() && controlObject->isCheckboxOrRadio())
return true;
// NOTE: BRs always have text boxes now, so the text box check here can be removed
if (m_renderer->isText()) {
// static text beneath MenuItems and MenuButtons are just reported along with the menu item, so it's ignored on an individual level
AXObject* parent = parentObjectUnignored();
if (parent && (parent->ariaRoleAttribute() == MenuItemRole || parent->ariaRoleAttribute() == MenuButtonRole))
return true;
RenderText* renderText = toRenderText(m_renderer);
if (m_renderer->isBR() || !renderText->firstTextBox())
return true;
// Don't ignore static text in editable text controls.
for (AXObject* parent = parentObject(); parent; parent = parent->parentObject()) {
if (parent->roleValue() == TextFieldRole || parent->roleValue() == TextAreaRole)
return false;
}
// text elements that are just empty whitespace should not be returned
// FIXME(dmazzoni): we probably shouldn't ignore this if the style is 'pre', or similar...
return renderText->text().impl()->containsOnlyWhitespace();
}
if (isHeading())
return false;
if (isLandmarkRelated())
return false;
if (isLink())
return false;
// all controls are accessible
if (isControl())
return false;
if (ariaRoleAttribute() != UnknownRole)
return false;
// don't ignore labels, because they serve as TitleUIElements
Node* node = m_renderer->node();
if (isHTMLLabelElement(node))
return false;
// Anything that is content editable should not be ignored.
// However, one cannot just call node->rendererIsEditable() since that will ask if its parents
// are also editable. Only the top level content editable region should be exposed.
if (hasContentEditableAttributeSet())
return false;
// List items play an important role in defining the structure of lists. They should not be ignored.
if (roleValue() == ListItemRole)
return false;
if (roleValue() == DialogRole)
return false;
// if this element has aria attributes on it, it should not be ignored.
if (supportsARIAAttributes())
return false;
// <span> tags are inline tags and not meant to convey information if they have no other aria
// information on them. If we don't ignore them, they may emit signals expected to come from
// their parent. In addition, because included spans are GroupRole objects, and GroupRole
// objects are often containers with meaningful information, the inclusion of a span can have
// the side effect of causing the immediate parent accessible to be ignored. This is especially
// problematic for platforms which have distinct roles for textual block elements.
if (isHTMLSpanElement(node))
return true;
if (m_renderer->isRenderBlockFlow() && m_renderer->childrenInline() && !canSetFocusAttribute())
return !toRenderBlock(m_renderer)->firstLineBox() && !mouseButtonListener();
// ignore images seemingly used as spacers
if (isImage()) {
// If the image can take focus, it should not be ignored, lest the user not be able to interact with something important.
if (canSetFocusAttribute())
return false;
if (node && node->isElementNode()) {
Element* elt = toElement(node);
const AtomicString& alt = elt->getAttribute(altAttr);
// don't ignore an image that has an alt tag
if (!alt.string().containsOnlyWhitespace())
return false;
// informal standard is to ignore images with zero-length alt strings
if (!alt.isNull())
return true;
}
if (isNativeImage() && m_renderer->isImage()) {
// check for one-dimensional image
RenderImage* image = toRenderImage(m_renderer);
if (image->height() <= 1 || image->width() <= 1)
return true;
// check whether rendered image was stretched from one-dimensional file image
if (image->cachedImage()) {
LayoutSize imageSize = image->cachedImage()->imageSizeForRenderer(m_renderer, image->view()->zoomFactor());
return imageSize.height() <= 1 || imageSize.width() <= 1;
}
}
return false;
}
if (isCanvas()) {
if (canvasHasFallbackContent())
return false;
RenderHTMLCanvas* canvas = toRenderHTMLCanvas(m_renderer);
if (canvas->height() <= 1 || canvas->width() <= 1)
return true;
// Otherwise fall through; use presence of help text, title, or description to decide.
}
if (isWebArea() || m_renderer->isListMarker())
return false;
// Using the help text, title or accessibility description (so we
// check if there's some kind of accessible name for the element)
// to decide an element's visibility is not as definitive as
// previous checks, so this should remain as one of the last.
//
// These checks are simplified in the interest of execution speed;
// for example, any element having an alt attribute will make it
// not ignored, rather than just images.
if (!getAttribute(aria_helpAttr).isEmpty() || !getAttribute(aria_describedbyAttr).isEmpty() || !getAttribute(altAttr).isEmpty() || !getAttribute(titleAttr).isEmpty())
return false;
// Don't ignore generic focusable elements like <div tabindex=0>
// unless they're completely empty, with no children.
if (isGenericFocusableElement() && node->firstChild())
return false;
if (!ariaAccessibilityDescription().isEmpty())
return false;
// By default, objects should be ignored so that the AX hierarchy is not
// filled with unnecessary items.
return true;
}
//
// Properties of static elements.
//
const AtomicString& AXRenderObject::accessKey() const
{
Node* node = m_renderer->node();
if (!node)
return nullAtom;
if (!node->isElementNode())
return nullAtom;
return toElement(node)->getAttribute(accesskeyAttr);
}
AccessibilityOrientation AXRenderObject::orientation() const
{
const AtomicString& ariaOrientation = getAttribute(aria_orientationAttr);
if (equalIgnoringCase(ariaOrientation, "horizontal"))
return AccessibilityOrientationHorizontal;
if (equalIgnoringCase(ariaOrientation, "vertical"))
return AccessibilityOrientationVertical;
return AXObject::orientation();
}
String AXRenderObject::text() const
{
if (isPasswordField())
return String();
return AXNodeObject::text();
}
int AXRenderObject::textLength() const
{
if (!isTextControl())
return -1;
if (isPasswordField())
return -1; // need to return something distinct from 0
return text().length();
}
KURL AXRenderObject::url() const
{
if (isAnchor() && isHTMLAnchorElement(m_renderer->node())) {
if (HTMLAnchorElement* anchor = toHTMLAnchorElement(anchorElement()))
return anchor->href();
}
if (isWebArea())
return m_renderer->document().url();
if (isImage() && isHTMLImageElement(m_renderer->node()))
return toHTMLImageElement(*m_renderer->node()).src();
if (isInputImage())
return toHTMLInputElement(m_renderer->node())->src();
return KURL();
}
//
// Properties of interactive elements.
//
static String queryString(WebLocalizedString::Name name)
{
return Locale::defaultLocale().queryString(name);
}
String AXRenderObject::actionVerb() const
{
switch (roleValue()) {
case ButtonRole:
case ToggleButtonRole:
return queryString(WebLocalizedString::AXButtonActionVerb);
case TextFieldRole:
case TextAreaRole:
return queryString(WebLocalizedString::AXTextFieldActionVerb);
case RadioButtonRole:
return queryString(WebLocalizedString::AXRadioButtonActionVerb);
case CheckBoxRole:
return queryString(isChecked() ? WebLocalizedString::AXCheckedCheckBoxActionVerb : WebLocalizedString::AXUncheckedCheckBoxActionVerb);
case LinkRole:
return queryString(WebLocalizedString::AXLinkActionVerb);
default:
return emptyString();
}
}
String AXRenderObject::stringValue() const
{
if (!m_renderer)
return String();
if (isPasswordField())
return String();
RenderBoxModelObject* cssBox = renderBoxModelObject();
if (ariaRoleAttribute() == StaticTextRole) {
String staticText = text();
if (!staticText.length())
staticText = textUnderElement();
return staticText;
}
if (m_renderer->isText())
return textUnderElement();
if (cssBox && cssBox->isMenuList()) {
// RenderMenuList will go straight to the text() of its selected item.
// This has to be overridden in the case where the selected item has an ARIA label.
HTMLSelectElement* selectElement = toHTMLSelectElement(m_renderer->node());
int selectedIndex = selectElement->selectedIndex();
const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = selectElement->listItems();
if (selectedIndex >= 0 && static_cast<size_t>(selectedIndex) < listItems.size()) {
const AtomicString& overriddenDescription = listItems[selectedIndex]->fastGetAttribute(aria_labelAttr);
if (!overriddenDescription.isNull())
return overriddenDescription;
}
return toRenderMenuList(m_renderer)->text();
}
if (m_renderer->isListMarker())
return toRenderListMarker(m_renderer)->text();
if (isWebArea()) {
// FIXME: Why would a renderer exist when the Document isn't attached to a frame?
if (m_renderer->frame())
return String();
ASSERT_NOT_REACHED();
}
if (isTextControl())
return text();
if (m_renderer->isFileUploadControl())
return toRenderFileUploadControl(m_renderer)->fileTextValue();
// FIXME: We might need to implement a value here for more types
// FIXME: It would be better not to advertise a value at all for the types for which we don't implement one;
// this would require subclassing or making accessibilityAttributeNames do something other than return a
// single static array.
return String();
}
//
// ARIA attributes.
//
AXObject* AXRenderObject::activeDescendant() const
{
if (!m_renderer)
return 0;
if (m_renderer->node() && !m_renderer->node()->isElementNode())
return 0;
Element* element = toElement(m_renderer->node());
if (!element)
return 0;
const AtomicString& activeDescendantAttrStr = element->getAttribute(aria_activedescendantAttr);
if (activeDescendantAttrStr.isNull() || activeDescendantAttrStr.isEmpty())
return 0;
Element* target = element->treeScope().getElementById(activeDescendantAttrStr);
if (!target)
return 0;
AXObject* obj = axObjectCache()->getOrCreate(target);
// An activedescendant is only useful if it has a renderer, because that's what's needed to post the notification.
if (obj && obj->isAXRenderObject())
return obj;
return 0;
}
void AXRenderObject::accessibilityChildrenFromAttribute(QualifiedName attr, AccessibilityChildrenVector& children) const
{
Vector<Element*> elements;
elementsFromAttribute(elements, attr);
AXObjectCache* cache = axObjectCache();
unsigned count = elements.size();
for (unsigned k = 0; k < count; ++k) {
Element* element = elements[k];
AXObject* child = cache->getOrCreate(element);
if (child)
children.append(child);
}
}
void AXRenderObject::ariaFlowToElements(AccessibilityChildrenVector& flowTo) const
{
accessibilityChildrenFromAttribute(aria_flowtoAttr, flowTo);
}
void AXRenderObject::ariaControlsElements(AccessibilityChildrenVector& controls) const
{
accessibilityChildrenFromAttribute(aria_controlsAttr, controls);
}
void AXRenderObject::ariaDescribedbyElements(AccessibilityChildrenVector& describedby) const
{
accessibilityChildrenFromAttribute(aria_describedbyAttr, describedby);
}
void AXRenderObject::ariaLabelledbyElements(AccessibilityChildrenVector& labelledby) const
{
accessibilityChildrenFromAttribute(aria_labelledbyAttr, labelledby);
}
void AXRenderObject::ariaOwnsElements(AccessibilityChildrenVector& owns) const
{
accessibilityChildrenFromAttribute(aria_ownsAttr, owns);
}
bool AXRenderObject::ariaHasPopup() const
{
return elementAttributeValue(aria_haspopupAttr);
}
bool AXRenderObject::ariaRoleHasPresentationalChildren() const
{
switch (m_ariaRole) {
case ButtonRole:
case SliderRole:
case ImageRole:
case ProgressIndicatorRole:
case SpinButtonRole:
// case SeparatorRole:
return true;
default:
return false;
}
}
bool AXRenderObject::isPresentationalChildOfAriaRole() const
{
// Walk the parent chain looking for a parent that has presentational children
AXObject* parent;
for (parent = parentObject(); parent && !parent->ariaRoleHasPresentationalChildren(); parent = parent->parentObject())
{ }
return parent;
}
bool AXRenderObject::shouldFocusActiveDescendant() const
{
switch (ariaRoleAttribute()) {
case ComboBoxRole:
case GridRole:
case GroupRole:
case ListBoxRole:
case MenuRole:
case MenuBarRole:
case OutlineRole:
case PopUpButtonRole:
case ProgressIndicatorRole:
case RadioGroupRole:
case RowRole:
case TabListRole:
case ToolbarRole:
case TreeRole:
case TreeGridRole:
return true;
default:
return false;
}
}
bool AXRenderObject::supportsARIADragging() const
{
const AtomicString& grabbed = getAttribute(aria_grabbedAttr);
return equalIgnoringCase(grabbed, "true") || equalIgnoringCase(grabbed, "false");
}
bool AXRenderObject::supportsARIADropping() const
{
const AtomicString& dropEffect = getAttribute(aria_dropeffectAttr);
return !dropEffect.isEmpty();
}
bool AXRenderObject::supportsARIAFlowTo() const
{
return !getAttribute(aria_flowtoAttr).isEmpty();
}
bool AXRenderObject::supportsARIAOwns() const
{
if (!m_renderer)
return false;
const AtomicString& ariaOwns = getAttribute(aria_ownsAttr);
return !ariaOwns.isEmpty();
}
//
// ARIA live-region features.
//
const AtomicString& AXRenderObject::ariaLiveRegionStatus() const
{
DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusAssertive, ("assertive", AtomicString::ConstructFromLiteral));
DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusPolite, ("polite", AtomicString::ConstructFromLiteral));
DEFINE_STATIC_LOCAL(const AtomicString, liveRegionStatusOff, ("off", AtomicString::ConstructFromLiteral));
const AtomicString& liveRegionStatus = getAttribute(aria_liveAttr);
// These roles have implicit live region status.
if (liveRegionStatus.isEmpty()) {
switch (roleValue()) {
case AlertDialogRole:
case AlertRole:
return liveRegionStatusAssertive;
case LogRole:
case StatusRole:
return liveRegionStatusPolite;
case TimerRole:
case MarqueeRole:
return liveRegionStatusOff;
default:
break;
}
}
return liveRegionStatus;
}
const AtomicString& AXRenderObject::ariaLiveRegionRelevant() const
{
DEFINE_STATIC_LOCAL(const AtomicString, defaultLiveRegionRelevant, ("additions text", AtomicString::ConstructFromLiteral));
const AtomicString& relevant = getAttribute(aria_relevantAttr);
// Default aria-relevant = "additions text".
if (relevant.isEmpty())
return defaultLiveRegionRelevant;
return relevant;
}
bool AXRenderObject::ariaLiveRegionAtomic() const
{
return elementAttributeValue(aria_atomicAttr);
}
bool AXRenderObject::ariaLiveRegionBusy() const
{
return elementAttributeValue(aria_busyAttr);
}
//
// Accessibility Text.
//
String AXRenderObject::textUnderElement() const
{
if (!m_renderer)
return String();
if (m_renderer->isFileUploadControl())
return toRenderFileUploadControl(m_renderer)->buttonValue();
if (m_renderer->isText())
return toRenderText(m_renderer)->plainText();
return AXNodeObject::textUnderElement();
}
//
// Accessibility Text - (To be deprecated).
//
String AXRenderObject::helpText() const
{
if (!m_renderer)
return String();
const AtomicString& ariaHelp = getAttribute(aria_helpAttr);
if (!ariaHelp.isEmpty())
return ariaHelp;
String describedBy = ariaDescribedByAttribute();
if (!describedBy.isEmpty())
return describedBy;
String description = accessibilityDescription();
for (RenderObject* curr = m_renderer; curr; curr = curr->parent()) {
if (curr->node() && curr->node()->isHTMLElement()) {
const AtomicString& summary = toElement(curr->node())->getAttribute(summaryAttr);
if (!summary.isEmpty())
return summary;
// The title attribute should be used as help text unless it is already being used as descriptive text.
const AtomicString& title = toElement(curr->node())->getAttribute(titleAttr);
if (!title.isEmpty() && description != title)
return title;
}
// Only take help text from an ancestor element if its a group or an unknown role. If help was
// added to those kinds of elements, it is likely it was meant for a child element.
AXObject* axObj = axObjectCache()->getOrCreate(curr);
if (axObj) {
AccessibilityRole role = axObj->roleValue();
if (role != GroupRole && role != UnknownRole)
break;
}
}
return String();
}
//
// Position and size.
//
void AXRenderObject::checkCachedElementRect() const
{
if (m_cachedElementRectDirty)
return;
if (!m_renderer)
return;
if (!m_renderer->isBox())
return;
bool dirty = false;
RenderBox* box = toRenderBox(m_renderer);
if (box->frameRect() != m_cachedFrameRect)
dirty = true;
if (box->canBeScrolledAndHasScrollableArea()) {
ScrollableArea* scrollableArea = box->scrollableArea();
if (scrollableArea && scrollableArea->scrollPosition() != m_cachedScrollPosition)
dirty = true;
}
if (dirty)
markCachedElementRectDirty();
}
void AXRenderObject::updateCachedElementRect() const
{
if (!m_cachedElementRectDirty)
return;
if (!m_renderer)
return;
if (!m_renderer->isBox())
return;
RenderBox* box = toRenderBox(m_renderer);
m_cachedFrameRect = box->frameRect();
if (box->canBeScrolledAndHasScrollableArea()) {
ScrollableArea* scrollableArea = box->scrollableArea();
if (scrollableArea)
m_cachedScrollPosition = scrollableArea->scrollPosition();
}
m_cachedElementRect = computeElementRect();
m_cachedElementRectDirty = false;
}
void AXRenderObject::markCachedElementRectDirty() const
{
if (m_cachedElementRectDirty)
return;
// Marks children recursively, if this element changed.
m_cachedElementRectDirty = true;
for (AXObject* child = firstChild(); child; child = child->nextSibling())
child->markCachedElementRectDirty();
}
IntPoint AXRenderObject::clickPoint()
{
// Headings are usually much wider than their textual content. If the mid point is used, often it can be wrong.
if (isHeading() && children().size() == 1)
return children()[0]->clickPoint();
// use the default position unless this is an editable web area, in which case we use the selection bounds.
if (!isWebArea() || isReadOnly())
return AXObject::clickPoint();
IntRect bounds = pixelSnappedIntRect(elementRect());
return IntPoint(bounds.x() + (bounds.width() / 2), bounds.y() - (bounds.height() / 2));
}
//
// Hit testing.
//
AXObject* AXRenderObject::accessibilityHitTest(const IntPoint& point) const
{
if (!m_renderer || !m_renderer->hasLayer())
return 0;
RenderLayer* layer = toRenderBox(m_renderer)->layer();
HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
HitTestResult hitTestResult = HitTestResult(point);
layer->hitTest(request, hitTestResult);
if (!hitTestResult.innerNode())
return 0;
Node* node = hitTestResult.innerNode()->deprecatedShadowAncestorNode();
if (isHTMLAreaElement(node))
return accessibilityImageMapHitTest(toHTMLAreaElement(node), point);
if (isHTMLOptionElement(node))
node = toHTMLOptionElement(*node).ownerSelectElement();
RenderObject* obj = node->renderer();
if (!obj)
return 0;
AXObject* result = obj->document().axObjectCache()->getOrCreate(obj);
result->updateChildrenIfNecessary();
// Allow the element to perform any hit-testing it might need to do to reach non-render children.
result = result->elementAccessibilityHitTest(point);
if (result && result->accessibilityIsIgnored()) {
// If this element is the label of a control, a hit test should return the control.
if (result->isAXRenderObject()) {
AXObject* controlObject = toAXRenderObject(result)->correspondingControlForLabelElement();
if (controlObject && !controlObject->exposesTitleUIElement())
return controlObject;
}
result = result->parentObjectUnignored();
}
return result;
}
AXObject* AXRenderObject::elementAccessibilityHitTest(const IntPoint& point) const
{
if (isSVGImage())
return remoteSVGElementHitTest(point);
return AXObject::elementAccessibilityHitTest(point);
}
//
// High-level accessibility tree access.
//
AXObject* AXRenderObject::parentObject() const
{
if (!m_renderer)
return 0;
if (ariaRoleAttribute() == MenuBarRole)
return axObjectCache()->getOrCreate(m_renderer->parent());
// menuButton and its corresponding menu are DOM siblings, but Accessibility needs them to be parent/child
if (ariaRoleAttribute() == MenuRole) {
AXObject* parent = menuButtonForMenu();
if (parent)
return parent;
}
RenderObject* parentObj = renderParentObject();
if (parentObj)
return axObjectCache()->getOrCreate(parentObj);
// WebArea's parent should be the scroll view containing it.
if (isWebArea())
return axObjectCache()->getOrCreate(m_renderer->frame()->view());
return 0;
}
AXObject* AXRenderObject::parentObjectIfExists() const
{
// WebArea's parent should be the scroll view containing it.
if (isWebArea())
return axObjectCache()->get(m_renderer->frame()->view());
return axObjectCache()->get(renderParentObject());
}
//
// Low-level accessibility tree exploration, only for use within the accessibility module.
//
AXObject* AXRenderObject::firstChild() const
{
if (!m_renderer)
return 0;
RenderObject* firstChild = firstChildConsideringContinuation(m_renderer);
if (!firstChild)
return 0;
return axObjectCache()->getOrCreate(firstChild);
}
AXObject* AXRenderObject::nextSibling() const
{
if (!m_renderer)
return 0;
RenderObject* nextSibling = 0;
RenderInline* inlineContinuation;
if (m_renderer->isRenderBlock() && (inlineContinuation = toRenderBlock(m_renderer)->inlineElementContinuation())) {
// Case 1: node is a block and has an inline continuation. Next sibling is the inline continuation's first child.
nextSibling = firstChildConsideringContinuation(inlineContinuation);
} else if (m_renderer->isAnonymousBlock() && lastChildHasContinuation(m_renderer)) {
// Case 2: Anonymous block parent of the start of a continuation - skip all the way to
// after the parent of the end, since everything in between will be linked up via the continuation.
RenderObject* lastParent = endOfContinuations(toRenderBlock(m_renderer)->lastChild())->parent();
while (lastChildHasContinuation(lastParent))
lastParent = endOfContinuations(lastParent->slowLastChild())->parent();
nextSibling = lastParent->nextSibling();
} else if (RenderObject* ns = m_renderer->nextSibling()) {
// Case 3: node has an actual next sibling
nextSibling = ns;
} else if (isInlineWithContinuation(m_renderer)) {
// Case 4: node is an inline with a continuation. Next sibling is the next sibling of the end
// of the continuation chain.
nextSibling = endOfContinuations(m_renderer)->nextSibling();
} else if (isInlineWithContinuation(m_renderer->parent())) {
// Case 5: node has no next sibling, and its parent is an inline with a continuation.
RenderObject* continuation = toRenderInline(m_renderer->parent())->continuation();
if (continuation->isRenderBlock()) {
// Case 5a: continuation is a block - in this case the block itself is the next sibling.
nextSibling = continuation;
} else {
// Case 5b: continuation is an inline - in this case the inline's first child is the next sibling.
nextSibling = firstChildConsideringContinuation(continuation);
}
}
if (!nextSibling)
return 0;
return axObjectCache()->getOrCreate(nextSibling);
}
void AXRenderObject::addChildren()
{
// If the need to add more children in addition to existing children arises,
// childrenChanged should have been called, leaving the object with no children.
ASSERT(!m_haveChildren);
m_haveChildren = true;
if (!canHaveChildren())
return;
for (RefPtr<AXObject> obj = firstChild(); obj; obj = obj->nextSibling())
addChild(obj.get());
addHiddenChildren();
addAttachmentChildren();
addImageMapChildren();
addTextFieldChildren();
addCanvasChildren();
addRemoteSVGChildren();
addInlineTextBoxChildren();
}
bool AXRenderObject::canHaveChildren() const
{
if (!m_renderer)
return false;
return AXNodeObject::canHaveChildren();
}
void AXRenderObject::updateChildrenIfNecessary()
{
if (needsToUpdateChildren())
clearChildren();
AXObject::updateChildrenIfNecessary();
}
void AXRenderObject::clearChildren()
{
AXObject::clearChildren();
m_childrenDirty = false;
}
AXObject* AXRenderObject::observableObject() const
{
// Find the object going up the parent chain that is used in accessibility to monitor certain notifications.
for (RenderObject* renderer = m_renderer; renderer && renderer->node(); renderer = renderer->parent()) {
if (renderObjectIsObservable(renderer))
return axObjectCache()->getOrCreate(renderer);
}
return 0;
}
//
// Properties of the object's owning document or page.
//
double AXRenderObject::estimatedLoadingProgress() const
{
if (!m_renderer)
return 0;
if (isLoaded())
return 1.0;
if (LocalFrame* frame = m_renderer->document().frame())
return frame->loader().progress().estimatedProgress();
return 0;
}
//
// DOM and Render tree access.
//
Node* AXRenderObject::node() const
{
return m_renderer ? m_renderer->node() : 0;
}
Document* AXRenderObject::document() const
{
if (!m_renderer)
return 0;
return &m_renderer->document();
}
FrameView* AXRenderObject::documentFrameView() const
{
if (!m_renderer)
return 0;
// this is the RenderObject's Document's LocalFrame's FrameView
return m_renderer->document().view();
}
Element* AXRenderObject::anchorElement() const
{
if (!m_renderer)
return 0;
AXObjectCache* cache = axObjectCache();
RenderObject* currRenderer;
// Search up the render tree for a RenderObject with a DOM node. Defer to an earlier continuation, though.
for (currRenderer = m_renderer; currRenderer && !currRenderer->node(); currRenderer = currRenderer->parent()) {
if (currRenderer->isAnonymousBlock()) {
RenderObject* continuation = toRenderBlock(currRenderer)->continuation();
if (continuation)
return cache->getOrCreate(continuation)->anchorElement();
}
}
// bail if none found
if (!currRenderer)
return 0;
// search up the DOM tree for an anchor element
// NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElement
Node* node = currRenderer->node();
for ( ; node; node = node->parentNode()) {
if (isHTMLAnchorElement(*node) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
return toElement(node);
}
return 0;
}
Widget* AXRenderObject::widgetForAttachmentView() const
{
if (!isAttachment())
return 0;
return toRenderWidget(m_renderer)->widget();
}
//
// Selected text.
//
AXObject::PlainTextRange AXRenderObject::selectedTextRange() const
{
if (!isTextControl())
return PlainTextRange();
if (isPasswordField())
return PlainTextRange();
AccessibilityRole ariaRole = ariaRoleAttribute();
if (isNativeTextControl() && ariaRole == UnknownRole && m_renderer->isTextControl()) {
HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
return PlainTextRange(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());
}
if (ariaRole == UnknownRole)
return PlainTextRange();
return ariaSelectedTextRange();
}
VisibleSelection AXRenderObject::selection() const
{
return m_renderer->frame()->selection().selection();
}
//
// Modify or take an action on an object.
//
void AXRenderObject::setSelectedTextRange(const PlainTextRange& range)
{
if (isNativeTextControl() && m_renderer->isTextControl()) {
HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
textControl->setSelectionRange(range.start, range.start + range.length);
return;
}
Document& document = m_renderer->document();
LocalFrame* frame = document.frame();
if (!frame)
return;
Node* node = m_renderer->node();
frame->selection().setSelection(VisibleSelection(Position(node, range.start, Position::PositionIsOffsetInAnchor),
Position(node, range.start + range.length, Position::PositionIsOffsetInAnchor), DOWNSTREAM));
}
void AXRenderObject::setValue(const String& string)
{
if (!node() || !node()->isElementNode())
return;
if (!m_renderer || !m_renderer->isBoxModelObject())
return;
RenderBoxModelObject* renderer = toRenderBoxModelObject(m_renderer);
if (renderer->isTextField() && isHTMLInputElement(*node()))
toHTMLInputElement(*node()).setValue(string);
else if (renderer->isTextArea() && isHTMLTextAreaElement(*node()))
toHTMLTextAreaElement(*node()).setValue(string);
}
// FIXME: This function should use an IntSize to avoid the conversion below.
void AXRenderObject::scrollTo(const IntPoint& point) const
{
if (!m_renderer || !m_renderer->isBox())
return;
RenderBox* box = toRenderBox(m_renderer);
if (!box->canBeScrolledAndHasScrollableArea())
return;
box->scrollToOffset(IntSize(point.x(), point.y()));
}
//
// Notifications that this object may have changed.
//
void AXRenderObject::handleActiveDescendantChanged()
{
Element* element = toElement(renderer()->node());
if (!element)
return;
Document& doc = renderer()->document();
if (!doc.frame()->selection().isFocusedAndActive() || doc.focusedElement() != element)
return;
AXRenderObject* activedescendant = toAXRenderObject(activeDescendant());
if (activedescendant && shouldNotifyActiveDescendant())
doc.axObjectCache()->postNotification(m_renderer, AXObjectCache::AXActiveDescendantChanged, true);
}
void AXRenderObject::handleAriaExpandedChanged()
{
// Find if a parent of this object should handle aria-expanded changes.
AXObject* containerParent = this->parentObject();
while (containerParent) {
bool foundParent = false;
switch (containerParent->roleValue()) {
case TreeRole:
case TreeGridRole:
case GridRole:
case TableRole:
case BrowserRole:
foundParent = true;
break;
default:
break;
}
if (foundParent)
break;
containerParent = containerParent->parentObject();
}
// Post that the row count changed.
if (containerParent)
axObjectCache()->postNotification(containerParent, document(), AXObjectCache::AXRowCountChanged, true);
// Post that the specific row either collapsed or expanded.
if (roleValue() == RowRole || roleValue() == TreeItemRole)
axObjectCache()->postNotification(this, document(), isExpanded() ? AXObjectCache::AXRowExpanded : AXObjectCache::AXRowCollapsed, true);
}
void AXRenderObject::textChanged()
{
if (!m_renderer)
return;
if (AXObjectCache::inlineTextBoxAccessibility() && roleValue() == StaticTextRole)
childrenChanged();
// Do this last - AXNodeObject::textChanged posts live region announcements,
// and we should update the inline text boxes first.
AXNodeObject::textChanged();
}
//
// Text metrics. Most of these should be deprecated, needs major cleanup.
//
// NOTE: Consider providing this utility method as AX API
int AXRenderObject::index(const VisiblePosition& position) const
{
if (position.isNull() || !isTextControl())
return -1;
if (renderObjectContainsPosition(m_renderer, position.deepEquivalent()))
return indexForVisiblePosition(position);
return -1;
}
VisiblePosition AXRenderObject::visiblePositionForIndex(int index) const
{
if (!m_renderer)
return VisiblePosition();
if (isNativeTextControl() && m_renderer->isTextControl())
return toRenderTextControl(m_renderer)->textFormControlElement()->visiblePositionForIndex(index);
if (!allowsTextRanges() && !m_renderer->isText())
return VisiblePosition();
Node* node = m_renderer->node();
if (!node)
return VisiblePosition();
if (index <= 0)
return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
RefPtrWillBeRawPtr<Range> range = Range::create(m_renderer->document());
range->selectNodeContents(node, IGNORE_EXCEPTION);
CharacterIterator it(range.get());
it.advance(index - 1);
return VisiblePosition(Position(it.range()->endContainer(), it.range()->endOffset(), Position::PositionIsOffsetInAnch\
or), UPSTREAM);
}
int AXRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
{
if (isNativeTextControl() && m_renderer->isTextControl()) {
HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
return textControl->indexForVisiblePosition(pos);
}
if (!isTextControl())
return 0;
Node* node = m_renderer->node();
if (!node)
return 0;
Position indexPosition = pos.deepEquivalent();
if (indexPosition.isNull() || highestEditableRoot(indexPosition, HasEditableAXRole) != node)
return 0;
RefPtrWillBeRawPtr<Range> range = Range::create(m_renderer->document());
range->setStart(node, 0, IGNORE_EXCEPTION);
range->setEnd(indexPosition, IGNORE_EXCEPTION);
return TextIterator::rangeLength(range.get());
}
void AXRenderObject::addInlineTextBoxChildren()
{
if (!axObjectCache()->inlineTextBoxAccessibility())
return;
if (!renderer() || !renderer()->isText())
return;
if (renderer()->needsLayout()) {
// If a RenderText needs layout, its inline text boxes are either
// nonexistent or invalid, so defer until the layout happens and
// the renderer calls AXObjectCache::inlineTextBoxesUpdated.
return;
}
RenderText* renderText = toRenderText(renderer());
for (RefPtr<AbstractInlineTextBox> box = renderText->firstAbstractInlineTextBox(); box.get(); box = box->nextInlineTextBox()) {
AXObject* axObject = axObjectCache()->getOrCreate(box.get());
if (!axObject->accessibilityIsIgnored())
m_children.append(axObject);
}
}
void AXRenderObject::lineBreaks(Vector<int>& lineBreaks) const
{
if (!isTextControl())
return;
VisiblePosition visiblePos = visiblePositionForIndex(0);
VisiblePosition savedVisiblePos = visiblePos;
visiblePos = nextLinePosition(visiblePos, 0);
while (!visiblePos.isNull() && visiblePos != savedVisiblePos) {
lineBreaks.append(indexForVisiblePosition(visiblePos));
savedVisiblePos = visiblePos;
visiblePos = nextLinePosition(visiblePos, 0);
}
}
//
// Private.
//
bool AXRenderObject::isAllowedChildOfTree() const
{
// Determine if this is in a tree. If so, we apply special behavior to make it work like an AXOutline.
AXObject* axObj = parentObject();
bool isInTree = false;
while (axObj) {
if (axObj->isTree()) {
isInTree = true;
break;
}
axObj = axObj->parentObject();
}
// If the object is in a tree, only tree items should be exposed (and the children of tree items).
if (isInTree) {
AccessibilityRole role = roleValue();
if (role != TreeItemRole && role != StaticTextRole)
return false;
}
return true;
}
void AXRenderObject::ariaListboxSelectedChildren(AccessibilityChildrenVector& result)
{
bool isMulti = isMultiSelectable();
AccessibilityChildrenVector childObjects = children();
unsigned childrenSize = childObjects.size();
for (unsigned k = 0; k < childrenSize; ++k) {
// Every child should have aria-role option, and if so, check for selected attribute/state.
AXObject* child = childObjects[k].get();
if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRole) {
result.append(child);
if (!isMulti)
return;
}
}
}
AXObject::PlainTextRange AXRenderObject::ariaSelectedTextRange() const
{
Node* node = m_renderer->node();
if (!node)
return PlainTextRange();
VisibleSelection visibleSelection = selection();
RefPtrWillBeRawPtr<Range> currentSelectionRange = visibleSelection.toNormalizedRange();
if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, IGNORE_EXCEPTION))
return PlainTextRange();
int start = indexForVisiblePosition(visibleSelection.visibleStart());
int end = indexForVisiblePosition(visibleSelection.visibleEnd());
return PlainTextRange(start, end - start);
}
bool AXRenderObject::nodeIsTextControl(const Node* node) const
{
if (!node)
return false;
const AXObject* axObjectForNode = axObjectCache()->getOrCreate(const_cast<Node*>(node));
if (!axObjectForNode)
return false;
return axObjectForNode->isTextControl();
}
bool AXRenderObject::isTabItemSelected() const
{
if (!isTabItem() || !m_renderer)
return false;
Node* node = m_renderer->node();
if (!node || !node->isElementNode())
return false;
// The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel
// that has keyboard focus inside of it, or if a tabpanel in its aria-controls list has KB
// focus inside of it.
AXObject* focusedElement = focusedUIElement();
if (!focusedElement)
return false;
Vector<Element*> elements;
elementsFromAttribute(elements, aria_controlsAttr);
unsigned count = elements.size();
for (unsigned k = 0; k < count; ++k) {
Element* element = elements[k];
AXObject* tabPanel = axObjectCache()->getOrCreate(element);
// A tab item should only control tab panels.
if (!tabPanel || tabPanel->roleValue() != TabPanelRole)
continue;
AXObject* checkFocusElement = focusedElement;
// Check if the focused element is a descendant of the element controlled by the tab item.
while (checkFocusElement) {
if (tabPanel == checkFocusElement)
return true;
checkFocusElement = checkFocusElement->parentObject();
}
}
return false;
}
AXObject* AXRenderObject::accessibilityImageMapHitTest(HTMLAreaElement* area, const IntPoint& point) const
{
if (!area)
return 0;
AXObject* parent = axObjectCache()->getOrCreate(area->imageElement());
if (!parent)
return 0;
AXObject::AccessibilityChildrenVector children = parent->children();
unsigned count = children.size();
for (unsigned k = 0; k < count; ++k) {
if (children[k]->elementRect().contains(point))
return children[k].get();
}
return 0;
}
bool AXRenderObject::renderObjectIsObservable(RenderObject* renderer) const
{
// AX clients will listen for AXValueChange on a text control.
if (renderer->isTextControl())
return true;
// AX clients will listen for AXSelectedChildrenChanged on listboxes.
Node* node = renderer->node();
if (nodeHasRole(node, "listbox") || (renderer->isBoxModelObject() && toRenderBoxModelObject(renderer)->isListBox()))
return true;
// Textboxes should send out notifications.
if (nodeHasRole(node, "textbox"))
return true;
return false;
}
RenderObject* AXRenderObject::renderParentObject() const
{
if (!m_renderer)
return 0;
RenderObject* parent = m_renderer->parent();
RenderObject* startOfConts = 0;
RenderObject* firstChild = 0;
if (m_renderer->isRenderBlock() && (startOfConts = startOfContinuations(m_renderer))) {
// Case 1: node is a block and is an inline's continuation. Parent
// is the start of the continuation chain.
parent = startOfConts;
} else if (parent && parent->isRenderInline() && (startOfConts = startOfContinuations(parent))) {
// Case 2: node's parent is an inline which is some node's continuation; parent is
// the earliest node in the continuation chain.
parent = startOfConts;
} else if (parent && (firstChild = parent->slowFirstChild()) && firstChild->node()) {
// Case 3: The first sibling is the beginning of a continuation chain. Find the origin of that continuation.
// Get the node's renderer and follow that continuation chain until the first child is found.
RenderObject* nodeRenderFirstChild = firstChild->node()->renderer();
while (nodeRenderFirstChild != firstChild) {
for (RenderObject* contsTest = nodeRenderFirstChild; contsTest; contsTest = nextContinuation(contsTest)) {
if (contsTest == firstChild) {
parent = nodeRenderFirstChild->parent();
break;
}
}
RenderObject* newFirstChild = parent->slowFirstChild();
if (firstChild == newFirstChild)
break;
firstChild = newFirstChild;
if (!firstChild->node())
break;
nodeRenderFirstChild = firstChild->node()->renderer();
}
}
return parent;
}
bool AXRenderObject::isDescendantOfElementType(const QualifiedName& tagName) const
{
for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
if (parent->node() && parent->node()->hasTagName(tagName))
return true;
}
return false;
}
bool AXRenderObject::isSVGImage() const
{
return remoteSVGRootElement();
}
void AXRenderObject::detachRemoteSVGRoot()
{
if (AXSVGRoot* root = remoteSVGRootElement())
root->setParent(0);
}
AXSVGRoot* AXRenderObject::remoteSVGRootElement() const
{
if (!m_renderer || !m_renderer->isRenderImage())
return 0;
ImageResource* cachedImage = toRenderImage(m_renderer)->cachedImage();
if (!cachedImage)
return 0;
Image* image = cachedImage->image();
if (!image || !image->isSVGImage())
return 0;
FrameView* frameView = toSVGImage(image)->frameView();
if (!frameView)
return 0;
Document* doc = frameView->frame().document();
if (!doc || !doc->isSVGDocument())
return 0;
SVGSVGElement* rootElement = doc->accessSVGExtensions().rootElement();
if (!rootElement)
return 0;
RenderObject* rendererRoot = rootElement->renderer();
if (!rendererRoot)
return 0;
AXObject* rootSVGObject = doc->axObjectCache()->getOrCreate(rendererRoot);
// In order to connect the AX hierarchy from the SVG root element from the loaded resource
// the parent must be set, because there's no other way to get back to who created the image.
ASSERT(rootSVGObject && rootSVGObject->isAXSVGRoot());
if (!rootSVGObject->isAXSVGRoot())
return 0;
return toAXSVGRoot(rootSVGObject);
}
AXObject* AXRenderObject::remoteSVGElementHitTest(const IntPoint& point) const
{
AXObject* remote = remoteSVGRootElement();
if (!remote)
return 0;
IntSize offset = point - roundedIntPoint(elementRect().location());
return remote->accessibilityHitTest(IntPoint(offset));
}
// The boundingBox for elements within the remote SVG element needs to be offset by its position
// within the parent page, otherwise they are in relative coordinates only.
void AXRenderObject::offsetBoundingBoxForRemoteSVGElement(LayoutRect& rect) const
{
for (AXObject* parent = parentObject(); parent; parent = parent->parentObject()) {
if (parent->isAXSVGRoot()) {
rect.moveBy(parent->parentObject()->elementRect().location());
break;
}
}
}
// Hidden children are those that are not rendered or visible, but are specifically marked as aria-hidden=false,
// meaning that they should be exposed to the AX hierarchy.
void AXRenderObject::addHiddenChildren()
{
Node* node = this->node();
if (!node)
return;
// First do a quick run through to determine if we have any hidden nodes (most often we will not).
// If we do have hidden nodes, we need to determine where to insert them so they match DOM order as close as possible.
bool shouldInsertHiddenNodes = false;
for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
if (!child->renderer() && isNodeAriaVisible(child)) {
shouldInsertHiddenNodes = true;
break;
}
}
if (!shouldInsertHiddenNodes)
return;
// Iterate through all of the children, including those that may have already been added, and
// try to insert hidden nodes in the correct place in the DOM order.
unsigned insertionIndex = 0;
for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
if (child->renderer()) {
// Find out where the last render sibling is located within m_children.
AXObject* childObject = axObjectCache()->get(child->renderer());
if (childObject && childObject->accessibilityIsIgnored()) {
AccessibilityChildrenVector children = childObject->children();
if (children.size())
childObject = children.last().get();
else
childObject = 0;
}
if (childObject)
insertionIndex = m_children.find(childObject) + 1;
continue;
}
if (!isNodeAriaVisible(child))
continue;
unsigned previousSize = m_children.size();
if (insertionIndex > previousSize)
insertionIndex = previousSize;
insertChild(axObjectCache()->getOrCreate(child), insertionIndex);
insertionIndex += (m_children.size() - previousSize);
}
}
void AXRenderObject::addTextFieldChildren()
{
Node* node = this->node();
if (!isHTMLInputElement(node))
return;
HTMLInputElement& input = toHTMLInputElement(*node);
Element* spinButtonElement = input.userAgentShadowRoot()->getElementById(ShadowElementNames::spinButton());
if (!spinButtonElement || !spinButtonElement->isSpinButtonElement())
return;
AXSpinButton* axSpinButton = toAXSpinButton(axObjectCache()->getOrCreate(SpinButtonRole));
axSpinButton->setSpinButtonElement(toSpinButtonElement(spinButtonElement));
axSpinButton->setParent(this);
m_children.append(axSpinButton);
}
void AXRenderObject::addImageMapChildren()
{
RenderBoxModelObject* cssBox = renderBoxModelObject();
if (!cssBox || !cssBox->isRenderImage())
return;
HTMLMapElement* map = toRenderImage(cssBox)->imageMap();
if (!map)
return;
for (HTMLAreaElement* area = Traversal<HTMLAreaElement>::firstWithin(*map); area; area = Traversal<HTMLAreaElement>::next(*area, map)) {
// add an <area> element for this child if it has a link
if (area->isLink()) {
AXImageMapLink* areaObject = toAXImageMapLink(axObjectCache()->getOrCreate(ImageMapLinkRole));
areaObject->setHTMLAreaElement(area);
areaObject->setHTMLMapElement(map);
areaObject->setParent(this);
if (!areaObject->accessibilityIsIgnored())
m_children.append(areaObject);
else
axObjectCache()->remove(areaObject->axObjectID());
}
}
}
void AXRenderObject::addCanvasChildren()
{
if (!isHTMLCanvasElement(node()))
return;
// If it's a canvas, it won't have rendered children, but it might have accessible fallback content.
// Clear m_haveChildren because AXNodeObject::addChildren will expect it to be false.
ASSERT(!m_children.size());
m_haveChildren = false;
AXNodeObject::addChildren();
}
void AXRenderObject::addAttachmentChildren()
{
if (!isAttachment())
return;
// FrameView's need to be inserted into the AX hierarchy when encountered.
Widget* widget = widgetForAttachmentView();
if (!widget || !widget->isFrameView())
return;
AXObject* axWidget = axObjectCache()->getOrCreate(widget);
if (!axWidget->accessibilityIsIgnored())
m_children.append(axWidget);
}
void AXRenderObject::addRemoteSVGChildren()
{
AXSVGRoot* root = remoteSVGRootElement();
if (!root)
return;
root->setParent(this);
if (root->accessibilityIsIgnored()) {
AccessibilityChildrenVector children = root->children();
unsigned length = children.size();
for (unsigned i = 0; i < length; ++i)
m_children.append(children[i]);
} else {
m_children.append(root);
}
}
void AXRenderObject::ariaSelectedRows(AccessibilityChildrenVector& result)
{
// Get all the rows.
AccessibilityChildrenVector allRows;
if (isTree())
ariaTreeRows(allRows);
else if (isAXTable() && toAXTable(this)->supportsSelectedRows())
allRows = toAXTable(this)->rows();
// Determine which rows are selected.
bool isMulti = isMultiSelectable();
// Prefer active descendant over aria-selected.
AXObject* activeDesc = activeDescendant();
if (activeDesc && (activeDesc->isTreeItem() || activeDesc->isTableRow())) {
result.append(activeDesc);
if (!isMulti)
return;
}
unsigned count = allRows.size();
for (unsigned k = 0; k < count; ++k) {
if (allRows[k]->isSelected()) {
result.append(allRows[k]);
if (!isMulti)
break;
}
}
}
bool AXRenderObject::elementAttributeValue(const QualifiedName& attributeName) const
{
if (!m_renderer)
return false;
return equalIgnoringCase(getAttribute(attributeName), "true");
}
bool AXRenderObject::inheritsPresentationalRole() const
{
// ARIA states if an item can get focus, it should not be presentational.
if (canSetFocusAttribute())
return false;
// ARIA spec says that when a parent object is presentational, and it has required child elements,
// those child elements are also presentational. For example, <li> becomes presentational from <ul>.
// http://www.w3.org/WAI/PF/aria/complete#presentation
if (roleValue() != ListItemRole && roleValue() != ListMarkerRole)
return false;
AXObject* parent = parentObject();
if (!parent->isAXRenderObject())
return false;
Node* elementNode = toAXRenderObject(parent)->node();
if (!elementNode || !elementNode->isElementNode())
return false;
QualifiedName tagName = toElement(elementNode)->tagQName();
if (tagName == ulTag || tagName == olTag || tagName == dlTag)
return parent->roleValue() == PresentationalRole;
return false;
}
LayoutRect AXRenderObject::computeElementRect() const
{
RenderObject* obj = m_renderer;
if (!obj)
return LayoutRect();
if (obj->node()) // If we are a continuation, we want to make sure to use the primary renderer.
obj = obj->node()->renderer();
// absoluteFocusRingQuads will query the hierarchy below this element, which for large webpages can be very slow.
// For a web area, which will have the most elements of any element, absoluteQuads should be used.
// We should also use absoluteQuads for SVG elements, otherwise transforms won't be applied.
Vector<FloatQuad> quads;
if (obj->isText())
toRenderText(obj)->absoluteQuads(quads, 0, RenderText::ClipToEllipsis);
else if (isWebArea() || obj->isSVGRoot())
obj->absoluteQuads(quads);
else
obj->absoluteFocusRingQuads(quads);
LayoutRect result = boundingBoxForQuads(obj, quads);
Document* document = this->document();
if (document && document->isSVGDocument())
offsetBoundingBoxForRemoteSVGElement(result);
// The size of the web area should be the content size, not the clipped size.
if (isWebArea() && obj->frame()->view())
result.setSize(obj->frame()->view()->contentsSize());
// Checkboxes and radio buttons include their label as part of their rect.
if (isCheckboxOrRadio()) {
HTMLLabelElement* label = labelForElement(toElement(m_renderer->node()));
if (label && label->renderer()) {
LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementRect();
result.unite(labelRect);
}
}
return result;
}
} // namespace WebCore
|