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 "core/accessibility/AXMenuListPopup.h"
29 #include "core/accessibility/AXMenuListOption.h"
30 #include "core/accessibility/AXObjectCache.h"
31 #include "core/html/HTMLSelectElement.h"
35 using namespace HTMLNames;
37 AXMenuListPopup::AXMenuListPopup()
41 bool AXMenuListPopup::isVisible() const
46 bool AXMenuListPopup::isOffScreen() const
51 return m_parent->isCollapsed();
54 bool AXMenuListPopup::isEnabled() const
59 return m_parent->isEnabled();
62 bool AXMenuListPopup::computeAccessibilityIsIgnored() const
64 return accessibilityIsIgnoredByDefault();
67 AXMenuListOption* AXMenuListPopup::menuListOptionAXObject(HTMLElement* element) const
70 if (!isHTMLOptionElement(*element))
73 AXObject* object = document()->axObjectCache()->getOrCreate(MenuListOptionRole);
74 ASSERT_WITH_SECURITY_IMPLICATION(object->isMenuListOption());
76 AXMenuListOption* option = toAXMenuListOption(object);
77 option->setElement(element);
82 bool AXMenuListPopup::press() const
91 void AXMenuListPopup::addChildren()
96 Node* selectNode = m_parent->node();
100 m_haveChildren = true;
102 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = toHTMLSelectElement(selectNode)->listItems();
103 unsigned length = listItems.size();
104 for (unsigned i = 0; i < length; i++) {
105 AXMenuListOption* option = menuListOptionAXObject(listItems[i]);
107 option->setParent(this);
108 m_children.append(option);
113 void AXMenuListPopup::childrenChanged()
115 AXObjectCache* cache = axObjectCache();
116 for (size_t i = m_children.size(); i > 0 ; --i) {
117 AXObject* child = m_children[i - 1].get();
118 // FIXME: How could children end up in here that have no actionElement(), the check
119 // in menuListOptionAXObject would seem to prevent that.
120 if (child->actionElement()) {
121 child->detachFromParent();
122 cache->remove(child->axObjectID());
127 m_haveChildren = false;
130 void AXMenuListPopup::didUpdateActiveOption(int optionIndex)
132 // We defer creation of the children until updating the active option so that we don't
133 // create AXObjects for <option> elements while they're in the middle of removal.
137 ASSERT_ARG(optionIndex, optionIndex >= 0);
138 ASSERT_ARG(optionIndex, optionIndex < static_cast<int>(m_children.size()));
140 AXObjectCache* cache = axObjectCache();
141 RefPtr<AXObject> child = m_children[optionIndex].get();
143 cache->postNotification(child.get(), document(), AXObjectCache::AXFocusedUIElementChanged, true, PostSynchronously);
144 cache->postNotification(child.get(), document(), AXObjectCache::AXMenuListItemSelected, true, PostSynchronously);
147 } // namespace WebCore