Bug 422744 - process a11y events caused by DOM events by target document, r=fer, a=blocking2.0Final+
authorAlexander Surkov <surkov.alexander@gmail.com>
Mon, 13 Dec 2010 14:06:34 -0800
changeset 59161 cef32fff6f24f3f0e47a21b7698039dbc7d8f23a
parent 59160 2b3626056e132c6bb9019836c41050b1e83c9e40
child 59162 87b5643a26894a47096bcf547a3ca98c732dd8e4
push idunknown
push userunknown
push dateunknown
reviewersfer, blocking2.0Final
bugs422744
milestone2.0b8pre
Bug 422744 - process a11y events caused by DOM events by target document, r=fer, a=blocking2.0Final+
accessible/src/base/nsRootAccessible.cpp
accessible/tests/mochitest/events/test_focus.html
accessible/tests/mochitest/test_text_caret.html
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -350,16 +350,19 @@ nsRootAccessible::FireAccessibleFocusEve
   }
 
   // Fire focus only if it changes, but always fire focus events when
   // aForceEvent == PR_TRUE
   nsINode* focusNode = focusAccessible->GetNode();
   if (gLastFocusedNode == focusNode && !aForceEvent)
     return;
 
+  nsDocAccessible* focusDocument = focusAccessible->GetDocAccessible();
+  NS_ASSERTION(focusDocument, "No document while accessible is in document?!");
+
   gLastFocusedAccessiblesState = nsAccUtils::State(focusAccessible);
 
   // Fire menu start/end events for ARIA menus.
   if (focusAccessible->ARIARole() == nsIAccessibleRole::ROLE_MENUITEM) {
     // The focus is inside a menu.
     if (!mCurrentARIAMenubar) {
       // Entering ARIA menu. Fire menu start event.
       nsAccessible* menuBarAccessible =
@@ -368,41 +371,42 @@ nsRootAccessible::FireAccessibleFocusEve
       if (menuBarAccessible) {
         mCurrentARIAMenubar = menuBarAccessible->GetNode();
         if (mCurrentARIAMenubar) {
           nsRefPtr<AccEvent> menuStartEvent =
             new AccEvent(nsIAccessibleEvent::EVENT_MENU_START,
                          menuBarAccessible, aIsFromUserInput,
                          AccEvent::eAllowDupes);
           if (menuStartEvent)
-            FireDelayedAccessibleEvent(menuStartEvent);
+            focusDocument->FireDelayedAccessibleEvent(menuStartEvent);
         }
       }
     }
   }
   else if (mCurrentARIAMenubar) {
     // Focus left a menu. Fire menu end event.
     nsRefPtr<AccEvent> menuEndEvent =
       new AccEvent(nsIAccessibleEvent::EVENT_MENU_END, mCurrentARIAMenubar,
                    aIsFromUserInput, AccEvent::eAllowDupes);
     if (menuEndEvent) {
-      FireDelayedAccessibleEvent(menuEndEvent);
+      focusDocument->FireDelayedAccessibleEvent(menuEndEvent);
     }
     mCurrentARIAMenubar = nsnull;
   }
 
   NS_IF_RELEASE(gLastFocusedNode);
   gLastFocusedNode = focusNode;
   NS_IF_ADDREF(gLastFocusedNode);
 
   // Coalesce focus events from the same document, because DOM focus event might
   // be fired for the document node and then for the focused DOM element.
-  FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_FOCUS,
-                             focusNode, AccEvent::eCoalesceFromSameDocument,
-                             aIsFromUserInput);
+  focusDocument->FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_FOCUS,
+                                            focusNode,
+                                            AccEvent::eCoalesceFromSameDocument,
+                                            aIsFromUserInput);
 }
 
 void
 nsRootAccessible::FireCurrentFocusEvent()
 {
   if (IsDefunct())
     return;
 
@@ -454,16 +458,19 @@ nsRootAccessible::HandleEvent(nsIDOMEven
     GetAccService()->GetAccessibleOrContainer(origTarget, weakShell);
 
   if (eventType.EqualsLiteral("popuphiding"))
     return HandlePopupHidingEvent(origTarget, accessible);
 
   if (!accessible)
     return NS_OK;
 
+  nsDocAccessible* targetDocument = accessible->GetDocAccessible();
+  NS_ASSERTION(targetDocument, "No document while accessible is in document?!");
+
   nsINode* targetNode = accessible->GetNode();
   nsIContent* targetContent = targetNode->IsElement() ?
     targetNode->AsElement() : nsnull;
 #ifdef MOZ_XUL
   PRBool isTree = targetContent ?
     targetContent->NodeInfo()->Equals(nsAccessibilityAtoms::tree,
                                       kNameSpaceID_XUL) : PR_FALSE;
 
@@ -687,18 +694,19 @@ nsRootAccessible::HandleEvent(nsIDOMEven
                             accessible, eFromUserInput);
   }
   else if (eventType.EqualsLiteral("DOMMenuBarInactive")) {  // Always from user input
     nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_MENU_END,
                             accessible, eFromUserInput);
     FireCurrentFocusEvent();
   }
   else if (eventType.EqualsLiteral("ValueChange")) {
-    FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_VALUE_CHANGE,
-                               targetNode, AccEvent::eRemoveDupes);
+    targetDocument->
+      FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_VALUE_CHANGE,
+                                 targetNode, AccEvent::eRemoveDupes);
   }
 #ifdef DEBUG_DRAGDROPSTART
   else if (eventType.EqualsLiteral("mouseover")) {
     nsEventShell::FireEvent(nsIAccessibleEvent::EVENT_DRAGDROP_START,
                             accessible);
   }
 #endif
   return NS_OK;
--- a/accessible/tests/mochitest/events/test_focus.html
+++ b/accessible/tests/mochitest/events/test_focus.html
@@ -62,22 +62,21 @@
     {
       this.ID = "alertdialog";
       this.DOMNode = getNode(this.ID);
 
       this.invoke = function showNFocusAlertDialog_invoke()
       {
         document.getElementById(this.ID).style.display = 'block';
         document.getElementById(this.ID).focus();
-        todo(false, "Enable show event handling when bug 422744 is fixed.");
       }
 
       this.eventSeq = [
-        new invokerChecker(EVENT_FOCUS, this.DOMNode),
-        // new invokerChecker(EVENT_SHOW, this.DOMNode)
+        new invokerChecker(EVENT_SHOW, this.DOMNode),
+        new invokerChecker(EVENT_FOCUS, this.DOMNode)
       ];
 
       this.getID = function showNFocusAlertDialog_getID()
       {
         return "Show and focus alert dialog " + prettyName(this.ID);
       }
     }
 
--- a/accessible/tests/mochitest/test_text_caret.html
+++ b/accessible/tests/mochitest/test_text_caret.html
@@ -38,26 +38,25 @@
      */
     function setCaretOffsetInvoker(aID, aOffset)
     {
       this.target = getAccessible(aID, [nsIAccessibleText]);
 
       this.invoke = function setCaretOffsetInvoker_invoke()
       {
         this.target.caretOffset = aOffset;
-        todo(false, "Enable focus event handling when bug 422744 is fixed.");
       }
 
       this.getID = function setCaretOffsetInvoker_getID()
       {
         return "nsIAccessibleText::caretOffset test";
       }
 
       this.eventSeq = [
-        // new invokerChecker(EVENT_FOCUS, this.target),
+        new invokerChecker(EVENT_FOCUS, this.target),
         new caretMovedChecker(this.target, aOffset)
       ];
     }
 
     /**
      * Do tests.
      */
     var gQueue = null;