Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes
nsCounterList Class Reference

#include <nsCounterManager.h>

Inheritance diagram for nsCounterList:
Inheritance graph
[legend]
Collaboration diagram for nsCounterList:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsCounterList ()
void Insert (nsCounterNode *aNode)
nsCounterNodeFirst ()
void SetScope (nsCounterNode *aNode)
void RecalcAll ()
PRBool IsDirty ()
void SetDirty ()
void Clear ()
void Insert (nsGenConNode *aNode)
PRBool DestroyNodesFor (nsIFrame *aFrame)
void Remove (nsGenConNode *aNode)
PRBool IsLast (nsGenConNode *aNode)

Static Public Member Functions

static nsCounterNodeNext (nsCounterNode *aNode)
static nsCounterNodePrev (nsCounterNode *aNode)
static PRInt32 ValueBefore (nsCounterNode *aNode)
static nsGenConNodeNext (nsGenConNode *aNode)
static nsGenConNodePrev (nsGenConNode *aNode)
static PRBool NodeAfter (const nsGenConNode *aNode1, const nsGenConNode *aNode2)

Protected Attributes

nsGenConNodemFirstNode
PRUint32 mSize

Private Attributes

PRBool mDirty

Detailed Description

Definition at line 184 of file nsCounterManager.h.


Constructor & Destructor Documentation

Definition at line 186 of file nsCounterManager.h.


Member Function Documentation

void nsGenConList::Clear ( void  ) [inherited]

Definition at line 43 of file nsGenConList.cpp.

