Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: Source/modules/accessibility/AXLayoutObject.cpp

Issue 1086253002: Revert of Made content editables report the caret and text selection by treating them as text controls. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (m_layoutObject->isTextControl()) { 1593 AccessibilityRole ariaRole = ariaRoleAttribute();
1594 if (isNativeTextControl() && ariaRole == UnknownRole && m_layoutObject->isTe xtControl()) {
1594 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb ject)->textFormControlElement(); 1595 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb ject)->textFormControlElement();
1595 return PlainTextRange(textControl->selectionStart(), textControl->select ionEnd() - textControl->selectionStart()); 1596 return PlainTextRange(textControl->selectionStart(), textControl->select ionEnd() - textControl->selectionStart());
1596 } 1597 }
1597 1598
1598 return visibleSelectionUnderObject(); 1599 if (ariaRole == UnknownRole)
1600 return PlainTextRange();
1601
1602 return ariaSelectedTextRange();
1599 } 1603 }
1600 1604
1601 VisibleSelection AXLayoutObject::selection() const 1605 VisibleSelection AXLayoutObject::selection() const
1602 { 1606 {
1603 return m_layoutObject->frame()->selection().selection(); 1607 return m_layoutObject->frame()->selection().selection();
1604 } 1608 }
1605 1609
1606 // 1610 //
1607 // Modify or take an action on an object. 1611 // Modify or take an action on an object.
1608 // 1612 //
1609 1613
1610 void AXLayoutObject::setSelectedTextRange(const PlainTextRange& range) 1614 void AXLayoutObject::setSelectedTextRange(const PlainTextRange& range)
1611 { 1615 {
1612 if (m_layoutObject->isTextControl()) { 1616 if (isNativeTextControl() && m_layoutObject->isTextControl()) {
1613 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb ject)->textFormControlElement(); 1617 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb ject)->textFormControlElement();
1614 textControl->setSelectionRange(range.start, range.start + range.length, SelectionHasNoDirection, NotDispatchSelectEvent); 1618 textControl->setSelectionRange(range.start, range.start + range.length, SelectionHasNoDirection, NotDispatchSelectEvent);
1615 return; 1619 return;
1616 } 1620 }
1617 1621
1618 Document& document = m_layoutObject->document(); 1622 Document& document = m_layoutObject->document();
1619 LocalFrame* frame = document.frame(); 1623 LocalFrame* frame = document.frame();
1620 if (!frame) 1624 if (!frame)
1621 return; 1625 return;
1622 Node* node = m_layoutObject->node(); 1626 Node* node = m_layoutObject->node();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 return indexForVisiblePosition(position); 1743 return indexForVisiblePosition(position);
1740 1744
1741 return -1; 1745 return -1;
1742 } 1746 }
1743 1747
1744 VisiblePosition AXLayoutObject::visiblePositionForIndex(int index) const 1748 VisiblePosition AXLayoutObject::visiblePositionForIndex(int index) const
1745 { 1749 {
1746 if (!m_layoutObject) 1750 if (!m_layoutObject)
1747 return VisiblePosition(); 1751 return VisiblePosition();
1748 1752
1749 if (m_layoutObject->isTextControl()) 1753 if (isNativeTextControl() && m_layoutObject->isTextControl())
1750 return toLayoutTextControl(m_layoutObject)->textFormControlElement()->vi siblePositionForIndex(index); 1754 return toLayoutTextControl(m_layoutObject)->textFormControlElement()->vi siblePositionForIndex(index);
1751 1755
1752 if (!allowsTextRanges() && !m_layoutObject->isText()) 1756 if (!allowsTextRanges() && !m_layoutObject->isText())
1753 return VisiblePosition(); 1757 return VisiblePosition();
1754 1758
1755 Node* node = m_layoutObject->node(); 1759 Node* node = m_layoutObject->node();
1756 if (!node) 1760 if (!node)
1757 return VisiblePosition(); 1761 return VisiblePosition();
1758 1762
1759 if (index <= 0) 1763 if (index <= 0)
1760 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM); 1764 return VisiblePosition(firstPositionInOrBeforeNode(node), DOWNSTREAM);
1761 1765
1762 Position start, end; 1766 Position start, end;
1763 bool selected = Range::selectNodeContents(node, start, end); 1767 bool selected = Range::selectNodeContents(node, start, end);
1764 if (!selected) 1768 if (!selected)
1765 return VisiblePosition(); 1769 return VisiblePosition();
1766 1770
1767 CharacterIterator it(start, end); 1771 CharacterIterator it(start, end);
1768 it.advance(index - 1); 1772 it.advance(index - 1);
1769 return VisiblePosition(Position(it.currentContainer(), it.endOffset(), Posit ion::PositionIsOffsetInAnchor), UPSTREAM); 1773 return VisiblePosition(Position(it.currentContainer(), it.endOffset(), Posit ion::PositionIsOffsetInAnchor), UPSTREAM);
1770 } 1774 }
1771 1775
1772 int AXLayoutObject::indexForVisiblePosition(const VisiblePosition& pos) const 1776 int AXLayoutObject::indexForVisiblePosition(const VisiblePosition& pos) const
1773 { 1777 {
1774 if (m_layoutObject->isTextControl()) { 1778 if (isNativeTextControl() && m_layoutObject->isTextControl()) {
1775 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb ject)->textFormControlElement(); 1779 HTMLTextFormControlElement* textControl = toLayoutTextControl(m_layoutOb ject)->textFormControlElement();
1776 return textControl->indexForVisiblePosition(pos); 1780 return textControl->indexForVisiblePosition(pos);
1777 } 1781 }
1778 1782
1779 if (!isTextControl()) 1783 if (!isTextControl())
1780 return 0; 1784 return 0;
1781 1785
1782 Node* node = m_layoutObject->node(); 1786 Node* node = m_layoutObject->node();
1783 if (!node) 1787 if (!node)
1784 return 0; 1788 return 0;
1785 1789
1786 Position indexPosition = pos.deepEquivalent(); 1790 Position indexPosition = pos.deepEquivalent();
1787 if (indexPosition.isNull() 1791 if (indexPosition.isNull() || highestEditableRoot(indexPosition, HasEditable AXRole) != node)
1788 || (highestEditableRoot(indexPosition) != node
1789 && highestEditableRoot(indexPosition, HasEditableAXRole) != node))
1790 return 0; 1792 return 0;
1791 1793
1792 RefPtrWillBeRawPtr<Range> range = Range::create(m_layoutObject->document()); 1794 RefPtrWillBeRawPtr<Range> range = Range::create(m_layoutObject->document());
1793 range->setStart(node, 0, IGNORE_EXCEPTION); 1795 range->setStart(node, 0, IGNORE_EXCEPTION);
1794 range->setEnd(indexPosition, IGNORE_EXCEPTION); 1796 range->setEnd(indexPosition, IGNORE_EXCEPTION);
1795 1797
1796 return TextIterator::rangeLength(range->startPosition(), range->endPosition( )); 1798 return TextIterator::rangeLength(range->startPosition(), range->endPosition( ));
1797 } 1799 }
1798 1800
1799 void AXLayoutObject::addInlineTextBoxChildren(bool force) 1801 void AXLayoutObject::addInlineTextBoxChildren(bool force)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 for (const auto& child : children()) { 1870 for (const auto& child : children()) {
1869 // Every child should have aria-role option, and if so, check for select ed attribute/state. 1871 // Every child should have aria-role option, and if so, check for select ed attribute/state.
1870 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRo le) { 1872 if (child->isSelected() && child->ariaRoleAttribute() == ListBoxOptionRo le) {
1871 result.append(child); 1873 result.append(child);
1872 if (!isMulti) 1874 if (!isMulti)
1873 return; 1875 return;
1874 } 1876 }
1875 } 1877 }
1876 } 1878 }
1877 1879
1878 AXObject::PlainTextRange AXLayoutObject::visibleSelectionUnderObject() const 1880 AXObject::PlainTextRange AXLayoutObject::ariaSelectedTextRange() const
1879 { 1881 {
1880 Node* node = m_layoutObject->node(); 1882 Node* node = m_layoutObject->node();
1881 if (!node) 1883 if (!node)
1882 return PlainTextRange(); 1884 return PlainTextRange();
1883 1885
1884 VisibleSelection visibleSelection = selection(); 1886 VisibleSelection visibleSelection = selection();
1885 RefPtrWillBeRawPtr<Range> currentSelectionRange = visibleSelection.toNormali zedRange(); 1887 RefPtrWillBeRawPtr<Range> currentSelectionRange = visibleSelection.toNormali zedRange();
1886 if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, I GNORE_EXCEPTION)) 1888 if (!currentSelectionRange || !currentSelectionRange->intersectsNode(node, I GNORE_EXCEPTION))
1887 return PlainTextRange(); 1889 return PlainTextRange();
1888 1890
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
2266 if (label && label->layoutObject()) { 2268 if (label && label->layoutObject()) {
2267 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR ect(); 2269 LayoutRect labelRect = axObjectCache()->getOrCreate(label)->elementR ect();
2268 result.unite(labelRect); 2270 result.unite(labelRect);
2269 } 2271 }
2270 } 2272 }
2271 2273
2272 return result; 2274 return result;
2273 } 2275 }
2274 2276
2275 } // namespace blink 2277 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/accessibility/AXLayoutObject.h ('k') | Source/modules/accessibility/AXNodeObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698