Back to index

lightning-sunbird  0.9+nobinonly
nsGenConList.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Esben Mose Hansen.
00019  *
00020  * Contributor(s):
00021  *   Esben Mose Hansen <esben@oek.dk> (original author)
00022  *   L. David Baron <dbaron@dbaron.org>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef nsGenConList_h___
00038 #define nsGenConList_h___
00039 
00040 #include "nsIFrame.h"
00041 #include "nsStyleStruct.h"
00042 #include "prclist.h"
00043 #include "nsIDOMCharacterData.h"
00044 #include "nsCSSPseudoElements.h"
00045 
00046 struct nsGenConNode : public PRCList {
00047   // The wrapper frame for all of the pseudo-element's content.  This
00048   // frame generally has useful style data and has the
00049   // NS_FRAME_GENERATED_CONTENT bit set (so we use it to track removal),
00050   // but does not necessarily for |nsCounterChangeNode|s.
00051   nsIFrame* const mPseudoFrame;
00052 
00053   // Index within the list of things specified by the 'content' property,
00054   // which is needed to do 'content: open-quote open-quote' correctly,
00055   // and needed for similar cases for counters.
00056   const PRInt32 mContentIndex;
00057 
00058   // null for 'content:no-open-quote', 'content:no-close-quote' and for
00059   // counter nodes for increments and resets (rather than uses)
00060   nsCOMPtr<nsIDOMCharacterData> mText;
00061 
00062   nsGenConNode(nsIFrame* aPseudoFrame, PRInt32 aContentIndex)
00063     : mPseudoFrame(aPseudoFrame)
00064     , mContentIndex(aContentIndex)
00065   {
00066     NS_ASSERTION(aContentIndex <
00067                    PRInt32(aPseudoFrame->GetStyleContent()->ContentCount()),
00068                  "index out of range");
00069     // We allow negative values of mContentIndex for 'counter-reset' and
00070     // 'counter-increment'.
00071 
00072     NS_ASSERTION(aContentIndex < 0 ||
00073                  aPseudoFrame->GetStyleContext()->GetPseudoType() ==
00074                    nsCSSPseudoElements::before ||
00075                  aPseudoFrame->GetStyleContext()->GetPseudoType() ==
00076                    nsCSSPseudoElements::after,
00077                  "not :before/:after generated content and not counter change");
00078     NS_ASSERTION(aContentIndex < 0 ||
00079                  aPseudoFrame->GetStateBits() & NS_FRAME_GENERATED_CONTENT,
00080                  "not generated content and not counter change");
00081   }
00082 
00083   virtual ~nsGenConNode() {} // XXX Avoid, perhaps?
00084 };
00085 
00086 class nsGenConList {
00087 protected:
00088   nsGenConNode* mFirstNode;
00089   PRUint32 mSize;
00090 public:
00091   nsGenConList() : mFirstNode(nsnull), mSize(0) {}
00092   ~nsGenConList() { Clear(); }
00093   void Clear();
00094   static nsGenConNode* Next(nsGenConNode* aNode) {
00095     return NS_STATIC_CAST(nsGenConNode*, PR_NEXT_LINK(aNode));
00096   }
00097   static nsGenConNode* Prev(nsGenConNode* aNode) {
00098     return NS_STATIC_CAST(nsGenConNode*, PR_PREV_LINK(aNode));
00099   }
00100   void Insert(nsGenConNode* aNode);
00101   // returns whether any nodes have been destroyed
00102   PRBool DestroyNodesFor(nsIFrame* aFrame); //destroy all nodes with aFrame as parent
00103 
00104   // Return true if |aNode1| is after |aNode2|.
00105   static PRBool NodeAfter(const nsGenConNode* aNode1,
00106                           const nsGenConNode* aNode2);
00107 
00108   void Remove(nsGenConNode* aNode) { PR_REMOVE_LINK(aNode); mSize--; }
00109   PRBool IsLast(nsGenConNode* aNode) { return (Next(aNode) == mFirstNode); }
00110 };
00111 
00112 #endif /* nsGenConList_h___ */