Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2103)

Unified Diff: Source/modules/accessibility/AXMenuListPopup.cpp

Issue 1061063004: Revert of Don't keep recreating AXMenuListPopup (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@suppress_extra_events
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/accessibility/AXMenuListPopup.h ('k') | Source/modules/accessibility/AXObjectCacheImpl.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/accessibility/AXMenuListPopup.cpp
diff --git a/Source/modules/accessibility/AXMenuListPopup.cpp b/Source/modules/accessibility/AXMenuListPopup.cpp
index 0b2b490caaab4493887a6ac2ee72f57cad7a9d46..cdefe82992c8dd9c4f135b1edc69d9478a286a18 100644
--- a/Source/modules/accessibility/AXMenuListPopup.cpp
+++ b/Source/modules/accessibility/AXMenuListPopup.cpp
@@ -71,19 +71,17 @@
if (!isHTMLOptionElement(*element))
return 0;
- AXObject* object = axObjectCache()->getOrCreate(element);
- if (!object)
- return 0;
+ AXObject* object = axObjectCache()->getOrCreate(MenuListOptionRole);
+ ASSERT_WITH_SECURITY_IMPLICATION(object->isMenuListOption());
- ASSERT_WITH_SECURITY_IMPLICATION(object->isMenuListOption());
- return toAXMenuListOption(object);
+ AXMenuListOption* option = toAXMenuListOption(object);
+ option->setElement(element);
+
+ return option;
}
int AXMenuListPopup::getSelectedIndex() const
{
- if (!m_parent)
- return -1;
-
Node* selectNode = m_parent->node();
if (!selectNode)
return -1;
@@ -113,9 +111,7 @@
HTMLSelectElement* htmlSelectElement = toHTMLSelectElement(selectNode);
m_haveChildren = true;
- if (m_activeIndex == -1)
- m_activeIndex = getSelectedIndex();
-
+ m_activeIndex = getSelectedIndex();
const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = htmlSelectElement->listItems();
unsigned length = listItems.size();
for (unsigned i = 0; i < length; i++) {
@@ -127,18 +123,34 @@
}
}
-void AXMenuListPopup::updateChildrenIfNecessary()
+void AXMenuListPopup::childrenChanged()
{
- if (m_haveChildren && m_parent && m_parent->needsToUpdateChildren())
- clearChildren();
+ AXObjectCacheImpl* cache = axObjectCache();
+ if (!cache)
+ return;
+ for (size_t i = m_children.size(); i > 0 ; --i) {
+ AXObject* child = m_children[i - 1].get();
+ // FIXME: How could children end up in here that have no actionElement(), the check
+ // in menuListOptionAXObject would seem to prevent that.
+ if (child->actionElement()) {
+ child->detachFromParent();
+ cache->remove(child->axObjectID());
+ }
+ }
- if (!m_haveChildren)
- addChildren();
+ m_children.clear();
+ m_haveChildren = false;
}
void AXMenuListPopup::didUpdateActiveOption(int optionIndex)
{
- updateChildrenIfNecessary();
+ // We defer creation of the children until updating the active option so that we don't
+ // create AXObjects for <option> elements while they're in the middle of removal.
+ if (!m_haveChildren)
+ addChildren();
+
+ ASSERT_ARG(optionIndex, optionIndex >= 0);
+ ASSERT_ARG(optionIndex, optionIndex < static_cast<int>(m_children.size()));
AXObjectCacheImpl* cache = axObjectCache();
if (m_activeIndex != optionIndex && m_activeIndex >= 0 && m_activeIndex < static_cast<int>(m_children.size())) {
@@ -146,12 +158,9 @@
cache->postNotification(previousChild.get(), AXObjectCacheImpl::AXMenuListItemUnselected);
}
- if (optionIndex >= 0 && optionIndex < static_cast<int>(m_children.size())) {
- RefPtr<AXObject> child = m_children[optionIndex].get();
- cache->postNotification(child.get(), AXObjectCacheImpl::AXFocusedUIElementChanged);
- cache->postNotification(child.get(), AXObjectCacheImpl::AXMenuListItemSelected);
- }
-
+ RefPtr<AXObject> child = m_children[optionIndex].get();
+ cache->postNotification(child.get(), AXObjectCacheImpl::AXFocusedUIElementChanged);
+ cache->postNotification(child.get(), AXObjectCacheImpl::AXMenuListItemSelected);
m_activeIndex = optionIndex;
}
« no previous file with comments | « Source/modules/accessibility/AXMenuListPopup.h ('k') | Source/modules/accessibility/AXObjectCacheImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698