Merge "[CherryPick] [WEBGL] Rename WEBKIT_WEBGL_lose_context to WEBGL_lose_context...
[framework/web/webkit-efl.git] / Source / WebCore / accessibility / AccessibilityTableColumn.cpp
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 "AccessibilityTableColumn.h"
31
32 #include "AXObjectCache.h"
33 #include "AccessibilityTableCell.h"
34 #include "HTMLNames.h"
35 #include "RenderTable.h"
36 #include "RenderTableCell.h"
37 #include "RenderTableSection.h"
38
39 using namespace std;
40
41 namespace WebCore {
42     
43 using namespace HTMLNames;
44
45 AccessibilityTableColumn::AccessibilityTableColumn()
46 {
47 }
48
49 AccessibilityTableColumn::~AccessibilityTableColumn()
50 {
51 }    
52
53 PassRefPtr<AccessibilityTableColumn> AccessibilityTableColumn::create()
54 {
55     return adoptRef(new AccessibilityTableColumn());
56 }
57
58 void AccessibilityTableColumn::setParent(AccessibilityObject* parent)
59 {
60     AccessibilityMockObject::setParent(parent);
61     
62     clearChildren();
63 }
64     
65 LayoutRect AccessibilityTableColumn::elementRect() const
66 {
67     // this will be filled in when addChildren is called
68     return m_columnRect;
69 }
70
71 AccessibilityObject* AccessibilityTableColumn::headerObject()
72 {
73     if (!m_parent)
74         return 0;
75     
76     RenderObject* renderer = m_parent->renderer();
77     if (!renderer)
78         return 0;
79     
80     if (!m_parent->isAccessibilityTable())
81         return 0;
82     
83     AccessibilityTable* parentTable = toAccessibilityTable(m_parent);
84     if (parentTable->isAriaTable()) {
85         AccessibilityChildrenVector rowChildren = children();
86         unsigned childrenCount = rowChildren.size();
87         for (unsigned i = 0; i < childrenCount; ++i) {
88             AccessibilityObject* cell = rowChildren[i].get();
89             if (cell->ariaRoleAttribute() == ColumnHeaderRole)
90                 return cell;
91         }
92         
93         return 0;
94     }
95
96     if (!renderer->isTable())
97         return 0;
98     
99     RenderTable* table = toRenderTable(renderer);
100     
101     AccessibilityObject* headerObject = 0;
102     
103     // try the <thead> section first. this doesn't require th tags
104     headerObject = headerObjectForSection(table->header(), false);
105
106     if (headerObject)
107         return headerObject;
108     
109     // now try for <th> tags in the first body
110     headerObject = headerObjectForSection(table->firstBody(), true);
111
112     return headerObject;
113 }
114
115 AccessibilityObject* AccessibilityTableColumn::headerObjectForSection(RenderTableSection* section, bool thTagRequired)
116 {
117     if (!section)
118         return 0;
119     
120     unsigned numCols = section->numColumns();
121     if (m_columnIndex >= numCols)
122         return 0;
123     
124     if (!section->numRows())
125         return 0;
126     
127     RenderTableCell* cell = 0;
128     // also account for cells that have a span
129     for (int testCol = m_columnIndex; testCol >= 0; --testCol) {
130         RenderTableCell* testCell = section->primaryCellAt(0, testCol);
131         if (!testCell)
132             continue;
133         
134         // we've reached a cell that doesn't even overlap our column 
135         // it can't be our header
136         if ((testCell->col() + (testCell->colSpan()-1)) < m_columnIndex)
137             break;
138         
139         Node* node = testCell->node();
140         if (!node)
141             continue;
142         
143         if (thTagRequired && !node->hasTagName(thTag))
144             continue;
145         
146         cell = testCell;
147     }
148     
149     if (!cell)
150         return 0;
151
152     return axObjectCache()->getOrCreate(cell);
153 }
154     
155 bool AccessibilityTableColumn::accessibilityIsIgnored() const
156 {
157     if (!m_parent)
158         return true;
159     
160 #if PLATFORM(GTK)
161     return true;
162 #endif
163     
164     return m_parent->accessibilityIsIgnored();
165 }
166     
167 void AccessibilityTableColumn::addChildren()
168 {
169     ASSERT(!m_haveChildren); 
170     
171     m_haveChildren = true;
172     if (!m_parent || !m_parent->isAccessibilityTable())
173         return;
174     
175     AccessibilityTable* parentTable = toAccessibilityTable(m_parent);
176     int numRows = parentTable->rowCount();
177     
178     for (int i = 0; i < numRows; i++) {
179         AccessibilityTableCell* cell = parentTable->cellForColumnAndRow(m_columnIndex, i);
180         if (!cell)
181             continue;
182         
183         // make sure the last one isn't the same as this one (rowspan cells)
184         if (m_children.size() > 0 && m_children.last() == cell)
185             continue;
186             
187         m_children.append(cell);
188         m_columnRect.unite(cell->elementRect());
189     }
190 }
191     
192 } // namespace WebCore