AccessibilityARIAGridRow.cpp [plain text]
#include "config.h"
#include "AccessibilityARIAGridRow.h"
#include "AccessibilityObject.h"
#include "AccessibilityTable.h"
namespace WebCore {
AccessibilityARIAGridRow::AccessibilityARIAGridRow(RenderObject* renderer)
: AccessibilityTableRow(renderer)
{
}
AccessibilityARIAGridRow::~AccessibilityARIAGridRow() = default;
Ref<AccessibilityARIAGridRow> AccessibilityARIAGridRow::create(RenderObject* renderer)
{
return adoptRef(*new AccessibilityARIAGridRow(renderer));
}
bool AccessibilityARIAGridRow::isARIATreeGridRow() const
{
AccessibilityObject* parent = parentTable();
if (!parent)
return false;
return parent->isTreeGrid();
}
AXCoreObject::AccessibilityChildrenVector AccessibilityARIAGridRow::disclosedRows()
{
AccessibilityChildrenVector disclosedRows;
AccessibilityObject* parent = parentObjectUnignored();
if (!is<AccessibilityTable>(*parent) || !downcast<AccessibilityTable>(*parent).isExposable())
return disclosedRows;
int index = rowIndex();
if (index < 0)
return disclosedRows;
unsigned level = hierarchicalLevel();
auto allRows = parent->rows();
int rowCount = allRows.size();
for (int k = index + 1; k < rowCount; ++k) {
auto* row = allRows[k].get();
if (row->hierarchicalLevel() != level + 1)
break;
disclosedRows.append(row);
}
return disclosedRows;
}
AXCoreObject* AccessibilityARIAGridRow::disclosedByRow() const
{
AccessibilityObject* parent = parentObjectUnignored();
if (!is<AccessibilityTable>(*parent) || !downcast<AccessibilityTable>(*parent).isExposable())
return nullptr;
unsigned level = hierarchicalLevel();
if (level <= 1)
return nullptr;
int index = rowIndex();
auto allRows = parent->rows();
int rowCount = allRows.size();
if (index >= rowCount)
return nullptr;
for (int k = index - 1; k >= 0; --k) {
auto* row = allRows[k].get();
if (row->hierarchicalLevel() == level - 1)
return row;
}
return nullptr;
}
AccessibilityObject* AccessibilityARIAGridRow::parentObjectUnignored() const
{
return parentTable();
}
AccessibilityTable* AccessibilityARIAGridRow::parentTable() const
{
for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
if (is<AccessibilityTable>(*parent)) {
AccessibilityTable& tableParent = downcast<AccessibilityTable>(*parent);
if (tableParent.isExposable() && (tableParent.isAriaTable() || node()->hasTagName(HTMLNames::trTag)))
return &tableParent;
}
}
return nullptr;
}
AXCoreObject* AccessibilityARIAGridRow::headerObject()
{
for (const auto& child : children()) {
if (child->ariaRoleAttribute() == AccessibilityRole::RowHeader)
return child.get();
}
return nullptr;
}
}