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

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

Issue 1059503002: Re-land: Don't keep recreating AXMenuListPopup (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@suppress_extra_events
Patch Set: Fix optgroup 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 cdefe82992c8dd9c4f135b1edc69d9478a286a18..0b2b490caaab4493887a6ac2ee72f57cad7a9d46 100644
--- a/Source/modules/accessibility/AXMenuListPopup.cpp
+++ b/Source/modules/accessibility/AXMenuListPopup.cpp
@@ -71,17 +71,19 @@ AXMenuListOption* AXMenuListPopup::menuListOptionAXObject(HTMLElement* element)
if (!isHTMLOptionElement(*element))
return 0;
- AXObject* object = axObjectCache()->getOrCreate(MenuListOptionRole);
- ASSERT_WITH_SECURITY_IMPLICATION(object->isMenuListOption());
-
- AXMenuListOption* option = toAXMenuListOption(object);
- option->setElement(element);
+ AXObject* object = axObjectCache()->getOrCreate(element);
+ if (!object)
+ return 0;
- return option;
+ ASSERT_WITH_SECURITY_IMPLICATION(object->isMenuListOption());
+ return toAXMenuListOption(object);
}
int AXMenuListPopup::getSelectedIndex() const
{
+ if (!m_parent)
+ return -1;
+
Node* selectNode = m_parent->node();
if (!selectNode)
return -1;
@@ -111,7 +113,9 @@ void AXMenuListPopup::addChildren()
HTMLSelectElement* htmlSelectElement = toHTMLSelectElement(selectNode);
m_haveChildren = true;
- m_activeIndex = getSelectedIndex();
+ if (m_activeIndex == -1)
+ m_activeIndex = getSelectedIndex();
+
const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = htmlSelectElement->listItems();
unsigned length = listItems.size();
for (unsigned i = 0; i < length; i++) {
@@ -123,34 +127,18 @@ void AXMenuListPopup::addChildren()
}
}
-void AXMenuListPopup::childrenChanged()
+void AXMenuListPopup::updateChildrenIfNecessary()
{
- 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 && m_parent && m_parent->needsToUpdateChildren())
+ clearChildren();
- m_children.clear();
- m_haveChildren = false;
+ if (!m_haveChildren)
+ addChildren();
}
void AXMenuListPopup::didUpdateActiveOption(int optionIndex)
{
- // 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()));
+ updateChildrenIfNecessary();
AXObjectCacheImpl* cache = axObjectCache();
if (m_activeIndex != optionIndex && m_activeIndex >= 0 && m_activeIndex < static_cast<int>(m_children.size())) {
@@ -158,9 +146,12 @@ void AXMenuListPopup::didUpdateActiveOption(int optionIndex)
cache->postNotification(previousChild.get(), AXObjectCacheImpl::AXMenuListItemUnselected);
}
- RefPtr<AXObject> child = m_children[optionIndex].get();
- cache->postNotification(child.get(), AXObjectCacheImpl::AXFocusedUIElementChanged);
- cache->postNotification(child.get(), AXObjectCacheImpl::AXMenuListItemSelected);
+ 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);
+ }
+
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