Bug 1769547 - Do not MOZ_CRASH() on missing process r=nika
[gecko.git] / accessible / windows / msaa / MsaaAccessible.h
blob5766d0e091089c56fbbf0eabd393b90baf6b7ecf
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
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 mozilla_a11y_MsaaAccessible_h_
8 #define mozilla_a11y_MsaaAccessible_h_
10 #include "ia2Accessible.h"
11 #include "ia2AccessibleComponent.h"
12 #include "ia2AccessibleHyperlink.h"
13 #include "ia2AccessibleValue.h"
14 #include "IUnknownImpl.h"
15 #include "mozilla/a11y/MsaaIdGenerator.h"
16 #include "mozilla/dom/ipc/IdType.h"
17 #include "nsXULAppAPI.h"
19 namespace mozilla {
20 namespace a11y {
21 class Accessible;
22 class AccessibleWrap;
23 class LocalAccessible;
24 class sdnAccessible;
26 class MsaaAccessible : public ia2Accessible,
27 public ia2AccessibleComponent,
28 public ia2AccessibleHyperlink,
29 public ia2AccessibleValue {
30 public:
31 static MsaaAccessible* Create(Accessible* aAcc);
33 Accessible* Acc() { return mAcc; }
34 AccessibleWrap* LocalAcc();
36 uint32_t GetExistingID() const { return mID; }
37 static const uint32_t kNoID = 0;
38 void SetID(uint32_t aID);
40 static int32_t GetChildIDFor(Accessible* aAccessible);
41 static uint32_t GetContentProcessIdFor(dom::ContentParentId aIPCContentId);
42 static void ReleaseContentProcessIdFor(dom::ContentParentId aIPCContentId);
43 static void AssignChildIDTo(NotNull<sdnAccessible*> aSdnAcc);
44 static void ReleaseChildID(NotNull<sdnAccessible*> aSdnAcc);
45 static HWND GetHWNDFor(Accessible* aAccessible);
46 static void FireWinEvent(Accessible* aTarget, uint32_t aEventType);
48 /**
49 * Find an accessible by the given child ID in cached documents.
51 [[nodiscard]] already_AddRefed<IAccessible> GetIAccessibleFor(
52 const VARIANT& aVarChild, bool* aIsDefunct);
54 /**
55 * Associate a COM object with this MsaaAccessible so it will be disconnected
56 * from remote clients when this MsaaAccessible shuts down.
57 * This should only be called with separate COM objects with a different
58 * IUnknown to this MsaaAccessible; e.g. IAccessibleRelation.
60 void AssociateCOMObjectForDisconnection(IUnknown* aObject) {
61 // We only need to track these for content processes because COM garbage
62 // collection is disabled there.
63 if (XRE_IsContentProcess()) {
64 mAssociatedCOMObjectsForDisconnection.AppendElement(aObject);
68 void MsaaShutdown();
70 static IDispatch* NativeAccessible(Accessible* aAccessible);
72 static MsaaAccessible* GetFrom(Accessible* aAcc);
74 DECL_IUNKNOWN
76 // IAccessible
77 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accParent(
78 /* [retval][out] */ IDispatch __RPC_FAR* __RPC_FAR* ppdispParent)
79 override;
80 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accChildCount(
81 /* [retval][out] */ long __RPC_FAR* pcountChildren) override;
82 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accChild(
83 /* [in] */ VARIANT varChild,
84 /* [retval][out] */ IDispatch __RPC_FAR* __RPC_FAR* ppdispChild) override;
85 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accName(
86 /* [optional][in] */ VARIANT varChild,
87 /* [retval][out] */ BSTR __RPC_FAR* pszName) override;
88 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accValue(
89 /* [optional][in] */ VARIANT varChild,
90 /* [retval][out] */ BSTR __RPC_FAR* pszValue) override;
91 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accDescription(
92 /* [optional][in] */ VARIANT varChild,
93 /* [retval][out] */ BSTR __RPC_FAR* pszDescription) override;
94 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accRole(
95 /* [optional][in] */ VARIANT varChild,
96 /* [retval][out] */ VARIANT __RPC_FAR* pvarRole) override;
97 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accState(
98 /* [optional][in] */ VARIANT varChild,
99 /* [retval][out] */ VARIANT __RPC_FAR* pvarState) override;
100 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accHelp(
101 /* [optional][in] */ VARIANT varChild,
102 /* [retval][out] */ BSTR __RPC_FAR* pszHelp) override;
103 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accHelpTopic(
104 /* [out] */ BSTR __RPC_FAR* pszHelpFile,
105 /* [optional][in] */ VARIANT varChild,
106 /* [retval][out] */ long __RPC_FAR* pidTopic) override;
107 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accKeyboardShortcut(
108 /* [optional][in] */ VARIANT varChild,
109 /* [retval][out] */ BSTR __RPC_FAR* pszKeyboardShortcut) override;
110 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accFocus(
111 /* [retval][out] */ VARIANT __RPC_FAR* pvarChild) override;
112 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accSelection(
113 /* [retval][out] */ VARIANT __RPC_FAR* pvarChildren) override;
114 virtual /* [id][propget] */ HRESULT STDMETHODCALLTYPE get_accDefaultAction(
115 /* [optional][in] */ VARIANT varChild,
116 /* [retval][out] */ BSTR __RPC_FAR* pszDefaultAction) override;
117 virtual /* [id] */ HRESULT STDMETHODCALLTYPE accSelect(
118 /* [in] */ long flagsSelect,
119 /* [optional][in] */ VARIANT varChild) override;
120 virtual /* [id] */ HRESULT STDMETHODCALLTYPE accLocation(
121 /* [out] */ long __RPC_FAR* pxLeft,
122 /* [out] */ long __RPC_FAR* pyTop,
123 /* [out] */ long __RPC_FAR* pcxWidth,
124 /* [out] */ long __RPC_FAR* pcyHeight,
125 /* [optional][in] */ VARIANT varChild) override;
126 virtual /* [id] */ HRESULT STDMETHODCALLTYPE accNavigate(
127 /* [in] */ long navDir,
128 /* [optional][in] */ VARIANT varStart,
129 /* [retval][out] */ VARIANT __RPC_FAR* pvarEndUpAt) override;
130 virtual /* [id] */ HRESULT STDMETHODCALLTYPE accHitTest(
131 /* [in] */ long xLeft,
132 /* [in] */ long yTop,
133 /* [retval][out] */ VARIANT __RPC_FAR* pvarChild) override;
134 virtual /* [id] */ HRESULT STDMETHODCALLTYPE accDoDefaultAction(
135 /* [optional][in] */ VARIANT varChild) override;
136 virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_accName(
137 /* [optional][in] */ VARIANT varChild,
138 /* [in] */ BSTR szName) override;
139 virtual /* [id][propput] */ HRESULT STDMETHODCALLTYPE put_accValue(
140 /* [optional][in] */ VARIANT varChild,
141 /* [in] */ BSTR szValue) override;
143 // IDispatch (support of scripting languages like VB)
144 virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT* pctinfo) override;
145 virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo, LCID lcid,
146 ITypeInfo** ppTInfo) override;
147 virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid,
148 LPOLESTR* rgszNames,
149 UINT cNames, LCID lcid,
150 DISPID* rgDispId) override;
151 virtual HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid,
152 LCID lcid, WORD wFlags,
153 DISPPARAMS* pDispParams,
154 VARIANT* pVarResult,
155 EXCEPINFO* pExcepInfo,
156 UINT* puArgErr) override;
158 protected:
159 explicit MsaaAccessible(Accessible* aAcc);
160 virtual ~MsaaAccessible();
162 Accessible* mAcc;
164 uint32_t mID;
165 static MsaaIdGenerator sIDGen;
167 HRESULT
168 ResolveChild(const VARIANT& aVarChild, IAccessible** aOutInterface);
170 enum navRelations {
171 NAVRELATION_CONTROLLED_BY = 0x1000,
172 NAVRELATION_CONTROLLER_FOR = 0x1001,
173 NAVRELATION_LABEL_FOR = 0x1002,
174 NAVRELATION_LABELLED_BY = 0x1003,
175 NAVRELATION_MEMBER_OF = 0x1004,
176 NAVRELATION_NODE_CHILD_OF = 0x1005,
177 NAVRELATION_FLOWS_TO = 0x1006,
178 NAVRELATION_FLOWS_FROM = 0x1007,
179 NAVRELATION_SUBWINDOW_OF = 0x1008,
180 NAVRELATION_EMBEDS = 0x1009,
181 NAVRELATION_EMBEDDED_BY = 0x100a,
182 NAVRELATION_POPUP_FOR = 0x100b,
183 NAVRELATION_PARENT_WINDOW_OF = 0x100c,
184 NAVRELATION_DEFAULT_BUTTON = 0x100d,
185 NAVRELATION_DESCRIBED_BY = 0x100e,
186 NAVRELATION_DESCRIPTION_FOR = 0x100f,
187 NAVRELATION_NODE_PARENT_OF = 0x1010,
188 NAVRELATION_CONTAINING_DOCUMENT = 0x1011,
189 NAVRELATION_CONTAINING_TAB_PANE = 0x1012,
190 NAVRELATION_CONTAINING_WINDOW = 0x1013,
191 NAVRELATION_CONTAINING_APPLICATION = 0x1014,
192 NAVRELATION_DETAILS = 0x1015,
193 NAVRELATION_DETAILS_FOR = 0x1016,
194 NAVRELATION_ERROR = 0x1017,
195 NAVRELATION_ERROR_FOR = 0x1018,
196 NAVRELATION_LINKS_TO = 0x1019
199 private:
201 * Find a remote accessible by the given child ID.
203 [[nodiscard]] already_AddRefed<IAccessible> GetRemoteIAccessibleFor(
204 const VARIANT& aVarChild);
206 nsTArray<RefPtr<IUnknown>> mAssociatedCOMObjectsForDisconnection;
209 * Creates ITypeInfo for LIBID_Accessibility if it's needed and returns it.
211 static ITypeInfo* GetTI(LCID lcid);
212 static ITypeInfo* gTypeInfo;
215 } // namespace a11y
216 } // namespace mozilla
218 #ifdef XP_WIN
219 // Undo the windows.h damage
220 # undef GetMessage
221 # undef CreateEvent
222 # undef GetClassName
223 # undef GetBinaryType
224 # undef RemoveDirectory
225 #endif
227 #endif