2
* Copyright (C) 2008 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
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.
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.
30
#include "AccessibilityListBoxOption.h"
32
#include "AXObjectCache.h"
33
#include "AccessibilityListBox.h"
35
#include "HTMLElement.h"
36
#include "HTMLNames.h"
37
#include "HTMLOptionElement.h"
38
#include "HTMLOptGroupElement.h"
39
#include "HTMLSelectElement.h"
41
#include "RenderObject.h"
42
#include "RenderListBox.h"
48
using namespace HTMLNames;
50
AccessibilityListBoxOption::AccessibilityListBoxOption()
55
AccessibilityListBoxOption::~AccessibilityListBoxOption()
59
PassRefPtr<AccessibilityListBoxOption> AccessibilityListBoxOption::create()
61
return adoptRef(new AccessibilityListBoxOption());
64
bool AccessibilityListBoxOption::isEnabled() const
69
if (m_optionElement->hasTagName(optgroupTag))
75
bool AccessibilityListBoxOption::isSelected() const
80
if (!m_optionElement->hasTagName(optionTag))
83
return static_cast<HTMLOptionElement*>(m_optionElement)->selected();
86
IntRect AccessibilityListBoxOption::elementRect() const
92
HTMLSelectElement* listBoxParentNode = listBoxOptionParentNode();
93
if (!listBoxParentNode)
96
RenderObject* listBoxRenderer = listBoxParentNode->renderer();
100
IntRect parentRect = listBoxRenderer->document()->axObjectCache()->get(listBoxRenderer)->boundingBoxRect();
101
int index = listBoxOptionIndex();
103
rect = static_cast<RenderListBox*>(listBoxRenderer)->itemBoundingBoxRect(parentRect.x(), parentRect.y(), index);
108
bool AccessibilityListBoxOption::canSetSelectedAttribute() const
110
if (!m_optionElement)
113
if (!m_optionElement->hasTagName(optionTag))
116
if (m_optionElement->disabled())
119
HTMLSelectElement* selectElement = listBoxOptionParentNode();
120
if (selectElement && selectElement->disabled())
126
String AccessibilityListBoxOption::stringValue() const
128
if (!m_optionElement)
131
if (m_optionElement->hasTagName(optionTag))
132
return static_cast<HTMLOptionElement*>(m_optionElement)->text();
134
if (m_optionElement->hasTagName(optgroupTag))
135
return static_cast<HTMLOptGroupElement*>(m_optionElement)->groupLabelText();
140
IntSize AccessibilityListBoxOption::size() const
142
return elementRect().size();
145
Element* AccessibilityListBoxOption::actionElement() const
147
return m_optionElement;
150
AccessibilityObject* AccessibilityListBoxOption::parentObject() const
152
HTMLSelectElement* parentNode = listBoxOptionParentNode();
156
return m_optionElement->document()->axObjectCache()->get(parentNode->renderer());
159
void AccessibilityListBoxOption::setSelected(bool selected)
161
HTMLSelectElement* selectElement = listBoxOptionParentNode();
165
if (!canSetSelectedAttribute())
168
bool isOptionSelected = isSelected();
169
if ((isOptionSelected && selected) || (!isOptionSelected && !selected))
172
selectElement->accessKeySetSelectedIndex(listBoxOptionIndex());
175
HTMLSelectElement* AccessibilityListBoxOption::listBoxOptionParentNode() const
177
if (!m_optionElement)
180
if (m_optionElement->hasTagName(optionTag))
181
return static_cast<HTMLOptionElement*>(m_optionElement)->ownerSelectElement();
183
if (m_optionElement->hasTagName(optgroupTag))
184
return static_cast<HTMLOptGroupElement*>(m_optionElement)->ownerSelectElement();
189
int AccessibilityListBoxOption::listBoxOptionIndex() const
191
if (!m_optionElement)
194
HTMLSelectElement* selectElement = listBoxOptionParentNode();
198
const Vector<HTMLElement*>& listItems = selectElement->listItems();
199
unsigned length = listItems.size();
200
for (unsigned i = 0; i < length; i++)
201
if (listItems[i] == m_optionElement)
207
} // namespace WebCore