• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "AccessibilityTableCell.h"
31 
32 #include "AXObjectCache.h"
33 #include "HTMLNames.h"
34 #include "RenderObject.h"
35 #include "RenderTableCell.h"
36 
37 using namespace std;
38 
39 namespace WebCore {
40 
41 using namespace HTMLNames;
42 
AccessibilityTableCell(RenderObject * renderer)43 AccessibilityTableCell::AccessibilityTableCell(RenderObject* renderer)
44     : AccessibilityRenderObject(renderer)
45 {
46 }
47 
~AccessibilityTableCell()48 AccessibilityTableCell::~AccessibilityTableCell()
49 {
50 }
51 
create(RenderObject * renderer)52 PassRefPtr<AccessibilityTableCell> AccessibilityTableCell::create(RenderObject* renderer)
53 {
54     return adoptRef(new AccessibilityTableCell(renderer));
55 }
56 
accessibilityIsIgnored() const57 bool AccessibilityTableCell::accessibilityIsIgnored() const
58 {
59     if (!isTableCell())
60         return AccessibilityRenderObject::accessibilityIsIgnored();
61 
62     return false;
63 }
64 
parentTable() const65 AccessibilityObject* AccessibilityTableCell::parentTable() const
66 {
67     if (!m_renderer || !m_renderer->isTableCell())
68         return false;
69 
70     return axObjectCache()->getOrCreate(toRenderTableCell(m_renderer)->table());
71 }
72 
isTableCell() const73 bool AccessibilityTableCell::isTableCell() const
74 {
75     AccessibilityObject* table = parentTable();
76     if (!table || !table->isDataTable())
77         return false;
78 
79     return true;
80 }
81 
roleValue() const82 AccessibilityRole AccessibilityTableCell::roleValue() const
83 {
84     if (!isTableCell())
85         return AccessibilityRenderObject::roleValue();
86 
87     return CellRole;
88 }
89 
rowIndexRange(pair<int,int> & rowRange)90 void AccessibilityTableCell::rowIndexRange(pair<int, int>& rowRange)
91 {
92     if (!m_renderer || !m_renderer->isTableCell())
93         return;
94 
95     RenderTableCell* renderCell = toRenderTableCell(m_renderer);
96     rowRange.first = renderCell->row();
97     rowRange.second = renderCell->rowSpan();
98 
99     // since our table might have multiple sections, we have to offset our row appropriately
100     RenderTableSection* section = renderCell->section();
101     RenderTable* table = renderCell->table();
102     if (!table || !section)
103         return;
104 
105     RenderTableSection* tableSection = table->header();
106     if (!tableSection)
107         tableSection = table->firstBody();
108 
109     unsigned rowOffset = 0;
110     while (tableSection) {
111         if (tableSection == section)
112             break;
113         rowOffset += tableSection->numRows();
114         tableSection = table->sectionBelow(tableSection, true);
115     }
116 
117     rowRange.first += rowOffset;
118 }
119 
columnIndexRange(pair<int,int> & columnRange)120 void AccessibilityTableCell::columnIndexRange(pair<int, int>& columnRange)
121 {
122     if (!m_renderer || !m_renderer->isTableCell())
123         return;
124 
125     RenderTableCell* renderCell = toRenderTableCell(m_renderer);
126     columnRange.first = renderCell->col();
127     columnRange.second = renderCell->colSpan();
128 }
129 
titleUIElement() const130 AccessibilityObject* AccessibilityTableCell::titleUIElement() const
131 {
132     // Try to find if the first cell in this row is a <th>. If it is,
133     // then it can act as the title ui element. (This is only in the
134     // case when the table is not appearing as an AXTable.)
135     if (isTableCell() || !m_renderer || !m_renderer->isTableCell())
136         return 0;
137 
138     // Table cells that are th cannot have title ui elements, since by definition
139     // they are title ui elements
140     Node* node = m_renderer->node();
141     if (node && node->hasTagName(thTag))
142         return 0;
143 
144     RenderTableCell* renderCell = toRenderTableCell(m_renderer);
145 
146     // If this cell is in the first column, there is no need to continue.
147     int col = renderCell->col();
148     if (!col)
149         return 0;
150 
151     int row = renderCell->row();
152 
153     RenderTableSection* section = renderCell->section();
154     if (!section)
155         return 0;
156 
157     RenderTableCell* headerCell = section->cellAt(row, 0).cell;
158     if (!headerCell || headerCell == renderCell)
159         return 0;
160 
161     Node* cellElement = headerCell->node();
162     if (!cellElement || !cellElement->hasTagName(thTag))
163         return 0;
164 
165     return axObjectCache()->getOrCreate(headerCell);
166 }
167 
168 } // namespace WebCore
169