1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/nsGenConList.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* base class for nsCounterList and nsQuoteList */ 1.10 + 1.11 +#ifndef nsGenConList_h___ 1.12 +#define nsGenConList_h___ 1.13 + 1.14 +#include "nsIFrame.h" 1.15 +#include "nsStyleStruct.h" 1.16 +#include "prclist.h" 1.17 +#include "nsIDOMCharacterData.h" 1.18 +#include "nsCSSPseudoElements.h" 1.19 + 1.20 +class nsGenConList; 1.21 + 1.22 +struct nsGenConNode : public PRCList { 1.23 + // The wrapper frame for all of the pseudo-element's content. This 1.24 + // frame generally has useful style data and has the 1.25 + // NS_FRAME_GENERATED_CONTENT bit set (so we use it to track removal), 1.26 + // but does not necessarily for |nsCounterChangeNode|s. 1.27 + nsIFrame* mPseudoFrame; 1.28 + 1.29 + // Index within the list of things specified by the 'content' property, 1.30 + // which is needed to do 'content: open-quote open-quote' correctly, 1.31 + // and needed for similar cases for counters. 1.32 + const int32_t mContentIndex; 1.33 + 1.34 + // null for 'content:no-open-quote', 'content:no-close-quote' and for 1.35 + // counter nodes for increments and resets (rather than uses) 1.36 + nsCOMPtr<nsIDOMCharacterData> mText; 1.37 + 1.38 + nsGenConNode(int32_t aContentIndex) 1.39 + : mPseudoFrame(nullptr) 1.40 + , mContentIndex(aContentIndex) 1.41 + { 1.42 + } 1.43 + 1.44 + /** 1.45 + * Finish initializing the generated content node once we know the 1.46 + * relevant text frame. This must be called just after 1.47 + * the textframe has been initialized. This need not be called at all 1.48 + * for nodes that don't generate text. This will generally set the 1.49 + * mPseudoFrame, insert the node into aList, and set aTextFrame up 1.50 + * with the correct text. 1.51 + * @param aList the list the node belongs to 1.52 + * @param aPseudoFrame the :before or :after frame 1.53 + * @param aTextFrame the textframe where the node contents will render 1.54 + * @return true iff this marked the list dirty 1.55 + */ 1.56 + virtual bool InitTextFrame(nsGenConList* aList, nsIFrame* aPseudoFrame, 1.57 + nsIFrame* aTextFrame) 1.58 + { 1.59 + mPseudoFrame = aPseudoFrame; 1.60 + CheckFrameAssertions(); 1.61 + return false; 1.62 + } 1.63 + 1.64 + virtual ~nsGenConNode() {} // XXX Avoid, perhaps? 1.65 + 1.66 +protected: 1.67 + void CheckFrameAssertions() { 1.68 + NS_ASSERTION(mContentIndex < 1.69 + int32_t(mPseudoFrame->StyleContent()->ContentCount()), 1.70 + "index out of range"); 1.71 + // We allow negative values of mContentIndex for 'counter-reset' and 1.72 + // 'counter-increment'. 1.73 + 1.74 + NS_ASSERTION(mContentIndex < 0 || 1.75 + mPseudoFrame->StyleContext()->GetPseudo() == 1.76 + nsCSSPseudoElements::before || 1.77 + mPseudoFrame->StyleContext()->GetPseudo() == 1.78 + nsCSSPseudoElements::after, 1.79 + "not :before/:after generated content and not counter change"); 1.80 + NS_ASSERTION(mContentIndex < 0 || 1.81 + mPseudoFrame->GetStateBits() & NS_FRAME_GENERATED_CONTENT, 1.82 + "not generated content and not counter change"); 1.83 + } 1.84 +}; 1.85 + 1.86 +class nsGenConList { 1.87 +protected: 1.88 + nsGenConNode* mFirstNode; 1.89 + uint32_t mSize; 1.90 +public: 1.91 + nsGenConList() : mFirstNode(nullptr), mSize(0) {} 1.92 + ~nsGenConList() { Clear(); } 1.93 + void Clear(); 1.94 + static nsGenConNode* Next(nsGenConNode* aNode) { 1.95 + return static_cast<nsGenConNode*>(PR_NEXT_LINK(aNode)); 1.96 + } 1.97 + static nsGenConNode* Prev(nsGenConNode* aNode) { 1.98 + return static_cast<nsGenConNode*>(PR_PREV_LINK(aNode)); 1.99 + } 1.100 + void Insert(nsGenConNode* aNode); 1.101 + // returns whether any nodes have been destroyed 1.102 + bool DestroyNodesFor(nsIFrame* aFrame); //destroy all nodes with aFrame as parent 1.103 + 1.104 + // Return true if |aNode1| is after |aNode2|. 1.105 + static bool NodeAfter(const nsGenConNode* aNode1, 1.106 + const nsGenConNode* aNode2); 1.107 + 1.108 + void Remove(nsGenConNode* aNode) { PR_REMOVE_LINK(aNode); mSize--; } 1.109 + bool IsLast(nsGenConNode* aNode) { return (Next(aNode) == mFirstNode); } 1.110 +}; 1.111 + 1.112 +#endif /* nsGenConList_h___ */