| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1812 if (textSelection.isValid()) | 1812 if (textSelection.isValid()) |
| 1813 return textSelection; | 1813 return textSelection; |
| 1814 | 1814 |
| 1815 if (!getLayoutObject() || !getLayoutObject()->frame()) | 1815 if (!getLayoutObject() || !getLayoutObject()->frame()) |
| 1816 return AXRange(); | 1816 return AXRange(); |
| 1817 | 1817 |
| 1818 VisibleSelection selection = getLayoutObject()->frame()->selection().selecti
on(); | 1818 VisibleSelection selection = getLayoutObject()->frame()->selection().selecti
on(); |
| 1819 if (selection.isNone()) | 1819 if (selection.isNone()) |
| 1820 return AXRange(); | 1820 return AXRange(); |
| 1821 | 1821 |
| 1822 Position visibleStart = selection.visibleStart().toParentAnchoredPosition(); | 1822 VisiblePosition visibleStart = selection.visibleStart(); |
| 1823 Position visibleEnd = selection.visibleEnd().toParentAnchoredPosition(); | 1823 Position start = visibleStart.toParentAnchoredPosition(); |
| 1824 TextAffinity startAffinity = visibleStart.affinity(); |
| 1825 VisiblePosition visibleEnd = selection.visibleEnd(); |
| 1826 Position end = visibleEnd.toParentAnchoredPosition(); |
| 1827 TextAffinity endAffinity = visibleEnd.affinity(); |
| 1824 | 1828 |
| 1825 Node* anchorNode = visibleStart.anchorNode(); | 1829 Node* anchorNode = start.anchorNode(); |
| 1826 ASSERT(anchorNode); | 1830 ASSERT(anchorNode); |
| 1827 | 1831 |
| 1828 AXLayoutObject* anchorObject = nullptr; | 1832 AXLayoutObject* anchorObject = nullptr; |
| 1829 // Find the closest node that has a corresponding AXObject. | 1833 // Find the closest node that has a corresponding AXObject. |
| 1830 // This is because some nodes may be aria hidden or might not even have | 1834 // This is because some nodes may be aria hidden or might not even have |
| 1831 // a layout object if they are part of the shadow DOM. | 1835 // a layout object if they are part of the shadow DOM. |
| 1832 while (anchorNode) { | 1836 while (anchorNode) { |
| 1833 anchorObject = getUnignoredObjectFromNode(*anchorNode); | 1837 anchorObject = getUnignoredObjectFromNode(*anchorNode); |
| 1834 if (anchorObject) | 1838 if (anchorObject) |
| 1835 break; | 1839 break; |
| 1836 | 1840 |
| 1837 if (anchorNode->nextSibling()) | 1841 if (anchorNode->nextSibling()) |
| 1838 anchorNode = anchorNode->nextSibling(); | 1842 anchorNode = anchorNode->nextSibling(); |
| 1839 else | 1843 else |
| 1840 anchorNode = anchorNode->parentNode(); | 1844 anchorNode = anchorNode->parentNode(); |
| 1841 } | 1845 } |
| 1842 | 1846 |
| 1843 Node* focusNode = visibleEnd.anchorNode(); | 1847 Node* focusNode = end.anchorNode(); |
| 1844 ASSERT(focusNode); | 1848 ASSERT(focusNode); |
| 1845 | 1849 |
| 1846 AXLayoutObject* focusObject = nullptr; | 1850 AXLayoutObject* focusObject = nullptr; |
| 1847 while (focusNode) { | 1851 while (focusNode) { |
| 1848 focusObject = getUnignoredObjectFromNode(*focusNode); | 1852 focusObject = getUnignoredObjectFromNode(*focusNode); |
| 1849 if (focusObject) | 1853 if (focusObject) |
| 1850 break; | 1854 break; |
| 1851 | 1855 |
| 1852 if (focusNode->previousSibling()) | 1856 if (focusNode->previousSibling()) |
| 1853 focusNode = focusNode->previousSibling(); | 1857 focusNode = focusNode->previousSibling(); |
| 1854 else | 1858 else |
| 1855 focusNode = focusNode->parentNode(); | 1859 focusNode = focusNode->parentNode(); |
| 1856 } | 1860 } |
| 1857 | 1861 |
| 1858 if (!anchorObject || !focusObject) | 1862 if (!anchorObject || !focusObject) |
| 1859 return AXRange(); | 1863 return AXRange(); |
| 1860 | 1864 |
| 1861 int anchorOffset = anchorObject->indexForVisiblePosition( | 1865 int anchorOffset = anchorObject->indexForVisiblePosition(visibleStart); |
| 1862 selection.visibleStart()); | |
| 1863 ASSERT(anchorOffset >= 0); | 1866 ASSERT(anchorOffset >= 0); |
| 1864 int focusOffset = focusObject->indexForVisiblePosition( | 1867 int focusOffset = focusObject->indexForVisiblePosition(visibleEnd); |
| 1865 selection.visibleEnd()); | |
| 1866 ASSERT(focusOffset >= 0); | 1868 ASSERT(focusOffset >= 0); |
| 1867 return AXRange( | 1869 return AXRange(anchorObject, anchorOffset, startAffinity, |
| 1868 anchorObject, anchorOffset, | 1870 focusObject, focusOffset, endAffinity); |
| 1869 focusObject, focusOffset); | |
| 1870 } | 1871 } |
| 1871 | 1872 |
| 1872 // Gets only the start and end offsets of the selection computed using the | 1873 // Gets only the start and end offsets of the selection computed using the |
| 1873 // current object as the starting point. Returns a null selection if there is | 1874 // current object as the starting point. Returns a null selection if there is |
| 1874 // no selection in the subtree rooted at this object. | 1875 // no selection in the subtree rooted at this object. |
| 1875 AXObject::AXRange AXLayoutObject::selectionUnderObject() const | 1876 AXObject::AXRange AXLayoutObject::selectionUnderObject() const |
| 1876 { | 1877 { |
| 1877 AXRange textSelection = textControlSelection(); | 1878 AXRange textSelection = textControlSelection(); |
| 1878 if (textSelection.isValid()) | 1879 if (textSelection.isValid()) |
| 1879 return textSelection; | 1880 return textSelection; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 layout = focusedElement->layoutObject(); | 1917 layout = focusedElement->layoutObject(); |
| 1917 } | 1918 } |
| 1918 | 1919 |
| 1919 if (!layout) | 1920 if (!layout) |
| 1920 return AXRange(); | 1921 return AXRange(); |
| 1921 | 1922 |
| 1922 AXObject* axObject = axObjectCache().getOrCreate(layout); | 1923 AXObject* axObject = axObjectCache().getOrCreate(layout); |
| 1923 if (!axObject || !axObject->isAXLayoutObject()) | 1924 if (!axObject || !axObject->isAXLayoutObject()) |
| 1924 return AXRange(); | 1925 return AXRange(); |
| 1925 | 1926 |
| 1927 VisibleSelection selection = layout->frame()->selection().selection(); |
| 1926 HTMLTextFormControlElement* textControl = toLayoutTextControl( | 1928 HTMLTextFormControlElement* textControl = toLayoutTextControl( |
| 1927 layout)->textFormControlElement(); | 1929 layout)->textFormControlElement(); |
| 1928 ASSERT(textControl); | 1930 ASSERT(textControl); |
| 1929 int start = textControl->selectionStart(); | 1931 int start = textControl->selectionStart(); |
| 1930 int end = textControl->selectionEnd(); | 1932 int end = textControl->selectionEnd(); |
| 1931 return AXRange(axObject, start, axObject, end); | 1933 |
| 1934 return AXRange(axObject, start, selection.visibleStart().affinity(), |
| 1935 axObject, end, selection.visibleEnd().affinity()); |
| 1932 } | 1936 } |
| 1933 | 1937 |
| 1934 int AXLayoutObject::indexForVisiblePosition(const VisiblePosition& position) con
st | 1938 int AXLayoutObject::indexForVisiblePosition(const VisiblePosition& position) con
st |
| 1935 { | 1939 { |
| 1936 if (getLayoutObject() && getLayoutObject()->isTextControl()) { | 1940 if (getLayoutObject() && getLayoutObject()->isTextControl()) { |
| 1937 HTMLTextFormControlElement* textControl = toLayoutTextControl( | 1941 HTMLTextFormControlElement* textControl = toLayoutTextControl( |
| 1938 getLayoutObject())->textFormControlElement(); | 1942 getLayoutObject())->textFormControlElement(); |
| 1939 return textControl->indexForVisiblePosition(position); | 1943 return textControl->indexForVisiblePosition(position); |
| 1940 } | 1944 } |
| 1941 | 1945 |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2570 result.unite(labelRect); | 2574 result.unite(labelRect); |
| 2571 } | 2575 } |
| 2572 } | 2576 } |
| 2573 } | 2577 } |
| 2574 } | 2578 } |
| 2575 | 2579 |
| 2576 return result; | 2580 return result; |
| 2577 } | 2581 } |
| 2578 | 2582 |
| 2579 } // namespace blink | 2583 } // namespace blink |
| OLD | NEW |