OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 12 matching lines...) Expand all Loading... |
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 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 | 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 | 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. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "core/accessibility/AXListBoxOption.h" | 30 #include "core/accessibility/AXListBoxOption.h" |
31 | 31 |
32 #include "core/accessibility/AXObjectCache.h" | 32 #include "core/accessibility/AXObjectCache.h" |
33 #include "core/html/HTMLOptGroupElement.h" | |
34 #include "core/html/HTMLOptionElement.h" | 33 #include "core/html/HTMLOptionElement.h" |
35 #include "core/html/HTMLSelectElement.h" | 34 #include "core/html/HTMLSelectElement.h" |
36 #include "core/rendering/RenderListBox.h" | 35 #include "core/rendering/RenderListBox.h" |
37 | 36 |
38 | 37 |
39 namespace WebCore { | 38 namespace WebCore { |
40 | 39 |
41 using namespace HTMLNames; | 40 using namespace HTMLNames; |
42 | 41 |
43 AXListBoxOption::AXListBoxOption() | 42 AXListBoxOption::AXListBoxOption(RenderObject* renderer) |
44 : m_optionElement(0) | 43 : AXRenderObject(renderer) |
45 { | 44 { |
46 } | 45 } |
47 | 46 |
48 AXListBoxOption::~AXListBoxOption() | 47 AXListBoxOption::~AXListBoxOption() |
49 { | 48 { |
50 } | 49 } |
51 | 50 |
52 PassRefPtr<AXListBoxOption> AXListBoxOption::create() | 51 PassRefPtr<AXListBoxOption> AXListBoxOption::create(RenderObject* renderer) |
53 { | 52 { |
54 return adoptRef(new AXListBoxOption()); | 53 return adoptRef(new AXListBoxOption(renderer)); |
55 } | 54 } |
56 | 55 |
57 bool AXListBoxOption::isEnabled() const | 56 bool AXListBoxOption::isEnabled() const |
58 { | 57 { |
59 if (!m_optionElement) | 58 if (!node()) |
60 return false; | |
61 | |
62 if (isHTMLOptGroupElement(*m_optionElement)) | |
63 return false; | 59 return false; |
64 | 60 |
65 if (equalIgnoringCase(getAttribute(aria_disabledAttr), "true")) | 61 if (equalIgnoringCase(getAttribute(aria_disabledAttr), "true")) |
66 return false; | 62 return false; |
67 | 63 |
68 if (m_optionElement->hasAttribute(disabledAttr)) | 64 if (toElement(node())->hasAttribute(disabledAttr)) |
69 return false; | 65 return false; |
70 | 66 |
71 return true; | 67 return true; |
72 } | 68 } |
73 | 69 |
74 bool AXListBoxOption::isSelected() const | 70 bool AXListBoxOption::isSelected() const |
75 { | 71 { |
76 if (!isHTMLOptionElement(m_optionElement)) | 72 return isHTMLOptionElement(node()) && toHTMLOptionElement(node())->selected(
); |
77 return false; | |
78 | |
79 return toHTMLOptionElement(m_optionElement)->selected(); | |
80 } | 73 } |
81 | 74 |
82 bool AXListBoxOption::isSelectedOptionActive() const | 75 bool AXListBoxOption::isSelectedOptionActive() const |
83 { | 76 { |
84 HTMLSelectElement* listBoxParentNode = listBoxOptionParentNode(); | 77 HTMLSelectElement* listBoxParentNode = listBoxOptionParentNode(); |
85 if (!listBoxParentNode) | 78 if (!listBoxParentNode) |
86 return false; | 79 return false; |
87 | 80 |
88 return listBoxParentNode->activeSelectionEndListIndex() == listBoxOptionInde
x(); | 81 return listBoxParentNode->activeSelectionEndListIndex() == listBoxOptionInde
x(); |
89 } | 82 } |
90 | 83 |
91 LayoutRect AXListBoxOption::elementRect() const | |
92 { | |
93 LayoutRect rect; | |
94 if (!m_optionElement) | |
95 return rect; | |
96 | |
97 HTMLSelectElement* listBoxParentNode = listBoxOptionParentNode(); | |
98 if (!listBoxParentNode) | |
99 return rect; | |
100 | |
101 RenderObject* listBoxRenderer = listBoxParentNode->renderer(); | |
102 if (!listBoxRenderer) | |
103 return rect; | |
104 | |
105 LayoutRect parentRect = listBoxRenderer->document().axObjectCache()->getOrCr
eate(listBoxRenderer)->elementRect(); | |
106 int index = listBoxOptionIndex(); | |
107 if (index != -1) | |
108 rect = toRenderListBox(listBoxRenderer)->itemBoundingBoxRect(parentRect.
location(), index); | |
109 | |
110 return rect; | |
111 } | |
112 | |
113 bool AXListBoxOption::computeAccessibilityIsIgnored() const | 84 bool AXListBoxOption::computeAccessibilityIsIgnored() const |
114 { | 85 { |
115 if (!m_optionElement) | 86 if (!node()) |
116 return true; | 87 return true; |
117 | 88 |
118 if (accessibilityIsIgnoredByDefault()) | 89 if (accessibilityIsIgnoredByDefault()) |
119 return true; | 90 return true; |
120 | 91 |
121 return parentObject()->accessibilityIsIgnored(); | 92 return false; |
122 } | 93 } |
123 | 94 |
124 bool AXListBoxOption::canSetSelectedAttribute() const | 95 bool AXListBoxOption::canSetSelectedAttribute() const |
125 { | 96 { |
126 if (!isHTMLOptionElement(m_optionElement)) | 97 if (!isHTMLOptionElement(node())) |
127 return false; | 98 return false; |
128 | 99 |
129 if (m_optionElement->isDisabledFormControl()) | 100 if (toHTMLOptionElement(node())->isDisabledFormControl()) |
130 return false; | 101 return false; |
131 | 102 |
132 HTMLSelectElement* selectElement = listBoxOptionParentNode(); | 103 HTMLSelectElement* selectElement = listBoxOptionParentNode(); |
133 if (selectElement && selectElement->isDisabledFormControl()) | 104 if (selectElement && selectElement->isDisabledFormControl()) |
134 return false; | 105 return false; |
135 | 106 |
136 return true; | 107 return true; |
137 } | 108 } |
138 | 109 |
139 String AXListBoxOption::stringValue() const | 110 String AXListBoxOption::stringValue() const |
140 { | 111 { |
141 if (!m_optionElement) | 112 if (!node()) |
142 return String(); | 113 return String(); |
143 | 114 |
144 const AtomicString& ariaLabel = getAttribute(aria_labelAttr); | 115 const AtomicString& ariaLabel = getAttribute(aria_labelAttr); |
145 if (!ariaLabel.isNull()) | 116 if (!ariaLabel.isNull()) |
146 return ariaLabel; | 117 return ariaLabel; |
147 | 118 |
148 if (isHTMLOptionElement(*m_optionElement)) | 119 if (isHTMLOptionElement(node())) |
149 return toHTMLOptionElement(m_optionElement)->text(); | 120 return toHTMLOptionElement(node())->text(); |
150 | |
151 if (isHTMLOptGroupElement(*m_optionElement)) | |
152 return toHTMLOptGroupElement(m_optionElement)->groupLabelText(); | |
153 | 121 |
154 return String(); | 122 return String(); |
155 } | 123 } |
156 | 124 |
157 Element* AXListBoxOption::actionElement() const | |
158 { | |
159 return m_optionElement; | |
160 } | |
161 | |
162 AXObject* AXListBoxOption::parentObject() const | |
163 { | |
164 HTMLSelectElement* parentNode = listBoxOptionParentNode(); | |
165 if (!parentNode) | |
166 return 0; | |
167 | |
168 return m_optionElement->document().axObjectCache()->getOrCreate(parentNode); | |
169 } | |
170 | |
171 void AXListBoxOption::setSelected(bool selected) | 125 void AXListBoxOption::setSelected(bool selected) |
172 { | 126 { |
173 HTMLSelectElement* selectElement = listBoxOptionParentNode(); | 127 HTMLSelectElement* selectElement = listBoxOptionParentNode(); |
174 if (!selectElement) | 128 if (!selectElement) |
175 return; | 129 return; |
176 | 130 |
177 if (!canSetSelectedAttribute()) | 131 if (!canSetSelectedAttribute()) |
178 return; | 132 return; |
179 | 133 |
180 bool isOptionSelected = isSelected(); | 134 bool isOptionSelected = isSelected(); |
181 if ((isOptionSelected && selected) || (!isOptionSelected && !selected)) | 135 if ((isOptionSelected && selected) || (!isOptionSelected && !selected)) |
182 return; | 136 return; |
183 | 137 |
184 // Convert from the entire list index to the option index. | 138 // Convert from the entire list index to the option index. |
185 int optionIndex = selectElement->listToOptionIndex(listBoxOptionIndex()); | 139 int optionIndex = selectElement->listToOptionIndex(listBoxOptionIndex()); |
186 selectElement->accessKeySetSelectedIndex(optionIndex); | 140 selectElement->accessKeySetSelectedIndex(optionIndex); |
187 } | 141 } |
188 | 142 |
189 HTMLSelectElement* AXListBoxOption::listBoxOptionParentNode() const | 143 HTMLSelectElement* AXListBoxOption::listBoxOptionParentNode() const |
190 { | 144 { |
191 if (!m_optionElement) | 145 if (!node()) |
192 return 0; | 146 return 0; |
193 | 147 |
194 if (isHTMLOptionElement(*m_optionElement)) | 148 if (isHTMLOptionElement(node())) |
195 return toHTMLOptionElement(m_optionElement)->ownerSelectElement(); | 149 return toHTMLOptionElement(node())->ownerSelectElement(); |
196 | |
197 if (isHTMLOptGroupElement(*m_optionElement)) | |
198 return toHTMLOptGroupElement(m_optionElement)->ownerSelectElement(); | |
199 | 150 |
200 return 0; | 151 return 0; |
201 } | 152 } |
202 | 153 |
203 int AXListBoxOption::listBoxOptionIndex() const | 154 int AXListBoxOption::listBoxOptionIndex() const |
204 { | 155 { |
205 if (!m_optionElement) | |
206 return -1; | |
207 | |
208 HTMLSelectElement* selectElement = listBoxOptionParentNode(); | 156 HTMLSelectElement* selectElement = listBoxOptionParentNode(); |
209 if (!selectElement) | 157 if (!selectElement) |
210 return -1; | 158 return -1; |
211 | 159 |
212 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element->listItems(); | 160 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select
Element->listItems(); |
213 unsigned length = listItems.size(); | 161 unsigned length = listItems.size(); |
214 for (unsigned i = 0; i < length; i++) { | 162 for (unsigned i = 0; i < length; i++) { |
215 if (listItems[i] == m_optionElement) | 163 if (listItems[i] == node()) |
216 return i; | 164 return i; |
217 } | 165 } |
218 | 166 |
219 return -1; | 167 return -1; |
220 } | 168 } |
221 | 169 |
222 } // namespace WebCore | 170 } // namespace WebCore |
OLD | NEW |