AccessibilityARIAGridCell.cpp [plain text]
#include "config.h"
#include "AccessibilityARIAGridCell.h"
#include "AccessibilityObject.h"
#include "AccessibilityTable.h"
#include "AccessibilityTableRow.h"
#include "HTMLNames.h"
namespace WebCore {
using namespace HTMLNames;
AccessibilityARIAGridCell::AccessibilityARIAGridCell(RenderObject* renderer)
: AccessibilityTableCell(renderer)
{
}
AccessibilityARIAGridCell::~AccessibilityARIAGridCell()
{
}
Ref<AccessibilityARIAGridCell> AccessibilityARIAGridCell::create(RenderObject* renderer)
{
return adoptRef(*new AccessibilityARIAGridCell(renderer));
}
AccessibilityTable* AccessibilityARIAGridCell::parentTable() const
{
for (AccessibilityObject* parent = parentObjectUnignored(); parent; parent = parent->parentObjectUnignored()) {
if (is<AccessibilityTable>(*parent) && downcast<AccessibilityTable>(*parent).isExposableThroughAccessibility())
return downcast<AccessibilityTable>(parent);
}
return nullptr;
}
void AccessibilityARIAGridCell::rowIndexRange(std::pair<unsigned, unsigned>& rowRange) const
{
AccessibilityObject* parent = parentObjectUnignored();
if (!parent)
return;
if (is<AccessibilityTableRow>(*parent)) {
rowRange.first = downcast<AccessibilityTableRow>(*parent).rowIndex();
} else if (is<AccessibilityTable>(*parent) && downcast<AccessibilityTable>(*parent).isExposableThroughAccessibility()) {
unsigned columnCount = downcast<AccessibilityTable>(*parent).columnCount();
if (!columnCount)
return;
const auto& siblings = parent->children();
unsigned childrenSize = siblings.size();
for (unsigned k = 0; k < childrenSize; ++k) {
if (siblings[k].get() == this) {
rowRange.first = k / columnCount;
break;
}
}
}
rowRange.second = ariaRowSpanWithRowIndex(rowRange.first);
}
unsigned AccessibilityARIAGridCell::ariaRowSpanWithRowIndex(unsigned rowIndex) const
{
int rowSpan = AccessibilityTableCell::ariaRowSpan();
if (rowSpan == -1) {
std::pair<unsigned, unsigned> range;
AccessibilityTableCell::rowIndexRange(range);
return std::max(static_cast<int>(range.second), 1);
}
AccessibilityObject* parent = parentObjectUnignored();
if (!parent)
return 1;
if (!rowSpan) {
rowSpan = 1;
if (AccessibilityObject* parentRowGroup = this->parentRowGroup()) {
if (is<AccessibilityTable>(*parentRowGroup))
rowSpan = downcast<AccessibilityTable>(*parentRowGroup).rowCount() - rowIndex;
else if (is<AccessibilityTableRow>(*parent)) {
const auto& siblings = parentRowGroup->children();
unsigned rowCount = siblings.size();
for (unsigned k = 0; k < rowCount; ++k) {
if (siblings[k].get() == parent) {
rowSpan = rowCount - k;
break;
}
}
}
}
}
return rowSpan;
}
void AccessibilityARIAGridCell::columnIndexRange(std::pair<unsigned, unsigned>& columnRange) const
{
AccessibilityObject* parent = parentObjectUnignored();
if (!parent)
return;
if (!is<AccessibilityTableRow>(*parent)
&& !(is<AccessibilityTable>(*parent) && downcast<AccessibilityTable>(*parent).isExposableThroughAccessibility()))
return;
const AccessibilityChildrenVector& siblings = parent->children();
unsigned childrenSize = siblings.size();
unsigned indexWithSpan = 0;
for (unsigned k = 0; k < childrenSize; ++k) {
auto child = siblings[k].get();
if (child == this) {
columnRange.first = indexWithSpan;
break;
}
indexWithSpan += is<AccessibilityTableCell>(*child) ? std::max(downcast<AccessibilityTableCell>(*child).ariaColumnSpan(), 1) : 1;
}
int columnSpan = AccessibilityTableCell::ariaColumnSpan();
if (columnSpan == -1) {
std::pair<unsigned, unsigned> range;
AccessibilityTableCell::columnIndexRange(range);
columnSpan = range.second;
}
columnRange.second = std::max(columnSpan, 1);
}
AccessibilityObject* AccessibilityARIAGridCell::parentRowGroup() const
{
for (AccessibilityObject* parent = parentObject(); parent; parent = parent->parentObject()) {
if (parent->hasTagName(theadTag) || parent->hasTagName(tbodyTag) || parent->hasTagName(tfootTag) || parent->roleValue() == RowGroupRole)
return parent;
}
return parentTable();
}
String AccessibilityARIAGridCell::ariaReadOnlyValue() const
{
if (hasAttribute(aria_readonlyAttr))
return getAttribute(aria_readonlyAttr).string().convertToASCIILowercase();
if (AccessibilityObject* parent = parentTable())
return parent->ariaReadOnlyValue();
return String();
}
}