Chromium Code Reviews| 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 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1827 } | 1827 } |
| 1828 | 1828 |
| 1829 Widget* AXLayoutObject::widgetForAttachmentView() const | 1829 Widget* AXLayoutObject::widgetForAttachmentView() const |
| 1830 { | 1830 { |
| 1831 if (!isAttachment()) | 1831 if (!isAttachment()) |
| 1832 return 0; | 1832 return 0; |
| 1833 return toLayoutPart(m_layoutObject)->widget(); | 1833 return toLayoutPart(m_layoutObject)->widget(); |
| 1834 } | 1834 } |
| 1835 | 1835 |
| 1836 // | 1836 // |
| 1837 // Selected text. | 1837 // Get the current selection. |
| 1838 // | 1838 // |
| 1839 | 1839 |
| 1840 AXObject::PlainTextRange AXLayoutObject::selectedTextRange() const | 1840 AXObject::AXRange AXLayoutObject::selection() const |
| 1841 { | 1841 { |
| 1842 if (!isTextControl()) | 1842 AXRange textSelection = textControlSelection(); |
| 1843 return PlainTextRange(); | 1843 if (!textSelection.isNull()) |
| 1844 return textSelection; | |
| 1844 | 1845 |
| 1845 if (m_layoutObject->isTextControl()) { | 1846 // Find the closest parent that has a node. |
|
dmazzoni
2015/06/22 17:13:35
I don't think you need to find a parent with a nod
| |
| 1846 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb ject)->textFormControlElement(); | 1847 const AXObject* axObject = this; |
| 1847 return PlainTextRange(textControl->selectionStart(), textControl->select ionEnd() - textControl->selectionStart()); | 1848 while (axObject |
| 1849 && (!axObject->isAXLayoutObject() || !axObject->node() | |
| 1850 || axObject->accessibilityIsIgnored())) | |
| 1851 axObject = axObject->parentObject(); | |
| 1852 if (!axObject) | |
| 1853 return AXRange(); | |
| 1854 | |
| 1855 VisibleSelection selection = axObject->visibleSelection(); | |
| 1856 RefPtrWillBeRawPtr<Range> selectionRange = selection.firstRange(); | |
| 1857 if (!selectionRange) | |
| 1858 return AXRange(); | |
| 1859 | |
| 1860 Node* anchorNode = selectionRange->startContainer(); | |
| 1861 ASSERT(anchorNode); | |
| 1862 RefPtrWillBeRawPtr<AXObject> anchorObject = axObjectCache()->get(anchorNode) ; | |
| 1863 Node* focusNode = selectionRange->endContainer(); | |
| 1864 ASSERT(focusNode); | |
| 1865 RefPtrWillBeRawPtr<AXObject> focusObject = axObjectCache()->get(focusNode); | |
| 1866 | |
| 1867 if (!anchorObject || !focusObject) | |
|
dmazzoni
2015/06/22 17:13:35
Here's where you need to walk up the tree. anchorN
| |
| 1868 return AXRange(); | |
| 1869 | |
| 1870 int anchorOffset = selectionRange->startOffset(); | |
| 1871 ASSERT(anchorOffset >= 0); | |
| 1872 int focusOffset = selectionRange->endOffset(); | |
| 1873 ASSERT(focusOffset >= 0); | |
| 1874 | |
| 1875 return AXRange( | |
| 1876 anchorObject, anchorOffset, | |
| 1877 focusObject, focusOffset); | |
| 1878 } | |
| 1879 | |
| 1880 // Gets only the start and end offsets of the selection computed using the | |
| 1881 // current object as the starting point. Returns a null selection if there is | |
| 1882 // no selection in the subtree rooted at this object. | |
| 1883 AXObject::AXRange AXLayoutObject::selectionUnderObject() const | |
| 1884 { | |
| 1885 AXRange textSelection = textControlSelection(); | |
| 1886 if (!textSelection.isNull()) | |
| 1887 return textSelection; | |
| 1888 | |
| 1889 if (!node()) | |
| 1890 return AXRange(); | |
| 1891 | |
| 1892 VisibleSelection selection = visibleSelection(); | |
| 1893 RefPtrWillBeRawPtr<Range> selectionRange = selection.firstRange(); | |
| 1894 if (!selectionRange | |
| 1895 || !selectionRange->intersectsNode(node(), IGNORE_EXCEPTION)) | |
|
dmazzoni
2015/06/22 17:13:35
It looks like selectionUnderObject returns a selec
| |
| 1896 return AXRange(); | |
| 1897 | |
| 1898 int start = indexForVisiblePosition(selection.visibleStart()); | |
| 1899 int end = indexForVisiblePosition(selection.visibleEnd()); | |
| 1900 | |
| 1901 return AXRange(start, end); | |
| 1902 } | |
| 1903 | |
| 1904 AXObject::AXRange AXLayoutObject::textControlSelection() const | |
| 1905 { | |
| 1906 if (!layoutObject()) | |
| 1907 return AXRange(); | |
| 1908 | |
| 1909 Node* node = isHTMLTextFormControlElement(node()) ? node() : | |
| 1910 document()->focusedElement(); | |
| 1911 | |
| 1912 if (!node) | |
| 1913 return AXRange(); | |
| 1914 | |
| 1915 AXObject axObject = axObjectCache()->get(node); | |
| 1916 if (!axObject) | |
| 1917 return AXRange(); | |
| 1918 | |
| 1919 HTMLTextFormControlElement* textControl = toHTMLTextFormControlElement(node) ; | |
| 1920 int start = textControl->selectionStart(); | |
| 1921 int end = textControl->selectionEnd(); | |
| 1922 return AXRange(axObject, start, axObject, end); | |
| 1923 } | |
| 1924 | |
| 1925 VisibleSelection AXLayoutObject::visibleSelection() const | |
|
dmazzoni
2015/06/22 17:13:35
I'd just delete this helper, because any function
| |
| 1926 { | |
| 1927 return layoutObject() ? | |
| 1928 layoutObject()->frame()->selection().selection() : VisibleSelection(); | |
| 1929 } | |
| 1930 | |
| 1931 int AXLayoutObject::indexForVisiblePosition(const VisiblePosition& position) con st | |
| 1932 { | |
| 1933 if (layoutObject() && layoutObject()->isTextControl()) { | |
| 1934 HTMLTextFormControlElement* textControl = toLayoutTextControl( | |
| 1935 layoutObject())->textFormControlElement(); | |
| 1936 return textControl->indexForVisiblePosition(position); | |
| 1848 } | 1937 } |
| 1849 | 1938 |
| 1850 return visibleSelectionUnderObject(); | 1939 if (!node()) |
| 1851 } | 1940 return 0; |
| 1852 | 1941 |
| 1853 VisibleSelection AXLayoutObject::selection() const | 1942 Position indexPosition = position.deepEquivalent(); |
| 1854 { | 1943 if (indexPosition.isNull()) |
| 1855 return m_layoutObject->frame()->selection().selection(); | 1944 return 0; |
| 1945 | |
| 1946 RefPtrWillBeRawPtr<Range> range = Range::create(*document()); | |
| 1947 range->setStart(node(), 0, IGNORE_EXCEPTION); | |
| 1948 range->setEnd(indexPosition, IGNORE_EXCEPTION); | |
| 1949 | |
| 1950 return TextIterator::rangeLength(range->startPosition(), range->endPosition( )); | |
| 1856 } | 1951 } |
| 1857 | 1952 |
| 1858 // | 1953 // |
| 1859 // Modify or take an action on an object. | 1954 // Modify or take an action on an object. |
| 1860 // | 1955 // |
| 1861 | 1956 |
| 1862 void AXLayoutObject::setSelectedTextRange(const PlainTextRange& range) | 1957 void AXLayoutObject::setSelection(const AXRange& selection) |
| 1863 { | 1958 { |
| 1864 if (m_layoutObject->isTextControl()) { | 1959 if (selection.isNull()) |
| 1865 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb ject)->textFormControlElement(); | 1960 return; |
| 1866 textControl->setSelectionRange(range.start, range.start + range.length, SelectionHasNoDirection, NotDispatchSelectEvent); | 1961 |
| 1962 AXObject* anchorObject = this; | |
| 1963 if (selection.anchorObject | |
| 1964 && axObjectCache()->isIDinUse(selection.anchorObject->axObjectID())) | |
|
dmazzoni
2015/06/22 17:13:35
Rather than isIDinUse, just check selection.anchor
| |
| 1965 anchorObject = selection.anchorObject.get(); | |
| 1966 | |
| 1967 AXObject* focusObject = this; | |
| 1968 if (selection.focusObject | |
| 1969 && axObjectCache()->isIDinUse(selection.focusObject->axObjectID())) | |
| 1970 focusObject = selection.focusObject.get(); | |
| 1971 | |
| 1972 if (anchorObject == this && anchorObject == focusObject | |
| 1973 && layoutObject() && layoutObject()->isTextControl()) { | |
| 1974 HTMLTextFormControlElement* textControl = toLayoutTextControl( | |
| 1975 layoutObject())->textFormControlElement(); | |
| 1976 textControl->setSelectionRange(selection.anchorOffset, selection.focusOf fset, | |
| 1977 SelectionHasNoDirection, NotDispatchSelectEvent); | |
| 1867 return; | 1978 return; |
| 1868 } | 1979 } |
| 1869 | 1980 |
| 1870 Document& document = m_layoutObject->document(); | 1981 Node* anchorNode = anchorObject->node(); |
|
dmazzoni
2015/06/22 17:13:35
Need to walk up the tree here - someone might want
| |
| 1871 LocalFrame* frame = document.frame(); | 1982 Node* focusNode = focusObject->node(); |
| 1983 if (!anchorNode || !focusNode) | |
| 1984 return; | |
| 1985 | |
| 1986 Document* objectDocument = document(); | |
| 1987 ASSERT(objectDocument); | |
| 1988 LocalFrame* frame = objectDocument->frame(); | |
| 1872 if (!frame) | 1989 if (!frame) |
| 1873 return; | 1990 return; |
| 1874 Node* node = m_layoutObject->node(); | 1991 |
| 1875 frame->selection().setSelection(VisibleSelection(Position(node, range.start, Position::PositionIsOffsetInAnchor), | 1992 frame->selection().setSelection(VisibleSelection(Position(anchorNode, |
| 1876 Position(node, range.start + range.length, Position::PositionIsOffsetInA nchor), DOWNSTREAM)); | 1993 selection.anchorOffset, Position::PositionIsOffsetInAnchor), |
| 1994 Position(focusNode, selection.focusOffset, | |
| 1995 Position::PositionIsOffsetInAnchor), DOWNSTREAM)); | |
| 1877 } | 1996 } |
| 1878 | 1997 |
| 1879 void AXLayoutObject::setValue(const String& string) | 1998 void AXLayoutObject::setValue(const String& string) |
| 1880 { | 1999 { |
| 1881 if (!node() || !node()->isElementNode()) | 2000 if (!node() || !node()->isElementNode()) |
| 1882 return; | 2001 return; |
| 1883 if (!m_layoutObject || !m_layoutObject->isBoxModelObject()) | 2002 if (!m_layoutObject || !m_layoutObject->isBoxModelObject()) |
| 1884 return; | 2003 return; |
| 1885 | 2004 |
| 1886 LayoutBoxModelObject* layoutObject = toLayoutBoxModelObject(m_layoutObject); | 2005 LayoutBoxModelObject* layoutObject = toLayoutBoxModelObject(m_layoutObject); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2001 Position start, end; | 2120 Position start, end; |
| 2002 bool selected = Range::selectNodeContents(node, start, end); | 2121 bool selected = Range::selectNodeContents(node, start, end); |
| 2003 if (!selected) | 2122 if (!selected) |
| 2004 return VisiblePosition(); | 2123 return VisiblePosition(); |
| 2005 | 2124 |
| 2006 CharacterIterator it(start, end); | 2125 CharacterIterator it(start, end); |
| 2007 it.advance(index - 1); | 2126 it.advance(index - 1); |
| 2008 return VisiblePosition(Position(it.currentContainer(), it.endOffset(), Posit ion::PositionIsOffsetInAnchor), UPSTREAM); | 2127 return VisiblePosition(Position(it.currentContainer(), it.endOffset(), Posit ion::PositionIsOffsetInAnchor), UPSTREAM); |
| 2009 } | 2128 } |
| 2010 | 2129 |
| 2011 int AXLayoutObject::indexForVisiblePosition(const VisiblePosition& pos) const | |
| 2012 { | |
| 2013 if (m_layoutObject->isTextControl()) { | |
| 2014 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb ject)->textFormControlElement(); | |
| 2015 return textControl->indexForVisiblePosition(pos); | |
| 2016 } | |
| 2017 | |
| 2018 if (!isTextControl()) | |
| 2019 return 0; | |
| 2020 | |
| 2021 Node* node = m_layoutObject->node(); | |
| 2022 if (!node) | |
| 2023 return 0; | |
| 2024 | |
| 2025 Position indexPosition = pos.deepEquivalent(); | |
| 2026 if (indexPosition.isNull() | |
| 2027 || (highestEditableRoot(indexPosition) != node | |
| 2028 && highestEditableRoot(indexPosition, HasEditableAXRole) != node)) | |
| 2029 return 0; | |
| 2030 | |
| 2031 RefPtrWillBeRawPtr<Range> range = Range::create(m_layoutObject->document()); | |
| 2032 range->setStart(node, 0, IGNORE_EXCEPTION); | |
| 2033 range->setEnd(indexPosition, IGNORE_EXCEPTION); | |
| 2034 | |
| 2035 return TextIterator::rangeLength(range->startPosition(), range->endPosition( )); | |
| 2036 } | |
| 2037 | |
| 2038 void AXLayoutObject::addInlineTextBoxChildren(bool force) | 2130 void AXLayoutObject::addInlineTextBoxChildren(bool force) |
| 2039 { | 2131 { |
| 2040 Settings* settings = document()->settings(); | 2132 Settings* settings = document()->settings(); |
| 2041 if (!force && (!settings || !settings->inlineTextBoxAccessibilityEnabled())) | 2133 if (!force && (!settings || !settings->inlineTextBoxAccessibilityEnabled())) |
| 2042 return; | 2134 return; |
| 2043 | 2135 |
| 2044 if (!layoutObject() || !layoutObject()->isText()) | 2136 if (!layoutObject() || !layoutObject()->isText()) |
| 2045 return; | 2137 return; |
| 2046 | 2138 |
| 2047 if (layoutObject()->needsLayout()) { | 2139 if (layoutObject()->needsLayout()) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2109 for (const auto& child : children()) { | 2201 for (const auto& child : children()) { |
| 2110 // Every child should have aria-role option, and if so, check for select ed attribute/state. | 2202 // Every child should have aria-role option, and if so, check for select ed attribute/state. |
| 2111 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRo le) { | 2203 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRo le) { |
| 2112 result.append(child); | 2204 result.append(child); |
| 2113 if (!isMulti) | 2205 if (!isMulti) |
| 2114 return; | 2206 return; |
| 2115 } | 2207 } |
| 2116 } | 2208 } |
| 2117 } | 2209 } |
| 2118 | 2210 |
| 2119 AXObject::PlainTextRange AXLayoutObject::visibleSelectionUnderObject() const | |
| 2120 { | |
| 2121 Node* node = m_layoutObject->node(); | |
| 2122 if (!node) | |
| 2123 return PlainTextRange(); | |
| 2124 | |
| 2125 VisibleSelection visibleSelection = selection(); | |
| 2126 RefPtrWillBeRawPtr<Range> currentSelectionRange = visibleSelection.toNormali zedRange(); | |
| 2127 if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, I GNORE_EXCEPTION)) | |
| 2128 return PlainTextRange(); | |
| 2129 | |
| 2130 int start = indexForVisiblePosition(visibleSelection.visibleStart()); | |
| 2131 int end = indexForVisiblePosition(visibleSelection.visibleEnd()); | |
| 2132 | |
| 2133 return PlainTextRange(start, end - start); | |
| 2134 } | |
| 2135 | |
| 2136 bool AXLayoutObject::nodeIsTextControl(const Node* node) const | 2211 bool AXLayoutObject::nodeIsTextControl(const Node* node) const |
| 2137 { | 2212 { |
| 2138 if (!node) | 2213 if (!node) |
| 2139 return false; | 2214 return false; |
| 2140 | 2215 |
| 2141 const AXObject* axObjectForNode = axObjectCache()->getOrCreate(const_cast<No de*>(node)); | 2216 const AXObject* axObjectForNode = axObjectCache()->getOrCreate(const_cast<No de*>(node)); |
| 2142 if (!axObjectForNode) | 2217 if (!axObjectForNode) |
| 2143 return false; | 2218 return false; |
| 2144 | 2219 |
| 2145 return axObjectForNode->isTextControl(); | 2220 return axObjectForNode->isTextControl(); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2507 if (label && label->layoutObject()) { | 2582 if (label && label->layoutObject()) { |
| 2508 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR ect(); | 2583 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR ect(); |
| 2509 result.unite(labelRect); | 2584 result.unite(labelRect); |
| 2510 } | 2585 } |
| 2511 } | 2586 } |
| 2512 | 2587 |
| 2513 return result; | 2588 return result; |
| 2514 } | 2589 } |
| 2515 | 2590 |
| 2516 } // namespace blink | 2591 } // namespace blink |
| OLD | NEW |