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