Example #1
0
void
nsCanvasFrame::DestroyFrom(nsIFrame* aDestructRoot)
{
  nsIScrollableFrame* sf =
    PresContext()->GetPresShell()->GetRootScrollFrameAsScrollable();
  if (sf) {
    sf->RemoveScrollPositionListener(this);
  }

  nsContentUtils::DestroyAnonymousContent(&mTouchCaretElement);
  nsContentUtils::DestroyAnonymousContent(&mSelectionCaretsStartElement);
  nsContentUtils::DestroyAnonymousContent(&mSelectionCaretsEndElement);

  // Elements inserted in the custom content container have the same lifetime as
  // the document, so before destroying the container, make sure to keep a clone
  // of each of them at document level so they can be re-appended on reframe.
  if (mCustomContentContainer) {
    nsCOMPtr<nsIDocument> doc = mContent->OwnerDoc();
    ErrorResult rv;

    for (int32_t i = doc->GetAnonymousContents().Length() - 1; i >= 0; --i) {
      AnonymousContent* content = doc->GetAnonymousContents()[i];
      nsCOMPtr<nsINode> clonedElement = content->GetContentNode()->CloneNode(true, rv);
      content->SetContentNode(clonedElement->AsElement());
    }
  }
  nsContentUtils::DestroyAnonymousContent(&mCustomContentContainer);

  nsContainerFrame::DestroyFrom(aDestructRoot);
}
Example #2
0
void
nsCanvasFrame::DestroyFrom(nsIFrame* aDestructRoot)
{
  nsIScrollableFrame* sf =
    PresContext()->GetPresShell()->GetRootScrollFrameAsScrollable();
  if (sf) {
    sf->RemoveScrollPositionListener(this);
  }

  // Elements inserted in the custom content container have the same lifetime as
  // the document, so before destroying the container, make sure to keep a clone
  // of each of them at document level so they can be re-appended on reframe.
  if (mCustomContentContainer) {
    nsCOMPtr<nsIDocument> doc = mContent->OwnerDoc();
    ErrorResult rv;

    nsTArray<RefPtr<mozilla::dom::AnonymousContent>>& docAnonContents =
      doc->GetAnonymousContents();
    for (size_t i = 0, len = docAnonContents.Length(); i < len; ++i) {
      AnonymousContent* content = docAnonContents[i];
      nsCOMPtr<nsINode> clonedElement = content->GetContentNode()->CloneNode(true, rv);
      content->SetContentNode(clonedElement->AsElement());
    }
  }
  nsContentUtils::DestroyAnonymousContent(&mCustomContentContainer);

  nsContainerFrame::DestroyFrom(aDestructRoot);
}