Merge autoland to mozilla-central. a=merge
[gecko.git] / accessible / base / CacheConstants.h
blob4a0238aad3942d50b2ae85be9486c3b66afbf1f5
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set expandtab shiftwidth=2 tabstop=2: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef _CacheConstants_h_
8 #define _CacheConstants_h_
10 #include "nsGkAtoms.h"
11 #include "mozilla/a11y/RelationType.h"
13 namespace mozilla {
14 namespace a11y {
16 class CacheDomain {
17 public:
18 static constexpr uint64_t NameAndDescription = ((uint64_t)0x1) << 0;
19 static constexpr uint64_t Value = ((uint64_t)0x1) << 1;
20 static constexpr uint64_t Bounds = ((uint64_t)0x1) << 2;
21 static constexpr uint64_t Resolution = ((uint64_t)0x1) << 3;
22 static constexpr uint64_t Text = ((uint64_t)0x1) << 4;
23 static constexpr uint64_t DOMNodeIDAndClass = ((uint64_t)0x1) << 5;
24 static constexpr uint64_t State = ((uint64_t)0x1) << 6;
25 static constexpr uint64_t GroupInfo = ((uint64_t)0x1) << 7;
26 static constexpr uint64_t Actions = ((uint64_t)0x1) << 8;
27 static constexpr uint64_t Style = ((uint64_t)0x1) << 9;
28 static constexpr uint64_t TransformMatrix = ((uint64_t)0x1) << 10;
29 static constexpr uint64_t ScrollPosition = ((uint64_t)0x1) << 11;
30 static constexpr uint64_t Table = ((uint64_t)0x1) << 12;
31 static constexpr uint64_t Spelling = ((uint64_t)0x1) << 13;
32 static constexpr uint64_t Viewport = ((uint64_t)0x1) << 14;
33 static constexpr uint64_t ARIA = ((uint64_t)0x1) << 15;
34 static constexpr uint64_t Relations = ((uint64_t)0x1) << 16;
35 #ifdef XP_WIN
36 // Used for MathML.
37 static constexpr uint64_t InnerHTML = ((uint64_t)0x1) << 17;
38 #endif
39 static constexpr uint64_t All = ~((uint64_t)0x0);
42 enum class CacheUpdateType {
44 * An initial cache push of a loaded document or inserted subtree.
46 Initial,
49 * An incremental cache push of one or more fields that have changed.
51 Update,
54 struct RelationData {
55 nsStaticAtom* const mAtom;
56 nsStaticAtom* const mValidTag;
57 RelationType mType;
58 RelationType mReverseType;
61 /**
62 * This array of RelationData lists our relation types (explicit and reverse)
63 * and the cache attribute atoms that store their targets. Attributes may
64 * describe different kinds of relations, depending on the element they
65 * originate on. For example, an <output> element's `for` attribute describes a
66 * CONTROLLER_FOR relation, while the `for` attribute of a <label> describes a
67 * LABEL_FOR relation. To ensure we process these attributes appropriately,
68 * RelationData.mValidTag contains the atom for the tag this attribute/relation
69 * type pairing is valid on. If the pairing is valid for all tag types, this
70 * field is null.
72 static constexpr RelationData kRelationTypeAtoms[] = {
73 {nsGkAtoms::aria_labelledby, nullptr, RelationType::LABELLED_BY,
74 RelationType::LABEL_FOR},
75 {nsGkAtoms::_for, nsGkAtoms::label, RelationType::LABEL_FOR,
76 RelationType::LABELLED_BY},
77 {nsGkAtoms::aria_controls, nullptr, RelationType::CONTROLLER_FOR,
78 RelationType::CONTROLLED_BY},
79 {nsGkAtoms::_for, nsGkAtoms::output, RelationType::CONTROLLED_BY,
80 RelationType::CONTROLLER_FOR},
81 {nsGkAtoms::aria_describedby, nullptr, RelationType::DESCRIBED_BY,
82 RelationType::DESCRIPTION_FOR},
83 {nsGkAtoms::aria_flowto, nullptr, RelationType::FLOWS_TO,
84 RelationType::FLOWS_FROM},
85 {nsGkAtoms::aria_details, nullptr, RelationType::DETAILS,
86 RelationType::DETAILS_FOR},
87 {nsGkAtoms::aria_errormessage, nullptr, RelationType::ERRORMSG,
88 RelationType::ERRORMSG_FOR},
91 // The count of numbers needed to serialize an nsRect. This is used when
92 // flattening character rects into an array of ints.
93 constexpr int32_t kNumbersInRect = 4;
95 /**
96 * RemoteAccessible cache keys.
97 * Cache keys are nsAtoms, but this is mostly an implementation detail. Rather
98 * than creating new atoms specific to the RemoteAccessible cache, we often
99 * reuse existing atoms which are a reasonably close match for the value we're
100 * caching, though the choices aren't always clear or intuitive. For clarity, we
101 * alias the cache keys to atoms below. Code dealing with the RemoteAccessible
102 * cache should generally use these aliases rather than using nsAtoms directly.
103 * There are two exceptions:
104 * 1. Some ARIA attributes are copied directly from the DOM node, so these
105 * aren't aliased. Specifically, aria-level, aria-posinset and aria-setsize
106 * are copied as separate cache keys as part of CacheDomain::GroupInfo.
107 * 2. Keys for relations are defined in kRelationTypeAtoms above.
109 class CacheKey {
110 public:
111 // uint64_t, CacheDomain::Actions
112 // As returned by Accessible::AccessKey.
113 static constexpr nsStaticAtom* AccessKey = nsGkAtoms::accesskey;
114 // int32_t, no domain
115 static constexpr nsStaticAtom* AppUnitsPerDevPixel =
116 nsGkAtoms::_moz_device_pixel_ratio;
117 // AccAttributes, CacheDomain::ARIA
118 // ARIA attributes that are exposed as object attributes; i.e. returned in
119 // Accessible::Attributes.
120 static constexpr nsStaticAtom* ARIAAttributes = nsGkAtoms::aria;
121 // nsString, CacheUpdateType::Initial
122 // The ARIA role attribute if the role is unknown or if there are multiple
123 // roles.
124 static constexpr nsStaticAtom* ARIARole = nsGkAtoms::role;
125 // bool, CacheDomain::State
126 // The aria-selected attribute.
127 static constexpr nsStaticAtom* ARIASelected = nsGkAtoms::aria_selected;
128 // nsTArray<uint64_t>, CacheDomain::Table
129 // The explicit headers of an HTML table cell.
130 static constexpr nsStaticAtom* CellHeaders = nsGkAtoms::headers;
131 // int32_t, CacheDomain::Table
132 // The colspan of an HTML table cell.
133 static constexpr nsStaticAtom* ColSpan = nsGkAtoms::colspan;
134 // nsTArray<int32_t, 2>, CacheDomain::Bounds
135 // The offset from an OuterDocAccessible (iframe) to its embedded document.
136 static constexpr nsStaticAtom* CrossDocOffset = nsGkAtoms::crossorigin;
137 // nsAtom, CacheDomain::Style
138 // CSS display; block, inline, etc.
139 static constexpr nsStaticAtom* CSSDisplay = nsGkAtoms::display;
140 // nsAtom, CacheDomain::Style
141 // CSS overflow; e.g. hidden.
142 static constexpr nsStaticAtom* CSSOverflow = nsGkAtoms::overflow;
143 // nsAtom, CacheDomain::Style
144 // CSS position; e.g. fixed.
145 static constexpr nsStaticAtom* CssPosition = nsGkAtoms::position;
146 // nsString, CacheDomain::NameAndDescription
147 static constexpr nsStaticAtom* Description = nsGkAtoms::description;
148 // nsString, CacheDomain::Relations
149 // The "name" DOM attribute.
150 static constexpr nsStaticAtom* DOMName = nsGkAtoms::attributeName;
151 // nsAtom, CacheDomain::DOMNodeIDAndClass
152 // The "class" DOM attribute.
153 static constexpr nsStaticAtom* DOMNodeClass = nsGkAtoms::_class;
154 // nsAtom, CacheDomain::DOMNodeIDAndClass
155 static constexpr nsStaticAtom* DOMNodeID = nsGkAtoms::id;
156 // AccGroupInfo, no domain
157 static constexpr nsStaticAtom* GroupInfo = nsGkAtoms::group;
158 // nsTArray<int32_t>, no domain
159 // As returned by HyperTextAccessibleBase::CachedHyperTextOffsets.
160 static constexpr nsStaticAtom* HyperTextOffsets = nsGkAtoms::offset;
161 // bool, CacheDomain::Actions
162 // Whether this image has a longdesc.
163 static constexpr nsStaticAtom* HasLongdesc = nsGkAtoms::longdesc;
164 // nsString, CacheDomain::NameAndDescription
165 static constexpr nsStaticAtom* HTMLPlaceholder = nsGkAtoms::placeholder;
166 #ifdef XP_WIN
167 // nsString, CacheDomain::InnerHTML
168 static constexpr nsStaticAtom* InnerHTML = nsGkAtoms::html;
169 #endif
170 // nsAtom, CacheUpdateType::Initial
171 // The type of an <input> element; tel, email, etc.
172 static constexpr nsStaticAtom* InputType = nsGkAtoms::textInputType;
173 // bool, CacheDomain::Bounds
174 // Whether the Accessible is fully clipped.
175 static constexpr nsStaticAtom* IsClipped = nsGkAtoms::clip_rule;
176 // nsAtom, CacheDomain::Text
177 // As returned by Accessible::Language.
178 static constexpr nsStaticAtom* Language = nsGkAtoms::language;
179 // nsString, CacheUpdateType::Initial
180 static constexpr nsStaticAtom* MimeType = nsGkAtoms::headerContentType;
181 // double, CacheDomain::Value
182 static constexpr nsStaticAtom* MaxValue = nsGkAtoms::max;
183 // double, CacheDomain::Value
184 static constexpr nsStaticAtom* MinValue = nsGkAtoms::min;
185 // nsString, CacheDomain::NameAndDescription
186 static constexpr nsStaticAtom* Name = nsGkAtoms::name;
187 // ENameValueFlag, CacheDomain::NameAndDescription
188 // Returned by Accessible::Name.
189 static constexpr nsStaticAtom* NameValueFlag = nsGkAtoms::explicit_name;
190 // double, CacheDomain::Value
191 // The numeric value returned by Accessible::CurValue.
192 static constexpr nsStaticAtom* NumericValue = nsGkAtoms::value;
193 // float, CacheDomain::Style
194 static constexpr nsStaticAtom* Opacity = nsGkAtoms::opacity;
195 // nsTArray<int32_t, 4>, CacheDomain::Bounds
196 // The screen bounds relative to the parent Accessible
197 // as returned by LocalAccessible::ParentRelativeBounds.
198 static constexpr nsStaticAtom* ParentRelativeBounds =
199 nsGkAtoms::relativeBounds;
200 // nsAtom, CacheUpdateType::Initial
201 // The type of a popup (used for HTML popover).
202 static constexpr nsStaticAtom* PopupType = nsGkAtoms::ispopup;
203 // nsAtom, CacheDomain::Actions
204 static constexpr nsStaticAtom* PrimaryAction = nsGkAtoms::action;
205 // float, no domain
206 // Document resolution.
207 static constexpr nsStaticAtom* Resolution = nsGkAtoms::resolution;
208 // int32_t, CacheDomain::Table
209 // The rowspan of an HTML table cell.
210 static constexpr nsStaticAtom* RowSpan = nsGkAtoms::rowspan;
211 // nsTArray<int32_t, 2>, CacheDomain::ScrollPosition
212 static constexpr nsStaticAtom* ScrollPosition = nsGkAtoms::scrollPosition;
213 // nsTArray<int32_t>, CacheDomain::Spelling | CacheDomain::Text
214 // The offsets of spelling errors.
215 static constexpr nsStaticAtom* SpellingErrors = nsGkAtoms::spelling;
216 // nsString, CacheDomain::Value
217 // The src URL of images.
218 static constexpr nsStaticAtom* SrcURL = nsGkAtoms::src;
219 // uint64_t, CacheDomain::State
220 // As returned by Accessible::State.
221 static constexpr nsStaticAtom* State = nsGkAtoms::state;
222 // double, CacheDomain::Value
223 // The value step returned by Accessible::Step.
224 static constexpr nsStaticAtom* Step = nsGkAtoms::step;
225 // nsAtom, CacheUpdateType::Initial
226 // The tag name of the element.
227 static constexpr nsStaticAtom* TagName = nsGkAtoms::tag;
228 // bool, CacheDomain::Table
229 // Whether this is a layout table.
230 static constexpr nsStaticAtom* TableLayoutGuess = nsGkAtoms::layout_guess;
231 // nsString, CacheDomain::Text
232 // The text of TextLeafAccessibles.
233 static constexpr nsStaticAtom* Text = nsGkAtoms::text;
234 // AccAttributes, CacheDomain::Text
235 // Text attributes; font, etc.
236 static constexpr nsStaticAtom* TextAttributes = nsGkAtoms::style;
237 // nsTArray<int32_t, 4 * n>, CacheDomain::Text | CacheDomain::Bounds
238 // The bounds of each character in a text leaf.
239 static constexpr nsStaticAtom* TextBounds = nsGkAtoms::characterData;
240 // nsTArray<int32_t>, CacheDomain::Text | CacheDomain::Bounds
241 // The text offsets where new lines start.
242 static constexpr nsStaticAtom* TextLineStarts = nsGkAtoms::line;
243 // nsString, CacheDomain::Value
244 // The textual value returned by Accessible::Value (as opposed to
245 // the numeric value returned by Accessible::CurValue).
246 static constexpr nsStaticAtom* TextValue = nsGkAtoms::aria_valuetext;
247 // gfx::Matrix4x4, CacheDomain::TransformMatrix
248 static constexpr nsStaticAtom* TransformMatrix = nsGkAtoms::transform;
249 // int32_t, CacheDomain::Value
250 static constexpr nsStaticAtom* ValueRegion = nsGkAtoms::valuetype;
251 // nsTArray<uint64_t>, CacheDomain::Viewport
252 // The list of Accessibles in the viewport used for hit testing and on-screen
253 // determination.
254 static constexpr nsStaticAtom* Viewport = nsGkAtoms::viewport;
257 } // namespace a11y
258 } // namespace mozilla
260 #endif