2007-05-01 21:08:26 +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-01 21:08:26 +04:00
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
#include "ia2AccessibleText.h"
|
2007-05-01 21:08:26 +04:00
|
|
|
|
|
|
|
#include "Accessible2.h"
|
|
|
|
#include "AccessibleText_i.c"
|
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
#include "HyperTextAccessibleWrap.h"
|
2013-11-18 17:19:33 +04:00
|
|
|
#include "HyperTextAccessible-inl.h"
|
2015-04-06 13:04:44 +03:00
|
|
|
#include "ProxyWrappers.h"
|
2015-08-06 22:27:35 +03:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2012-02-29 14:59:38 +04:00
|
|
|
|
2012-11-18 06:01:44 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2015-08-06 22:27:35 +03:00
|
|
|
StaticRefPtr<Accessible> ia2AccessibleText::sLastTextChangeAcc;
|
|
|
|
StaticAutoPtr<nsString> ia2AccessibleText::sLastTextChangeString;
|
|
|
|
uint32_t ia2AccessibleText::sLastTextChangeStart = 0;
|
|
|
|
uint32_t ia2AccessibleText::sLastTextChangeEnd = 0;
|
|
|
|
bool ia2AccessibleText::sLastTextChangeWasInsert = false;
|
|
|
|
|
2007-05-01 21:08:26 +04:00
|
|
|
// IAccessibleText
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::addSelection(long aStartOffset, long aEndOffset)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
return proxy->AddToSelection(aStartOffset, aEndOffset) ?
|
|
|
|
S_OK : E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
2012-04-09 18:45:47 +04:00
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
return textAcc->AddToSelection(aStartOffset, aEndOffset) ?
|
|
|
|
S_OK : E_INVALIDARG;
|
2008-02-12 18:48:51 +03:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::get_attributes(long aOffset, long *aStartOffset,
|
|
|
|
long *aEndOffset, BSTR *aTextAttributes)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2008-04-23 10:01:02 +04:00
|
|
|
if (!aStartOffset || !aEndOffset || !aTextAttributes)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-03-30 07:24:02 +04:00
|
|
|
*aStartOffset = 0;
|
|
|
|
*aEndOffset = 0;
|
2013-04-03 04:33:43 +04:00
|
|
|
*aTextAttributes = nullptr;
|
2008-03-16 04:17:38 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2015-04-06 13:04:44 +03:00
|
|
|
HRESULT hr;
|
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
nsAutoTArray<Attribute, 10> attrs;
|
|
|
|
proxy->TextAttributes(true, aOffset, &attrs, &startOffset, &endOffset);
|
|
|
|
hr = AccessibleWrap::ConvertToIA2Attributes(&attrs, aTextAttributes);
|
|
|
|
} else {
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
textAcc->TextAttributes(true, aOffset, &startOffset, &endOffset);
|
|
|
|
|
|
|
|
hr = AccessibleWrap::ConvertToIA2Attributes(attributes, aTextAttributes);
|
|
|
|
}
|
2013-11-18 17:19:33 +04:00
|
|
|
|
2008-07-17 16:06:24 +04:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
2008-07-17 16:06:24 +04:00
|
|
|
|
|
|
|
return S_OK;
|
2008-03-30 07:24:02 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::get_caretOffset(long *aOffset)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aOffset)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-03-30 07:24:02 +04:00
|
|
|
*aOffset = -1;
|
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
*aOffset = proxy->CaretOffset();
|
|
|
|
} else {
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
|
|
|
|
*aOffset = textAcc->CaretOffset();
|
|
|
|
}
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
return *aOffset != -1 ? S_OK : S_FALSE;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::get_characterExtents(long aOffset,
|
|
|
|
enum IA2CoordinateType aCoordType,
|
2013-11-18 17:19:33 +04:00
|
|
|
long* aX, long* aY,
|
|
|
|
long* aWidth, long* aHeight)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aX || !aY || !aWidth || !aHeight)
|
|
|
|
return E_INVALIDARG;
|
2013-11-18 17:19:33 +04:00
|
|
|
*aX = *aY = *aWidth = *aHeight = 0;
|
2008-03-30 07:24:02 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
|
2007-05-01 21:08:26 +04:00
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
|
2015-04-06 13:04:44 +03:00
|
|
|
nsIntRect rect;
|
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
rect = proxy->CharBounds(aOffset, geckoCoordType);
|
|
|
|
} else {
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
rect = textAcc->CharBounds(aOffset, geckoCoordType);
|
|
|
|
}
|
2008-03-30 07:24:02 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
*aX = rect.x;
|
|
|
|
*aY = rect.y;
|
|
|
|
*aWidth = rect.width;
|
|
|
|
*aHeight = rect.height;
|
2008-03-30 07:24:02 +04:00
|
|
|
return S_OK;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2013-11-18 17:19:33 +04:00
|
|
|
ia2AccessibleText::get_nSelections(long* aNSelections)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aNSelections)
|
|
|
|
return E_INVALIDARG;
|
2008-03-30 07:24:02 +04:00
|
|
|
*aNSelections = 0;
|
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
*aNSelections = proxy->SelectionCount();
|
|
|
|
} else {
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
|
|
|
|
*aNSelections = textAcc->SelectionCount();
|
|
|
|
}
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2008-03-30 07:24:02 +04:00
|
|
|
return S_OK;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::get_offsetAtPoint(long aX, long aY,
|
|
|
|
enum IA2CoordinateType aCoordType,
|
2013-11-18 17:19:33 +04:00
|
|
|
long* aOffset)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aOffset)
|
|
|
|
return E_INVALIDARG;
|
2008-03-30 07:24:02 +04:00
|
|
|
*aOffset = 0;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
|
2007-05-01 21:08:26 +04:00
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
|
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
*aOffset = proxy->OffsetAtPoint(aX, aY, geckoCoordType);
|
|
|
|
} else {
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
|
|
|
|
*aOffset = textAcc->OffsetAtPoint(aX, aY, geckoCoordType);
|
|
|
|
}
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
return *aOffset == -1 ? S_FALSE : S_OK;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2013-11-18 17:19:33 +04:00
|
|
|
ia2AccessibleText::get_selection(long aSelectionIndex, long* aStartOffset,
|
|
|
|
long* aEndOffset)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aStartOffset || !aEndOffset)
|
|
|
|
return E_INVALIDARG;
|
2013-11-18 17:19:33 +04:00
|
|
|
*aStartOffset = *aEndOffset = 0;
|
2008-03-30 07:24:02 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2015-04-06 13:04:44 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
nsString unused;
|
|
|
|
if (!proxy->SelectionBoundsAt(aSelectionIndex, unused, &startOffset,
|
|
|
|
&endOffset))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
} else {
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
|
|
|
|
if (!textAcc->SelectionBoundsAt(aSelectionIndex, &startOffset, &endOffset))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2008-03-30 07:24:02 +04:00
|
|
|
|
2007-05-01 21:08:26 +04:00
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
2008-03-30 07:24:02 +04:00
|
|
|
return S_OK;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2013-11-18 17:19:33 +04:00
|
|
|
ia2AccessibleText::get_text(long aStartOffset, long aEndOffset, BSTR* aText)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aText)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2013-04-03 04:33:43 +04:00
|
|
|
*aText = nullptr;
|
2008-03-16 04:17:38 +03:00
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
nsAutoString text;
|
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
if (!proxy->TextSubstring(aStartOffset, aEndOffset, text)) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
if (!textAcc->IsValidRange(aStartOffset, aEndOffset))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
textAcc->TextSubstring(aStartOffset, aEndOffset, text);
|
|
|
|
}
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2008-03-16 04:17:38 +03:00
|
|
|
if (text.IsEmpty())
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
*aText = ::SysAllocStringLen(text.get(), text.Length());
|
2008-03-30 07:24:02 +04:00
|
|
|
return *aText ? 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-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::get_textBeforeOffset(long aOffset,
|
|
|
|
enum IA2TextBoundaryType aBoundaryType,
|
2013-11-18 17:19:33 +04:00
|
|
|
long* aStartOffset, long* aEndOffset,
|
|
|
|
BSTR* aText)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aStartOffset || !aEndOffset || !aText)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
*aStartOffset = *aEndOffset = 0;
|
2013-04-03 04:33:43 +04:00
|
|
|
*aText = nullptr;
|
2008-03-16 04:17:38 +03:00
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
2011-01-25 06:33:47 +03:00
|
|
|
if (textAcc->IsDefunct())
|
2012-04-09 18:45:47 +04:00
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2013-11-25 23:54:14 +04:00
|
|
|
if (!textAcc->IsValidOffset(aOffset))
|
2013-11-18 17:19:33 +04:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-05-01 21:08:26 +04:00
|
|
|
nsAutoString text;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
|
|
|
if (aBoundaryType == IA2_TEXT_BOUNDARY_ALL) {
|
|
|
|
startOffset = 0;
|
2011-01-25 06:33:47 +03:00
|
|
|
endOffset = textAcc->CharacterCount();
|
2013-11-18 17:19:33 +04:00
|
|
|
textAcc->TextSubstring(startOffset, endOffset, text);
|
2007-05-01 21:08:26 +04:00
|
|
|
} else {
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleTextBoundary boundaryType = GetGeckoTextBoundary(aBoundaryType);
|
2008-01-30 00:39:34 +03:00
|
|
|
if (boundaryType == -1)
|
|
|
|
return S_FALSE;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
textAcc->TextBeforeOffset(aOffset, boundaryType, &startOffset, &endOffset, text);
|
|
|
|
}
|
2007-05-01 21:08:26 +04:00
|
|
|
|
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
|
|
|
|
2008-03-16 04:17:38 +03:00
|
|
|
if (text.IsEmpty())
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
*aText = ::SysAllocStringLen(text.get(), text.Length());
|
2008-03-30 07:24:02 +04:00
|
|
|
return *aText ? 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-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::get_textAfterOffset(long aOffset,
|
|
|
|
enum IA2TextBoundaryType aBoundaryType,
|
2013-11-18 17:19:33 +04:00
|
|
|
long* aStartOffset, long* aEndOffset,
|
|
|
|
BSTR* aText)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aStartOffset || !aEndOffset || !aText)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-03-30 07:24:02 +04:00
|
|
|
*aStartOffset = 0;
|
|
|
|
*aEndOffset = 0;
|
2013-04-03 04:33:43 +04:00
|
|
|
*aText = nullptr;
|
2008-03-16 04:17:38 +03:00
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
2011-01-25 06:33:47 +03:00
|
|
|
if (textAcc->IsDefunct())
|
2012-04-09 18:45:47 +04:00
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2013-11-25 23:54:14 +04:00
|
|
|
if (!textAcc->IsValidOffset(aOffset))
|
2013-11-18 17:19:33 +04:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-05-01 21:08:26 +04:00
|
|
|
nsAutoString text;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
|
|
|
if (aBoundaryType == IA2_TEXT_BOUNDARY_ALL) {
|
|
|
|
startOffset = 0;
|
2011-01-25 06:33:47 +03:00
|
|
|
endOffset = textAcc->CharacterCount();
|
2013-11-18 17:19:33 +04:00
|
|
|
textAcc->TextSubstring(startOffset, endOffset, text);
|
2007-05-01 21:08:26 +04:00
|
|
|
} else {
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleTextBoundary boundaryType = GetGeckoTextBoundary(aBoundaryType);
|
2008-01-30 00:39:34 +03:00
|
|
|
if (boundaryType == -1)
|
|
|
|
return S_FALSE;
|
2013-11-18 17:19:33 +04:00
|
|
|
textAcc->TextAfterOffset(aOffset, boundaryType, &startOffset, &endOffset, text);
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
|
|
|
|
2008-03-16 04:17:38 +03:00
|
|
|
if (text.IsEmpty())
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
*aText = ::SysAllocStringLen(text.get(), text.Length());
|
2008-03-30 07:24:02 +04:00
|
|
|
return *aText ? 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-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::get_textAtOffset(long aOffset,
|
|
|
|
enum IA2TextBoundaryType aBoundaryType,
|
2013-11-18 17:19:33 +04:00
|
|
|
long* aStartOffset, long* aEndOffset,
|
|
|
|
BSTR* aText)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aStartOffset || !aEndOffset || !aText)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
*aStartOffset = *aEndOffset = 0;
|
2013-04-03 04:33:43 +04:00
|
|
|
*aText = nullptr;
|
2008-03-30 07:24:02 +04:00
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
2011-01-25 06:33:47 +03:00
|
|
|
if (textAcc->IsDefunct())
|
2012-04-09 18:45:47 +04:00
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2013-11-25 23:54:14 +04:00
|
|
|
if (!textAcc->IsValidOffset(aOffset))
|
2013-11-18 17:19:33 +04:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-05-01 21:08:26 +04:00
|
|
|
nsAutoString text;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startOffset = 0, endOffset = 0;
|
2007-05-01 21:08:26 +04:00
|
|
|
if (aBoundaryType == IA2_TEXT_BOUNDARY_ALL) {
|
|
|
|
startOffset = 0;
|
2011-01-25 06:33:47 +03:00
|
|
|
endOffset = textAcc->CharacterCount();
|
2013-11-18 17:19:33 +04:00
|
|
|
textAcc->TextSubstring(startOffset, endOffset, text);
|
2007-05-01 21:08:26 +04:00
|
|
|
} else {
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleTextBoundary boundaryType = GetGeckoTextBoundary(aBoundaryType);
|
2008-01-30 00:39:34 +03:00
|
|
|
if (boundaryType == -1)
|
|
|
|
return S_FALSE;
|
2013-11-18 17:19:33 +04:00
|
|
|
textAcc->TextAtOffset(aOffset, boundaryType, &startOffset, &endOffset, text);
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*aStartOffset = startOffset;
|
|
|
|
*aEndOffset = endOffset;
|
|
|
|
|
2008-03-16 04:17:38 +03:00
|
|
|
if (text.IsEmpty())
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
*aText = ::SysAllocStringLen(text.get(), text.Length());
|
2008-03-30 07:24:02 +04:00
|
|
|
return *aText ? 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-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::removeSelection(long aSelectionIndex)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
return proxy->RemoveFromSelection(aSelectionIndex) ? S_OK : E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
2012-04-09 18:45:47 +04:00
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
return textAcc->RemoveFromSelection(aSelectionIndex) ?
|
|
|
|
S_OK : E_INVALIDARG;
|
2008-02-12 18:48:51 +03:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::setCaretOffset(long aOffset)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
return proxy->SetCaretOffset(aOffset) ? S_OK : E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
2012-04-09 18:45:47 +04:00
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
if (!textAcc->IsValidOffset(aOffset))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
textAcc->SetCaretOffset(aOffset);
|
|
|
|
return S_OK;
|
2008-02-12 18:48:51 +03:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::setSelection(long aSelectionIndex, long aStartOffset,
|
|
|
|
long aEndOffset)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
return proxy->SetSelectionBoundsAt(aSelectionIndex, aStartOffset,
|
|
|
|
aEndOffset) ? S_OK : E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
2012-04-09 18:45:47 +04:00
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
return textAcc->SetSelectionBoundsAt(aSelectionIndex, aStartOffset, aEndOffset) ?
|
|
|
|
S_OK : E_INVALIDARG;
|
2008-02-12 18:48:51 +03:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2013-11-18 17:19:33 +04:00
|
|
|
ia2AccessibleText::get_nCharacters(long* aNCharacters)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aNCharacters)
|
|
|
|
return E_INVALIDARG;
|
2008-03-30 07:24:02 +04:00
|
|
|
*aNCharacters = 0;
|
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
*aNCharacters = proxy->CharacterCount();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
2011-01-25 06:33:47 +03:00
|
|
|
if (textAcc->IsDefunct())
|
2012-04-09 18:45:47 +04:00
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2008-03-30 07:24:02 +04:00
|
|
|
|
2011-01-25 06:33:47 +03:00
|
|
|
*aNCharacters = textAcc->CharacterCount();
|
2008-03-30 07:24:02 +04:00
|
|
|
return S_OK;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::scrollSubstringTo(long aStartIndex, long aEndIndex,
|
|
|
|
enum IA2ScrollType aScrollType)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
proxy->ScrollSubstringTo(aStartIndex, aEndIndex, aScrollType);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
2012-04-09 18:45:47 +04:00
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
if (!textAcc->IsValidRange(aStartIndex, aEndIndex))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
textAcc->ScrollSubstringTo(aStartIndex, aEndIndex, aScrollType);
|
|
|
|
return S_OK;
|
2008-02-12 18:48:51 +03:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::scrollSubstringToPoint(long aStartIndex, long aEndIndex,
|
|
|
|
enum IA2CoordinateType aCoordType,
|
|
|
|
long aX, long aY)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2015-04-06 13:04:44 +03:00
|
|
|
uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = HyperTextProxyFor(this)) {
|
|
|
|
proxy->ScrollSubstringToPoint(aStartIndex, aEndIndex, geckoCoordType, aX,
|
|
|
|
aY);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
2012-04-09 18:45:47 +04:00
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
if (!textAcc->IsValidRange(aStartIndex, aEndIndex))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
textAcc->ScrollSubstringToPoint(aStartIndex, aEndIndex,
|
|
|
|
geckoCoordType, aX, aY);
|
|
|
|
return S_OK;
|
2008-02-12 18:48:51 +03:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::get_newText(IA2TextSegment *aNewText)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return GetModifiedText(true, aNewText);
|
2008-03-30 07:24:02 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::get_oldText(IA2TextSegment *aOldText)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_BEGIN
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return GetModifiedText(false, aOldText);
|
2008-03-30 07:24:02 +04:00
|
|
|
|
2012-11-28 14:27:20 +04:00
|
|
|
A11Y_TRYBLOCK_END
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
2012-06-16 09:28:31 +04:00
|
|
|
// ia2AccessibleText
|
2007-05-01 21:08:26 +04:00
|
|
|
|
|
|
|
HRESULT
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::GetModifiedText(bool aGetInsertedText,
|
|
|
|
IA2TextSegment *aText)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aText)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t startOffset = 0, endOffset = 0;
|
2007-05-01 21:08:26 +04:00
|
|
|
nsAutoString text;
|
|
|
|
|
|
|
|
nsresult rv = GetModifiedText(aGetInsertedText, text,
|
|
|
|
&startOffset, &endOffset);
|
|
|
|
if (NS_FAILED(rv))
|
2008-03-30 07:24:02 +04:00
|
|
|
return GetHRESULT(rv);
|
2007-05-01 21:08:26 +04:00
|
|
|
|
|
|
|
aText->start = startOffset;
|
|
|
|
aText->end = endOffset;
|
|
|
|
|
2008-03-30 07:24:02 +04:00
|
|
|
if (text.IsEmpty())
|
|
|
|
return S_FALSE;
|
|
|
|
|
2008-03-16 04:17:38 +03:00
|
|
|
aText->text = ::SysAllocStringLen(text.get(), text.Length());
|
2008-03-30 07:24:02 +04:00
|
|
|
return aText->text ? S_OK : E_OUTOFMEMORY;
|
2007-05-01 21:08:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
AccessibleTextBoundary
|
2012-06-16 09:28:31 +04:00
|
|
|
ia2AccessibleText::GetGeckoTextBoundary(enum IA2TextBoundaryType aBoundaryType)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
|
|
|
switch (aBoundaryType) {
|
|
|
|
case IA2_TEXT_BOUNDARY_CHAR:
|
|
|
|
return nsIAccessibleText::BOUNDARY_CHAR;
|
|
|
|
case IA2_TEXT_BOUNDARY_WORD:
|
|
|
|
return nsIAccessibleText::BOUNDARY_WORD_START;
|
|
|
|
case IA2_TEXT_BOUNDARY_LINE:
|
|
|
|
return nsIAccessibleText::BOUNDARY_LINE_START;
|
2008-01-30 00:39:34 +03:00
|
|
|
//case IA2_TEXT_BOUNDARY_SENTENCE:
|
|
|
|
//case IA2_TEXT_BOUNDARY_PARAGRAPH:
|
|
|
|
// XXX: not implemented
|
2007-05-01 21:08:26 +04:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-06 22:27:35 +03:00
|
|
|
void
|
|
|
|
ia2AccessibleText::InitTextChangeData()
|
|
|
|
{
|
|
|
|
ClearOnShutdown(&sLastTextChangeAcc);
|
|
|
|
ClearOnShutdown(&sLastTextChangeString);
|
|
|
|
}
|