/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */
// 16 seems to be the maximum number of manual Native Anonymous Content (NAC) // nodes that editor creates for a given element. // // These need to be manually removed by the machinery that sets the NAC, // otherwise we'll leak. using ManualNACArray = AutoTArray<RefPtr<dom::Element>, 16>;
/** * Smart pointer class to own "manual" Native Anonymous Content, and perform * the necessary registration and deregistration on the parent element.
*/ class ManualNACPtr final { public:
ManualNACPtr() = default;
MOZ_IMPLICIT ManualNACPtr(decltype(nullptr)) {} explicit ManualNACPtr(already_AddRefed<dom::Element> aNewNAC)
: mPtr(aNewNAC) { if (!mPtr) { return;
}
// Record the NAC on the element, so that AllChildrenIterator can find it.
nsIContent* parentContent = mPtr->GetParent(); auto nac = static_cast<ManualNACArray*>(
parentContent->GetProperty(nsGkAtoms::manualNACProperty)); if (!nac) {
nac = new ManualNACArray();
parentContent->SetProperty(nsGkAtoms::manualNACProperty, nac,
nsINode::DeleteProperty<ManualNACArray>);
}
nac->AppendElement(mPtr);
}
// We use move semantics, and delete the copy-constructor and operator=.
ManualNACPtr(ManualNACPtr&& aOther) : mPtr(std::move(aOther.mPtr)) {}
ManualNACPtr(ManualNACPtr& aOther) = delete;
ManualNACPtr& operator=(ManualNACPtr&& aOther) {
mPtr = std::move(aOther.mPtr); return *this;
}
ManualNACPtr& operator=(ManualNACPtr& aOther) = delete;
// Remove reference from the parent element. auto* nac = static_cast<ManualNACArray*>(
parentContent->GetProperty(nsGkAtoms::manualNACProperty)); // Document::AdoptNode might remove all properties before destroying editor. // So we have to consider that NAC could be already removed. if (nac) {
nac->RemoveElement(aAnonymousContent); if (nac->IsEmpty()) {
parentContent->RemoveProperty(nsGkAtoms::manualNACProperty);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.