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 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/accessibility/accessibility_controller.h"
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include "ash/accelerators/accelerator_controller_impl.h"
#include "ash/accessibility/a11y_feature_type.h"
#include "ash/accessibility/accessibility_notification_controller.h"
#include "ash/accessibility/accessibility_observer.h"
#include "ash/accessibility/autoclick/autoclick_controller.h"
#include "ash/accessibility/disable_touchpad_event_rewriter.h"
#include "ash/accessibility/drag_event_rewriter.h"
#include "ash/accessibility/filter_keys_event_rewriter.h"
#include "ash/accessibility/flash_screen_controller.h"
#include "ash/accessibility/mouse_keys/mouse_keys_controller.h"
#include "ash/accessibility/sticky_keys/sticky_keys_controller.h"
#include "ash/accessibility/switch_access/point_scan_controller.h"
#include "ash/accessibility/ui/accessibility_confirmation_dialog.h"
#include "ash/accessibility/ui/accessibility_highlight_controller.h"
#include "ash/accessibility/ui/accessibility_panel_layout_manager.h"
#include "ash/color_enhancement/color_enhancement_controller.h"
#include "ash/constants/ash_constants.h"
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/constants/notifier_catalogs.h"
#include "ash/events/accessibility_event_rewriter.h"
#include "ash/events/event_rewriter_controller_impl.h"
#include "ash/events/select_to_speak_event_handler.h"
#include "ash/keyboard/keyboard_controller_impl.h"
#include "ash/keyboard/ui/keyboard_util.h"
#include "ash/login_status.h"
#include "ash/policy/policy_recommendation_restorer.h"
#include "ash/public/cpp/accessibility_controller_client.h"
#include "ash/public/cpp/accessibility_controller_enums.h"
#include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/notification_utils.h"
#include "ash/public/cpp/session/session_observer.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/system/anchored_nudge_data.h"
#include "ash/public/cpp/system/anchored_nudge_manager.h"
#include "ash/public/cpp/system_tray_client.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/accessibility/accessibility_feature_disable_dialog.h"
#include "ash/system/accessibility/dictation_bubble_controller.h"
#include "ash/system/accessibility/dictation_button_tray.h"
#include "ash/system/accessibility/facegaze_bubble_controller.h"
#include "ash/system/accessibility/floating_accessibility_controller.h"
#include "ash/system/accessibility/select_to_speak/select_to_speak_menu_bubble_controller.h"
#include "ash/system/accessibility/switch_access/switch_access_menu_bubble_controller.h"
#include "ash/system/input_device_settings/input_device_settings_controller_impl.h"
#include "ash/system/model/enterprise_domain_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/power/backlights_forced_off_setter.h"
#include "ash/system/power/power_status.h"
#include "ash/system/power/scoped_backlights_forced_off.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/wm/window_util.h"
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "chromeos/ash/components/audio/cras_audio_handler.h"
#include "chromeos/ash/components/audio/sounds.h"
#include "components/live_caption/caption_util.h"
#include "components/live_caption/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/session_manager/session_manager_types.h"
#include "components/user_manager/user_type.h"
#include "components/vector_icons/vector_icons.h"
#include "media/base/media_switches.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/accessibility/aura/aura_window_properties.h"
#include "ui/aura/window.h"
#include "ui/base/cursor/cursor_size.h"
#include "ui/base/ime/ash/ime_keyboard.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/display/screen.h"
#include "ui/display/tablet_state.h"
#include "ui/events/ash/keyboard_capability.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/keyboard_device.h"
#include "ui/events/event_sink.h"
#include "ui/gfx/animation/animation.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/notifier_id.h"
#include "ui/native_theme/features/native_theme_features.h"
#include "ui/native_theme/native_theme.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/core/cursor_manager.h"
using session_manager::SessionState;
namespace ash {
namespace {
// How much time before the time out dialog should close.
const int kDialogTimeoutSeconds = 30;
// How much distance to travel with each generated scroll event.
const int kScrollDelta = 40;
AccessibilityController* g_instance = nullptr;
using FeatureType = A11yFeatureType;
// These classes are used to store the static configuration for a11y features.
struct FeatureData {
FeatureType type;
const char* pref;
// This field is not a raw_ptr<> because it only ever points to statically-
// allocated data which is never freed, and hence cannot dangle.
RAW_PTR_EXCLUSION const gfx::VectorIcon* icon;
const int name_resource_id;
bool toggleable_in_quicksettings = true;
FeatureType conflicting_feature = FeatureType::kNoConflictingFeature;
};
struct FeatureDialogData {
FeatureType type;
const char* pref;
int title;
int body;
};
// A static array describing each feature.
const FeatureData kFeatures[] = {
{FeatureType::kAlwaysShowScrollbar,
prefs::kAccessibilityAlwaysShowScrollbarsEnabled, nullptr, 0,
/*toggleable_in_quicksettings=*/false},
{FeatureType::kAutoclick, prefs::kAccessibilityAutoclickEnabled,
&kSystemMenuAccessibilityAutoClickIcon,
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_AUTOCLICK},
{FeatureType::kBounceKeys, prefs::kAccessibilityBounceKeysEnabled, nullptr,
0, /*toggleable_in_quicksettings=*/false},
{FeatureType::kCaretHighlight, prefs::kAccessibilityCaretHighlightEnabled,
nullptr, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_CARET_HIGHLIGHT},
{FeatureType::kCursorHighlight, prefs::kAccessibilityCursorHighlightEnabled,
nullptr, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGHLIGHT_MOUSE_CURSOR},
{FeatureType::kCursorColor, prefs::kAccessibilityCursorColorEnabled,
nullptr, 0, /*toggleable_in_quicksettings=*/false},
{FeatureType::kDictation, prefs::kAccessibilityDictationEnabled,
&kDictationMenuIcon, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DICTATION},
{FeatureType::kColorCorrection, prefs::kAccessibilityColorCorrectionEnabled,
&kColorCorrectionIcon, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_COLOR_CORRECTION},
{FeatureType::kFlashNotifications,
prefs::kAccessibilityFlashNotificationsEnabled, nullptr, 0,
/*toggleable_in_quicksettings=*/false},
{FeatureType::kFocusHighlight, prefs::kAccessibilityFocusHighlightEnabled,
nullptr, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGHLIGHT_KEYBOARD_FOCUS,
/*toggleable_in_quicksettings=*/true,
/* conflicting_feature= */ FeatureType::kSpokenFeedback},
{FeatureType::kFloatingMenu, prefs::kAccessibilityFloatingMenuEnabled,
nullptr, IDS_ASH_FLOATING_ACCESSIBILITY_MAIN_MENU,
/*toggleable_in_quicksettings=*/false},
{FeatureType::kFullscreenMagnifier,
prefs::kAccessibilityScreenMagnifierEnabled,
&kSystemMenuAccessibilityFullscreenMagnifierIcon,
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SCREEN_MAGNIFIER},
{FeatureType::kDockedMagnifier, prefs::kDockedMagnifierEnabled,
&kSystemMenuAccessibilityDockedMagnifierIcon,
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DOCKED_MAGNIFIER},
{FeatureType::kHighContrast, prefs::kAccessibilityHighContrastEnabled,
&kSystemMenuAccessibilityContrastIcon,
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_HIGH_CONTRAST_MODE},
{FeatureType::kLargeCursor, prefs::kAccessibilityLargeCursorEnabled,
nullptr, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_LARGE_CURSOR},
{FeatureType::kLiveCaption, ::prefs::kLiveCaptionEnabled,
&vector_icons::kLiveCaptionOnIcon, IDS_ASH_STATUS_TRAY_LIVE_CAPTION},
{FeatureType::kMonoAudio, prefs::kAccessibilityMonoAudioEnabled, nullptr,
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_MONO_AUDIO},
{FeatureType::kMouseKeys, prefs::kAccessibilityMouseKeysEnabled, nullptr, 0,
/*toggleable_in_quicksettings=*/false},
{FeatureType::kSpokenFeedback, prefs::kAccessibilitySpokenFeedbackEnabled,
&kSystemMenuAccessibilityChromevoxIcon,
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SPOKEN_FEEDBACK},
{FeatureType::kReducedAnimations,
prefs::kAccessibilityReducedAnimationsEnabled, nullptr, 0,
/*toggleable_in_quicksettings=*/false},
{FeatureType::kSelectToSpeak, prefs::kAccessibilitySelectToSpeakEnabled,
&kSystemMenuAccessibilitySelectToSpeakIcon,
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SELECT_TO_SPEAK},
{FeatureType::kSlowKeys, prefs::kAccessibilitySlowKeysEnabled, nullptr, 0,
/*toggleable_in_quicksettings=*/false},
{FeatureType::kStickyKeys, prefs::kAccessibilityStickyKeysEnabled, nullptr,
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_STICKY_KEYS,
/*toggleable_in_quicksettings=*/true,
/*conflicting_feature=*/FeatureType::kSpokenFeedback},
{FeatureType::kSwitchAccess, prefs::kAccessibilitySwitchAccessEnabled,
&kSwitchAccessIcon, IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SWITCH_ACCESS},
{FeatureType::kVirtualKeyboard, prefs::kAccessibilityVirtualKeyboardEnabled,
&kSystemMenuKeyboardLegacyIcon,
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD},
{FeatureType::kFaceGaze, prefs::kAccessibilityFaceGazeEnabled, nullptr,
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_FACEGAZE,
/*toggleable_in_quicksettings=*/true},
{FeatureType::kDisableTouchpad, prefs::kAccessibilityDisableTrackpadEnabled,
nullptr, 0, /*toggleable_in_quicksettings=*/false},
};
// An array describing the confirmation dialogs for the features which have
// them.
const FeatureDialogData kFeatureDialogs[] = {
{FeatureType::kFullscreenMagnifier,
prefs::kScreenMagnifierAcceleratorDialogHasBeenAccepted},
{FeatureType::kDockedMagnifier,
prefs::kDockedMagnifierAcceleratorDialogHasBeenAccepted},
{FeatureType::kHighContrast,
prefs::kHighContrastAcceleratorDialogHasBeenAccepted}};
constexpr char kFaceGazeActiveNotificationId[] =
"facegaze_active_notification_id";
constexpr char kNotificationId[] = "chrome://settings/accessibility";
constexpr char kNotifierAccessibility[] = "ash.accessibility";
constexpr char kDictationLanguageUpgradedNudgeId[] =
"dictation_language_upgraded.nudge_id";
// TODO(warx): Signin screen has more controllable accessibility prefs. We may
// want to expand this to a complete list. If so, merge this with
// |kCopiedOnSigninAccessibilityPrefs|.
constexpr const char* const kA11yPrefsForRecommendedValueOnSignin[]{
prefs::kAccessibilityLargeCursorEnabled,
prefs::kAccessibilityHighContrastEnabled,
prefs::kAccessibilityScreenMagnifierEnabled,
prefs::kAccessibilitySpokenFeedbackEnabled,
prefs::kAccessibilityVirtualKeyboardEnabled,
};
// List of accessibility prefs that are to be copied (if changed by the user) on
// signin screen profile to a newly created user profile or a guest session.
constexpr const char* const kCopiedOnSigninAccessibilityPrefs[]{
prefs::kAccessibilityAutoclickDelayMs,
prefs::kAccessibilityAutoclickEnabled,
prefs::kAccessibilityBounceKeysDelayMs,
prefs::kAccessibilityBounceKeysEnabled,
prefs::kAccessibilityCaretHighlightEnabled,
prefs::kAccessibilityChromeVoxAutoRead,
prefs::kAccessibilityChromeVoxAnnounceDownloadNotifications,
prefs::kAccessibilityChromeVoxAnnounceRichTextAttributes,
prefs::kAccessibilityChromeVoxAudioStrategy,
prefs::kAccessibilityChromeVoxBrailleSideBySide,
prefs::kAccessibilityChromeVoxBrailleTable,
prefs::kAccessibilityChromeVoxBrailleTable6,
prefs::kAccessibilityChromeVoxBrailleTable8,
prefs::kAccessibilityChromeVoxBrailleTableType,
prefs::kAccessibilityChromeVoxBrailleWordWrap,
prefs::kAccessibilityChromeVoxCapitalStrategy,
prefs::kAccessibilityChromeVoxCapitalStrategyBackup,
prefs::kAccessibilityChromeVoxEnableBrailleLogging,
prefs::kAccessibilityChromeVoxEnableEarconLogging,
prefs::kAccessibilityChromeVoxEnableEventStreamLogging,
prefs::kAccessibilityChromeVoxEnableSpeechLogging,
prefs::kAccessibilityChromeVoxEventStreamFilters,
prefs::kAccessibilityChromeVoxLanguageSwitching,
prefs::kAccessibilityChromeVoxMenuBrailleCommands,
prefs::kAccessibilityChromeVoxNumberReadingStyle,
prefs::kAccessibilityChromeVoxPreferredBrailleDisplayAddress,
prefs::kAccessibilityChromeVoxPunctuationEcho,
prefs::kAccessibilityChromeVoxSmartStickyMode,
prefs::kAccessibilityChromeVoxSpeakTextUnderMouse,
prefs::kAccessibilityChromeVoxUsePitchChanges,
prefs::kAccessibilityChromeVoxUseVerboseMode,
prefs::kAccessibilityChromeVoxVirtualBrailleColumns,
prefs::kAccessibilityChromeVoxVirtualBrailleRows,
prefs::kAccessibilityChromeVoxVoiceName,
prefs::kAccessibilityColorCorrectionEnabled,
prefs::kAccessibilityCursorHighlightEnabled,
prefs::kAccessibilityCursorColorEnabled,
prefs::kAccessibilityCursorColor,
prefs::kAccessibilityDictationEnabled,
prefs::kAccessibilityDictationLocale,
prefs::kAccessibilityDictationLocaleOfflineNudge,
prefs::kAccessibilityDisableTrackpadEnabled,
prefs::kAccessibilityDisableTrackpadMode,
prefs::kAccessibilityFocusHighlightEnabled,
prefs::kAccessibilityHighContrastEnabled,
prefs::kAccessibilityLargeCursorEnabled,
prefs::kAccessibilityFaceGazeEnabled,
prefs::kAccessibilityMonoAudioEnabled,
prefs::kAccessibilityReducedAnimationsEnabled,
prefs::kAccessibilityAlwaysShowScrollbarsEnabled,
prefs::kAccessibilityMouseKeysEnabled,
prefs::kAccessibilityMouseKeysAcceleration,
prefs::kAccessibilityMouseKeysMaxSpeed,
prefs::kAccessibilityMouseKeysUsePrimaryKeys,
prefs::kAccessibilityMouseKeysDominantHand,
prefs::kAccessibilityScreenMagnifierEnabled,
prefs::kAccessibilityScreenMagnifierFocusFollowingEnabled,
prefs::kAccessibilityMagnifierFollowsChromeVox,
prefs::kAccessibilityMagnifierFollowsSts,
prefs::kAccessibilityScreenMagnifierMouseFollowingMode,
prefs::kAccessibilityScreenMagnifierScale,
prefs::kAccessibilitySelectToSpeakEnabled,
prefs::kAccessibilitySlowKeysDelayMs,
prefs::kAccessibilitySlowKeysEnabled,
prefs::kAccessibilitySpokenFeedbackEnabled,
prefs::kAccessibilityStickyKeysEnabled,
prefs::kAccessibilityShortcutsEnabled,
prefs::kAccessibilitySwitchAccessEnabled,
prefs::kAccessibilityVirtualKeyboardEnabled,
prefs::kDockedMagnifierEnabled,
prefs::kDockedMagnifierScale,
prefs::kDockedMagnifierScreenHeightDivisor,
prefs::kHighContrastAcceleratorDialogHasBeenAccepted,
prefs::kScreenMagnifierAcceleratorDialogHasBeenAccepted,
prefs::kDockedMagnifierAcceleratorDialogHasBeenAccepted,
prefs::kDictationAcceleratorDialogHasBeenAccepted,
prefs::kDictationDlcSuccessNotificationHasBeenShown,
prefs::kDictationDlcOnlyPumpkinDownloadedNotificationHasBeenShown,
prefs::kDictationDlcOnlySodaDownloadedNotificationHasBeenShown,
prefs::kDictationNoDlcsDownloadedNotificationHasBeenShown,
prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted2,
prefs::kSelectToSpeakAcceleratorDialogHasBeenAccepted,
prefs::kAccessibilityFaceGazeAcceleratorDialogHasBeenAccepted,
prefs::kFaceGazeDlcSuccessNotificationHasBeenShown,
prefs::kFaceGazeDlcFailureNotificationHasBeenShown,
};
// List of switch access accessibility prefs that are to be copied (if changed
// by the user) from the current user to the signin screen profile. That way
// if a switch access user signs out, their switch continues to function.
constexpr const char* const kSwitchAccessPrefsCopiedToSignin[]{
prefs::kAccessibilitySwitchAccessAutoScanEnabled,
prefs::kAccessibilitySwitchAccessAutoScanKeyboardSpeedMs,
prefs::kAccessibilitySwitchAccessAutoScanSpeedMs,
prefs::kAccessibilitySwitchAccessPointScanSpeedDipsPerSecond,
prefs::kAccessibilitySwitchAccessEnabled,
prefs::kAccessibilitySwitchAccessNextDeviceKeyCodes,
prefs::kAccessibilitySwitchAccessPreviousDeviceKeyCodes,
prefs::kAccessibilitySwitchAccessSelectDeviceKeyCodes,
};
// Helper function that is used to verify the validity of kFeatures and
// kFeatureDialogs.
bool VerifyFeaturesData() {
// All feature prefs must be unique.
std::set<const char*> feature_prefs;
for (auto feature_data : kFeatures) {
if (base::Contains(feature_prefs, feature_data.pref)) {
return false;
}
feature_prefs.insert(feature_data.pref);
}
for (auto dialog_data : kFeatureDialogs) {
if (base::Contains(feature_prefs, dialog_data.pref)) {
return false;
}
feature_prefs.insert(dialog_data.pref);
}
return true;
}
// Returns true if |pref_service| is the one used for the signin screen.
bool IsSigninPrefService(PrefService* pref_service) {
const PrefService* signin_pref_service =
Shell::Get()->session_controller()->GetSigninScreenPrefService();
DCHECK(signin_pref_service);
return pref_service == signin_pref_service;
}
// Returns true if the current session is the guest session.
bool IsCurrentSessionGuest() {
const std::optional<user_manager::UserType> user_type =
Shell::Get()->session_controller()->GetUserType();
return user_type && *user_type == user_manager::UserType::kGuest;
}
bool IsUserFirstLogin() {
return Shell::Get()->session_controller()->IsUserFirstLogin();
}
// The copying of any modified accessibility prefs on the signin prefs happens
// when the |previous_pref_service| is of the signin profile, and the
// |current_pref_service| is of a newly created profile first logged in, or if
// the current session is the guest session.
bool ShouldCopySigninPrefs(PrefService* previous_pref_service,
PrefService* current_pref_service) {
DCHECK(previous_pref_service);
if (IsUserFirstLogin() && IsSigninPrefService(previous_pref_service) &&
!IsSigninPrefService(current_pref_service)) {
// If the user set a pref value on the login screen and is now starting a
// session with a new profile, copy the pref value to the profile.
return true;
}
if (IsCurrentSessionGuest()) {
// Guest sessions don't have their own prefs, so always copy.
return true;
}
return false;
}
// On a user's first login into a device, any a11y features enabled/disabled
// by the user on the login screen are enabled/disabled in the user's profile.
// This function copies settings from the signin prefs into the user's prefs
// when it detects a login with a newly created profile.
void CopySigninPrefsIfNeeded(PrefService* previous_pref_service,
PrefService* current_pref_service) {
DCHECK(current_pref_service);
if (!ShouldCopySigninPrefs(previous_pref_service, current_pref_service)) {
return;
}
PrefService* signin_prefs =
Shell::Get()->session_controller()->GetSigninScreenPrefService();
DCHECK(signin_prefs);
for (const auto* pref_path : kCopiedOnSigninAccessibilityPrefs) {
const PrefService::Preference* pref =
signin_prefs->FindPreference(pref_path);
// Ignore if the pref has not been set by the user.
if (!pref || !pref->IsUserControlled()) {
continue;
}
// Copy the pref value from the signin profile.
const base::Value* value_on_login = pref->GetValue();
current_pref_service->Set(pref_path, *value_on_login);
}
}
// Returns notification icon based on the A11yNotificationType.
const gfx::VectorIcon& GetNotificationIcon(A11yNotificationType type) {
switch (type) {
case A11yNotificationType::kSpokenFeedbackBrailleEnabled:
case A11yNotificationType::kTouchpadDisabled:
return kNotificationAccessibilityIcon;
case A11yNotificationType::kBrailleDisplayConnected:
return kNotificationAccessibilityBrailleIcon;
case A11yNotificationType::kSwitchAccessEnabled:
return kSwitchAccessIcon;
case A11yNotificationType::kDictationAllDlcsDownloaded:
case A11yNotificationType::kDictationNoDlcsDownloaded:
case A11yNotificationType::kDicationOnlyPumpkinDownloaded:
case A11yNotificationType::kDictationOnlySodaDownloaded:
return kDictationMenuIcon;
case A11yNotificationType::kFaceGazeActive:
return kFacegazeIcon;
default:
return kNotificationChromevoxIcon;
}
}
void ShowAccessibilityNotification(
const AccessibilityController::A11yNotificationWrapper& wrapper) {
A11yNotificationType type = wrapper.type;
std::string notification_id = wrapper.notification_id;
const auto& replacements = wrapper.replacements;
message_center::MessageCenter* message_center =
message_center::MessageCenter::Get();
message_center->RemoveNotification(notification_id, false /* by_user */);
if (type == A11yNotificationType::kNone) {
return;
}
std::u16string text;
std::u16string title;
std::u16string display_source;
auto catalog_name = NotificationCatalogName::kNone;
bool pinned = true;
message_center::SystemNotificationWarningLevel warning =
message_center::SystemNotificationWarningLevel::NORMAL;
message_center::RichNotificationData options;
scoped_refptr<message_center::NotificationDelegate> delegate;
if (wrapper.callback.has_value()) {
delegate =
base::MakeRefCounted<message_center::HandleNotificationClickDelegate>(
wrapper.callback.value());
}
if (type == A11yNotificationType::kBrailleDisplayConnected) {
title = l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_BRAILLE_DISPLAY_CONNECTED);
catalog_name = NotificationCatalogName::kBrailleDisplayConnected;
} else if (type == A11yNotificationType::kDictationAllDlcsDownloaded) {
display_source =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DICTATION);
title = l10n_util::GetStringFUTF16(
IDS_ASH_A11Y_DICTATION_NOTIFICATION_ALL_DLCS_DOWNLOADED_TITLE,
replacements, nullptr);
text = l10n_util::GetStringUTF16(
IDS_ASH_A11Y_DICTATION_NOTIFICATION_ALL_DLCS_DOWNLOADED_DESC);
catalog_name = NotificationCatalogName::kDictationAllDlcsDownloaded;
pinned = false;
} else if (type == A11yNotificationType::kDictationNoDlcsDownloaded) {
display_source =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DICTATION);
title = l10n_util::GetStringFUTF16(
IDS_ASH_A11Y_DICTATION_NOTIFICATION_NO_DLCS_DOWNLOADED_TITLE,
replacements, nullptr);
text = l10n_util::GetStringUTF16(
IDS_ASH_A11Y_DICTATION_NOTIFICATION_NO_DLCS_DOWNLOADED_DESC);
catalog_name = NotificationCatalogName::kDictationNoDlcsDownloaded;
pinned = false;
// Use CRITICAL_WARNING to force the notification color to red.
warning = message_center::SystemNotificationWarningLevel::CRITICAL_WARNING;
} else if (type == A11yNotificationType::kDicationOnlyPumpkinDownloaded) {
display_source =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DICTATION);
title = l10n_util::GetStringFUTF16(
IDS_ASH_A11Y_DICTATION_NOTIFICATION_ONLY_PUMPKIN_DOWNLOADED_TITLE,
replacements, nullptr);
text = l10n_util::GetStringUTF16(
IDS_ASH_A11Y_DICTATION_NOTIFICATION_ONLY_PUMPKIN_DOWNLOADED_DESC);
catalog_name = NotificationCatalogName::kDicationOnlyPumpkinDownloaded;
pinned = false;
// Use CRITICAL_WARNING to force the notification color to red.
warning = message_center::SystemNotificationWarningLevel::CRITICAL_WARNING;
} else if (type == A11yNotificationType::kDictationOnlySodaDownloaded) {
display_source =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DICTATION);
title = l10n_util::GetStringFUTF16(
IDS_ASH_A11Y_DICTATION_NOTIFICATION_ONLY_SODA_DOWNLOADED_TITLE,
replacements, nullptr);
text = l10n_util::GetStringUTF16(
IDS_ASH_A11Y_DICTATION_NOTIFICATION_ONLY_SODA_DOWNLOADED_DESC);
catalog_name = NotificationCatalogName::kDictationOnlySodaDownloaded;
pinned = false;
// Use CRITICAL_WARNING to force the notification color to red.
warning = message_center::SystemNotificationWarningLevel::CRITICAL_WARNING;
} else if (type == A11yNotificationType::kFaceGazeActive) {
title =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_FACEGAZE_ACTIVE_TITLE);
catalog_name = NotificationCatalogName::kFaceGazeActive;
options.pinned = true;
options.buttons.emplace_back(
l10n_util::GetStringUTF16(IDS_ASH_FACEGAZE_CLOSE_BUTTON_TEXT));
} else if (type == A11yNotificationType::kFaceGazeAssetsDownloaded) {
title = l10n_util::GetStringUTF16(
IDS_ASH_A11Y_FACEGAZE_ASSETS_DOWNLOADED_TITLE);
text =
l10n_util::GetStringUTF16(IDS_ASH_A11Y_FACEGAZE_ASSETS_DOWNLOADED_DESC);
catalog_name = NotificationCatalogName::kFaceGazeAssetsDownloaded;
pinned = false;
} else if (type == A11yNotificationType::kFaceGazeAssetsFailed) {
title =
l10n_util::GetStringUTF16(IDS_ASH_A11Y_FACEGAZE_ASSETS_FAILED_TITLE);
text = l10n_util::GetStringUTF16(IDS_ASH_A11Y_FACEGAZE_ASSETS_FAILED_DESC);
catalog_name = NotificationCatalogName::kFaceGazeAssetsFailed;
pinned = false;
// Use CRITICAL_WARNING to force the notification color to red.
warning = message_center::SystemNotificationWarningLevel::CRITICAL_WARNING;
} else if (type == A11yNotificationType::kSwitchAccessEnabled) {
title = l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_SWITCH_ACCESS_ENABLED_TITLE);
text = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SWITCH_ACCESS_ENABLED);
catalog_name = NotificationCatalogName::kSwitchAccessEnabled;
} else if (type == A11yNotificationType::kTouchpadDisabled) {
title =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_TOUCHPAD_DISABLED_TITLE);
text = l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_TOUCHPAD_DISABLED_DESCRIPTION);
catalog_name = NotificationCatalogName::kTouchpadDisabled;
options.pinned = true;
options.buttons.emplace_back(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_TOUCHPAD_DISABLED_TURN_ON));
} else {
bool is_tablet = display::Screen::GetScreen()->InTabletMode();
title = l10n_util::GetStringUTF16(
type == A11yNotificationType::kSpokenFeedbackBrailleEnabled
? IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_BRAILLE_ENABLED_TITLE
: IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_TITLE);
text = l10n_util::GetStringUTF16(
is_tablet ? IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED_TABLET
: IDS_ASH_STATUS_TRAY_SPOKEN_FEEDBACK_ENABLED);
catalog_name = type == A11yNotificationType::kSpokenFeedbackBrailleEnabled
? NotificationCatalogName::kSpokenFeedbackBrailleEnabled
: NotificationCatalogName::kSpokenFeedbackEnabled;
}
options.should_make_spoken_feedback_for_popup_updates = false;
std::unique_ptr<message_center::Notification> notification =
ash::CreateSystemNotificationPtr(
message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, title,
text, display_source, GURL(),
message_center::NotifierId(
message_center::NotifierType::SYSTEM_COMPONENT,
kNotifierAccessibility, catalog_name),
options, delegate, GetNotificationIcon(type), warning);
notification->set_pinned(pinned);
message_center->AddNotification(std::move(notification));
}
void RemoveAccessibilityNotification() {
ShowAccessibilityNotification(
AccessibilityController::A11yNotificationWrapper(
A11yNotificationType::kNone, kNotificationId,
std::vector<std::u16string>()));
}
AccessibilityPanelLayoutManager* GetLayoutManager() {
// The accessibility panel is only shown on the primary display.
aura::Window* root = Shell::GetPrimaryRootWindow();
aura::Window* container =
Shell::GetContainer(root, kShellWindowId_AccessibilityPanelContainer);
// TODO(jamescook): Avoid this cast by moving ash::AccessibilityObserver
// ownership to this class and notifying it on accessibility panel fullscreen
// updates.
return static_cast<AccessibilityPanelLayoutManager*>(
container->layout_manager());
}
std::string PrefKeyForSwitchAccessCommand(SwitchAccessCommand command) {
switch (command) {
case SwitchAccessCommand::kSelect:
return prefs::kAccessibilitySwitchAccessSelectDeviceKeyCodes;
case SwitchAccessCommand::kNext:
return prefs::kAccessibilitySwitchAccessNextDeviceKeyCodes;
case SwitchAccessCommand::kPrevious:
return prefs::kAccessibilitySwitchAccessPreviousDeviceKeyCodes;
case SwitchAccessCommand::kNone:
NOTREACHED();
}
}
std::string UmaNameForSwitchAccessCommand(SwitchAccessCommand command) {
switch (command) {
case SwitchAccessCommand::kSelect:
return "Accessibility.CrosSwitchAccess.SelectKeyCode";
case SwitchAccessCommand::kNext:
return "Accessibility.CrosSwitchAccess.NextKeyCode";
case SwitchAccessCommand::kPrevious:
return "Accessibility.CrosSwitchAccess.PreviousKeyCode";
case SwitchAccessCommand::kNone:
NOTREACHED();
}
}
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SwitchAccessKeyCode {
kUnknown = 0,
kKeycode1 = 1,
kKeycode2 = 2,
kKeycode3 = 3,
kKeycode4 = 4,
kKeycode5 = 5,
kKeycode6 = 6,
kKeycode7 = 7,
kBackspace = 8,
kTab = 9,
kKeycode10 = 10,
kKeycode11 = 11,
kClear = 12,
kReturn = 13,
kKeycode14 = 14,
kKeycode15 = 15,
kShift = 16,
kControl = 17,
kAlt = 18,
kPause = 19,
kCapital = 20,
kKana = 21,
kKeycode22 = 22,
kJunja = 23,
kFinal = 24,
kHanja = 25,
kKeycode26 = 26,
kEscape = 27,
kConvert = 28,
kNonconvert = 29,
kAccept = 30,
kModechange = 31,
kSpace = 32,
kPrior = 33,
kNext = 34,
kEnd = 35,
kHome = 36,
kLeft = 37,
kUp = 38,
kRight = 39,
kDown = 40,
kSelect = 41,
kPrint = 42,
kExecute = 43,
kSnapshot = 44,
kInsert = 45,
kKeyDelete = 46,
kHelp = 47,
kNum0 = 48,
kNum1 = 49,
kNum2 = 50,
kNum3 = 51,
kNum4 = 52,
kNum5 = 53,
kNum6 = 54,
kNum7 = 55,
kNum8 = 56,
kNum9 = 57,
kKeycode58 = 58,
kKeycode59 = 59,
kKeycode60 = 60,
kKeycode61 = 61,
kKeycode62 = 62,
kKeycode63 = 63,
kKeycode64 = 64,
kA = 65,
kB = 66,
kC = 67,
kD = 68,
kE = 69,
kF = 70,
kG = 71,
kH = 72,
kI = 73,
kJ = 74,
kK = 75,
kL = 76,
kM = 77,
kN = 78,
kO = 79,
kP = 80,
kQ = 81,
kR = 82,
kS = 83,
kT = 84,
kU = 85,
kV = 86,
kW = 87,
kX = 88,
kY = 89,
kZ = 90,
kLwin = 91,
kRwin = 92,
kApps = 93,
kKeycode94 = 94,
kSleep = 95,
kNumpad0 = 96,
kNumpad1 = 97,
kNumpad2 = 98,
kNumpad3 = 99,
kNumpad4 = 100,
kNumpad5 = 101,
kNumpad6 = 102,
kNumpad7 = 103,
kNumpad8 = 104,
kNumpad9 = 105,
kMultiply = 106,
kAdd = 107,
kSeparator = 108,
kSubtract = 109,
kDecimal = 110,
kDivide = 111,
kF1 = 112,
kF2 = 113,
kF3 = 114,
kF4 = 115,
kF5 = 116,
kF6 = 117,
kF7 = 118,
kF8 = 119,
kF9 = 120,
kF10 = 121,
kF11 = 122,
kF12 = 123,
kF13 = 124,
kF14 = 125,
kF15 = 126,
kF16 = 127,
kF17 = 128,
kF18 = 129,
kF19 = 130,
kF20 = 131,
kF21 = 132,
kF22 = 133,
kF23 = 134,
kF24 = 135,
kKeycode136 = 136,
kKeycode137 = 137,
kKeycode138 = 138,
kKeycode139 = 139,
kKeycode140 = 140,
kKeycode141 = 141,
kKeycode142 = 142,
kKeycode143 = 143,
kNumlock = 144,
kScroll = 145,
kKeycode146 = 146,
kKeycode147 = 147,
kKeycode148 = 148,
kKeycode149 = 149,
kKeycode150 = 150,
kWlan = 151,
kPower = 152,
kAssistant = 153,
kKeycode154 = 154,
kKeycode155 = 155,
kKeycode156 = 156,
kKeycode157 = 157,
kKeycode158 = 158,
kKeycode159 = 159,
kLshift = 160,
kRshift = 161,
kLcontrol = 162,
kRcontrol = 163,
kLmenu = 164,
kRmenu = 165,
kBrowserBack = 166,
kBrowserForward = 167,
kBrowserRefresh = 168,
kBrowserStop = 169,
kBrowserSearch = 170,
kBrowserFavorites = 171,
kBrowserHome = 172,
kVolumeMute = 173,
kVolumeDown = 174,
kVolumeUp = 175,
kMediaNextTrack = 176,
kMediaPrevTrack = 177,
kMediaStop = 178,
kMediaPlayPause = 179,
kMediaLaunchMail = 180,
kMediaLaunchMediaSelect = 181,
kMediaLaunchApp1 = 182,
kMediaLaunchApp2 = 183,
kKeycode184 = 184,
kKeycode185 = 185,
kOem1 = 186,
kOemPlus = 187,
kOemComma = 188,
kOemMinus = 189,
kOemPeriod = 190,
kOem2 = 191,
kOem3 = 192,
kKeycode193 = 193,
kKeycode194 = 194,
kKeycode195 = 195,
kKeycode196 = 196,
kKeycode197 = 197,
kKeycode198 = 198,
kKeycode199 = 199,
kKeycode200 = 200,
kKeycode201 = 201,
kKeycode202 = 202,
kKeycode203 = 203,
kKeycode204 = 204,
kKeycode205 = 205,
kKeycode206 = 206,
kKeycode207 = 207,
kKeycode208 = 208,
kKeycode209 = 209,
kKeycode210 = 210,
kKeycode211 = 211,
kKeycode212 = 212,
kKeycode213 = 213,
kKeycode214 = 214,
kKeycode215 = 215,
kBrightnessDown = 216,
kBrightnessUp = 217,
kKbdBrightnessDown = 218,
kOem4 = 219,
kOem5 = 220,
kOem6 = 221,
kOem7 = 222,
kOem8 = 223,
kKeycode224 = 224,
kAltgr = 225,
kOem102 = 226,
kKeycode227 = 227,
kKeycode228 = 228,
kProcesskey = 229,
kCompose = 230,
kPacket = 231,
kKbdBrightnessUp = 232,
kKeycode233 = 233,
kKeycode234 = 234,
kKeycode235 = 235,
kKeycode236 = 236,
kKeycode237 = 237,
kKeycode238 = 238,
kKeycode239 = 239,
kKeycode240 = 240,
kKeycode241 = 241,
kKeycode242 = 242,
kDbeSbcschar = 243,
kDbeDbcschar = 244,
kKeycode245 = 245,
kAttn = 246,
kCrsel = 247,
kExsel = 248,
kEreof = 249,
kPlay = 250,
kZoom = 251,
kNoname = 252,
kPa1 = 253,
kOemClear = 254,
kKeycode255 = 255,
kNone = 256,
kMaxValue = kNone,
};
} // namespace
AccessibilityController::Feature::Feature(
FeatureType type,
const std::string& pref_name,
const gfx::VectorIcon* icon,
const int name_resource_id,
const bool toggleable_in_quicksettings,
AccessibilityController* controller)
: type_(type),
pref_name_(pref_name),
icon_(icon),
name_resource_id_(name_resource_id),
toggleable_in_quicksettings_(toggleable_in_quicksettings),
owner_(controller) {
// If a feature is toggleable in quicksettings it must have a
// `name_resource_id` so it's name can be looked up.
if (toggleable_in_quicksettings_) {
CHECK(name_resource_id);
}
}
AccessibilityController::Feature::~Feature() = default;
void AccessibilityController::Feature::SetEnabled(bool enabled) {
PrefService* prefs = owner_->active_user_prefs_;
if (!prefs) {
return;
}
prefs->SetBoolean(pref_name_, enabled);
prefs->CommitPendingWrite();
}
bool AccessibilityController::Feature::IsVisibleInTray() const {
return (conflicting_feature_ == FeatureType::kNoConflictingFeature ||
!owner_->GetFeature(conflicting_feature_).enabled()) &&
owner_->IsAccessibilityFeatureVisibleInTrayMenu(pref_name_);
}
bool AccessibilityController::Feature::IsEnterpriseIconVisible() const {
return owner_->IsEnterpriseIconVisibleInTrayMenu(pref_name_);
}
const gfx::VectorIcon& AccessibilityController::Feature::icon() const {
DCHECK(icon_);
if (icon_) {
return *icon_;
}
return kPaletteTrayIconDefaultIcon;
}
void AccessibilityController::Feature::UpdateFromPref() {
PrefService* prefs = owner_->active_user_prefs_;
DCHECK(prefs);
bool enabled = prefs->GetBoolean(pref_name_);
if (conflicting_feature_ != FeatureType::kNoConflictingFeature &&
owner_->GetFeature(conflicting_feature_).enabled()) {
enabled = false;
}
if (enabled) {
// If it was turned on and we are in a active logged in session,
// prepare to record duration metrics.
session_manager::SessionState session_state =
Shell::Get()->session_controller()->GetSessionState();
if (session_state == session_manager::SessionState::ACTIVE) {
enabled_time_ = base::Time::Now();
}
} else {
// Disabled. Log the duration since it was enabled, if needed.
LogDurationMetric();
}
if (enabled == enabled_) {
return;
}
enabled_ = enabled;
owner_->UpdateFeatureFromPref(type_);
}
// don't pass prefservice here because it might be old.
// instead save the session state type from when enabled_time_ was set.
// maybe don't bother logging user type. just have this be for logged in??
// is session state more interesting?
// duration if session state is ACTIVE
void AccessibilityController::Feature::LogDurationMetric() {
if (enabled_time_ == base::Time()) {
return;
}
std::string feature_duration_metric = "Accessibility.";
switch (type_) {
case FeatureType::kAlwaysShowScrollbar:
feature_duration_metric += "CrosAlwaysShowScrollbar";
break;
case FeatureType::kAutoclick:
feature_duration_metric += "CrosAutoclick";
break;
case FeatureType::kBounceKeys:
feature_duration_metric += "CrosBounceKeys";
break;
case FeatureType::kCaretHighlight:
feature_duration_metric += "CrosCaretHighlight";
break;
case FeatureType::kColorCorrection:
feature_duration_metric += "CrosColorCorrection";
break;
case FeatureType::kCursorColor:
feature_duration_metric += "CrosCursorColor";
break;
case FeatureType::kCursorHighlight:
feature_duration_metric += "CrosCursorHighlight";
break;
case FeatureType::kDictation:
feature_duration_metric += "CrosDictation";
break;
case FeatureType::kDisableTouchpad:
feature_duration_metric += "CrosDisableTouchpad";
break;
case FeatureType::kDockedMagnifier:
feature_duration_metric += "CrosDockedMagnifier";
break;
case FeatureType::kFaceGaze:
feature_duration_metric += "CrosFaceGaze";
break;
case FeatureType::kFlashNotifications:
feature_duration_metric += "CrosFlashNotifications";
break;
case FeatureType::kFocusHighlight:
feature_duration_metric += "CrosFocusHighlight";
break;
case FeatureType::kFullscreenMagnifier:
feature_duration_metric += "CrosScreenMagnifier";
break;
case FeatureType::kHighContrast:
feature_duration_metric += "CrosHighContrast";
break;
case FeatureType::kLargeCursor:
feature_duration_metric += "CrosLargeCursor";
break;
case FeatureType::kLiveCaption:
feature_duration_metric += "CrosLiveCaption";
break;
case FeatureType::kMonoAudio:
feature_duration_metric += "CrosMonoAudio";
break;
case FeatureType::kMouseKeys:
feature_duration_metric += "CrosMouseKeys";
break;
case FeatureType::kReducedAnimations:
feature_duration_metric += "CrosReducedAnimations";
break;
case FeatureType::kSelectToSpeak:
feature_duration_metric += "CrosSelectToSpeak";
break;
case FeatureType::kSlowKeys:
feature_duration_metric += "CrosSlowKeys";
break;
case FeatureType::kSpokenFeedback:
feature_duration_metric += "CrosSpokenFeedback";
break;
case FeatureType::kStickyKeys:
feature_duration_metric += "CrosStickyKeys";
break;
case FeatureType::kSwitchAccess:
feature_duration_metric += "CrosSwitchAccess";
break;
case FeatureType::kVirtualKeyboard:
feature_duration_metric += "CrosVirtualKeyboard";
break;
default:
return;
}
feature_duration_metric += ".SessionDuration";
base::TimeDelta duration = base::Time::Now() - enabled_time_;
base::UmaHistogramCustomCounts(feature_duration_metric, duration.InSeconds(),
1, base::Days(1) / base::Seconds(1), 100);
// Reset enabled time as this duration is now logged and accounted for.
enabled_time_ = base::Time();
}
void AccessibilityController::Feature::SetConflictingFeature(
FeatureType feature) {
DCHECK_EQ(conflicting_feature_, FeatureType::kNoConflictingFeature);
conflicting_feature_ = feature;
}
void AccessibilityController::Feature::ObserveConflictingFeature() {
std::string conflicting_pref_name = "";
switch (conflicting_feature_) {
case A11yFeatureType::kSpokenFeedback:
conflicting_pref_name = prefs::kAccessibilitySpokenFeedbackEnabled;
break;
default:
// No other features are used as conflicting features at the moment,
// but this could be populated if needed in the future.
NOTREACHED() << "No pref name for conflicting feature "
<< static_cast<int>(conflicting_feature_);
}
pref_change_registrar_ = std::make_unique<PrefChangeRegistrar>();
pref_change_registrar_->Init(owner_->active_user_prefs_);
pref_change_registrar_->Add(
conflicting_pref_name,
base::BindRepeating(&AccessibilityController::Feature::UpdateFromPref,
base::Unretained(this)));
}
AccessibilityController::FeatureWithDialog::FeatureWithDialog(
FeatureType type,
const std::string& pref_name,
const gfx::VectorIcon* icon,
const int name_resource_id,
const bool toggleable_in_quicksettings,
const std::string& dialog_pref,
AccessibilityController* controller)
: AccessibilityController::Feature(type,
pref_name,
icon,
name_resource_id,
toggleable_in_quicksettings,
controller),
dialog_pref_(dialog_pref) {}
AccessibilityController::FeatureWithDialog::~FeatureWithDialog() = default;
void AccessibilityController::FeatureWithDialog::SetDialogAccepted() {
PrefService* prefs = owner_->active_user_prefs_;
if (!prefs) {
return;
}
prefs->SetBoolean(dialog_pref_, true);
prefs->CommitPendingWrite();
}
bool AccessibilityController::FeatureWithDialog::WasDialogAccepted() const {
PrefService* prefs = owner_->active_user_prefs_;
DCHECK(prefs);
return prefs->GetBoolean(dialog_pref_);
}
// static
AccessibilityController* AccessibilityController::Get() {
return g_instance;
}
AccessibilityController::AccessibilityController()
: autoclick_delay_(AutoclickController::GetDefaultAutoclickDelay()) {
DCHECK_EQ(nullptr, g_instance);
g_instance = this;
Shell::Get()->session_controller()->AddObserver(this);
display::Screen::GetScreen()->AddObserver(this);
CreateAccessibilityFeatures();
accessibility_notification_controller_ =
std::make_unique<AccessibilityNotificationController>();
flash_screen_controller_ = std::make_unique<FlashScreenController>();
}
AccessibilityController::~AccessibilityController() {
floating_menu_controller_.reset();
accessibility_notification_controller_.reset();
DCHECK_EQ(this, g_instance);
g_instance = nullptr;
}
void AccessibilityController::CreateAccessibilityFeatures() {
// First, build all features with dialog.
std::map<FeatureType, std::string> dialogs;
for (auto dialog_data : kFeatureDialogs) {
dialogs[dialog_data.type] = dialog_data.pref;
}
for (auto feature_data : kFeatures) {
size_t feature_index = static_cast<size_t>(feature_data.type);
DCHECK(!features_[feature_index]);
auto it = dialogs.find(feature_data.type);
if (it == dialogs.end()) {
features_[feature_index] = std::make_unique<Feature>(
feature_data.type, feature_data.pref, feature_data.icon,
feature_data.name_resource_id,
feature_data.toggleable_in_quicksettings, this);
} else {
features_[feature_index] = std::make_unique<FeatureWithDialog>(
feature_data.type, feature_data.pref, feature_data.icon,
feature_data.name_resource_id,
feature_data.toggleable_in_quicksettings, it->second, this);
}
if (feature_data.conflicting_feature !=
FeatureType::kNoConflictingFeature) {
features_[feature_index]->SetConflictingFeature(
feature_data.conflicting_feature);
}
}
}
// static
void AccessibilityController::RegisterProfilePrefs(
PrefRegistrySimple* registry) {
//
// Non-syncable prefs.
//
// These prefs control whether an accessibility feature is enabled. They are
// not synced due to the impact they have on device interaction.
registry->RegisterBooleanPref(prefs::kAccessibilityAutoclickEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilityBounceKeysEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilityCursorColorEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilityCaretHighlightEnabled,
false);
registry->RegisterBooleanPref(prefs::kAccessibilityCursorHighlightEnabled,
false);
registry->RegisterBooleanPref(prefs::kAccessibilityDictationEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilityFloatingMenuEnabled,
false);
registry->RegisterBooleanPref(prefs::kAccessibilityFocusHighlightEnabled,
false);
registry->RegisterBooleanPref(prefs::kAccessibilityHighContrastEnabled,
false);
registry->RegisterBooleanPref(prefs::kAccessibilityLargeCursorEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilityMonoAudioEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilityMouseKeysEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilityScreenMagnifierEnabled,
false);
registry->RegisterBooleanPref(prefs::kAccessibilitySelectToSpeakEnabled,
false);
registry->RegisterBooleanPref(prefs::kAccessibilityShortcutsEnabled, true);
registry->RegisterBooleanPref(prefs::kAccessibilitySlowKeysEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilitySpokenFeedbackEnabled,
false);
registry->RegisterBooleanPref(prefs::kAccessibilityStickyKeysEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilitySwitchAccessEnabled,
false);
registry->RegisterBooleanPref(prefs::kAccessibilityVirtualKeyboardEnabled,
false);
registry->RegisterBooleanPref(
prefs::kAccessibilityTabletModeShelfNavigationButtonsEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilityFaceGazeEnabled, false);
registry->RegisterBooleanPref(prefs::kAccessibilityFaceGazeEnabledSentinel,
false);
registry->RegisterBooleanPref(
prefs::kAccessibilityFaceGazeEnabledSentinelShowDialog, true);
registry->RegisterBooleanPref(
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel, true);
registry->RegisterBooleanPref(
prefs::kAccessibilityFaceGazeActionsEnabledSentinel, true);
registry->RegisterBooleanPref(prefs::kAccessibilityDisableTrackpadEnabled,
false);
registry->RegisterIntegerPref(prefs::kAccessibilityDisableTrackpadMode,
static_cast<int>(DisableTouchpadMode::kNever));
registry->RegisterIntegerPref(prefs::kAccessibilityCursorColor,
ui::kDefaultCursorColor);
// Not syncable because it might change depending on application locale,
// user settings, and because different languages can cause speech recognition
// files to download.
registry->RegisterStringPref(prefs::kAccessibilityDictationLocale,
std::string());
registry->RegisterDictionaryPref(
prefs::kAccessibilityDictationLocaleOfflineNudge);
// A pref in this list is associated with accepting for the first time,
// enabling of some pref above. Non-syncable like all of the above prefs.
registry->RegisterBooleanPref(
prefs::kHighContrastAcceleratorDialogHasBeenAccepted, false);
registry->RegisterBooleanPref(
prefs::kScreenMagnifierAcceleratorDialogHasBeenAccepted, false);
registry->RegisterBooleanPref(
prefs::kDockedMagnifierAcceleratorDialogHasBeenAccepted, false);
registry->RegisterBooleanPref(
prefs::kDictationAcceleratorDialogHasBeenAccepted, false);
registry->RegisterBooleanPref(
prefs::kSelectToSpeakAcceleratorDialogHasBeenAccepted, false);
registry->RegisterBooleanPref(
prefs::kDictationDlcSuccessNotificationHasBeenShown, false);
registry->RegisterBooleanPref(
prefs::kDictationDlcOnlyPumpkinDownloadedNotificationHasBeenShown, false);
registry->RegisterBooleanPref(
prefs::kDictationDlcOnlySodaDownloadedNotificationHasBeenShown, false);
registry->RegisterBooleanPref(
prefs::kDictationNoDlcsDownloadedNotificationHasBeenShown, false);
registry->RegisterBooleanPref(
prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted2, false);
registry->RegisterBooleanPref(prefs::kShouldAlwaysShowAccessibilityMenu,
false);
registry->RegisterBooleanPref(
prefs::kAccessibilityFaceGazeAcceleratorDialogHasBeenAccepted, false);
registry->RegisterBooleanPref(
prefs::kFaceGazeDlcSuccessNotificationHasBeenShown, false);
registry->RegisterBooleanPref(
prefs::kFaceGazeDlcFailureNotificationHasBeenShown, false);
registry->RegisterBooleanPref(prefs::kAccessibilityColorCorrectionEnabled,
false);
registry->RegisterBooleanPref(
prefs::kAccessibilityColorCorrectionHasBeenSetup, false);
registry->RegisterBooleanPref(prefs::kAccessibilityFlashNotificationsEnabled,
false);
registry->RegisterBooleanPref(prefs::kAccessibilityReducedAnimationsEnabled,
false);
// TODO(b/266816160): Make ChromeVox prefs are syncable, to so that ChromeOS
// backs up users' ChromeVox settings and reflects across their devices.
registry->RegisterBooleanPref(prefs::kAccessibilityChromeVoxAutoRead, false);
registry->RegisterBooleanPref(
prefs::kAccessibilityChromeVoxAnnounceDownloadNotifications, true);
registry->RegisterBooleanPref(
prefs::kAccessibilityChromeVoxAnnounceRichTextAttributes, true);
registry->RegisterStringPref(prefs::kAccessibilityChromeVoxAudioStrategy,
kDefaultAccessibilityChromeVoxAudioStrategy);
registry->RegisterBooleanPref(prefs::kAccessibilityChromeVoxBrailleSideBySide,
true);
registry->RegisterStringPref(prefs::kAccessibilityChromeVoxBrailleTable,
kDefaultAccessibilityChromeVoxBrailleTable);
registry->RegisterStringPref(prefs::kAccessibilityChromeVoxBrailleTable6,
kDefaultAccessibilityChromeVoxBrailleTable6);
registry->RegisterStringPref(prefs::kAccessibilityChromeVoxBrailleTable8,
kDefaultAccessibilityChromeVoxBrailleTable8);
registry->RegisterStringPref(prefs::kAccessibilityChromeVoxBrailleTableType,
kDefaultAccessibilityChromeVoxBrailleTableType);
registry->RegisterBooleanPref(prefs::kAccessibilityChromeVoxBrailleWordWrap,
true);
registry->RegisterStringPref(prefs::kAccessibilityChromeVoxCapitalStrategy,
kDefaultAccessibilityChromeVoxCapitalStrategy);
registry->RegisterStringPref(
prefs::kAccessibilityChromeVoxCapitalStrategyBackup,
kDefaultAccessibilityChromeVoxCapitalStrategyBackup);
registry->RegisterBooleanPref(
prefs::kAccessibilityChromeVoxEnableBrailleLogging, false);
registry->RegisterBooleanPref(
prefs::kAccessibilityChromeVoxEnableEarconLogging, false);
registry->RegisterBooleanPref(
prefs::kAccessibilityChromeVoxEnableEventStreamLogging, false);
registry->RegisterBooleanPref(
prefs::kAccessibilityChromeVoxEnableSpeechLogging, false);
registry->RegisterDictionaryPref(
prefs::kAccessibilityChromeVoxEventStreamFilters, base::Value::Dict());
registry->RegisterBooleanPref(prefs::kAccessibilityChromeVoxLanguageSwitching,
false);
registry->RegisterBooleanPref(
prefs::kAccessibilityChromeVoxMenuBrailleCommands, false);
registry->RegisterStringPref(
prefs::kAccessibilityChromeVoxNumberReadingStyle,
kDefaultAccessibilityChromeVoxNumberReadingStyle);
registry->RegisterStringPref(
prefs::kAccessibilityChromeVoxPreferredBrailleDisplayAddress,
kDefaultAccessibilityChromeVoxPreferredBrailleDisplayAddress);
registry->RegisterIntegerPref(prefs::kAccessibilityChromeVoxPunctuationEcho,
kDefaultAccessibilityChromeVoxPunctuationEcho);
registry->RegisterBooleanPref(prefs::kAccessibilityChromeVoxSmartStickyMode,
true);
registry->RegisterBooleanPref(
prefs::kAccessibilityChromeVoxSpeakTextUnderMouse, false);
registry->RegisterBooleanPref(prefs::kAccessibilityChromeVoxUsePitchChanges,
true);
registry->RegisterBooleanPref(prefs::kAccessibilityChromeVoxUseVerboseMode,
true);
registry->RegisterIntegerPref(
prefs::kAccessibilityChromeVoxVirtualBrailleColumns,
kDefaultAccessibilityChromeVoxVirtualBrailleColumns);
registry->RegisterIntegerPref(
prefs::kAccessibilityChromeVoxVirtualBrailleRows,
kDefaultAccessibilityChromeVoxVirtualBrailleRows);
registry->RegisterStringPref(prefs::kAccessibilityChromeVoxVoiceName,
kDefaultAccessibilityChromeVoxVoiceName);
// TODO(b/259372916): Enable sync for Mouse Keys settings before launch.
registry->RegisterDoublePref(prefs::kAccessibilityMouseKeysAcceleration,
MouseKeysController::kDefaultAcceleration);
registry->RegisterDoublePref(prefs::kAccessibilityMouseKeysMaxSpeed,
MouseKeysController::kDefaultMaxSpeed);
registry->RegisterBooleanPref(prefs::kAccessibilityMouseKeysUsePrimaryKeys,
true);
registry->RegisterIntegerPref(
prefs::kAccessibilityMouseKeysDominantHand,
static_cast<int>(MouseKeysDominantHand::kRightHandDominant));
//
// Syncable prefs.
//
// These prefs pertain to specific features. They are synced to preserve
// behaviors tied to user accounts once that user enables a feature.
registry->RegisterIntegerPref(
prefs::kAccessibilityAutoclickDelayMs, kDefaultAutoclickDelayMs,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilityAutoclickEventType,
static_cast<int>(kDefaultAutoclickEventType),
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilityAutoclickRevertToLeftClick, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilityAutoclickStabilizePosition, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilityAutoclickMovementThreshold,
kDefaultAutoclickMovementThreshold,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilityAutoclickMenuPosition,
static_cast<int>(kDefaultAutoclickMenuPosition),
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
if (::features::IsAccessibilityBounceKeysEnabled()) {
registry->RegisterIntegerPref(
prefs::kAccessibilityBounceKeysDelayMs,
kDefaultAccessibilityBounceKeysDelay.InMilliseconds(),
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
}
registry->RegisterIntegerPref(
prefs::kAccessibilityFloatingMenuPosition,
static_cast<int>(kDefaultFloatingMenuPosition),
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(prefs::kAccessibilityLargeCursorDipSize,
kDefaultLargeCursorSize);
registry->RegisterIntegerPref(
prefs::kAccessibilityScreenMagnifierMouseFollowingMode,
static_cast<int>(MagnifierMouseFollowingMode::kEdge),
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilityScreenMagnifierFocusFollowingEnabled, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterDoublePref(prefs::kAccessibilityScreenMagnifierScale,
std::numeric_limits<double>::min());
if (::features::IsAccessibilitySlowKeysEnabled()) {
registry->RegisterIntegerPref(
prefs::kAccessibilitySlowKeysDelayMs,
kDefaultAccessibilitySlowKeysDelay.InMilliseconds(),
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
}
registry->RegisterDictionaryPref(
prefs::kAccessibilitySwitchAccessSelectDeviceKeyCodes,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterDictionaryPref(
prefs::kAccessibilitySwitchAccessNextDeviceKeyCodes,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterDictionaryPref(
prefs::kAccessibilitySwitchAccessPreviousDeviceKeyCodes,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilitySwitchAccessAutoScanEnabled, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilitySwitchAccessAutoScanSpeedMs,
kDefaultSwitchAccessAutoScanSpeed.InMilliseconds(),
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilitySwitchAccessAutoScanKeyboardSpeedMs,
kDefaultSwitchAccessAutoScanSpeed.InMilliseconds(),
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilitySwitchAccessPointScanSpeedDipsPerSecond,
kDefaultSwitchAccessPointScanSpeedDipsPerSecond,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilityEnhancedNetworkVoicesInSelectToSpeakAllowed,
kDefaultAccessibilityEnhancedNetworkVoicesInSelectToSpeakAllowed,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilitySelectToSpeakBackgroundShading,
kDefaultAccessibilitySelectToSpeakBackgroundShading,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilitySelectToSpeakEnhancedNetworkVoices,
kDefaultAccessibilitySelectToSpeakEnhancedNetworkVoices,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilitySelectToSpeakEnhancedVoicesDialogShown,
kDefaultAccessibilitySelectToSpeakEnhancedVoicesDialogShown,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilitySelectToSpeakNavigationControls,
kDefaultAccessibilitySelectToSpeakNavigationControls,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilitySelectToSpeakVoiceSwitching,
kDefaultAccessibilitySelectToSpeakVoiceSwitching,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilitySelectToSpeakWordHighlight,
kDefaultAccessibilitySelectToSpeakWordHighlight,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterStringPref(
prefs::kAccessibilitySelectToSpeakEnhancedVoiceName,
kDefaultAccessibilitySelectToSpeakEnhancedVoiceName,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterStringPref(
prefs::kAccessibilitySelectToSpeakHighlightColor,
kDefaultAccessibilitySelectToSpeakHighlightColor,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterStringPref(
prefs::kAccessibilitySelectToSpeakVoiceName,
kDefaultAccessibilitySelectToSpeakVoiceName,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilityColorVisionCorrectionAmount, 100,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilityColorVisionCorrectionType,
ColorVisionCorrectionType::kDeuteranomaly,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
if (::features::IsAccessibilityFaceGazeEnabled()) {
registry->RegisterIntegerPref(
prefs::kAccessibilityFaceGazeCursorSpeedUp, kDefaultFaceGazeCursorSpeed,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilityFaceGazeCursorSpeedDown,
kDefaultFaceGazeCursorSpeed,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilityFaceGazeCursorSpeedLeft,
kDefaultFaceGazeCursorSpeed,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilityFaceGazeCursorSpeedRight,
kDefaultFaceGazeCursorSpeed,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilityFaceGazeCursorUseAcceleration,
kDefaultFaceGazeCursorUseAcceleration,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterDictionaryPref(
prefs::kAccessibilityFaceGazeGesturesToKeyCombos,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterDictionaryPref(
prefs::kAccessibilityFaceGazeGesturesToMacros,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterDictionaryPref(
prefs::kAccessibilityFaceGazeGesturesToConfidence,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilityFaceGazeCursorControlEnabled, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilityFaceGazeActionsEnabled, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilityFaceGazeAdjustSpeedSeparately, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilityFaceGazeVelocityThreshold,
kDefaultFaceGazeVelocityThreshold,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterBooleanPref(
prefs::kAccessibilityFaceGazePrecisionClick, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kAccessibilityFaceGazePrecisionClickSpeedFactor,
kDefaultFaceGazePrecisionClickSpeedFactor,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
}
if (::features::IsAccessibilityMagnifierFollowsChromeVoxEnabled()) {
registry->RegisterBooleanPref(
prefs::kAccessibilityMagnifierFollowsChromeVox, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
}
registry->RegisterBooleanPref(
prefs::kAccessibilityMagnifierFollowsSts, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(prefs::kAccessibilityCaretBlinkInterval,
kDefaultCaretBlinkIntervalMs);
if (::features::IsAccessibilityFlashScreenFeatureEnabled()) {
registry->RegisterIntegerPref(prefs::kAccessibilityFlashNotificationsColor,
kDefaultFlashNotificationsColor);
}
registry->RegisterBooleanPref(
prefs::kAccessibilityAlwaysShowScrollbarsEnabled, false);
}
void AccessibilityController::Shutdown() {
// Log metrics at shutdown.
for (auto& feature : features_) {
feature->LogDurationMetric();
}
display::Screen::GetScreen()->RemoveObserver(this);
Shell::Get()->session_controller()->RemoveObserver(this);
// Clean up any child windows and widgets that might be animating out.
dictation_bubble_controller_.reset();
facegaze_bubble_controller_.reset();
for (auto& observer : observers_) {
observer.OnAccessibilityControllerShutdown();
}
}
bool AccessibilityController::HasDisplayRotationAcceleratorDialogBeenAccepted()
const {
return active_user_prefs_ &&
active_user_prefs_->GetBoolean(
prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted2);
}
void AccessibilityController::
SetDisplayRotationAcceleratorDialogBeenAccepted() {
if (!active_user_prefs_) {
return;
}
active_user_prefs_->SetBoolean(
prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted2, true);
active_user_prefs_->CommitPendingWrite();
}
void AccessibilityController::AddObserver(AccessibilityObserver* observer) {
observers_.AddObserver(observer);
}
void AccessibilityController::RemoveObserver(AccessibilityObserver* observer) {
observers_.RemoveObserver(observer);
}
AccessibilityController::Feature& AccessibilityController::GetFeature(
FeatureType type) const {
size_t feature_index = static_cast<size_t>(type);
DCHECK(features_[feature_index].get());
return *features_[feature_index].get();
}
std::vector<AccessibilityController::Feature*>
AccessibilityController::GetEnabledFeaturesInQuickSettings() const {
std::vector<Feature*> enabled_features;
for (auto& feature : features_) {
if (feature->enabled() && feature->toggleable_in_quicksettings()) {
enabled_features.push_back(feature.get());
}
}
return enabled_features;
}
base::WeakPtr<AccessibilityController> AccessibilityController::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
AccessibilityController::Feature&
AccessibilityController::always_show_scrollbar() const {
return GetFeature(FeatureType::kAlwaysShowScrollbar);
}
AccessibilityController::Feature& AccessibilityController::autoclick() const {
return GetFeature(FeatureType::kAutoclick);
}
AccessibilityController::Feature& AccessibilityController::bounce_keys() const {
return GetFeature(FeatureType::kBounceKeys);
}
AccessibilityController::Feature& AccessibilityController::caret_highlight()
const {
return GetFeature(FeatureType::kCaretHighlight);
}
AccessibilityController::Feature& AccessibilityController::cursor_highlight()
const {
return GetFeature(FeatureType::kCursorHighlight);
}
AccessibilityController::Feature& AccessibilityController::cursor_color()
const {
return GetFeature(FeatureType::kCursorColor);
}
AccessibilityController::Feature& AccessibilityController::dictation() const {
return GetFeature(FeatureType::kDictation);
}
AccessibilityController::Feature& AccessibilityController::disable_touchpad()
const {
return GetFeature(FeatureType::kDisableTouchpad);
}
AccessibilityController::Feature& AccessibilityController::color_correction()
const {
return GetFeature(FeatureType::kColorCorrection);
}
AccessibilityController::Feature& AccessibilityController::face_gaze() const {
return GetFeature(FeatureType::kFaceGaze);
}
AccessibilityController::Feature& AccessibilityController::flash_notifications()
const {
return GetFeature(FeatureType::kFlashNotifications);
}
AccessibilityController::Feature& AccessibilityController::focus_highlight()
const {
return GetFeature(FeatureType::kFocusHighlight);
}
AccessibilityController::Feature& AccessibilityController::floating_menu()
const {
return GetFeature(FeatureType::kFloatingMenu);
}
AccessibilityController::FeatureWithDialog&
AccessibilityController::fullscreen_magnifier() const {
return static_cast<FeatureWithDialog&>(
GetFeature(FeatureType::kFullscreenMagnifier));
}
AccessibilityController::FeatureWithDialog&
AccessibilityController::docked_magnifier() const {
return static_cast<FeatureWithDialog&>(
GetFeature(FeatureType::kDockedMagnifier));
}
AccessibilityController::FeatureWithDialog&
AccessibilityController::high_contrast() const {
return static_cast<FeatureWithDialog&>(
GetFeature(FeatureType::kHighContrast));
}
AccessibilityController::Feature& AccessibilityController::large_cursor()
const {
return GetFeature(FeatureType::kLargeCursor);
}
AccessibilityController::Feature& AccessibilityController::live_caption()
const {
return GetFeature(FeatureType::kLiveCaption);
}
AccessibilityController::Feature& AccessibilityController::mono_audio() const {
return GetFeature(FeatureType::kMonoAudio);
}
AccessibilityController::Feature& AccessibilityController::mouse_keys() const {
return GetFeature(FeatureType::kMouseKeys);
}
AccessibilityController::Feature& AccessibilityController::reduced_animations()
const {
return GetFeature(FeatureType::kReducedAnimations);
}
AccessibilityController::Feature& AccessibilityController::spoken_feedback()
const {
return GetFeature(FeatureType::kSpokenFeedback);
}
AccessibilityController::Feature& AccessibilityController::select_to_speak()
const {
return GetFeature(FeatureType::kSelectToSpeak);
}
AccessibilityController::Feature& AccessibilityController::slow_keys() const {
return GetFeature(FeatureType::kSlowKeys);
}
AccessibilityController::Feature& AccessibilityController::sticky_keys() const {
return GetFeature(FeatureType::kStickyKeys);
}
AccessibilityController::Feature& AccessibilityController::switch_access()
const {
return GetFeature(FeatureType::kSwitchAccess);
}
AccessibilityController::Feature& AccessibilityController::virtual_keyboard()
const {
return GetFeature(FeatureType::kVirtualKeyboard);
}
bool AccessibilityController::IsAutoclickSettingVisibleInTray() {
return autoclick().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForAutoclick() {
return autoclick().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsCaretHighlightSettingVisibleInTray() {
return caret_highlight().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForCaretHighlight() {
return caret_highlight().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsCursorHighlightSettingVisibleInTray() {
return cursor_highlight().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForCursorHighlight() {
return cursor_highlight().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsDictationSettingVisibleInTray() {
return dictation().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForDictation() {
return dictation().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsFaceGazeSettingVisibleInTray() {
// For managed accounts, we restrict the face control quick setting to
// signed-in profiles. If the device is on the login screen, locked, or in a
// kiosk app, we don't show the face control quick setting.
bool is_managed =
Shell::Get()
->system_tray_model()
->enterprise_domain()
->management_device_mode() != ManagementDeviceMode::kNone;
if (is_managed) {
LoginStatus status = Shell::Get()->session_controller()->login_status();
if (status == LoginStatus::NOT_LOGGED_IN || status == LoginStatus::LOCKED ||
status == LoginStatus::KIOSK_APP) {
return false;
}
}
return face_gaze().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForFaceGaze() {
return face_gaze().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsFocusHighlightSettingVisibleInTray() {
return focus_highlight().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForFocusHighlight() {
return focus_highlight().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsFullScreenMagnifierSettingVisibleInTray() {
return fullscreen_magnifier().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForFullScreenMagnifier() {
return fullscreen_magnifier().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsDockedMagnifierSettingVisibleInTray() {
return docked_magnifier().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForDockedMagnifier() {
return docked_magnifier().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsHighContrastSettingVisibleInTray() {
return high_contrast().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForHighContrast() {
return high_contrast().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsColorCorrectionSettingVisibleInTray() {
if (!color_correction().enabled() &&
Shell::Get()->session_controller()->login_status() ==
ash::LoginStatus::NOT_LOGGED_IN) {
// Don't allow users to enable this on not logged in profiles because it
// requires set-up in settings the first time it is run.
return false;
}
return color_correction().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForColorCorrection() {
return color_correction().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsLargeCursorSettingVisibleInTray() {
return large_cursor().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForLargeCursor() {
return large_cursor().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsLiveCaptionSettingVisibleInTray() {
return captions::IsLiveCaptionFeatureSupported() &&
live_caption().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForLiveCaption() {
return captions::IsLiveCaptionFeatureSupported() &&
live_caption().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsMonoAudioSettingVisibleInTray() {
return mono_audio().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForMonoAudio() {
return mono_audio().IsEnterpriseIconVisible();
}
void AccessibilityController::SetSpokenFeedbackEnabled(
bool enabled,
AccessibilityNotificationVisibility notify) {
spoken_feedback().SetEnabled(enabled);
// Value could be left unchanged because of higher-priority pref source, eg.
// policy. See crbug.com/953245.
const bool actual_enabled = active_user_prefs_->GetBoolean(
prefs::kAccessibilitySpokenFeedbackEnabled);
A11yNotificationType type = A11yNotificationType::kNone;
if (enabled && actual_enabled && notify == A11Y_NOTIFICATION_SHOW) {
type = A11yNotificationType::kSpokenFeedbackEnabled;
}
ShowAccessibilityNotification(A11yNotificationWrapper(
type, kNotificationId, std::vector<std::u16string>()));
}
bool AccessibilityController::IsSpokenFeedbackSettingVisibleInTray() {
return spoken_feedback().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForSpokenFeedback() {
return spoken_feedback().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsSelectToSpeakSettingVisibleInTray() {
return select_to_speak().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForSelectToSpeak() {
return select_to_speak().IsEnterpriseIconVisible();
}
void AccessibilityController::RequestSelectToSpeakStateChange() {
client_->RequestSelectToSpeakStateChange();
}
void AccessibilityController::OnFaceGazeActiveNotificationClicked(
std::optional<int> button_index) {
if (!button_index) {
return;
}
RequestDisableFaceGaze();
}
void AccessibilityController::OnTouchpadNotificationClicked(
std::optional<int> button_index) {
if (!button_index) {
return;
}
EnableInternalTouchpad();
}
void AccessibilityController::RecordSelectToSpeakSpeechDuration(
SelectToSpeakState old_state,
SelectToSpeakState new_state) {
if (new_state != SelectToSpeakState::kSelectToSpeakStateSpeaking &&
select_to_speak_speech_start_time_ == base::Time()) {
select_to_speak_speech_start_time_ = base::Time::Now();
}
if (old_state != SelectToSpeakState::kSelectToSpeakStateSpeaking &&
new_state != old_state &&
select_to_speak_speech_start_time_ != base::Time()) {
base::TimeDelta duration =
base::Time::Now() - select_to_speak_speech_start_time_;
base::UmaHistogramCustomCounts(
"Accessibility.CrosSelectToSpeak.SpeechDuration", duration.InSeconds(),
/*min=*/1, /*max=*/base::Minutes(20) / base::Seconds(1),
/*buckets=*/100);
select_to_speak_speech_start_time_ = base::Time();
}
}
void AccessibilityController::SetSelectToSpeakState(SelectToSpeakState state) {
RecordSelectToSpeakSpeechDuration(select_to_speak_state_, state);
select_to_speak_state_ = state;
// Forward the state change event to select_to_speak_event_handler_.
// The extension may have requested that the handler enter SELECTING state.
// Prepare to start capturing events from stylus, mouse or touch.
if (select_to_speak_event_handler_) {
select_to_speak_event_handler_->SetSelectToSpeakStateSelecting(
state == SelectToSpeakState::kSelectToSpeakStateSelecting);
}
NotifyAccessibilityStatusChanged();
}
void AccessibilityController::SetSelectToSpeakEventHandlerDelegate(
SelectToSpeakEventHandlerDelegate* delegate) {
select_to_speak_event_handler_delegate_ = delegate;
MaybeCreateSelectToSpeakEventHandler();
}
SelectToSpeakState AccessibilityController::GetSelectToSpeakState() const {
return select_to_speak_state_;
}
void AccessibilityController::ShowSelectToSpeakPanel(const gfx::Rect& anchor,
bool is_paused,
double speech_rate) {
if (!select_to_speak_bubble_controller_) {
select_to_speak_bubble_controller_ =
std::make_unique<SelectToSpeakMenuBubbleController>();
}
select_to_speak_bubble_controller_->Show(anchor, is_paused, speech_rate);
}
void AccessibilityController::HideSelectToSpeakPanel() {
if (!select_to_speak_bubble_controller_) {
return;
}
select_to_speak_bubble_controller_->Hide();
}
void AccessibilityController::OnSelectToSpeakPanelAction(
SelectToSpeakPanelAction action,
double value) {
if (!client_) {
return;
}
client_->OnSelectToSpeakPanelAction(action, value);
}
bool AccessibilityController::IsSwitchAccessRunning() const {
return switch_access().enabled() || switch_access_disable_dialog_showing_;
}
bool AccessibilityController::IsSwitchAccessSettingVisibleInTray() {
// Switch Access cannot be enabled on the sign-in page because there is no way
// to configure switches while the device is locked.
if (!switch_access().enabled() &&
Shell::Get()->session_controller()->login_status() ==
ash::LoginStatus::NOT_LOGGED_IN) {
return false;
}
return switch_access().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForSwitchAccess() {
return switch_access().IsEnterpriseIconVisible();
}
void AccessibilityController::SetAccessibilityEventRewriter(
AccessibilityEventRewriter* accessibility_event_rewriter) {
accessibility_event_rewriter_ = accessibility_event_rewriter;
}
void AccessibilityController::SetDisableTouchpadEventRewriter(
DisableTouchpadEventRewriter* rewriter) {
disable_touchpad_event_rewriter_ = rewriter;
}
void AccessibilityController::EnableInternalTouchpad() {
active_user_prefs_->SetInteger(prefs::kAccessibilityDisableTrackpadMode,
static_cast<int>(DisableTouchpadMode::kNever));
}
void AccessibilityController::SetFilterKeysEventRewriter(
FilterKeysEventRewriter* rewriter) {
filter_keys_event_rewriter_ = rewriter;
}
void AccessibilityController::HideSwitchAccessBackButton() {
if (IsSwitchAccessRunning()) {
switch_access_bubble_controller_->HideBackButton();
}
}
void AccessibilityController::HideSwitchAccessMenu() {
if (IsSwitchAccessRunning()) {
switch_access_bubble_controller_->HideMenuBubble();
}
}
void AccessibilityController::ShowSwitchAccessBackButton(
const gfx::Rect& anchor) {
switch_access_bubble_controller_->ShowBackButton(anchor);
}
void AccessibilityController::ShowSwitchAccessMenu(
const gfx::Rect& anchor,
std::vector<std::string> actions_to_show) {
switch_access_bubble_controller_->ShowMenu(anchor, actions_to_show);
}
bool AccessibilityController::IsPointScanEnabled() {
return point_scan_controller_.get() &&
point_scan_controller_->IsPointScanEnabled();
}
void AccessibilityController::StartPointScan() {
point_scan_controller_->Start();
}
void AccessibilityController::SetA11yOverrideWindow(
aura::Window* a11y_override_window) {
if (client_) {
client_->SetA11yOverrideWindow(a11y_override_window);
}
}
void AccessibilityController::StopPointScan() {
if (point_scan_controller_) {
point_scan_controller_->HideAll();
}
}
void AccessibilityController::SetPointScanSpeedDipsPerSecond(
int point_scan_speed_dips_per_second) {
if (point_scan_controller_) {
point_scan_controller_->SetSpeedDipsPerSecond(
point_scan_speed_dips_per_second);
}
}
void AccessibilityController::DisablePolicyRecommendationRestorerForTesting() {
Shell::Get()->policy_recommendation_restorer()->DisableForTesting();
}
bool AccessibilityController::IsStickyKeysSettingVisibleInTray() {
return sticky_keys().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForStickyKeys() {
return sticky_keys().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsReducedAnimationsSettingVisibleInTray() {
if (!::features::IsAccessibilityReducedAnimationsInKioskEnabled()) {
return false;
}
// Only visible in kiosk mode.
if (!Shell::Get()->session_controller()->IsRunningInAppMode()) {
return false;
}
return reduced_animations().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForReducedAnimations() {
return reduced_animations().IsEnterpriseIconVisible();
}
bool AccessibilityController::IsVirtualKeyboardSettingVisibleInTray() {
return virtual_keyboard().IsVisibleInTray();
}
bool AccessibilityController::IsEnterpriseIconVisibleForVirtualKeyboard() {
return virtual_keyboard().IsEnterpriseIconVisible();
}
void AccessibilityController::ShowFloatingMenuIfEnabled() {
if (floating_menu().enabled() && !floating_menu_controller_) {
floating_menu_controller_ =
std::make_unique<FloatingAccessibilityController>(this);
floating_menu_controller_->Show(GetFloatingMenuPosition());
} else {
always_show_floating_menu_when_enabled_ = true;
}
}
FloatingAccessibilityController*
AccessibilityController::GetFloatingMenuController() {
return floating_menu_controller_.get();
}
PointScanController* AccessibilityController::GetPointScanController() {
return point_scan_controller_.get();
}
void AccessibilityController::SetTabletModeShelfNavigationButtonsEnabled(
bool enabled) {
if (!active_user_prefs_) {
return;
}
active_user_prefs_->SetBoolean(
prefs::kAccessibilityTabletModeShelfNavigationButtonsEnabled, enabled);
active_user_prefs_->CommitPendingWrite();
}
void AccessibilityController::TriggerAccessibilityAlert(
AccessibilityAlert alert) {
if (client_) {
client_->TriggerAccessibilityAlert(alert);
}
}
void AccessibilityController::TriggerAccessibilityAlertWithMessage(
const std::string& message) {
if (client_) {
client_->TriggerAccessibilityAlertWithMessage(message);
}
}
void AccessibilityController::PlayEarcon(Sound sound_key) {
if (client_) {
client_->PlayEarcon(sound_key);
}
}
base::TimeDelta AccessibilityController::PlayShutdownSound() {
return client_ ? client_->PlayShutdownSound() : base::TimeDelta();
}
void AccessibilityController::HandleAccessibilityGesture(
ax::mojom::Gesture gesture,
gfx::PointF location) {
if (client_) {
client_->HandleAccessibilityGesture(gesture, location);
}
}
void AccessibilityController::ToggleDictation() {
// Do nothing if dictation is not enabled.
if (!dictation().enabled()) {
return;
}
if (client_) {
const bool is_active = client_->ToggleDictation();
SetDictationActive(is_active);
if (is_active) {
Shell::Get()->OnDictationStarted();
} else {
Shell::Get()->OnDictationEnded();
}
}
}
void AccessibilityController::SetDictationActive(bool is_active) {
dictation_active_ = is_active;
}
void AccessibilityController::ToggleDictationFromSource(
DictationToggleSource source) {
base::RecordAction(base::UserMetricsAction("Accel_Toggle_Dictation"));
UMA_HISTOGRAM_ENUMERATION("Accessibility.CrosDictation.ToggleDictationMethod",
source);
dictation().SetEnabled(true);
ToggleDictation();
}
void AccessibilityController::EnableSelectToSpeakWithDialog() {
if (select_to_speak().enabled()) {
return;
}
if (active_user_prefs_
->FindPreference(prefs::kAccessibilitySelectToSpeakEnabled)
->IsManaged() &&
!active_user_prefs_->GetBoolean(
prefs::kAccessibilitySelectToSpeakEnabled)) {
// Don't show the dialog if Select to speak has been disabled by a policy.
return;
}
if (active_user_prefs_->GetBoolean(
prefs::kSelectToSpeakAcceleratorDialogHasBeenAccepted)) {
// Enable Select to Speak if the confirmation dialog has been previously
// accepted.
OnSelectToSpeakKeyboardDialogAccepted();
} else {
// Show the confirmation dialog if it hasn't been accepted yet.
ShowSelectToSpeakKeyboardDialog();
}
}
void AccessibilityController::EnableOrToggleDictationFromSource(
DictationToggleSource source) {
if (dictation().enabled()) {
ToggleDictationFromSource(source);
} else if (source == DictationToggleSource::kKeyboard) {
// Only allow direct-enabling of Dictation from the keyboard. Show the
// confirmation dialog if it hasn't been accepted yet.
if (active_user_prefs_->GetBoolean(
prefs::kDictationAcceleratorDialogHasBeenAccepted)) {
OnDictationKeyboardDialogAccepted();
} else {
ShowDictationKeyboardDialog();
}
}
}
void AccessibilityController::ShowDictationKeyboardDialog() {
if (!client_) {
return;
}
dictation_keyboard_dialog_showing_for_testing_ = true;
std::string dictation_locale;
if (active_user_prefs_->GetString(prefs::kAccessibilityDictationLocale)
.empty()) {
dictation_locale = client_->GetDictationDefaultLocale(/*new_user=*/true);
} else {
dictation_locale =
active_user_prefs_->GetString(prefs::kAccessibilityDictationLocale);
}
std::u16string display_locale = l10n_util::GetDisplayNameForLocale(
/*locale=*/dictation_locale, /*display_locale=*/dictation_locale,
/*is_for_ui=*/true);
std::vector<std::u16string> replacements{display_locale};
std::u16string title =
l10n_util::GetStringUTF16(IDS_ASH_DICTATION_KEYBOARD_DIALOG_TITLE);
std::u16string description =
::features::IsDictationOfflineAvailable()
? l10n_util::GetStringFUTF16(
IDS_ASH_DICTATION_KEYBOARD_DIALOG_DESCRIPTION_SODA_AVAILABLE,
replacements, nullptr)
: l10n_util::GetStringFUTF16(
IDS_ASH_DICTATION_KEYBOARD_DIALOG_DESCRIPTION_SODA_NOT_AVAILABLE,
replacements, nullptr);
ShowConfirmationDialog(
title, description, l10n_util::GetStringUTF16(IDS_ASH_CONTINUE_BUTTON),
l10n_util::GetStringUTF16(IDS_APP_CANCEL),
base::BindOnce(
&AccessibilityController::OnDictationKeyboardDialogAccepted,
GetWeakPtr()),
base::BindOnce(
&AccessibilityController::OnDictationKeyboardDialogDismissed,
GetWeakPtr()),
base::BindOnce(
&AccessibilityController::OnDictationKeyboardDialogDismissed,
GetWeakPtr()));
}
void AccessibilityController::OnDictationKeyboardDialogAccepted() {
dictation_keyboard_dialog_showing_for_testing_ = false;
active_user_prefs_->SetBoolean(
prefs::kDictationAcceleratorDialogHasBeenAccepted, true);
confirmation_dialog_.reset();
base::RecordAction(base::UserMetricsAction("Accel_Enable_Dictation"));
dictation().SetEnabled(true);
}
void AccessibilityController::OnDictationKeyboardDialogDismissed() {
dictation_keyboard_dialog_showing_for_testing_ = false;
}
void AccessibilityController::ShowSelectToSpeakKeyboardDialog() {
if (!client_) {
return;
}
std::u16string title =
l10n_util::GetStringUTF16(IDS_ASH_SELECT_TO_SPEAK_KEYBOARD_DIALOG_TITLE);
std::u16string modifier_key;
if (Shell::Get()->keyboard_capability()->HasLauncherButtonOnAnyKeyboard()) {
modifier_key = l10n_util::GetStringUTF16(IDS_KSV_MODIFIER_LAUNCHER);
} else {
modifier_key = l10n_util::GetStringUTF16(IDS_KSV_MODIFIER_SEARCH);
}
std::u16string description = l10n_util::GetStringFUTF16(
IDS_ASH_SELECT_TO_SPEAK_KEYBOARD_DIALOG_DESCRIPTION, modifier_key);
ShowConfirmationDialog(
title, description, l10n_util::GetStringUTF16(IDS_ASH_CONTINUE_BUTTON),
l10n_util::GetStringUTF16(IDS_APP_CANCEL),
base::BindOnce(
&AccessibilityController::OnSelectToSpeakKeyboardDialogAccepted,
GetWeakPtr()),
base::BindOnce(
&AccessibilityController::OnSelectToSpeakKeyboardDialogDismissed,
GetWeakPtr()),
base::BindOnce(
&AccessibilityController::OnSelectToSpeakKeyboardDialogDismissed,
GetWeakPtr()));
}
void AccessibilityController::OnSelectToSpeakKeyboardDialogAccepted() {
active_user_prefs_->SetBoolean(
prefs::kSelectToSpeakAcceleratorDialogHasBeenAccepted, true);
confirmation_dialog_.reset();
select_to_speak().SetEnabled(true);
}
void AccessibilityController::OnSelectToSpeakKeyboardDialogDismissed() {
confirmation_dialog_.reset();
}
void AccessibilityController::ShowDictationLanguageUpgradedNudge(
const std::string& dictation_locale,
const std::string& application_locale) {
const std::u16string language_name = l10n_util::GetDisplayNameForLocale(
dictation_locale, application_locale, /*is_for_ui=*/true);
const std::u16string body_text = l10n_util::GetStringFUTF16(
IDS_ASH_DICTATION_LANGUAGE_SUPPORTED_OFFLINE_NUDGE, language_name);
AnchoredNudgeData nudge_data(kDictationLanguageUpgradedNudgeId,
NudgeCatalogName::kDictation, body_text);
AnchoredNudgeManager::Get()->Show(nudge_data);
}
void AccessibilityController::SilenceSpokenFeedback() {
if (client_) {
client_->SilenceSpokenFeedback();
}
}
bool AccessibilityController::ShouldToggleSpokenFeedbackViaTouch() const {
return client_ && client_->ShouldToggleSpokenFeedbackViaTouch();
}
void AccessibilityController::PlaySpokenFeedbackToggleCountdown(
int tick_count) {
if (client_) {
client_->PlaySpokenFeedbackToggleCountdown(tick_count);
}
}
bool AccessibilityController::IsEnterpriseIconVisibleInTrayMenu(
const std::string& path) {
return active_user_prefs_ &&
active_user_prefs_->FindPreference(path)->IsManaged();
}
void AccessibilityController::SetClient(AccessibilityControllerClient* client) {
client_ = client;
}
void AccessibilityController::SetDarkenScreen(bool darken) {
if (darken && !scoped_backlights_forced_off_) {
scoped_backlights_forced_off_ =
Shell::Get()->backlights_forced_off_setter()->ForceBacklightsOff();
} else if (!darken && scoped_backlights_forced_off_) {
scoped_backlights_forced_off_.reset();
}
}
void AccessibilityController::BrailleDisplayStateChanged(bool connected) {
A11yNotificationType type = A11yNotificationType::kNone;
if (connected && spoken_feedback().enabled()) {
type = A11yNotificationType::kBrailleDisplayConnected;
} else if (connected && !spoken_feedback().enabled()) {
type = A11yNotificationType::kSpokenFeedbackBrailleEnabled;
}
if (connected) {
SetSpokenFeedbackEnabled(true, A11Y_NOTIFICATION_NONE);
}
NotifyAccessibilityStatusChanged();
ShowAccessibilityNotification(A11yNotificationWrapper(
type, kNotificationId, std::vector<std::u16string>()));
}
void AccessibilityController::SetFocusHighlightRect(
const gfx::Rect& bounds_in_screen) {
if (!accessibility_highlight_controller_) {
return;
}
accessibility_highlight_controller_->SetFocusHighlightRect(bounds_in_screen);
}
void AccessibilityController::SetCaretBounds(
const gfx::Rect& bounds_in_screen) {
if (!accessibility_highlight_controller_) {
return;
}
accessibility_highlight_controller_->SetCaretBounds(bounds_in_screen);
}
void AccessibilityController::SetAccessibilityPanelAlwaysVisible(
bool always_visible) {
GetLayoutManager()->SetAlwaysVisible(always_visible);
}
void AccessibilityController::SetAccessibilityPanelBounds(
const gfx::Rect& bounds,
AccessibilityPanelState state) {
GetLayoutManager()->SetPanelBounds(bounds, state);
}
void AccessibilityController::OnSigninScreenPrefServiceInitialized(
PrefService* prefs) {
// Make |kA11yPrefsForRecommendedValueOnSignin| observing recommended values
// on signin screen. See PolicyRecommendationRestorer.
PolicyRecommendationRestorer* policy_recommendation_restorer =
Shell::Get()->policy_recommendation_restorer();
for (auto* const pref_name : kA11yPrefsForRecommendedValueOnSignin) {
policy_recommendation_restorer->ObservePref(pref_name);
}
// Observe user settings. This must happen after PolicyRecommendationRestorer.
ObservePrefs(prefs);
}
void AccessibilityController::OnActiveUserPrefServiceChanged(
PrefService* prefs) {
// This is guaranteed to be received after
// OnSigninScreenPrefServiceInitialized() so only copy the signin prefs if
// needed here.
CopySigninPrefsIfNeeded(active_user_prefs_, prefs);
ObservePrefs(prefs);
}
void AccessibilityController::OnSessionStateChanged(
session_manager::SessionState state) {
if (state != SessionState::ACTIVE) {
// Log metrics for how long the features were enabled if needed.
for (auto& feature : features_) {
feature->LogDurationMetric();
}
}
// Everything behind the lock screen is in
// kShellWindowId_NonLockScreenContainersContainer. If the session state is
// changed to block the user session due to the lock screen or similar,
// everything in that window should be made invisible for accessibility.
// This keeps a11y features from being able to access parts of the tree
// that are visibly hidden behind the lock screen.
aura::Window* container =
Shell::GetContainer(Shell::GetPrimaryRootWindow(),
kShellWindowId_NonLockScreenContainersContainer);
container->SetProperty(
ui::kAXConsiderInvisibleAndIgnoreChildren,
Shell::Get()->session_controller()->IsUserSessionBlocked());
}
AccessibilityEventRewriter*
AccessibilityController::GetAccessibilityEventRewriterForTest() {
return accessibility_event_rewriter_;
}
DisableTouchpadEventRewriter*
AccessibilityController::GetDisableTouchpadEventRewriterForTest() {
return disable_touchpad_event_rewriter_;
}
FilterKeysEventRewriter*
AccessibilityController::GetFilterKeysEventRewriterForTest() {
return filter_keys_event_rewriter_;
}
void AccessibilityController::DisableAutoClickConfirmationDialogForTest() {
no_auto_click_confirmation_dialog_for_testing_ = true;
}
void AccessibilityController::
DisableSwitchAccessDisableConfirmationDialogTesting() {
no_switch_access_disable_confirmation_dialog_for_testing_ = true;
}
void AccessibilityController::DisableSwitchAccessEnableNotificationTesting() {
skip_switch_access_notification_ = true;
}
void AccessibilityController::OnDisplayTabletStateChanged(
display::TabletState state) {
if (spoken_feedback().enabled()) {
// Show accessibility notification when tablet mode transition is completed.
if (state == display::TabletState::kInTabletMode ||
state == display::TabletState::kInClamshellMode) {
ShowAccessibilityNotification(A11yNotificationWrapper(
A11yNotificationType::kSpokenFeedbackEnabled, kNotificationId,
std::vector<std::u16string>()));
}
}
}
void AccessibilityController::ObservePrefs(PrefService* prefs) {
DCHECK(prefs);
active_user_prefs_ = prefs;
// Watch for pref updates from webui settings and policy.
pref_change_registrar_ = std::make_unique<PrefChangeRegistrar>();
pref_change_registrar_->Init(prefs);
// It is safe to use base::Unreatined since we own pref_change_registrar.
for (const std::unique_ptr<Feature>& feature : features_) {
DCHECK(feature);
pref_change_registrar_->Add(
feature->pref_name(),
base::BindRepeating(&AccessibilityController::Feature::UpdateFromPref,
base::Unretained(feature.get())));
if (feature->conflicting_feature() != FeatureType::kNoConflictingFeature) {
feature->ObserveConflictingFeature();
}
// Features will be initialized from current prefs later.
}
// TODO(crbug.com/383754550): Consider updating calls from
// base::Unretained(this) to GetWeakPtr().
pref_change_registrar_->Add(
prefs::kAccessibilityAutoclickDelayMs,
base::BindRepeating(
&AccessibilityController::UpdateAutoclickDelayFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityAutoclickEventType,
base::BindRepeating(
&AccessibilityController::UpdateAutoclickEventTypeFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityAutoclickRevertToLeftClick,
base::BindRepeating(
&AccessibilityController::UpdateAutoclickRevertToLeftClickFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityAutoclickStabilizePosition,
base::BindRepeating(
&AccessibilityController::UpdateAutoclickStabilizePositionFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityAutoclickMovementThreshold,
base::BindRepeating(
&AccessibilityController::UpdateAutoclickMovementThresholdFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityAutoclickMenuPosition,
base::BindRepeating(
&AccessibilityController::UpdateAutoclickMenuPositionFromPref,
base::Unretained(this)));
if (::features::IsAccessibilityBounceKeysEnabled()) {
pref_change_registrar_->Add(
prefs::kAccessibilityBounceKeysDelayMs,
base::BindRepeating(
&AccessibilityController::UpdateBounceKeysDelayFromPref,
base::Unretained(this)));
}
if (::features::IsAccessibilitySlowKeysEnabled()) {
pref_change_registrar_->Add(
prefs::kAccessibilitySlowKeysDelayMs,
base::BindRepeating(
&AccessibilityController::UpdateSlowKeysDelayFromPref,
base::Unretained(this)));
}
if (::features::IsAccessibilityMouseKeysEnabled()) {
pref_change_registrar_->Add(
prefs::kAccessibilityMouseKeysAcceleration,
base::BindRepeating(
&AccessibilityController::UpdateMouseKeysAccelerationFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityMouseKeysMaxSpeed,
base::BindRepeating(
&AccessibilityController::UpdateMouseKeysMaxSpeedFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityMouseKeysUsePrimaryKeys,
base::BindRepeating(
&AccessibilityController::UpdateMouseKeysUsePrimaryKeysFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityMouseKeysDominantHand,
base::BindRepeating(
&AccessibilityController::UpdateMouseKeysDominantHandFromPref,
base::Unretained(this)));
}
pref_change_registrar_->Add(
prefs::kAccessibilityFloatingMenuPosition,
base::BindRepeating(
&AccessibilityController::UpdateFloatingMenuPositionFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityLargeCursorDipSize,
base::BindRepeating(&AccessibilityController::UpdateLargeCursorFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityShortcutsEnabled,
base::BindRepeating(
&AccessibilityController::UpdateShortcutsEnabledFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilitySwitchAccessSelectDeviceKeyCodes,
base::BindRepeating(
&AccessibilityController::UpdateSwitchAccessKeyCodesFromPref,
base::Unretained(this), SwitchAccessCommand::kSelect));
pref_change_registrar_->Add(
prefs::kAccessibilitySwitchAccessNextDeviceKeyCodes,
base::BindRepeating(
&AccessibilityController::UpdateSwitchAccessKeyCodesFromPref,
base::Unretained(this), SwitchAccessCommand::kNext));
pref_change_registrar_->Add(
prefs::kAccessibilitySwitchAccessPreviousDeviceKeyCodes,
base::BindRepeating(
&AccessibilityController::UpdateSwitchAccessKeyCodesFromPref,
base::Unretained(this), SwitchAccessCommand::kPrevious));
pref_change_registrar_->Add(
prefs::kAccessibilitySwitchAccessAutoScanEnabled,
base::BindRepeating(
&AccessibilityController::UpdateSwitchAccessAutoScanEnabledFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilitySwitchAccessAutoScanSpeedMs,
base::BindRepeating(
&AccessibilityController::UpdateSwitchAccessAutoScanSpeedFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilitySwitchAccessAutoScanKeyboardSpeedMs,
base::BindRepeating(&AccessibilityController::
UpdateSwitchAccessAutoScanKeyboardSpeedFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilitySwitchAccessPointScanSpeedDipsPerSecond,
base::BindRepeating(
&AccessibilityController::UpdateSwitchAccessPointScanSpeedFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityTabletModeShelfNavigationButtonsEnabled,
base::BindRepeating(&AccessibilityController::
UpdateTabletModeShelfNavigationButtonsFromPref,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityCursorColor,
base::BindRepeating(&AccessibilityController::UpdateCursorColorFromPrefs,
base::Unretained(this), /*notify*/ true));
pref_change_registrar_->Add(
prefs::kAccessibilityColorVisionCorrectionAmount,
base::BindRepeating(
&AccessibilityController::UpdateColorCorrectionFromPrefs,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityColorVisionCorrectionType,
base::BindRepeating(
&AccessibilityController::UpdateColorCorrectionFromPrefs,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAccessibilityCaretBlinkInterval,
base::BindRepeating(
&AccessibilityController::UpdateCaretBlinkIntervalFromPrefs,
base::Unretained(this)));
if (::features::IsAccessibilityFlashScreenFeatureEnabled()) {
pref_change_registrar_->Add(
prefs::kAccessibilityFlashNotificationsColor,
base::BindRepeating(
&AccessibilityController::UpdateFlashNotificationsFromPrefs,
base::Unretained(this)));
}
if (::features::IsAccessibilityDisableTouchpadEnabled()) {
pref_change_registrar_->Add(
prefs::kAccessibilityDisableTrackpadMode,
base::BindRepeating(
&AccessibilityController::UpdateDisableTouchpadFromPrefs,
base::Unretained(this), /*notify*/ true));
}
for (const std::unique_ptr<Feature>& feature : features_) {
// Log previous duration and clear duration metric if necessary
// when the profile has changed.
feature->LogDurationMetric();
// Load current state.
feature->UpdateFromPref();
}
// Load current state of other prefs.
UpdateAutoclickDelayFromPref();
UpdateAutoclickEventTypeFromPref();
UpdateAutoclickRevertToLeftClickFromPref();
UpdateAutoclickStabilizePositionFromPref();
UpdateAutoclickMovementThresholdFromPref();
UpdateAutoclickMenuPositionFromPref();
if (::features::IsAccessibilityBounceKeysEnabled()) {
UpdateBounceKeysDelayFromPref();
}
if (::features::IsAccessibilitySlowKeysEnabled()) {
UpdateSlowKeysDelayFromPref();
}
if (::features::IsAccessibilityMouseKeysEnabled()) {
UpdateMouseKeysAccelerationFromPref();
UpdateMouseKeysMaxSpeedFromPref();
UpdateMouseKeysUsePrimaryKeysFromPref();
UpdateMouseKeysDominantHandFromPref();
}
UpdateFloatingMenuPositionFromPref();
UpdateLargeCursorFromPref();
UpdateCursorColorFromPrefs(/*notify=*/true);
UpdateShortcutsEnabledFromPref();
UpdateTabletModeShelfNavigationButtonsFromPref();
UpdateColorCorrectionFromPrefs();
UpdateCaretBlinkIntervalFromPrefs();
if (::features::IsAccessibilityFaceGazeEnabled()) {
UpdateFaceGazeFromPrefs();
pref_change_registrar_->Add(
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel,
base::BindRepeating(
&AccessibilityController::OnFaceGazeSentinelChanged,
base::Unretained(this),
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel,
prefs::kAccessibilityFaceGazeCursorControlEnabled));
pref_change_registrar_->Add(
prefs::kAccessibilityFaceGazeActionsEnabledSentinel,
base::BindRepeating(&AccessibilityController::OnFaceGazeSentinelChanged,
base::Unretained(this),
prefs::kAccessibilityFaceGazeActionsEnabledSentinel,
prefs::kAccessibilityFaceGazeActionsEnabled));
}
if (::features::IsAccessibilityFlashScreenFeatureEnabled()) {
UpdateFlashNotificationsFromPrefs();
}
if (::features::IsAccessibilityDisableTouchpadEnabled()) {
UpdateDisableTouchpadFromPrefs(/*notify=*/false);
}
}
void AccessibilityController::UpdateAutoclickDelayFromPref() {
DCHECK(active_user_prefs_);
base::TimeDelta autoclick_delay = base::Milliseconds(int64_t{
active_user_prefs_->GetInteger(prefs::kAccessibilityAutoclickDelayMs)});
if (autoclick_delay_ == autoclick_delay) {
return;
}
autoclick_delay_ = autoclick_delay;
Shell::Get()->autoclick_controller()->SetAutoclickDelay(autoclick_delay_);
}
void AccessibilityController::UpdateAutoclickEventTypeFromPref() {
Shell::Get()->autoclick_controller()->SetAutoclickEventType(
GetAutoclickEventType());
}
void AccessibilityController::SetAutoclickEventType(
AutoclickEventType event_type) {
if (!active_user_prefs_) {
return;
}
active_user_prefs_->SetInteger(prefs::kAccessibilityAutoclickEventType,
static_cast<int>(event_type));
active_user_prefs_->CommitPendingWrite();
Shell::Get()->autoclick_controller()->SetAutoclickEventType(event_type);
}
AutoclickEventType AccessibilityController::GetAutoclickEventType() {
DCHECK(active_user_prefs_);
return static_cast<AutoclickEventType>(
active_user_prefs_->GetInteger(prefs::kAccessibilityAutoclickEventType));
}
void AccessibilityController::UpdateAutoclickRevertToLeftClickFromPref() {
DCHECK(active_user_prefs_);
bool revert_to_left_click = active_user_prefs_->GetBoolean(
prefs::kAccessibilityAutoclickRevertToLeftClick);
Shell::Get()->autoclick_controller()->set_revert_to_left_click(
revert_to_left_click);
}
void AccessibilityController::UpdateAutoclickStabilizePositionFromPref() {
DCHECK(active_user_prefs_);
bool stabilize_position = active_user_prefs_->GetBoolean(
prefs::kAccessibilityAutoclickStabilizePosition);
Shell::Get()->autoclick_controller()->set_stabilize_click_position(
stabilize_position);
}
void AccessibilityController::UpdateAutoclickMovementThresholdFromPref() {
DCHECK(active_user_prefs_);
int movement_threshold = active_user_prefs_->GetInteger(
prefs::kAccessibilityAutoclickMovementThreshold);
Shell::Get()->autoclick_controller()->SetMovementThreshold(
movement_threshold);
}
void AccessibilityController::UpdateAutoclickMenuPositionFromPref() {
Shell::Get()->autoclick_controller()->SetMenuPosition(
GetAutoclickMenuPosition());
}
void AccessibilityController::UpdateBounceKeysDelayFromPref() {
if (!filter_keys_event_rewriter_) {
return;
}
DCHECK(active_user_prefs_);
base::TimeDelta delay = base::Milliseconds(
active_user_prefs_->GetInteger(prefs::kAccessibilityBounceKeysDelayMs));
filter_keys_event_rewriter_->SetBounceKeysDelay(delay);
}
void AccessibilityController::UpdateSlowKeysDelayFromPref() {
DCHECK(active_user_prefs_);
base::TimeDelta delay = base::Milliseconds(
active_user_prefs_->GetInteger(prefs::kAccessibilitySlowKeysDelayMs));
input_method::InputMethodManager::Get()->GetImeKeyboard()->SetSlowKeysDelay(
delay);
}
void AccessibilityController::UpdateMouseKeysAccelerationFromPref() {
DCHECK(active_user_prefs_);
double acceleration =
active_user_prefs_->GetDouble(prefs::kAccessibilityMouseKeysAcceleration);
Shell::Get()->mouse_keys_controller()->set_acceleration(acceleration);
}
void AccessibilityController::UpdateMouseKeysMaxSpeedFromPref() {
DCHECK(active_user_prefs_);
double max_speed =
active_user_prefs_->GetDouble(prefs::kAccessibilityMouseKeysMaxSpeed);
Shell::Get()->mouse_keys_controller()->SetMaxSpeed(max_speed);
}
void AccessibilityController::UpdateMouseKeysUsePrimaryKeysFromPref() {
DCHECK(active_user_prefs_);
bool value = active_user_prefs_->GetBoolean(
prefs::kAccessibilityMouseKeysUsePrimaryKeys);
Shell::Get()->mouse_keys_controller()->set_use_primary_keys(value);
}
void AccessibilityController::UpdateMouseKeysDominantHandFromPref() {
DCHECK(active_user_prefs_);
MouseKeysDominantHand dominant_hand =
static_cast<MouseKeysDominantHand>(active_user_prefs_->GetInteger(
prefs::kAccessibilityMouseKeysDominantHand));
Shell::Get()->mouse_keys_controller()->set_left_handed(
dominant_hand == MouseKeysDominantHand::kLeftHandDominant);
}
void AccessibilityController::SetAutoclickMenuPosition(
FloatingMenuPosition position) {
if (!active_user_prefs_) {
return;
}
active_user_prefs_->SetInteger(prefs::kAccessibilityAutoclickMenuPosition,
static_cast<int>(position));
active_user_prefs_->CommitPendingWrite();
Shell::Get()->autoclick_controller()->SetMenuPosition(position);
}
FloatingMenuPosition AccessibilityController::GetAutoclickMenuPosition() {
DCHECK(active_user_prefs_);
return static_cast<FloatingMenuPosition>(active_user_prefs_->GetInteger(
prefs::kAccessibilityAutoclickMenuPosition));
}
void AccessibilityController::RequestAutoclickScrollableBoundsForPoint(
const gfx::Point& point_in_screen) {
if (client_) {
client_->RequestAutoclickScrollableBoundsForPoint(point_in_screen);
}
}
void AccessibilityController::MagnifierBoundsChanged(
const gfx::Rect& bounds_in_screen) {
if (client_) {
client_->MagnifierBoundsChanged(bounds_in_screen);
}
}
void AccessibilityController::UpdateFloatingPanelBoundsIfNeeded() {
Shell* shell = Shell::Get();
if (shell->accessibility_controller()->autoclick().enabled()) {
shell->autoclick_controller()->UpdateAutoclickMenuBoundsIfNeeded();
}
if (shell->accessibility_controller()->sticky_keys().enabled()) {
shell->sticky_keys_controller()->UpdateStickyKeysOverlayBoundsIfNeeded();
}
}
void AccessibilityController::UpdateAutoclickMenuBoundsIfNeeded() {
Shell::Get()->autoclick_controller()->UpdateAutoclickMenuBoundsIfNeeded();
}
void AccessibilityController::HandleAutoclickScrollableBoundsFound(
const gfx::Rect& bounds_in_screen) {
Shell::Get()->autoclick_controller()->HandleAutoclickScrollableBoundsFound(
bounds_in_screen);
}
void AccessibilityController::SetFloatingMenuPosition(
FloatingMenuPosition position) {
if (!active_user_prefs_) {
return;
}
active_user_prefs_->SetInteger(prefs::kAccessibilityFloatingMenuPosition,
static_cast<int>(position));
active_user_prefs_->CommitPendingWrite();
}
void AccessibilityController::UpdateFloatingMenuPositionFromPref() {
if (floating_menu_controller_) {
floating_menu_controller_->SetMenuPosition(GetFloatingMenuPosition());
}
}
FloatingMenuPosition AccessibilityController::GetFloatingMenuPosition() {
DCHECK(active_user_prefs_);
return static_cast<FloatingMenuPosition>(active_user_prefs_->GetInteger(
prefs::kAccessibilityFloatingMenuPosition));
}
void AccessibilityController::UpdateLargeCursorFromPref() {
DCHECK(active_user_prefs_);
const bool enabled = large_cursor().enabled();
const int size = enabled ? active_user_prefs_->GetInteger(
prefs::kAccessibilityLargeCursorDipSize)
: kDefaultLargeCursorSize;
if (large_cursor_size_in_dip_ == size) {
return;
}
large_cursor_size_in_dip_ = size;
NotifyAccessibilityStatusChanged();
Shell* shell = Shell::Get();
shell->cursor_manager()->SetCursorSize(enabled ? ui::CursorSize::kLarge
: ui::CursorSize::kNormal);
shell->SetLargeCursorSizeInDip(large_cursor_size_in_dip_);
shell->UpdateCursorCompositingEnabled();
}
void AccessibilityController::UpdateCursorColorFromPrefs(bool notify) {
DCHECK(active_user_prefs_);
const bool enabled =
active_user_prefs_->GetBoolean(prefs::kAccessibilityCursorColorEnabled);
Shell* shell = Shell::Get();
shell->SetCursorColor(
enabled ? active_user_prefs_->GetInteger(prefs::kAccessibilityCursorColor)
: ui::kDefaultCursorColor);
if (notify) {
NotifyAccessibilityStatusChanged();
}
shell->UpdateCursorCompositingEnabled();
}
void AccessibilityController::UpdateFaceGazeFromPrefs() {
if (!::features::IsAccessibilityFaceGazeEnabled()) {
return;
}
const bool cursor_control_enabled = active_user_prefs_->GetBoolean(
prefs::kAccessibilityFaceGazeCursorControlEnabled);
const bool cursor_control_sentinel_enabled = active_user_prefs_->GetBoolean(
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel);
if (cursor_control_enabled != cursor_control_sentinel_enabled) {
active_user_prefs_->SetBoolean(
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel,
cursor_control_enabled);
}
const bool actions_enabled = active_user_prefs_->GetBoolean(
prefs::kAccessibilityFaceGazeActionsEnabled);
const bool actions_sentinel_enabled = active_user_prefs_->GetBoolean(
prefs::kAccessibilityFaceGazeActionsEnabledSentinel);
if (actions_enabled != actions_sentinel_enabled) {
active_user_prefs_->SetBoolean(
prefs::kAccessibilityFaceGazeActionsEnabledSentinel, actions_enabled);
}
const bool enabled =
active_user_prefs_->GetBoolean(prefs::kAccessibilityFaceGazeEnabled);
// Manage the pinned notification.
if (enabled) {
ShowAccessibilityNotification(A11yNotificationWrapper(
A11yNotificationType::kFaceGazeActive, kFaceGazeActiveNotificationId,
std::vector<std::u16string>(),
base::BindRepeating(
&AccessibilityController::OnFaceGazeActiveNotificationClicked,
GetWeakPtr())));
} else {
message_center::MessageCenter::Get()->RemoveNotification(
kFaceGazeActiveNotificationId, /*by_user=*/false);
}
}
void AccessibilityController::UpdateFlashNotificationsFromPrefs() {
if (!::features::IsAccessibilityFlashScreenFeatureEnabled()) {
return;
}
flash_screen_controller_->set_enabled(active_user_prefs_->GetBoolean(
prefs::kAccessibilityFlashNotificationsEnabled));
flash_screen_controller_->set_color(active_user_prefs_->GetInteger(
prefs::kAccessibilityFlashNotificationsColor));
}
void AccessibilityController::UpdateDisableTouchpadFromPrefs(bool notify) {
if (!disable_touchpad_event_rewriter_ ||
!::features::IsAccessibilityDisableTouchpadEnabled()) {
return;
}
if (notify) {
DisableTouchpadWithDialog();
return;
}
const DisableTouchpadMode touchpad_mode = static_cast<DisableTouchpadMode>(
active_user_prefs_->GetInteger(prefs::kAccessibilityDisableTrackpadMode));
if (touchpad_mode == DisableTouchpadMode::kAlways ||
touchpad_mode == DisableTouchpadMode::kOnExternalMouseConnected) {
disable_touchpad_event_rewriter_->SetEnabled(true);
}
}
void AccessibilityController::DisableTouchpadWithDialog() {
const DisableTouchpadMode touchpad_mode = static_cast<DisableTouchpadMode>(
active_user_prefs_->GetInteger(prefs::kAccessibilityDisableTrackpadMode));
switch (touchpad_mode) {
case DisableTouchpadMode::kAlways:
ShowDisableTouchpadDialog();
break;
case DisableTouchpadMode::kOnExternalMouseConnected:
if (Shell::Get()
->input_device_settings_controller()
->GetConnectedMice()
.size() > 0) {
ShowDisableTouchpadDialog();
}
break;
case DisableTouchpadMode::kNever:
active_user_prefs_->SetBoolean(
prefs::kAccessibilityDisableTrackpadEnabled, false);
message_center::MessageCenter* message_center =
message_center::MessageCenter::Get();
message_center->RemoveNotification(kNotificationId, false /* by_user */);
ShowToast(AccessibilityToastType::kTouchpadDisabled);
disable_touchpad_event_rewriter_->SetEnabled(false);
break;
}
}
void AccessibilityController::OnMouseConnected(const mojom::Mouse& mouse) {
ExternalDeviceConnected();
}
void AccessibilityController::OnTouchpadConnected(
const mojom::Touchpad& touchpad) {
ExternalDeviceConnected();
}
void AccessibilityController::ExternalDeviceConnected() {
if (!disable_touchpad_event_rewriter_) {
return;
}
const DisableTouchpadMode touchpad_mode = static_cast<DisableTouchpadMode>(
active_user_prefs_->GetInteger(prefs::kAccessibilityDisableTrackpadMode));
const bool touchpad_disabled = disable_touchpad_event_rewriter_->IsEnabled();
if (touchpad_mode == DisableTouchpadMode::kOnExternalMouseConnected &&
!touchpad_disabled) {
DisableTouchpadWithDialog();
}
}
void AccessibilityController::ShowDisableTouchpadDialog() {
accessibility_notification_controller_->CancelToast();
active_user_prefs_->SetBoolean(prefs::kAccessibilityDisableTrackpadEnabled,
true);
// The internal touchpad should be disabled before the user clicks "Accept",
// This is done to ensure the user can navigate with their keyboard.
disable_touchpad_event_rewriter_->SetEnabled(true);
const DisableTouchpadMode disable_touchpad_mode =
static_cast<DisableTouchpadMode>(active_user_prefs_->GetInteger(
prefs::kAccessibilityDisableTrackpadMode));
const std::u16string title =
l10n_util::GetStringUTF16(IDS_ASH_DISABLE_TOUCHPAD_DIALOG_TITLE);
// Construct the timeout message, leaving a placeholder for the countdown
// timer so that the string does not need to be completely rebuilt every
// timer tick.
constexpr char16_t kTimeoutPlaceHolder[] = u"$1";
const std::u16string description =
disable_touchpad_mode == DisableTouchpadMode::kAlways
? l10n_util::GetStringFUTF16(
IDS_ASH_DISABLE_TOUCHPAD_DIALOG_DESCRIPTION,
kTimeoutPlaceHolder)
: l10n_util::GetStringFUTF16(
IDS_ASH_DISABLE_TOUCHPAD_DIALOG_EXTERNAL_MOUSE_DESCRIPTION,
kTimeoutPlaceHolder);
ShowConfirmationDialog(
title, description, l10n_util::GetStringUTF16(IDS_ASH_CONFIRM_BUTTON),
l10n_util::GetStringUTF16(IDS_APP_CANCEL),
base::BindOnce(&AccessibilityController::OnDisableTouchpadDialogAccepted,
GetWeakPtr()),
base::BindOnce(&AccessibilityController::OnDisableTouchpadDialogDismissed,
GetWeakPtr()),
base::BindOnce(&AccessibilityController::OnDisableTouchpadDialogDismissed,
GetWeakPtr()),
kDialogTimeoutSeconds);
}
void AccessibilityController::OnDisableTouchpadDialogAccepted() {
confirmation_dialog_.reset();
ShowAccessibilityNotification(A11yNotificationWrapper(
A11yNotificationType::kTouchpadDisabled, kNotificationId,
std::vector<std::u16string>(),
base::BindRepeating(
&AccessibilityController::OnTouchpadNotificationClicked,
GetWeakPtr())));
}
void AccessibilityController::OnDisableTouchpadDialogDismissed() {
confirmation_dialog_.reset();
active_user_prefs_->SetInteger(prefs::kAccessibilityDisableTrackpadMode,
static_cast<int>(DisableTouchpadMode::kNever));
}
DisableTouchpadMode AccessibilityController::GetDisableTouchpadMode() {
return static_cast<DisableTouchpadMode>(
active_user_prefs_->GetInteger(prefs::kAccessibilityDisableTrackpadMode));
}
bool AccessibilityController::IsTouchpadDisabled() {
return disable_touchpad().enabled() &&
disable_touchpad_event_rewriter_->IsEnabled() &&
active_user_prefs_->GetInteger(
prefs::kAccessibilityDisableTrackpadMode) !=
static_cast<int>(DisableTouchpadMode::kNever);
}
void AccessibilityController::UpdateColorCorrectionFromPrefs() {
DCHECK(active_user_prefs_);
auto* color_enhancement_controller =
Shell::Get()->color_enhancement_controller();
if (!active_user_prefs_->GetBoolean(
prefs::kAccessibilityColorCorrectionEnabled)) {
color_enhancement_controller->SetColorCorrectionEnabledAndUpdateDisplays(
false);
return;
}
const float cvd_correction_amount =
active_user_prefs_->GetInteger(
prefs::kAccessibilityColorVisionCorrectionAmount) /
100.0f;
ColorVisionCorrectionType type =
static_cast<ColorVisionCorrectionType>(active_user_prefs_->GetInteger(
prefs::kAccessibilityColorVisionCorrectionType));
color_enhancement_controller->SetColorVisionCorrectionFilter(
type, cvd_correction_amount);
// Ensure displays get updated.
color_enhancement_controller->SetColorCorrectionEnabledAndUpdateDisplays(
true);
}
void AccessibilityController::UpdateCaretBlinkIntervalFromPrefs() const {
base::TimeDelta caret_blink_interval = base::Milliseconds(
active_user_prefs_->GetInteger(prefs::kAccessibilityCaretBlinkInterval));
bool notify_dark = false;
bool notify_web = false;
bool notify_native = false;
auto* native_theme_dark = ui::NativeTheme::GetInstanceForDarkUI();
if (native_theme_dark->GetCaretBlinkInterval() != caret_blink_interval) {
notify_dark = true;
native_theme_dark->set_caret_blink_interval(caret_blink_interval);
}
auto* native_theme_web = ui::NativeTheme::GetInstanceForWeb();
if (native_theme_web->GetCaretBlinkInterval() != caret_blink_interval) {
notify_web = true;
native_theme_web->set_caret_blink_interval(caret_blink_interval);
}
auto* native_theme = ui::NativeTheme::GetInstanceForNativeUi();
if (native_theme->GetCaretBlinkInterval() != caret_blink_interval) {
notify_native = true;
native_theme->set_caret_blink_interval(caret_blink_interval);
}
// Avoid unnecessary notifications.
if (notify_dark) {
native_theme_dark->NotifyOnNativeThemeUpdated();
}
if (notify_web) {
native_theme_web->NotifyOnNativeThemeUpdated();
}
if (notify_native) {
native_theme->NotifyOnNativeThemeUpdated();
}
}
void AccessibilityController::UpdateUseOverlayScrollbarFromPref() const {
const bool overlay_scrollbar_enabled_by_feature_flag =
::ui::IsOverlayScrollbarEnabledByFeatureFlag();
const bool overlay_scrollbar_enabled_by_os_setting =
!always_show_scrollbar().enabled();
const bool use_overlay_scrollbar =
overlay_scrollbar_enabled_by_feature_flag ||
overlay_scrollbar_enabled_by_os_setting;
bool notify_dark = false;
bool notify_web = false;
bool notify_native = false;
auto* native_theme_dark = ui::NativeTheme::GetInstanceForDarkUI();
if (native_theme_dark->use_overlay_scrollbar() != use_overlay_scrollbar) {
notify_dark = true;
native_theme_dark->set_use_overlay_scrollbar(use_overlay_scrollbar);
}
auto* native_theme_web = ui::NativeTheme::GetInstanceForWeb();
if (native_theme_web->use_overlay_scrollbar() != use_overlay_scrollbar) {
notify_web = true;
native_theme_web->set_use_overlay_scrollbar(use_overlay_scrollbar);
}
auto* native_theme = ui::NativeTheme::GetInstanceForNativeUi();
if (native_theme->use_overlay_scrollbar() != use_overlay_scrollbar) {
notify_native = true;
native_theme->set_use_overlay_scrollbar(use_overlay_scrollbar);
}
// Avoid unnecessary notifications.
if (notify_dark) {
native_theme_dark->NotifyOnNativeThemeUpdated();
}
if (notify_web) {
native_theme_web->NotifyOnNativeThemeUpdated();
}
if (notify_native) {
native_theme->NotifyOnNativeThemeUpdated();
}
}
std::optional<ui::KeyboardCode>
AccessibilityController::GetCaretBrowsingActionKey() {
const std::vector<ui::KeyboardDevice>& keyboards =
ui::DeviceDataManager::GetInstance()->GetKeyboardDevices();
std::optional<ui::TopRowActionKey> key;
if (keyboards.size() > 0) {
if (ash::Shell::Get()
->event_rewriter_controller()
->event_rewriter_ash_delegate()
->TopRowKeysAreFunctionKeys(keyboards[0].id)) {
return ui::VKEY_F7;
}
key = ash::Shell::Get()
->keyboard_capability()
->GetCorrespondingActionKeyForFKey(keyboards[0], ui::VKEY_F7);
}
if (key) {
return ui::KeyboardCapability::ConvertToKeyboardCode(*key);
}
return std::nullopt;
}
void AccessibilityController::UpdateAccessibilityHighlightingFromPrefs() {
if (!caret_highlight().enabled() && !cursor_highlight().enabled() &&
!focus_highlight().enabled()) {
accessibility_highlight_controller_.reset();
return;
}
if (!accessibility_highlight_controller_) {
accessibility_highlight_controller_ =
std::make_unique<AccessibilityHighlightController>();
}
accessibility_highlight_controller_->HighlightCaret(
caret_highlight().enabled());
accessibility_highlight_controller_->HighlightCursor(
cursor_highlight().enabled());
accessibility_highlight_controller_->HighlightFocus(
focus_highlight().enabled());
}
void AccessibilityController::MaybeCreateSelectToSpeakEventHandler() {
// Construct the handler as needed when Select-to-Speak is enabled and the
// delegate is set. Otherwise, destroy the handler when Select-to-Speak is
// disabled or the delegate has been destroyed.
if (!select_to_speak().enabled() ||
!select_to_speak_event_handler_delegate_) {
select_to_speak_event_handler_.reset();
return;
}
if (select_to_speak_event_handler_) {
return;
}
select_to_speak_event_handler_ = std::make_unique<SelectToSpeakEventHandler>(
select_to_speak_event_handler_delegate_);
}
void AccessibilityController::UpdateSwitchAccessKeyCodesFromPref(
SwitchAccessCommand command) {
if (!active_user_prefs_) {
return;
}
SyncSwitchAccessPrefsToSignInProfile();
if (!accessibility_event_rewriter_) {
return;
}
std::string pref_key = PrefKeyForSwitchAccessCommand(command);
const base::Value::Dict& key_codes_pref =
active_user_prefs_->GetDict(pref_key);
std::map<int, std::set<std::string>> key_codes;
for (const auto v : key_codes_pref) {
int key_code;
if (!base::StringToInt(v.first, &key_code)) {
NOTREACHED();
}
key_codes[key_code] = std::set<std::string>();
for (const base::Value& device_type : v.second.GetList()) {
key_codes[key_code].insert(device_type.GetString());
}
DCHECK(!key_codes[key_code].empty());
}
std::string uma_name = UmaNameForSwitchAccessCommand(command);
if (key_codes.size() == 0) {
base::UmaHistogramEnumeration(uma_name, SwitchAccessKeyCode::kNone);
}
for (const auto& key_code : key_codes) {
base::UmaHistogramEnumeration(
uma_name, static_cast<SwitchAccessKeyCode>(key_code.first));
}
accessibility_event_rewriter_->SetKeyCodesForSwitchAccessCommand(key_codes,
command);
}
void AccessibilityController::UpdateSwitchAccessAutoScanEnabledFromPref() {
DCHECK(active_user_prefs_);
const bool enabled = active_user_prefs_->GetBoolean(
prefs::kAccessibilitySwitchAccessAutoScanEnabled);
base::UmaHistogramBoolean("Accessibility.CrosSwitchAccess.AutoScan", enabled);
SyncSwitchAccessPrefsToSignInProfile();
}
void AccessibilityController::UpdateSwitchAccessAutoScanSpeedFromPref() {
DCHECK(active_user_prefs_);
const int speed_ms = active_user_prefs_->GetInteger(
prefs::kAccessibilitySwitchAccessAutoScanSpeedMs);
base::UmaHistogramCustomCounts(
"Accessibility.CrosSwitchAccess.AutoScan.SpeedMs", speed_ms, 1 /* min */,
10000 /* max */, 100 /* buckets */);
SyncSwitchAccessPrefsToSignInProfile();
}
void AccessibilityController::
UpdateSwitchAccessAutoScanKeyboardSpeedFromPref() {
DCHECK(active_user_prefs_);
const int speed_ms = active_user_prefs_->GetInteger(
prefs::kAccessibilitySwitchAccessAutoScanKeyboardSpeedMs);
base::UmaHistogramCustomCounts(
"Accessibility.CrosSwitchAccess.AutoScan.KeyboardSpeedMs", speed_ms,
1 /* min */, 10000 /* max */, 100 /* buckets */);
SyncSwitchAccessPrefsToSignInProfile();
}
void AccessibilityController::UpdateSwitchAccessPointScanSpeedFromPref() {
// TODO(accessibility): Log histogram for point scan speed
DCHECK(active_user_prefs_);
const int point_scan_speed_dips_per_second = active_user_prefs_->GetInteger(
prefs::kAccessibilitySwitchAccessPointScanSpeedDipsPerSecond);
SetPointScanSpeedDipsPerSecond(point_scan_speed_dips_per_second);
SyncSwitchAccessPrefsToSignInProfile();
}
void AccessibilityController::SwitchAccessDisableDialogClosed(
bool disable_dialog_accepted) {
switch_access_disable_dialog_showing_ = false;
// Always deactivate switch access. Turning switch access off ensures it is
// re-activated correctly.
// The pref was already disabled, but we left switch access on so the user
// could interact with the dialog.
DeactivateSwitchAccess();
if (disable_dialog_accepted) {
RemoveAccessibilityNotification();
NotifyAccessibilityStatusChanged();
SyncSwitchAccessPrefsToSignInProfile();
} else {
// Reset the preference (which was already set to false). Doing so turns
// switch access back on.
skip_switch_access_notification_ = true;
switch_access().SetEnabled(true);
}
}
void AccessibilityController::UpdateKeyCodesAfterSwitchAccessEnabled() {
UpdateSwitchAccessKeyCodesFromPref(SwitchAccessCommand::kSelect);
UpdateSwitchAccessKeyCodesFromPref(SwitchAccessCommand::kNext);
UpdateSwitchAccessKeyCodesFromPref(SwitchAccessCommand::kPrevious);
}
void AccessibilityController::ActivateSwitchAccess() {
switch_access_bubble_controller_ =
std::make_unique<SwitchAccessMenuBubbleController>();
point_scan_controller_ = std::make_unique<PointScanController>();
UpdateKeyCodesAfterSwitchAccessEnabled();
UpdateSwitchAccessPointScanSpeedFromPref();
if (skip_switch_access_notification_) {
skip_switch_access_notification_ = false;
return;
}
ShowAccessibilityNotification(
A11yNotificationWrapper(A11yNotificationType::kSwitchAccessEnabled,
kNotificationId, std::vector<std::u16string>()));
}
void AccessibilityController::DeactivateSwitchAccess() {
if (client_) {
client_->OnSwitchAccessDisabled();
}
point_scan_controller_.reset();
switch_access_bubble_controller_.reset();
}
void AccessibilityController::SyncSwitchAccessPrefsToSignInProfile() {
if (!active_user_prefs_ || IsSigninPrefService(active_user_prefs_)) {
return;
}
PrefService* signin_prefs =
Shell::Get()->session_controller()->GetSigninScreenPrefService();
DCHECK(signin_prefs);
for (const auto* pref_path : kSwitchAccessPrefsCopiedToSignin) {
const PrefService::Preference* pref =
active_user_prefs_->FindPreference(pref_path);
// Ignore if the pref has not been set by the user.
if (!pref || !pref->IsUserControlled()) {
continue;
}
// Copy the pref value to the signin profile.
const base::Value* value = pref->GetValue();
signin_prefs->Set(pref_path, *value);
}
}
void AccessibilityController::UpdateShortcutsEnabledFromPref() {
DCHECK(active_user_prefs_);
const bool enabled =
active_user_prefs_->GetBoolean(prefs::kAccessibilityShortcutsEnabled);
if (shortcuts_enabled_ == enabled) {
return;
}
shortcuts_enabled_ = enabled;
NotifyAccessibilityStatusChanged();
}
void AccessibilityController::UpdateTabletModeShelfNavigationButtonsFromPref() {
DCHECK(active_user_prefs_);
const bool enabled = active_user_prefs_->GetBoolean(
prefs::kAccessibilityTabletModeShelfNavigationButtonsEnabled);
if (tablet_mode_shelf_navigation_buttons_enabled_ == enabled) {
return;
}
tablet_mode_shelf_navigation_buttons_enabled_ = enabled;
NotifyAccessibilityStatusChanged();
}
std::u16string AccessibilityController::GetBatteryDescription() const {
// Pass battery status as string to callback function.
return PowerStatus::Get()->GetAccessibleNameString(
/*full_description=*/true);
}
void AccessibilityController::SetVirtualKeyboardVisible(bool is_visible) {
if (is_visible) {
Shell::Get()->keyboard_controller()->ShowKeyboard();
} else {
Shell::Get()->keyboard_controller()->HideKeyboard(HideReason::kUser);
}
if (set_virtual_keyboard_visible_callback_) {
set_virtual_keyboard_visible_callback_.Run();
}
}
void AccessibilityController::ToggleMouseKeys() {
if (::features::IsAccessibilityMouseKeysEnabled() && mouse_keys().enabled()) {
Shell::Get()->mouse_keys_controller()->Toggle();
NotifyAccessibilityStatusChanged();
}
}
void AccessibilityController::PerformAccessibilityAction() {
// TODO(b/335456364): Add UMA.
aura::Window* target_root = Shell::GetRootWindowForNewWindows();
StatusAreaWidget* status_area_widget =
RootWindowController::ForWindow(target_root)->GetStatusAreaWidget();
if (!status_area_widget) {
// TODO(b/335456364): Support Kiosk mode.
}
UnifiedSystemTray* tray = status_area_widget->unified_system_tray();
if (tray->IsBubbleShown()) {
if (tray->bubble()
->unified_system_tray_controller()
->showing_accessibility_detailed_view()) {
tray->CloseBubble();
return;
}
} else {
tray->ShowBubble();
}
tray->bubble()
->unified_system_tray_controller()
->ShowAccessibilityDetailedView();
}
void AccessibilityController::PerformAcceleratorAction(
AcceleratorAction accelerator_action) {
AcceleratorController::Get()->PerformActionIfEnabled(accelerator_action,
/* accelerator = */ {});
}
void AccessibilityController::NotifyAccessibilityStatusChanged() {
for (auto& observer : observers_) {
observer.OnAccessibilityStatusChanged();
}
}
bool AccessibilityController::IsAccessibilityFeatureVisibleInTrayMenu(
const std::string& path) {
if (!active_user_prefs_) {
return true;
}
if (active_user_prefs_->FindPreference(path)->IsManaged() &&
!active_user_prefs_->GetBoolean(path)) {
return false;
}
return true;
}
void AccessibilityController::SuspendSwitchAccessKeyHandling(bool suspend) {
accessibility_event_rewriter_->set_suspend_switch_access_key_handling(
suspend);
}
void AccessibilityController::EnableChromeVoxVolumeSlideGesture() {
enable_chromevox_volume_slide_gesture_ = true;
}
void AccessibilityController::ShowConfirmationDialog(
const std::u16string& title,
const std::u16string& description,
const std::u16string& confirm_name,
const std::u16string& cancel_name,
base::OnceClosure on_accept_callback,
base::OnceClosure on_cancel_callback,
base::OnceClosure on_close_callback,
std::optional<int> timeout_seconds) {
if (confirmation_dialog_) {
// If a dialog is already being shown we do not show a new one.
// Instead, run the on_close_callback on the new dialog to indicate
// it was closed without the user taking any action.
// This is consistent with AcceleratorController.
std::move(on_close_callback).Run();
return;
}
auto* dialog = new AccessibilityConfirmationDialog(
title, description, confirm_name, cancel_name,
std::move(on_accept_callback), std::move(on_cancel_callback),
std::move(on_close_callback), timeout_seconds);
// Save the dialog so it doesn't go out of scope before it is
// used and closed.
confirmation_dialog_ = dialog->GetWeakPtr();
if (show_confirmation_dialog_callback_for_testing_) {
show_confirmation_dialog_callback_for_testing_.Run();
}
}
gfx::Rect AccessibilityController::GetConfirmationDialogBoundsInScreen() {
if (!confirmation_dialog_.get()) {
return gfx::Rect();
}
return confirmation_dialog_.get()->GetWidget()->GetWindowBoundsInScreen();
}
void AccessibilityController::ShowFeatureDisableDialog(
int window_title_text_id,
base::OnceClosure on_accept_callback,
base::OnceClosure on_cancel_callback) {
if (disable_dialog_) {
// If a dialog is already being shown we do not show a new one.
// Instead, run the on_close_callback on the new dialog to indicate
// it was closed without the user taking any action.
// This is consistent with AcceleratorController.
std::move(on_cancel_callback).Run();
return;
}
auto* dialog = new AccessibilityFeatureDisableDialog(
window_title_text_id, std::move(on_accept_callback),
std::move(on_cancel_callback));
disable_dialog_ = dialog->GetWeakPtr();
if (show_disable_dialog_callback_for_testing_) {
show_disable_dialog_callback_for_testing_.Run();
}
}
void AccessibilityController::PreviewFlashNotification() const {
flash_screen_controller_->PreviewFlash();
}
void AccessibilityController::
UpdateDictationButtonOnSpeechRecognitionDownloadChanged(
int download_progress) {
dictation_soda_download_progress_ = download_progress;
Shell::Get()
->GetPrimaryRootWindowController()
->GetStatusAreaWidget()
->dictation_button_tray()
->UpdateOnSpeechRecognitionDownloadChanged(download_progress);
}
void AccessibilityController::ShowNotificationForDictation(
DictationNotificationType type,
const std::u16string& display_language) {
A11yNotificationType notification_type;
switch (type) {
case DictationNotificationType::kAllDlcsDownloaded:
notification_type = A11yNotificationType::kDictationAllDlcsDownloaded;
break;
case DictationNotificationType::kNoDlcsDownloaded:
notification_type = A11yNotificationType::kDictationNoDlcsDownloaded;
break;
case DictationNotificationType::kOnlySodaDownloaded:
notification_type = A11yNotificationType::kDictationOnlySodaDownloaded;
break;
case DictationNotificationType::kOnlyPumpkinDownloaded:
notification_type = A11yNotificationType::kDicationOnlyPumpkinDownloaded;
break;
}
ShowAccessibilityNotification(
A11yNotificationWrapper(notification_type, kNotificationId,
std::vector<std::u16string>{display_language}));
}
void AccessibilityController::ShowNotificationForFaceGaze(
FaceGazeNotificationType type) {
A11yNotificationType notification_type;
std::string notification_shown_pref;
switch (type) {
case FaceGazeNotificationType::kDlcSucceeded:
notification_type = A11yNotificationType::kFaceGazeAssetsDownloaded;
notification_shown_pref =
prefs::kFaceGazeDlcSuccessNotificationHasBeenShown;
break;
case FaceGazeNotificationType::kDlcFailed:
notification_type = A11yNotificationType::kFaceGazeAssetsFailed;
notification_shown_pref =
prefs::kFaceGazeDlcFailureNotificationHasBeenShown;
break;
}
if (active_user_prefs_->GetBoolean(notification_shown_pref) &&
notification_shown_pref ==
prefs::kFaceGazeDlcSuccessNotificationHasBeenShown) {
// Do not show success notifications more than once.
return;
}
active_user_prefs_->SetBoolean(notification_shown_pref, true);
ShowAccessibilityNotification(A11yNotificationWrapper(
notification_type, kNotificationId, std::vector<std::u16string>()));
}
AccessibilityController::A11yNotificationWrapper::A11yNotificationWrapper() =
default;
AccessibilityController::A11yNotificationWrapper::A11yNotificationWrapper(
A11yNotificationType type_in,
const std::string& notification_id_in,
std::vector<std::u16string> replacements_in)
: type(type_in),
notification_id(notification_id_in),
replacements(replacements_in) {}
AccessibilityController::A11yNotificationWrapper::A11yNotificationWrapper(
A11yNotificationType type_in,
const std::string& notification_id_in,
std::vector<std::u16string> replacements_in,
std::optional<base::RepeatingCallback<void(std::optional<int>)>>
callback_in)
: type(type_in),
notification_id(notification_id_in),
replacements(replacements_in),
callback(std::move(callback_in)) {}
AccessibilityController::A11yNotificationWrapper::~A11yNotificationWrapper() =
default;
AccessibilityController::A11yNotificationWrapper::A11yNotificationWrapper(
const A11yNotificationWrapper&) = default;
void AccessibilityController::UpdateFeatureFromPref(FeatureType feature) {
size_t feature_index = static_cast<size_t>(feature);
bool enabled = features_[feature_index]->enabled();
bool is_managed = active_user_prefs_->IsManagedPreference(
features_[feature_index]->pref_name());
switch (feature) {
case FeatureType::kAutoclick:
Shell::Get()->autoclick_controller()->SetEnabled(
enabled, /*show_confirmation_dialog=*/
!no_auto_click_confirmation_dialog_for_testing_ && !is_managed);
break;
case FeatureType::kBounceKeys:
if (filter_keys_event_rewriter_) {
filter_keys_event_rewriter_->SetBounceKeysEnabled(enabled);
}
break;
case FeatureType::kCaretHighlight:
UpdateAccessibilityHighlightingFromPrefs();
break;
case FeatureType::kCursorHighlight:
UpdateAccessibilityHighlightingFromPrefs();
break;
case FeatureType::kDictation:
if (enabled) {
if (!dictation_bubble_controller_) {
dictation_bubble_controller_ =
std::make_unique<DictationBubbleController>();
}
} else {
dictation_bubble_controller_.reset();
}
break;
case FeatureType::kDisableTouchpad:
if (!::features::IsAccessibilityDisableTouchpadEnabled() ||
!disable_touchpad_event_rewriter_) {
return;
}
disable_touchpad_event_rewriter_->SetEnabled(enabled);
break;
case FeatureType::kFloatingMenu:
if (enabled && always_show_floating_menu_when_enabled_) {
ShowFloatingMenuIfEnabled();
} else {
floating_menu_controller_.reset();
}
break;
case FeatureType::kFocusHighlight:
UpdateAccessibilityHighlightingFromPrefs();
break;
case FeatureType::kFullscreenMagnifier:
break;
case FeatureType::kDockedMagnifier:
break;
case FeatureType::kHighContrast:
Shell::Get()->color_enhancement_controller()->SetHighContrastEnabled(
enabled);
break;
case FeatureType::kLargeCursor:
Shell::Get()->cursor_manager()->SetCursorSize(
large_cursor().enabled() ? ui::CursorSize::kLarge
: ui::CursorSize::kNormal);
Shell::Get()->SetLargeCursorSizeInDip(large_cursor_size_in_dip_);
Shell::Get()->UpdateCursorCompositingEnabled();
break;
case FeatureType::kLiveCaption:
live_caption().SetEnabled(enabled);
break;
case FeatureType::kMonoAudio:
CrasAudioHandler::Get()->SetOutputMonoEnabled(enabled);
break;
case FeatureType::kMouseKeys:
if (::features::IsAccessibilityMouseKeysEnabled()) {
// TODO(b/259372916): Consider creating/deleting MouseKeysController
// here.
Shell::Get()->mouse_keys_controller()->set_enabled(enabled);
}
break;
case FeatureType::kSpokenFeedback:
message_center::MessageCenter::Get()->SetSpokenFeedbackEnabled(enabled);
// TODO(warx): ChromeVox loading/unloading requires browser process
// started, thus it is still handled on Chrome side.
// ChromeVox focus highlighting overrides the other focus highlighting.
focus_highlight().UpdateFromPref();
break;
case FeatureType::kReducedAnimations:
// Handled in AccessibilityManager.
break;
case FeatureType::kAlwaysShowScrollbar:
UpdateUseOverlayScrollbarFromPref();
break;
case FeatureType::kSelectToSpeak:
select_to_speak_state_ = SelectToSpeakState::kSelectToSpeakStateInactive;
if (enabled) {
MaybeCreateSelectToSpeakEventHandler();
} else {
select_to_speak_event_handler_.reset();
HideSelectToSpeakPanel();
select_to_speak_bubble_controller_.reset();
}
break;
case FeatureType::kSlowKeys:
if (::features::IsAccessibilitySlowKeysEnabled()) {
input_method::InputMethodManager::Get()
->GetImeKeyboard()
->SetSlowKeysEnabled(enabled);
}
break;
case FeatureType::kStickyKeys:
Shell::Get()->sticky_keys_controller()->Enable(enabled);
break;
case FeatureType::kSwitchAccess:
if (!enabled) {
if (no_switch_access_disable_confirmation_dialog_for_testing_) {
SwitchAccessDisableDialogClosed(true);
} else {
// Show a dialog before disabling Switch Access.
new AccessibilityFeatureDisableDialog(
IDS_ASH_SWITCH_ACCESS_DISABLE_CONFIRMATION_TEXT,
base::BindOnce(
&AccessibilityController::SwitchAccessDisableDialogClosed,
weak_ptr_factory_.GetWeakPtr(), true),
base::BindOnce(
&AccessibilityController::SwitchAccessDisableDialogClosed,
weak_ptr_factory_.GetWeakPtr(), false));
switch_access_disable_dialog_showing_ = true;
}
// Return early. We will call NotifyAccessibilityStatusChanged() if the
// user accepts the dialog.
return;
} else {
ActivateSwitchAccess();
}
SyncSwitchAccessPrefsToSignInProfile();
break;
case FeatureType::kVirtualKeyboard:
keyboard::SetAccessibilityKeyboardEnabled(enabled);
break;
case FeatureType::kCursorColor:
// The notification will already come via UpdateFeatureFromPref
// so we don't need to run it twice.
UpdateCursorColorFromPrefs(/*notify=*/false);
break;
case FeatureType::kColorCorrection:
if (enabled && !active_user_prefs_->GetBoolean(
prefs::kAccessibilityColorCorrectionHasBeenSetup)) {
Shell::Get()
->system_tray_model()
->client()
->ShowColorCorrectionSettings();
active_user_prefs_->SetBoolean(
prefs::kAccessibilityColorCorrectionHasBeenSetup, true);
}
UpdateColorCorrectionFromPrefs();
break;
case FeatureType::kFaceGaze:
if (enabled && ::features::IsAccessibilityFaceGazeEnabled()) {
if (!facegaze_bubble_controller_) {
facegaze_bubble_controller_ =
std::make_unique<FaceGazeBubbleController>(base::BindRepeating(
&AccessibilityController::RequestDisableFaceGaze,
GetWeakPtr()));
}
if (!drag_event_rewriter_) {
drag_event_rewriter_ = std::make_unique<DragEventRewriter>();
Shell::GetPrimaryRootWindow()
->GetHost()
->GetEventSource()
->AddEventRewriter(drag_event_rewriter_.get());
}
} else {
facegaze_bubble_controller_.reset();
Shell::GetPrimaryRootWindow()
->GetHost()
->GetEventSource()
->RemoveEventRewriter(drag_event_rewriter_.get());
drag_event_rewriter_.reset();
}
UpdateFaceGazeFromPrefs();
break;
case FeatureType::kFlashNotifications:
UpdateFlashNotificationsFromPrefs();
break;
case FeatureType::kFeatureCount:
case FeatureType::kNoConflictingFeature:
NOTREACHED();
}
NotifyAccessibilityStatusChanged();
}
void AccessibilityController::UpdateDictationBubble(
bool visible,
DictationBubbleIconType icon,
const std::optional<std::u16string>& text,
const std::optional<std::vector<DictationBubbleHintType>>& hints) {
DCHECK(dictation().enabled());
DCHECK(dictation_bubble_controller_);
dictation_bubble_controller_->UpdateBubble(visible, icon, text, hints);
}
DictationBubbleController*
AccessibilityController::GetDictationBubbleControllerForTest() {
if (!dictation_bubble_controller_) {
dictation_bubble_controller_ =
std::make_unique<DictationBubbleController>();
}
return dictation_bubble_controller_.get();
}
void AccessibilityController::ShowToast(AccessibilityToastType type) {
accessibility_notification_controller_->ShowToast(type);
}
void AccessibilityController::AddShowToastCallbackForTesting(
base::RepeatingCallback<void(AccessibilityToastType)> callback) {
accessibility_notification_controller_->AddShowToastCallbackForTesting(
std::move(callback));
}
void AccessibilityController::AddShowConfirmationDialogCallbackForTesting(
base::RepeatingCallback<void()> callback) {
show_confirmation_dialog_callback_for_testing_ = std::move(callback);
}
void AccessibilityController::AddFeatureDisableDialogCallbackForTesting(
base::RepeatingCallback<void()> callback) {
show_disable_dialog_callback_for_testing_ = std::move(callback);
}
bool AccessibilityController::VerifyFeaturesDataForTesting() {
return VerifyFeaturesData();
}
void AccessibilityController::SetVirtualKeyboardVisibleCallbackForTesting(
base::RepeatingCallback<void()> callback) {
set_virtual_keyboard_visible_callback_ = std::move(callback);
}
void AccessibilityController::ScrollAtPoint(
const gfx::Point& target,
AccessibilityScrollDirection direction) {
float scroll_x = 0.0f;
float scroll_y = 0.0f;
switch (direction) {
case AccessibilityScrollDirection::kUp:
scroll_y = kScrollDelta;
break;
case AccessibilityScrollDirection::kDown:
scroll_y = -kScrollDelta;
break;
case AccessibilityScrollDirection::kLeft:
scroll_x = kScrollDelta;
break;
case AccessibilityScrollDirection::kRight:
scroll_x = -kScrollDelta;
}
// Generate a scroll event at the target location.
aura::Window* root_window = window_util::GetRootWindowAt(target);
gfx::Point location_in_pixels(target);
::wm::ConvertPointFromScreen(root_window, &location_in_pixels);
aura::WindowTreeHost* host = root_window->GetHost();
host->ConvertDIPToPixels(&location_in_pixels);
ui::ScrollEvent scroll(
ui::EventType::kScroll, gfx::PointF(location_in_pixels),
gfx::PointF(location_in_pixels), ui::EventTimeForNow(),
ui::EF_IS_SYNTHESIZED, scroll_x, scroll_y, 0 /* x_offset_ordinal */,
0 /* y_offset_ordinal */, 2 /* finger_count */);
ui::MouseWheelEvent wheel(scroll);
std::ignore = host->GetEventSink()->OnEventFromSource(&wheel);
}
void AccessibilityController::OnFaceGazeSentinelChanged(
const std::string& sentinel_pref,
const std::string& behavior_pref) {
DCHECK(active_user_prefs_);
if (active_user_prefs_->GetBoolean(sentinel_pref)) {
active_user_prefs_->SetBoolean(behavior_pref, true);
return;
}
int window_title_text_id = 0;
if (sentinel_pref ==
prefs::kAccessibilityFaceGazeCursorControlEnabledSentinel) {
window_title_text_id =
IDS_ASH_FACEGAZE_CURSOR_CONTROL_DISABLE_CONFIRMATION_TEXT;
} else if (sentinel_pref ==
prefs::kAccessibilityFaceGazeActionsEnabledSentinel) {
window_title_text_id = IDS_ASH_FACEGAZE_ACTIONS_DISABLE_CONFIRMATION_TEXT;
} else {
NOTREACHED();
}
ShowFeatureDisableDialog(
window_title_text_id,
BindOnce(&AccessibilityController::OnFaceGazeDisableDialogClosed,
GetWeakPtr(), sentinel_pref, behavior_pref,
/*dialog_accepted=*/true),
BindOnce(&AccessibilityController::OnFaceGazeDisableDialogClosed,
GetWeakPtr(), sentinel_pref, behavior_pref,
/*dialog_accepted=*/false));
}
void AccessibilityController::OnFaceGazeDisableDialogClosed(
const std::string& sentinel_pref,
const std::string& behavior_pref,
bool dialog_accepted) {
if (dialog_accepted) {
// After confirmation, set behavior pref to false to turn off the feature.
active_user_prefs_->SetBoolean(behavior_pref, false);
} else {
// Ensure sentinel pref is in sync with behavior pref if dialog is
// cancelled.
active_user_prefs_->SetBoolean(sentinel_pref, true);
}
disable_dialog_.reset();
}
void AccessibilityController::UpdateFaceGazeBubble(const std::u16string& text,
bool is_warning) {
if (!facegaze_bubble_controller_ ||
!::features::IsAccessibilityFaceGazeEnabled()) {
return;
}
facegaze_bubble_controller_->UpdateBubble(text, is_warning);
}
FaceGazeBubbleController*
AccessibilityController::GetFaceGazeBubbleControllerForTest() {
if (!facegaze_bubble_controller_) {
facegaze_bubble_controller_ =
std::make_unique<FaceGazeBubbleController>(base::BindRepeating(
&AccessibilityController::RequestDisableFaceGaze, GetWeakPtr()));
}
return facegaze_bubble_controller_.get();
}
void AccessibilityController::ObserveInputDeviceSettings() {
if (!input_device_settings_observer_.IsObservingSource(
Shell::Get()->input_device_settings_controller())) {
input_device_settings_observer_.Observe(
Shell::Get()->input_device_settings_controller());
}
}
void AccessibilityController::EnableDragEventRewriter(bool enabled) {
if (!drag_event_rewriter_) {
return;
}
drag_event_rewriter_->SetEnabled(enabled);
}
void AccessibilityController::RequestDisableFaceGaze() {
ShowFeatureDisableDialog(
IDS_ASH_FACEGAZE_DISABLE_CONFIRMATION_TEXT,
BindOnce(&AccessibilityController::OnRequestDisableFaceGazeAction,
GetWeakPtr(), /*dialog_accepted=*/true),
BindOnce(&AccessibilityController::OnRequestDisableFaceGazeAction,
GetWeakPtr(), /*dialog_accepted=*/false));
}
void AccessibilityController::OnRequestDisableFaceGazeAction(
bool dialog_accepted) {
if (dialog_accepted) {
active_user_prefs_->SetBoolean(prefs::kAccessibilityFaceGazeEnabled, false);
}
disable_dialog_.reset();
client_->SendFaceGazeDisableDialogResultToSettings(dialog_accepted);
}
} // namespace ash
|