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

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

Issue 2805493002: Boolean properties for Accessibility Object Model Phase 1 (Closed)
Patch Set: Created 3 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, 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 382
383 const AtomicString& AXObject::getAOMPropertyOrARIAAttribute( 383 const AtomicString& AXObject::getAOMPropertyOrARIAAttribute(
384 AOMStringProperty property) const { 384 AOMStringProperty property) const {
385 Node* node = this->getNode(); 385 Node* node = this->getNode();
386 if (!node || !node->isElementNode()) 386 if (!node || !node->isElementNode())
387 return nullAtom; 387 return nullAtom;
388 388
389 return AccessibleNode::getProperty(toElement(node), property); 389 return AccessibleNode::getProperty(toElement(node), property);
390 } 390 }
391 391
392 bool AXObject::getAOMPropertyOrARIAAttribute(AOMBooleanProperty property,
aboxhall 2017/04/07 05:22:35 Ok, now I see what you were talking about. This i
dmazzoni 2017/04/21 07:11:37 Thanks for the discussion. I went with this form:
393 bool& result) const {
394 Node* node = this->getNode();
aboxhall 2017/04/07 05:22:35 Would it help to make a convenience protected/priv
dmazzoni 2017/04/21 07:11:37 Good idea. Used it throughout the file.
395 if (!node || !node->isElementNode())
396 return false;
397
398 bool isNull = true;
399 result = AccessibleNode::getProperty(toElement(node), property, isNull);
400 return !isNull;
401 }
402
403 bool AXObject::hasAOMPropertyOrARIAAttribute(
404 AOMBooleanProperty property) const {
405 bool dummyResult;
406 return getAOMPropertyOrARIAAttribute(property, dummyResult);
407 }
408
409 bool AXObject::AOMPropertyOrARIAAttributeIsTrue(
410 AOMBooleanProperty property) const {
411 bool result;
412 if (getAOMPropertyOrARIAAttribute(property, result))
413 return result;
414 return false;
415 }
416
417 bool AXObject::AOMPropertyOrARIAAttributeIsFalse(
418 AOMBooleanProperty property) const {
419 bool result;
420 if (getAOMPropertyOrARIAAttribute(property, result))
421 return !result;
422 return false;
423 }
424
392 bool AXObject::isARIATextControl() const { 425 bool AXObject::isARIATextControl() const {
393 return ariaRoleAttribute() == TextFieldRole || 426 return ariaRoleAttribute() == TextFieldRole ||
394 ariaRoleAttribute() == SearchBoxRole || 427 ariaRoleAttribute() == SearchBoxRole ||
395 ariaRoleAttribute() == ComboBoxRole; 428 ariaRoleAttribute() == ComboBoxRole;
396 } 429 }
397 430
398 bool AXObject::isButton() const { 431 bool AXObject::isButton() const {
399 AccessibilityRole role = roleValue(); 432 AccessibilityRole role = roleValue();
400 433
401 return role == ButtonRole || role == PopUpButtonRole || 434 return role == ButtonRole || role == PopUpButtonRole ||
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 return parent; 622 return parent;
590 623
591 return parent->leafNodeAncestor(); 624 return parent->leafNodeAncestor();
592 } 625 }
593 626
594 return 0; 627 return 0;
595 } 628 }
596 629
597 const AXObject* AXObject::ariaHiddenRoot() const { 630 const AXObject* AXObject::ariaHiddenRoot() const {
598 for (const AXObject* object = this; object; object = object->parentObject()) { 631 for (const AXObject* object = this; object; object = object->parentObject()) {
599 if (equalIgnoringASCIICase(object->getAttribute(aria_hiddenAttr), "true")) 632 if (object->AOMPropertyOrARIAAttributeIsTrue(AOMBooleanProperty::kHidden))
600 return object; 633 return object;
601 } 634 }
602 635
603 return 0; 636 return 0;
604 } 637 }
605 638
606 bool AXObject::isDescendantOfDisabledNode() const { 639 bool AXObject::isDescendantOfDisabledNode() const {
607 updateCachedAttributeValuesIfNeeded(); 640 updateCachedAttributeValuesIfNeeded();
608 return m_cachedIsDescendantOfDisabledNode; 641 return m_cachedIsDescendantOfDisabledNode;
609 } 642 }
610 643
611 const AXObject* AXObject::disabledAncestor() const { 644 const AXObject* AXObject::disabledAncestor() const {
612 const AtomicString& disabled = getAttribute(aria_disabledAttr); 645 bool disabled = false;
613 if (equalIgnoringASCIICase(disabled, "true")) 646 if (getAOMPropertyOrARIAAttribute(AOMBooleanProperty::kDisabled, disabled)) {
614 return this; 647 if (disabled)
615 if (equalIgnoringASCIICase(disabled, "false")) 648 return this;
616 return 0; 649 return nullptr;
650 }
617 651
618 if (AXObject* parent = parentObject()) 652 if (AXObject* parent = parentObject())
619 return parent->disabledAncestor(); 653 return parent->disabledAncestor();
620 654
621 return 0; 655 return nullptr;
622 } 656 }
623 657
624 bool AXObject::lastKnownIsIgnoredValue() { 658 bool AXObject::lastKnownIsIgnoredValue() {
625 if (m_lastKnownIsIgnoredValue == DefaultBehavior) 659 if (m_lastKnownIsIgnoredValue == DefaultBehavior)
626 m_lastKnownIsIgnoredValue = 660 m_lastKnownIsIgnoredValue =
627 accessibilityIsIgnored() ? IgnoreObject : IncludeObject; 661 accessibilityIsIgnored() ? IgnoreObject : IncludeObject;
628 662
629 return m_lastKnownIsIgnoredValue == IgnoreObject; 663 return m_lastKnownIsIgnoredValue == IgnoreObject;
630 } 664 }
631 665
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 AXObjectSet& visited) { 750 AXObjectSet& visited) {
717 if (visited.contains(&axObj) && !inAriaLabelledByTraversal) 751 if (visited.contains(&axObj) && !inAriaLabelledByTraversal)
718 return String(); 752 return String();
719 753
720 AXNameFrom tmpNameFrom; 754 AXNameFrom tmpNameFrom;
721 return axObj.textAlternative(true, inAriaLabelledByTraversal, visited, 755 return axObj.textAlternative(true, inAriaLabelledByTraversal, visited,
722 tmpNameFrom, nullptr, nullptr); 756 tmpNameFrom, nullptr, nullptr);
723 } 757 }
724 758
725 bool AXObject::isHiddenForTextAlternativeCalculation() const { 759 bool AXObject::isHiddenForTextAlternativeCalculation() const {
726 if (equalIgnoringASCIICase(getAttribute(aria_hiddenAttr), "false")) 760 if (AOMPropertyOrARIAAttributeIsFalse(AOMBooleanProperty::kHidden))
727 return false; 761 return false;
728 762
729 if (getLayoutObject()) 763 if (getLayoutObject())
730 return getLayoutObject()->style()->visibility() != EVisibility::kVisible; 764 return getLayoutObject()->style()->visibility() != EVisibility::kVisible;
731 765
732 // This is an obscure corner case: if a node has no LayoutObject, that means 766 // This is an obscure corner case: if a node has no LayoutObject, that means
733 // it's not rendered, but we still may be exploring it as part of a text 767 // it's not rendered, but we still may be exploring it as part of a text
734 // alternative calculation, for example if it was explicitly referenced by 768 // alternative calculation, for example if it was explicitly referenced by
735 // aria-labelledby. So we need to explicitly call the style resolver to check 769 // aria-labelledby. So we need to explicitly call the style resolver to check
736 // whether it's invisible or display:none, rather than relying on the style 770 // whether it's invisible or display:none, rather than relying on the style
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 1009
976 if (isHTMLTextAreaElement(*node)) 1010 if (isHTMLTextAreaElement(*node))
977 return true; 1011 return true;
978 1012
979 if (hasEditableStyle(*node)) 1013 if (hasEditableStyle(*node))
980 return true; 1014 return true;
981 1015
982 if (!isNativeTextControl() && !isNonNativeTextControl()) 1016 if (!isNativeTextControl() && !isNonNativeTextControl())
983 return false; 1017 return false;
984 1018
985 return equalIgnoringASCIICase(getAttribute(aria_multilineAttr), "true"); 1019 return AOMPropertyOrARIAAttributeIsTrue(AOMBooleanProperty::kMultiline);
986 } 1020 }
987 1021
988 bool AXObject::ariaPressedIsPresent() const { 1022 bool AXObject::ariaPressedIsPresent() const {
989 return !getAttribute(aria_pressedAttr).isEmpty(); 1023 return !getAttribute(aria_pressedAttr).isEmpty();
990 } 1024 }
991 1025
992 bool AXObject::supportsActiveDescendant() const { 1026 bool AXObject::supportsActiveDescendant() const {
993 // According to the ARIA Spec, all ARIA composite widgets, ARIA text boxes 1027 // According to the ARIA Spec, all ARIA composite widgets, ARIA text boxes
994 // and ARIA groups should be able to expose an active descendant. 1028 // and ARIA groups should be able to expose an active descendant.
995 // Implicitly, <input> and <textarea> elements should also have this ability. 1029 // Implicitly, <input> and <textarea> elements should also have this ability.
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 } 1821 }
1788 1822
1789 DEFINE_TRACE(AXObject) { 1823 DEFINE_TRACE(AXObject) {
1790 visitor->trace(m_children); 1824 visitor->trace(m_children);
1791 visitor->trace(m_parent); 1825 visitor->trace(m_parent);
1792 visitor->trace(m_cachedLiveRegionRoot); 1826 visitor->trace(m_cachedLiveRegionRoot);
1793 visitor->trace(m_axObjectCache); 1827 visitor->trace(m_axObjectCache);
1794 } 1828 }
1795 1829
1796 } // namespace blink 1830 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698