LocalAccessible.h (32068B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef _LocalAccessible_H_ 7 #define _LocalAccessible_H_ 8 9 #include "mozilla/ComputedStyle.h" 10 #include "mozilla/a11y/Accessible.h" 11 #include "mozilla/a11y/AccTypes.h" 12 #include "mozilla/a11y/CacheConstants.h" 13 #include "mozilla/a11y/RelationType.h" 14 #include "mozilla/a11y/States.h" 15 16 #include "mozilla/UniquePtr.h" 17 18 #include "nsIContent.h" 19 #include "nsTArray.h" 20 #include "nsRefPtrHashtable.h" 21 #include "nsRect.h" 22 23 struct nsRoleMapEntry; 24 25 class nsIFrame; 26 27 class nsAttrValue; 28 29 enum class AttrModType : uint8_t; // Defined in nsIMutationObserver.h 30 31 namespace mozilla::dom { 32 class Element; 33 } 34 35 namespace mozilla { 36 namespace a11y { 37 38 class LocalAccessible; 39 class AccAttributes; 40 class AccEvent; 41 class AccGroupInfo; 42 class ApplicationAccessible; 43 class CacheData; 44 class DocAccessible; 45 class EmbeddedObjCollector; 46 class EventTree; 47 class HTMLImageMapAccessible; 48 class HTMLLIAccessible; 49 class HTMLLinkAccessible; 50 class HyperTextAccessible; 51 class HyperTextAccessibleBase; 52 class ImageAccessible; 53 class KeyBinding; 54 class OuterDocAccessible; 55 class RemoteAccessible; 56 class Relation; 57 class RootAccessible; 58 class TableAccessible; 59 class TableCellAccessible; 60 class TextLeafAccessible; 61 class XULLabelAccessible; 62 class XULTreeAccessible; 63 64 enum class CacheUpdateType; 65 66 #ifdef A11Y_LOG 67 namespace logging { 68 typedef const char* (*GetTreePrefix)(void* aData, LocalAccessible*); 69 void Tree(const char* aTitle, const char* aMsgText, LocalAccessible* aRoot, 70 GetTreePrefix aPrefixFunc, void* GetTreePrefixData); 71 void TreeSize(const char* aTitle, const char* aMsgText, LocalAccessible* aRoot); 72 }; // namespace logging 73 #endif 74 75 typedef nsRefPtrHashtable<nsPtrHashKey<const void>, LocalAccessible> 76 AccessibleHashtable; 77 78 #define NS_ACCESSIBLE_IMPL_IID \ 79 {/* 133c8bf4-4913-4355-bd50-426bd1d6e1ad */ \ 80 0x133c8bf4, \ 81 0x4913, \ 82 0x4355, \ 83 {0xbd, 0x50, 0x42, 0x6b, 0xd1, 0xd6, 0xe1, 0xad}} 84 85 /** 86 * An accessibility tree node that originated in mDoc's content process. 87 */ 88 class LocalAccessible : public nsISupports, public Accessible { 89 public: 90 LocalAccessible(nsIContent* aContent, DocAccessible* aDoc); 91 92 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 93 NS_DECL_CYCLE_COLLECTION_CLASS(LocalAccessible) 94 95 NS_INLINE_DECL_STATIC_IID(NS_ACCESSIBLE_IMPL_IID) 96 97 ////////////////////////////////////////////////////////////////////////////// 98 // Public methods 99 100 /** 101 * Return the document accessible for this accessible. 102 */ 103 DocAccessible* Document() const { return mDoc; } 104 105 /** 106 * Return the root document accessible for this accessible. 107 */ 108 a11y::RootAccessible* RootAccessible() const; 109 110 /** 111 * Return frame for this accessible. 112 * Note that this will return null for display: contents. Also, 113 * DocAccessible::GetFrame can return null if the frame tree hasn't been 114 * created yet. 115 */ 116 virtual nsIFrame* GetFrame() const; 117 118 /** 119 * Return DOM node associated with the accessible. 120 */ 121 virtual nsINode* GetNode() const; 122 123 nsIContent* GetContent() const { return mContent; } 124 dom::Element* Elm() const; 125 126 /** 127 * Return node type information of DOM node associated with the accessible. 128 */ 129 bool IsContent() const { return GetNode() && GetNode()->IsContent(); } 130 131 /** 132 * Return the unique identifier of the accessible. 133 * ID() should be preferred, but this method still exists because many 134 * LocalAccessible callers expect a void*. 135 */ 136 void* UniqueID() { return static_cast<void*>(this); } 137 138 virtual uint64_t ID() const override { 139 return IsDoc() ? 0 : reinterpret_cast<uintptr_t>(this); 140 } 141 142 virtual void Language(nsAString& aLocale) override; 143 144 /** 145 * Get the description of this accessible. 146 */ 147 virtual EDescriptionValueFlag Description( 148 nsString& aDescription) const override; 149 150 /** 151 * Get the value of this accessible. 152 */ 153 virtual void Value(nsString& aValue) const override; 154 155 /** 156 * Get the name of this accessible. 157 */ 158 virtual ENameValueFlag Name(nsString& aName) const override final; 159 160 virtual ENameValueFlag DirectName(nsString& aName) const; 161 162 /** 163 * Maps ARIA state attributes to state of accessible. Note the given state 164 * argument should hold states for accessible before you pass it into this 165 * method. 166 * 167 * @param [in/out] where to fill the states into. 168 */ 169 virtual void ApplyARIAState(uint64_t* aState) const; 170 171 /** 172 * Return accessible role specified by ARIA (see constants in 173 * roles). 174 */ 175 inline mozilla::a11y::role ARIARole(); 176 177 /** 178 * Returns enumerated accessible role from native markup (see constants in 179 * Role.h). Doesn't take into account ARIA roles. 180 */ 181 virtual mozilla::a11y::role NativeRole() const override; 182 183 virtual uint64_t State() override; 184 185 /** 186 * Return interactive states present on the accessible 187 * (@see NativeInteractiveState). 188 */ 189 uint64_t InteractiveState() const { 190 uint64_t state = NativeInteractiveState(); 191 ApplyARIAState(&state); 192 return state; 193 } 194 195 /** 196 * Return link states present on the accessible. 197 */ 198 uint64_t LinkState() const { 199 uint64_t state = NativeLinkState(); 200 ApplyARIAState(&state); 201 return state; 202 } 203 204 /** 205 * Return the states of accessible, not taking into account ARIA states. 206 * Use State() to get complete set of states. 207 */ 208 virtual uint64_t NativeState() const; 209 210 /** 211 * Return native interactice state (unavailable, focusable or selectable). 212 */ 213 virtual uint64_t NativeInteractiveState() const; 214 215 /** 216 * Return native link states present on the accessible. 217 */ 218 virtual uint64_t NativeLinkState() const; 219 220 /** 221 * Return bit set of invisible and offscreen states. 222 */ 223 uint64_t VisibilityState() const; 224 225 /** 226 * Return true if native unavailable state present. 227 */ 228 virtual bool NativelyUnavailable() const; 229 230 virtual already_AddRefed<AccAttributes> Attributes() override; 231 232 /** 233 * Return direct or deepest child at the given point. 234 * 235 * @param aX [in] x coordinate relative screen 236 * @param aY [in] y coordinate relative screen 237 * @param aWhichChild [in] flag points if deepest or direct child 238 * should be returned 239 */ 240 virtual LocalAccessible* LocalChildAtPoint(int32_t aX, int32_t aY, 241 EWhichChildAtPoint aWhichChild); 242 243 /** 244 * Similar to LocalChildAtPoint but crosses process boundaries. 245 */ 246 virtual Accessible* ChildAtPoint(int32_t aX, int32_t aY, 247 EWhichChildAtPoint aWhichChild) override; 248 249 virtual Relation RelationByType(RelationType aType) const override; 250 251 ////////////////////////////////////////////////////////////////////////////// 252 // Initializing methods 253 254 /** 255 * Shutdown this accessible object. 256 */ 257 virtual void Shutdown(); 258 259 /** 260 * Set the ARIA role map entry for a new accessible. 261 */ 262 inline void SetRoleMapEntry(const nsRoleMapEntry* aRoleMapEntry); 263 264 /** 265 * Append/insert/remove a child. Return true if operation was successful. 266 */ 267 bool AppendChild(LocalAccessible* aChild) { 268 return InsertChildAt(mChildren.Length(), aChild); 269 } 270 virtual bool InsertChildAt(uint32_t aIndex, LocalAccessible* aChild); 271 272 /** 273 * Inserts a child after given sibling. If the child cannot be inserted, 274 * then the child is unbound from the document, and false is returned. Make 275 * sure to null out any references on the child object as it may be destroyed. 276 */ 277 inline bool InsertAfter(LocalAccessible* aNewChild, 278 LocalAccessible* aRefChild); 279 280 virtual bool RemoveChild(LocalAccessible* aChild); 281 282 /** 283 * Reallocates the child within its parent. 284 */ 285 virtual void RelocateChild(uint32_t aNewIndex, LocalAccessible* aChild); 286 287 // Accessible hierarchy method overrides 288 289 virtual Accessible* Parent() const override { return LocalParent(); } 290 291 virtual Accessible* ChildAt(uint32_t aIndex) const override { 292 return LocalChildAt(aIndex); 293 } 294 295 virtual Accessible* NextSibling() const override { 296 return LocalNextSibling(); 297 } 298 299 virtual Accessible* PrevSibling() const override { 300 return LocalPrevSibling(); 301 } 302 303 ////////////////////////////////////////////////////////////////////////////// 304 // LocalAccessible tree traverse methods 305 306 /** 307 * Return parent accessible. 308 */ 309 LocalAccessible* LocalParent() const { return mParent; } 310 311 /** 312 * Return child accessible at the given index. 313 */ 314 virtual LocalAccessible* LocalChildAt(uint32_t aIndex) const; 315 316 /** 317 * Return child accessible count. 318 */ 319 virtual uint32_t ChildCount() const override; 320 321 /** 322 * Return index of the given child accessible. 323 */ 324 int32_t GetIndexOf(const LocalAccessible* aChild) const { 325 return (aChild->mParent != this) ? -1 : aChild->IndexInParent(); 326 } 327 328 /** 329 * Return index in parent accessible. 330 */ 331 virtual int32_t IndexInParent() const override; 332 333 /** 334 * Return first/last/next/previous sibling of the accessible. 335 */ 336 inline LocalAccessible* LocalNextSibling() const { 337 return GetSiblingAtOffset(1); 338 } 339 inline LocalAccessible* LocalPrevSibling() const { 340 return GetSiblingAtOffset(-1); 341 } 342 inline LocalAccessible* LocalFirstChild() const { return LocalChildAt(0); } 343 inline LocalAccessible* LocalLastChild() const { 344 uint32_t childCount = ChildCount(); 345 return childCount != 0 ? LocalChildAt(childCount - 1) : nullptr; 346 } 347 348 virtual uint32_t EmbeddedChildCount() override; 349 350 /** 351 * Return embedded accessible child at the given index. 352 */ 353 virtual Accessible* EmbeddedChildAt(uint32_t aIndex) override; 354 355 virtual int32_t IndexOfEmbeddedChild(Accessible* aChild) override; 356 357 /** 358 * Return number of content children/content child at index. The content 359 * child is created from markup in contrast to it's never constructed by its 360 * parent accessible (like treeitem accessibles for XUL trees). 361 */ 362 uint32_t ContentChildCount() const { return mChildren.Length(); } 363 LocalAccessible* ContentChildAt(uint32_t aIndex) const { 364 return mChildren.ElementAt(aIndex); 365 } 366 367 /** 368 * Return true if the accessible is attached to tree. 369 */ 370 bool IsBoundToParent() const { return !!mParent; } 371 372 ////////////////////////////////////////////////////////////////////////////// 373 // Miscellaneous methods 374 375 /** 376 * Handle accessible event, i.e. process it, notifies observers and fires 377 * platform specific event. 378 */ 379 virtual nsresult HandleAccEvent(AccEvent* aAccEvent); 380 381 /** 382 * Return true if the accessible is an acceptable child. 383 */ 384 virtual bool IsAcceptableChild(nsIContent* aEl) const { 385 return aEl && 386 !aEl->IsAnyOfHTMLElements(nsGkAtoms::option, nsGkAtoms::optgroup); 387 } 388 389 virtual void AppendTextTo(nsAString& aText, uint32_t aStartOffset = 0, 390 uint32_t aLength = UINT32_MAX) override; 391 392 virtual nsRect BoundsInAppUnits() const override; 393 394 virtual LayoutDeviceIntRect Bounds() const override; 395 396 /** 397 * Return boundaries rect relative the bounding frame. 398 */ 399 virtual nsRect RelativeBounds(nsIFrame** aRelativeFrame) const; 400 401 /** 402 * Return boundaries rect relative to the frame of the parent accessible. 403 * The returned bounds are the same regardless of whether the parent is 404 * scrolled. This means the scroll position must be later subtracted to 405 * calculate absolute coordinates. 406 */ 407 virtual nsRect ParentRelativeBounds(); 408 409 /** 410 * Selects the accessible within its container if applicable. 411 */ 412 virtual void SetSelected(bool aSelect) override; 413 414 /** 415 * Select the accessible within its container. 416 */ 417 virtual void TakeSelection() override; 418 419 /** 420 * Focus the accessible. 421 */ 422 MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual void TakeFocus() const override; 423 424 MOZ_CAN_RUN_SCRIPT 425 virtual void ScrollTo(uint32_t aHow) const override; 426 427 virtual void ScrollToPoint(uint32_t aCoordinateType, int32_t aX, 428 int32_t aY) override; 429 430 virtual bool IsScrollable() const override; 431 432 virtual bool IsPopover() const override; 433 434 virtual bool IsEditable() const override; 435 436 /** 437 * Get a pointer to accessibility interface for this node, which is specific 438 * to the OS/accessibility toolkit we're running on. 439 */ 440 virtual void GetNativeInterface(void** aNativeAccessible); 441 442 virtual Maybe<int32_t> GetIntARIAAttr(nsAtom* aAttrName) const override; 443 444 virtual bool GetStringARIAAttr(nsAtom* aAttrName, 445 nsAString& aAttrValue) const override; 446 447 virtual bool ARIAAttrValueIs(nsAtom* aAttrName, 448 nsAtom* aAttrValue) const override; 449 450 virtual bool HasARIAAttr(nsAtom* aAttrName) const override; 451 452 ////////////////////////////////////////////////////////////////////////////// 453 // Downcasting and types 454 455 ApplicationAccessible* AsApplication(); 456 457 DocAccessible* AsDoc(); 458 459 const DocAccessible* AsDoc() const { 460 DocAccessible* doc = const_cast<LocalAccessible*>(this)->AsDoc(); 461 return const_cast<const DocAccessible*>(doc); 462 } 463 464 HyperTextAccessible* AsHyperText(); 465 virtual HyperTextAccessibleBase* AsHyperTextBase() override; 466 467 HTMLLIAccessible* AsHTMLListItem(); 468 469 HTMLLinkAccessible* AsHTMLLink(); 470 471 ImageAccessible* AsImage(); 472 473 HTMLImageMapAccessible* AsImageMap(); 474 475 OuterDocAccessible* AsOuterDoc(); 476 477 a11y::RootAccessible* AsRoot(); 478 479 virtual TableAccessible* AsTable() override; 480 virtual TableCellAccessible* AsTableCell() override; 481 482 TextLeafAccessible* AsTextLeaf(); 483 484 XULLabelAccessible* AsXULLabel(); 485 486 XULTreeAccessible* AsXULTree(); 487 488 ////////////////////////////////////////////////////////////////////////////// 489 // ActionAccessible 490 491 virtual bool HasPrimaryAction() const override; 492 493 virtual uint8_t ActionCount() const override; 494 495 virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override; 496 497 virtual bool DoAction(uint8_t aIndex) const override; 498 499 virtual bool HasCustomActions() const override; 500 501 virtual KeyBinding AccessKey() const override; 502 503 /** 504 * Return global keyboard shortcut for default action, such as Ctrl+O for 505 * Open file menuitem. 506 */ 507 virtual KeyBinding KeyboardShortcut() const; 508 509 ////////////////////////////////////////////////////////////////////////////// 510 // HyperLinkAccessible (any embedded object in text can implement HyperLink, 511 // which helps determine where it is located within containing text). 512 513 /** 514 * Return true if the accessible is hyper link accessible. 515 */ 516 virtual bool IsLink() const override; 517 518 ////////////////////////////////////////////////////////////////////////////// 519 // SelectAccessible 520 521 /** 522 * Return an array of selected items. 523 */ 524 virtual void SelectedItems(nsTArray<Accessible*>* aItems) override; 525 526 /** 527 * Return the number of selected items. 528 */ 529 virtual uint32_t SelectedItemCount() override; 530 531 /** 532 * Return selected item at the given index. 533 */ 534 virtual Accessible* GetSelectedItem(uint32_t aIndex) override; 535 536 /** 537 * Determine if item at the given index is selected. 538 */ 539 virtual bool IsItemSelected(uint32_t aIndex) override; 540 541 /** 542 * Add item at the given index the selection. Return true if success. 543 */ 544 virtual bool AddItemToSelection(uint32_t aIndex) override; 545 546 /** 547 * Remove item at the given index from the selection. Return if success. 548 */ 549 virtual bool RemoveItemFromSelection(uint32_t aIndex) override; 550 551 /** 552 * Select all items. Return true if success. 553 */ 554 virtual bool SelectAll() override; 555 556 /** 557 * Unselect all items. Return true if success. 558 */ 559 virtual bool UnselectAll() override; 560 561 ////////////////////////////////////////////////////////////////////////////// 562 // Value (numeric value interface) 563 564 virtual double MaxValue() const override; 565 virtual double MinValue() const override; 566 virtual double CurValue() const override; 567 virtual double Step() const override; 568 virtual bool SetCurValue(double aValue) override; 569 570 ////////////////////////////////////////////////////////////////////////////// 571 // Widgets 572 573 /** 574 * Return true if accessible is a widget, i.e. control or accessible that 575 * manages its items. Note, being a widget the accessible may be a part of 576 * composite widget. 577 */ 578 virtual bool IsWidget() const; 579 580 /** 581 * Return true if the widget is active, i.e. has a focus within it. 582 */ 583 virtual bool IsActiveWidget() const; 584 585 /** 586 * Return true if the widget has items and items are operable by user and 587 * can be activated. 588 */ 589 virtual bool AreItemsOperable() const; 590 591 /** 592 * Return the current item of the widget, i.e. an item that has or will have 593 * keyboard focus when widget gets active. 594 */ 595 virtual LocalAccessible* CurrentItem() const; 596 597 /** 598 * Set the current item of the widget. 599 */ 600 virtual void SetCurrentItem(const LocalAccessible* aItem); 601 602 /** 603 * Return container widget this accessible belongs to. 604 */ 605 virtual LocalAccessible* ContainerWidget() const; 606 607 /** 608 * Accessible's element ID is referenced as a aria-activedescendant in the 609 * document. This method is only used for ID changes and therefore does not 610 * need to work for direct element references via ariaActiveDescendantElement. 611 */ 612 bool IsActiveDescendant(LocalAccessible** aWidget = nullptr) const; 613 614 /** 615 * Return true if the accessible is defunct. 616 */ 617 inline bool IsDefunct() const; 618 619 /** 620 * Return false if the accessible is no longer in the document. 621 */ 622 bool IsInDocument() const { return !(mStateFlags & eIsNotInDocument); } 623 624 /** 625 * Return true if the accessible should be contained by document node map. 626 */ 627 bool IsNodeMapEntry() const { 628 return HasOwnContent() && !(mStateFlags & eNotNodeMapEntry); 629 } 630 631 /** 632 * Return true if the accessible has associated DOM content. 633 */ 634 bool HasOwnContent() const { 635 return mContent && !(mStateFlags & eSharedNode); 636 } 637 638 /** 639 * Return true if native markup has a numeric value. 640 */ 641 inline bool NativeHasNumericValue() const; 642 643 /** 644 * Return true if ARIA specifies support for a numeric value. 645 */ 646 inline bool ARIAHasNumericValue() const; 647 648 /** 649 * Return true if the accessible has a numeric value. 650 */ 651 virtual bool HasNumericValue() const override; 652 653 /** 654 * Return true if the accessible state change is processed by handling proper 655 * DOM UI event, if otherwise then false. For example, CheckboxAccessible 656 * created for HTML:input@type="checkbox" will process 657 * nsIDocumentObserver::ElementStateChanged instead of 'CheckboxStateChange' 658 * event. 659 */ 660 bool NeedsDOMUIEvent() const { return !(mStateFlags & eIgnoreDOMUIEvent); } 661 662 /** 663 * Get/set repositioned bit indicating that the accessible was moved in 664 * the accessible tree, i.e. the accessible tree structure differs from DOM. 665 */ 666 bool IsRelocated() const { return mStateFlags & eRelocated; } 667 void SetRelocated(bool aRelocated) { 668 if (aRelocated) { 669 mStateFlags |= eRelocated; 670 } else { 671 mStateFlags &= ~eRelocated; 672 } 673 } 674 675 /** 676 * Return true if the accessible allows accessible children from subtree of 677 * a DOM element of this accessible. 678 */ 679 bool KidsFromDOM() const { return !(mStateFlags & eNoKidsFromDOM); } 680 681 /** 682 * Return true if this accessible has a parent, relation or ancestor with a 683 * relation whose name depends on this accessible. 684 */ 685 bool HasNameDependent() const { return mContextFlags & eHasNameDependent; } 686 687 /** 688 * Return true if this accessible has a parent, relation or ancestor with a 689 * relation whose description depends on this accessible. 690 */ 691 bool HasDescriptionDependent() const { 692 return mContextFlags & eHasDescriptionDependent; 693 } 694 695 /** 696 * Return true if the element is inside an alert. 697 */ 698 bool IsInsideAlert() const { return mContextFlags & eInsideAlert; } 699 700 /** 701 * Return true if there is a pending reorder event for this accessible. 702 */ 703 bool ReorderEventTarget() const { return mReorderEventTarget; } 704 705 /** 706 * Return true if there is a pending show event for this accessible. 707 */ 708 bool ShowEventTarget() const { return mShowEventTarget; } 709 710 /** 711 * Return true if there is a pending hide event for this accessible. 712 */ 713 bool HideEventTarget() const { return mHideEventTarget; } 714 715 /** 716 * Set if there is a pending reorder event for this accessible. 717 */ 718 void SetReorderEventTarget(bool aTarget) { mReorderEventTarget = aTarget; } 719 720 /** 721 * Set if this accessible is a show event target. 722 */ 723 void SetShowEventTarget(bool aTarget) { mShowEventTarget = aTarget; } 724 725 /** 726 * Set if this accessible is a hide event target. 727 */ 728 void SetHideEventTarget(bool aTarget) { mHideEventTarget = aTarget; } 729 730 void Announce(const nsAString& aAnnouncement, uint16_t aPriority); 731 732 virtual bool IsRemote() const override { return false; } 733 734 already_AddRefed<AccAttributes> BundleFieldsForCache( 735 uint64_t aCacheDomain, CacheUpdateType aUpdateType, 736 uint64_t aInitialDomains = CacheDomain::None); 737 738 /** 739 * Push fields to cache. 740 * aCacheDomain - describes which fields to bundle and ultimately send 741 * aUpdate - describes whether this is an initial or subsequent update 742 * aAppendEventData - don't send the event now; append it to the mutation 743 * events list on the DocAccessibleChild 744 */ 745 void SendCache(uint64_t aCacheDomain, CacheUpdateType aUpdate, 746 bool aAppendEventData = false); 747 748 void MaybeQueueCacheUpdateForStyleChanges(); 749 750 virtual nsAtom* TagName() const override; 751 752 virtual already_AddRefed<nsAtom> DisplayStyle() const override; 753 754 virtual float Opacity() const override; 755 756 virtual WritingMode GetWritingMode() const override; 757 758 virtual void DOMNodeID(nsString& aID) const override; 759 760 virtual void DOMNodeClass(nsString& aClass) const override; 761 762 virtual void LiveRegionAttributes(nsAString* aLive, nsAString* aRelevant, 763 Maybe<bool>* aAtomic, 764 nsAString* aBusy) const override; 765 766 virtual Maybe<bool> ARIASelected() const override; 767 768 protected: 769 virtual ~LocalAccessible(); 770 771 /** 772 * Return the accessible name provided by native markup. It doesn't take 773 * into account ARIA markup used to specify the name. 774 */ 775 virtual mozilla::a11y::ENameValueFlag NativeName(nsString& aName) const; 776 777 /** 778 * Return the accessible description provided by native markup. It doesn't 779 * take into account ARIA markup used to specify the description. 780 */ 781 void NativeDescription(nsString& aDescription) const; 782 783 uint64_t ExplicitState() const; 784 785 /** 786 * Return object attributes provided by native markup. It doesn't take into 787 * account ARIA. 788 */ 789 virtual already_AddRefed<AccAttributes> NativeAttributes(); 790 791 /** 792 * The given attribute has the potential of changing the accessible's state. 793 * This is used to capture the state before the attribute change and compare 794 * it with the state after. 795 */ 796 virtual bool AttributeChangesState(nsAtom* aAttribute); 797 798 /** 799 * Notify accessible that a DOM attribute on its associated content has 800 * changed. This allows the accessible to update its state and emit any 801 * relevant events. 802 */ 803 virtual void DOMAttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute, 804 AttrModType aModType, 805 const nsAttrValue* aOldValue, 806 uint64_t aOldState); 807 808 ////////////////////////////////////////////////////////////////////////////// 809 // Initializing, cache and tree traverse methods 810 811 /** 812 * Destroy the object. 813 */ 814 void LastRelease(); 815 816 /** 817 * Set accessible parent and index in parent. 818 */ 819 void BindToParent(LocalAccessible* aParent, uint32_t aIndexInParent); 820 void UnbindFromParent(); 821 822 /** 823 * Return sibling accessible at the given offset. 824 */ 825 virtual LocalAccessible* GetSiblingAtOffset(int32_t aOffset, 826 nsresult* aError = nullptr) const; 827 828 void ModifySubtreeContextFlags(uint32_t aContextFlags, bool aAdd); 829 830 /** 831 * Flags used to describe the state of this accessible. 832 */ 833 enum StateFlags { 834 eIsDefunct = 1 << 0, // accessible is defunct 835 eIsNotInDocument = 1 << 1, // accessible is not in document 836 eSharedNode = 1 << 2, // accessible shares DOM node from another accessible 837 eNotNodeMapEntry = 1 << 3, // accessible shouldn't be in document node map 838 eGroupInfoDirty = 1 << 4, // accessible needs to update group info 839 eKidsMutating = 1 << 5, // subtree is being mutated 840 eIgnoreDOMUIEvent = 1 << 6, // don't process DOM UI events for a11y events 841 eRelocated = 1 << 7, // accessible was moved in tree 842 eNoKidsFromDOM = 1 << 8, // accessible doesn't allow children from DOM 843 eHasTextKids = 1 << 9, // accessible have a text leaf in children 844 eOldFrameHasValidTransformStyle = 845 1 << 10, // frame prior to most recent style change both has transform 846 // styling and supports transforms 847 848 eLastStateFlag = eOldFrameHasValidTransformStyle 849 }; 850 851 /** 852 * Flags used for contextual information about the accessible. 853 */ 854 enum ContextFlags { 855 eHasNameDependent = 1 << 0, // See HasNameDependent(). 856 eInsideAlert = 1 << 1, 857 eHasDescriptionDependent = 1 << 2, // See HasDescriptionDependent(). 858 859 eLastContextFlag = eHasDescriptionDependent 860 }; 861 862 protected: 863 ////////////////////////////////////////////////////////////////////////////// 864 // Miscellaneous helpers 865 866 ////////////////////////////////////////////////////////////////////////////// 867 // Name helpers 868 869 /** 870 * Returns the accessible name specified by ARIA. 871 */ 872 ENameValueFlag ARIAName(nsString& aName) const; 873 874 /** 875 * Returns the accessible description specified by ARIA. 876 */ 877 bool ARIADescription(nsString& aDescription) const; 878 879 /** 880 * Returns the accessible "tooltip", usually derived from title attribute in 881 * HTML or tooltiptext in XUL. 882 */ 883 bool Tooltip(nsString& aTooltip) const; 884 885 /** 886 * Returns the accessible name specified for this control using XUL 887 * <label control="id" ...>. 888 */ 889 static void NameFromAssociatedXULLabel(DocAccessible* aDocument, 890 nsIContent* aElm, nsString& aName); 891 892 /** 893 * Return the name for XUL element. 894 */ 895 static void XULElmName(DocAccessible* aDocument, nsIContent* aElm, 896 nsString& aName); 897 898 // helper method to verify frames 899 static nsresult GetFullKeyName(const nsAString& aModifierName, 900 const nsAString& aKeyName, 901 nsAString& aStringOut); 902 903 ////////////////////////////////////////////////////////////////////////////// 904 // Action helpers 905 906 /** 907 * Prepares click action that will be invoked in timeout. 908 * 909 * @note DoCommand() prepares an action in timeout because when action 910 * command opens a modal dialog/window, it won't return until the 911 * dialog/window is closed. If executing action command directly in 912 * nsIAccessible::DoAction() method, it will block AT tools (e.g. GOK) that 913 * invoke action of mozilla accessibles direclty (see bug 277888 for 914 * details). 915 * 916 * @param aActionIndex [in, optional] index of accessible action 917 */ 918 void DoCommand(uint32_t aActionIndex = 0) const; 919 920 /** 921 * Dispatch click event. 922 */ 923 MOZ_CAN_RUN_SCRIPT 924 virtual void DispatchClickEvent(uint32_t aActionIndex) const; 925 926 ////////////////////////////////////////////////////////////////////////////// 927 // Helpers 928 929 /** 930 * Get the container node for an atomic region, defined by aria-atomic="true" 931 * @return the container node 932 */ 933 nsIContent* GetAtomicRegion() const; 934 935 /** 936 * Return numeric value of the given ARIA attribute, NaN if not applicable. 937 * 938 * @param aARIAProperty [in] the ARIA property we're using 939 * @return a numeric value 940 */ 941 double AttrNumericValue(nsAtom* aARIAAttr) const; 942 943 /** 944 * Return the action rule based on ARIA enum constants EActionRule 945 * (see ARIAMap.h). Used by ActionCount() and ActionNameAt(). 946 */ 947 uint32_t GetActionRule() const; 948 949 virtual AccGroupInfo* GetGroupInfo() const override; 950 951 virtual AccGroupInfo* GetOrCreateGroupInfo() override; 952 953 virtual void ARIAGroupPosition(int32_t* aLevel, int32_t* aSetSize, 954 int32_t* aPosInSet) const override; 955 956 // Data Members 957 // mContent can be null in a DocAccessible if the document has no body or 958 // root element, or if the initial tree hasn't been constructed yet. 959 nsCOMPtr<nsIContent> mContent; 960 RefPtr<DocAccessible> mDoc; 961 962 LocalAccessible* mParent; 963 nsTArray<LocalAccessible*> mChildren; 964 int32_t mIndexInParent; 965 966 // These are used to determine whether to send cache updates. 967 Maybe<nsRect> mBounds; 968 int32_t mFirstLineStart; 969 970 /** 971 * Maintain a reference to the ComputedStyle of our frame so we can 972 * send cache updates when style changes are observed. 973 * 974 * This RefPtr is initialised in BundleFieldsForCache to the ComputedStyle 975 * for our initial frame. 976 * Style changes are observed in one of two ways: 977 * 1. Style changes on the same frame are observed in 978 * nsIFrame::DidSetComputedStyle. 979 * 2. Style changes for reconstructed frames are handled in 980 * DocAccessible::PruneOrInsertSubtree. 981 * In both cases, we call into MaybeQueueCacheUpdateForStyleChanges. There, we 982 * compare a11y-relevant properties in mOldComputedStyle with the current 983 * ComputedStyle fetched from GetFrame()->Style(). Finally, we send cache 984 * updates for attributes affected by the style change and update 985 * mOldComputedStyle to the style of our current frame. 986 */ 987 RefPtr<const ComputedStyle> mOldComputedStyle; 988 989 static const uint8_t kStateFlagsBits = 11; 990 static const uint8_t kContextFlagsBits = 3; 991 992 /** 993 * Keep in sync with StateFlags, ContextFlags, and AccTypes. 994 */ 995 mutable uint32_t mStateFlags : kStateFlagsBits; 996 uint32_t mContextFlags : kContextFlagsBits; 997 uint32_t mReorderEventTarget : 1; 998 uint32_t mShowEventTarget : 1; 999 uint32_t mHideEventTarget : 1; 1000 1001 void StaticAsserts() const; 1002 1003 #ifdef A11Y_LOG 1004 friend void logging::Tree(const char* aTitle, const char* aMsgText, 1005 LocalAccessible* aRoot, 1006 logging::GetTreePrefix aPrefixFunc, 1007 void* aGetTreePrefixData); 1008 friend void logging::TreeSize(const char* aTitle, const char* aMsgText, 1009 LocalAccessible* aRoot); 1010 #endif 1011 friend class DocAccessible; 1012 friend class xpcAccessible; 1013 friend class TreeMutation; 1014 1015 UniquePtr<mozilla::a11y::EmbeddedObjCollector> mEmbeddedObjCollector; 1016 int32_t mIndexOfEmbeddedChild; 1017 1018 friend class EmbeddedObjCollector; 1019 1020 mutable AccGroupInfo* mGroupInfo; 1021 friend class AccGroupInfo; 1022 1023 private: 1024 LocalAccessible() = delete; 1025 LocalAccessible(const LocalAccessible&) = delete; 1026 LocalAccessible& operator=(const LocalAccessible&) = delete; 1027 1028 /** 1029 * Traverses the accessible's parent chain in search of an accessible with 1030 * a frame. Returns the frame when found. Includes special handling for 1031 * OOP iframe docs and tab documents. 1032 */ 1033 nsIFrame* FindNearestAccessibleAncestorFrame(); 1034 1035 LocalAccessible* GetCommandForDetailsRelation() const; 1036 1037 LocalAccessible* GetPopoverTargetDetailsRelation() const; 1038 1039 LocalAccessible* GetAnchorPositionTargetDetailsRelation() const; 1040 }; 1041 1042 //////////////////////////////////////////////////////////////////////////////// 1043 // LocalAccessible downcasting method 1044 1045 inline LocalAccessible* Accessible::AsLocal() { 1046 return IsLocal() ? static_cast<LocalAccessible*>(this) : nullptr; 1047 } 1048 1049 } // namespace a11y 1050 } // namespace mozilla 1051 1052 #endif