uiaRawElmProvider.h (8333B)
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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_a11y_uiaRawElmProvider_h__ 8 #define mozilla_a11y_uiaRawElmProvider_h__ 9 10 #include <objbase.h> 11 #include <stdint.h> 12 #include <uiautomation.h> 13 14 #include <initializer_list> 15 16 #include "nsString.h" 17 18 template <class T> 19 class nsTArray; 20 template <class T> 21 class RefPtr; 22 23 namespace mozilla { 24 namespace a11y { 25 26 class Accessible; 27 enum class RelationType; 28 29 struct UiaRegistrations { 30 PROPERTYID mAccessibleActions = 0; 31 }; 32 33 /** 34 * IRawElementProviderSimple implementation (maintains IAccessibleEx approach). 35 */ 36 class uiaRawElmProvider : public IAccessibleEx, 37 public IRawElementProviderSimple, 38 public IRawElementProviderFragment, 39 public IInvokeProvider, 40 public IToggleProvider, 41 public IExpandCollapseProvider, 42 public IScrollItemProvider, 43 public IValueProvider, 44 public IRangeValueProvider, 45 public ISelectionProvider, 46 public ISelectionItemProvider, 47 public ITextChildProvider { 48 public: 49 static constexpr enum ProviderOptions kProviderOptions = 50 static_cast<enum ProviderOptions>(ProviderOptions_ServerSideProvider | 51 ProviderOptions_UseComThreading | 52 ProviderOptions_HasNativeIAccessible); 53 54 static void RaiseUiaEventForGeckoEvent(Accessible* aAcc, 55 uint32_t aGeckoEvent); 56 static void RaiseUiaEventForStateChange(Accessible* aAcc, uint64_t aState, 57 bool aEnabled); 58 59 // IUnknown 60 STDMETHODIMP QueryInterface(REFIID aIid, void** aInterface); 61 62 // IAccessibleEx 63 virtual HRESULT STDMETHODCALLTYPE GetObjectForChild( 64 /* [in] */ long aIdChild, 65 /* [retval][out] */ __RPC__deref_out_opt IAccessibleEx** aAccEx); 66 67 virtual HRESULT STDMETHODCALLTYPE GetIAccessiblePair( 68 /* [out] */ __RPC__deref_out_opt IAccessible** aAcc, 69 /* [out] */ __RPC__out long* aIdChild); 70 71 virtual HRESULT STDMETHODCALLTYPE GetRuntimeId( 72 /* [retval][out] */ __RPC__deref_out_opt SAFEARRAY** aRuntimeIds); 73 74 virtual HRESULT STDMETHODCALLTYPE ConvertReturnedElement( 75 /* [in] */ __RPC__in_opt IRawElementProviderSimple* aRawElmProvider, 76 /* [out] */ __RPC__deref_out_opt IAccessibleEx** aAccEx); 77 78 // IRawElementProviderSimple 79 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ProviderOptions( 80 /* [retval][out] */ __RPC__out enum ProviderOptions* aProviderOptions); 81 82 virtual HRESULT STDMETHODCALLTYPE GetPatternProvider( 83 /* [in] */ PATTERNID aPatternId, 84 /* [retval][out] */ __RPC__deref_out_opt IUnknown** aPatternProvider); 85 86 virtual HRESULT STDMETHODCALLTYPE GetPropertyValue( 87 /* [in] */ PROPERTYID aPropertyId, 88 /* [retval][out] */ __RPC__out VARIANT* aPropertyValue); 89 90 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_HostRawElementProvider( 91 /* [retval][out] */ __RPC__deref_out_opt IRawElementProviderSimple** 92 aRawElmProvider); 93 94 // IRawElementProviderFragment 95 virtual HRESULT STDMETHODCALLTYPE Navigate( 96 /* [in] */ enum NavigateDirection aDirection, 97 /* [retval][out] */ __RPC__deref_out_opt IRawElementProviderFragment** 98 aRetVal); 99 100 // GetRuntimeId is shared with IAccessibleEx. 101 102 virtual HRESULT STDMETHODCALLTYPE get_BoundingRectangle( 103 /* [retval][out] */ __RPC__out struct UiaRect* aRetVal); 104 105 virtual HRESULT STDMETHODCALLTYPE GetEmbeddedFragmentRoots( 106 /* [retval][out] */ __RPC__deref_out_opt SAFEARRAY** aRetVal); 107 108 virtual HRESULT STDMETHODCALLTYPE SetFocus(void); 109 110 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_FragmentRoot( 111 /* [retval][out] */ __RPC__deref_out_opt IRawElementProviderFragmentRoot** 112 aRetVal); 113 114 // IInvokeProvider 115 virtual HRESULT STDMETHODCALLTYPE Invoke(void); 116 117 // IToggleProvider 118 virtual HRESULT STDMETHODCALLTYPE Toggle(void); 119 120 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ToggleState( 121 /* [retval][out] */ __RPC__out enum ToggleState* aRetVal); 122 123 // IExpandCollapseProvider 124 virtual HRESULT STDMETHODCALLTYPE Expand(void); 125 126 virtual HRESULT STDMETHODCALLTYPE Collapse(void); 127 128 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_ExpandCollapseState( 129 /* [retval][out] */ __RPC__out enum ExpandCollapseState* aRetVal); 130 131 // IScrollItemProvider 132 virtual HRESULT STDMETHODCALLTYPE ScrollIntoView(void); 133 134 // IValueProvider 135 virtual HRESULT STDMETHODCALLTYPE SetValue( 136 /* [in] */ __RPC__in LPCWSTR val); 137 138 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Value( 139 /* [retval][out] */ __RPC__deref_out_opt BSTR* pRetVal); 140 141 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsReadOnly( 142 /* [retval][out] */ __RPC__out BOOL* pRetVal); 143 144 // IRangeValueProvider 145 virtual HRESULT STDMETHODCALLTYPE SetValue( 146 /* [in] */ double aVal); 147 148 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Value( 149 /* [retval][out] */ __RPC__out double* aRetVal); 150 151 // get_IsReadOnly is shared with IValueProvider. 152 153 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Maximum( 154 /* [retval][out] */ __RPC__out double* aRetVal); 155 156 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_Minimum( 157 /* [retval][out] */ __RPC__out double* aRetVal); 158 159 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_LargeChange( 160 /* [retval][out] */ __RPC__out double* aRetVal); 161 162 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_SmallChange( 163 /* [retval][out] */ __RPC__out double* aRetVal); 164 165 // ISelectionProvider 166 virtual HRESULT STDMETHODCALLTYPE GetSelection( 167 /* [retval][out] */ __RPC__deref_out_opt SAFEARRAY** aRetVal); 168 169 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_CanSelectMultiple( 170 /* [retval][out] */ __RPC__out BOOL* aRetVal); 171 172 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsSelectionRequired( 173 /* [retval][out] */ __RPC__out BOOL* aRetVal); 174 175 // ISelectionItemProvider methods 176 virtual HRESULT STDMETHODCALLTYPE Select(void); 177 178 virtual HRESULT STDMETHODCALLTYPE AddToSelection(void); 179 180 virtual HRESULT STDMETHODCALLTYPE RemoveFromSelection(void); 181 182 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_IsSelected( 183 /* [retval][out] */ __RPC__out BOOL* aRetVal); 184 185 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_SelectionContainer( 186 /* [retval][out] */ __RPC__deref_out_opt IRawElementProviderSimple** 187 aRetVal); 188 189 // ITextChildProvider 190 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_TextContainer( 191 /* [retval][out] */ __RPC__deref_out_opt IRawElementProviderSimple** 192 aRetVal); 193 194 virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_TextRange( 195 /* [retval][out] */ __RPC__deref_out_opt ITextRangeProvider** aRetVal); 196 197 private: 198 Accessible* Acc() const; 199 bool IsControl(); 200 long GetControlType() const; 201 bool HasTogglePattern(); 202 bool HasExpandCollapsePattern(); 203 bool HasValuePattern() const; 204 template <class Derived, class Interface> 205 RefPtr<Interface> GetPatternFromDerived(); 206 bool HasSelectionItemPattern(); 207 SAFEARRAY* AccRelationsToUiaArray( 208 std::initializer_list<RelationType> aTypes) const; 209 Accessible* GetLabeledBy() const; 210 long GetLandmarkType() const; 211 void GetLocalizedLandmarkType(nsAString& aLocalized) const; 212 long GetLiveSetting() const; 213 }; 214 215 SAFEARRAY* AccessibleArrayToUiaArray(const nsTArray<Accessible*>& aAccs); 216 217 /** 218 * Get ids for custom UI Automation properties and events which are not defined 219 * by Windows and therefore need to be registered at runtime. This function will 220 * register the properties and events the first time it is called. Thereafter, 221 * cached ids will be returned, since they are valid for the lifetime of the 222 * process. 223 */ 224 const UiaRegistrations& GetUiaRegistrations(); 225 226 } // namespace a11y 227 } // namespace mozilla 228 229 #endif