Bug 530014 - ARIA single selectable widget should implement nsIAccessibleSelectable, r=marcoz, davidb
authorAlexander Surkov <surkov.alexander@gmail.com>
Sat, 12 Dec 2009 03:38:55 +0800
changeset 35584 8eb40c0a36501edf4b16b30a0dc110155b6e026c
parent 35583 1f455848b0863354324809e341575450d477106f
child 35585 eae814b48ddcdfcfdfa5890b94d2a4c3d3ac1464
push id10638
push usersurkov.alexander@gmail.com
push dateFri, 11 Dec 2009 19:39:38 +0000
treeherdermozilla-central@eae814b48ddc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarcoz, davidb
bugs530014
milestone1.9.3a1pre
Bug 530014 - ARIA single selectable widget should implement nsIAccessibleSelectable, r=marcoz, davidb
accessible/src/base/nsAccUtils.cpp
accessible/src/base/nsAccUtils.h
accessible/src/base/nsAccessible.cpp
accessible/src/base/nsDocAccessible.cpp
accessible/src/html/nsHTMLSelectAccessible.cpp
accessible/tests/mochitest/Makefile.in
accessible/tests/mochitest/selectable/Makefile.in
accessible/tests/mochitest/selectable/test_aria.html
accessible/tests/mochitest/selectable/test_select.html
accessible/tests/mochitest/selectable/test_tree.xul
accessible/tests/mochitest/test_selectable_tree.xul
--- a/accessible/src/base/nsAccUtils.cpp
+++ b/accessible/src/base/nsAccUtils.cpp
@@ -497,16 +497,56 @@ nsAccUtils::GetARIATreeItemParent(nsIAcc
     role = nsAccUtils::Role(prevAccessible);
   }
   if (role == nsIAccessibleRole::ROLE_OUTLINEITEM) {
     // Previous sibling of parent group is a tree item -- this is the conceptual tree item parent
     NS_ADDREF(*aTreeItemParentResult = prevAccessible);
   }
 }
 
