AccessibilityMenuListPopup.cpp [plain text]
#include "config.h"
#include "AccessibilityMenuListPopup.h"
#include "AXObjectCache.h"
#include "AccessibilityMenuList.h"
#include "AccessibilityMenuListOption.h"
#include "HTMLNames.h"
#include "HTMLOptionElement.h"
#include "HTMLSelectElement.h"
#include "RenderMenuList.h"
namespace WebCore {
using namespace HTMLNames;
AccessibilityMenuListPopup::AccessibilityMenuListPopup()
{
}
bool AccessibilityMenuListPopup::isVisible() const
{
return false;
}
bool AccessibilityMenuListPopup::isOffScreen() const
{
if (!m_parent)
return true;
return m_parent->isCollapsed();
}
bool AccessibilityMenuListPopup::isEnabled() const
{
if (!m_parent)
return false;
return m_parent->isEnabled();
}
bool AccessibilityMenuListPopup::computeAccessibilityIsIgnored() const
{
return accessibilityIsIgnoredByDefault();
}
AccessibilityMenuListOption* AccessibilityMenuListPopup::menuListOptionAccessibilityObject(HTMLElement* element) const
{
if (!is<HTMLOptionElement>(element) || !element->inRenderedDocument())
return nullptr;
auto& option = downcast<AccessibilityMenuListOption>(*document()->axObjectCache()->getOrCreate(MenuListOptionRole));
option.setElement(element);
return &option;
}
bool AccessibilityMenuListPopup::press()
{
if (!m_parent)
return false;
m_parent->press();
return true;
}
void AccessibilityMenuListPopup::addChildren()
{
if (!m_parent)
return;
Node* selectNode = m_parent->node();
if (!selectNode)
return;
m_haveChildren = true;
for (const auto& listItem : downcast<HTMLSelectElement>(*selectNode).listItems()) {
AccessibilityMenuListOption* option = menuListOptionAccessibilityObject(listItem);
if (option) {
option->setParent(this);
m_children.append(option);
}
}
}
void AccessibilityMenuListPopup::childrenChanged()
{
AXObjectCache* cache = axObjectCache();
for (size_t i = m_children.size(); i > 0 ; --i) {
AccessibilityObject* child = m_children[i - 1].get();
if (child->actionElement() && !child->actionElement()->inRenderedDocument()) {
child->detachFromParent();
cache->remove(child->axObjectID());
}
}
m_children.clear();
m_haveChildren = false;
addChildren();
}
void AccessibilityMenuListPopup::didUpdateActiveOption(int optionIndex)
{
ASSERT_ARG(optionIndex, optionIndex >= 0);
ASSERT_ARG(optionIndex, optionIndex < static_cast<int>(m_children.size()));
AXObjectCache* cache = axObjectCache();
RefPtr<AccessibilityObject> child = m_children[optionIndex].get();
cache->postNotification(child.get(), document(), AXObjectCache::AXFocusedUIElementChanged, TargetElement, PostSynchronously);
cache->postNotification(child.get(), document(), AXObjectCache::AXMenuListItemSelected, TargetElement, PostSynchronously);
}
}