Bug 880159, part3 - clean up CharAt stuff, r=tbsaunde

This commit is contained in:
Alexander Surkov 2013-12-19 14:28:51 -05:00
parent 07f15964fb
commit 4b2006e951
4 changed files with 27 additions and 74 deletions

View File

@ -187,18 +187,8 @@ getCharacterAtOffsetCB(AtkText* aText, gint aOffset)
if (!text || !text->IsTextRole())
return 0;
// PRUnichar is unsigned short in Mozilla
// gnuichar is guint32 in glib
PRUnichar uniChar = 0;
nsresult rv = text->GetCharacterAtOffset(aOffset, &uniChar);
if (NS_FAILED(rv))
return 0;
// Convert char to "*" when it's "password text".
if (accWrap->NativeRole() == roles::PASSWORD_TEXT)
uniChar = '*';
return static_cast<gunichar>(uniChar);
// PRUnichar is unsigned short in Mozilla, gnuichar is guint32 in glib.
return static_cast<gunichar>(text->CharAt(aOffset));
}
static gchar*

View File

@ -588,11 +588,6 @@ HyperTextAccessible::TextBeforeOffset(int32_t aOffset,
int32_t* aStartOffset, int32_t* aEndOffset,
nsAString& aText)
{
if (aBoundaryType == BOUNDARY_CHAR) {
GetCharAt(aOffset, eGetBefore, aText, aStartOffset, aEndOffset);
return;
}
*aStartOffset = *aEndOffset = 0;
aText.Truncate();
@ -608,7 +603,8 @@ HyperTextAccessible::TextBeforeOffset(int32_t aOffset,
switch (aBoundaryType) {
case BOUNDARY_CHAR:
MOZ_ASSUME_UNREACHABLE("Already handled!");
if (convertedOffset != 0)
CharAt(convertedOffset - 1, aText, aStartOffset, aEndOffset);
break;
case BOUNDARY_WORD_START: {
@ -675,7 +671,7 @@ HyperTextAccessible::TextAtOffset(int32_t aOffset,
switch (aBoundaryType) {
case BOUNDARY_CHAR:
GetCharAt(aOffset, eGetAt, aText, aStartOffset, aEndOffset);
CharAt(adjustedOffset, aText, aStartOffset, aEndOffset);
break;
case BOUNDARY_WORD_START:
@ -723,11 +719,6 @@ HyperTextAccessible::TextAfterOffset(int32_t aOffset,
int32_t* aStartOffset, int32_t* aEndOffset,
nsAString& aText)
{
if (aBoundaryType == BOUNDARY_CHAR) {
GetCharAt(aOffset, eGetAfter, aText, aStartOffset, aEndOffset);
return;
}
*aStartOffset = *aEndOffset = 0;
aText.Truncate();
@ -743,7 +734,7 @@ HyperTextAccessible::TextAfterOffset(int32_t aOffset,
switch (aBoundaryType) {
case BOUNDARY_CHAR:
MOZ_ASSUME_UNREACHABLE("Already handled!");
CharAt(convertedOffset + 1, aText, aStartOffset, aEndOffset);
break;
case BOUNDARY_WORD_START:
@ -1656,25 +1647,6 @@ HyperTextAccessible::RenderedToContentOffset(nsIFrame* aFrame, uint32_t aRendere
////////////////////////////////////////////////////////////////////////////////
// HyperTextAccessible public
bool
HyperTextAccessible::GetCharAt(int32_t aOffset, EGetTextType aShift,
nsAString& aChar, int32_t* aStartOffset,
int32_t* aEndOffset)
{
aChar.Truncate();
int32_t offset = ConvertMagicOffset(aOffset) + static_cast<int32_t>(aShift);
if (!CharAt(offset, aChar))
return false;
if (aStartOffset)
*aStartOffset = offset;
if (aEndOffset)
*aEndOffset = aChar.IsEmpty() ? offset : offset + 1;
return true;
}
int32_t
HyperTextAccessible::GetChildOffset(uint32_t aChildIndex,
bool aInvalidateAfter)

View File

@ -24,8 +24,6 @@ struct DOMPoint {
int32_t idx;
};
enum EGetTextType { eGetBefore=-1, eGetAt=0, eGetAfter=1 };
// This character marks where in the text returned via nsIAccessibleText(),
// that embedded object characters exist
const PRUnichar kEmbeddedObjectChar = 0xfffc;
@ -170,26 +168,38 @@ public:
/**
* Get a character at the given offset (don't support magic offsets).
*/
bool CharAt(int32_t aOffset, nsAString& aChar)
bool CharAt(int32_t aOffset, nsAString& aChar,
int32_t* aStartOffset = nullptr, int32_t* aEndOffset = nullptr)
{
NS_ASSERTION(!aStartOffset == !aEndOffset,
"Offsets should be both defined or both undefined!");
int32_t childIdx = GetChildIndexAtOffset(aOffset);
if (childIdx == -1)
return false;
Accessible* child = GetChildAt(childIdx);
child->AppendTextTo(aChar, aOffset - GetChildOffset(childIdx), 1);
if (aStartOffset && aEndOffset) {
*aStartOffset = aOffset;
*aEndOffset = aOffset + aChar.Length();
}
return true;
}
PRUnichar CharAt(int32_t aOffset)
{
nsAutoString charAtOffset;
CharAt(aOffset, charAtOffset);
return charAtOffset.CharAt(0);
}
/**
* Return true if char at the given offset equals to given char.
*/
bool IsCharAt(int32_t aOffset, char aChar)
{
nsAutoString charAtOffset;
CharAt(aOffset, charAtOffset);
return charAtOffset.CharAt(0) == aChar;
}
bool IsCharAt(int32_t aOffset, PRUnichar aChar)
{ return CharAt(aOffset) == aChar; }
/**
* Return true if terminal char is at the given offset.
@ -197,20 +207,6 @@ public:
bool IsLineEndCharAt(int32_t aOffset)
{ return IsCharAt(aOffset, '\n'); }
/**
* Get a character before/at/after the given offset.
*
* @param aOffset [in] the given offset
* @param aShift [in] specifies whether to get a char before/at/after
* offset
* @param aChar [out] the character
* @param aStartOffset [out, optional] the start offset of the character
* @param aEndOffset [out, optional] the end offset of the character
* @return false if offset at the given shift is out of range
*/
bool GetCharAt(int32_t aOffset, EGetTextType aShift, nsAString& aChar,
int32_t* aStartOffset = nullptr, int32_t* aEndOffset = nullptr);
/**
* Return text between given offsets.
*/

View File

@ -137,13 +137,8 @@ xpcAccessibleHyperText::GetCharacterAtOffset(int32_t aOffset,
if (text->IsDefunct())
return NS_ERROR_FAILURE;
nsAutoString character;
if (text->GetCharAt(aOffset, eGetAt, character)) {
*aCharacter = character.First();
return NS_OK;
}
return NS_ERROR_INVALID_ARG;
*aCharacter = text->CharAt(aOffset);
return NS_OK;
}
NS_IMETHODIMP