1 | /* |
2 | * Copyright (C) 2009 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 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 "AccessibilityARIAGrid.h" |
31 | |
32 | #include "AXObjectCache.h" |
33 | #include "AccessibilityARIAGridRow.h" |
34 | #include "AccessibilityTableCell.h" |
35 | #include "AccessibilityTableColumn.h" |
36 | #include "AccessibilityTableHeaderContainer.h" |
37 | #include "RenderObject.h" |
38 | #include "RenderTableSection.h" |
39 | |
40 | namespace WebCore { |
41 | |
42 | AccessibilityARIAGrid::AccessibilityARIAGrid(RenderObject* renderer) |
43 | : AccessibilityTable(renderer) |
44 | { |
45 | } |
46 | |
47 | AccessibilityARIAGrid::~AccessibilityARIAGrid() = default; |
48 | |
49 | Ref<AccessibilityARIAGrid> AccessibilityARIAGrid::create(RenderObject* renderer) |
50 | { |
51 | return adoptRef(*new AccessibilityARIAGrid(renderer)); |
52 | } |
53 | |
54 | bool AccessibilityARIAGrid::addTableCellChild(AccessibilityObject* child, HashSet<AccessibilityObject*>& appendedRows, unsigned& columnCount) |
55 | { |
56 | if (!child || (!is<AccessibilityTableRow>(*child) && !is<AccessibilityARIAGridRow>(*child))) |
57 | return false; |
58 | |
59 | auto& row = downcast<AccessibilityTableRow>(*child); |
60 | if (appendedRows.contains(&row)) |
61 | return false; |
62 | |
63 | // store the maximum number of columns |
64 | unsigned rowCellCount = row.children().size(); |
65 | if (rowCellCount > columnCount) |
66 | columnCount = rowCellCount; |
67 | |
68 | row.setRowIndex((int)m_rows.size()); |
69 | m_rows.append(&row); |
70 | |
71 | // Try adding the row if it's not ignoring accessibility, |
72 | // otherwise add its children (the cells) as the grid's children. |
73 | if (!row.accessibilityIsIgnored()) |
74 | m_children.append(&row); |
75 | else |
76 | m_children.appendVector(row.children()); |
77 | |
78 | appendedRows.add(&row); |
79 | return true; |
80 | } |
81 | |
82 | bool AccessibilityARIAGrid::isMultiSelectable() const |
83 | { |
84 | const AtomicString& ariaMultiSelectable = getAttribute(HTMLNames::aria_multiselectableAttr); |
85 | return !equalLettersIgnoringASCIICase(ariaMultiSelectable, "false" ); |
86 | } |
87 | |
88 | void AccessibilityARIAGrid::addRowDescendant(AccessibilityObject* rowChild, HashSet<AccessibilityObject*>& appendedRows, unsigned& columnCount) |
89 | { |
90 | if (!rowChild) |
91 | return; |
92 | |
93 | if (!rowChild->isTableRow() || !rowChild->node()) { |
94 | // Although a "grid" should have rows as its direct descendants, if this is not a table row, |
95 | // or this row is anonymous, dive deeper into the descendants to try to find a valid row. |
96 | for (const auto& child : rowChild->children()) |
97 | addRowDescendant(child.get(), appendedRows, columnCount); |
98 | } else |
99 | addTableCellChild(rowChild, appendedRows, columnCount); |
100 | } |
101 | |
102 | void AccessibilityARIAGrid::addChildren() |
103 | { |
104 | ASSERT(!m_haveChildren); |
105 | |
106 | if (!isExposableThroughAccessibility()) { |
107 | AccessibilityRenderObject::addChildren(); |
108 | return; |
109 | } |
110 | |
111 | m_haveChildren = true; |
112 | if (!m_renderer) |
113 | return; |
114 | |
115 | AXObjectCache* axCache = m_renderer->document().axObjectCache(); |
116 | |
117 | // Add the children rows but be mindful in case there are footer sections in this table. |
118 | HashSet<AccessibilityObject*> appendedRows; |
119 | unsigned columnCount = 0; |
120 | AccessibilityChildrenVector ; |
121 | for (RefPtr<AccessibilityObject> child = firstChild(); child; child = child->nextSibling()) { |
122 | bool = false; |
123 | if (RenderObject* childRenderer = child->renderer()) { |
124 | if (is<RenderTableSection>(*childRenderer)) { |
125 | RenderTableSection& childSection = downcast<RenderTableSection>(*childRenderer); |
126 | if (&childSection == childSection.table()->footer()) { |
127 | footerSections.append(child); |
128 | footerSection = true; |
129 | } |
130 | } |
131 | } |
132 | if (!footerSection) |
133 | addRowDescendant(child.get(), appendedRows, columnCount); |
134 | } |
135 | |
136 | for (const auto& : footerSections) |
137 | addRowDescendant(footerSection.get(), appendedRows, columnCount); |
138 | |
139 | // make the columns based on the number of columns in the first body |
140 | for (unsigned i = 0; i < columnCount; ++i) { |
141 | auto& column = downcast<AccessibilityTableColumn>(*axCache->getOrCreate(AccessibilityRole::Column)); |
142 | column.setColumnIndex(static_cast<int>(i)); |
143 | column.setParent(this); |
144 | m_columns.append(&column); |
145 | if (!column.accessibilityIsIgnored()) |
146 | m_children.append(&column); |
147 | } |
148 | |
149 | AccessibilityObject* = headerContainer(); |
150 | if (headerContainerObject && !headerContainerObject->accessibilityIsIgnored()) |
151 | m_children.append(headerContainerObject); |
152 | } |
153 | |
154 | } // namespace WebCore |
155 | |