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-07 20:21:15 +03:00
|
|
|
StaticRefPtr<HyperTextAccessibleWrap> ia2AccessibleText::sLastTextChangeAcc;
|
2015-08-06 22:27:35 +03:00
|
|
|
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
|
|
|
{
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
2015-04-06 13:04:44 +03:00
|
|
|
|
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;
|
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
|
|
|
{
|
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;
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct()) {
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2016-08-19 11:02:28 +03:00
|
|
|
}
|
2016-07-22 23:20:42 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
nsCOMPtr<nsIPersistentProperties> attributes =
|
|
|
|
textAcc->TextAttributes(true, aOffset, &startOffset, &endOffset);
|
|
|
|
|
|
|
|
hr = AccessibleWrap::ConvertToIA2Attributes(attributes, aTextAttributes);
|
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;
|
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
|
|
|
{
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aOffset)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-03-30 07:24:02 +04:00
|
|
|
*aOffset = -1;
|
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct()) {
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2016-08-19 11:02:28 +03:00
|
|
|
}
|
2016-07-22 23:20:42 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
*aOffset = textAcc->CaretOffset();
|
|
|
|
|
2013-11-18 17:19:33 +04:00
|
|
|
return *aOffset != -1 ? S_OK : S_FALSE;
|
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
|
|
|
{
|
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;
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct())
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2016-07-22 23:20:42 +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
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
2013-11-18 17:19:33 +04:00
|
|
|
ia2AccessibleText::get_nSelections(long* aNSelections)
|
2007-05-01 21:08:26 +04:00
|
|
|
{
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aNSelections)
|
|
|
|
return E_INVALIDARG;
|
2008-03-30 07:24:02 +04:00
|
|
|
*aNSelections = 0;
|
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct()) {
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2016-08-19 11:02:28 +03:00
|
|
|
}
|
2016-07-22 23:20:42 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
*aNSelections = textAcc->SelectionCount();
|
|
|
|
|
2008-03-30 07:24:02 +04:00
|
|
|
return S_OK;
|
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
|
|
|
{
|
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;
|
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct()) {
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
2016-08-19 11:02:28 +03:00
|
|
|
}
|
2016-07-22 23:20:42 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
*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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
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;
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct()) {
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
}
|
2015-04-06 13:04:44 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
if (!textAcc->SelectionBoundsAt(aSelectionIndex, &startOffset, &endOffset)) {
|
|
|
|
return E_INVALIDARG;
|
2015-04-06 13:04:44 +03:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
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;
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
|
|
|
HyperTextAccessible* textAcc = static_cast<HyperTextAccessibleWrap*>(this);
|
|
|
|
if (textAcc->IsDefunct()) {
|
|
|
|
return CO_E_OBJNOTCONNECTED;
|
|
|
|
}
|
2016-07-22 23:20:42 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
if (!textAcc->IsValidRange(aStartOffset, aEndOffset)) {
|
|
|
|
return E_INVALIDARG;
|
2016-08-19 11:02:28 +03:00
|
|
|
}
|
2016-07-22 23:20:42 +03:00
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
textAcc->TextSubstring(aStartOffset, aEndOffset, text);
|
|
|
|
|
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;
|
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
|
|
|
{
|
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;
|
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
|
|
|
{
|
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;
|
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
|
|
|
{
|
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;
|
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
|
|
|
{
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
2015-04-06 13:04:44 +03:00
|
|
|
|
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;
|
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
|
|
|
{
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
2015-04-06 13:04:44 +03:00
|
|
|
|
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;
|
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
|
|
|
{
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
2015-04-06 13:04:44 +03:00
|
|
|
|
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;
|
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
|
|
|
{
|
2013-06-27 23:02:00 +04:00
|
|
|
if (!aNCharacters)
|
|
|
|
return E_INVALIDARG;
|
2008-03-30 07:24:02 +04:00
|
|
|
*aNCharacters = 0;
|
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
2015-04-06 13:04:44 +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;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
2015-04-06 13:04:44 +03:00
|
|
|
|
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;
|
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
|
|
|
{
|
2015-04-06 13:04:44 +03:00
|
|
|
uint32_t geckoCoordType = (aCoordType == IA2_COORDTYPE_SCREEN_RELATIVE) ?
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE :
|
|
|
|
nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE;
|
|
|
|
|
2016-07-22 23:20:42 +03:00
|
|
|
MOZ_ASSERT(!HyperTextProxyFor(this));
|
2015-04-06 13:04:44 +03:00
|
|
|
|
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;
|
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
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return GetModifiedText(true, aNewText);
|
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
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return GetModifiedText(false, aOldText);
|
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;
|
|
|
|
|
2015-08-07 20:21:15 +03:00
|
|
|
if (!sLastTextChangeAcc)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (aGetInsertedText != sLastTextChangeWasInsert)
|
|
|
|
return S_OK;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2015-08-07 20:21:15 +03:00
|
|
|
if (sLastTextChangeAcc != this)
|
|
|
|
return S_OK;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2015-08-07 20:21:15 +03:00
|
|
|
aText->start = sLastTextChangeStart;
|
|
|
|
aText->end = sLastTextChangeEnd;
|
2007-05-01 21:08:26 +04:00
|
|
|
|
2015-08-07 20:21:15 +03:00
|
|
|
if (sLastTextChangeString->IsEmpty())
|
2008-03-30 07:24:02 +04:00
|
|
|
return S_FALSE;
|
|
|
|
|
2015-08-07 20:21:15 +03:00
|
|
|
aText->text = ::SysAllocStringLen(sLastTextChangeString->get(), sLastTextChangeString->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);
|
|
|
|
}
|
2015-08-06 23:57:31 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
ia2AccessibleText::UpdateTextChangeData(HyperTextAccessibleWrap* aAcc,
|
|
|
|
bool aInsert, const nsString& aStr,
|
|
|
|
int32_t aStart, uint32_t aLen)
|
|
|
|
{
|
|
|
|
if (!sLastTextChangeString)
|
|
|
|
sLastTextChangeString = new nsString();
|
|
|
|
|
|
|
|
sLastTextChangeAcc = aAcc;
|
|
|
|
sLastTextChangeStart = aStart;
|
|
|
|
sLastTextChangeEnd = aStart + aLen;
|
|
|
|
sLastTextChangeWasInsert = aInsert;
|
|
|
|
*sLastTextChangeString = aStr;
|
|
|
|
}
|