Line data Source code
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/. */
6 :
7 : #include "mozilla/dom/HTMLTemplateElement.h"
8 : #include "mozilla/dom/HTMLTemplateElementBinding.h"
9 :
10 : #include "mozilla/GenericSpecifiedValuesInlines.h"
11 : #include "nsGkAtoms.h"
12 : #include "nsStyleConsts.h"
13 : #include "nsIAtom.h"
14 :
15 0 : NS_IMPL_NS_NEW_HTML_ELEMENT(Template)
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 0 : HTMLTemplateElement::HTMLTemplateElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
21 0 : : nsGenericHTMLElement(aNodeInfo)
22 : {
23 0 : SetHasWeirdParserInsertionMode();
24 :
25 0 : nsIDocument* contentsOwner = OwnerDoc()->GetTemplateContentsOwner();
26 0 : if (!contentsOwner) {
27 0 : MOZ_CRASH("There should always be a template contents owner.");
28 : }
29 :
30 0 : mContent = contentsOwner->CreateDocumentFragment();
31 0 : mContent->SetHost(this);
32 0 : }
33 :
34 0 : HTMLTemplateElement::~HTMLTemplateElement()
35 : {
36 0 : if (mContent) {
37 0 : mContent->SetHost(nullptr);
38 : }
39 0 : }
40 :
41 0 : NS_IMPL_ADDREF_INHERITED(HTMLTemplateElement, Element)
42 0 : NS_IMPL_RELEASE_INHERITED(HTMLTemplateElement, Element)
43 :
44 : NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTemplateElement)
45 :
46 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLTemplateElement,
47 : nsGenericHTMLElement)
48 0 : if (tmp->mContent) {
49 0 : tmp->mContent->SetHost(nullptr);
50 0 : tmp->mContent = nullptr;
51 : }
52 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
53 :
54 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTemplateElement,
55 : nsGenericHTMLElement)
56 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mContent)
57 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
58 :
59 : // QueryInterface implementation for HTMLTemplateElement
60 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLTemplateElement)
61 0 : NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
62 :
63 0 : NS_IMPL_ELEMENT_CLONE(HTMLTemplateElement)
64 :
65 : JSObject*
66 0 : HTMLTemplateElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
67 : {
68 0 : return HTMLTemplateElementBinding::Wrap(aCx, this, aGivenProto);
69 : }
70 :
71 : } // namespace dom
72 : } // namespace mozilla
73 :
|