{
  //Delete entire list
  if (!mFirstNode)
    return;
  for (nsGenConNode *node = Next(mFirstNode); node != mFirstNode;
       node = Next(mFirstNode))
  {
    Remove(node);
    delete node;
  }
  delete mFirstNode;

  mFirstNode = nsnull;
  mSize = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsGenConList::DestroyNodesFor ( nsIFrame aFrame) [inherited]

Definition at line 61 of file nsGenConList.cpp.

{
  if (!mFirstNode)
    return PR_FALSE; // list empty
  nsGenConNode* node;
  PRBool destroyed = PR_FALSE;
  while (mFirstNode->mPseudoFrame == aFrame) {
    destroyed = PR_TRUE;
    node = Next(mFirstNode);
    if (node == mFirstNode) { // Last link
      mFirstNode = nsnull;
      delete node;
      return PR_TRUE;
    }
    else {
      Remove(mFirstNode);
      delete mFirstNode;
      mFirstNode = node;
    }
  }
  node = Next(mFirstNode);
  while (node != mFirstNode) {
    if (node->mPseudoFrame == aFrame) {
      destroyed = PR_TRUE;
      nsGenConNode *nextNode = Next(node);
      Remove(node);
      delete node;
      node = nextNode;
    } else {
      node = Next(node);
    }
  }
  return destroyed;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 199 of file nsCounterManager.h.

Here is the caller graph for this function:

void nsGenConList::Insert ( nsGenConNode aNode) [inherited]

Definition at line 142 of file nsGenConList.cpp.

{
  if (mFirstNode) {
    // Check for append.
    if (NodeAfter(aNode, Prev(mFirstNode))) {
      PR_INSERT_BEFORE(aNode, mFirstNode);
    }
    else {
      // Binary search.

      // the range of indices at which |aNode| could end up.
      PRUint32 first = 0, last = mSize - 1;

      // A cursor to avoid walking more than the length of the list.
      nsGenConNode *curNode = Prev(mFirstNode);
      PRUint32 curIndex = mSize - 1;

      while (first != last) {
        PRUint32 test = (first + last) / 2;
        if (last == curIndex) {
          for ( ; curIndex != test; --curIndex)
            curNode = Prev(curNode);
        } else {
          for ( ; curIndex != test; ++curIndex)
            curNode = Next(curNode);
        }

        if (NodeAfter(aNode, curNode)) {
          first = test + 1;
          // if we exit the loop, we need curNode to be right
          ++curIndex;
          curNode = Next(curNode);
        } else {
          last = test;
        }
      }
      PR_INSERT_BEFORE(aNode, curNode);
      if (curNode == mFirstNode) {
        mFirstNode = aNode;
      }
    }
  }
  else {
    // initialize list with first node
    PR_INIT_CLIST(aNode);
    mFirstNode = aNode;
  }
  ++mSize;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCounterList::Insert ( nsCounterNode aNode) [inline]

Definition at line 190 of file nsCounterManager.h.

                                      {
        nsGenConList::Insert(aNode);
        // Don't SetScope if we're dirty -- we'll reset all the scopes anyway,
        // and we can't usefully compute scopes right now.
        if (NS_LIKELY(!IsDirty())) {
            SetScope(aNode);
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 221 of file nsCounterManager.h.

{ return mDirty; }

Here is the caller graph for this function:

PRBool nsGenConList::IsLast ( nsGenConNode aNode) [inline, inherited]

Definition at line 109 of file nsGenConList.h.

{ return (Next(aNode) == mFirstNode); }

Here is the call graph for this function:

Here is the caller graph for this function:

static nsGenConNode* nsGenConList::Next ( nsGenConNode aNode) [inline, static, inherited]

Definition at line 94 of file nsGenConList.h.

                                                 {
    return NS_STATIC_CAST(nsGenConNode*, PR_NEXT_LINK(aNode));
  }

Here is the caller graph for this function:

static nsCounterNode* nsCounterList::Next ( nsCounterNode aNode) [inline, static]

Definition at line 203 of file nsCounterManager.h.

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsGenConList::NodeAfter ( const nsGenConNode aNode1,
const nsGenConNode aNode2 
) [static, inherited]

Definition at line 108 of file nsGenConList.cpp.

{
  nsIFrame *frame1 = aNode1->mPseudoFrame;
  nsIFrame *frame2 = aNode2->mPseudoFrame;
  if (frame1 == frame2) {
    NS_ASSERTION(aNode2->mContentIndex != aNode1->mContentIndex, "identical");
    return aNode1->mContentIndex > aNode2->mContentIndex;
  }
  PRInt32 pseudoType1 = PseudoCompareType(frame1);
  PRInt32 pseudoType2 = PseudoCompareType(frame2);
  nsIContent *content1 = frame1->GetContent();
  nsIContent *content2 = frame2->GetContent();
  if (pseudoType1 == 0 || pseudoType2 == 0) {
    if (content1 == content2) {
      NS_ASSERTION(pseudoType1 != pseudoType2, "identical");
      return pseudoType2 == 0;
    }
    // We want to treat an element as coming before its :before (preorder
    // traversal), so treating both as :before now works.
    if (pseudoType1 == 0) pseudoType1 = -1;
    if (pseudoType2 == 0) pseudoType2 = -1;
  } else {
    if (content1 == content2) {
      NS_ASSERTION(pseudoType1 != pseudoType2, "identical");
      return pseudoType1 == 1;
    }
  }
  PRInt32 cmp = nsLayoutUtils::DoCompareTreePosition(content1, content2,
                                                     pseudoType1, -pseudoType2);
  NS_ASSERTION(cmp != 0, "same content, different frames");
  return cmp > 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsGenConNode* nsGenConList::Prev ( nsGenConNode aNode) [inline, static, inherited]

Definition at line 97 of file nsGenConList.h.

                                                 {
    return NS_STATIC_CAST(nsGenConNode*, PR_PREV_LINK(aNode));
  }

Here is the caller graph for this function:

static nsCounterNode* nsCounterList::Prev ( nsCounterNode aNode) [inline, static]

Definition at line 206 of file nsCounterManager.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 164 of file nsCounterManager.cpp.

{
    mDirty = PR_FALSE;

    nsCounterNode *node = First();
    if (!node)
        return;

    do {
        SetScope(node);
        node->Calc(this);

        if (node->mType == nsCounterNode::USE) {
            nsCounterUseNode *useNode = node->UseNode();
            // Null-check mText, since if the frame constructor isn't
            // batching, we could end up here while the node is being
            // constructed.
            if (useNode->mText) {
                nsAutoString text;
                useNode->GetText(text);
                useNode->mText->SetData(text);
            }
        }
    } while ((node = Next(node)) != First());
}

Here is the call graph for this function:

void nsGenConList::Remove ( nsGenConNode aNode) [inline, inherited]

Definition at line 108 of file nsGenConList.h.

{ PR_REMOVE_LINK(aNode); mSize--; }

Here is the caller graph for this function:

Definition at line 222 of file nsCounterManager.h.

{ mDirty = PR_TRUE; }

Here is the caller graph for this function:

Definition at line 95 of file nsCounterManager.cpp.

{
    // This function is responsible for setting |mScopeStart| and
    // |mScopePrev| (whose purpose is described in nsCounterManager.h).
    // We do this by starting from the node immediately preceding
    // |aNode| in content tree order, which is reasonably likely to be
    // the previous element in our scope (or, for a reset, the previous
    // element in the containing scope, which is what we want).  If
    // we're not in the same scope that it is, then it's too deep in the
    // frame tree, so we walk up parent scopes until we find something
    // appropriate.

    if (aNode == First()) {
        aNode->mScopeStart = nsnull;
        aNode->mScopePrev = nsnull;
        return;
    }

    // Get the content node for aNode's rendering object's *parent*,
    // since scope includes siblings, so we want a descendant check on
    // parents.  If aNode is for a pseudo-element, then the parent
    // rendering object is the frame's content; if aNode is for an
    // element, then the parent rendering object is the frame's
    // content's parent.
    nsIContent *nodeContent = aNode->mPseudoFrame->GetContent();
    if (!aNode->mPseudoFrame->GetStyleContext()->GetPseudoType()) {
        nodeContent = nodeContent->GetParent();
    }

    for (nsCounterNode *prev = Prev(aNode), *start;
         prev; prev = start->mScopePrev) {
        // If |prev| starts a scope (because it's a real or implied
        // reset), we want it as the scope start rather than the start
        // of its enclosing scope.  Otherwise, there's no enclosing
        // scope, so the next thing in prev's scope shares its scope
        // start.
        start = (prev->mType == nsCounterNode::RESET || !prev->mScopeStart)
                  ? prev : prev->mScopeStart;

        // |startContent| is analogous to |nodeContent| (see above).
        nsIContent *startContent = start->mPseudoFrame->GetContent();
        if (!start->mPseudoFrame->GetStyleContext()->GetPseudoType()) {
            startContent = startContent->GetParent();
        }
        NS_ASSERTION(nodeContent || !startContent,
                     "null check on startContent should be sufficient to "
                     "null check nodeContent as well, since if nodeContent "
                     "is for the root, startContent (which is before it) "
                     "must be too");

             // A reset's outer scope can't be a scope created by a sibling.
        if (!(aNode->mType == nsCounterNode::RESET &&
              nodeContent == startContent) &&
              // everything is inside the root (except the case above,
              // a second reset on the root)
            (!startContent ||
             nsContentUtils::ContentIsDescendantOf(nodeContent,
                                                   startContent))) {
            aNode->mScopeStart = start;
            aNode->mScopePrev  = prev;
            return;
        }
    }

    aNode->mScopeStart = nsnull;
    aNode->mScopePrev  = nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRInt32 nsCounterList::ValueBefore ( nsCounterNode aNode) [inline, static]

Definition at line 210 of file nsCounterManager.h.

                                                     {
        return aNode->mScopePrev ? aNode->mScopePrev->mValueAfter : 0;
    }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 225 of file nsCounterManager.h.

nsGenConNode* nsGenConList::mFirstNode [protected, inherited]

Definition at line 88 of file nsGenConList.h.

PRUint32 nsGenConList::mSize [protected, inherited]

Definition at line 89 of file nsGenConList.h.


The documentation for this class was generated from the following files: