зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1361301: Add nsContentUtils::GetCommonFlattenedTreeAncestor. r=smaug
MozReview-Commit-ID: EVyjTrjpid2 --HG-- extra : rebase_source : 7f0933c88b78275682be96f3ea596bfb24ec9aa4
This commit is contained in:
Родитель
775ab6e694
Коммит
6e1af77eca
|
@ -2547,6 +2547,16 @@ nsContentUtils::GetCommonAncestor(nsINode* aNode1, nsINode* aNode2)
|
|||
});
|
||||
}
|
||||
|
||||
/* static */
|
||||
nsIContent*
|
||||
nsContentUtils::GetCommonFlattenedTreeAncestor(nsIContent* aContent1,
|
||||
nsIContent* aContent2)
|
||||
{
|
||||
return GetCommonAncestorInternal(aContent1, aContent2, [](nsIContent* aContent) {
|
||||
return aContent->GetFlattenedTreeParent();
|
||||
});
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool
|
||||
nsContentUtils::PositionIsBefore(nsINode* aNode1, nsINode* aNode2)
|
||||
|
|
|
@ -372,6 +372,12 @@ public:
|
|||
*/
|
||||
static nsINode* GetCommonAncestor(nsINode* aNode1, nsINode* aNode2);
|
||||
|
||||
/**
|
||||
* Returns the common flattened tree ancestor, if any, for two given content
|
||||
* nodes.
|
||||
*/
|
||||
static nsIContent* GetCommonFlattenedTreeAncestor(nsIContent* aContent1,
|
||||
nsIContent* aContent2);
|
||||
|
||||
/**
|
||||
* Returns true if aNode1 is before aNode2 in the same connected
|
||||
|
|
|
@ -4776,48 +4776,13 @@ GetLabelTarget(nsIContent* aPossibleLabel)
|
|||
return label->GetLabeledElement();
|
||||
}
|
||||
|
||||
static nsIContent* FindCommonAncestor(nsIContent *aNode1, nsIContent *aNode2)
|
||||
static nsIContent*
|
||||
FindCommonAncestor(nsIContent* aNode1, nsIContent* aNode2)
|
||||
{
|
||||
// Find closest common ancestor
|
||||
if (aNode1 && aNode2) {
|
||||
// Find the nearest common ancestor by counting the distance to the
|
||||
// root and then walking up again, in pairs.
|
||||
int32_t offset = 0;
|
||||
nsIContent *anc1 = aNode1;
|
||||
for (;;) {
|
||||
++offset;
|
||||
nsIContent* parent = anc1->GetFlattenedTreeParent();
|
||||
if (!parent)
|
||||
break;
|
||||
anc1 = parent;
|
||||
}
|
||||
nsIContent *anc2 = aNode2;
|
||||
for (;;) {
|
||||
--offset;
|
||||
nsIContent* parent = anc2->GetFlattenedTreeParent();
|
||||
if (!parent)
|
||||
break;
|
||||
anc2 = parent;
|
||||
}
|
||||
if (anc1 == anc2) {
|
||||
anc1 = aNode1;
|
||||
anc2 = aNode2;
|
||||
while (offset > 0) {
|
||||
anc1 = anc1->GetFlattenedTreeParent();
|
||||
--offset;
|
||||
}
|
||||
while (offset < 0) {
|
||||
anc2 = anc2->GetFlattenedTreeParent();
|
||||
++offset;
|
||||
}
|
||||
while (anc1 != anc2) {
|
||||
anc1 = anc1->GetFlattenedTreeParent();
|
||||
anc2 = anc2->GetFlattenedTreeParent();
|
||||
}
|
||||
return anc1;
|
||||
}
|
||||
if (!aNode1 || !aNode2) {
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
return nsContentUtils::GetCommonFlattenedTreeAncestor(aNode1, aNode2);
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
|
Загрузка…
Ссылка в новой задаче