1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef AccGroupInfo_h_ 6 #define AccGroupInfo_h_ 7 8 #include "LocalAccessible-inl.h" 9 10 namespace mozilla { 11 namespace a11y { 12 13 /** 14 * Calculate and store group information. 15 */ 16 class AccGroupInfo { 17 public: MOZ_COUNTED_DTOR(AccGroupInfo)18 MOZ_COUNTED_DTOR(AccGroupInfo) 19 20 /** 21 * Return 1-based position in the group. 22 */ 23 uint32_t PosInSet() const { return mPosInSet; } 24 25 /** 26 * Return a number of items in the group. 27 */ SetSize()28 uint32_t SetSize() const { return mSetSize; } 29 30 /** 31 * Return a direct or logical parent of the accessible that this group info is 32 * created for. 33 */ ConceptualParent()34 LocalAccessible* ConceptualParent() const { return mParent; } 35 36 /** 37 * Update group information. 38 */ 39 void Update(); 40 41 /** 42 * Create group info. 43 */ CreateGroupInfo(const LocalAccessible * aAccessible)44 static AccGroupInfo* CreateGroupInfo(const LocalAccessible* aAccessible) { 45 mozilla::a11y::role role = aAccessible->Role(); 46 if (role != mozilla::a11y::roles::ROW && 47 role != mozilla::a11y::roles::OUTLINEITEM && 48 role != mozilla::a11y::roles::OPTION && 49 role != mozilla::a11y::roles::LISTITEM && 50 role != mozilla::a11y::roles::MENUITEM && 51 role != mozilla::a11y::roles::COMBOBOX_OPTION && 52 role != mozilla::a11y::roles::RICH_OPTION && 53 role != mozilla::a11y::roles::CHECK_RICH_OPTION && 54 role != mozilla::a11y::roles::PARENT_MENUITEM && 55 role != mozilla::a11y::roles::CHECK_MENU_ITEM && 56 role != mozilla::a11y::roles::RADIO_MENU_ITEM && 57 role != mozilla::a11y::roles::RADIOBUTTON && 58 role != mozilla::a11y::roles::PAGETAB && 59 role != mozilla::a11y::roles::COMMENT) { 60 return nullptr; 61 } 62 63 AccGroupInfo* info = new AccGroupInfo(aAccessible, BaseRole(role)); 64 return info; 65 } 66 67 /** 68 * Return a first item for the given container. 69 */ 70 static LocalAccessible* FirstItemOf(const LocalAccessible* aContainer); 71 72 /** 73 * Return total number of items in container, and if it is has nested 74 * collections. 75 */ 76 static uint32_t TotalItemCount(LocalAccessible* aContainer, 77 bool* aIsHierarchical); 78 79 /** 80 * Return next item of the same group to the given item. 81 */ 82 static LocalAccessible* NextItemTo(LocalAccessible* aItem); 83 84 protected: 85 AccGroupInfo(const LocalAccessible* aItem, a11y::role aRole); 86 87 private: 88 AccGroupInfo() = delete; 89 AccGroupInfo(const AccGroupInfo&) = delete; 90 AccGroupInfo& operator=(const AccGroupInfo&) = delete; 91 BaseRole(mozilla::a11y::role aRole)92 static mozilla::a11y::role BaseRole(mozilla::a11y::role aRole) { 93 if (aRole == mozilla::a11y::roles::CHECK_MENU_ITEM || 94 aRole == mozilla::a11y::roles::PARENT_MENUITEM || 95 aRole == mozilla::a11y::roles::RADIO_MENU_ITEM) { 96 return mozilla::a11y::roles::MENUITEM; 97 } 98 99 if (aRole == mozilla::a11y::roles::CHECK_RICH_OPTION) { 100 return mozilla::a11y::roles::RICH_OPTION; 101 } 102 103 return aRole; 104 } 105 106 /** 107 * Return true if the given parent and child roles should have their node 108 * relations reported. 109 */ 110 static bool ShouldReportRelations(a11y::role aRole, a11y::role aParentRole); 111 112 uint32_t mPosInSet; 113 uint32_t mSetSize; 114 LocalAccessible* mParent; 115 const LocalAccessible* mItem; 116 a11y::role mRole; 117 }; 118 119 } // namespace a11y 120 } // namespace mozilla 121 122 #endif 123