ServiceProvider.cpp (3283B)
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 #include "ServiceProvider.h" 8 9 #include "AccessibleApplication_i.c" 10 #include "ApplicationAccessibleWrap.h" 11 #include "DocAccessible.h" 12 #include "nsAccUtils.h" 13 #include "nsCoreUtils.h" 14 #include "Relation.h" 15 #include "RootAccessible.h" 16 #include "uiaRawElmProvider.h" 17 18 #include "mozilla/a11y/Compatibility.h" 19 #include "mozilla/a11y/DocAccessibleChild.h" 20 21 #include "ISimpleDOM.h" 22 23 namespace mozilla { 24 namespace a11y { 25 26 IMPL_IUNKNOWN_QUERY_HEAD(ServiceProvider) 27 IMPL_IUNKNOWN_QUERY_IFACE(IServiceProvider) 28 IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(mMsaa) 29 30 //////////////////////////////////////////////////////////////////////////////// 31 // IServiceProvider 32 33 STDMETHODIMP 34 ServiceProvider::QueryService(REFGUID aGuidService, REFIID aIID, 35 void** aInstancePtr) { 36 if (!aInstancePtr) return E_INVALIDARG; 37 38 *aInstancePtr = nullptr; 39 Accessible* acc = mMsaa->Acc(); 40 if (!acc) { 41 return CO_E_OBJNOTCONNECTED; 42 } 43 44 // Provide a special service ID for getting the accessible for the browser tab 45 // document that contains this accessible object. If this accessible object 46 // is not inside a browser tab then the service fails with E_NOINTERFACE. 47 // A use case for this is for screen readers that need to switch context or 48 // 'virtual buffer' when focus moves from one browser tab area to another. 49 static const GUID SID_IAccessibleContentDocument = { 50 0xa5d8e1f3, 51 0x3571, 52 0x4d8f, 53 {0x95, 0x21, 0x07, 0xed, 0x28, 0xfb, 0x07, 0x2e}}; 54 if (aGuidService == SID_IAccessibleContentDocument) { 55 if (aIID != IID_IAccessible) return E_NOINTERFACE; 56 57 Relation rel = acc->RelationByType(RelationType::CONTAINING_TAB_PANE); 58 RefPtr<IAccessible> next = MsaaAccessible::GetFrom(rel.Next()); 59 if (!next) { 60 return E_NOINTERFACE; 61 } 62 63 next.forget(aInstancePtr); 64 return S_OK; 65 } 66 67 // Can get to IAccessibleApplication from any node via QS 68 // Note: in case of JAWS we want to check if aIID is 69 // IID_IAccessibleApplication. 70 if (aGuidService == IID_IAccessibleApplication || 71 aIID == IID_IAccessibleApplication) { 72 ApplicationAccessibleWrap* applicationAcc = 73 static_cast<ApplicationAccessibleWrap*>(ApplicationAcc()); 74 if (!applicationAcc) return E_NOINTERFACE; 75 76 RefPtr<IAccessible> appIa; 77 applicationAcc->GetNativeInterface(getter_AddRefs(appIa)); 78 return appIa->QueryInterface(aIID, aInstancePtr); 79 } 80 81 static const GUID IID_SimpleDOMDeprecated = { 82 0x0c539790, 83 0x12e4, 84 0x11cf, 85 {0xb6, 0x61, 0x00, 0xaa, 0x00, 0x4c, 0xd6, 0xd8}}; 86 if (aGuidService == IID_ISimpleDOMNode || 87 aGuidService == IID_SimpleDOMDeprecated || 88 aGuidService == IID_IAccessible || aGuidService == IID_IAccessible2 || 89 // UIA IAccessibleEx 90 (aGuidService == IID_IAccessibleEx && Compatibility::IsUiaEnabled())) { 91 return mMsaa->QueryInterface(aIID, aInstancePtr); 92 } 93 94 return E_INVALIDARG; 95 } 96 97 } // namespace a11y 98 } // namespace mozilla