gecko-dev/dom/base/BindContext.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 строки
2.6 KiB
C
Исходник Обычный вид История

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
2019-05-29 07:27:04 +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: */
/* 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/. */
/* State that is passed down to BindToTree. */
#ifndef mozilla_dom_BindContext_h__
#define mozilla_dom_BindContext_h__
#include "mozilla/Attributes.h"
#include "nsXBLBinding.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ShadowRoot.h"
namespace mozilla {
namespace dom {
struct MOZ_STACK_CLASS BindContext final {
// Whether our subtree root is changing as a result of this operation.
bool SubtreeRootChanges() const { return mSubtreeRootChanges; }
// Returns the binding parent of the subtree to be inserted.
//
// This can be null.
Element* GetBindingParent() const { return mBindingParent; }
// This constructor should be used for regular appends to content.
//
// FIXME(emilio, bug 1555944): nsIContent::GetBindingParent() should return an
// Element*.
explicit BindContext(nsINode& aParentNode)
: mSubtreeRootChanges(true),
mBindingParent(aParentNode.IsContent()
? static_cast<Element*>(
aParentNode.AsContent()->GetBindingParent())
: nullptr) {}
// When re-binding a shadow host into a tree, we re-bind all the shadow tree
// from the root. In that case, the shadow tree contents remain within the
// same subtree root. So children should avoid doing silly things like adding
// themselves to the ShadowRoot's id table twice or what not.
//
// This constructor is only meant to be used in that situation.
explicit BindContext(ShadowRoot& aShadowRoot)
: mSubtreeRootChanges(false),
mBindingParent(aShadowRoot.Host()) {}
// This constructor is meant to be used when inserting native-anonymous
// children into a subtree.
enum ForNativeAnonymous { ForNativeAnonymous };
BindContext(Element& aParentElement, enum ForNativeAnonymous)
: mSubtreeRootChanges(true),
mBindingParent(&aParentElement) {}
// This is meant to be used to bind XBL anonymous content.
BindContext(nsXBLBinding& aBinding, Element& aParentElement)
: mSubtreeRootChanges(true),
mBindingParent(aBinding.GetBoundElement()) {}
private:
// Whether the bind operation will change the subtree root of the content
// we're binding.
const bool mSubtreeRootChanges;
Element* const mBindingParent;
};
} // namespace dom
} // namespace mozilla
#endif