Bug 1795723 - Unified extensions UI should support High Contrast Mode. r=ayeddi,deskt...
[gecko.git] / dom / html / HTMLTemplateElement.cpp
blob266405ef1ed14ef5ecceb87d5b619b71fcf119e9
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/HTMLTemplateElement.h"
8 #include "mozilla/dom/HTMLTemplateElementBinding.h"
10 #include "mozilla/dom/Document.h"
11 #include "mozilla/MappedDeclarations.h"
12 #include "nsGkAtoms.h"
13 #include "nsStyleConsts.h"
14 #include "nsAtom.h"
16 NS_IMPL_NS_NEW_HTML_ELEMENT(Template)
18 namespace mozilla::dom {
20 HTMLTemplateElement::HTMLTemplateElement(
21 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
22 : nsGenericHTMLElement(std::move(aNodeInfo)) {
23 SetHasWeirdParserInsertionMode();
25 Document* contentsOwner = OwnerDoc()->GetTemplateContentsOwner();
26 if (!contentsOwner) {
27 MOZ_CRASH("There should always be a template contents owner.");
30 mContent = contentsOwner->CreateDocumentFragment();
31 mContent->SetHost(this);
34 HTMLTemplateElement::~HTMLTemplateElement() {
35 if (mContent) {
36 mContent->SetHost(nullptr);
40 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(HTMLTemplateElement,
41 nsGenericHTMLElement)
43 NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTemplateElement)
45 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLTemplateElement,
46 nsGenericHTMLElement)
47 if (tmp->mContent) {
48 tmp->mContent->SetHost(nullptr);
49 tmp->mContent = nullptr;
51 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
53 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTemplateElement,
54 nsGenericHTMLElement)
55 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContent)
56 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
58 NS_IMPL_ELEMENT_CLONE(HTMLTemplateElement)
60 JSObject* HTMLTemplateElement::WrapNode(JSContext* aCx,
61 JS::Handle<JSObject*> aGivenProto) {
62 return HTMLTemplateElement_Binding::Wrap(aCx, this, aGivenProto);
65 } // namespace mozilla::dom