mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-01 12:03:08 +00:00
Bug 335913: Reimplement CompareDocumentPosition using nsINode interfaces. r/sr=bz
This commit is contained in:
parent
0e8bc6bf62
commit
b0d7599f6b
@ -291,8 +291,8 @@ nsLayoutUtils::DoCompareTreePosition(nsIContent* aContent1,
|
||||
NS_PRECONDITION(aContent2, "aContent2 must not be null");
|
||||
|
||||
nsAutoVoidArray content1Ancestors;
|
||||
nsIContent* c1;
|
||||
for (c1 = aContent1; c1 && c1 != aCommonAncestor; c1 = c1->GetParent()) {
|
||||
nsINode* c1;
|
||||
for (c1 = aContent1; c1 && c1 != aCommonAncestor; c1 = c1->GetNodeParent()) {
|
||||
content1Ancestors.AppendElement(c1);
|
||||
}
|
||||
if (!c1 && aCommonAncestor) {
|
||||
@ -302,8 +302,8 @@ nsLayoutUtils::DoCompareTreePosition(nsIContent* aContent1,
|
||||
}
|
||||
|
||||
nsAutoVoidArray content2Ancestors;
|
||||
nsIContent* c2;
|
||||
for (c2 = aContent2; c2 && c2 != aCommonAncestor; c2 = c2->GetParent()) {
|
||||
nsINode* c2;
|
||||
for (c2 = aContent2; c2 && c2 != aCommonAncestor; c2 = c2->GetNodeParent()) {
|
||||
content2Ancestors.AppendElement(c2);
|
||||
}
|
||||
if (!c2 && aCommonAncestor) {
|
||||
@ -315,11 +315,11 @@ nsLayoutUtils::DoCompareTreePosition(nsIContent* aContent1,
|
||||
|
||||
int last1 = content1Ancestors.Count() - 1;
|
||||
int last2 = content2Ancestors.Count() - 1;
|
||||
nsIContent* content1Ancestor = nsnull;
|
||||
nsIContent* content2Ancestor = nsnull;
|
||||
nsINode* content1Ancestor = nsnull;
|
||||
nsINode* content2Ancestor = nsnull;
|
||||
while (last1 >= 0 && last2 >= 0
|
||||
&& ((content1Ancestor = NS_STATIC_CAST(nsIContent*, content1Ancestors.ElementAt(last1)))
|
||||
== (content2Ancestor = NS_STATIC_CAST(nsIContent*, content2Ancestors.ElementAt(last2))))) {
|
||||
&& ((content1Ancestor = NS_STATIC_CAST(nsINode*, content1Ancestors.ElementAt(last1)))
|
||||
== (content2Ancestor = NS_STATIC_CAST(nsINode*, content2Ancestors.ElementAt(last2))))) {
|
||||
last1--;
|
||||
last2--;
|
||||
}
|
||||
@ -328,32 +328,31 @@ nsLayoutUtils::DoCompareTreePosition(nsIContent* aContent1,
|
||||
if (last2 < 0) {
|
||||
NS_ASSERTION(aContent1 == aContent2, "internal error?");
|
||||
return 0;
|
||||
} else {
|
||||
// aContent1 is an ancestor of aContent2
|
||||
return aIf1Ancestor;
|
||||
}
|
||||
} else {
|
||||
if (last2 < 0) {
|
||||
// aContent2 is an ancestor of aContent1
|
||||
return aIf2Ancestor;
|
||||
} else {
|
||||
// content1Ancestor != content2Ancestor, so they must be siblings with the same parent
|
||||
nsIContent* parent = content1Ancestor->GetParent();
|
||||
NS_ASSERTION(parent, "no common ancestor at all???");
|
||||
if (!parent) { // different documents??
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 index1 = parent->IndexOf(content1Ancestor);
|
||||
PRInt32 index2 = parent->IndexOf(content2Ancestor);
|
||||
if (index1 < 0 || index2 < 0) {
|
||||
// one of them must be anonymous; we can't determine the order
|
||||
return 0;
|
||||
}
|
||||
|
||||
return index1 - index2;
|
||||
}
|
||||
// aContent1 is an ancestor of aContent2
|
||||
return aIf1Ancestor;
|
||||
}
|
||||
|
||||
if (last2 < 0) {
|
||||
// aContent2 is an ancestor of aContent1
|
||||
return aIf2Ancestor;
|
||||
}
|
||||
|
||||
// content1Ancestor != content2Ancestor, so they must be siblings with the same parent
|
||||
nsINode* parent = content1Ancestor->GetNodeParent();
|
||||
NS_ASSERTION(parent, "no common ancestor at all???");
|
||||
if (!parent) { // different documents??
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 index1 = parent->IndexOf(content1Ancestor);
|
||||
PRInt32 index2 = parent->IndexOf(content2Ancestor);
|
||||
if (index1 < 0 || index2 < 0) {
|
||||
// one of them must be anonymous; we can't determine the order
|
||||
return 0;
|
||||
}
|
||||
|
||||
return index1 - index2;
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -1101,9 +1101,6 @@ CSSLoaderImpl::InsertSheetInDoc(nsICSSStyleSheet* aSheet,
|
||||
|
||||
// all nodes that link in sheets should be implementing nsIDOM3Node
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIDOM3Node> linkingNode = do_QueryInterface(aLinkingContent);
|
||||
NS_ASSERTION(linkingNode || !aLinkingContent,
|
||||
"Need to implement nsIDOM3Node to get insertion order right");
|
||||
|
||||
// XXX Need to cancel pending sheet loads for this element, if any
|
||||
|
||||
@ -1125,7 +1122,7 @@ CSSLoaderImpl::InsertSheetInDoc(nsICSSStyleSheet* aSheet,
|
||||
NS_ASSERTION(domSheet, "All the \"normal\" sheets implement nsIDOMStyleSheet");
|
||||
nsCOMPtr<nsIDOMNode> sheetOwner;
|
||||
domSheet->GetOwnerNode(getter_AddRefs(sheetOwner));
|
||||
if (sheetOwner && !linkingNode) {
|
||||
if (sheetOwner && !aLinkingContent) {
|
||||
// Keep moving; all sheets with a sheetOwner come after all
|
||||
// sheets without a linkingNode
|
||||
continue;
|
||||
@ -1137,21 +1134,12 @@ CSSLoaderImpl::InsertSheetInDoc(nsICSSStyleSheet* aSheet,
|
||||
break;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsINode> sheetOwnerNode = do_QueryInterface(sheetOwner);
|
||||
NS_ASSERTION(aLinkingContent != sheetOwnerNode,
|
||||
"Why do we still have our old sheet?");
|
||||
|
||||
// Have to compare
|
||||
PRUint16 comparisonFlags = 0;
|
||||
rv = linkingNode->CompareDocumentPosition(sheetOwner, &comparisonFlags);
|
||||
// If we can't get the order right, just bail...
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(!(comparisonFlags & nsIDOM3Node::DOCUMENT_POSITION_DISCONNECTED),
|
||||
"Why are these elements in different documents?");
|
||||
#ifdef DEBUG
|
||||
{
|
||||
PRBool sameNode = PR_FALSE;
|
||||
linkingNode->IsSameNode(sheetOwner, &sameNode);
|
||||
NS_ASSERTION(!sameNode, "Why do we still have our old sheet?");
|
||||
}
|
||||
#endif // DEBUG
|
||||
if (comparisonFlags & nsIDOM3Node::DOCUMENT_POSITION_PRECEDING) {
|
||||
if (nsContentUtils::PositionBefore(sheetOwnerNode, aLinkingContent)) {
|
||||
// The current sheet comes before us, and it better be the first
|
||||
// such, because now we break
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user