Accessibility/TextAttributes
<< Back to Accessibility Home Page
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
The following method returns a collection of text attributes at the given offset, and calculates the range where returned attributes are stretched.
| API | Attributes for a text range | Attributes for entire object |
|---|---|---|
| Internal XPCOM |
nsIPersistentProperties
getTextAttributes(in long offset,
out long rangeStartOffset,
out long rangeEndOffset);
|
nsIPersistentProperties getDefaultTextAttributes(); |
| IAccessible2 |
HRESULT
get_attributes(in long offset,
long *rangeStartOffset,
long *rangeEndOFfset,
BSTR *textAttributes);
|
Not supported: Combined into get_attributes() results. |
| AT-SPI |
string
getAttributes(in long offset,
out long *rangeStartOffset,
out long *rangeEndOffset);
|
string getDefaultAttributes(); |
Parameters (for getTextAttributes/get_attributes/getAttributes)
- 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 for both methods
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.
The IA2 and ATK/AT-SPI return value is a single strange in the format name:value;name:value;name:value etc.
Events
When a certain text attribute is changed then the internal event 'EVENT_TEXT_ATTRIBUTE_CHANGED' 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.
For Firefox 3, events will not be fired for style changes that are not caused by DOM changes. At the moment we are focused on the rich text editing use case. For rich text editing there will always be a DOM change.
List of supported attributes
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 |
|---|---|---|
| auto-generated | "true" for list bullet/numbering text or layout-inserted text (such as via CSS pseudo styles :before or :after) | false |
| background-color | Background color as rgb(r,g,b) where r, g and b are 0-255
|
transparent |
| color | Foreground color as rgb(r,g,b) where r, g and b are 0-255
|
rgb(0,0,0) |
| font-family | The computed font name | no default, always specified |
| font-size | Font size in points | 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, bolder = 900) | 400 |
| invalid | "spelling" if it is marked by the inline spell checker for being incorrectly spelled. Attribute not present in all other cases. Also can support "grammar" or "true" (generally invalid but no reason given) since aria-invalid can be used to mark up any span, and aria-invalid must map to this. | Not misspelled or invalid in any way |
| 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?) We purposely call this language and not lang, to be in line with the IA2 text attributes spec. | en-US |
| 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 |
| text-align | left/center/right/justify | left |
| text-indent | [#]mm where [#] is the number of millimeters (max precision = 1/100 of a millimeter). The text "mm" must come after the number. | 0 = no indent |
| text-position (for sup/sub) | super/sub (translate from values in vertical-align) | none |
| writing-mode | rl or lr (we don't support tb - top to bottom) | lr |
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-line-through-width
- text-outline
- text-shadow
- text-underline-type
- text-underline-width
- text-underline-mode
The following object attribute in IA2 is not supported, because we support it via text attributes in a different way:
- list (with sub-attributes style, level & prefix) -- the list bullet text is exposed via the accessible text interface, with the text attribute static=true
The following IA2 object attributes are not supported, but potentially could be if asked for. We may need them to fully support online word processors, but need to think about how to pass on the true intentions of the word processor at that place in the text. In fact, it is currently possible for the word processor to specify these on any object by prepending aria- to the object attribute name and simply insert the attribute on the appropriate element.
- line-height
- line-spacing
- text-align
- text-indent
- margin-left, margin-top, margin-right, margin-bottom: these object attributes are not supported, because the related browser CSS attributes have nothing to do with page margins as the IA2 object attributes do. In Mozilla the bounds of an object can be used to find where it is located.
References
- IA2 Text Attributes - IAccessible2 Text Attributes Documentation