This source file includes following definitions.
- create
- canSetSelectedChildrenAttribute
- addChildren
- setSelectedChildren
- selectedChildren
- listBoxOptionAXObject
- elementAccessibilityHitTest
#include "config.h"
#include "core/accessibility/AXListBox.h"
#include "core/accessibility/AXListBoxOption.h"
#include "core/accessibility/AXObjectCache.h"
#include "core/html/HTMLSelectElement.h"
#include "core/rendering/RenderListBox.h"
namespace WebCore {
using namespace HTMLNames;
AXListBox::AXListBox(RenderObject* renderer)
: AXRenderObject(renderer)
{
}
AXListBox::~AXListBox()
{
}
PassRefPtr<AXListBox> AXListBox::create(RenderObject* renderer)
{
return adoptRef(new AXListBox(renderer));
}
bool AXListBox::canSetSelectedChildrenAttribute() const
{
Node* selectNode = m_renderer->node();
if (!selectNode)
return false;
return !toHTMLSelectElement(selectNode)->isDisabledFormControl();
}
void AXListBox::addChildren()
{
Node* selectNode = m_renderer->node();
if (!selectNode)
return;
m_haveChildren = true;
const Vector<HTMLElement*>& listItems = toHTMLSelectElement(selectNode)->listItems();
unsigned length = listItems.size();
for (unsigned i = 0; i < length; i++) {
AXObject* listOption = listBoxOptionAXObject(listItems[i]);
if (listOption && !listOption->accessibilityIsIgnored())
m_children.append(listOption);
}
}
void AXListBox::setSelectedChildren(AccessibilityChildrenVector& children)
{
if (!canSetSelectedChildrenAttribute())
return;
Node* selectNode = m_renderer->node();
if (!selectNode)
return;
unsigned length = m_children.size();
for (unsigned i = 0; i < length; i++) {
AXListBoxOption* listBoxOption = toAXListBoxOption(m_children[i].get());
if (listBoxOption->isSelected())
listBoxOption->setSelected(false);
}
length = children.size();
for (unsigned i = 0; i < length; i++) {
AXObject* obj = children[i].get();
if (obj->roleValue() != ListBoxOptionRole)
continue;
toAXListBoxOption(obj)->setSelected(true);
}
}
void AXListBox::selectedChildren(AccessibilityChildrenVector& result)
{
ASSERT(result.isEmpty());
if (!hasChildren())
addChildren();
unsigned length = m_children.size();
for (unsigned i = 0; i < length; i++) {
if (toAXListBoxOption(m_children[i].get())->isSelected())
result.append(m_children[i]);
}
}
AXObject* AXListBox::listBoxOptionAXObject(HTMLElement* element) const
{
if (!element || isHTMLHRElement(*element))
return 0;
AXObject* listBoxObject = m_renderer->document().axObjectCache()->getOrCreate(ListBoxOptionRole);
toAXListBoxOption(listBoxObject)->setHTMLElement(element);
return listBoxObject;
}
AXObject* AXListBox::elementAccessibilityHitTest(const IntPoint& point) const
{
if (!m_renderer)
return 0;
Node* node = m_renderer->node();
if (!node)
return 0;
LayoutRect parentRect = elementRect();
AXObject* listBoxOption = 0;
unsigned length = m_children.size();
for (unsigned i = 0; i < length; i++) {
LayoutRect rect = toRenderListBox(m_renderer)->itemBoundingBoxRect(parentRect.location(), i);
if (rect.contains(point)) {
listBoxOption = m_children[i].get();
break;
}
}
if (listBoxOption && !listBoxOption->accessibilityIsIgnored())
return listBoxOption;
return axObjectCache()->getOrCreate(m_renderer);
}
}