layout/base/nsGenConList.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /* base class for nsCounterList and nsQuoteList */
michael@0 7
michael@0 8 #ifndef nsGenConList_h___
michael@0 9 #define nsGenConList_h___
michael@0 10
michael@0 11 #include "nsIFrame.h"
michael@0 12 #include "nsStyleStruct.h"
michael@0 13 #include "prclist.h"
michael@0 14 #include "nsIDOMCharacterData.h"
michael@0 15 #include "nsCSSPseudoElements.h"
michael@0 16
michael@0 17 class nsGenConList;
michael@0 18
michael@0 19 struct nsGenConNode : public PRCList {
michael@0 20 // The wrapper frame for all of the pseudo-element's content. This
michael@0 21 // frame generally has useful style data and has the
michael@0 22 // NS_FRAME_GENERATED_CONTENT bit set (so we use it to track removal),
michael@0 23 // but does not necessarily for |nsCounterChangeNode|s.
michael@0 24 nsIFrame* mPseudoFrame;
michael@0 25
michael@0 26 // Index within the list of things specified by the 'content' property,
michael@0 27 // which is needed to do 'content: open-quote open-quote' correctly,
michael@0 28 // and needed for similar cases for counters.
michael@0 29 const int32_t mContentIndex;
michael@0 30
michael@0 31 // null for 'content:no-open-quote', 'content:no-close-quote' and for
michael@0 32 // counter nodes for increments and resets (rather than uses)
michael@0 33 nsCOMPtr<nsIDOMCharacterData> mText;
michael@0 34
michael@0 35 nsGenConNode(int32_t aContentIndex)
michael@0 36 : mPseudoFrame(nullptr)
michael@0 37 , mContentIndex(aContentIndex)
michael@0 38 {
michael@0 39 }
michael@0 40
michael@0 41 /**
michael@0 42 * Finish initializing the generated content node once we know the
michael@0 43 * relevant text frame. This must be called just after
michael@0 44 * the textframe has been initialized. This need not be called at all
michael@0 45 * for nodes that don't generate text. This will generally set the
michael@0 46 * mPseudoFrame, insert the node into aList, and set aTextFrame up
michael@0 47 * with the correct text.
michael@0 48 * @param aList the list the node belongs to
michael@0 49 * @param aPseudoFrame the :before or :after frame
michael@0 50 * @param aTextFrame the textframe where the node contents will render
michael@0 51 * @return true iff this marked the list dirty
michael@0 52 */
michael@0 53 virtual bool InitTextFrame(nsGenConList* aList, nsIFrame* aPseudoFrame,
michael@0 54 nsIFrame* aTextFrame)
michael@0 55 {
michael@0 56 mPseudoFrame = aPseudoFrame;
michael@0 57 CheckFrameAssertions();
michael@0 58 return false;
michael@0 59 }
michael@0 60
michael@0 61 virtual ~nsGenConNode() {} // XXX Avoid, perhaps?
michael@0 62
michael@0 63 protected:
michael@0 64 void CheckFrameAssertions() {
michael@0 65 NS_ASSERTION(mContentIndex <
michael@0 66 int32_t(mPseudoFrame->StyleContent()->ContentCount()),
michael@0 67 "index out of range");
michael@0 68 // We allow negative values of mContentIndex for 'counter-reset' and
michael@0 69 // 'counter-increment'.
michael@0 70
michael@0 71 NS_ASSERTION(mContentIndex < 0 ||
michael@0 72 mPseudoFrame->StyleContext()->GetPseudo() ==
michael@0 73 nsCSSPseudoElements::before ||
michael@0 74 mPseudoFrame->StyleContext()->GetPseudo() ==
michael@0 75 nsCSSPseudoElements::after,
michael@0 76 "not :before/:after generated content and not counter change");
michael@0 77 NS_ASSERTION(mContentIndex < 0 ||
michael@0 78 mPseudoFrame->GetStateBits() & NS_FRAME_GENERATED_CONTENT,
michael@0 79 "not generated content and not counter change");
michael@0 80 }
michael@0 81 };
michael@0 82
michael@0 83 class nsGenConList {
michael@0 84 protected:
michael@0 85 nsGenConNode* mFirstNode;
michael@0 86 uint32_t mSize;
michael@0 87 public:
michael@0 88 nsGenConList() : mFirstNode(nullptr), mSize(0) {}
michael@0 89 ~nsGenConList() { Clear(); }
michael@0 90 void Clear();
michael@0 91 static nsGenConNode* Next(nsGenConNode* aNode) {
michael@0 92 return static_cast<nsGenConNode*>(PR_NEXT_LINK(aNode));
michael@0 93 }
michael@0 94 static nsGenConNode* Prev(nsGenConNode* aNode) {
michael@0 95 return static_cast<nsGenConNode*>(PR_PREV_LINK(aNode));
michael@0 96 }
michael@0 97 void Insert(nsGenConNode* aNode);
michael@0 98 // returns whether any nodes have been destroyed
michael@0 99 bool DestroyNodesFor(nsIFrame* aFrame); //destroy all nodes with aFrame as parent
michael@0 100
michael@0 101 // Return true if |aNode1| is after |aNode2|.
michael@0 102 static bool NodeAfter(const nsGenConNode* aNode1,
michael@0 103 const nsGenConNode* aNode2);
michael@0 104
michael@0 105 void Remove(nsGenConNode* aNode) { PR_REMOVE_LINK(aNode); mSize--; }
michael@0 106 bool IsLast(nsGenConNode* aNode) { return (Next(aNode) == mFirstNode); }
michael@0 107 };
michael@0 108
michael@0 109 #endif /* nsGenConList_h___ */

mercurial