summaryrefslogtreecommitdiff
path: root/Source/WebCore/accessibility/AccessibilityTableRow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/accessibility/AccessibilityTableRow.cpp')
-rw-r--r--Source/WebCore/accessibility/AccessibilityTableRow.cpp83
1 files changed, 60 insertions, 23 deletions
diff --git a/Source/WebCore/accessibility/AccessibilityTableRow.cpp b/Source/WebCore/accessibility/AccessibilityTableRow.cpp
index ab4d0d03b..b51b18c41 100644
--- a/Source/WebCore/accessibility/AccessibilityTableRow.cpp
+++ b/Source/WebCore/accessibility/AccessibilityTableRow.cpp
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -51,9 +51,9 @@ AccessibilityTableRow::~AccessibilityTableRow()
{
}
-PassRefPtr<AccessibilityTableRow> AccessibilityTableRow::create(RenderObject* renderer)
+Ref<AccessibilityTableRow> AccessibilityTableRow::create(RenderObject* renderer)
{
- return adoptRef(new AccessibilityTableRow(renderer));
+ return adoptRef(*new AccessibilityTableRow(renderer));
}
AccessibilityRole AccessibilityTableRow::determineAccessibilityRole()
@@ -61,11 +61,8 @@ AccessibilityRole AccessibilityTableRow::determineAccessibilityRole()
if (!isTableRow())
return AccessibilityRenderObject::determineAccessibilityRole();
- m_ariaRole = determineAriaRoleAttribute();
-
- AccessibilityRole ariaRole = ariaRoleAttribute();
- if (ariaRole != UnknownRole)
- return ariaRole;
+ if ((m_ariaRole = determineAriaRoleAttribute()) != UnknownRole)
+ return m_ariaRole;
return RowRole;
}
@@ -73,10 +70,7 @@ AccessibilityRole AccessibilityTableRow::determineAccessibilityRole()
bool AccessibilityTableRow::isTableRow() const
{
AccessibilityObject* table = parentTable();
- if (!table || !table->isAccessibilityTable())
- return false;
-
- return true;
+ return is<AccessibilityTable>(table) && downcast<AccessibilityTable>(*table).isExposableThroughAccessibility();
}
AccessibilityObject* AccessibilityTableRow::observableObject() const
@@ -104,38 +98,81 @@ AccessibilityTable* AccessibilityTableRow::parentTable() const
// The parent table might not be the direct ancestor of the row unfortunately. ARIA states that role="grid" should
// only have "row" elements, but if not, we still should handle it gracefully by finding the right table.
for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
- // If this is a table object, but not an accessibility table, we should stop because we don't want to
+ // If this is a non-anonymous table object, but not an accessibility table, we should stop because we don't want to
// choose another ancestor table as this row's table.
- if (parent->isTable())
- return parent->isAccessibilityTable() ? toAccessibilityTable(parent) : 0;
+ if (is<AccessibilityTable>(*parent)) {
+ auto& parentTable = downcast<AccessibilityTable>(*parent);
+ if (parentTable.isExposableThroughAccessibility())
+ return &parentTable;
+ if (parentTable.node())
+ break;
+ }
}
- return 0;
+ return nullptr;
}
AccessibilityObject* AccessibilityTableRow::headerObject()
{
if (!m_renderer || !m_renderer->isTableRow())
- return 0;
+ return nullptr;
const auto& rowChildren = children();
if (!rowChildren.size())
- return 0;
+ return nullptr;
// check the first element in the row to see if it is a TH element
AccessibilityObject* cell = rowChildren[0].get();
- if (!cell->isTableCell())
- return 0;
+ if (!is<AccessibilityTableCell>(*cell))
+ return nullptr;
- RenderObject* cellRenderer = toAccessibilityTableCell(cell)->renderer();
+ RenderObject* cellRenderer = downcast<AccessibilityTableCell>(*cell).renderer();
if (!cellRenderer)
- return 0;
+ return nullptr;
Node* cellNode = cellRenderer->node();
if (!cellNode || !cellNode->hasTagName(thTag))
- return 0;
+ return nullptr;
return cell;
}
+void AccessibilityTableRow::addChildren()
+{
+ AccessibilityRenderObject::addChildren();
+
+ // "ARIA 1.1, If the set of columns which is present in the DOM is contiguous, and if there are no cells which span more than one row or
+ // column in that set, then authors may place aria-colindex on each row, setting the value to the index of the first column of the set."
+ // Update child cells' ariaColIndex if there's an aria-colindex value set for the row. So the cell doesn't have to go through the siblings
+ // to calculate the index.
+ int colIndex = ariaColumnIndex();
+ if (colIndex == -1)
+ return;
+
+ unsigned index = 0;
+ for (const auto& cell : children()) {
+ if (is<AccessibilityTableCell>(*cell))
+ downcast<AccessibilityTableCell>(*cell).setARIAColIndexFromRow(colIndex + index);
+ index++;
+ }
+}
+
+int AccessibilityTableRow::ariaColumnIndex() const
+{
+ const AtomicString& colIndexValue = getAttribute(aria_colindexAttr);
+ if (colIndexValue.toInt() >= 1)
+ return colIndexValue.toInt();
+
+ return -1;
+}
+
+int AccessibilityTableRow::ariaRowIndex() const
+{
+ const AtomicString& rowIndexValue = getAttribute(aria_rowindexAttr);
+ if (rowIndexValue.toInt() >= 1)
+ return rowIndexValue.toInt();
+
+ return -1;
+}
+
} // namespace WebCore