Bug 629394, part1 - turn children flags into generic flags, r=fer, sr=neil, a=davidb

This commit is contained in:
Alexander Surkov 2011-01-28 13:15:04 +08:00
parent 3ca74c7744
commit 2c1f661a95
3 changed files with 39 additions and 19 deletions

View File

@ -185,7 +185,7 @@ nsresult nsAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr)
nsAccessible::nsAccessible(nsIContent *aContent, nsIWeakReference *aShell) :
nsAccessNodeWrap(aContent, aShell),
mParent(nsnull), mIndexInParent(-1), mChildrenFlags(eChildrenUninitialized),
mParent(nsnull), mIndexInParent(-1), mFlags(eChildrenUninitialized),
mIndexOfEmbeddedChild(-1), mRoleMapEntry(nsnull)
{
#ifdef NS_DEBUG_X
@ -2758,7 +2758,7 @@ nsAccessible::InvalidateChildren()
mEmbeddedObjCollector = nsnull;
mChildren.Clear();
mChildrenFlags = eChildrenUninitialized;
SetChildrenFlag(eChildrenUninitialized);
}
PRBool
@ -2771,7 +2771,7 @@ nsAccessible::AppendChild(nsAccessible* aChild)
return PR_FALSE;
if (!nsAccUtils::IsEmbeddedObject(aChild))
mChildrenFlags = eMixedChildren;
SetChildrenFlag(eMixedChildren);
aChild->BindToParent(this, mChildren.Length() - 1);
return PR_TRUE;
@ -2792,7 +2792,7 @@ nsAccessible::InsertChildAt(PRUint32 aIndex, nsAccessible* aChild)
}
if (nsAccUtils::IsText(aChild))
mChildrenFlags = eMixedChildren;
SetChildrenFlag(eMixedChildren);
mEmbeddedObjCollector = nsnull;
@ -2905,7 +2905,7 @@ nsAccessible::GetEmbeddedChildCount()
if (EnsureChildren())
return -1;
if (mChildrenFlags == eMixedChildren) {
if (IsChildrenFlag(eMixedChildren)) {
if (!mEmbeddedObjCollector)
mEmbeddedObjCollector = new EmbeddedObjCollector(this);
return mEmbeddedObjCollector ? mEmbeddedObjCollector->Count() : -1;
@ -2920,7 +2920,7 @@ nsAccessible::GetEmbeddedChildAt(PRUint32 aIndex)
if (EnsureChildren())
return nsnull;
if (mChildrenFlags == eMixedChildren) {
if (IsChildrenFlag(eMixedChildren)) {
if (!mEmbeddedObjCollector)
mEmbeddedObjCollector = new EmbeddedObjCollector(this);
return mEmbeddedObjCollector ?
@ -2936,7 +2936,7 @@ nsAccessible::GetIndexOfEmbeddedChild(nsAccessible* aChild)
if (EnsureChildren())
return -1;
if (mChildrenFlags == eMixedChildren) {
if (IsChildrenFlag(eMixedChildren)) {
if (!mEmbeddedObjCollector)
mEmbeddedObjCollector = new EmbeddedObjCollector(this);
return mEmbeddedObjCollector ?
@ -3185,7 +3185,7 @@ nsAccessible::TestChildCache(nsAccessible* aCachedChild) const
#ifdef DEBUG
PRInt32 childCount = mChildren.Length();
if (childCount == 0) {
NS_ASSERTION(mChildrenFlags == eChildrenUninitialized,
NS_ASSERTION(IsChildrenFlag(eChildrenUninitialized),
"No children but initialized!");
return;
}
@ -3207,15 +3207,15 @@ bool
nsAccessible::EnsureChildren()
{
if (IsDefunct()) {
mChildrenFlags = eChildrenUninitialized;
SetChildrenFlag(eChildrenUninitialized);
return true;
}
if (mChildrenFlags != eChildrenUninitialized)
if (!IsChildrenFlag(eChildrenUninitialized))
return false;
// State is embedded children until text leaf accessible is appended.
mChildrenFlags = eEmbeddedChildren; // Prevent reentry
SetChildrenFlag(eEmbeddedChildren); // Prevent reentry
// Notify the document about caching status.
nsDocAccessible* document = GetDocAccessible();

View File

@ -318,7 +318,8 @@ public:
}
PRUint32 GetCachedChildCount() const { return mChildren.Length(); }
nsAccessible* GetCachedChildAt(PRUint32 aIndex) const { return mChildren.ElementAt(aIndex); }
PRBool AreChildrenCached() const { return mChildrenFlags != eChildrenUninitialized; }
inline bool AreChildrenCached() const
{ return !IsChildrenFlag(eChildrenUninitialized); }
bool IsBoundToParent() const { return !!mParent; }
//////////////////////////////////////////////////////////////////////////////
@ -466,6 +467,27 @@ protected:
virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
nsresult *aError = nsnull);
/**
* Flags used to describe the state and type of children.
*/
enum ChildrenFlags {
eChildrenUninitialized = 0, // children aren't initialized
eMixedChildren = 1 << 0, // text leaf children are presented
eEmbeddedChildren = 1 << 1 // all children are embedded objects
};
/**
* Return true if the children flag is set.
*/
inline bool IsChildrenFlag(ChildrenFlags aFlag) const
{ return (mFlags & kChildrenFlagsMask) == aFlag; }
/**
* Set children flag.
*/
inline void SetChildrenFlag(ChildrenFlags aFlag)
{ mFlags = (mFlags & ~kChildrenFlagsMask) | aFlag; }
//////////////////////////////////////////////////////////////////////////////
// Miscellaneous helpers
@ -580,12 +602,10 @@ protected:
nsTArray<nsRefPtr<nsAccessible> > mChildren;
PRInt32 mIndexInParent;
enum ChildrenFlags {
eChildrenUninitialized = 0x00,
eMixedChildren = 0x01,
eEmbeddedChildren = 0x02
};
ChildrenFlags mChildrenFlags;
static const PRUint32 kChildrenFlagsMask =
eChildrenUninitialized | eMixedChildren | eEmbeddedChildren;
PRUint32 mFlags;
nsAutoPtr<EmbeddedObjCollector> mEmbeddedObjCollector;
PRInt32 mIndexOfEmbeddedChild;

View File

@ -190,7 +190,7 @@ nsOuterDocAccessible::InvalidateChildren()
// then allow nsAccDocManager to handle this case since the document
// accessible is created and appended as a child when it's requested.
mChildrenFlags = eChildrenUninitialized;
SetChildrenFlag(eChildrenUninitialized);
}
PRBool