| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012, Google Inc. All rights reserved. | 2 * Copyright (C) 2012, Google 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 : AXObject(axObjectCache) | 63 : AXObject(axObjectCache) |
| 64 , m_ariaRole(UnknownRole) | 64 , m_ariaRole(UnknownRole) |
| 65 , m_childrenDirty(false) | 65 , m_childrenDirty(false) |
| 66 #if ENABLE(ASSERT) | 66 #if ENABLE(ASSERT) |
| 67 , m_initialized(false) | 67 , m_initialized(false) |
| 68 #endif | 68 #endif |
| 69 , m_node(node) | 69 , m_node(node) |
| 70 { | 70 { |
| 71 } | 71 } |
| 72 | 72 |
| 73 PassRefPtr<AXNodeObject> AXNodeObject::create(Node* node, AXObjectCacheImpl* axO
bjectCache) | 73 PassRefPtrWillBeRawPtr<AXNodeObject> AXNodeObject::create(Node* node, AXObjectCa
cheImpl* axObjectCache) |
| 74 { | 74 { |
| 75 return adoptRef(new AXNodeObject(node, axObjectCache)); | 75 return adoptRefWillBeNoop(new AXNodeObject(node, axObjectCache)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 AXNodeObject::~AXNodeObject() | 78 AXNodeObject::~AXNodeObject() |
| 79 { | 79 { |
| 80 ASSERT(isDetached()); | 80 ASSERT(isDetached()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // This function implements the ARIA accessible name as described by the Mozilla | 83 // This function implements the ARIA accessible name as described by the Mozilla |
| 84 // ARIA Implementer's Guide. | 84 // ARIA Implementer's Guide. |
| 85 static String accessibleNameForNode(Node* node) | 85 static String accessibleNameForNode(Node* node) |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 ASSERT(!m_initialized); | 729 ASSERT(!m_initialized); |
| 730 m_initialized = true; | 730 m_initialized = true; |
| 731 #endif | 731 #endif |
| 732 m_role = determineAccessibilityRole(); | 732 m_role = determineAccessibilityRole(); |
| 733 } | 733 } |
| 734 | 734 |
| 735 void AXNodeObject::detach() | 735 void AXNodeObject::detach() |
| 736 { | 736 { |
| 737 clearChildren(); | 737 clearChildren(); |
| 738 AXObject::detach(); | 738 AXObject::detach(); |
| 739 m_node = 0; | 739 m_node = nullptr; |
| 740 } | 740 } |
| 741 | 741 |
| 742 bool AXNodeObject::isAnchor() const | 742 bool AXNodeObject::isAnchor() const |
| 743 { | 743 { |
| 744 return !isNativeImage() && isLink(); | 744 return !isNativeImage() && isLink(); |
| 745 } | 745 } |
| 746 | 746 |
| 747 bool AXNodeObject::isControl() const | 747 bool AXNodeObject::isControl() const |
| 748 { | 748 { |
| 749 Node* node = this->node(); | 749 Node* node = this->node(); |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 if (node && node->isTextNode()) | 1563 if (node && node->isTextNode()) |
| 1564 return toText(node)->wholeText(); | 1564 return toText(node)->wholeText(); |
| 1565 | 1565 |
| 1566 StringBuilder builder; | 1566 StringBuilder builder; |
| 1567 AXObject* previous = nullptr; | 1567 AXObject* previous = nullptr; |
| 1568 for (AXObject* child = firstChild(); child; child = child->nextSibling()) { | 1568 for (AXObject* child = firstChild(); child; child = child->nextSibling()) { |
| 1569 if (!shouldUseAccessibilityObjectInnerText(child)) | 1569 if (!shouldUseAccessibilityObjectInnerText(child)) |
| 1570 continue; | 1570 continue; |
| 1571 | 1571 |
| 1572 if (child->isAXNodeObject()) { | 1572 if (child->isAXNodeObject()) { |
| 1573 Vector<AccessibilityText> textOrder; | 1573 WillBeHeapVector<OwnPtrWillBeMember<AccessibilityText>> textOrder; |
| 1574 toAXNodeObject(child)->alternativeText(textOrder); | 1574 toAXNodeObject(child)->alternativeText(textOrder); |
| 1575 if (textOrder.size() > 0) { | 1575 if (textOrder.size() > 0) { |
| 1576 builder.append(textOrder[0].text); | 1576 builder.append(textOrder[0]->text()); |
| 1577 if (mode == TextUnderElementAny) | 1577 if (mode == TextUnderElementAny) |
| 1578 break; | 1578 break; |
| 1579 continue; | 1579 continue; |
| 1580 } | 1580 } |
| 1581 } | 1581 } |
| 1582 | 1582 |
| 1583 // If we're going between two layoutObjects that are in separate LayoutB
oxes, add | 1583 // If we're going between two layoutObjects that are in separate LayoutB
oxes, add |
| 1584 // whitespace if it wasn't there already. Intuitively if you have | 1584 // whitespace if it wasn't there already. Intuitively if you have |
| 1585 // <span>Hello</span><span>World</span>, those are part of the same Layo
utBox | 1585 // <span>Hello</span><span>World</span>, those are part of the same Layo
utBox |
| 1586 // so we should return "HelloWorld", but given <div>Hello</div><div>Worl
d</div> the | 1586 // so we should return "HelloWorld", but given <div>Hello</div><div>Worl
d</div> the |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1778 return placeholder; | 1778 return placeholder; |
| 1779 } | 1779 } |
| 1780 | 1780 |
| 1781 return String(); | 1781 return String(); |
| 1782 } | 1782 } |
| 1783 | 1783 |
| 1784 // | 1784 // |
| 1785 // New AX name calculation. | 1785 // New AX name calculation. |
| 1786 // | 1786 // |
| 1787 | 1787 |
| 1788 String AXNodeObject::textAlternative(bool recursive, bool inAriaLabelledByTraver
sal, HashSet<AXObject*>& visited, AXNameFrom* nameFrom, Vector<AXObject*>* nameO
bjects) | 1788 String AXNodeObject::textAlternative(bool recursive, bool inAriaLabelledByTraver
sal, WillBeHeapHashSet<RawPtrWillBeMember<AXObject>>& visited, AXNameFrom* nameF
rom, WillBeHeapVector<RawPtrWillBeMember<AXObject>>* nameObjects) |
| 1789 { | 1789 { |
| 1790 bool alreadyVisited = visited.contains(this); | 1790 bool alreadyVisited = visited.contains(this); |
| 1791 visited.add(this); | 1791 visited.add(this); |
| 1792 | 1792 |
| 1793 if (!node() && !layoutObject()) | 1793 if (!node() && !layoutObject()) |
| 1794 return String(); | 1794 return String(); |
| 1795 | 1795 |
| 1796 // Step 2A from: http://www.w3.org/TR/accname-aam-1.1 | 1796 // Step 2A from: http://www.w3.org/TR/accname-aam-1.1 |
| 1797 if (!recursive && layoutObject() | 1797 if (!recursive && layoutObject() |
| 1798 && layoutObject()->style()->visibility() != VISIBLE | 1798 && layoutObject()->style()->visibility() != VISIBLE |
| 1799 && !equalIgnoringCase(getAttribute(aria_hiddenAttr), "false")) { | 1799 && !equalIgnoringCase(getAttribute(aria_hiddenAttr), "false")) { |
| 1800 return String(); | 1800 return String(); |
| 1801 } | 1801 } |
| 1802 | 1802 |
| 1803 // Step 2B from: http://www.w3.org/TR/accname-aam-1.1 | 1803 // Step 2B from: http://www.w3.org/TR/accname-aam-1.1 |
| 1804 if (!inAriaLabelledByTraversal && hasAttribute(aria_labelledbyAttr) && !alre
adyVisited) { | 1804 if (!inAriaLabelledByTraversal && hasAttribute(aria_labelledbyAttr) && !alre
adyVisited) { |
| 1805 if (nameFrom) | 1805 if (nameFrom) |
| 1806 *nameFrom = AXNameFromRelatedElement; | 1806 *nameFrom = AXNameFromRelatedElement; |
| 1807 WillBeHeapVector<RawPtrWillBeMember<Element>> elements; | 1807 WillBeHeapVector<RawPtrWillBeMember<Element>> elements; |
| 1808 ariaLabeledByElements(elements); | 1808 ariaLabeledByElements(elements); |
| 1809 StringBuilder accumulatedText; | 1809 StringBuilder accumulatedText; |
| 1810 for (const auto& element : elements) { | 1810 for (const auto& element : elements) { |
| 1811 RefPtr<AXObject> axElement = axObjectCache()->getOrCreate(element); | 1811 RefPtrWillBeRawPtr<AXObject> axElement = axObjectCache()->getOrCreat
e(element); |
| 1812 if (axElement) { | 1812 if (axElement) { |
| 1813 if (nameObjects) | 1813 if (nameObjects) |
| 1814 nameObjects->append(axElement.get()); | 1814 nameObjects->append(axElement.get()); |
| 1815 String result = axElement->textAlternative(true, true, visited,
nullptr, nullptr); | 1815 String result = axElement->textAlternative(true, true, visited,
nullptr, nullptr); |
| 1816 if (!result.isEmpty()) { | 1816 if (!result.isEmpty()) { |
| 1817 if (!accumulatedText.isEmpty()) | 1817 if (!accumulatedText.isEmpty()) |
| 1818 accumulatedText.append(" "); | 1818 accumulatedText.append(" "); |
| 1819 accumulatedText.append(result); | 1819 accumulatedText.append(result); |
| 1820 } | 1820 } |
| 1821 } | 1821 } |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2295 String documentTitle = document->title(); | 2295 String documentTitle = document->title(); |
| 2296 if (!documentTitle.isEmpty()) | 2296 if (!documentTitle.isEmpty()) |
| 2297 return documentTitle; | 2297 return documentTitle; |
| 2298 | 2298 |
| 2299 if (HTMLElement* body = document->body()) | 2299 if (HTMLElement* body = document->body()) |
| 2300 return body->getNameAttribute(); | 2300 return body->getNameAttribute(); |
| 2301 | 2301 |
| 2302 return String(); | 2302 return String(); |
| 2303 } | 2303 } |
| 2304 | 2304 |
| 2305 void AXNodeObject::alternativeText(Vector<AccessibilityText>& textOrder) const | 2305 void AXNodeObject::alternativeText(WillBeHeapVector<OwnPtrWillBeMember<Accessibi
lityText>>& textOrder) const |
| 2306 { | 2306 { |
| 2307 if (isWebArea()) { | 2307 if (isWebArea()) { |
| 2308 String webAreaText = alternativeTextForWebArea(); | 2308 String webAreaText = alternativeTextForWebArea(); |
| 2309 if (!webAreaText.isEmpty()) | 2309 if (!webAreaText.isEmpty()) |
| 2310 textOrder.append(AccessibilityText(webAreaText, AlternativeText)); | 2310 textOrder.append(AccessibilityText::create(webAreaText, AlternativeT
ext)); |
| 2311 return; | 2311 return; |
| 2312 } | 2312 } |
| 2313 | 2313 |
| 2314 ariaLabeledByText(textOrder); | 2314 ariaLabeledByText(textOrder); |
| 2315 | 2315 |
| 2316 const AtomicString& ariaLabel = getAttribute(aria_labelAttr); | 2316 const AtomicString& ariaLabel = getAttribute(aria_labelAttr); |
| 2317 if (!ariaLabel.isEmpty()) | 2317 if (!ariaLabel.isEmpty()) |
| 2318 textOrder.append(AccessibilityText(ariaLabel, AlternativeText)); | 2318 textOrder.append(AccessibilityText::create(ariaLabel, AlternativeText)); |
| 2319 | 2319 |
| 2320 if (isImage() || isInputImage() || isNativeImage() || isCanvas()) { | 2320 if (isImage() || isInputImage() || isNativeImage() || isCanvas()) { |
| 2321 // Images should use alt as long as the attribute is present, even if em
pty. | 2321 // Images should use alt as long as the attribute is present, even if em
pty. |
| 2322 // Otherwise, it should fallback to other methods, like the title attrib
ute. | 2322 // Otherwise, it should fallback to other methods, like the title attrib
ute. |
| 2323 const AtomicString& alt = getAttribute(altAttr); | 2323 const AtomicString& alt = getAttribute(altAttr); |
| 2324 if (!alt.isNull()) | 2324 if (!alt.isNull()) |
| 2325 textOrder.append(AccessibilityText(alt, AlternativeText)); | 2325 textOrder.append(AccessibilityText::create(alt, AlternativeText)); |
| 2326 } | 2326 } |
| 2327 } | 2327 } |
| 2328 | 2328 |
| 2329 void AXNodeObject::ariaLabeledByText(Vector<AccessibilityText>& textOrder) const | 2329 void AXNodeObject::ariaLabeledByText(WillBeHeapVector<OwnPtrWillBeMember<Accessi
bilityText>>& textOrder) const |
| 2330 { | 2330 { |
| 2331 String ariaLabeledBy = ariaLabeledByAttribute(); | 2331 String ariaLabeledBy = ariaLabeledByAttribute(); |
| 2332 if (!ariaLabeledBy.isEmpty()) { | 2332 if (!ariaLabeledBy.isEmpty()) { |
| 2333 WillBeHeapVector<RawPtrWillBeMember<Element>> elements; | 2333 WillBeHeapVector<RawPtrWillBeMember<Element>> elements; |
| 2334 ariaLabeledByElements(elements); | 2334 ariaLabeledByElements(elements); |
| 2335 | 2335 |
| 2336 for (const auto& element : elements) { | 2336 for (const auto& element : elements) { |
| 2337 RefPtr<AXObject> axElement = axObjectCache()->getOrCreate(element); | 2337 RefPtrWillBeRawPtr<AXObject> axElement = axObjectCache()->getOrCreat
e(element); |
| 2338 textOrder.append(AccessibilityText(ariaLabeledBy, AlternativeText, a
xElement)); | 2338 textOrder.append(AccessibilityText::create(ariaLabeledBy, Alternativ
eText, axElement)); |
| 2339 } | 2339 } |
| 2340 } | 2340 } |
| 2341 } | 2341 } |
| 2342 | 2342 |
| 2343 DEFINE_TRACE(AXNodeObject) |
| 2344 { |
| 2345 AXObject::trace(visitor); |
| 2346 visitor->trace(m_node); |
| 2347 } |
| 2348 |
| 2343 } // namespace blink | 2349 } // namespace blink |
| OLD | NEW |