Accessibility/TextAttributes
Introduction
This article is targeted to reflect a support of text attributes by Gecko accessibility API. There is no implementation in Gecko yet. This is a draft of specification how we will do it.
Proposed API
Summary
This is the internal nsIAccessibleText method (not the ATK or IA2 method -- the implementation for those will consume this method).
The following method returns a collection of text attributes at the given offset, and calculates the range where returned attributes are stretched.
nsIPersistentProperties getTextAttributes(in long offset,
out long rangeStartOffset,
out long rangeEndOffset);
Parameters
- offset
- [in] the given offset
- rangeStartOffset
- [out] the start offset of the result range
- rangeEndOffset
- [out] the end offset of the result range
Ranges are not nested. They are consecutive, so that AT's always know when to ask for the next range. For example, for text 'abc
<b>
def
</b>
ghi', there are three ranges (0, 3), (3, 6) and (6, 9).
Return Value
A collection of text attributes (the list of pairs consisted from name and value). All text attributes that apply to the current range are exposed, but in order to conserve the amount of data passed, most text attributes will have reasonable defaults and will not be exposed in the list when they are equal to the default. For example, if font-style is "normal" it will not be exposed in the return value. See the list of text attributes below to find the defaults.
Events
When a certain text attribute is changed then 'EVENT_TEXT_ATTRIBUTE_CHANGED' event should be fired.
In IA2, there is no data to specify what attribute changed, and for what offsets. Therefore, the AT must cache attributes of any objects that it will want to know about text attribute changes for. For example, it can cache the the text attribute ranges for the current text accessible, and compare the previous text attribute runs with the current text attribute runs.
Events will be fired for the topic object to which they apply, in order to avoid floods of too many events. For example, if someone selects all and then boldfaces the selection -- every object in the accessible tree is essentially getting an attribute change. We will reduce the number of events by only firing the text attribute change event on the root accessible for the change.
Questions
ATK default attribute questions
- Should we support ATK default attributes? IA2 does not have them. We could do it through an object attribute, if we really need it.
Unit questions
- The IA2 site does not say what unit color values are exposed as -- it just says use CSS values. However, in CSS colors can be exposed in many different ways. You can use the color name, you can use a 3 digit hex value, a 6 digit hex value, 3 comma-separated unsigned shorts, .... Is it better just to get 3 comma separated unsigned shorts (R, G, B) so you can determine a name for the color yourself?
- We have a similar problem for anything exposing a length, e.g. margin-left. How do you want the units?
Event questions
- It's not clear how to track CSS style changes mapped to text attributes. Possibly some of those changes will lead accessible is recreated. For the most important case, rich text editing, there will be a DOM change.
List of supported attributes
Gecko specific
| Attribute name | Attribute description | Default value if attribute not exposed |
|---|---|---|
| direction | rtl or ltr for bidi text | ltr |
| border | not sure how best to expose these properties, or whether to (same with outline CSS property) | no border |
| language | What language is this text in, e.g. en-US (do we want this or do we use IA2::locale and make sure each locale change gets separate accessible object?) | same as doc itself? |
| misspelled | "true" if it is marked by the inline spell checker for being incorrectly spelled. Attribute not present in all other cases. | Not misspelled |
| static | "true" for list bullet/numbering text or layout-inserted text (such as via CSS pseudo styles :before or :after) | false |
| z-index | a number which indicates how low/high an element is | 0 (normal height) |
Linux Foundation Proposed (ATK + IA2)
Note: the following characters in names and values need to be escaped with a backslash: backslash, colon, comma, equals, and semicolon.
| Attribute name | Attribute description | Default value if attribute not exposed |
|---|---|---|
| background-color | Background color as u, u, u | no default, always specified? |
| color | Foreground color as u, u, u | no default, always specified? |
| font-family | The computed font name | no default, always specified? |
| font-size | Font size in pixels | no default, always specified? |
| font-style | italic (oblique not currently supported) | normal |
| font-weight | The computed font weight (100, 200, 300, 400, 500, 600, 700, 800, 900; normal = 400, bold = 700) | 400 |
| text-line-through-style | solid (only exposed if if there is a line through) | no line through |
| text-underline-style | solid (only exposed if if there is an underline) | no underline |
| line-height | CSS2 (Too vague? Wouldn't it be better to only provide one unit ever?) | no default, always specified? |
| margin-bottom | CSS2 (Too vague? Wouldn't it be better to only provide one unit ever?) | no default, always specified? |
| margin-left | CSS2 (Too vague? Wouldn't it be better to only provide one unit ever?) | no default, always specified? |
| margin-right | CSS2 (Too vague? Wouldn't it be better to only provide one unit ever?) | no default, always specified? |
| text-align | left/center/right/justify | left |
| text-indent | CSS2 (Too vague? Wouldn't it be better to only provide one unit ever?) | no indent |
| text-position (for sup/sub) | ? | ? |
Currently unsupported
The following text attributes, which are in the IAccessible2 text attribute specification, are not currently supported due to today's limitations of text formatting on the web:
- text-line-through-mode
- text-line-through-type
- text-underline-type
- text-underline-width
- text-underline-mode
- list -- the list bullet text is exposed via the accessible text interface, with the text attribute static=true
- tab-stop
- text-shadow
References
- IA2 Text Attributes - IAccessible2 Text Attributes Documentation