Bug 1069574 - [AccessFu] added support for interaction hints in B2G. r=eeejay
authorYura Zenevich <yzenevich@mozilla.com>
Thu, 20 Nov 2014 10:00:05 -0500
changeset 216648 c7c492d4f480b0e09d4c6055bb66e632aacb5cab
parent 216647 ef55c94657dc6d1a04dc23919da1d7b917de2302
child 216649 a500a8bf99f9b7d97ab9c662c798c134702f5bee
push id27858
push userkwierso@gmail.com
push dateFri, 21 Nov 2014 01:35:46 +0000
treeherdermozilla-central@6309710dd71d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseeejay
bugs1069574, 100644
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1069574 - [AccessFu] added support for interaction hints in B2G. r=eeejay --- accessible/jsat/Presentation.jsm | 3 +- accessible/jsat/Utils.jsm | 19 ++++++ accessible/tests/mochitest/jsat/a11y.ini | 1 + accessible/tests/mochitest/jsat/output.js | 13 ++++ accessible/tests/mochitest/jsat/test_hints.html | 85 +++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 accessible/tests/mochitest/jsat/test_hints.html
accessible/jsat/Presentation.jsm
accessible/jsat/Utils.jsm
accessible/tests/mochitest/jsat/a11y.ini
accessible/tests/mochitest/jsat/output.js
accessible/tests/mochitest/jsat/test_hints.html
--- a/accessible/jsat/Presentation.jsm
+++ b/accessible/jsat/Presentation.jsm
@@ -502,17 +502,18 @@ B2GPresenter.prototype.pivotChanged =
       type: this.type,
       details: {
         eventType: 'vc-change',
         data: UtteranceGenerator.genForContext(aContext),
         options: {
           pattern: this.PIVOT_CHANGE_HAPTIC_PATTERN,
           isKey: Utils.isActivatableOnFingerUp(aContext.accessible),
           reason: this.pivotChangedReasons[aReason],
-          isUserInput: aIsUserInput
+          isUserInput: aIsUserInput,
+          hints: aContext.interactionHints
         }
       }
     };
   };
 
 B2GPresenter.prototype.valueChanged =
   function B2GPresenter_valueChanged(aAccessible) {
 
--- a/accessible/jsat/Utils.jsm
+++ b/accessible/jsat/Utils.jsm
@@ -823,16 +823,35 @@ PivotContext.prototype = {
           [yield node for (node of this._traverse(child, aPreorder, aStop))]; // jshint ignore:line
           yield child;
         }
       }
       child = child.nextSibling;
     }
   },
 
