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 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1583 | 1583 |
1584 // | 1584 // |
1585 // Selected text. | 1585 // Selected text. |
1586 // | 1586 // |
1587 | 1587 |
1588 AXObject::PlainTextRange AXLayoutObject::selectedTextRange() const | 1588 AXObject::PlainTextRange AXLayoutObject::selectedTextRange() const |
1589 { | 1589 { |
1590 if (!isTextControl()) | 1590 if (!isTextControl()) |
1591 return PlainTextRange(); | 1591 return PlainTextRange(); |
1592 | 1592 |
1593 AccessibilityRole ariaRole = ariaRoleAttribute(); | 1593 if (m_layoutObject->isTextControl()) { |
1594 if (isNativeTextControl() && ariaRole == UnknownRole && m_layoutObject->isTe
xtControl()) { | |
1595 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb
ject)->textFormControlElement(); | 1594 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb
ject)->textFormControlElement(); |
1596 return PlainTextRange(textControl->selectionStart(), textControl->select
ionEnd() - textControl->selectionStart()); | 1595 return PlainTextRange(textControl->selectionStart(), textControl->select
ionEnd() - textControl->selectionStart()); |
1597 } | 1596 } |
1598 | 1597 |
1599 if (ariaRole == UnknownRole) | 1598 return visibleSelectionUnderObject(); |
1600 return PlainTextRange(); | |
1601 | |
1602 return ariaSelectedTextRange(); | |
1603 } | 1599 } |
1604 | 1600 |
1605 VisibleSelection AXLayoutObject::selection() const | 1601 VisibleSelection AXLayoutObject::selection() const |
1606 { | 1602 { |
1607 return m_layoutObject->frame()->selection().selection(); | 1603 return m_layoutObject->frame()->selection().selection(); |
1608 } | 1604 } |
1609 | 1605 |
1610 // | 1606 // |
1611 // Modify or take an action on an object. | 1607 // Modify or take an action on an object. |
1612 // | 1608 // |
1613 | 1609 |
1614 void AXLayoutObject::setSelectedTextRange(const PlainTextRange& range) | 1610 void AXLayoutObject::setSelectedTextRange(const PlainTextRange& range) |
1615 { | 1611 { |
1616 if (isNativeTextControl() && m_layoutObject->isTextControl()) { | 1612 if (m_layoutObject->isTextControl()) { |
1617 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb
ject)->textFormControlElement(); | 1613 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb
ject)->textFormControlElement(); |
1618 textControl->setSelectionRange(range.start, range.start + range.length,
SelectionHasNoDirection, NotDispatchSelectEvent); | 1614 textControl->setSelectionRange(range.start, range.start + range.length,
SelectionHasNoDirection, NotDispatchSelectEvent); |
1619 return; | 1615 return; |
1620 } | 1616 } |
1621 | 1617 |
1622 Document& document = m_layoutObject->document(); | 1618 Document& document = m_layoutObject->document(); |
1623 LocalFrame* frame = document.frame(); | 1619 LocalFrame* frame = document.frame(); |
1624 if (!frame) | 1620 if (!frame) |
1625 return; | 1621 return; |
1626 Node* node = m_layoutObject->node(); | 1622 Node* node = m_layoutObject->node(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 return indexForVisiblePosition(position); | 1739 return indexForVisiblePosition(position); |
1744 | 1740 |
1745 return -1; | 1741 return -1; |
1746 } | 1742 } |
1747 | 1743 |
1748 VisiblePosition AXLayoutObject::visiblePositionForIndex(int index) const | 1744 VisiblePosition AXLayoutObject::visiblePositionForIndex(int index) const |
1749 { | 1745 { |
1750 if (!m_layoutObject) | 1746 if (!m_layoutObject) |
1751 return VisiblePosition(); | 1747 return VisiblePosition(); |
1752 | 1748 |
1753 if (isNativeTextControl() && m_layoutObject->isTextControl()) | 1749 if (m_layoutObject->isTextControl()) |
1754 return toLayoutTextControl(m_layoutObject)->textFormControlElement()->vi
siblePositionForIndex(index); | 1750 return toLayoutTextControl(m_layoutObject)->textFormControlElement()->vi
siblePositionForIndex(index); |
1755 | 1751 |
1756 if (!allowsTextRanges() && !m_layoutObject->isText()) | 1752 if (!allowsTextRanges() && !m_layoutObject->isText()) |
1757 return VisiblePosition(); | 1753 return VisiblePosition(); |
1758 | 1754 |
1759 Node* node = m_layoutObject->node(); | 1755 Node* node = m_layoutObject->node(); |
1760 if (!node) | 1756 if (!node) |
1761 return VisiblePosition(); | 1757 return VisiblePosition(); |
1762 | 1758 |
1763 if (index <= 0) | 1759 if (index <= 0) |
1764 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM); | 1760 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM); |
1765 | 1761 |
1766 Position start, end; | 1762 Position start, end; |
1767 bool selected = Range::selectNodeContents(node, start, end); | 1763 bool selected = Range::selectNodeContents(node, start, end); |
1768 if (!selected) | 1764 if (!selected) |
1769 return VisiblePosition(); | 1765 return VisiblePosition(); |
1770 | 1766 |
1771 CharacterIterator it(start, end); | 1767 CharacterIterator it(start, end); |
1772 it.advance(index - 1); | 1768 it.advance(index - 1); |
1773 return VisiblePosition(Position(it.currentContainer(), it.endOffset(), Posit
ion::PositionIsOffsetInAnchor), UPSTREAM); | 1769 return VisiblePosition(Position(it.currentContainer(), it.endOffset(), Posit
ion::PositionIsOffsetInAnchor), UPSTREAM); |
1774 } | 1770 } |
1775 | 1771 |
1776 int AXLayoutObject::indexForVisiblePosition(const VisiblePosition& pos) const | 1772 int AXLayoutObject::indexForVisiblePosition(const VisiblePosition& pos) const |
1777 { | 1773 { |
1778 if (isNativeTextControl() && m_layoutObject->isTextControl()) { | 1774 if (m_layoutObject->isTextControl()) { |
1779 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb
ject)->textFormControlElement(); | 1775 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb
ject)->textFormControlElement(); |
1780 return textControl->indexForVisiblePosition(pos); | 1776 return textControl->indexForVisiblePosition(pos); |
1781 } | 1777 } |
1782 | 1778 |
1783 if (!isTextControl()) | 1779 if (!isTextControl()) |
1784 return 0; | 1780 return 0; |
1785 | 1781 |
1786 Node* node = m_layoutObject->node(); | 1782 Node* node = m_layoutObject->node(); |
1787 if (!node) | 1783 if (!node) |
1788 return 0; | 1784 return 0; |
1789 | 1785 |
1790 Position indexPosition = pos.deepEquivalent(); | 1786 Position indexPosition = pos.deepEquivalent(); |
1791 if (indexPosition.isNull() || highestEditableRoot(indexPosition, HasEditable
AXRole) != node) | 1787 if (indexPosition.isNull() |
| 1788 || (highestEditableRoot(indexPosition) != node |
| 1789 && highestEditableRoot(indexPosition, HasEditableAXRole) != node)) |
1792 return 0; | 1790 return 0; |
1793 | 1791 |
1794 RefPtrWillBeRawPtr<Range> range = Range::create(m_layoutObject->document()); | 1792 RefPtrWillBeRawPtr<Range> range = Range::create(m_layoutObject->document()); |
1795 range->setStart(node, 0, IGNORE_EXCEPTION); | 1793 range->setStart(node, 0, IGNORE_EXCEPTION); |
1796 range->setEnd(indexPosition, IGNORE_EXCEPTION); | 1794 range->setEnd(indexPosition, IGNORE_EXCEPTION); |
1797 | 1795 |
1798 return TextIterator::rangeLength(range->startPosition(), range->endPosition(
)); | 1796 return TextIterator::rangeLength(range->startPosition(), range->endPosition(
)); |
1799 } | 1797 } |
1800 | 1798 |
1801 void AXLayoutObject::addInlineTextBoxChildren(bool force) | 1799 void AXLayoutObject::addInlineTextBoxChildren(bool force) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 for (const auto& child : children()) { | 1868 for (const auto& child : children()) { |
1871 // Every child should have aria-role option, and if so, check for select
ed attribute/state. | 1869 // Every child should have aria-role option, and if so, check for select
ed attribute/state. |
1872 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRo
le) { | 1870 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRo
le) { |
1873 result.append(child); | 1871 result.append(child); |
1874 if (!isMulti) | 1872 if (!isMulti) |
1875 return; | 1873 return; |
1876 } | 1874 } |
1877 } | 1875 } |
1878 } | 1876 } |
1879 | 1877 |
1880 AXObject::PlainTextRange AXLayoutObject::ariaSelectedTextRange() const | 1878 AXObject::PlainTextRange AXLayoutObject::visibleSelectionUnderObject() const |
1881 { | 1879 { |
1882 Node* node = m_layoutObject->node(); | 1880 Node* node = m_layoutObject->node(); |
1883 if (!node) | 1881 if (!node) |
1884 return PlainTextRange(); | 1882 return PlainTextRange(); |
1885 | 1883 |
1886 VisibleSelection visibleSelection = selection(); | 1884 VisibleSelection visibleSelection = selection(); |
1887 RefPtrWillBeRawPtr<Range> currentSelectionRange = visibleSelection.toNormali
zedRange(); | 1885 RefPtrWillBeRawPtr<Range> currentSelectionRange = visibleSelection.toNormali
zedRange(); |
1888 if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, I
GNORE_EXCEPTION)) | 1886 if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, I
GNORE_EXCEPTION)) |
1889 return PlainTextRange(); | 1887 return PlainTextRange(); |
1890 | 1888 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 if (label && label->layoutObject()) { | 2266 if (label && label->layoutObject()) { |
2269 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR
ect(); | 2267 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR
ect(); |
2270 result.unite(labelRect); | 2268 result.unite(labelRect); |
2271 } | 2269 } |
2272 } | 2270 } |
2273 | 2271 |
2274 return result; | 2272 return result; |
2275 } | 2273 } |
2276 | 2274 |
2277 } // namespace blink | 2275 } // namespace blink |
OLD | NEW |