2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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> {
|
2020-01-05 16:10:39 +03:00
|
|
|
using StyleContentType = mozilla::StyleContentItem::Tag;
|
2018-06-30 16:05:15 +03:00
|
|
|
|
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
|
|
|
|
2019-05-21 20:30:42 +03:00
|
|
|
// null for:
|
|
|
|
// * content: no-open-quote / content: no-close-quote
|
|
|
|
// * counter nodes for increments and resets
|
|
|
|
// * counter nodes for bullets (mPseudoFrame->IsBulletFrame()).
|
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)
|
2005-04-02 03:07:00 +04:00
|
|
|
: mPseudoFrame(nullptr), 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(
|
2019-05-21 20:30:42 +03:00
|
|
|
mContentIndex < int32_t(mPseudoFrame->StyleContent()->ContentCount()) ||
|
|
|
|
// Special-case for the use node created for the legacy markers,
|
|
|
|
// which don't use the content property.
|
|
|
|
(mPseudoFrame->IsBulletFrame() && mContentIndex == 0 &&
|
|
|
|
mPseudoFrame->Style()->GetPseudoType() ==
|
|
|
|
mozilla::PseudoStyleType::marker &&
|
|
|
|
!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'.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
NS_ASSERTION(mContentIndex < 0 ||
|
|
|
|
mPseudoFrame->Style()->GetPseudoType() ==
|
|
|
|
mozilla::PseudoStyleType::before ||
|
|
|
|
mPseudoFrame->Style()->GetPseudoType() ==
|
2019-03-25 01:13:53 +03:00
|
|
|
mozilla::PseudoStyleType::after ||
|
|
|
|
mPseudoFrame->Style()->GetPseudoType() ==
|
|
|
|
mozilla::PseudoStyleType::marker,
|
|
|
|
"not CSS 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:
|
2017-03-28 17:04:48 +03:00
|
|
|
nsGenConList() : mSize(0), mLastInserted(nullptr) {}
|
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, const nsGenConNode* aNode2);
|
2016-10-27 13:07:52 +03:00
|
|
|
|
|
|
|
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;
|
2017-03-28 17:04:48 +03:00
|
|
|
|
|
|
|
// A weak pointer to the node most recently inserted, used to avoid repeated
|
|
|
|
// list traversals in Insert().
|
|
|
|
nsGenConNode* mLastInserted;
|
2005-04-02 03:07:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsGenConList_h___ */
|