+  /**
+   * Get interaction hints for the context ancestry.
+   * @return {Array} Array of interaction hints.
+   */
+  get interactionHints() {
+    let hints = [];
+    this.newAncestry.concat(this.accessible).reverse().forEach(aAccessible => {
+      let hint = Utils.getAttributes(aAccessible)['moz-hint'];
+      if (hint) {
+        hints.push(hint);
+      } else if (aAccessible.actionCount > 0) {
+        hints.push({
+          string: Utils.AccRetrieval.getStringRole(aAccessible.role) + '-hint'
+        });
+      }
+    });
+    return hints;
+  },
+
   /*
    * A subtree generator function, used to generate a flattened
    * list of the accessible's subtree in pre or post order.
    * It only includes the accessible's visible chidren.
    * @param {boolean} aPreorder A flag for traversal order. If true, traverse
    * in preorder; if false, traverse in postorder.
    * @param {function} aStop An optional function, indicating whether subtree
    * traversal should stop.
--- a/accessible/tests/mochitest/jsat/a11y.ini
+++ b/accessible/tests/mochitest/jsat/a11y.ini
@@ -10,15 +10,16 @@ support-files =
 
 [test_alive.html]
 [test_content_integration.html]
 skip-if = buildapp == 'mulet'
 [test_content_text.html]
 skip-if = buildapp == 'mulet'
 [test_explicit_names.html]
 [test_gesture_tracker.html]
+[test_hints.html]
 [test_landmarks.html]
 [test_live_regions.html]
 [test_output.html]
 [test_quicknav_modes.html]
 [test_tables.html]
 [test_pointer_relay.html]
 [test_traversal.html]
--- a/accessible/tests/mochitest/jsat/output.js
+++ b/accessible/tests/mochitest/jsat/output.js
@@ -94,8 +94,21 @@ function testOutput(expected, aAccOrElmO
   testContextOutput(expected, aAccOrElmOrID, aOldAccOrElmOrID, generator);
   // Just need to test object output for individual
   // accOrElmOrID.
   if (aOldAccOrElmOrID) {
     return;
   }
   testObjectOutput(aAccOrElmOrID, generator);
 }
+
+function testHints(expected, aAccOrElmOrID, aOldAccOrElmOrID) {
+  var accessible = getAccessible(aAccOrElmOrID);
+  var oldAccessible = aOldAccOrElmOrID !== null ?
+  getAccessible(aOldAccOrElmOrID || 'root') : null;
+  var context = new PivotContext(accessible, oldAccessible);
+  var hints = context.interactionHints;
+
+  isDeeply(hints, expected,
+           "Context hitns are correct for " + aAccOrElmOrID +
+           " (hints: " + JSON.stringify(hints) + ") ==" +
+           " (expected: " + JSON.stringify(expected) + ")");
+}
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/jsat/test_hints.html
@@ -0,0 +1,85 @@
+<html>
+<head>
+  <title> [AccessFu] Interaction Hints </title>
+
+  <link rel="stylesheet" type="text/css"
+        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript"
+          src="../common.js"></script>
+  <script type="application/javascript"
+          src="output.js"></script>
+  <script type="application/javascript">
+
+    function doTest() {
+      var tests = [{
+        accOrElmOrID: 'can_wheel',
+        expectedHints: ['Swipe with two fingers to move between pages']
+      }, {
+        accOrElmOrID: 'nested_link',
+        expectedHints: [{string: 'link-hint'},
+          'Swipe with two fingers to move between pages']
+      }, {
+        accOrElmOrID: 'nested_link',
+        oldAccOrElmOrID: 'can_wheel',
+        expectedHints: [{string: 'link-hint'}]
+      }, {
+        accOrElmOrID: 'link_with_default_hint',
+        expectedHints: [{string: 'link-hint'}]
+      }, {
+        accOrElmOrID: 'link_with_hint_override',
+        expectedHints: ['Tap and hold to get to menu']
+      }, {
+        accOrElmOrID: 'button_with_default_hint',
+        expectedHints: [{string: 'pushbutton-hint'}]
+      }, {
+        accOrElmOrID: 'button_with_hint_override',
+        expectedHints: ['Tap and hold to activate']
+      }, {
+        accOrElmOrID: 'nested_link2',
+        expectedHints: [{string: 'link-hint'}]
+      }, {
+        accOrElmOrID: 'nested_link3',
+        expectedHints: [{string: 'link-hint'}, {string: 'pushbutton-hint'},
+          "Double tap and hold to activate"]
+      }];
+
+      // Test hints.
+      tests.forEach(function run(test) {
+        testHints(test.expectedHints, test.accOrElmOrID, test.oldAccOrElmOrID);
+      });
+
+      SimpleTest.finish();
+    }
+
+    SimpleTest.waitForExplicitFinish();
+    addA11yLoadEvent(doTest);
+  </script>
+</head>
+<body>
+  <div id="root">
+    <a target="_blank"
+       href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069574"
+       title="[AccessFu] Interaction Hints">
+       Mozilla Bug 1069574
+       </a>
+    <p id="display"></p>
+    <div id="content" style="display: none"></div>
+    <pre id="test"></pre>
+      <span role="region" id="can_wheel" aria-moz-hint="Swipe with two fingers to move between pages">
+        <a href="#" id="nested_link">I can be clicked</a>
+      </span>
+      <span role="region" aria-moz-hint="">
+        <a><a href="#" id="nested_link2">I can be clicked</a></a>
+      </span>
+      <span role="region" aria-moz-hint="Double tap and hold to activate">
+        <button><a href="#" id="nested_link3">I can be clicked</a></button>
+      </span>
+      <a href="#" id="link_with_default_hint">I can be clicked</a>
+      <a href="#" id="link_with_hint_override" aria-moz-hint="Tap and hold to get to menu">I am a special link</a>
+      <button id="button_with_default_hint">Toggle</button>
+      <button id="button_with_hint_override" aria-moz-hint="Tap and hold to activate">Special</button>
+  </div>
+</body>
+</html>