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()
45 bool AccessibilityMenuListPopup::isVisible() const
50 bool AccessibilityMenuListPopup::isOffScreen() const
52 return m_menuList->isCollapsed();
55 AccessibilityObject* AccessibilityMenuListPopup::parentObject() const
60 bool AccessibilityMenuListPopup::isEnabled() const
62 return m_menuList->isEnabled();
65 AccessibilityMenuListOption* AccessibilityMenuListPopup::menuListOptionAccessibilityObject(HTMLElement* element) const
67 if (!element || !element->hasTagName(optionTag))
70 AccessibilityObject* object = m_menuList->renderer()->document()->axObjectCache()->getOrCreate(MenuListOptionRole);
71 ASSERT(object->isMenuListOption());
73 AccessibilityMenuListOption* option = static_cast<AccessibilityMenuListOption*>(object);
74 option->setElement(element);
79 bool AccessibilityMenuListPopup::press() const
85 void AccessibilityMenuListPopup::addChildren()
87 Node* selectNode = m_menuList->renderer()->node();
91 m_haveChildren = true;
93 ASSERT(selectNode->hasTagName(selectTag));
95 const Vector<Element*>& listItems = static_cast<HTMLSelectElement*>(selectNode)->listItems();
96 unsigned length = listItems.size();
97 for (unsigned i = 0; i < length; i++) {
98 AccessibilityMenuListOption* option = menuListOptionAccessibilityObject(toHTMLElement(listItems[i]));
100 option->setParent(this);
101 m_children.append(option);
106 void AccessibilityMenuListPopup::childrenChanged()
108 for (size_t i = m_children.size(); i > 0 ; --i) {
109 AccessibilityObject* child = m_children[i - 1].get();
110 if (child->actionElement() && !child->actionElement()->attached()) {
111 m_menuList->renderer()->document()->axObjectCache()->remove(child->axObjectID());
115 m_haveChildren = false;
119 void AccessibilityMenuListPopup::setMenuList(AccessibilityMenuList* menuList)
121 ASSERT_ARG(menuList, menuList);
123 m_menuList = menuList;
126 void AccessibilityMenuListPopup::didUpdateActiveOption(int optionIndex)
128 ASSERT_ARG(optionIndex, optionIndex >= 0);
129 ASSERT_ARG(optionIndex, optionIndex < static_cast<int>(m_children.size()));
131 RefPtr<Document> document = m_menuList->renderer()->document();
132 AXObjectCache* cache = document->axObjectCache();
133 RefPtr<AccessibilityObject> child = m_children[optionIndex].get();
135 cache->postNotification(child.get(), document.get(), AXObjectCache::AXFocusedUIElementChanged, true, PostSynchronously);
136 cache->postNotification(child.get(), document.get(), AXObjectCache::AXMenuListItemSelected, true, PostSynchronously);
139 } // namespace WebCore