+already_AddRefed<nsIAccessible>
+nsAccUtils::GetSelectableContainer(nsIAccessible *aAccessible, PRUint32 aState)
+{
+  if (!aAccessible)
+    return nsnull;
+
+  if (!(aState & nsIAccessibleStates::STATE_SELECTABLE))
+    return nsnull;
+
+  nsCOMPtr<nsIAccessibleSelectable> container;
+  nsCOMPtr<nsIAccessible> parent, accessible(aAccessible);
+  while (!container) {
+    accessible->GetParent(getter_AddRefs(parent));
+
+    if (!parent || Role(parent) == nsIAccessibleRole::ROLE_PANE)
+      return nsnull;
+
+    container = do_QueryInterface(parent);
+    parent.swap(accessible);
+  }
+
+  return accessible.forget();
+}
+
+already_AddRefed<nsIAccessible>
+nsAccUtils::GetMultiSelectableContainer(nsIDOMNode *aNode)
+{
+  nsCOMPtr<nsIAccessible> accessible;
+  nsAccessNode::GetAccService()->GetAccessibleFor(aNode,
+                                                  getter_AddRefs(accessible));
+
+  nsCOMPtr<nsIAccessible> container =
+    GetSelectableContainer(accessible, State(accessible));
+
+  if (State(container) & nsIAccessibleStates::STATE_MULTISELECTABLE)
+    return container.forget();
+
+  return nsnull;
+}
+
 PRBool
 nsAccUtils::IsARIASelected(nsIAccessible *aAccessible)
 {
   nsRefPtr<nsAccessible> acc = nsAccUtils::QueryAccessible(aAccessible);
   nsCOMPtr<nsIDOMNode> node;
   acc->GetDOMNode(getter_AddRefs(node));
   NS_ASSERTION(node, "No DOM node!");
 
@@ -922,47 +962,16 @@ PRBool
 nsAccUtils::IsNodeRelevant(nsIDOMNode *aNode)
 {
   nsCOMPtr<nsIDOMNode> relevantNode;
   nsAccessNode::GetAccService()->GetRelevantContentNodeFor(aNode,
                                                            getter_AddRefs(relevantNode));
   return aNode == relevantNode;
 }
 
-already_AddRefed<nsIAccessible>
-nsAccUtils::GetMultiSelectFor(nsIDOMNode *aNode)
-{
-  if (!aNode)
-    return nsnull;
-
-  nsCOMPtr<nsIAccessible> accessible;
-  nsAccessNode::GetAccService()->GetAccessibleFor(aNode,
-                                                  getter_AddRefs(accessible));
-  if (!accessible)
-    return nsnull;
-
-  PRUint32 state = State(accessible);
-  if (0 == (state & nsIAccessibleStates::STATE_SELECTABLE))
-    return nsnull;
-
-  while (0 == (state & nsIAccessibleStates::STATE_MULTISELECTABLE)) {
-    nsIAccessible *current = accessible;
-    current->GetParent(getter_AddRefs(accessible));
-    if (!accessible ||
-        nsAccUtils::Role(accessible) == nsIAccessibleRole::ROLE_PANE) {
-      return nsnull;
-    }
-    state = State(accessible);
-  }
-
-  nsIAccessible *returnAccessible = nsnull;
-  accessible.swap(returnAccessible);
-  return returnAccessible;
-}
-
 nsresult
 nsAccUtils::GetHeaderCellsFor(nsIAccessibleTable *aTable,
                               nsIAccessibleTableCell *aCell,
                               PRInt32 aRowOrColHeaderCells, nsIArray **aCells)
 {
   nsresult rv = NS_OK;
   nsCOMPtr<nsIMutableArray> cells = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/accessible/src/base/nsAccUtils.h
+++ b/accessible/src/base/nsAccUtils.h
@@ -175,16 +175,31 @@ public:
      * @param The tree item's parent, or null if none
      */
    static void
      GetARIATreeItemParent(nsIAccessible *aStartTreeItem,
                            nsIContent *aStartTreeItemContent,
                            nsIAccessible **aTreeItemParent);
 
   /**
+   * Return single or multi selectable container for the given item.
+   *
+   * @param  aAccessible  [in] the item accessible
+   * @param  aState       [in] the state of the item accessible
+   */
+  static already_AddRefed<nsIAccessible>
+    GetSelectableContainer(nsIAccessible *aAccessible, PRUint32 aState);
+
+  /**
+   * Return multi selectable container for the given item.
+   */
+  static already_AddRefed<nsIAccessible>
+    GetMultiSelectableContainer(nsIDOMNode *aNode);
+
+  /**
    * Return true if the DOM node of given accessible has aria-selected="true"
    * attribute.
    */
   static PRBool IsARIASelected(nsIAccessible *aAccessible);
 
   /**
    * Return text accessible containing focus point of the given selection.
    * Used for normal and misspelling selection changes processing.
@@ -463,21 +478,16 @@ public:
 
   /**
    * Return true if the given node can be accessible and attached to
    * the document's accessible tree.
    */
   static PRBool IsNodeRelevant(nsIDOMNode *aNode);
 
   /**
-   * Return multiselectable parent for the given selectable accessible if any.
-   */
-  static already_AddRefed<nsIAccessible> GetMultiSelectFor(nsIDOMNode *aNode);
-
-  /**
    * Search hint enum constants. Used by GetHeaderCellsFor() method.
    */
   enum {
     // search for row header cells, left direction
     eRowHeaderCells,
     // search for column header cells, top direction
     eColumnHeaderCells
   };
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -179,33 +179,29 @@ nsresult nsAccessible::QueryInterface(RE
 
   if (aIID.Equals(NS_GET_IID(nsAccessible))) {
     *aInstancePtr = static_cast<nsAccessible*>(this);
     NS_ADDREF_THIS();
     return NS_OK;
   }
 
   if (aIID.Equals(NS_GET_IID(nsIAccessibleSelectable))) {
-    nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
-    if (!content) {
-      return NS_ERROR_FAILURE; // This accessible has been shut down
-    }
-    if (content->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::role)) {
-      // If we have an XHTML role attribute present and the
-      // aria-multiselectable attribute is true, then we need
-      // to support nsIAccessibleSelectable
+    if (mRoleMapEntry &&
+        (mRoleMapEntry->attributeMap1 == eARIAMultiSelectable ||
+         mRoleMapEntry->attributeMap2 == eARIAMultiSelectable ||
+         mRoleMapEntry->attributeMap3 == eARIAMultiSelectable)) {
+
+      // If we have an ARIA role attribute present and the role allows multi
+      // selectable state, then we need to support nsIAccessibleSelectable.
       // If either attribute (role or multiselectable) change, then we'll
       // destroy this accessible so that we can follow COM identity rules.
-      nsAutoString multiselectable;
-      if (content->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::aria_multiselectable,
-                               nsAccessibilityAtoms::_true, eCaseMatters)) {
-        *aInstancePtr = static_cast<nsIAccessibleSelectable*>(this);
-        NS_ADDREF_THIS();
-        return NS_OK;
-      }
+
+      *aInstancePtr = static_cast<nsIAccessibleSelectable*>(this);
+      NS_ADDREF_THIS();
+      return NS_OK;
     }
   }
 
   if (aIID.Equals(NS_GET_IID(nsIAccessibleValue))) {
     if (mRoleMapEntry && mRoleMapEntry->valueRule != eNoValue) {
       *aInstancePtr = static_cast<nsIAccessibleValue*>(this);
       NS_ADDREF_THIS();
       return NS_OK;
@@ -1178,17 +1174,17 @@ NS_IMETHODIMP nsAccessible::SetSelected(
   // Add or remove selection
   if (!mDOMNode) {
     return NS_ERROR_FAILURE;
   }
 
   PRUint32 state = nsAccUtils::State(this);
   if (state & nsIAccessibleStates::STATE_SELECTABLE) {
     nsCOMPtr<nsIAccessible> multiSelect =
-      nsAccUtils::GetMultiSelectFor(mDOMNode);
+      nsAccUtils::GetMultiSelectableContainer(mDOMNode);
     if (!multiSelect) {
       return aSelect ? TakeFocus() : NS_ERROR_FAILURE;
     }
     nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
     NS_ASSERTION(content, "Called for dead accessible");
 
     if (mRoleMapEntry) {
       if (aSelect) {
@@ -1208,17 +1204,17 @@ NS_IMETHODIMP nsAccessible::TakeSelectio
   // Select only this item
   if (!mDOMNode) {
     return NS_ERROR_FAILURE;
   }
 
   PRUint32 state = nsAccUtils::State(this);
   if (state & nsIAccessibleStates::STATE_SELECTABLE) {
     nsCOMPtr<nsIAccessible> multiSelect =
-      nsAccUtils::GetMultiSelectFor(mDOMNode);
+      nsAccUtils::GetMultiSelectableContainer(mDOMNode);
     if (multiSelect) {
       nsCOMPtr<nsIAccessibleSelectable> selectable = do_QueryInterface(multiSelect);
       selectable->ClearSelection();
     }
     return SetSelected(PR_TRUE);
   }
 
   return NS_ERROR_FAILURE;
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -1164,17 +1164,17 @@ nsDocAccessible::AttributeChangedImpl(ns
                                targetNode);
     return;
   }
 
   if (aAttribute == nsAccessibilityAtoms::selected ||
       aAttribute == nsAccessibilityAtoms::aria_selected) {
     // ARIA or XUL selection
     nsCOMPtr<nsIAccessible> multiSelect =
-      nsAccUtils::GetMultiSelectFor(targetNode);
+      nsAccUtils::GetMultiSelectableContainer(targetNode);
     // Multi selects use selection_add and selection_remove
     // Single select widgets just mirror event_selection for
     // whatever gets event_focus, which is done in
     // nsRootAccessible::FireAccessibleFocusEvent()
     // So right here we make sure only to deal with multi selects
     if (multiSelect) {
       // Need to find the right event to use here, SELECTION_WITHIN would
       // seem right but we had started using it for something else
--- a/accessible/src/html/nsHTMLSelectAccessible.cpp
+++ b/accessible/src/html/nsHTMLSelectAccessible.cpp
@@ -790,17 +790,17 @@ void nsHTMLSelectOptionAccessible::Selec
       !aPossibleOption->IsHTML()) {
     return;
   }
 
   nsCOMPtr<nsIDOMNode> optionNode(do_QueryInterface(aPossibleOption));
   NS_ASSERTION(optionNode, "No option node for nsIContent with option tag!");
 
   nsCOMPtr<nsIAccessible> multiSelect =
-    nsAccUtils::GetMultiSelectFor(optionNode);
+    nsAccUtils::GetMultiSelectableContainer(optionNode);
   if (!multiSelect)
     return;
 
   nsCOMPtr<nsIAccessible> optionAccessible;
   GetAccService()->GetAccessibleFor(optionNode,
                                     getter_AddRefs(optionAccessible));
   if (!optionAccessible)
     return;
--- a/accessible/tests/mochitest/Makefile.in
+++ b/accessible/tests/mochitest/Makefile.in
@@ -37,17 +37,17 @@
 # ***** END LICENSE BLOCK *****
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = accessible
 
-DIRS	= tree
+DIRS	= tree selectable
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES =\
 		letters.gif \
 		moz.png \
 		$(topsrcdir)/content/media/test/bug461281.ogg \
@@ -127,17 +127,16 @@ include $(topsrcdir)/config/rules.mk
 		test_nsIAccessNode_utils.html \
 		test_nsOuterDocAccessible.html \
  		test_objectattrs.html \
 		test_relations.html \
 		test_relations.xul \
 		test_relations_tree.xul \
 		test_role_nsHyperTextAcc.html \
 		test_role_table_cells.html \
-		test_selectable_tree.xul \
 		test_states.html \
 		test_states_doc.html \
 		test_states_docarticle.html \
 		test_states_editablebody.html \
 		test_states_frames.html \
 		test_states_popup.xul \
 		test_states_tree.xul \
 		test_table_1.html \
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/selectable/Makefile.in
@@ -0,0 +1,55 @@
+#
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is mozilla.org code.
+#
+# The Initial Developer of the Original Code is
+# Mozilla Corporation.
+# Portions created by the Initial Developer are Copyright (C) 2009
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#   Alexander Surkov <surkov.alexander@gmail.com> (original author)
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either of the GNU General Public License Version 2 or later (the "GPL"),
+# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+DEPTH		= ../../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+relativesrcdir  = accessible/selectable
+
+include $(DEPTH)/config/autoconf.mk
+include $(topsrcdir)/config/rules.mk
+
+_TEST_FILES =\
+		test_aria.html \
+		test_select.html \
+		test_tree.xul \
+		$(NULL)
+
+libs:: $(_TEST_FILES)
+	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/a11y/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/selectable/test_aria.html
@@ -0,0 +1,120 @@
+<html>
+
+<head>
+  <title>nsIAccessibleSelectable ARIA widgets testing</title>
+
+  <link rel="stylesheet" type="text/css"
+        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+
+  </style>
+
+  <script type="application/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+  <script type="application/javascript"
+          src="chrome://mochikit/content/a11y/accessible/common.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/a11y/accessible/role.js"></script>
+
+  <script type="application/javascript">
+    function doTest()
+    {
+      var id = "list1";
+      ok(isAccessible(id, [nsIAccessibleSelectable]),
+         "No selectable accessible for " + id);
+
+      id = "listbox1";
+      ok(isAccessible(id, [nsIAccessibleSelectable]),
+         "No selectable accessible for " + id);
+
+      id = "listbox2";
+      ok(isAccessible(id, [nsIAccessibleSelectable]),
+         "No selectable accessible for " + id);
+
+      id = "grid1";
+      ok(isAccessible(id, [nsIAccessibleSelectable]),
+         "No selectable accessible for " + id);
+
+      id = "tree1";
+      ok(isAccessible(id, [nsIAccessibleSelectable]),
+         "No selectable accessible for " + id);
+
+      id = "treegrid1";
+      ok(isAccessible(id, [nsIAccessibleSelectable]),
+         "No selectable accessible for " + id);
+
+      SimpleTest.finish();
+    }
+
+    SimpleTest.waitForExplicitFinish();
+    addA11yLoadEvent(doTest);
+  </script>
+
+</head>
+
+<body>
+
+  <a target="_blank"
+     href="https://bugzilla.mozilla.org/show_bug.cgi?id=530014"
+     title="ARIA single selectable widget should implement nsIAccessibleSelectable">
+    Mozilla Bug 530014
+  </a><br>
+  <p id="display"></p>
+  <div id="content" style="display: none"></div>
+  <pre id="test">
+  </pre>
+
+  <div role="list" id="list1">
+    <div role="listitem">item1</div>
+    <div role="listitem">item2</div>
+  </div>
+
+  <div role="listbox" id="listbox1">
+    <div role="listitem">item1</div>
+    <div role="listitem">item2</div>
+  </div>
+
+  <div role="listbox" id="listbox2" aria-multiselectable="true">
+    <div role="listitem">item1</div>
+    <div role="listitem">item2</div>
+  </div>
+
+  <div role="grid" id="grid1">
+    <div role="row">
+      <span role="gridcell">cell</span>
+      <span role="gridcell">cell</span>
+    </div>
+    <div role="row">
+      <span role="gridcell">cell</span>
+      <span role="gridcell">cell</span>
+    </div>
+  </div>
+
+  <div role="tree" id="tree1">
+    <div role="treeitem">
+      item1
+      <div role="group">
+        <div role="treeitem">item1.1</div>
+      </div>
+    </div>
+    <div>item2</div>
+  </div>
+
+  <div role="treegrid" id="treegrid1">
+    <div role="row" aria-level="1">
+      <span role="gridcell">cell</span>
+      <span role="gridcell">cell</span>
+    </div>
+    <div role="row" aria-level="2">
+      <span role="gridcell">cell</span>
+      <span role="gridcell">cell</span>
+    </div>
+    <div role="row" aria-level="1">
+      <span role="gridcell">cell</span>
+      <span role="gridcell">cell</span>
+    </div>
+  </div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/selectable/test_select.html
@@ -0,0 +1,66 @@
+<html>
+
+<head>
+  <title>nsIAccessibleSelectable HTML select testing</title>
+
+  <link rel="stylesheet" type="text/css"
+        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+
+  </style>
+
+  <script type="application/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+  <script type="application/javascript"
+          src="chrome://mochikit/content/a11y/accessible/common.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/a11y/accessible/role.js"></script>
+
+  <script type="application/javascript">
+
+    function doTest()
+    {
+      var combobox = getAccessible("combobox");
+      var comboboxList = combobox.firstChild;
+      ok(isAccessible(comboboxList, [nsIAccessibleSelectable]),
+         "No selectable accessible for list of " + id);
+
+      var id = "listbox";
+      ok(isAccessible(id, [nsIAccessibleSelectable]),
+         "No selectable accessible for " + id);
+
+      SimpleTest.finish();
+    }
+
+    SimpleTest.waitForExplicitFinish();
+    addA11yLoadEvent(doTest);
+  </script>
+
+</head>
+
+<body>
+
+  <a target="_blank"
+     href="https://bugzilla.mozilla.org/show_bug.cgi?id=530014"
+     title="ARIA single selectable widget should implement nsIAccessibleSelectable">
+    Mozilla Bug 530014
+  </a><br>
+  <p id="display"></p>
+  <div id="content" style="display: none"></div>
+  <pre id="test">
+  </pre>
+
+  <select id="combobox">
+    <option>option</option>
+    <option>option</option>
+  </select>
+
+  <select id="listbox" size="4">
+    <option>option</option>
+    <option>option</option>
+  </select>
+
+</body>
+</html>
rename from accessible/tests/mochitest/test_selectable_tree.xul
rename to accessible/tests/mochitest/selectable/test_tree.xul