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 "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) {
|
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) {
|
2015-10-09 18:56:14 +03:00
|
|
|
auto accWrap = static_cast<AccessibleWrap*>(this);
|
|
|
|
if (accWrap->IsProxy()
|
|
|
|
? !(accWrap->ProxyInterfaces() & Interfaces::HYPERLINK)
|
|
|
|
: !accWrap->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) {
|
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);
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!thisObj->IsProxy());
|
2015-04-29 20:59:47 +03:00
|
|
|
|
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
|
|
|
|
2016-10-27 03:16:57 +03:00
|
|
|
aAnchor->punkVal = static_cast<IUnknown*>(instancePtr);
|
2007-05-16 08:28:38 +04:00
|
|
|
aAnchor->vt = VT_UNKNOWN;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-26 12:18:48 +04:00
|
|
|
ia2AccessibleHyperlink::get_anchorTarget(long aIndex, VARIANT* aAnchorTarget) {
|
2016-07-22 23:20:42 +03:00
|
|
|
if (!aAnchorTarget) {
|
2013-06-27 23:02:00 +04:00
|
|
|
return E_INVALIDARG;
|
2016-07-22 23:20:42 +03:00
|
|
|
}
|
2013-06-27 23:02:00 +04:00
|
|
|
|
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;
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!thisObj->IsProxy());
|
|
|
|
if (thisObj->IsDefunct()) {
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
}
|
2016-08-16 01:58:45 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
if (aIndex < 0 || aIndex >= static_cast<long>(thisObj->AnchorCount())) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2016-08-18 10:30:21 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
if (!thisObj->IsLink()) {
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
2016-08-19 11:02:28 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
nsCOMPtr<nsIURI> uri = thisObj->AnchorURIAt(aIndex);
|
|
|
|
if (!uri) {
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
2015-04-29 20:59:47 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
nsresult rv = uri->GetSpec(uriStr);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return GetHRESULT(rv);
|
2015-04-29 20:59:47 +03:00
|
|
|
}
|
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;
|
2007-05-16 08:28:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-26 12:18:48 +04:00
|
|
|
ia2AccessibleHyperlink::get_startIndex(long* aIndex) {
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aIndex) return E_INVALIDARG;
|
|
|
|
|
2007-05-16 08:28:38 +04:00
|
|
|
*aIndex = 0;
|
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
2015-04-29 20:59:47 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-26 12:18:48 +04:00
|
|
|
ia2AccessibleHyperlink::get_endIndex(long* aIndex) {
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aIndex) return E_INVALIDARG;
|
|
|
|
|
2007-05-16 08:28:38 +04:00
|
|
|
*aIndex = 0;
|
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
2015-04-29 20:59:47 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-26 12:18:48 +04:00
|
|
|
ia2AccessibleHyperlink::get_valid(boolean* aValid) {
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aValid) return E_INVALIDARG;
|
|
|
|
|
2008-03-30 07:24:02 +04:00
|
|
|
*aValid = false;
|
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
2015-04-29 20:59:47 +03:00
|
|
|
|
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
|
|
|
}
|