2007-05-16 08:28:38 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=2:tabstop=2:
|
|
|
|
*/
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2007-05-16 08:28:38 +04:00
|
|
|
|
|
|
|
#include "Accessible2.h"
|
|
|
|
#include "AccessibleHyperlink.h"
|
|
|
|
#include "AccessibleHyperlink_i.c"
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
#include "AccessibleWrap.h"
|
2013-05-05 09:38:14 +04:00
|
|
|
#include "IUnknownImpl.h"
|
2013-08-24 06:42:40 +04:00
|
|
|
#include "nsIURI.h"
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2012-11-18 06:01:44 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2007-05-16 08:28:38 +04:00
|
|
|
// IUnknown
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-26 12:18:48 +04:00
|
|
|
ia2AccessibleHyperlink::QueryInterface(REFIID iid, void** ppv)
|
2007-05-16 08:28:38 +04:00
|
|
|
{
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!ppv)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2013-04-03 04:33:43 +04:00
|
|
|
*ppv = nullptr;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
|
|
|
if (IID_IAccessibleHyperlink == iid) {
|
2012-06-26 12:18:48 +04:00
|
|
|
if (!static_cast<AccessibleWrap*>(this)->IsLink())
|
2007-06-08 18:16:27 +04:00
|
|
|
return E_NOINTERFACE;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
*ppv = static_cast<IAccessibleHyperlink*>(this);
|
|
|
|
(reinterpret_cast<IUnknown*>(*ppv))->AddRef();
|
2007-05-16 08:28:38 +04:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-01 23:49:38 +04:00
|
|
|
return ia2AccessibleAction::QueryInterface(iid, ppv);
|
2007-05-16 08:28:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// IAccessibleHyperlink
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-26 12:18:48 +04:00
|
|
|
ia2AccessibleHyperlink::get_anchor(long aIndex, VARIANT* aAnchor)
|
2007-05-16 08:28:38 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aAnchor)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-05-16 08:28:38 +04:00
|
|
|
VariantInit(aAnchor);
|
|
|
|
|
2012-06-26 12:18:48 +04:00
|
|
|
Accessible* thisObj = static_cast<AccessibleWrap*>(this);
|
2015-04-29 20:59:47 +03:00
|
|
|
if (thisObj->IsProxy()) {
|
|
|
|
ProxyAccessible* anchor = thisObj->Proxy()->AnchorAt(aIndex);
|
|
|
|
if (!anchor)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2015-05-25 22:50:55 +03:00
|
|
|
IUnknown* tmp = static_cast<IAccessibleHyperlink*>(WrapperFor(anchor));
|
|
|
|
tmp->AddRef();
|
|
|
|
aAnchor->punkVal = tmp;
|
2015-04-29 20:59:47 +03:00
|
|
|
aAnchor->vt = VT_UNKNOWN;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-09 18:45:47 +04:00
|
|
|
if (thisObj->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2010-09-01 07:26:13 +04:00
|
|
|
if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount()))
|
|
|
|
return E_INVALIDARG;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2012-04-09 18:45:47 +04:00
|
|
|
if (!thisObj->IsLink())
|
|
|
|
return S_FALSE;
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleWrap* anchor =
|
|
|
|
static_cast<AccessibleWrap*>(thisObj->AnchorAt(aIndex));
|
2010-09-01 07:26:13 +04:00
|
|
|
if (!anchor)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2013-04-03 04:33:43 +04:00
|
|
|
void* instancePtr = nullptr;
|
2012-04-09 14:38:39 +04:00
|
|
|
HRESULT result = anchor->QueryInterface(IID_IUnknown, &instancePtr);
|
|
|
|
if (FAILED(result))
|
|
|
|
return result;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2012-04-09 14:38:39 +04:00
|
|
|
IUnknown* unknownPtr = static_cast<IUnknown*>(instancePtr);
|
2007-05-16 08:28:38 +04:00
|
|
|
aAnchor->ppunkVal = &unknownPtr;
|
|
|
|
aAnchor->vt = VT_UNKNOWN;
|
|
|
|
return S_OK;
|
2008-03-30 07:24:02 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-16 08:28:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-26 12:18:48 +04:00
|
|
|
ia2AccessibleHyperlink::get_anchorTarget(long aIndex, VARIANT* aAnchorTarget)
|
2007-05-16 08:28:38 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aAnchorTarget)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-05-16 08:28:38 +04:00
|
|
|
VariantInit(aAnchorTarget);
|
|
|
|
|
2012-06-26 12:18:48 +04:00
|
|
|
Accessible* thisObj = static_cast<AccessibleWrap*>(this);
|
2015-04-29 20:59:47 +03:00
|
|
|
nsAutoCString uriStr;
|
|
|
|
if (thisObj->IsProxy()) {
|
|
|
|
bool ok;
|
|
|
|
thisObj->Proxy()->AnchorURIAt(aIndex, uriStr, &ok);
|
|
|
|
if (!ok)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (thisObj->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
|
|
|
|
if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount()))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (!thisObj->IsLink())
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri = thisObj->AnchorURIAt(aIndex);
|
|
|
|
if (!uri)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
nsresult rv = uri->GetSpec(uriStr);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return GetHRESULT(rv);
|
|
|
|
}
|
2007-05-16 08:28:38 +04:00
|
|
|
|
|
|
|
nsAutoString stringURI;
|
2015-04-29 20:59:47 +03:00
|
|
|
AppendUTF8toUTF16(uriStr, stringURI);
|
2007-05-16 08:28:38 +04:00
|
|
|
|
|
|
|
aAnchorTarget->vt = VT_BSTR;
|
2008-03-16 04:17:38 +03:00
|
|
|
aAnchorTarget->bstrVal = ::SysAllocStringLen(stringURI.get(),
|
|
|
|
stringURI.Length());
|
2008-03-30 07:24:02 +04:00
|
|
|
return aAnchorTarget->bstrVal ? S_OK : E_OUTOFMEMORY;
|
2008-03-16 04:17:38 +03:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-16 08:28:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-26 12:18:48 +04:00
|
|
|
ia2AccessibleHyperlink::get_startIndex(long* aIndex)
|
2007-05-16 08:28:38 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aIndex)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-05-16 08:28:38 +04:00
|
|
|
*aIndex = 0;
|
|
|
|
|
2015-04-29 20:59:47 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
bool valid;
|
|
|
|
*aIndex = proxy->StartOffset(&valid);
|
|
|
|
return valid ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-26 12:18:48 +04:00
|
|
|
Accessible* thisObj = static_cast<AccessibleWrap*>(this);
|
2012-04-09 18:45:47 +04:00
|
|
|
if (thisObj->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
|
|
|
|
if (!thisObj->IsLink())
|
|
|
|
return S_FALSE;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2010-09-01 07:26:13 +04:00
|
|
|
*aIndex = thisObj->StartOffset();
|
2008-03-30 07:24:02 +04:00
|
|
|
return S_OK;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-16 08:28:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-26 12:18:48 +04:00
|
|
|
ia2AccessibleHyperlink::get_endIndex(long* aIndex)
|
2007-05-16 08:28:38 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aIndex)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-05-16 08:28:38 +04:00
|
|
|
*aIndex = 0;
|
|
|
|
|
2015-04-29 20:59:47 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
bool valid;
|
|
|
|
*aIndex = proxy->EndOffset(&valid);
|
|
|
|
return valid ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-26 12:18:48 +04:00
|
|
|
Accessible* thisObj = static_cast<AccessibleWrap*>(this);
|
2012-04-09 18:45:47 +04:00
|
|
|
if (thisObj->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
|
|
|
|
if (!thisObj->IsLink())
|
|
|
|
return S_FALSE;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2010-09-01 07:26:13 +04:00
|
|
|
*aIndex = thisObj->EndOffset();
|
2008-03-30 07:24:02 +04:00
|
|
|
return S_OK;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-16 08:28:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-26 12:18:48 +04:00
|
|
|
ia2AccessibleHyperlink::get_valid(boolean* aValid)
|
2007-05-16 08:28:38 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aValid)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-03-30 07:24:02 +04:00
|
|
|
*aValid = false;
|
|
|
|
|
2015-04-29 20:59:47 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
*aValid = proxy->IsLinkValid();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-26 12:18:48 +04:00
|
|
|
Accessible* thisObj = static_cast<AccessibleWrap*>(this);
|
2012-04-09 18:45:47 +04:00
|
|
|
if (thisObj->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
|
|
|
|
if (!thisObj->IsLink())
|
|
|
|
return S_FALSE;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2011-06-22 09:43:25 +04:00
|
|
|
*aValid = thisObj->IsLinkValid();
|
2008-03-30 07:24:02 +04:00
|
|
|
return S_OK;
|
2007-05-16 08:28:38 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-16 08:28:38 +04:00
|
|
|
}
|
|
|
|
|