2 * Copyright (C) 2010 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
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "AccessibilityMenuListPopup.h"
29 #include "AXObjectCache.h"
30 #include "AccessibilityMenuList.h"
31 #include "AccessibilityMenuListOption.h"
32 #include "HTMLNames.h"
33 #include "HTMLSelectElement.h"
34 #include "RenderMenuList.h"
38 using namespace HTMLNames;
40 AccessibilityMenuListPopup::AccessibilityMenuListPopup()
44 bool AccessibilityMenuListPopup::isVisible() const
49 bool AccessibilityMenuListPopup::isOffScreen() const
54 return m_parent->isCollapsed();
57 bool AccessibilityMenuListPopup::isEnabled() const
62 return m_parent->isEnabled();
65 bool AccessibilityMenuListPopup::computeAccessibilityIsIgnored() const
67 return accessibilityIsIgnoredByDefault();
70 AccessibilityMenuListOption* AccessibilityMenuListPopup::menuListOptionAccessibilityObject(HTMLElement* element) const
72 if (!element || !element->hasTagName(optionTag))
75 AccessibilityObject* object = document()->axObjectCache()->getOrCreate(MenuListOptionRole);
76 ASSERT_WITH_SECURITY_IMPLICATION(object->isMenuListOption());
78 AccessibilityMenuListOption* option = static_cast<AccessibilityMenuListOption*>(object);
79 option->setElement(element);
84 bool AccessibilityMenuListPopup::press() const
93 void AccessibilityMenuListPopup::addChildren()
98 Node* selectNode = m_parent->node();
102 m_haveChildren = true;
104 const Vector<HTMLElement*>& listItems = toHTMLSelectElement(selectNode)->listItems();
105 unsigned length = listItems.size();
106 for (unsigned i = 0; i < length; i++) {
107 AccessibilityMenuListOption* option = menuListOptionAccessibilityObject(listItems[i]);
109 option->setParent(this);
110 m_children.append(option);
115 void AccessibilityMenuListPopup::childrenChanged()
117 AXObjectCache* cache = axObjectCache();
118 for (size_t i = m_children.size(); i > 0 ; --i) {
119 AccessibilityObject* child = m_children[i - 1].get();
120 if (child->actionElement() && !child->actionElement()->attached()) {
121 child->detachFromParent();
122 cache->remove(child->axObjectID());
127 m_haveChildren = false;
131 void AccessibilityMenuListPopup::didUpdateActiveOption(int optionIndex)
133 ASSERT_ARG(optionIndex, optionIndex >= 0);
134 ASSERT_ARG(optionIndex, optionIndex < static_cast<int>(m_children.size()));
136 AXObjectCache* cache = axObjectCache();
137 RefPtr<AccessibilityObject> child = m_children[optionIndex].get();
139 cache->postNotification(child.get(), document(), AXObjectCache::AXFocusedUIElementChanged, true, PostSynchronously);
140 cache->postNotification(child.get(), document(), AXObjectCache::AXMenuListItemSelected, true, PostSynchronously);
143 } // namespace WebCore