2005-04-02 03:07:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-30 09:56:38 +04:00
|
|
|
|
|
|
|
/* base class for nsCounterList and nsQuoteList */
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
#ifndef nsGenConList_h___
|
|
|
|
#define nsGenConList_h___
|
|
|
|
|
2016-10-27 13:07:52 +03:00
|
|
|
#include "mozilla/LinkedList.h"
|
2005-04-02 03:07:00 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsStyleStruct.h"
|
|
|
|
#include "nsCSSPseudoElements.h"
|
2014-06-12 02:11:15 +04:00
|
|
|
#include "nsTextNode.h"
|
2005-04-02 03:07:00 +04:00
|
|
|
|
2008-08-18 05:16:42 +04:00
|
|
|
class nsGenConList;
|
|
|
|
|
2016-10-27 13:07:52 +03:00
|
|
|
struct nsGenConNode : public mozilla::LinkedListElement<nsGenConNode> {
|
2005-04-02 03:07:00 +04:00
|
|
|
// The wrapper frame for all of the pseudo-element's content. This
|
|
|
|
// frame generally has useful style data and has the
|
|
|
|
// NS_FRAME_GENERATED_CONTENT bit set (so we use it to track removal),
|
|
|
|
// but does not necessarily for |nsCounterChangeNode|s.
|
2008-08-18 05:16:42 +04:00
|
|
|
nsIFrame* mPseudoFrame;
|
2005-04-02 03:07:00 +04:00
|
|
|
|
|
|
|
// Index within the list of things specified by the 'content' property,
|
|
|
|
// which is needed to do 'content: open-quote open-quote' correctly,
|
|
|
|
// and needed for similar cases for counters.
|
2012-08-22 19:56:38 +04:00
|
|
|
const int32_t mContentIndex;
|
2005-04-02 03:07:00 +04:00
|
|
|
|
|
|
|
// null for 'content:no-open-quote', 'content:no-close-quote' and for
|
|
|
|
// counter nodes for increments and resets (rather than uses)
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsTextNode> mText;
|
2005-04-02 03:07:00 +04:00
|
|
|
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit nsGenConNode(int32_t aContentIndex)
|
2012-07-30 18:20:58 +04:00
|
|
|
: mPseudoFrame(nullptr)
|
2005-04-02 03:07:00 +04:00
|
|
|
, mContentIndex(aContentIndex)
|
|
|
|
{
|
2008-08-18 05:16:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finish initializing the generated content node once we know the
|
|
|
|
* relevant text frame. This must be called just after
|
|
|
|
* the textframe has been initialized. This need not be called at all
|
|
|
|
* for nodes that don't generate text. This will generally set the
|
|
|
|
* mPseudoFrame, insert the node into aList, and set aTextFrame up
|
|
|
|
* with the correct text.
|
|
|
|
* @param aList the list the node belongs to
|
|
|
|
* @param aPseudoFrame the :before or :after frame
|
|
|
|
* @param aTextFrame the textframe where the node contents will render
|
|
|
|
* @return true iff this marked the list dirty
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool InitTextFrame(nsGenConList* aList, nsIFrame* aPseudoFrame,
|
2016-10-27 13:07:52 +03:00
|
|
|
nsIFrame* aTextFrame)
|
2008-08-18 05:16:42 +04:00
|
|
|
{
|
|
|
|
mPseudoFrame = aPseudoFrame;
|
|
|
|
CheckFrameAssertions();
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-08-18 05:16:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsGenConNode() {} // XXX Avoid, perhaps?
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void CheckFrameAssertions() {
|
|
|
|
NS_ASSERTION(mContentIndex <
|
2013-02-17 01:51:02 +04:00
|
|
|
int32_t(mPseudoFrame->StyleContent()->ContentCount()),
|
2005-04-02 03:07:00 +04:00
|
|
|
"index out of range");
|
2008-08-18 05:16:42 +04:00
|
|
|
// We allow negative values of mContentIndex for 'counter-reset' and
|
|
|
|
// 'counter-increment'.
|
2005-04-02 03:07:00 +04:00
|
|
|
|
2008-08-18 05:16:42 +04:00
|
|
|
NS_ASSERTION(mContentIndex < 0 ||
|
2013-02-16 09:38:33 +04:00
|
|
|
mPseudoFrame->StyleContext()->GetPseudo() ==
|
2005-04-02 03:07:00 +04:00
|
|
|
nsCSSPseudoElements::before ||
|
2013-02-16 09:38:33 +04:00
|
|
|
mPseudoFrame->StyleContext()->GetPseudo() ==
|
2005-04-02 03:07:00 +04:00
|
|
|
nsCSSPseudoElements::after,
|
|
|
|
"not :before/:after generated content and not counter change");
|
2008-08-18 05:16:42 +04:00
|
|
|
NS_ASSERTION(mContentIndex < 0 ||
|
|
|
|
mPseudoFrame->GetStateBits() & NS_FRAME_GENERATED_CONTENT,
|
2005-04-02 03:07:00 +04:00
|
|
|
"not generated content and not counter change");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsGenConList {
|
|
|
|
protected:
|
2016-10-27 13:07:52 +03:00
|
|
|
mozilla::LinkedList<nsGenConNode> mList;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mSize;
|
2016-10-27 13:07:52 +03:00
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
public:
|
2016-10-27 13:07:52 +03:00
|
|
|
nsGenConList() : mSize(0) {}
|
2005-04-02 03:07:00 +04:00
|
|
|
~nsGenConList() { Clear(); }
|
|
|
|
void Clear();
|
|
|
|
static nsGenConNode* Next(nsGenConNode* aNode) {
|
2016-10-27 13:07:52 +03:00
|
|
|
MOZ_ASSERT(aNode, "aNode cannot be nullptr!");
|
|
|
|
return aNode->getNext();
|
2005-04-02 03:07:00 +04:00
|
|
|
}
|
|
|
|
static nsGenConNode* Prev(nsGenConNode* aNode) {
|
2016-10-27 13:07:52 +03:00
|
|
|
MOZ_ASSERT(aNode, "aNode cannot be nullptr!");
|
|
|
|
return aNode->getPrevious();
|
2005-04-02 03:07:00 +04:00
|
|
|
}
|
|
|
|
void Insert(nsGenConNode* aNode);
|
2016-10-27 13:07:52 +03:00
|
|
|
|
|
|
|
// Destroy all nodes with aFrame as parent. Returns true if some nodes
|
|
|
|
// have been destroyed; otherwise false.
|
|
|
|
bool DestroyNodesFor(nsIFrame* aFrame);
|
2005-04-02 03:07:00 +04:00
|
|
|
|
|
|
|
// Return true if |aNode1| is after |aNode2|.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool NodeAfter(const nsGenConNode* aNode1,
|
2016-10-27 13:07:52 +03:00
|
|
|
const nsGenConNode* aNode2);
|
|
|
|
|
|
|
|
bool IsFirst(nsGenConNode* aNode) {
|
|
|
|
MOZ_ASSERT(aNode, "aNode cannot be nullptr!");
|
|
|
|
return aNode == mList.getFirst();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsLast(nsGenConNode* aNode) {
|
|
|
|
MOZ_ASSERT(aNode, "aNode cannot be nullptr!");
|
|
|
|
return aNode == mList.getLast();
|
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
|
2016-08-23 03:31:26 +03:00
|
|
|
private:
|
|
|
|
void Destroy(nsGenConNode* aNode)
|
|
|
|
{
|
2016-10-27 13:07:52 +03:00
|
|
|
MOZ_ASSERT(aNode, "aNode cannot be nullptr!");
|
2016-08-23 03:31:26 +03:00
|
|
|
delete aNode;
|
|
|
|
mSize--;
|
|
|
|
}
|
2016-08-23 03:31:26 +03:00
|
|
|
|
|
|
|
// Map from frame to the first nsGenConNode of it in the list.
|
|
|
|
nsDataHashtable<nsPtrHashKey<nsIFrame>, nsGenConNode*> mNodes;
|
2005-04-02 03:07:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsGenConList_h___ */
|