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

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

Issue 2894103002: Int and Float properties for Accessibility Object Model phase 1 (Closed)
Patch Set: Created 3 years, 7 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 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 return ElementTraversal::FirstChild(*node); 1313 return ElementTraversal::FirstChild(*node);
1314 } 1314 }
1315 1315
1316 int AXNodeObject::HeadingLevel() const { 1316 int AXNodeObject::HeadingLevel() const {
1317 // headings can be in block flow and non-block flow 1317 // headings can be in block flow and non-block flow
1318 Node* node = this->GetNode(); 1318 Node* node = this->GetNode();
1319 if (!node) 1319 if (!node)
1320 return 0; 1320 return 0;
1321 1321
1322 if (RoleValue() == kHeadingRole) { 1322 if (RoleValue() == kHeadingRole) {
1323 String level_str = GetAttribute(aria_levelAttr); 1323 uint32_t level;
1324 if (!level_str.IsEmpty()) { 1324 if (HasAOMPropertyOrARIAAttribute(AOMUIntProperty::kLevel, level)) {
1325 int level = level_str.ToInt();
1326 if (level >= 1 && level <= 9) 1325 if (level >= 1 && level <= 9)
1327 return level; 1326 return level;
1328 return 1; 1327 return 1;
1329 } 1328 }
1330 } 1329 }
1331 1330
1332 if (!node->IsHTMLElement()) 1331 if (!node->IsHTMLElement())
1333 return 0; 1332 return 0;
1334 1333
1335 HTMLElement& element = ToHTMLElement(*node); 1334 HTMLElement& element = ToHTMLElement(*node);
(...skipping 12 matching lines...) Expand all
1348 if (element.HasTagName(h5Tag)) 1347 if (element.HasTagName(h5Tag))
1349 return 5; 1348 return 5;
1350 1349
1351 if (element.HasTagName(h6Tag)) 1350 if (element.HasTagName(h6Tag))
1352 return 6; 1351 return 6;
1353 1352
1354 return 0; 1353 return 0;
1355 } 1354 }
1356 1355
1357 unsigned AXNodeObject::HierarchicalLevel() const { 1356 unsigned AXNodeObject::HierarchicalLevel() const {
1358 Node* node = this->GetNode(); 1357 Element* element = GetElement();
1359 if (!node || !node->IsElementNode()) 1358 if (!element)
1360 return 0; 1359 return 0;
1361 1360
1362 Element* element = ToElement(node); 1361 uint32_t level;
1363 String level_str = element->getAttribute(aria_levelAttr); 1362 if (HasAOMPropertyOrARIAAttribute(AOMUIntProperty::kLevel, level)) {
1364 if (!level_str.IsEmpty()) { 1363 if (level >= 1 && level <= 9)
1365 int level = level_str.ToInt();
1366 if (level > 0)
1367 return level; 1364 return level;
1368 return 1; 1365 return 1;
1369 } 1366 }
1370 1367
1371 // Only tree item will calculate its level through the DOM currently. 1368 // Only tree item will calculate its level through the DOM currently.
1372 if (RoleValue() != kTreeItemRole) 1369 if (RoleValue() != kTreeItemRole)
1373 return 0; 1370 return 0;
1374 1371
1375 // Hierarchy leveling starts at 1, to match the aria-level spec. 1372 // Hierarchy leveling starts at 1, to match the aria-level spec.
1376 // We measure tree hierarchy by the number of groups that the item is within. 1373 // We measure tree hierarchy by the number of groups that the item is within.
1377 unsigned level = 1; 1374 level = 1;
1378 for (AXObjectImpl* parent = ParentObject(); parent; 1375 for (AXObjectImpl* parent = ParentObject(); parent;
1379 parent = parent->ParentObject()) { 1376 parent = parent->ParentObject()) {
1380 AccessibilityRole parent_role = parent->RoleValue(); 1377 AccessibilityRole parent_role = parent->RoleValue();
1381 if (parent_role == kGroupRole) 1378 if (parent_role == kGroupRole)
1382 level++; 1379 level++;
1383 else if (parent_role == kTreeRole) 1380 else if (parent_role == kTreeRole)
1384 break; 1381 break;
1385 } 1382 }
1386 1383
1387 return level; 1384 return level;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 bool is_invalid = !element->checkValidity(&invalid_controls, 1635 bool is_invalid = !element->checkValidity(&invalid_controls,
1639 kCheckValidityDispatchNoEvent); 1636 kCheckValidityDispatchNoEvent);
1640 return is_invalid ? kInvalidStateTrue : kInvalidStateFalse; 1637 return is_invalid ? kInvalidStateTrue : kInvalidStateFalse;
1641 } 1638 }
1642 1639
1643 return AXObjectImpl::GetInvalidState(); 1640 return AXObjectImpl::GetInvalidState();
1644 } 1641 }
1645 1642
1646 int AXNodeObject::PosInSet() const { 1643 int AXNodeObject::PosInSet() const {
1647 if (SupportsSetSizeAndPosInSet()) { 1644 if (SupportsSetSizeAndPosInSet()) {
1648 String pos_in_set_str = GetAttribute(aria_posinsetAttr); 1645 uint32_t pos_in_set;
1649 if (!pos_in_set_str.IsEmpty()) { 1646 if (HasAOMPropertyOrARIAAttribute(AOMUIntProperty::kPosInSet, pos_in_set))
1650 int pos_in_set = pos_in_set_str.ToInt(); 1647 return pos_in_set;
1651 if (pos_in_set > 0)
1652 return pos_in_set;
1653 return 1;
1654 }
1655 1648
1656 return AXObjectImpl::IndexInParent() + 1; 1649 return AXObjectImpl::IndexInParent() + 1;
1657 } 1650 }
1658 1651
1659 return 0; 1652 return 0;
1660 } 1653 }
1661 1654
1662 int AXNodeObject::SetSize() const { 1655 int AXNodeObject::SetSize() const {
1663 if (SupportsSetSizeAndPosInSet()) { 1656 if (SupportsSetSizeAndPosInSet()) {
1664 String set_size_str = GetAttribute(aria_setsizeAttr); 1657 int32_t set_size;
1665 if (!set_size_str.IsEmpty()) { 1658 if (HasAOMPropertyOrARIAAttribute(AOMIntProperty::kSetSize, set_size))
1666 int set_size = set_size_str.ToInt(); 1659 return set_size;
1667 if (set_size > 0)
1668 return set_size;
1669 return 1;
1670 }
1671 1660
1672 if (ParentObject()) { 1661 if (ParentObject()) {
1673 const auto& siblings = ParentObject()->Children(); 1662 const auto& siblings = ParentObject()->Children();
1674 return siblings.size(); 1663 return siblings.size();
1675 } 1664 }
1676 } 1665 }
1677 1666
1678 return 0; 1667 return 0;
1679 } 1668 }
1680 1669
1681 String AXNodeObject::AriaInvalidValue() const { 1670 String AXNodeObject::AriaInvalidValue() const {
1682 if (GetInvalidState() == kInvalidStateOther) 1671 if (GetInvalidState() == kInvalidStateOther)
1683 return GetAOMPropertyOrARIAAttribute(AOMStringProperty::kInvalid); 1672 return GetAOMPropertyOrARIAAttribute(AOMStringProperty::kInvalid);
1684 1673
1685 return String(); 1674 return String();
1686 } 1675 }
1687 1676
1688 String AXNodeObject::ValueDescription() const { 1677 String AXNodeObject::ValueDescription() const {
1689 if (!SupportsRangeValue()) 1678 if (!SupportsRangeValue())
1690 return String(); 1679 return String();
1691 1680
1692 return GetAOMPropertyOrARIAAttribute(AOMStringProperty::kValueText) 1681 return GetAOMPropertyOrARIAAttribute(AOMStringProperty::kValueText)
1693 .GetString(); 1682 .GetString();
1694 } 1683 }
1695 1684
1696 float AXNodeObject::ValueForRange() const { 1685 float AXNodeObject::ValueForRange() const {
1697 if (HasAttribute(aria_valuenowAttr)) 1686 float value_now;
1698 return GetAttribute(aria_valuenowAttr).ToFloat(); 1687 if (HasAOMPropertyOrARIAAttribute(AOMFloatProperty::kValueNow, value_now))
1688 return value_now;
1699 1689
1700 if (IsNativeSlider()) 1690 if (IsNativeSlider())
1701 return toHTMLInputElement(*GetNode()).valueAsNumber(); 1691 return toHTMLInputElement(*GetNode()).valueAsNumber();
1702 1692
1703 if (isHTMLMeterElement(GetNode())) 1693 if (isHTMLMeterElement(GetNode()))
1704 return toHTMLMeterElement(*GetNode()).value(); 1694 return toHTMLMeterElement(*GetNode()).value();
1705 1695
1706 return 0.0; 1696 return 0.0;
1707 } 1697 }
1708 1698
1709 float AXNodeObject::MaxValueForRange() const { 1699 float AXNodeObject::MaxValueForRange() const {
1710 if (HasAttribute(aria_valuemaxAttr)) 1700 float value_max;
1711 return GetAttribute(aria_valuemaxAttr).ToFloat(); 1701 if (HasAOMPropertyOrARIAAttribute(AOMFloatProperty::kValueMax, value_max))
1702 return value_max;
1712 1703
1713 if (IsNativeSlider()) 1704 if (IsNativeSlider())
1714 return toHTMLInputElement(*GetNode()).Maximum(); 1705 return toHTMLInputElement(*GetNode()).Maximum();
1715 1706
1716 if (isHTMLMeterElement(GetNode())) 1707 if (isHTMLMeterElement(GetNode()))
1717 return toHTMLMeterElement(*GetNode()).max(); 1708 return toHTMLMeterElement(*GetNode()).max();
1718 1709
1719 return 0.0; 1710 return 0.0;
1720 } 1711 }
1721 1712
1722 float AXNodeObject::MinValueForRange() const { 1713 float AXNodeObject::MinValueForRange() const {
1723 if (HasAttribute(aria_valueminAttr)) 1714 float value_min;
1724 return GetAttribute(aria_valueminAttr).ToFloat(); 1715 if (HasAOMPropertyOrARIAAttribute(AOMFloatProperty::kValueMin, value_min))
1716 return value_min;
1725 1717
1726 if (IsNativeSlider()) 1718 if (IsNativeSlider())
1727 return toHTMLInputElement(*GetNode()).Minimum(); 1719 return toHTMLInputElement(*GetNode()).Minimum();
1728 1720
1729 if (isHTMLMeterElement(GetNode())) 1721 if (isHTMLMeterElement(GetNode()))
1730 return toHTMLMeterElement(*GetNode()).min(); 1722 return toHTMLMeterElement(*GetNode()).min();
1731 1723
1732 return 0.0; 1724 return 0.0;
1733 } 1725 }
1734 1726
(...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after
3226 return String(); 3218 return String();
3227 return ToTextControlElement(node)->StrippedPlaceholder(); 3219 return ToTextControlElement(node)->StrippedPlaceholder();
3228 } 3220 }
3229 3221
3230 DEFINE_TRACE(AXNodeObject) { 3222 DEFINE_TRACE(AXNodeObject) {
3231 visitor->Trace(node_); 3223 visitor->Trace(node_);
3232 AXObjectImpl::Trace(visitor); 3224 AXObjectImpl::Trace(visitor);
3233 } 3225 }
3234 3226
3235 } // namespace blink 3227 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698