1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1.  Redistributions of source code must retain the above copyright
9 *     notice, this list of conditions and the following disclaimer.
10 * 2.  Redistributions in binary form must reproduce the above copyright
11 *     notice, this list of conditions and the following disclaimer in the
12 *     documentation and/or other materials provided with the distribution.
13 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 *     its contributors may be used to endorse or promote products derived
15 *     from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "config.h"
30#include "core/accessibility/AccessibilityTableRow.h"
31
32#include "core/accessibility/AccessibilityTableCell.h"
33#include "core/rendering/RenderTableRow.h"
34
35using namespace std;
36
37namespace WebCore {
38
39using namespace HTMLNames;
40
41AccessibilityTableRow::AccessibilityTableRow(RenderObject* renderer)
42    : AccessibilityRenderObject(renderer)
43{
44}
45
46AccessibilityTableRow::~AccessibilityTableRow()
47{
48}
49
50PassRefPtr<AccessibilityTableRow> AccessibilityTableRow::create(RenderObject* renderer)
51{
52    return adoptRef(new AccessibilityTableRow(renderer));
53}
54
55AccessibilityRole AccessibilityTableRow::determineAccessibilityRole()
56{
57    if (!isTableRow())
58        return AccessibilityRenderObject::determineAccessibilityRole();
59
60    m_ariaRole = determineAriaRoleAttribute();
61
62    AccessibilityRole ariaRole = ariaRoleAttribute();
63    if (ariaRole != UnknownRole)
64        return ariaRole;
65
66    return RowRole;
67}
68
69bool AccessibilityTableRow::isTableRow() const
70{
71    AccessibilityObject* table = parentTable();
72    if (!table || !table->isAccessibilityTable())
73        return false;
74
75    return true;
76}
77
78AccessibilityObject* AccessibilityTableRow::observableObject() const
79{
80    // This allows the table to be the one who sends notifications about tables.
81    return parentTable();
82}
83
84bool AccessibilityTableRow::computeAccessibilityIsIgnored() const
85{
86    AccessibilityObjectInclusion decision = defaultObjectInclusion();
87    if (decision == IncludeObject)
88        return false;
89    if (decision == IgnoreObject)
90        return true;
91
92    if (!isTableRow())
93        return AccessibilityRenderObject::computeAccessibilityIsIgnored();
94
95    return false;
96}
97
98AccessibilityObject* AccessibilityTableRow::parentTable() const
99{
100    AccessibilityObject* parent = parentObjectUnignored();
101    if (!parent || !parent->isAccessibilityTable())
102        return 0;
103
104    return parent;
105}
106
107AccessibilityObject* AccessibilityTableRow::headerObject()
108{
109    if (!m_renderer || !m_renderer->isTableRow())
110        return 0;
111
112    AccessibilityChildrenVector rowChildren = children();
113    if (!rowChildren.size())
114        return 0;
115
116    // check the first element in the row to see if it is a TH element
117    AccessibilityObject* cell = rowChildren[0].get();
118    if (!cell->isTableCell())
119        return 0;
120
121    RenderObject* cellRenderer = static_cast<AccessibilityTableCell*>(cell)->renderer();
122    if (!cellRenderer)
123        return 0;
124
125    Node* cellNode = cellRenderer->node();
126    if (!cellNode || !cellNode->hasTagName(thTag))
127        return 0;
128
129    return cell;
130}
131
132} // namespace WebCore
133