Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky

BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.

Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.

I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.

Steps are:

$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#                      nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format

Then manual fixups.

Depends on D32948

Differential Revision: https://phabricator.services.mozilla.com/D32949
This commit is contained in:
Emilio Cobos Álvarez
2019-05-29 06:27:04 +02:00
parent d06bb40abc
commit a3b32df884
109 changed files with 512 additions and 552 deletions

View File

@@ -15,6 +15,7 @@
#include "mozilla/ComputedStyleInlines.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindContext.h"
#include "mozilla/dom/GeneratedImageContent.h"
#include "mozilla/dom/HTMLDetailsElement.h"
#include "mozilla/dom/HTMLSelectElement.h"
@@ -1742,13 +1743,8 @@ void nsCSSFrameConstructor::CreateGeneratedContentItem(
container->SetIsNativeAnonymousRoot();
container->SetPseudoElementType(aPseudoElement);
// If the parent is in a shadow tree, make sure we don't
// bind with a document because shadow roots and its descendants
// are not in document.
Document* bindDocument =
aOriginatingElement.HasFlag(NODE_IS_IN_SHADOW_TREE) ? nullptr : mDocument;
rv = container->BindToTree(bindDocument, &aOriginatingElement,
&aOriginatingElement);
BindContext context(aOriginatingElement, BindContext::ForNativeAnonymous);
rv = container->BindToTree(context, aOriginatingElement);
if (NS_FAILED(rv)) {
container->UnbindFromTree();
return;
@@ -3857,6 +3853,7 @@ nsresult nsCSSFrameConstructor::GetAnonymousContent(
return rv;
}
MOZ_ASSERT(aParent->IsElement());
for (const auto& info : aContent) {
// get our child's content and set its parent to our content
nsIContent* content = info.mContent;
@@ -3864,12 +3861,9 @@ nsresult nsCSSFrameConstructor::GetAnonymousContent(
bool anonContentIsEditable = content->HasFlag(NODE_IS_EDITABLE);
// If the parent is in a shadow tree, make sure we don't
// bind with a document because shadow roots and its descendants
// are not in document.
Document* bindDocument =
aParent->HasFlag(NODE_IS_IN_SHADOW_TREE) ? nullptr : mDocument;
rv = content->BindToTree(bindDocument, aParent, aParent);
BindContext context(*aParent->AsElement(), BindContext::ForNativeAnonymous);
rv = content->BindToTree(context, *aParent);
// If the anonymous content creator requested that the content should be
// editable, honor its request.
// We need to set the flag on the whole subtree, because existing