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

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/AXObject.cpp

Issue 2750533006: Initial skeleton of Accessibility Object Model Phase 1 (Closed)
Patch Set: Add comment about ugly AXObjectCache interface Created 3 years, 9 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, 2009, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2008, 2009, 2011 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 12 matching lines...) Expand all
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "modules/accessibility/AXObject.h" 29 #include "modules/accessibility/AXObject.h"
30 30
31 #include "SkMatrix44.h" 31 #include "SkMatrix44.h"
32 #include "core/css/resolver/StyleResolver.h" 32 #include "core/css/resolver/StyleResolver.h"
33 #include "core/dom/AccessibleNode.h"
33 #include "core/dom/DocumentUserGestureToken.h" 34 #include "core/dom/DocumentUserGestureToken.h"
34 #include "core/editing/EditingUtilities.h" 35 #include "core/editing/EditingUtilities.h"
35 #include "core/editing/VisibleUnits.h" 36 #include "core/editing/VisibleUnits.h"
36 #include "core/frame/FrameView.h" 37 #include "core/frame/FrameView.h"
37 #include "core/frame/LocalFrame.h" 38 #include "core/frame/LocalFrame.h"
38 #include "core/frame/Settings.h" 39 #include "core/frame/Settings.h"
39 #include "core/html/HTMLDialogElement.h" 40 #include "core/html/HTMLDialogElement.h"
40 #include "core/html/HTMLFrameOwnerElement.h" 41 #include "core/html/HTMLFrameOwnerElement.h"
41 #include "core/html/parser/HTMLParserIdioms.h" 42 #include "core/html/parser/HTMLParserIdioms.h"
42 #include "core/layout/LayoutBoxModelObject.h" 43 #include "core/layout/LayoutBoxModelObject.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // no children are left with dangling pointers to their parent. 372 // no children are left with dangling pointers to their parent.
372 clearChildren(); 373 clearChildren();
373 374
374 m_axObjectCache = nullptr; 375 m_axObjectCache = nullptr;
375 } 376 }
376 377
377 bool AXObject::isDetached() const { 378 bool AXObject::isDetached() const {
378 return !m_axObjectCache; 379 return !m_axObjectCache;
379 } 380 }
380 381
382 using AOMStringPropertyToAriaMap = HashMap<AOMStringProperty,
383 QualifiedName,
384 WTF::IntHash<AOMStringProperty>,
385 AOMStringPropertyHashTraits>;
386
387 static AOMStringPropertyToAriaMap& getAOMStringPropertyToAriaMap() {
388 DEFINE_STATIC_LOCAL(AOMStringPropertyToAriaMap, map, ());
389 if (map.isEmpty()) {
390 map.set(AOMStringProperty::Role, roleAttr);
esprehn 2017/03/22 03:40:32 Can we just use roleAttr as the key into the AOM m
dmazzoni 2017/03/23 03:36:41 I got rid of this HashMap, instead now we can just
391 map.set(AOMStringProperty::Label, aria_labelAttr);
esprehn 2017/03/22 03:40:32 calling set() repeatedly inlines the hash function
392 }
393 return map;
394 }
395
396 AccessibleNode* AXObject::getAccessibleNode() const {
397 if (!RuntimeEnabledFeatures::accessibilityObjectModelEnabled())
398 return nullptr;
399
400 Node* node = getNode();
401 if (!node || !node->isElementNode())
402 return nullptr;
403
404 Element* element = toElement(node);
405 return element->accessibleNode();
406 }
407
408 const AtomicString& AXObject::getAriaAttributeOrAOMProperty(
409 AOMStringProperty property) const {
410 AOMStringPropertyToAriaMap& ariaMap = getAOMStringPropertyToAriaMap();
411 QualifiedName attrName = ariaMap.at(property);
412 if (attrName != QualifiedName::null()) {
413 const AtomicString& result = getAttribute(attrName);
414 if (!result.isNull())
415 return result;
416 }
417
418 AccessibleNode* aomNode = getAccessibleNode();
419 if (aomNode)
esprehn 2017/03/22 03:40:32 We often combines these like: if (auto* node = ge
dmazzoni 2017/03/23 03:36:41 Done.
420 return aomNode->getProperty(property);
421
422 return nullAtom;
423 }
424
381 bool AXObject::isARIATextControl() const { 425 bool AXObject::isARIATextControl() const {
382 return ariaRoleAttribute() == TextFieldRole || 426 return ariaRoleAttribute() == TextFieldRole ||
383 ariaRoleAttribute() == SearchBoxRole || 427 ariaRoleAttribute() == SearchBoxRole ||
384 ariaRoleAttribute() == ComboBoxRole; 428 ariaRoleAttribute() == ComboBoxRole;
385 } 429 }
386 430
387 bool AXObject::isButton() const { 431 bool AXObject::isButton() const {
388 AccessibilityRole role = roleValue(); 432 AccessibilityRole role = roleValue();
389 433
390 return role == ButtonRole || role == PopUpButtonRole || 434 return role == ButtonRole || role == PopUpButtonRole ||
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 } 840 }
797 } 841 }
798 842
799 // Step 2C from: http://www.w3.org/TR/accname-aam-1.1 843 // Step 2C from: http://www.w3.org/TR/accname-aam-1.1
800 // If you change this logic, update AXNodeObject::nameFromLabelElement, too. 844 // If you change this logic, update AXNodeObject::nameFromLabelElement, too.
801 nameFrom = AXNameFromAttribute; 845 nameFrom = AXNameFromAttribute;
802 if (nameSources) { 846 if (nameSources) {
803 nameSources->push_back(NameSource(*foundTextAlternative, aria_labelAttr)); 847 nameSources->push_back(NameSource(*foundTextAlternative, aria_labelAttr));
804 nameSources->back().type = nameFrom; 848 nameSources->back().type = nameFrom;
805 } 849 }
806 const AtomicString& ariaLabel = getAttribute(aria_labelAttr); 850 const AtomicString& ariaLabel =
851 getAriaAttributeOrAOMProperty(AOMStringProperty::Label);
807 if (!ariaLabel.isEmpty()) { 852 if (!ariaLabel.isEmpty()) {
808 textAlternative = ariaLabel; 853 textAlternative = ariaLabel;
809 854
810 if (nameSources) { 855 if (nameSources) {
811 NameSource& source = nameSources->back(); 856 NameSource& source = nameSources->back();
812 source.text = textAlternative; 857 source.text = textAlternative;
813 source.attributeValue = ariaLabel; 858 source.attributeValue = ariaLabel;
814 *foundTextAlternative = true; 859 *foundTextAlternative = true;
815 } else { 860 } else {
816 *foundTextAlternative = true; 861 *foundTextAlternative = true;
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 } 1807 }
1763 1808
1764 DEFINE_TRACE(AXObject) { 1809 DEFINE_TRACE(AXObject) {
1765 visitor->trace(m_children); 1810 visitor->trace(m_children);
1766 visitor->trace(m_parent); 1811 visitor->trace(m_parent);
1767 visitor->trace(m_cachedLiveRegionRoot); 1812 visitor->trace(m_cachedLiveRegionRoot);
1768 visitor->trace(m_axObjectCache); 1813 visitor->trace(m_axObjectCache);
1769 } 1814 }
1770 1815
1771 } // namespace blink 1816 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698