Accessibility/WebAccessibilityAPI: Difference between revisions

Jump to navigation Jump to search
Line 772: Line 772:
Accessible position can be moved through the content by criteria.
Accessible position can be moved through the content by criteria.


AccessiblePos .''move''(Where, Criteria)
AccessiblePos .''move'' (''Where'', ''Criteria'')
::Move the accessible position to the content complying with criteria.
::Move the accessible position to the content complying with criteria.
::Parameters
::Parameters
:::''where'' of ''Where''
:::''where'' of ''Where''
::::where the search should be performed
::::where the search should be performed
:::''controller'' of ''Controller''
:::''criteria'' of ''Criteria''
::::function describing a match
::::function describing a match
:::Return itself if succeeded, otherwise null.
:::Return itself if succeeded, otherwise null.




AccessiblePos .''search''(Where, Criteria)
AccessiblePos .''search'' (''Where'', ''Criteria'')
::Search for content of the given criteria relative the accessible position.
::Search for content of the given criteria relative the accessible position.
::Parameters
::Parameters
:::''where'' of ''Where''
:::''where'' of ''Where''
::::where the search should be performed
::::where the search should be performed
:::''controller'' of ''Controller''
:::''criteria'' of ''Criteria''
::::function describing a match
::::function describing a match
:::Return new instance if succeeded, otherwise null.
:::Return new instance if succeeded, otherwise null.
Line 793: Line 793:




=====Search area=====
=====Where to search=====


Methods traverse the accessible elements and runs the criteria function against each traversee for a match. The traversal is performed either by accessible tree hierarchy or by accessible elements layout on the screen what depends on <code>Where</code> argument.
The search area and the way accessible elements are traversed are defined by <code>Where</code> argument. It defines whether traversal is perfromed by accessible tree hierarchy or by layout on the screen, and whether the traversal is relative of the current position or relative of the root.


<pre>
<pre>
Line 829: Line 829:
::Search backwards from the accessible position in cycle.
::Search backwards from the accessible position in cycle.


Where .''tofirst''
Where .''first''
::Search for a first match inside the root.
::Search for a first match inside the root.


Where .''tolast''
Where .''last''
::Search backwards (from last to first element) for a first match inside the root.
::Search backwards (from last to first element) for a first match inside the root.


Line 858: Line 858:




Examples:
<b>Example.</b>
 
<pre>
<pre>
function criteria(el) { }
function criteria(el) { }
var pos1 = new A11ePos(new DOMPoint(x, y), a11edoc).move("forward", criteria);
var pos1 = new A11ePos(new DOMPoint(x, y), a11edoc).move("forward", criteria);


Line 871: Line 873:




=====Criteria=====


=====Criteria function=====
Criteria can be either a literal describing how the position should be moved or a matching function called for every traversed accessible.


<pre>
<pre>
callback Controller = SearchTerm sequence<SearchTerm> (AccessibleElement);
typedef CriteriaLiteral or CriteriaFunc Criteria;
</pre>
</pre>
<code>
Controller
::A matching function used to define an algorithm of how the position is moved through the document.
::Returns
:::a search term(s)
</code>




<pre>
<pre>
enum SearchTerm {
enum CriteriaLiteral {
   "char",
   "char",
   "word",
   "word",
Line 895: Line 890:
   "paragraph",
   "paragraph",
   "change",
   "change",
   "bit",
   "bit"
 
  "at",
  "skipsubtree",
  "stop",
  "next"
};
};
</pre>
</pre>


<code>
<code>
SearchTerm .''char''
CriteriaLiteral .''char''
::Used to move the position one char long.
::Used to move the position one char long.
</code>


<code>
CriteriaLiteral .''word''
SearchTerm .''word''
::Used to move the position to the next word.
::Used to move the position to the next word.
</code>


<code>
CriteriaLiteral .''sentence''
SearchTerm .''sentence''
::Used to move the position to the next sentence.
::Used to move the position to the next sentence.
</code>


<code>
CriteriaLiteral .''line''
SearchTerm .''line''
::Used to move the position to beginning of next line or end of previous line.
::Used to move the position to beginning of next line or end of previous line.
</code>


<code>
CriteriaLiteral .''paragraph''
SearchTerm .''paragraph''
::Used to move the position to beginning of next/previous paragraph.
::Used to move the position to beginning of next/previous paragraph.
</code>


