1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=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/. */ 6 7 #if defined(MOZILLA_INTERNAL_API) 8 # error This code is NOT for internal Gecko use! 9 #endif // defined(MOZILLA_INTERNAL_API) 10 11 #ifndef mozilla_a11y_AccessibleHandlerControl_h 12 # define mozilla_a11y_AccessibleHandlerControl_h 13 14 # include <unordered_map> 15 # include "Factory.h" 16 # include "HandlerData.h" 17 # include "IUnknownImpl.h" 18 # include "mozilla/mscom/Registration.h" 19 # include "mozilla/NotNull.h" 20 21 namespace mozilla { 22 namespace a11y { 23 24 namespace detail { 25 26 class TextChange final { 27 public: 28 TextChange(); 29 TextChange(long aIA2UniqueId, bool aIsInsert, NotNull<IA2TextSegment*> aText); 30 TextChange(TextChange&& aOther); 31 TextChange(const TextChange& aOther); 32 33 TextChange& operator=(TextChange&& aOther); 34 TextChange& operator=(const TextChange& aOther); 35 36 ~TextChange(); 37 38 HRESULT GetOld(long aIA2UniqueId, NotNull<IA2TextSegment*> aOutOldSegment); 39 HRESULT GetNew(long aIA2UniqueId, NotNull<IA2TextSegment*> aOutNewSegment); 40 41 private: 42 static BSTR BSTRCopy(const BSTR& aIn); 43 static HRESULT SegCopy(IA2TextSegment& aDest, const IA2TextSegment& aSrc); 44 45 long mIA2UniqueId; 46 bool mIsInsert; 47 IA2TextSegment mText; 48 }; 49 50 } // namespace detail 51 52 class AccessibleHandler; 53 54 class AccessibleHandlerControl final : public IHandlerControl { 55 public: 56 static HRESULT Create(AccessibleHandlerControl** aOutObject); 57 58 DECL_IUNKNOWN 59 60 // IHandlerControl 61 STDMETHODIMP Invalidate() override; 62 STDMETHODIMP OnTextChange(long aHwnd, long aIA2UniqueId, 63 VARIANT_BOOL aIsInsert, 64 IA2TextSegment* aText) override; 65 GetCacheGen()66 uint32_t GetCacheGen() const { return mCacheGen; } 67 68 HRESULT GetNewText(long aIA2UniqueId, NotNull<IA2TextSegment*> aOutNewText); 69 HRESULT GetOldText(long aIA2UniqueId, NotNull<IA2TextSegment*> aOutOldText); 70 71 HRESULT GetHandlerTypeInfo(ITypeInfo** aOutTypeInfo); 72 73 HRESULT Register(NotNull<IGeckoBackChannel*> aGecko); 74 75 void CacheAccessible(long aUniqueId, AccessibleHandler* aAccessible); 76 HRESULT GetCachedAccessible(long aUniqueId, AccessibleHandler** aAccessible); 77 78 private: 79 AccessibleHandlerControl(); 80 ~AccessibleHandlerControl() = default; 81 82 bool mIsRegistered; 83 uint32_t mCacheGen; 84 detail::TextChange mTextChange; 85 UniquePtr<mscom::RegisteredProxy> mIA2Proxy; 86 UniquePtr<mscom::RegisteredProxy> mHandlerProxy; 87 // We can't use Gecko APIs in this dll, hence the use of std::unordered_map. 88 typedef std::unordered_map<long, RefPtr<AccessibleHandler>> AccessibleCache; 89 AccessibleCache mAccessibleCache; 90 }; 91 92 extern mscom::SingletonFactory<AccessibleHandlerControl> gControlFactory; 93 94 } // namespace a11y 95 } // namespace mozilla 96 97 #endif // mozilla_a11y_AccessibleHandlerControl_h 98