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

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

Issue 1072273006: Oilpan: Prepare moving AXObject to heap (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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) 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
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 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 ASSERT(!m_initialized); 747 ASSERT(!m_initialized);
748 m_initialized = true; 748 m_initialized = true;
749 #endif 749 #endif
750 m_role = determineAccessibilityRole(); 750 m_role = determineAccessibilityRole();
751 } 751 }
752 752
753 void AXNodeObject::detach() 753 void AXNodeObject::detach()
754 { 754 {
755 clearChildren(); 755 clearChildren();
756 AXObject::detach(); 756 AXObject::detach();
757 m_node = 0; 757 m_node = nullptr;
758 } 758 }
759 759
760 bool AXNodeObject::isAnchor() const 760 bool AXNodeObject::isAnchor() const
761 { 761 {
762 return !isNativeImage() && isLink(); 762 return !isNativeImage() && isLink();
763 } 763 }
764 764
765 bool AXNodeObject::isControl() const 765 bool AXNodeObject::isControl() const
766 { 766 {
767 Node* node = this->node(); 767 Node* node = this->node();
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 if (node && node->isTextNode()) 1581 if (node && node->isTextNode())
1582 return toText(node)->wholeText(); 1582 return toText(node)->wholeText();
1583 1583
1584 StringBuilder builder; 1584 StringBuilder builder;
1585 AXObject* previous = nullptr; 1585 AXObject* previous = nullptr;
1586 for (AXObject* child = firstChild(); child; child = child->nextSibling()) { 1586 for (AXObject* child = firstChild(); child; child = child->nextSibling()) {
1587 if (!shouldUseAccessibilityObjectInnerText(child)) 1587 if (!shouldUseAccessibilityObjectInnerText(child))
1588 continue; 1588 continue;
1589 1589
1590 if (child->isAXNodeObject()) { 1590 if (child->isAXNodeObject()) {
1591 Vector<AccessibilityText> textOrder; 1591 WillBeHeapVector<OwnPtrWillBeMember<AccessibilityText>> textOrder;
1592 toAXNodeObject(child)->alternativeText(textOrder); 1592 toAXNodeObject(child)->alternativeText(textOrder);
1593 if (textOrder.size() > 0) { 1593 if (textOrder.size() > 0) {
1594 builder.append(textOrder[0].text); 1594 builder.append(textOrder[0]->text());
1595 if (mode == TextUnderElementAny) 1595 if (mode == TextUnderElementAny)
1596 break; 1596 break;
1597 continue; 1597 continue;
1598 } 1598 }
1599 } 1599 }
1600 1600
1601 // If we're going between two layoutObjects that are in separate LayoutB oxes, add 1601 // If we're going between two layoutObjects that are in separate LayoutB oxes, add
1602 // whitespace if it wasn't there already. Intuitively if you have 1602 // whitespace if it wasn't there already. Intuitively if you have
1603 // <span>Hello</span><span>World</span>, those are part of the same Layo utBox 1603 // <span>Hello</span><span>World</span>, those are part of the same Layo utBox
1604 // so we should return "HelloWorld", but given <div>Hello</div><div>Worl d</div> the 1604 // 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
1796 return placeholder; 1796 return placeholder;
1797 } 1797 }
1798 1798
1799 return String(); 1799 return String();
1800 } 1800 }
1801 1801
1802 // 1802 //
1803 // New AX name calculation. 1803 // New AX name calculation.
1804 // 1804 //
1805 1805
1806 String AXNodeObject::textAlternative(bool recursive, bool inAriaLabelledByTraver sal, HashSet<AXObject*>& visited, AXNameFrom* nameFrom, Vector<AXObject*>* nameO bjects) 1806 String AXNodeObject::textAlternative(bool recursive, bool inAriaLabelledByTraver sal, WillBeHeapHashSet<RawPtrWillBeMember<AXObject>>& visited, AXNameFrom* nameF rom, WillBeHeapVector<RawPtrWillBeMember<AXObject>>* nameObjects)
1807 { 1807 {
1808 bool alreadyVisited = visited.contains(this); 1808 bool alreadyVisited = visited.contains(this);
1809 visited.add(this); 1809 visited.add(this);
1810 1810
1811 if (!node() && !layoutObject()) 1811 if (!node() && !layoutObject())
1812 return String(); 1812 return String();
1813 1813
1814 // Step 2A from: http://www.w3.org/TR/accname-aam-1.1 1814 // Step 2A from: http://www.w3.org/TR/accname-aam-1.1
1815 if (!recursive && layoutObject() 1815 if (!recursive && layoutObject()
1816 && layoutObject()->style()->visibility() != VISIBLE 1816 && layoutObject()->style()->visibility() != VISIBLE
1817 && !equalIgnoringCase(getAttribute(aria_hiddenAttr), "false")) { 1817 && !equalIgnoringCase(getAttribute(aria_hiddenAttr), "false")) {
1818 return String(); 1818 return String();
1819 } 1819 }
1820 1820
1821 // Step 2B from: http://www.w3.org/TR/accname-aam-1.1 1821 // Step 2B from: http://www.w3.org/TR/accname-aam-1.1
1822 if (!inAriaLabelledByTraversal && hasAttribute(aria_labelledbyAttr) && !alre adyVisited) { 1822 if (!inAriaLabelledByTraversal && hasAttribute(aria_labelledbyAttr) && !alre adyVisited) {
1823 if (nameFrom) 1823 if (nameFrom)
1824 *nameFrom = AXNameFromRelatedElement; 1824 *nameFrom = AXNameFromRelatedElement;
1825 WillBeHeapVector<RawPtrWillBeMember<Element>> elements; 1825 WillBeHeapVector<RawPtrWillBeMember<Element>> elements;
1826 ariaLabeledByElements(elements); 1826 ariaLabeledByElements(elements);
1827 StringBuilder accumulatedText; 1827 StringBuilder accumulatedText;
1828 for (const auto& element : elements) { 1828 for (const auto& element : elements) {
1829 RefPtr<AXObject> axElement = axObjectCache()->getOrCreate(element); 1829 RefPtrWillBeRawPtr<AXObject> axElement = axObjectCache()->getOrCreat e(element);
1830 if (axElement) { 1830 if (axElement) {
1831 if (nameObjects) 1831 if (nameObjects)
1832 nameObjects->append(axElement.get()); 1832 nameObjects->append(axElement.get());
1833 String result = axElement->textAlternative(true, true, visited, nullptr, nullptr); 1833 String result = axElement->textAlternative(true, true, visited, nullptr, nullptr);
1834 if (!result.isEmpty()) { 1834 if (!result.isEmpty()) {
1835 if (!accumulatedText.isEmpty()) 1835 if (!accumulatedText.isEmpty())
1836 accumulatedText.append(" "); 1836 accumulatedText.append(" ");
1837 accumulatedText.append(result); 1837 accumulatedText.append(result);
1838 } 1838 }
1839 } 1839 }
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
2333 String documentTitle = document->title(); 2333 String documentTitle = document->title();
2334 if (!documentTitle.isEmpty()) 2334 if (!documentTitle.isEmpty())
2335 return documentTitle; 2335 return documentTitle;
2336 2336
2337 if (HTMLElement* body = document->body()) 2337 if (HTMLElement* body = document->body())
2338 return body->getNameAttribute(); 2338 return body->getNameAttribute();
2339 2339
2340 return String(); 2340 return String();
2341 } 2341 }
2342 2342
2343 void AXNodeObject::alternativeText(Vector<AccessibilityText>& textOrder) const 2343 void AXNodeObject::alternativeText(WillBeHeapVector<OwnPtrWillBeMember<Accessibi lityText>>& textOrder) const
2344 { 2344 {
2345 if (isWebArea()) { 2345 if (isWebArea()) {
2346 String webAreaText = alternativeTextForWebArea(); 2346 String webAreaText = alternativeTextForWebArea();
2347 if (!webAreaText.isEmpty()) 2347 if (!webAreaText.isEmpty())
2348 textOrder.append(AccessibilityText(webAreaText, AlternativeText)); 2348 textOrder.append(AccessibilityText::create(webAreaText, AlternativeT ext));
2349 return; 2349 return;
2350 } 2350 }
2351 2351
2352 ariaLabeledByText(textOrder); 2352 ariaLabeledByText(textOrder);
2353 2353
2354 const AtomicString& ariaLabel = getAttribute(aria_labelAttr); 2354 const AtomicString& ariaLabel = getAttribute(aria_labelAttr);
2355 if (!ariaLabel.isEmpty()) 2355 if (!ariaLabel.isEmpty())
2356 textOrder.append(AccessibilityText(ariaLabel, AlternativeText)); 2356 textOrder.append(AccessibilityText::create(ariaLabel, AlternativeText));
2357 2357
2358 if (isImage() || isInputImage() || isNativeImage() || isCanvas()) { 2358 if (isImage() || isInputImage() || isNativeImage() || isCanvas()) {
2359 // Images should use alt as long as the attribute is present, even if em pty. 2359 // Images should use alt as long as the attribute is present, even if em pty.
2360 // Otherwise, it should fallback to other methods, like the title attrib ute. 2360 // Otherwise, it should fallback to other methods, like the title attrib ute.
2361 const AtomicString& alt = getAttribute(altAttr); 2361 const AtomicString& alt = getAttribute(altAttr);
2362 if (!alt.isNull()) 2362 if (!alt.isNull())
2363 textOrder.append(AccessibilityText(alt, AlternativeText)); 2363 textOrder.append(AccessibilityText::create(alt, AlternativeText));
2364 } 2364 }
2365 } 2365 }
2366 2366
2367 void AXNodeObject::ariaLabeledByText(Vector<AccessibilityText>& textOrder) const 2367 void AXNodeObject::ariaLabeledByText(WillBeHeapVector<OwnPtrWillBeMember<Accessi bilityText>>& textOrder) const
2368 { 2368 {
2369 String ariaLabeledBy = ariaLabeledByAttribute(); 2369 String ariaLabeledBy = ariaLabeledByAttribute();
2370 if (!ariaLabeledBy.isEmpty()) { 2370 if (!ariaLabeledBy.isEmpty()) {
2371 WillBeHeapVector<RawPtrWillBeMember<Element>> elements; 2371 WillBeHeapVector<RawPtrWillBeMember<Element>> elements;
2372 ariaLabeledByElements(elements); 2372 ariaLabeledByElements(elements);
2373 2373
2374 for (const auto& element : elements) { 2374 for (const auto& element : elements) {
2375 RefPtr<AXObject> axElement = axObjectCache()->getOrCreate(element); 2375 RefPtrWillBeRawPtr<AXObject> axElement = axObjectCache()->getOrCreat e(element);
2376 textOrder.append(AccessibilityText(ariaLabeledBy, AlternativeText, a xElement)); 2376 textOrder.append(AccessibilityText::create(ariaLabeledBy, Alternativ eText, axElement));
2377 } 2377 }
2378 } 2378 }
2379 } 2379 }
2380 2380
2381 DEFINE_TRACE(AXNodeObject)
2382 {
2383 visitor->trace(m_node);
2384 AXObject::trace(visitor);
2385 }
2386
2381 } // namespace blink 2387 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698