Bug 630001, part 1 - fix AppendTextTo to not use nsIFrame::GetRenderedText, r=davidb, a=betaN

This commit is contained in:
Alexander Surkov 2011-02-01 11:00:24 +08:00
parent 2677f39ab9
commit b3a3aefaa7
8 changed files with 31 additions and 35 deletions

View File

@ -495,13 +495,11 @@ NotificationController::CoalesceTextChangeEventsFor(AccHideEvent* aTailEvent,
return;
if (aThisEvent->mNextSibling == aTailEvent->mAccessible) {
aTailEvent->mAccessible->AppendTextTo(textEvent->mModifiedText,
0, PR_UINT32_MAX);
aTailEvent->mAccessible->AppendTextTo(textEvent->mModifiedText);
} else if (aThisEvent->mPrevSibling == aTailEvent->mAccessible) {
PRUint32 oldLen = textEvent->GetLength();
aTailEvent->mAccessible->AppendTextTo(textEvent->mModifiedText,
0, PR_UINT32_MAX);
aTailEvent->mAccessible->AppendTextTo(textEvent->mModifiedText);
textEvent->mStart -= textEvent->GetLength() - oldLen;
}
@ -520,15 +518,14 @@ NotificationController::CoalesceTextChangeEventsFor(AccShowEvent* aTailEvent,
aThisEvent->mAccessible->GetIndexInParent() + 1) {
// If tail target was inserted after this target, i.e. tail target is next
// sibling of this target.
aTailEvent->mAccessible->AppendTextTo(textEvent->mModifiedText,
0, PR_UINT32_MAX);
aTailEvent->mAccessible->AppendTextTo(textEvent->mModifiedText);
} else if (aTailEvent->mAccessible->GetIndexInParent() ==
aThisEvent->mAccessible->GetIndexInParent() -1) {
// If tail target was inserted before this target, i.e. tail target is
// previous sibling of this target.
nsAutoString startText;
aTailEvent->mAccessible->AppendTextTo(startText, 0, PR_UINT32_MAX);
aTailEvent->mAccessible->AppendTextTo(startText);
textEvent->mModifiedText = startText + textEvent->mModifiedText;
textEvent->mStart -= startText.Length();
}
@ -564,7 +561,7 @@ NotificationController::CreateTextChangeEventFor(AccMutationEvent* aEvent)
PRInt32 offset = textAccessible->GetChildOffset(aEvent->mAccessible);
nsAutoString text;
aEvent->mAccessible->AppendTextTo(text, 0, PR_UINT32_MAX);
aEvent->mAccessible->AppendTextTo(text);
if (text.IsEmpty())
return;

View File

@ -661,7 +661,7 @@ nsAccUtils::TextLength(nsAccessible *aAccessible)
// XXX In the future, list bullets may have frame and anon content, so
// we should be able to remove this at that point
nsAutoString text;
aAccessible->AppendTextTo(text, 0, PR_UINT32_MAX); // Get all the text
aAccessible->AppendTextTo(text); // Get all the text
return text.Length();
}

View File

@ -2641,16 +2641,18 @@ nsAccessible::GetSelected(PRBool *aSelected)
}
nsresult
nsAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLength)
void
nsAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
PRUint32 aLength)
{
// Return text representation of non-text accessible within hypertext
// accessible. Text accessible overrides this method to return enclosed text.
if (aStartOffset != 0)
return NS_OK;
if (aStartOffset != 0 || aLength == 0)
return;
nsIFrame *frame = GetFrame();
NS_ENSURE_STATE(frame);
if (!frame)
return;
if (frame->GetType() == nsAccessibilityAtoms::brFrame) {
aText += kForcedNewLineChar;
@ -2661,8 +2663,6 @@ nsAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLe
} else {
aText += kEmbeddedObjectChar;
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -341,12 +341,14 @@ public:
* Returns text of accessible if accessible has text role otherwise empty
* string.
*
* @param aText returned text of the accessible
* @param aStartOffset start offset inside of the accesible
* @param aLength required lenght of text
* @param aText [in] returned text of the accessible
* @param aStartOffset [in, optional] start offset inside of the accessible,
* if missed entire text is appended
* @param aLength [in, optional] required length of text, if missed
* then text form start offset till the end is appended
*/
virtual nsresult AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
PRUint32 aLength);
virtual void AppendTextTo(nsAString& aText, PRUint32 aStartOffset = 0,
PRUint32 aLength = PR_UINT32_MAX);
/**
* Assert if child not in parent's cache if the cache was initialized at this

View File

@ -57,13 +57,11 @@ nsTextAccessible::NativeRole()
return nsIAccessibleRole::ROLE_TEXT_LEAF;
}
nsresult
nsTextAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset, PRUint32 aLength)
void
nsTextAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
PRUint32 aLength)
{
nsIFrame *frame = GetFrame();
if (!frame) return NS_ERROR_FAILURE;//NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
return frame->GetRenderedText(&aText, nsnull, nsnull, aStartOffset, aLength);
aText.Append(Substring(mText, aStartOffset, aLength));
}
void

View File

@ -51,8 +51,8 @@ public:
// nsAccessible
virtual PRUint32 NativeRole();
virtual nsresult AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
PRUint32 aLength);
virtual void AppendTextTo(nsAString& aText, PRUint32 aStartOffset = 0,
PRUint32 aLength = PR_UINT32_MAX);
// nsTextAccessible
void SetText(const nsAString& aText) { mText = aText; }

View File

@ -67,8 +67,8 @@ NS_IMETHODIMP
nsHTMLTextAccessible::GetName(nsAString& aName)
{
// Text node, ARIA can't be used.
aName.Truncate();
return AppendTextTo(aName, 0, PR_UINT32_MAX);
aName = mText;
return NS_OK;
}
PRUint32
@ -390,7 +390,7 @@ nsHTMLListBulletAccessible::GetStateInternal(PRUint32 *aState, PRUint32 *aExtraS
return NS_OK;
}
nsresult
void
nsHTMLListBulletAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
PRUint32 aLength)
{
@ -405,7 +405,6 @@ nsHTMLListBulletAccessible::AppendTextTo(nsAString& aText, PRUint32 aStartOffset
aText += Substring(bulletText, aStartOffset, aLength);
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -142,8 +142,8 @@ public:
// nsAccessible
virtual PRUint32 NativeRole();
virtual nsresult GetStateInternal(PRUint32 *aState, PRUint32 *aExtraState);
virtual nsresult AppendTextTo(nsAString& aText, PRUint32 aStartOffset,
PRUint32 aLength);
virtual void AppendTextTo(nsAString& aText, PRUint32 aStartOffset = 0,
PRUint32 aLength = PR_UINT32_MAX);
protected:
// XXX: Ideally we'd get the bullet text directly from the bullet frame via