From 6174d95762381792b4ce16901a1a7686e9764b53 Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Wed, 5 Sep 2012 20:03:39 +0900 Subject: [PATCH] Bug 761102 - focus may be missed when ARIA active-descendant is changed on active composite widget, r=tbsaunde, f=davidb --- accessible/src/base/FocusManager.cpp | 2 +- accessible/src/generic/Accessible.cpp | 16 +++++++++++++++- accessible/src/generic/DocAccessible.cpp | 6 +++--- .../test_focus_aria_activedescendant.html | 17 +++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/accessible/src/base/FocusManager.cpp b/accessible/src/base/FocusManager.cpp index cdfa9568a5c7..81ccd055f864 100644 --- a/accessible/src/base/FocusManager.cpp +++ b/accessible/src/base/FocusManager.cpp @@ -60,7 +60,7 @@ FocusManager::IsFocused(const Accessible* aAccessible) const DocAccessible* doc = GetAccService()->GetDocAccessible(focusedNode->OwnerDoc()); return aAccessible == - (doc ? doc->GetAccessibleOrContainer(focusedNode) : nullptr); + (doc ? doc->GetAccessibleOrContainer(focusedNode) : nullptr); } } return false; diff --git a/accessible/src/generic/Accessible.cpp b/accessible/src/generic/Accessible.cpp index 16dc38592453..17ce4a191ee1 100644 --- a/accessible/src/generic/Accessible.cpp +++ b/accessible/src/generic/Accessible.cpp @@ -2846,7 +2846,21 @@ Accessible::IsWidget() const bool Accessible::IsActiveWidget() const { - return FocusMgr()->IsFocused(this); + if (FocusMgr()->HasDOMFocus(mContent)) + return true; + + // If text entry of combobox widget has a focus then the combobox widget is + // active. + if (mRoleMapEntry && mRoleMapEntry->Is(nsGkAtoms::combobox)) { + PRUint32 childCount = ChildCount(); + for (PRUint32 idx = 0; idx < childCount; idx++) { + Accessible* child = mChildren.ElementAt(idx); + if (child->Role() == roles::ENTRY) + return FocusMgr()->HasDOMFocus(child->GetContent()); + } + } + + return false; } bool diff --git a/accessible/src/generic/DocAccessible.cpp b/accessible/src/generic/DocAccessible.cpp index ecd14d6df7b2..f1ed543f465a 100644 --- a/accessible/src/generic/DocAccessible.cpp +++ b/accessible/src/generic/DocAccessible.cpp @@ -1221,11 +1221,11 @@ DocAccessible::ARIAAttributeChanged(nsIContent* aContent, nsIAtom* aAttribute) void DocAccessible::ARIAActiveDescendantChanged(nsIContent* aElm) { - if (FocusMgr()->HasDOMFocus(aElm)) { + Accessible* widget = GetAccessible(aElm); + if (widget && widget->IsActiveWidget()) { nsAutoString id; if (aElm->GetAttr(kNameSpaceID_None, nsGkAtoms::aria_activedescendant, id)) { - nsIDocument* DOMDoc = aElm->OwnerDoc(); - dom::Element* activeDescendantElm = DOMDoc->GetElementById(id); + dom::Element* activeDescendantElm = aElm->OwnerDoc()->GetElementById(id); if (activeDescendantElm) { Accessible* activeDescendant = GetAccessible(activeDescendantElm); if (activeDescendant) { diff --git a/accessible/tests/mochitest/events/test_focus_aria_activedescendant.html b/accessible/tests/mochitest/events/test_focus_aria_activedescendant.html index b9655ce0c469..4c2a2a29624e 100644 --- a/accessible/tests/mochitest/events/test_focus_aria_activedescendant.html +++ b/accessible/tests/mochitest/events/test_focus_aria_activedescendant.html @@ -70,6 +70,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429547 gQueue.push(new synthFocus("container", new focusChecker("item1"))); gQueue.push(new changeARIAActiveDescendant("container", "item2")); + + gQueue.push(new synthFocus("combobox_entry", new focusChecker("combobox_entry"))); + gQueue.push(new changeARIAActiveDescendant("combobox", "combobox_option2")); + todo(false, "No focus for inserted element, bug 687011"); //gQueue.push(new insertItemNFocus("container", "item3")); @@ -87,6 +91,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429547 title="Support aria-activedescendant usage in nsIAccesible::TakeFocus()"> Mozilla Bug 429547 + + Mozilla Bug 761102 +

@@ -96,5 +105,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429547
     
item1
item2
+ +
+ +
    +
  • option1
  • +
  • option2
  • +
+