2005-04-02 03:07:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:cindent:ts=2:et:sw=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/. */
|
2005-04-02 03:07:00 +04:00
|
|
|
|
2006-03-30 09:56:38 +04:00
|
|
|
/* base class for nsCounterList and nsQuoteList */
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
#include "nsGenConList.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenConList::Clear()
|
|
|
|
{
|
|
|
|
//Delete entire list
|
|
|
|
if (!mFirstNode)
|
|
|
|
return;
|
|
|
|
for (nsGenConNode *node = Next(mFirstNode); node != mFirstNode;
|
|
|
|
node = Next(mFirstNode))
|
|
|
|
{
|
|
|
|
Remove(node);
|
|
|
|
delete node;
|
|
|
|
}
|
|
|
|
delete mFirstNode;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mFirstNode = nullptr;
|
2005-04-02 03:07:00 +04:00
|
|
|
mSize = 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2005-04-02 03:07:00 +04:00
|
|
|
nsGenConList::DestroyNodesFor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!mFirstNode)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // list empty
|
2005-04-02 03:07:00 +04:00
|
|
|
nsGenConNode* node;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool destroyed = false;
|
2005-04-02 03:07:00 +04:00
|
|
|
while (mFirstNode->mPseudoFrame == aFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
destroyed = true;
|
2005-04-02 03:07:00 +04:00
|
|
|
node = Next(mFirstNode);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isLastNode = node == mFirstNode; // before they're dangling
|
2007-01-17 12:24:19 +03:00
|
|
|
Remove(mFirstNode);
|
|
|
|
delete mFirstNode;
|
|
|
|
if (isLastNode) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mFirstNode = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2005-04-02 03:07:00 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mFirstNode = node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node = Next(mFirstNode);
|
|
|
|
while (node != mFirstNode) {
|
|
|
|
if (node->mPseudoFrame == aFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
destroyed = true;
|
2005-04-02 03:07:00 +04:00
|
|
|
nsGenConNode *nextNode = Next(node);
|
|
|
|
Remove(node);
|
|
|
|
delete node;
|
|
|
|
node = nextNode;
|
|
|
|
} else {
|
|
|
|
node = Next(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return destroyed;
|
|
|
|
}
|
|
|
|
|
2008-08-18 05:16:42 +04:00
|
|
|
/**
|
|
|
|
* Compute the type of the pseudo and the content for the pseudo that
|
|
|
|
* we'll use for comparison purposes.
|
|
|
|
* @param aContent the content to use is stored here; it's the element
|
|
|
|
* that generated the ::before or ::after content, or (if not for generated
|
|
|
|
* content), the frame's own element
|
|
|
|
* @return -1 for ::before, +1 for ::after, and 0 otherwise.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
inline int32_t PseudoCompareType(nsIFrame* aFrame, nsIContent** aContent)
|
2005-04-02 03:07:00 +04:00
|
|
|
{
|
2013-02-16 09:38:33 +04:00
|
|
|
nsIAtom *pseudo = aFrame->StyleContext()->GetPseudo();
|
2008-08-18 05:16:42 +04:00
|
|
|
if (pseudo == nsCSSPseudoElements::before) {
|
|
|
|
*aContent = aFrame->GetContent()->GetParent();
|
2005-04-02 03:07:00 +04:00
|
|
|
return -1;
|
2008-08-18 05:16:42 +04:00
|
|
|
}
|
|
|
|
if (pseudo == nsCSSPseudoElements::after) {
|
|
|
|
*aContent = aFrame->GetContent()->GetParent();
|
2005-04-02 03:07:00 +04:00
|
|
|
return 1;
|
2008-08-18 05:16:42 +04:00
|
|
|
}
|
|
|
|
*aContent = aFrame->GetContent();
|
2005-04-02 03:07:00 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2005-04-02 03:07:00 +04:00
|
|
|
nsGenConList::NodeAfter(const nsGenConNode* aNode1, const nsGenConNode* aNode2)
|
|
|
|
{
|
|
|
|
nsIFrame *frame1 = aNode1->mPseudoFrame;
|
|
|
|
nsIFrame *frame2 = aNode2->mPseudoFrame;
|
|
|
|
if (frame1 == frame2) {
|
|
|
|
NS_ASSERTION(aNode2->mContentIndex != aNode1->mContentIndex, "identical");
|
|
|
|
return aNode1->mContentIndex > aNode2->mContentIndex;
|
|
|
|
}
|
2008-08-18 05:16:42 +04:00
|
|
|
nsIContent *content1;
|
|
|
|
nsIContent *content2;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t pseudoType1 = PseudoCompareType(frame1, &content1);
|
|
|
|
int32_t pseudoType2 = PseudoCompareType(frame2, &content2);
|
2005-04-02 03:07:00 +04:00
|
|
|
if (pseudoType1 == 0 || pseudoType2 == 0) {
|
|
|
|
if (content1 == content2) {
|
|
|
|
NS_ASSERTION(pseudoType1 != pseudoType2, "identical");
|
|
|
|
return pseudoType2 == 0;
|
|
|
|
}
|
|
|
|
// We want to treat an element as coming before its :before (preorder
|
|
|
|
// traversal), so treating both as :before now works.
|
|
|
|
if (pseudoType1 == 0) pseudoType1 = -1;
|
|
|
|
if (pseudoType2 == 0) pseudoType2 = -1;
|
|
|
|
} else {
|
|
|
|
if (content1 == content2) {
|
|
|
|
NS_ASSERTION(pseudoType1 != pseudoType2, "identical");
|
|
|
|
return pseudoType1 == 1;
|
|
|
|
}
|
|
|
|
}
|
2007-01-17 12:24:19 +03:00
|
|
|
// XXX Switch to the frame version of DoCompareTreePosition?
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t cmp = nsLayoutUtils::DoCompareTreePosition(content1, content2,
|
2005-04-02 03:07:00 +04:00
|
|
|
pseudoType1, -pseudoType2);
|
|
|
|
NS_ASSERTION(cmp != 0, "same content, different frames");
|
|
|
|
return cmp > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenConList::Insert(nsGenConNode* aNode)
|
|
|
|
{
|
|
|
|
if (mFirstNode) {
|
|
|
|
// Check for append.
|
|
|
|
if (NodeAfter(aNode, Prev(mFirstNode))) {
|
|
|
|
PR_INSERT_BEFORE(aNode, mFirstNode);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Binary search.
|
|
|
|
|
|
|
|
// the range of indices at which |aNode| could end up.
|
2007-01-17 12:24:19 +03:00
|
|
|
// (We already know it can't be at index mSize.)
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t first = 0, last = mSize - 1;
|
2005-04-02 03:07:00 +04:00
|
|
|
|
|
|
|
// A cursor to avoid walking more than the length of the list.
|
|
|
|
nsGenConNode *curNode = Prev(mFirstNode);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t curIndex = mSize - 1;
|
2005-04-02 03:07:00 +04:00
|
|
|
|
|
|
|
while (first != last) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t test = (first + last) / 2;
|
2005-04-02 03:07:00 +04:00
|
|
|
if (last == curIndex) {
|
|
|
|
for ( ; curIndex != test; --curIndex)
|
|
|
|
curNode = Prev(curNode);
|
|
|
|
} else {
|
|
|
|
for ( ; curIndex != test; ++curIndex)
|
|
|
|
curNode = Next(curNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NodeAfter(aNode, curNode)) {
|
|
|
|
first = test + 1;
|
|
|
|
// if we exit the loop, we need curNode to be right
|
|
|
|
++curIndex;
|
|
|
|
curNode = Next(curNode);
|
|
|
|
} else {
|
|
|
|
last = test;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PR_INSERT_BEFORE(aNode, curNode);
|
|
|
|
if (curNode == mFirstNode) {
|
|
|
|
mFirstNode = aNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// initialize list with first node
|
|
|
|
PR_INIT_CLIST(aNode);
|
|
|
|
mFirstNode = aNode;
|
|
|
|
}
|
|
|
|
++mSize;
|
2007-01-17 12:24:19 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(aNode == mFirstNode || NodeAfter(aNode, Prev(aNode)),
|
|
|
|
"sorting error");
|
|
|
|
NS_ASSERTION(IsLast(aNode) || NodeAfter(Next(aNode), aNode),
|
|
|
|
"sorting error");
|
2005-04-02 03:07:00 +04:00
|
|
|
}
|