CacheConstants.h (13940B)
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/. */ 6 7 #ifndef _CacheConstants_h_ 8 #define _CacheConstants_h_ 9 10 #include "nsGkAtoms.h" 11 #include "mozilla/a11y/RelationType.h" 12 13 namespace mozilla { 14 namespace a11y { 15 16 class CacheDomain { 17 public: 18 static constexpr uint64_t None = 0; 19 static constexpr uint64_t NameAndDescription = ((uint64_t)0x1) << 0; 20 static constexpr uint64_t Value = ((uint64_t)0x1) << 1; 21 static constexpr uint64_t Bounds = ((uint64_t)0x1) << 2; 22 static constexpr uint64_t Resolution = ((uint64_t)0x1) << 3; 23 static constexpr uint64_t Text = ((uint64_t)0x1) << 4; 24 static constexpr uint64_t DOMNodeIDAndClass = ((uint64_t)0x1) << 5; 25 static constexpr uint64_t State = ((uint64_t)0x1) << 6; 26 static constexpr uint64_t GroupInfo = ((uint64_t)0x1) << 7; 27 static constexpr uint64_t Actions = ((uint64_t)0x1) << 8; 28 static constexpr uint64_t Style = ((uint64_t)0x1) << 9; 29 static constexpr uint64_t TransformMatrix = ((uint64_t)0x1) << 10; 30 static constexpr uint64_t ScrollPosition = ((uint64_t)0x1) << 11; 31 static constexpr uint64_t Table = ((uint64_t)0x1) << 12; 32 static constexpr uint64_t TextOffsetAttributes = ((uint64_t)0x1) << 13; 33 static constexpr uint64_t Viewport = ((uint64_t)0x1) << 14; 34 static constexpr uint64_t ARIA = ((uint64_t)0x1) << 15; 35 static constexpr uint64_t Relations = ((uint64_t)0x1) << 16; 36 #ifdef XP_WIN 37 // Used for MathML. 38 static constexpr uint64_t InnerHTML = ((uint64_t)0x1) << 17; 39 #endif 40 static constexpr uint64_t TextBounds = ((uint64_t)0x1) << 18; 41 static constexpr uint64_t APZ = ((uint64_t)0x1) << 19; 42 static constexpr uint64_t All = ~((uint64_t)0x0); 43 }; 44 45 enum class CacheUpdateType { 46 /* 47 * An initial cache push of a loaded document or inserted subtree. 48 */ 49 Initial, 50 51 /* 52 * An incremental cache push of one or more fields that have changed. 53 */ 54 Update, 55 }; 56 57 struct RelationData { 58 nsStaticAtom* const mAtom; 59 nsStaticAtom* const mValidTag; 60 RelationType mType; 61 RelationType mReverseType; 62 }; 63 64 /** 65 * This array of RelationData lists our relation types (explicit and reverse) 66 * and the cache attribute atoms that store their targets. Attributes may 67 * describe different kinds of relations, depending on the element they 68 * originate on. For example, an <output> element's `for` attribute describes a 69 * CONTROLLER_FOR relation, while the `for` attribute of a <label> describes a 70 * LABEL_FOR relation. To ensure we process these attributes appropriately, 71 * RelationData.mValidTag contains the atom for the tag this attribute/relation 72 * type pairing is valid on. If the pairing is valid for all tag types, this 73 * field is null. 74 */ 75 static constexpr RelationData kRelationTypeAtoms[] = { 76 {nsGkAtoms::aria_labelledby, nullptr, RelationType::LABELLED_BY, 77 RelationType::LABEL_FOR}, 78 {nsGkAtoms::_for, nsGkAtoms::label, RelationType::LABEL_FOR, 79 RelationType::LABELLED_BY}, 80 {nsGkAtoms::aria_controls, nullptr, RelationType::CONTROLLER_FOR, 81 RelationType::CONTROLLED_BY}, 82 {nsGkAtoms::_for, nsGkAtoms::output, RelationType::CONTROLLED_BY, 83 RelationType::CONTROLLER_FOR}, 84 {nsGkAtoms::aria_describedby, nullptr, RelationType::DESCRIBED_BY, 85 RelationType::DESCRIPTION_FOR}, 86 {nsGkAtoms::aria_flowto, nullptr, RelationType::FLOWS_TO, 87 RelationType::FLOWS_FROM}, 88 {nsGkAtoms::aria_details, nullptr, RelationType::DETAILS, 89 RelationType::DETAILS_FOR}, 90 {nsGkAtoms::commandfor, nullptr, RelationType::DETAILS, 91 RelationType::DETAILS_FOR}, 92 {nsGkAtoms::popovertarget, nullptr, RelationType::DETAILS, 93 RelationType::DETAILS_FOR}, 94 {nsGkAtoms::target, nullptr, RelationType::DETAILS, 95 RelationType::DETAILS_FOR}, 96 {nsGkAtoms::aria_errormessage, nullptr, RelationType::ERRORMSG, 97 RelationType::ERRORMSG_FOR}, 98 {nsGkAtoms::aria_actions, nullptr, RelationType::ACTION, 99 RelationType::ACTION_FOR}, 100 }; 101 102 // The count of numbers needed to serialize an nsRect. This is used when 103 // flattening character rects into an array of ints. 104 constexpr int32_t kNumbersInRect = 4; 105 106 /** 107 * RemoteAccessible cache keys. 108 * Cache keys are nsAtoms, but this is mostly an implementation detail. Rather 109 * than creating new atoms specific to the RemoteAccessible cache, we often 110 * reuse existing atoms which are a reasonably close match for the value we're 111 * caching, though the choices aren't always clear or intuitive. For clarity, we 112 * alias the cache keys to atoms below. Code dealing with the RemoteAccessible 113 * cache should generally use these aliases rather than using nsAtoms directly. 114 * There are two exceptions: 115 * 1. Some ARIA attributes are copied directly from the DOM node, so these 116 * aren't aliased. Specifically, aria-level, aria-posinset and aria-setsize 117 * are copied as separate cache keys as part of CacheDomain::GroupInfo. 118 * 2. Keys for relations are defined in kRelationTypeAtoms above. 119 */ 120 class CacheKey { 121 public: 122 // uint64_t, CacheDomain::Actions 123 // As returned by Accessible::AccessKey. 124 static constexpr nsStaticAtom* AccessKey = nsGkAtoms::accesskey; 125 // int32_t, no domain 126 static constexpr nsStaticAtom* AppUnitsPerDevPixel = 127 nsGkAtoms::_moz_device_pixel_ratio; 128 // nsTArray<uint32_t>, CacheDomain::APZ 129 // The difference between the layout viewport and the visual viewport in app 130 // units. This is stored as a two-element (x, y) array and is unscaled by zoom 131 // or resolution. 132 static constexpr nsStaticAtom* VisualViewportOffset = nsGkAtoms::voffset; 133 // AccAttributes, CacheDomain::ARIA 134 // ARIA attributes that are exposed as object attributes; i.e. returned in 135 // Accessible::Attributes. 136 static constexpr nsStaticAtom* ARIAAttributes = nsGkAtoms::aria; 137 // nsString, CacheUpdateType::Initial 138 // The ARIA role attribute if the role is unknown or if there are multiple 139 // roles. 140 static constexpr nsStaticAtom* ARIARole = nsGkAtoms::role; 141 // bool, CacheDomain::State 142 // The aria-selected attribute. 143 static constexpr nsStaticAtom* ARIASelected = nsGkAtoms::aria_selected; 144 // nsTArray<uint64_t>, CacheDomain::Table 145 // The explicit headers of an HTML table cell. 146 static constexpr nsStaticAtom* CellHeaders = nsGkAtoms::headers; 147 // int32_t, CacheDomain::Table 148 // The colspan of an HTML table cell. 149 static constexpr nsStaticAtom* ColSpan = nsGkAtoms::colspan; 150 // nsTArray<int32_t, 2>, CacheDomain::Bounds 151 // The offset from an OuterDocAccessible (iframe) to its embedded document. 152 static constexpr nsStaticAtom* CrossDocOffset = nsGkAtoms::crossorigin; 153 // nsAtom, CacheDomain::Style 154 // CSS display; block, inline, etc. 155 static constexpr nsStaticAtom* CSSDisplay = nsGkAtoms::display; 156 // nsAtom, CacheDomain::Style 157 // CSS overflow; e.g. hidden. 158 static constexpr nsStaticAtom* CSSOverflow = nsGkAtoms::overflow; 159 // nsAtom, CacheDomain::Style 160 // CSS position; e.g. fixed. 161 static constexpr nsStaticAtom* CssPosition = nsGkAtoms::position; 162 // nsString, CacheDomain::NameAndDescription 163 static constexpr nsStaticAtom* CssAltContent = nsGkAtoms::content; 164 // nsString, CacheDomain::NameAndDescription 165 static constexpr nsStaticAtom* Description = nsGkAtoms::description; 166 // EDescriptionValueFlag, CacheDomain::NameAndDescription 167 // Returned by Accessible::Description. 168 static constexpr nsStaticAtom* DescriptionValueFlag = 169 nsGkAtoms::aria_description; 170 // nsString, CacheDomain::Relations 171 // The "name" DOM attribute. 172 static constexpr nsStaticAtom* DOMName = nsGkAtoms::attributeName; 173 // nsAtom, CacheDomain::DOMNodeIDAndClass 174 // The "class" DOM attribute. 175 static constexpr nsStaticAtom* DOMNodeClass = nsGkAtoms::_class; 176 // nsAtom, CacheDomain::DOMNodeIDAndClass 177 static constexpr nsStaticAtom* DOMNodeID = nsGkAtoms::id; 178 // AccGroupInfo, no domain 179 static constexpr nsStaticAtom* GroupInfo = nsGkAtoms::group; 180 // nsTArray<int32_t>, no domain 181 // As returned by HyperTextAccessibleBase::CachedHyperTextOffsets. 182 static constexpr nsStaticAtom* HyperTextOffsets = nsGkAtoms::offset; 183 // bool, CacheDomain::ARIA 184 // Accessible has aria-actions 185 static constexpr nsStaticAtom* HasActions = nsGkAtoms::hasActions; 186 // bool, CacheDomain::Actions 187 // Whether this image has a longdesc. 188 static constexpr nsStaticAtom* HasLongdesc = nsGkAtoms::longdesc; 189 // nsString, CacheDomain::NameAndDescription 190 static constexpr nsStaticAtom* HTMLPlaceholder = nsGkAtoms::placeholder; 191 #ifdef XP_WIN 192 // nsString, CacheDomain::InnerHTML 193 static constexpr nsStaticAtom* InnerHTML = nsGkAtoms::html; 194 #endif 195 // nsAtom, CacheUpdateType::Initial 196 // The type of an <input> element; tel, email, etc. 197 static constexpr nsStaticAtom* InputType = nsGkAtoms::textInputType; 198 // bool, CacheDomain::Bounds 199 // Whether the Accessible is fully clipped. 200 static constexpr nsStaticAtom* IsClipped = nsGkAtoms::clip_rule; 201 // nsAtom, CacheDomain::Text 202 // As returned by Accessible::Language. 203 static constexpr nsStaticAtom* Language = nsGkAtoms::language; 204 // nsString, CacheUpdateType::Initial 205 static constexpr nsStaticAtom* MimeType = nsGkAtoms::headerContentType; 206 // double, CacheDomain::Value 207 static constexpr nsStaticAtom* MaxValue = nsGkAtoms::max; 208 // double, CacheDomain::Value 209 static constexpr nsStaticAtom* MinValue = nsGkAtoms::min; 210 // nsString, CacheDomain::NameAndDescription 211 static constexpr nsStaticAtom* Name = nsGkAtoms::name; 212 // double, CacheDomain::Value 213 // The numeric value returned by Accessible::CurValue. 214 static constexpr nsStaticAtom* NumericValue = nsGkAtoms::value; 215 // float, CacheDomain::Style 216 static constexpr nsStaticAtom* Opacity = nsGkAtoms::opacity; 217 // nsTArray<int32_t, 4>, CacheDomain::Bounds 218 // The screen bounds relative to the parent Accessible 219 // as returned by LocalAccessible::ParentRelativeBounds. 220 static constexpr nsStaticAtom* ParentRelativeBounds = 221 nsGkAtoms::relativeBounds; 222 // nsAtom, CacheUpdateType::Initial 223 // The type of a popup (used for HTML popover). 224 static constexpr nsStaticAtom* PopupType = nsGkAtoms::ispopup; 225 // nsAtom, CacheDomain::Actions 226 static constexpr nsStaticAtom* PrimaryAction = nsGkAtoms::action; 227 // float, no domain 228 // Document resolution. 229 static constexpr nsStaticAtom* Resolution = nsGkAtoms::resolution; 230 // int32_t, CacheDomain::Table 231 // The rowspan of an HTML table cell. 232 static constexpr nsStaticAtom* RowSpan = nsGkAtoms::rowspan; 233 // nsTArray<int32_t, 2>, CacheDomain::ScrollPosition 234 static constexpr nsStaticAtom* ScrollPosition = nsGkAtoms::scrollPosition; 235 // nsTArray<TextOffsetAttribute>, 236 // CacheDomain::TextOffsetAttributes | CacheDomain::Text 237 // Text offset attributes such as spelling errors. 238 static constexpr nsStaticAtom* TextOffsetAttributes = nsGkAtoms::spelling; 239 // nsString, CacheDomain::Value 240 // The src URL of images. 241 static constexpr nsStaticAtom* SrcURL = nsGkAtoms::src; 242 // uint64_t, CacheDomain::State 243 // As returned by Accessible::State. 244 static constexpr nsStaticAtom* State = nsGkAtoms::state; 245 // double, CacheDomain::Value 246 // The value step returned by Accessible::Step. 247 static constexpr nsStaticAtom* Step = nsGkAtoms::step; 248 // nsAtom, CacheUpdateType::Initial 249 // The tag name of the element. 250 static constexpr nsStaticAtom* TagName = nsGkAtoms::tag; 251 // bool, CacheDomain::Table 252 // Whether this is a layout table. 253 static constexpr nsStaticAtom* TableLayoutGuess = nsGkAtoms::layout_guess; 254 // nsString, CacheDomain::Text 255 // The text of TextLeafAccessibles. 256 static constexpr nsStaticAtom* Text = nsGkAtoms::text; 257 // AccAttributes, CacheDomain::Text 258 // Text attributes; font, etc. 259 static constexpr nsStaticAtom* TextAttributes = nsGkAtoms::style; 260 // nsTArray<int32_t, 4 * n>, CacheDomain::TextBounds 261 // The bounds of each character in a text leaf. 262 static constexpr nsStaticAtom* TextBounds = nsGkAtoms::characterData; 263 // nsTArray<int32_t>, CacheDomain::TextBounds 264 // The text offsets where new lines start. 265 static constexpr nsStaticAtom* TextLineStarts = nsGkAtoms::line; 266 // nsString, CacheDomain::Value 267 // The textual value returned by Accessible::Value (as opposed to 268 // the numeric value returned by Accessible::CurValue). 269 static constexpr nsStaticAtom* TextValue = nsGkAtoms::aria_valuetext; 270 // nsString, CacheDomain::NameAndDescription 271 static constexpr nsStaticAtom* Tooltip = nsGkAtoms::tooltip; 272 // gfx::Matrix4x4, CacheDomain::TransformMatrix 273 static constexpr nsStaticAtom* TransformMatrix = nsGkAtoms::transform; 274 // int32_t, CacheDomain::Value 275 static constexpr nsStaticAtom* ValueRegion = nsGkAtoms::valuetype; 276 // nsTArray<uint64_t>, CacheDomain::Viewport 277 // The list of Accessibles in the viewport used for hit testing and on-screen 278 // determination. 279 static constexpr nsStaticAtom* Viewport = nsGkAtoms::viewport; 280 // Computed writing mode 281 static constexpr nsStaticAtom* WritingMode = nsGkAtoms::writing_mode; 282 }; 283 284 // Return true if the given cache domains are already active. 285 bool DomainsAreActive(uint64_t aRequiredCacheDomains); 286 287 // Check whether the required cache domains are active. If they aren't, then 288 // request the requisite cache domains and return true. This function returns 289 // false if all required domains are already active. 290 bool RequestDomainsIfInactive(uint64_t aRequiredCacheDomains); 291 292 #define ASSERT_DOMAINS_ACTIVE(aCacheDomains) \ 293 MOZ_ASSERT( \ 294 (GetAccService() && !GetAccService()->ShouldAllowNewCacheDomains()) || \ 295 DomainsAreActive(aCacheDomains), \ 296 "Required domain(s) are not currently active.") 297 298 } // namespace a11y 299 } // namespace mozilla 300 301 #endif