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

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

Issue 1348503003: One AXObjectCache per frame (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Send focus notifications when focus is cleared Created 5 years, 3 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // We want to notify that the combo box has changed its active descendant, 240 // We want to notify that the combo box has changed its active descendant,
241 // but we do not want to change the focus, because focus should remain with the combo box. 241 // but we do not want to change the focus, because focus should remain with the combo box.
242 if (isComboBox()) 242 if (isComboBox())
243 return true; 243 return true;
244 244
245 return shouldFocusActiveDescendant(); 245 return shouldFocusActiveDescendant();
246 } 246 }
247 247
248 ScrollableArea* AXLayoutObject::getScrollableAreaIfScrollable() const 248 ScrollableArea* AXLayoutObject::getScrollableAreaIfScrollable() const
249 { 249 {
250 // FIXME(dmazzoni): the plan is to get rid of AXScrollView, but until 250 if (isWebArea())
251 // this is done, a WebArea delegates its scrolling to its parent scroll view . 251 return documentFrameView();
252 // http://crbug.com/484878
253 if (parentObject() && parentObject()->isAXScrollView())
254 return parentObject()->getScrollableAreaIfScrollable();
255 252
256 if (!m_layoutObject || !m_layoutObject->isBox()) 253 if (!m_layoutObject || !m_layoutObject->isBox())
257 return 0; 254 return 0;
258 255
259 LayoutBox* box = toLayoutBox(m_layoutObject); 256 LayoutBox* box = toLayoutBox(m_layoutObject);
260 if (!box->canBeScrolledAndHasScrollableArea()) 257 if (!box->canBeScrolledAndHasScrollableArea())
261 return 0; 258 return 0;
262 259
263 return box->scrollableArea(); 260 return box->scrollableArea();
264 } 261 }
(...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 if (ariaRoleAttribute() == MenuRole) { 1592 if (ariaRoleAttribute() == MenuRole) {
1596 AXObject* parent = menuButtonForMenu(); 1593 AXObject* parent = menuButtonForMenu();
1597 if (parent) 1594 if (parent)
1598 return parent; 1595 return parent;
1599 } 1596 }
1600 1597
1601 LayoutObject* parentObj = layoutParentObject(); 1598 LayoutObject* parentObj = layoutParentObject();
1602 if (parentObj) 1599 if (parentObj)
1603 return axObjectCache().getOrCreate(parentObj); 1600 return axObjectCache().getOrCreate(parentObj);
1604 1601
1605 // WebArea's parent should be the scroll view containing it.
1606 if (isWebArea())
1607 return axObjectCache().getOrCreate(m_layoutObject->frame()->view());
1608
1609 return 0; 1602 return 0;
1610 } 1603 }
1611 1604
1612 AXObject* AXLayoutObject::computeParentIfExists() const 1605 AXObject* AXLayoutObject::computeParentIfExists() const
1613 { 1606 {
1614 if (!m_layoutObject) 1607 if (!m_layoutObject)
1615 return 0; 1608 return 0;
1616 1609
1617 if (ariaRoleAttribute() == MenuBarRole) 1610 if (ariaRoleAttribute() == MenuBarRole)
1618 return axObjectCache().get(m_layoutObject->parent()); 1611 return axObjectCache().get(m_layoutObject->parent());
1619 1612
1620 // menuButton and its corresponding menu are DOM siblings, but Accessibility needs them to be parent/child 1613 // menuButton and its corresponding menu are DOM siblings, but Accessibility needs them to be parent/child
1621 if (ariaRoleAttribute() == MenuRole) { 1614 if (ariaRoleAttribute() == MenuRole) {
1622 AXObject* parent = menuButtonForMenu(); 1615 AXObject* parent = menuButtonForMenu();
1623 if (parent) 1616 if (parent)
1624 return parent; 1617 return parent;
1625 } 1618 }
1626 1619
1627 LayoutObject* parentObj = layoutParentObject(); 1620 LayoutObject* parentObj = layoutParentObject();
1628 if (parentObj) 1621 if (parentObj)
1629 return axObjectCache().get(parentObj); 1622 return axObjectCache().get(parentObj);
1630 1623
1631 // WebArea's parent should be the scroll view containing it.
1632 if (isWebArea())
1633 return axObjectCache().get(m_layoutObject->frame()->view());
1634
1635 return 0; 1624 return 0;
1636 } 1625 }
1637 1626
1638 // 1627 //
1639 // Low-level accessibility tree exploration, only for use within the accessibili ty module. 1628 // Low-level accessibility tree exploration, only for use within the accessibili ty module.
1640 // 1629 //
1641 1630
1642 AXObject* AXLayoutObject::firstChild() const 1631 AXObject* AXLayoutObject::firstChild() const
1643 { 1632 {
1644 if (!m_layoutObject) 1633 if (!m_layoutObject)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 1698
1710 HeapVector<Member<AXObject>> ownedChildren; 1699 HeapVector<Member<AXObject>> ownedChildren;
1711 computeAriaOwnsChildren(ownedChildren); 1700 computeAriaOwnsChildren(ownedChildren);
1712 1701
1713 for (AXObject* obj = firstChild(); obj; obj = obj->nextSibling()) { 1702 for (AXObject* obj = firstChild(); obj; obj = obj->nextSibling()) {
1714 if (!axObjectCache().isAriaOwned(obj)) 1703 if (!axObjectCache().isAriaOwned(obj))
1715 addChild(obj); 1704 addChild(obj);
1716 } 1705 }
1717 1706
1718 addHiddenChildren(); 1707 addHiddenChildren();
1719 addAttachmentChildren();
1720 addPopupChildren(); 1708 addPopupChildren();
1721 addImageMapChildren(); 1709 addImageMapChildren();
1722 addTextFieldChildren(); 1710 addTextFieldChildren();
1723 addCanvasChildren(); 1711 addCanvasChildren();
1724 addRemoteSVGChildren(); 1712 addRemoteSVGChildren();
1725 addInlineTextBoxChildren(false); 1713 addInlineTextBoxChildren(false);
1726 1714
1727 for (const auto& child : m_children) { 1715 for (const auto& child : m_children) {
1728 if (!child->cachedParentObject()) 1716 if (!child->cachedParentObject())
1729 child->setParent(this); 1717 child->setParent(this);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElem ent 1810 // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElem ent
1823 Node* node = currLayoutObject->node(); 1811 Node* node = currLayoutObject->node();
1824 for ( ; node; node = node->parentNode()) { 1812 for ( ; node; node = node->parentNode()) {
1825 if (isHTMLAnchorElement(*node) || (node->layoutObject() && cache.getOrCr eate(node->layoutObject())->isAnchor())) 1813 if (isHTMLAnchorElement(*node) || (node->layoutObject() && cache.getOrCr eate(node->layoutObject())->isAnchor()))
1826 return toElement(node); 1814 return toElement(node);
1827 } 1815 }
1828 1816
1829 return 0; 1817 return 0;
1830 } 1818 }
1831 1819
1832 Widget* AXLayoutObject::widgetForAttachmentView() const
1833 {
1834 if (!isAttachment())
1835 return 0;
1836 return toLayoutPart(m_layoutObject)->widget();
1837 }
1838
1839 // 1820 //
1840 // Functions that retrieve the current selection. 1821 // Functions that retrieve the current selection.
1841 // 1822 //
1842 1823
1843 AXObject::AXRange AXLayoutObject::selection() const 1824 AXObject::AXRange AXLayoutObject::selection() const
1844 { 1825 {
1845 AXRange textSelection = textControlSelection(); 1826 AXRange textSelection = textControlSelection();
1846 if (textSelection.isValid()) 1827 if (textSelection.isValid())
1847 return textSelection; 1828 return textSelection;
1848 1829
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2301 if (!isTabItem() || !m_layoutObject) 2282 if (!isTabItem() || !m_layoutObject)
2302 return false; 2283 return false;
2303 2284
2304 Node* node = m_layoutObject->node(); 2285 Node* node = m_layoutObject->node();
2305 if (!node || !node->isElementNode()) 2286 if (!node || !node->isElementNode())
2306 return false; 2287 return false;
2307 2288
2308 // The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel 2289 // The ARIA spec says a tab item can also be selected if it is aria-labeled by a tabpanel
2309 // that has keyboard focus inside of it, or if a tabpanel in its aria-contro ls list has KB 2290 // that has keyboard focus inside of it, or if a tabpanel in its aria-contro ls list has KB
2310 // focus inside of it. 2291 // focus inside of it.
2311 AXObject* focusedElement = focusedUIElement(); 2292 Document* doc = document();
2293 if (!doc)
2294 return false;
2295
2296 Element* focusedElement = doc->activeElement();
2312 if (!focusedElement) 2297 if (!focusedElement)
2313 return false; 2298 return false;
2314 2299
2315 WillBeHeapVector<RawPtrWillBeMember<Element>> elements; 2300 WillBeHeapVector<RawPtrWillBeMember<Element>> elements;
2316 elementsFromAttribute(elements, aria_controlsAttr); 2301 elementsFromAttribute(elements, aria_controlsAttr);
2317 2302
2318 for (const auto& element : elements) { 2303 for (const auto& element : elements) {
2319 AXObject* tabPanel = axObjectCache().getOrCreate(element); 2304 AXObject* tabPanel = axObjectCache().getOrCreate(element);
2320 2305
2321 // A tab item should only control tab panels. 2306 // A tab item should only control tab panels.
2322 if (!tabPanel || tabPanel->roleValue() != TabPanelRole) 2307 if (!tabPanel || tabPanel->roleValue() != TabPanelRole)
2323 continue; 2308 continue;
2324 2309
2325 AXObject* checkFocusElement = focusedElement; 2310 Element* checkFocusElement = focusedElement;
2326 // Check if the focused element is a descendant of the element controlle d by the tab item. 2311 // Check if the focused element is a descendant of the element controlle d by the tab item.
2327 while (checkFocusElement) { 2312 while (checkFocusElement) {
2328 if (tabPanel == checkFocusElement) 2313 if (tabPanel->node() == checkFocusElement)
2329 return true; 2314 return true;
2330 checkFocusElement = checkFocusElement->parentObject(); 2315 checkFocusElement = checkFocusElement->parentElement();
2331 } 2316 }
2332 } 2317 }
2333 2318
2334 return false; 2319 return false;
2335 } 2320 }
2336 2321
2337 AXObject* AXLayoutObject::accessibilityImageMapHitTest(HTMLAreaElement* area, co nst IntPoint& point) const 2322 AXObject* AXLayoutObject::accessibilityImageMapHitTest(HTMLAreaElement* area, co nst IntPoint& point) const
2338 { 2323 {
2339 if (!area) 2324 if (!area)
2340 return 0; 2325 return 0;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2532 if (!isHTMLCanvasElement(node())) 2517 if (!isHTMLCanvasElement(node()))
2533 return; 2518 return;
2534 2519
2535 // If it's a canvas, it won't have laid out children, but it might have acce ssible fallback content. 2520 // If it's a canvas, it won't have laid out children, but it might have acce ssible fallback content.
2536 // Clear m_haveChildren because AXNodeObject::addChildren will expect it to be false. 2521 // Clear m_haveChildren because AXNodeObject::addChildren will expect it to be false.
2537 ASSERT(!m_children.size()); 2522 ASSERT(!m_children.size());
2538 m_haveChildren = false; 2523 m_haveChildren = false;
2539 AXNodeObject::addChildren(); 2524 AXNodeObject::addChildren();
2540 } 2525 }
2541 2526
2542 void AXLayoutObject::addAttachmentChildren()
2543 {
2544 if (!isAttachment())
2545 return;
2546
2547 // FrameView's need to be inserted into the AX hierarchy when encountered.
2548 Widget* widget = widgetForAttachmentView();
2549 if (!widget || !widget->isFrameView())
2550 return;
2551
2552 AXObject* axWidget = axObjectCache().getOrCreate(widget);
2553 if (!axWidget->accessibilityIsIgnored())
2554 m_children.append(axWidget);
2555 }
2556
2557 void AXLayoutObject::addPopupChildren() 2527 void AXLayoutObject::addPopupChildren()
2558 { 2528 {
2559 if (!isHTMLInputElement(node())) 2529 if (!isHTMLInputElement(node()))
2560 return; 2530 return;
2561 if (AXObject* axPopup = toHTMLInputElement(node())->popupRootAXObject()) 2531 if (AXObject* axPopup = toHTMLInputElement(node())->popupRootAXObject())
2562 m_children.append(axPopup); 2532 m_children.append(axPopup);
2563 } 2533 }
2564 2534
2565 void AXLayoutObject::addRemoteSVGChildren() 2535 void AXLayoutObject::addRemoteSVGChildren()
2566 { 2536 {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2659 if (label && label->layoutObject()) { 2629 if (label && label->layoutObject()) {
2660 LayoutRect labelRect = axObjectCache().getOrCreate(label)->elementRe ct(); 2630 LayoutRect labelRect = axObjectCache().getOrCreate(label)->elementRe ct();
2661 result.unite(labelRect); 2631 result.unite(labelRect);
2662 } 2632 }
2663 } 2633 }
2664 2634
2665 return result; 2635 return result;
2666 } 2636 }
2667 2637
2668 } // namespace blink 2638 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698