DocAccessibleChild.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. #ifndef mozilla_a11y_DocAccessibleChild_h
  6. #define mozilla_a11y_DocAccessibleChild_h
  7. #include "mozilla/a11y/COMPtrTypes.h"
  8. #include "mozilla/a11y/DocAccessibleChildBase.h"
  9. #include "mozilla/dom/TabChild.h"
  10. #include "mozilla/mscom/Ptr.h"
  11. namespace mozilla {
  12. namespace a11y {
  13. /*
  14. * These objects handle content side communication for an accessible document,
  15. * and their lifetime is the same as the document they represent.
  16. */
  17. class DocAccessibleChild : public DocAccessibleChildBase
  18. {
  19. public:
  20. explicit DocAccessibleChild(DocAccessible* aDoc);
  21. ~DocAccessibleChild();
  22. virtual void Shutdown() override;
  23. virtual bool
  24. RecvParentCOMProxy(const IAccessibleHolder& aParentCOMProxy) override;
  25. IAccessible* GetParentIAccessible() const { return mParentProxy.get(); }
  26. bool SendEvent(const uint64_t& aID, const uint32_t& type);
  27. bool SendHideEvent(const uint64_t& aRootID, const bool& aFromUser);
  28. bool SendStateChangeEvent(const uint64_t& aID, const uint64_t& aState,
  29. const bool& aEnabled);
  30. bool SendCaretMoveEvent(const uint64_t& aID, const int32_t& aOffset);
  31. bool SendTextChangeEvent(const uint64_t& aID, const nsString& aStr,
  32. const int32_t& aStart, const uint32_t& aLen,
  33. const bool& aIsInsert, const bool& aFromUser);
  34. bool SendSelectionEvent(const uint64_t& aID, const uint64_t& aWidgetID,
  35. const uint32_t& aType);
  36. bool SendRoleChangedEvent(const uint32_t& aRole);
  37. bool ConstructChildDocInParentProcess(DocAccessibleChild* aNewChildDoc,
  38. uint64_t aUniqueID, uint32_t aMsaaID);
  39. bool SendBindChildDoc(DocAccessibleChild* aChildDoc,
  40. const uint64_t& aNewParentID);
  41. protected:
  42. virtual void MaybeSendShowEvent(ShowEventData& aData, bool aFromUser) override;
  43. private:
  44. void RemoveDeferredConstructor();
  45. bool IsConstructedInParentProcess() const { return mIsRemoteConstructed; }
  46. void SetConstructedInParentProcess() { mIsRemoteConstructed = true; }
  47. /**
  48. * DocAccessibleChild should not fire events until it has asynchronously
  49. * received the COM proxy for its parent. OTOH, content a11y may still be
  50. * attempting to fire events during this window of time. If this object does
  51. * not yet have its parent proxy, instead of immediately sending the events to
  52. * our parent, we enqueue them to mDeferredEvents. As soon as
  53. * RecvParentCOMProxy is called, we play back mDeferredEvents.
  54. */
  55. struct DeferredEvent
  56. {
  57. void Dispatch()
  58. {
  59. Dispatch(mTarget);
  60. }
  61. virtual ~DeferredEvent() {}
  62. protected:
  63. explicit DeferredEvent(DocAccessibleChild* aTarget)
  64. : mTarget(aTarget)
  65. {}
  66. virtual void Dispatch(DocAccessibleChild* aIPCDoc) = 0;
  67. private:
  68. DocAccessibleChild* mTarget;
  69. };
  70. void PushDeferredEvent(UniquePtr<DeferredEvent> aEvent);
  71. struct SerializedShow final : public DeferredEvent
  72. {
  73. SerializedShow(DocAccessibleChild* aTarget,
  74. ShowEventData& aEventData, bool aFromUser)
  75. : DeferredEvent(aTarget)
  76. , mEventData(aEventData.ID(), aEventData.Idx(), nsTArray<AccessibleData>())
  77. , mFromUser(aFromUser)
  78. {
  79. // Since IPDL doesn't generate a move constructor for ShowEventData,
  80. // we move NewTree manually (ugh). We still construct with an empty
  81. // NewTree above so that the compiler catches any changes made to the
  82. // ShowEventData structure in IPDL.
  83. mEventData.NewTree() = Move(aEventData.NewTree());
  84. }
  85. void Dispatch(DocAccessibleChild* aIPCDoc) override
  86. {
  87. Unused << aIPCDoc->SendShowEvent(mEventData, mFromUser);
  88. }
  89. ShowEventData mEventData;
  90. bool mFromUser;
  91. };
  92. struct SerializedHide final : public DeferredEvent
  93. {
  94. SerializedHide(DocAccessibleChild* aTarget, uint64_t aRootID, bool aFromUser)
  95. : DeferredEvent(aTarget)
  96. , mRootID(aRootID)
  97. , mFromUser(aFromUser)
  98. {}
  99. void Dispatch(DocAccessibleChild* aIPCDoc) override
  100. {
  101. Unused << aIPCDoc->SendHideEvent(mRootID, mFromUser);
  102. }
  103. uint64_t mRootID;
  104. bool mFromUser;
  105. };
  106. struct SerializedStateChange final : public DeferredEvent
  107. {
  108. SerializedStateChange(DocAccessibleChild* aTarget, uint64_t aID,
  109. uint64_t aState, bool aEnabled)
  110. : DeferredEvent(aTarget)
  111. , mID(aID)
  112. , mState(aState)
  113. , mEnabled(aEnabled)
  114. {}
  115. void Dispatch(DocAccessibleChild* aIPCDoc) override
  116. {
  117. Unused << aIPCDoc->SendStateChangeEvent(mID, mState, mEnabled);
  118. }
  119. uint64_t mID;
  120. uint64_t mState;
  121. bool mEnabled;
  122. };
  123. struct SerializedCaretMove final : public DeferredEvent
  124. {
  125. SerializedCaretMove(DocAccessibleChild* aTarget, uint64_t aID,
  126. int32_t aOffset)
  127. : DeferredEvent(aTarget)
  128. , mID(aID)
  129. , mOffset(aOffset)
  130. {}
  131. void Dispatch(DocAccessibleChild* aIPCDoc) override
  132. {
  133. Unused << aIPCDoc->SendCaretMoveEvent(mID, mOffset);
  134. }
  135. uint64_t mID;
  136. int32_t mOffset;
  137. };
  138. struct SerializedTextChange final : public DeferredEvent
  139. {
  140. SerializedTextChange(DocAccessibleChild* aTarget, uint64_t aID,
  141. const nsString& aStr, int32_t aStart, uint32_t aLen,
  142. bool aIsInsert, bool aFromUser)
  143. : DeferredEvent(aTarget)
  144. , mID(aID)
  145. , mStr(aStr)
  146. , mStart(aStart)
  147. , mLen(aLen)
  148. , mIsInsert(aIsInsert)
  149. , mFromUser(aFromUser)
  150. {}
  151. void Dispatch(DocAccessibleChild* aIPCDoc) override
  152. {
  153. Unused << aIPCDoc->SendTextChangeEvent(mID, mStr, mStart, mLen, mIsInsert,
  154. mFromUser);
  155. }
  156. uint64_t mID;
  157. nsString mStr;
  158. int32_t mStart;
  159. uint32_t mLen;
  160. bool mIsInsert;
  161. bool mFromUser;
  162. };
  163. struct SerializedSelection final : public DeferredEvent
  164. {
  165. SerializedSelection(DocAccessibleChild* aTarget, uint64_t aID,
  166. uint64_t aWidgetID, uint32_t aType)
  167. : DeferredEvent(aTarget)
  168. , mID(aID)
  169. , mWidgetID(aWidgetID)
  170. , mType(aType)
  171. {}
  172. void Dispatch(DocAccessibleChild* aIPCDoc) override
  173. {
  174. Unused << aIPCDoc->SendSelectionEvent(mID, mWidgetID, mType);
  175. }
  176. uint64_t mID;
  177. uint64_t mWidgetID;
  178. uint32_t mType;
  179. };
  180. struct SerializedRoleChanged final : public DeferredEvent
  181. {
  182. explicit SerializedRoleChanged(DocAccessibleChild* aTarget, uint32_t aRole)
  183. : DeferredEvent(aTarget)
  184. , mRole(aRole)
  185. {}
  186. void Dispatch(DocAccessibleChild* aIPCDoc) override
  187. {
  188. Unused << aIPCDoc->SendRoleChangedEvent(mRole);
  189. }
  190. uint32_t mRole;
  191. };
  192. struct SerializedEvent final : public DeferredEvent
  193. {
  194. SerializedEvent(DocAccessibleChild* aTarget, uint64_t aID, uint32_t aType)
  195. : DeferredEvent(aTarget)
  196. , mID(aID)
  197. , mType(aType)
  198. {}
  199. void Dispatch(DocAccessibleChild* aIPCDoc) override
  200. {
  201. Unused << aIPCDoc->SendEvent(mID, mType);
  202. }
  203. uint64_t mID;
  204. uint32_t mType;
  205. };
  206. struct SerializedChildDocConstructor final : public DeferredEvent
  207. {
  208. SerializedChildDocConstructor(DocAccessibleChild* aIPCDoc,
  209. DocAccessibleChild* aParentIPCDoc,
  210. uint64_t aUniqueID, uint32_t aMsaaID)
  211. : DeferredEvent(aParentIPCDoc)
  212. , mIPCDoc(aIPCDoc)
  213. , mUniqueID(aUniqueID)
  214. , mMsaaID(aMsaaID)
  215. {}
  216. void Dispatch(DocAccessibleChild* aParentIPCDoc) override
  217. {
  218. auto tabChild = static_cast<dom::TabChild*>(aParentIPCDoc->Manager());
  219. MOZ_ASSERT(tabChild);
  220. Unused << tabChild->SendPDocAccessibleConstructor(mIPCDoc, aParentIPCDoc,
  221. mUniqueID, mMsaaID,
  222. IAccessibleHolder());
  223. mIPCDoc->SetConstructedInParentProcess();
  224. }
  225. DocAccessibleChild* mIPCDoc;
  226. uint64_t mUniqueID;
  227. uint32_t mMsaaID;
  228. };
  229. friend struct SerializedChildDocConstructor;
  230. struct SerializedBindChildDoc final : public DeferredEvent
  231. {
  232. SerializedBindChildDoc(DocAccessibleChild* aParentDoc,
  233. DocAccessibleChild* aChildDoc, uint64_t aNewParentID)
  234. : DeferredEvent(aParentDoc)
  235. , mChildDoc(aChildDoc)
  236. , mNewParentID(aNewParentID)
  237. {}
  238. void Dispatch(DocAccessibleChild* aParentIPCDoc) override
  239. {
  240. Unused << aParentIPCDoc->SendBindChildDoc(mChildDoc, mNewParentID);
  241. }
  242. DocAccessibleChild* mChildDoc;
  243. uint64_t mNewParentID;
  244. };
  245. struct SerializedShutdown final : public DeferredEvent
  246. {
  247. explicit SerializedShutdown(DocAccessibleChild* aTarget)
  248. : DeferredEvent(aTarget)
  249. {
  250. }
  251. void Dispatch(DocAccessibleChild* aIPCDoc) override
  252. {
  253. aIPCDoc->Shutdown();
  254. }
  255. };
  256. bool mIsRemoteConstructed;
  257. mscom::ProxyUniquePtr<IAccessible> mParentProxy;
  258. nsTArray<UniquePtr<DeferredEvent>> mDeferredEvents;
  259. };
  260. } // namespace a11y
  261. } // namespace mozilla
  262. #endif // mozilla_a11y_DocAccessibleChild_h