<code>
CriteriaLiteral .''change''
SearchTerm .''change''
::Used to move the position to next change either of text attribute or new accessible.
::Used to move the position to next change either of text attribute or new accessible.
</code>


<code>
CriteriaLiteral .''bit''
SearchTerm .''bit''
::Used to move the position to next/previous navigable position. For example, from accessible start inside of it to right before accessible outside of it or moving from end of this line to start of next line in case of soft line break lines.
::Used to move the position to next/previous navigable position. For example, from accessible start inside of it to right before accessible outside of it or moving from end of this line to start of next line in case of soft line break lines.
</code>
</code>




<code>
<b>Example #1. Traverse a paragraph by words.</b>
SearchTerm .''at''
::Used to set the position at the element. Search is stopped.
 
SearchTerm .''stop''
::Search is discontinued after other search terms are processed.
 
SearchTerm .''skipsubtree''
::Subtree of traversed element is ignored for next step.
 
SearchTerm .''next''
::Used to continue the search if other search terms weren't succeed. Default option.
</code>
 
 
<b>Example. Traverse a paragraph by words.</b>


<pre>
<pre>
var p = document.getElementById("p").a11ement;
var p = document.getElementById("p").a11ement;
var pos1 = new A11ePos(p, "afterbegin"), pos2 = null;
var pos1 = new A11ePos(p, "begin", p), pos2 = null;
while (pos2 = pos1.search("forward", () = > { return "word"; })) {
while (pos2 = pos1.search("forward", "word")) {
   console.log(pos2.textInBetween(pos1));
   console.log(pos2.textInBetween(pos1));
   pos1 = pos2;
   pos1 = pos2;
Line 967: Line 930:


<pre>
<pre>
<p>Mozilla is a <a href="">free-software</a> community which
<p id="p">Mozilla is a <a href="">free-software</a> community which
produces the <a href="">Firefox web browser</a>.</p>
produces the <a href="">Firefox web browser</a>.</p>
<p>Mo<a href="">zilla</a>.</p>
</pre>
</pre>


the log is "Mozilla ", "is ", "a ", "free-", "software ", "community", "which ", "produces ", "the ", "Firefox ", "web ", "browser."
the log is "Mozilla ", "is ", "a ", "free-", "software ", "community", "which ", "produces ", "the ", "Firefox ", "web ", "browser."


The log is "It ", "is ", "Mozilla".


<b>Examples.</b>
<b>Example #2. Traverse by words.</b>
 
<pre>
<p id="p">Mo<a href="">zilla</a>.</p>
</pre>
 
The log is "Mozilla".
 
<b>Examples #3.</b>


<pre>
<pre>
Line 993: Line 962:
</pre>
</pre>
pos2 equals to pos1, pos3 points after "fellow" word in the link.
pos2 equals to pos1, pos3 points after "fellow" word in the link.
<pre>
callback CriteriaFunc = CriteriaLiteral or Offset or "next" (AccessibleElement);
</pre>
<code>
CriteriaFunc
::A criteria function used to define an algorithm of how the position is moved through the document.
::Returns
:::a search term(s)
</code>
If "next" is returned then criteria function is reentered with next traversed accessible. If offset is given then traversing is stopped, the accessible position is moved to the traversed accessible element and returned offset. If criteria literal is returned then the accessible position is moved to the position complying the criteria.




<b> Example. Navigate by widgets and structures, and by words in case of text.</b>
<b> Example. Navigate by widgets and structures, and by words in case of text.</b>
<pre>
<pre>
function controller(aEl)
function criteria(aEl)
{
{
   var role = document.taxonOf("role", aEl.role);
   var role = document.taxonOf("role", aEl.role);
   if (role.is("widget")
   if (role.is("widget")
     return [ "beforeend" ];
     return "at";


   if (role.is("structure")
   if (role.is("structure")
Line 1,008: Line 991:
   // Reenters with next accessible if it cannot move to the next word within this accessible.
   // Reenters with next accessible if it cannot move to the next word within this accessible.
   if (role.is("textcontainer"))
   if (role.is("textcontainer"))
     return "word";
     return "line";
// how to land on first line and then traverse all of them one by one?


   return "next";
   return "next";
Confirmed users
1,396

edits

Navigation menu