diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /accessible/windows/ia2/ia2AccessibleHypertext.cpp | |
parent | Initial commit. (diff) | |
download | firefox-e51783d008170d9ab27d25da98ca3a38b0a41b67.tar.xz firefox-e51783d008170d9ab27d25da98ca3a38b0a41b67.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'accessible/windows/ia2/ia2AccessibleHypertext.cpp')
-rw-r--r-- | accessible/windows/ia2/ia2AccessibleHypertext.cpp | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/accessible/windows/ia2/ia2AccessibleHypertext.cpp b/accessible/windows/ia2/ia2AccessibleHypertext.cpp new file mode 100644 index 0000000000..cc8c0cd321 --- /dev/null +++ b/accessible/windows/ia2/ia2AccessibleHypertext.cpp @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:expandtab:shiftwidth=2:tabstop=2: + */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "ia2AccessibleHypertext.h" + +#include "AccessibleHypertext_i.c" +#include "AccessibleHypertext2_i.c" + +#include "mozilla/a11y/HyperTextAccessibleBase.h" + +#include "IUnknownImpl.h" + +using namespace mozilla::a11y; + +HyperTextAccessibleBase* ia2AccessibleHypertext::TextAcc() { + Accessible* acc = Acc(); + return acc ? acc->AsHyperTextBase() : nullptr; +} + +// IUnknown +STDMETHODIMP +ia2AccessibleHypertext::QueryInterface(REFIID aIID, void** aInstancePtr) { + if (!aInstancePtr) return E_FAIL; + + *aInstancePtr = nullptr; + + Accessible* acc = Acc(); + if (acc && acc->IsTextRole()) { + if (aIID == IID_IAccessibleText) { + *aInstancePtr = + static_cast<IAccessibleText*>(static_cast<ia2AccessibleText*>(this)); + } else if (aIID == IID_IAccessibleHypertext) { + *aInstancePtr = static_cast<IAccessibleHypertext*>(this); + } else if (aIID == IID_IAccessibleHypertext2) { + *aInstancePtr = static_cast<IAccessibleHypertext2*>(this); + } else if (aIID == IID_IAccessibleEditableText) { + *aInstancePtr = static_cast<IAccessibleEditableText*>(this); + } else if (aIID == IID_IAccessibleTextSelectionContainer) { + *aInstancePtr = static_cast<IAccessibleTextSelectionContainer*>(this); + } + + if (*aInstancePtr) { + AddRef(); + return S_OK; + } + } + + return MsaaAccessible::QueryInterface(aIID, aInstancePtr); +} + +// IAccessibleHypertext + +STDMETHODIMP +ia2AccessibleHypertext::get_nHyperlinks(long* aHyperlinkCount) { + if (!aHyperlinkCount) return E_INVALIDARG; + + *aHyperlinkCount = 0; + + HyperTextAccessibleBase* hyperText = TextAcc(); + if (!hyperText) return CO_E_OBJNOTCONNECTED; + + *aHyperlinkCount = hyperText->LinkCount(); + return S_OK; +} + +STDMETHODIMP +ia2AccessibleHypertext::get_hyperlink(long aLinkIndex, + IAccessibleHyperlink** aHyperlink) { + if (!aHyperlink) return E_INVALIDARG; + + *aHyperlink = nullptr; + + HyperTextAccessibleBase* hyperText = TextAcc(); + if (!hyperText) { + return CO_E_OBJNOTCONNECTED; + } + + Accessible* hyperLink = hyperText->LinkAt(aLinkIndex); + + if (!hyperLink) return E_FAIL; + + RefPtr<IAccessibleHyperlink> result = MsaaAccessible::GetFrom(hyperLink); + result.forget(aHyperlink); + return S_OK; +} + +STDMETHODIMP +ia2AccessibleHypertext::get_hyperlinkIndex(long aCharIndex, + long* aHyperlinkIndex) { + if (!aHyperlinkIndex) return E_INVALIDARG; + + *aHyperlinkIndex = 0; + + HyperTextAccessibleBase* hyperAcc = TextAcc(); + if (!hyperAcc) return CO_E_OBJNOTCONNECTED; + + *aHyperlinkIndex = hyperAcc->LinkIndexAtOffset(aCharIndex); + return S_OK; +} + +STDMETHODIMP +ia2AccessibleHypertext::get_hyperlinks(IAccessibleHyperlink*** aHyperlinks, + long* aNHyperlinks) { + if (!aHyperlinks || !aNHyperlinks) { + return E_INVALIDARG; + } + + *aHyperlinks = nullptr; + *aNHyperlinks = 0; + + HyperTextAccessibleBase* hyperText = TextAcc(); + if (!hyperText) { + return CO_E_OBJNOTCONNECTED; + } + + uint32_t count = hyperText->LinkCount(); + *aNHyperlinks = count; + + if (count == 0) { + *aHyperlinks = nullptr; + return S_FALSE; + } + + *aHyperlinks = static_cast<IAccessibleHyperlink**>( + ::CoTaskMemAlloc(sizeof(IAccessibleHyperlink*) * count)); + if (!*aHyperlinks) { + return E_OUTOFMEMORY; + } + + for (uint32_t i = 0; i < count; ++i) { + Accessible* hyperLink = hyperText->LinkAt(i); + MOZ_ASSERT(hyperLink); + RefPtr<IAccessibleHyperlink> iaHyper = MsaaAccessible::GetFrom(hyperLink); + iaHyper.forget(&(*aHyperlinks)[i]); + } + + return S_OK; +} |